1c942fddfSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2*73f04d3dSAditya Srivastava /*
3049359d6SJames Hsiao  * AMCC SoC PPC4xx Crypto Driver
4049359d6SJames Hsiao  *
5049359d6SJames Hsiao  * Copyright (c) 2008 Applied Micro Circuits Corporation.
6049359d6SJames Hsiao  * All rights reserved. James Hsiao <jhsiao@amcc.com>
7049359d6SJames Hsiao  *
8049359d6SJames Hsiao  * This filr defines the register set for Security Subsystem
9049359d6SJames Hsiao  */
10049359d6SJames Hsiao 
11049359d6SJames Hsiao #ifndef __CRYPTO4XX_REG_DEF_H__
12049359d6SJames Hsiao #define __CRYPTO4XX_REG_DEF_H__
13049359d6SJames Hsiao 
14049359d6SJames Hsiao /* CRYPTO4XX Register offset */
15049359d6SJames Hsiao #define CRYPTO4XX_DESCRIPTOR			0x00000000
16049359d6SJames Hsiao #define CRYPTO4XX_CTRL_STAT			0x00000000
17049359d6SJames Hsiao #define CRYPTO4XX_SOURCE			0x00000004
18049359d6SJames Hsiao #define CRYPTO4XX_DEST				0x00000008
19049359d6SJames Hsiao #define CRYPTO4XX_SA				0x0000000C
20049359d6SJames Hsiao #define CRYPTO4XX_SA_LENGTH			0x00000010
21049359d6SJames Hsiao #define CRYPTO4XX_LENGTH			0x00000014
22049359d6SJames Hsiao 
23049359d6SJames Hsiao #define CRYPTO4XX_PE_DMA_CFG			0x00000040
24049359d6SJames Hsiao #define CRYPTO4XX_PE_DMA_STAT			0x00000044
25049359d6SJames Hsiao #define CRYPTO4XX_PDR_BASE			0x00000048
26049359d6SJames Hsiao #define CRYPTO4XX_RDR_BASE			0x0000004c
27049359d6SJames Hsiao #define CRYPTO4XX_RING_SIZE			0x00000050
28049359d6SJames Hsiao #define CRYPTO4XX_RING_CTRL			0x00000054
29049359d6SJames Hsiao #define CRYPTO4XX_INT_RING_STAT			0x00000058
30049359d6SJames Hsiao #define CRYPTO4XX_EXT_RING_STAT			0x0000005c
31049359d6SJames Hsiao #define CRYPTO4XX_IO_THRESHOLD			0x00000060
32049359d6SJames Hsiao #define CRYPTO4XX_GATH_RING_BASE		0x00000064
33049359d6SJames Hsiao #define CRYPTO4XX_SCAT_RING_BASE		0x00000068
34049359d6SJames Hsiao #define CRYPTO4XX_PART_RING_SIZE		0x0000006c
35049359d6SJames Hsiao #define CRYPTO4XX_PART_RING_CFG		        0x00000070
36049359d6SJames Hsiao 
37049359d6SJames Hsiao #define CRYPTO4XX_PDR_BASE_UADDR		0x00000080
38049359d6SJames Hsiao #define CRYPTO4XX_RDR_BASE_UADDR		0x00000084
39049359d6SJames Hsiao #define CRYPTO4XX_PKT_SRC_UADDR			0x00000088
40049359d6SJames Hsiao #define CRYPTO4XX_PKT_DEST_UADDR		0x0000008c
41049359d6SJames Hsiao #define CRYPTO4XX_SA_UADDR			0x00000090
42049359d6SJames Hsiao #define CRYPTO4XX_GATH_RING_BASE_UADDR		0x000000A0
43049359d6SJames Hsiao #define CRYPTO4XX_SCAT_RING_BASE_UADDR		0x000000A4
44049359d6SJames Hsiao 
45049359d6SJames Hsiao #define CRYPTO4XX_SEQ_RD			0x00000408
46049359d6SJames Hsiao #define CRYPTO4XX_SEQ_MASK_RD			0x0000040C
47049359d6SJames Hsiao 
48049359d6SJames Hsiao #define CRYPTO4XX_SA_CMD_0			0x00010600
49049359d6SJames Hsiao #define CRYPTO4XX_SA_CMD_1			0x00010604
50049359d6SJames Hsiao 
51049359d6SJames Hsiao #define CRYPTO4XX_STATE_PTR			0x000106dc
52049359d6SJames Hsiao #define CRYPTO4XX_STATE_IV			0x00010700
53049359d6SJames Hsiao #define CRYPTO4XX_STATE_HASH_BYTE_CNT_0		0x00010710
54049359d6SJames Hsiao #define CRYPTO4XX_STATE_HASH_BYTE_CNT_1		0x00010714
55049359d6SJames Hsiao 
56049359d6SJames Hsiao #define CRYPTO4XX_STATE_IDIGEST_0		0x00010718
57049359d6SJames Hsiao #define CRYPTO4XX_STATE_IDIGEST_1		0x0001071c
58049359d6SJames Hsiao 
59049359d6SJames Hsiao #define CRYPTO4XX_DATA_IN			0x00018000
60049359d6SJames Hsiao #define CRYPTO4XX_DATA_OUT			0x0001c000
61049359d6SJames Hsiao 
62049359d6SJames Hsiao #define CRYPTO4XX_INT_UNMASK_STAT		0x000500a0
63049359d6SJames Hsiao #define CRYPTO4XX_INT_MASK_STAT			0x000500a4
64049359d6SJames Hsiao #define CRYPTO4XX_INT_CLR			0x000500a4
65049359d6SJames Hsiao #define CRYPTO4XX_INT_EN			0x000500a8
66049359d6SJames Hsiao 
67049359d6SJames Hsiao #define CRYPTO4XX_INT_PKA			0x00000002
68049359d6SJames Hsiao #define CRYPTO4XX_INT_PDR_DONE			0x00008000
69049359d6SJames Hsiao #define CRYPTO4XX_INT_MA_WR_ERR			0x00020000
70049359d6SJames Hsiao #define CRYPTO4XX_INT_MA_RD_ERR			0x00010000
71049359d6SJames Hsiao #define CRYPTO4XX_INT_PE_ERR			0x00000200
72049359d6SJames Hsiao #define CRYPTO4XX_INT_USER_DMA_ERR		0x00000040
73049359d6SJames Hsiao #define CRYPTO4XX_INT_SLAVE_ERR			0x00000010
74049359d6SJames Hsiao #define CRYPTO4XX_INT_MASTER_ERR		0x00000008
75049359d6SJames Hsiao #define CRYPTO4XX_INT_ERROR			0x00030258
76049359d6SJames Hsiao 
77049359d6SJames Hsiao #define CRYPTO4XX_INT_CFG			0x000500ac
78049359d6SJames Hsiao #define CRYPTO4XX_INT_DESCR_RD			0x000500b0
79049359d6SJames Hsiao #define CRYPTO4XX_INT_DESCR_CNT			0x000500b4
80049359d6SJames Hsiao #define CRYPTO4XX_INT_TIMEOUT_CNT		0x000500b8
81049359d6SJames Hsiao 
82049359d6SJames Hsiao #define CRYPTO4XX_DEVICE_CTRL			0x00060080
83049359d6SJames Hsiao #define CRYPTO4XX_DEVICE_ID			0x00060084
84049359d6SJames Hsiao #define CRYPTO4XX_DEVICE_INFO			0x00060088
85049359d6SJames Hsiao #define CRYPTO4XX_DMA_USER_SRC			0x00060094
86049359d6SJames Hsiao #define CRYPTO4XX_DMA_USER_DEST			0x00060098
87049359d6SJames Hsiao #define CRYPTO4XX_DMA_USER_CMD			0x0006009C
88049359d6SJames Hsiao 
89049359d6SJames Hsiao #define CRYPTO4XX_DMA_CFG	        	0x000600d4
90049359d6SJames Hsiao #define CRYPTO4XX_BYTE_ORDER_CFG 		0x000600d8
91049359d6SJames Hsiao #define CRYPTO4XX_ENDIAN_CFG			0x000600d8
92049359d6SJames Hsiao 
93049359d6SJames Hsiao #define CRYPTO4XX_PRNG_STAT			0x00070000
94d072bfa4SChristian Lamparter #define CRYPTO4XX_PRNG_STAT_BUSY		0x1
95049359d6SJames Hsiao #define CRYPTO4XX_PRNG_CTRL			0x00070004
96049359d6SJames Hsiao #define CRYPTO4XX_PRNG_SEED_L			0x00070008
97049359d6SJames Hsiao #define CRYPTO4XX_PRNG_SEED_H			0x0007000c
98049359d6SJames Hsiao 
99049359d6SJames Hsiao #define CRYPTO4XX_PRNG_RES_0			0x00070020
100049359d6SJames Hsiao #define CRYPTO4XX_PRNG_RES_1			0x00070024
101049359d6SJames Hsiao #define CRYPTO4XX_PRNG_RES_2			0x00070028
102049359d6SJames Hsiao #define CRYPTO4XX_PRNG_RES_3			0x0007002C
103049359d6SJames Hsiao 
104049359d6SJames Hsiao #define CRYPTO4XX_PRNG_LFSR_L			0x00070030
105049359d6SJames Hsiao #define CRYPTO4XX_PRNG_LFSR_H			0x00070034
106049359d6SJames Hsiao 
107*73f04d3dSAditya Srivastava /*
108421f91d2SUwe Kleine-König  * Initialize CRYPTO ENGINE registers, and memory bases.
109049359d6SJames Hsiao  */
110049359d6SJames Hsiao #define PPC4XX_PDR_POLL				0x3ff
111049359d6SJames Hsiao #define PPC4XX_OUTPUT_THRESHOLD			2
112049359d6SJames Hsiao #define PPC4XX_INPUT_THRESHOLD			2
113049359d6SJames Hsiao #define PPC4XX_PD_SIZE				6
114049359d6SJames Hsiao #define PPC4XX_CTX_DONE_INT			0x2000
115049359d6SJames Hsiao #define PPC4XX_PD_DONE_INT			0x8000
116b66c685aSChristian Lamparter #define PPC4XX_TMO_ERR_INT			0x40000
117049359d6SJames Hsiao #define PPC4XX_BYTE_ORDER			0x22222
118049359d6SJames Hsiao #define PPC4XX_INTERRUPT_CLR			0x3ffff
119049359d6SJames Hsiao #define PPC4XX_PRNG_CTRL_AUTO_EN		0x3
120049359d6SJames Hsiao #define PPC4XX_DC_3DES_EN			1
1215343e674SChristian Lamparter #define PPC4XX_TRNG_EN				0x00020000
122b66c685aSChristian Lamparter #define PPC4XX_INT_DESCR_CNT			7
123049359d6SJames Hsiao #define PPC4XX_INT_TIMEOUT_CNT			0
124b66c685aSChristian Lamparter #define PPC4XX_INT_TIMEOUT_CNT_REVB		0x3FF
125049359d6SJames Hsiao #define PPC4XX_INT_CFG				1
126*73f04d3dSAditya Srivastava /*
127049359d6SJames Hsiao  * all follow define are ad hoc
128049359d6SJames Hsiao  */
129049359d6SJames Hsiao #define PPC4XX_RING_RETRY			100
130049359d6SJames Hsiao #define PPC4XX_RING_POLL			100
131049359d6SJames Hsiao #define PPC4XX_SDR_SIZE				PPC4XX_NUM_SD
132049359d6SJames Hsiao #define PPC4XX_GDR_SIZE				PPC4XX_NUM_GD
133049359d6SJames Hsiao 
134*73f04d3dSAditya Srivastava /*
135049359d6SJames Hsiao   * Generic Security Association (SA) with all possible fields. These will
136049359d6SJames Hsiao  * never likely used except for reference purpose. These structure format
137049359d6SJames Hsiao  * can be not changed as the hardware expects them to be layout as defined.
138049359d6SJames Hsiao  * Field can be removed or reduced but ordering can not be changed.
139049359d6SJames Hsiao  */
140049359d6SJames Hsiao #define CRYPTO4XX_DMA_CFG_OFFSET		0x40
141049359d6SJames Hsiao union ce_pe_dma_cfg {
142049359d6SJames Hsiao 	struct {
143049359d6SJames Hsiao 		u32 rsv:7;
144049359d6SJames Hsiao 		u32 dir_host:1;
145049359d6SJames Hsiao 		u32 rsv1:2;
146049359d6SJames Hsiao 		u32 bo_td_en:1;
147049359d6SJames Hsiao 		u32 dis_pdr_upd:1;
148049359d6SJames Hsiao 		u32 bo_sgpd_en:1;
149049359d6SJames Hsiao 		u32 bo_data_en:1;
150049359d6SJames Hsiao 		u32 bo_sa_en:1;
151049359d6SJames Hsiao 		u32 bo_pd_en:1;
152049359d6SJames Hsiao 		u32 rsv2:4;
153049359d6SJames Hsiao 		u32 dynamic_sa_en:1;
154049359d6SJames Hsiao 		u32 pdr_mode:2;
155049359d6SJames Hsiao 		u32 pe_mode:1;
156049359d6SJames Hsiao 		u32 rsv3:5;
157049359d6SJames Hsiao 		u32 reset_sg:1;
158049359d6SJames Hsiao 		u32 reset_pdr:1;
159049359d6SJames Hsiao 		u32 reset_pe:1;
160049359d6SJames Hsiao 	} bf;
161049359d6SJames Hsiao     u32 w;
162049359d6SJames Hsiao } __attribute__((packed));
163049359d6SJames Hsiao 
164049359d6SJames Hsiao #define CRYPTO4XX_PDR_BASE_OFFSET		0x48
165049359d6SJames Hsiao #define CRYPTO4XX_RDR_BASE_OFFSET		0x4c
166049359d6SJames Hsiao #define CRYPTO4XX_RING_SIZE_OFFSET		0x50
167049359d6SJames Hsiao union ce_ring_size {
168049359d6SJames Hsiao 	struct {
169049359d6SJames Hsiao 		u32 ring_offset:16;
170049359d6SJames Hsiao 		u32 rsv:6;
171049359d6SJames Hsiao 		u32 ring_size:10;
172049359d6SJames Hsiao 	} bf;
173049359d6SJames Hsiao     u32 w;
174049359d6SJames Hsiao } __attribute__((packed));
175049359d6SJames Hsiao 
176049359d6SJames Hsiao #define CRYPTO4XX_RING_CONTROL_OFFSET		0x54
1777c6c0dc7SColin Ian King union ce_ring_control {
178049359d6SJames Hsiao 	struct {
179049359d6SJames Hsiao 		u32 continuous:1;
180049359d6SJames Hsiao 		u32 rsv:5;
181049359d6SJames Hsiao 		u32 ring_retry_divisor:10;
182049359d6SJames Hsiao 		u32 rsv1:4;
183049359d6SJames Hsiao 		u32 ring_poll_divisor:10;
184049359d6SJames Hsiao 	} bf;
185049359d6SJames Hsiao     u32 w;
186049359d6SJames Hsiao } __attribute__((packed));
187049359d6SJames Hsiao 
188049359d6SJames Hsiao #define CRYPTO4XX_IO_THRESHOLD_OFFSET		0x60
189049359d6SJames Hsiao union ce_io_threshold {
190049359d6SJames Hsiao 	struct {
191049359d6SJames Hsiao 		u32 rsv:6;
192049359d6SJames Hsiao 		u32 output_threshold:10;
193049359d6SJames Hsiao 		u32 rsv1:6;
194049359d6SJames Hsiao 		u32 input_threshold:10;
195049359d6SJames Hsiao 	} bf;
196049359d6SJames Hsiao     u32 w;
197049359d6SJames Hsiao } __attribute__((packed));
198049359d6SJames Hsiao 
199049359d6SJames Hsiao #define CRYPTO4XX_GATHER_RING_BASE_OFFSET	0x64
200049359d6SJames Hsiao #define CRYPTO4XX_SCATTER_RING_BASE_OFFSET	0x68
201049359d6SJames Hsiao 
202049359d6SJames Hsiao union ce_part_ring_size  {
203049359d6SJames Hsiao 	struct {
204049359d6SJames Hsiao 		u32 sdr_size:16;
205049359d6SJames Hsiao 		u32 gdr_size:16;
206049359d6SJames Hsiao 	} bf;
207049359d6SJames Hsiao     u32 w;
208049359d6SJames Hsiao } __attribute__((packed));
209049359d6SJames Hsiao 
210049359d6SJames Hsiao #define MAX_BURST_SIZE_32			0
211049359d6SJames Hsiao #define MAX_BURST_SIZE_64			1
212049359d6SJames Hsiao #define MAX_BURST_SIZE_128			2
213049359d6SJames Hsiao #define MAX_BURST_SIZE_256			3
214049359d6SJames Hsiao 
215049359d6SJames Hsiao /* gather descriptor control length */
216049359d6SJames Hsiao struct gd_ctl_len {
217049359d6SJames Hsiao 	u32 len:16;
218049359d6SJames Hsiao 	u32 rsv:14;
219049359d6SJames Hsiao 	u32 done:1;
220049359d6SJames Hsiao 	u32 ready:1;
221049359d6SJames Hsiao } __attribute__((packed));
222049359d6SJames Hsiao 
223049359d6SJames Hsiao struct ce_gd {
224049359d6SJames Hsiao 	u32 ptr;
225049359d6SJames Hsiao 	struct gd_ctl_len ctl_len;
226049359d6SJames Hsiao } __attribute__((packed));
227049359d6SJames Hsiao 
228049359d6SJames Hsiao struct sd_ctl {
229049359d6SJames Hsiao 	u32 ctl:30;
230049359d6SJames Hsiao 	u32 done:1;
231049359d6SJames Hsiao 	u32 rdy:1;
232049359d6SJames Hsiao } __attribute__((packed));
233049359d6SJames Hsiao 
234049359d6SJames Hsiao struct ce_sd {
235049359d6SJames Hsiao     u32 ptr;
236049359d6SJames Hsiao 	struct sd_ctl ctl;
237049359d6SJames Hsiao } __attribute__((packed));
238049359d6SJames Hsiao 
239049359d6SJames Hsiao #define PD_PAD_CTL_32	0x10
240049359d6SJames Hsiao #define PD_PAD_CTL_64	0x20
241049359d6SJames Hsiao #define PD_PAD_CTL_128	0x40
242049359d6SJames Hsiao #define PD_PAD_CTL_256	0x80
243049359d6SJames Hsiao union ce_pd_ctl {
244049359d6SJames Hsiao 	struct {
245049359d6SJames Hsiao 		u32 pd_pad_ctl:8;
246049359d6SJames Hsiao 		u32 status:8;
247049359d6SJames Hsiao 		u32 next_hdr:8;
248049359d6SJames Hsiao 		u32 rsv:2;
249049359d6SJames Hsiao 		u32 cached_sa:1;
250049359d6SJames Hsiao 		u32 hash_final:1;
251049359d6SJames Hsiao 		u32 init_arc4:1;
252049359d6SJames Hsiao 		u32 rsv1:1;
253049359d6SJames Hsiao 		u32 pe_done:1;
254049359d6SJames Hsiao 		u32 host_ready:1;
255049359d6SJames Hsiao 	} bf;
256049359d6SJames Hsiao 	u32 w;
257049359d6SJames Hsiao } __attribute__((packed));
2584b5b7999SChristian Lamparter #define PD_CTL_HASH_FINAL	BIT(4)
2594b5b7999SChristian Lamparter #define PD_CTL_PE_DONE		BIT(1)
2604b5b7999SChristian Lamparter #define PD_CTL_HOST_READY	BIT(0)
261049359d6SJames Hsiao 
262049359d6SJames Hsiao union ce_pd_ctl_len {
263049359d6SJames Hsiao 	struct {
264049359d6SJames Hsiao 		u32 bypass:8;
265049359d6SJames Hsiao 		u32 pe_done:1;
266049359d6SJames Hsiao 		u32 host_ready:1;
267049359d6SJames Hsiao 		u32 rsv:2;
268049359d6SJames Hsiao 		u32 pkt_len:20;
269049359d6SJames Hsiao 	} bf;
270049359d6SJames Hsiao 	u32 w;
271049359d6SJames Hsiao } __attribute__((packed));
272049359d6SJames Hsiao 
273049359d6SJames Hsiao struct ce_pd {
274049359d6SJames Hsiao 	union ce_pd_ctl   pd_ctl;
275049359d6SJames Hsiao 	u32 src;
276049359d6SJames Hsiao 	u32 dest;
277049359d6SJames Hsiao 	u32 sa;                 /* get from ctx->sa_dma_addr */
278049359d6SJames Hsiao 	u32 sa_len;             /* only if dynamic sa is used */
279049359d6SJames Hsiao 	union ce_pd_ctl_len pd_ctl_len;
280049359d6SJames Hsiao 
281049359d6SJames Hsiao } __attribute__((packed));
282049359d6SJames Hsiao #endif
283