blob: 3a2a788dadba7421817e927a5e8ec50e50c7b475 [file] [log] [blame]
Kim Phillips8e8ec592011-03-13 16:54:26 +08001/*
2 * CAAM hardware register-level view
3 *
4 * Copyright 2008-2011 Freescale Semiconductor, Inc.
5 */
6
7#ifndef REGS_H
8#define REGS_H
9
10#include <linux/types.h>
11#include <linux/io.h>
12
13/*
14 * Architecture-specific register access methods
15 *
16 * CAAM's bus-addressable registers are 64 bits internally.
17 * They have been wired to be safely accessible on 32-bit
18 * architectures, however. Registers were organized such
19 * that (a) they can be contained in 32 bits, (b) if not, then they
20 * can be treated as two 32-bit entities, or finally (c) if they
21 * must be treated as a single 64-bit value, then this can safely
22 * be done with two 32-bit cycles.
23 *
24 * For 32-bit operations on 64-bit values, CAAM follows the same
25 * 64-bit register access conventions as it's predecessors, in that
26 * writes are "triggered" by a write to the register at the numerically
27 * higher address, thus, a full 64-bit write cycle requires a write
28 * to the lower address, followed by a write to the higher address,
29 * which will latch/execute the write cycle.
30 *
31 * For example, let's assume a SW reset of CAAM through the master
32 * configuration register.
33 * - SWRST is in bit 31 of MCFG.
34 * - MCFG begins at base+0x0000.
35 * - Bits 63-32 are a 32-bit word at base+0x0000 (numerically-lower)
36 * - Bits 31-0 are a 32-bit word at base+0x0004 (numerically-higher)
37 *
38 * (and on Power, the convention is 0-31, 32-63, I know...)
39 *
40 * Assuming a 64-bit write to this MCFG to perform a software reset
41 * would then require a write of 0 to base+0x0000, followed by a
42 * write of 0x80000000 to base+0x0004, which would "execute" the
43 * reset.
44 *
45 * Of course, since MCFG 63-32 is all zero, we could cheat and simply
46 * write 0x8000000 to base+0x0004, and the reset would work fine.
47 * However, since CAAM does contain some write-and-read-intended
48 * 64-bit registers, this code defines 64-bit access methods for
49 * the sake of internal consistency and simplicity, and so that a
50 * clean transition to 64-bit is possible when it becomes necessary.
51 *
52 * There are limitations to this that the developer must recognize.
53 * 32-bit architectures cannot enforce an atomic-64 operation,
54 * Therefore:
55 *
56 * - On writes, since the HW is assumed to latch the cycle on the
57 * write of the higher-numeric-address word, then ordered
58 * writes work OK.
59 *
60 * - For reads, where a register contains a relevant value of more
61 * that 32 bits, the hardware employs logic to latch the other
62 * "half" of the data until read, ensuring an accurate value.
63 * This is of particular relevance when dealing with CAAM's
64 * performance counters.
65 *
66 */
67
Victoria Milhoan509da8f2015-08-05 11:28:36 -070068#ifdef CONFIG_ARM
69/* These are common macros for Power, put here for ARM */
70#define setbits32(_addr, _v) writel((readl(_addr) | (_v)), (_addr))
71#define clrbits32(_addr, _v) writel((readl(_addr) & ~(_v)), (_addr))
72
73#define out_arch(type, endian, a, v) __raw_write##type(cpu_to_##endian(v), a)
74#define in_arch(type, endian, a) endian##_to_cpu(__raw_read##type(a))
75
76#define out_le32(a, v) out_arch(l, le32, a, v)
77#define in_le32(a) in_arch(l, le32, a)
78
79#define out_be32(a, v) out_arch(l, be32, a, v)
80#define in_be32(a) in_arch(l, be32, a)
81
82#define clrsetbits(type, addr, clear, set) \
83 out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
84
85#define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
86#define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
87#endif
88
Kim Phillips8e8ec592011-03-13 16:54:26 +080089#ifdef __BIG_ENDIAN
90#define wr_reg32(reg, data) out_be32(reg, data)
91#define rd_reg32(reg) in_be32(reg)
Victoria Milhoan509da8f2015-08-05 11:28:36 -070092#define clrsetbits_32(addr, clear, set) clrsetbits_be32(addr, clear, set)
Kim Phillips8e8ec592011-03-13 16:54:26 +080093#ifdef CONFIG_64BIT
94#define wr_reg64(reg, data) out_be64(reg, data)
95#define rd_reg64(reg) in_be64(reg)
96#endif
97#else
98#ifdef __LITTLE_ENDIAN
Dan Carpenterf829e7a2014-02-21 11:51:31 +030099#define wr_reg32(reg, data) __raw_writel(data, reg)
Kim Phillips8e8ec592011-03-13 16:54:26 +0800100#define rd_reg32(reg) __raw_readl(reg)
Victoria Milhoan509da8f2015-08-05 11:28:36 -0700101#define clrsetbits_32(addr, clear, set) clrsetbits_le32(addr, clear, set)
Kim Phillips8e8ec592011-03-13 16:54:26 +0800102#ifdef CONFIG_64BIT
Dan Carpenterf829e7a2014-02-21 11:51:31 +0300103#define wr_reg64(reg, data) __raw_writeq(data, reg)
Kim Phillips8e8ec592011-03-13 16:54:26 +0800104#define rd_reg64(reg) __raw_readq(reg)
105#endif
106#endif
107#endif
108
Steffen Trumtrarf657f822015-06-16 12:59:07 +0200109/*
110 * The only users of these wr/rd_reg64 functions is the Job Ring (JR).
111 * The DMA address registers in the JR are a pair of 32-bit registers.
112 * The layout is:
113 *
114 * base + 0x0000 : most-significant 32 bits
115 * base + 0x0004 : least-significant 32 bits
116 *
117 * The 32-bit version of this core therefore has to write to base + 0x0004
118 * to set the 32-bit wide DMA address. This seems to be independent of the
119 * endianness of the written/read data.
120 */
121
Kim Phillips8e8ec592011-03-13 16:54:26 +0800122#ifndef CONFIG_64BIT
Steffen Trumtrarf657f822015-06-16 12:59:07 +0200123#define REG64_MS32(reg) ((u32 __iomem *)(reg))
124#define REG64_LS32(reg) ((u32 __iomem *)(reg) + 1)
125
Kim Phillips8e8ec592011-03-13 16:54:26 +0800126static inline void wr_reg64(u64 __iomem *reg, u64 data)
127{
Steffen Trumtrarf657f822015-06-16 12:59:07 +0200128 wr_reg32(REG64_MS32(reg), data >> 32);
129 wr_reg32(REG64_LS32(reg), data);
Kim Phillips8e8ec592011-03-13 16:54:26 +0800130}
131
132static inline u64 rd_reg64(u64 __iomem *reg)
133{
Steffen Trumtrarf657f822015-06-16 12:59:07 +0200134 return ((u64)rd_reg32(REG64_MS32(reg)) << 32 |
135 (u64)rd_reg32(REG64_LS32(reg)));
Kim Phillips8e8ec592011-03-13 16:54:26 +0800136}
137#endif
138
139/*
140 * jr_outentry
141 * Represents each entry in a JobR output ring
142 */
143struct jr_outentry {
144 dma_addr_t desc;/* Pointer to completed descriptor */
145 u32 jrstatus; /* Status for completed descriptor */
146} __packed;
147
148/*
149 * caam_perfmon - Performance Monitor/Secure Memory Status/
150 * CAAM Global Status/Component Version IDs
151 *
152 * Spans f00-fff wherever instantiated
153 */
154
155/* Number of DECOs */
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530156#define CHA_NUM_MS_DECONUM_SHIFT 24
157#define CHA_NUM_MS_DECONUM_MASK (0xfull << CHA_NUM_MS_DECONUM_SHIFT)
Kim Phillips8e8ec592011-03-13 16:54:26 +0800158
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530159/* CHA Version IDs */
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530160#define CHA_ID_LS_AES_SHIFT 0
161#define CHA_ID_LS_AES_MASK (0xfull << CHA_ID_LS_AES_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530162
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530163#define CHA_ID_LS_DES_SHIFT 4
164#define CHA_ID_LS_DES_MASK (0xfull << CHA_ID_LS_DES_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530165
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530166#define CHA_ID_LS_ARC4_SHIFT 8
167#define CHA_ID_LS_ARC4_MASK (0xfull << CHA_ID_LS_ARC4_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530168
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530169#define CHA_ID_LS_MD_SHIFT 12
170#define CHA_ID_LS_MD_MASK (0xfull << CHA_ID_LS_MD_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530171
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530172#define CHA_ID_LS_RNG_SHIFT 16
173#define CHA_ID_LS_RNG_MASK (0xfull << CHA_ID_LS_RNG_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530174
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530175#define CHA_ID_LS_SNW8_SHIFT 20
176#define CHA_ID_LS_SNW8_MASK (0xfull << CHA_ID_LS_SNW8_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530177
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530178#define CHA_ID_LS_KAS_SHIFT 24
179#define CHA_ID_LS_KAS_MASK (0xfull << CHA_ID_LS_KAS_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530180
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530181#define CHA_ID_LS_PK_SHIFT 28
182#define CHA_ID_LS_PK_MASK (0xfull << CHA_ID_LS_PK_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530183
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530184#define CHA_ID_MS_CRC_SHIFT 0
185#define CHA_ID_MS_CRC_MASK (0xfull << CHA_ID_MS_CRC_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530186
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530187#define CHA_ID_MS_SNW9_SHIFT 4
188#define CHA_ID_MS_SNW9_MASK (0xfull << CHA_ID_MS_SNW9_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530189
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530190#define CHA_ID_MS_DECO_SHIFT 24
191#define CHA_ID_MS_DECO_MASK (0xfull << CHA_ID_MS_DECO_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530192
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530193#define CHA_ID_MS_JR_SHIFT 28
194#define CHA_ID_MS_JR_MASK (0xfull << CHA_ID_MS_JR_SHIFT)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530195
Alex Porosanu82c2f962012-07-11 11:06:11 +0800196struct sec_vid {
197 u16 ip_id;
198 u8 maj_rev;
199 u8 min_rev;
200};
201
Kim Phillips8e8ec592011-03-13 16:54:26 +0800202struct caam_perfmon {
203 /* Performance Monitor Registers f00-f9f */
204 u64 req_dequeued; /* PC_REQ_DEQ - Dequeued Requests */
205 u64 ob_enc_req; /* PC_OB_ENC_REQ - Outbound Encrypt Requests */
206 u64 ib_dec_req; /* PC_IB_DEC_REQ - Inbound Decrypt Requests */
207 u64 ob_enc_bytes; /* PC_OB_ENCRYPT - Outbound Bytes Encrypted */
208 u64 ob_prot_bytes; /* PC_OB_PROTECT - Outbound Bytes Protected */
209 u64 ib_dec_bytes; /* PC_IB_DECRYPT - Inbound Bytes Decrypted */
210 u64 ib_valid_bytes; /* PC_IB_VALIDATED Inbound Bytes Validated */
211 u64 rsvd[13];
212
213 /* CAAM Hardware Instantiation Parameters fa0-fbf */
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530214 u32 cha_rev_ms; /* CRNR - CHA Rev No. Most significant half*/
215 u32 cha_rev_ls; /* CRNR - CHA Rev No. Least significant half*/
216#define CTPR_MS_QI_SHIFT 25
217#define CTPR_MS_QI_MASK (0x1ull << CTPR_MS_QI_SHIFT)
Ruchika Gupta17157c92014-06-23 17:42:33 +0530218#define CTPR_MS_VIRT_EN_INCL 0x00000001
219#define CTPR_MS_VIRT_EN_POR 0x00000002
Nitesh Narayan Lalfb4562b2014-09-01 15:00:44 +0530220#define CTPR_MS_PG_SZ_MASK 0x10
221#define CTPR_MS_PG_SZ_SHIFT 4
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530222 u32 comp_parms_ms; /* CTPR - Compile Parameters Register */
223 u32 comp_parms_ls; /* CTPR - Compile Parameters Register */
Kim Phillips8e8ec592011-03-13 16:54:26 +0800224 u64 rsvd1[2];
225
226 /* CAAM Global Status fc0-fdf */
227 u64 faultaddr; /* FAR - Fault Address */
228 u32 faultliodn; /* FALR - Fault Address LIODN */
229 u32 faultdetail; /* FADR - Fault Addr Detail */
230 u32 rsvd2;
231 u32 status; /* CSTA - CAAM Status */
232 u64 rsvd3;
233
234 /* Component Instantiation Parameters fe0-fff */
235 u32 rtic_id; /* RVID - RTIC Version ID */
236 u32 ccb_id; /* CCBVID - CCB Version ID */
Ruchika Guptaeb1139c2014-06-23 15:08:28 +0530237 u32 cha_id_ms; /* CHAVID - CHA Version ID Most Significant*/
238 u32 cha_id_ls; /* CHAVID - CHA Version ID Least Significant*/
239 u32 cha_num_ms; /* CHANUM - CHA Number Most Significant */
240 u32 cha_num_ls; /* CHANUM - CHA Number Least Significant*/
241 u32 caam_id_ms; /* CAAMVID - CAAM Version ID MS */
242 u32 caam_id_ls; /* CAAMVID - CAAM Version ID LS */
Kim Phillips8e8ec592011-03-13 16:54:26 +0800243};
244
245/* LIODN programming for DMA configuration */
246#define MSTRID_LOCK_LIODN 0x80000000
247#define MSTRID_LOCK_MAKETRUSTED 0x00010000 /* only for JR masterid */
248
249#define MSTRID_LIODN_MASK 0x0fff
250struct masterid {
251 u32 liodn_ms; /* lock and make-trusted control bits */
252 u32 liodn_ls; /* LIODN for non-sequence and seq access */
253};
254
255/* Partition ID for DMA configuration */
256struct partid {
257 u32 rsvd1;
258 u32 pidr; /* partition ID, DECO */
259};
260
Kim Phillips281922a2012-06-22 19:48:52 -0500261/* RNGB test mode (replicated twice in some configurations) */
Kim Phillips8e8ec592011-03-13 16:54:26 +0800262/* Padded out to 0x100 */
263struct rngtst {
264 u32 mode; /* RTSTMODEx - Test mode */
265 u32 rsvd1[3];
266 u32 reset; /* RTSTRESETx - Test reset control */
267 u32 rsvd2[3];
268 u32 status; /* RTSTSSTATUSx - Test status */
269 u32 rsvd3;
270 u32 errstat; /* RTSTERRSTATx - Test error status */
271 u32 rsvd4;
272 u32 errctl; /* RTSTERRCTLx - Test error control */
273 u32 rsvd5;
274 u32 entropy; /* RTSTENTROPYx - Test entropy */
275 u32 rsvd6[15];
276 u32 verifctl; /* RTSTVERIFCTLx - Test verification control */
277 u32 rsvd7;
278 u32 verifstat; /* RTSTVERIFSTATx - Test verification status */
279 u32 rsvd8;
280 u32 verifdata; /* RTSTVERIFDx - Test verification data */
281 u32 rsvd9;
282 u32 xkey; /* RTSTXKEYx - Test XKEY */
283 u32 rsvd10;
284 u32 oscctctl; /* RTSTOSCCTCTLx - Test osc. counter control */
285 u32 rsvd11;
286 u32 oscct; /* RTSTOSCCTx - Test oscillator counter */
287 u32 rsvd12;
288 u32 oscctstat; /* RTSTODCCTSTATx - Test osc counter status */
289 u32 rsvd13[2];
290 u32 ofifo[4]; /* RTSTOFIFOx - Test output FIFO */
291 u32 rsvd14[15];
292};
293
Kim Phillips281922a2012-06-22 19:48:52 -0500294/* RNG4 TRNG test registers */
295struct rng4tst {
Alex Porosanu1005bcc2013-09-09 18:56:34 +0300296#define RTMCTL_PRGM 0x00010000 /* 1 -> program mode, 0 -> run mode */
Alex Porosanue5ffbfc2014-08-11 11:40:17 +0300297#define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_SC 0 /* use von Neumann data in
298 both entropy shifter and
299 statistical checker */
300#define RTMCTL_SAMP_MODE_RAW_ES_SC 1 /* use raw data in both
301 entropy shifter and
302 statistical checker */
303#define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_RAW_SC 2 /* use von Neumann data in
304 entropy shifter, raw data
305 in statistical checker */
306#define RTMCTL_SAMP_MODE_INVALID 3 /* invalid combination */
Kim Phillips281922a2012-06-22 19:48:52 -0500307 u32 rtmctl; /* misc. control register */
308 u32 rtscmisc; /* statistical check misc. register */
309 u32 rtpkrrng; /* poker range register */
310 union {
311 u32 rtpkrmax; /* PRGM=1: poker max. limit register */
312 u32 rtpkrsq; /* PRGM=0: poker square calc. result register */
313 };
314#define RTSDCTL_ENT_DLY_SHIFT 16
315#define RTSDCTL_ENT_DLY_MASK (0xffff << RTSDCTL_ENT_DLY_SHIFT)
Alex Porosanueeaa1722014-08-11 11:40:16 +0300316#define RTSDCTL_ENT_DLY_MIN 3200
Alex Porosanu84cf4822013-09-09 18:56:30 +0300317#define RTSDCTL_ENT_DLY_MAX 12800
Kim Phillips281922a2012-06-22 19:48:52 -0500318 u32 rtsdctl; /* seed control register */
319 union {
320 u32 rtsblim; /* PRGM=1: sparse bit limit register */
321 u32 rttotsam; /* PRGM=0: total samples register */
322 };
323 u32 rtfrqmin; /* frequency count min. limit register */
Alex Porosanub061f3f2014-08-11 11:40:15 +0300324#define RTFRQMAX_DISABLE (1 << 20)
Kim Phillips281922a2012-06-22 19:48:52 -0500325 union {
326 u32 rtfrqmax; /* PRGM=1: freq. count max. limit register */
327 u32 rtfrqcnt; /* PRGM=0: freq. count register */
328 };
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530329 u32 rsvd1[40];
Alex Porosanu1005bcc2013-09-09 18:56:34 +0300330#define RDSTA_SKVT 0x80000000
331#define RDSTA_SKVN 0x40000000
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530332#define RDSTA_IF0 0x00000001
Alex Porosanu1005bcc2013-09-09 18:56:34 +0300333#define RDSTA_IF1 0x00000002
334#define RDSTA_IFMASK (RDSTA_IF1 | RDSTA_IF0)
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530335 u32 rdsta;
336 u32 rsvd2[15];
Kim Phillips281922a2012-06-22 19:48:52 -0500337};
338
Kim Phillips8e8ec592011-03-13 16:54:26 +0800339/*
340 * caam_ctrl - basic core configuration
341 * starts base + 0x0000 padded out to 0x1000
342 */
343
344#define KEK_KEY_SIZE 8
345#define TKEK_KEY_SIZE 8
346#define TDSK_KEY_SIZE 8
347
348#define DECO_RESET 1 /* Use with DECO reset/availability regs */
349#define DECO_RESET_0 (DECO_RESET << 0)
350#define DECO_RESET_1 (DECO_RESET << 1)
351#define DECO_RESET_2 (DECO_RESET << 2)
352#define DECO_RESET_3 (DECO_RESET << 3)
353#define DECO_RESET_4 (DECO_RESET << 4)
354
355struct caam_ctrl {
356 /* Basic Configuration Section 000-01f */
357 /* Read/Writable */
358 u32 rsvd1;
359 u32 mcr; /* MCFG Master Config Register */
Vakul Garg575c1bd2013-03-12 13:55:21 +0530360 u32 rsvd2;
361 u32 scfgr; /* SCFGR, Security Config Register */
Kim Phillips8e8ec592011-03-13 16:54:26 +0800362
363 /* Bus Access Configuration Section 010-11f */
364 /* Read/Writable */
365 struct masterid jr_mid[4]; /* JRxLIODNR - JobR LIODN setup */
Ruchika Gupta17157c92014-06-23 17:42:33 +0530366 u32 rsvd3[11];
367 u32 jrstart; /* JRSTART - Job Ring Start Register */
Kim Phillips8e8ec592011-03-13 16:54:26 +0800368 struct masterid rtic_mid[4]; /* RTICxLIODNR - RTIC LIODN setup */
Ruchika Gupta17157c92014-06-23 17:42:33 +0530369 u32 rsvd4[5];
370 u32 deco_rsr; /* DECORSR - Deco Request Source */
371 u32 rsvd11;
Kim Phillips8e8ec592011-03-13 16:54:26 +0800372 u32 deco_rq; /* DECORR - DECO Request */
373 struct partid deco_mid[5]; /* DECOxLIODNR - 1 per DECO */
374 u32 rsvd5[22];
375
376 /* DECO Availability/Reset Section 120-3ff */
377 u32 deco_avail; /* DAR - DECO availability */
378 u32 deco_reset; /* DRR - DECO reset */
379 u32 rsvd6[182];
380
381 /* Key Encryption/Decryption Configuration 400-5ff */
382 /* Read/Writable only while in Non-secure mode */
383 u32 kek[KEK_KEY_SIZE]; /* JDKEKR - Key Encryption Key */
384 u32 tkek[TKEK_KEY_SIZE]; /* TDKEKR - Trusted Desc KEK */
385 u32 tdsk[TDSK_KEY_SIZE]; /* TDSKR - Trusted Desc Signing Key */
386 u32 rsvd7[32];
387 u64 sknonce; /* SKNR - Secure Key Nonce */
388 u32 rsvd8[70];
389
390 /* RNG Test/Verification/Debug Access 600-7ff */
391 /* (Useful in Test/Debug modes only...) */
Kim Phillips281922a2012-06-22 19:48:52 -0500392 union {
393 struct rngtst rtst[2];
394 struct rng4tst r4tst[2];
395 };
Kim Phillips8e8ec592011-03-13 16:54:26 +0800396
397 u32 rsvd9[448];
398
399 /* Performance Monitor f00-fff */
400 struct caam_perfmon perfmon;
401};
402
403/*
404 * Controller master config register defs
405 */
406#define MCFGR_SWRESET 0x80000000 /* software reset */
407#define MCFGR_WDENABLE 0x40000000 /* DECO watchdog enable */
408#define MCFGR_WDFAIL 0x20000000 /* DECO watchdog force-fail */
409#define MCFGR_DMA_RESET 0x10000000
410#define MCFGR_LONG_PTR 0x00010000 /* Use >32-bit desc addressing */
Vakul Garg575c1bd2013-03-12 13:55:21 +0530411#define SCFGR_RDBENABLE 0x00000400
Ruchika Gupta17157c92014-06-23 17:42:33 +0530412#define SCFGR_VIRT_EN 0x00008000
Ruchika Gupta997ad292013-07-04 11:26:03 +0530413#define DECORR_RQD0ENABLE 0x00000001 /* Enable DECO0 for direct access */
Ruchika Gupta17157c92014-06-23 17:42:33 +0530414#define DECORSR_JR0 0x00000001 /* JR to supply TZ, SDID, ICID */
415#define DECORSR_VALID 0x80000000
Ruchika Gupta997ad292013-07-04 11:26:03 +0530416#define DECORR_DEN0 0x00010000 /* DECO0 available for access*/
Kim Phillips8e8ec592011-03-13 16:54:26 +0800417
418/* AXI read cache control */
419#define MCFGR_ARCACHE_SHIFT 12
420#define MCFGR_ARCACHE_MASK (0xf << MCFGR_ARCACHE_SHIFT)
Horia Geant?f1096742015-07-17 16:54:52 +0300421#define MCFGR_ARCACHE_BUFF (0x1 << MCFGR_ARCACHE_SHIFT)
422#define MCFGR_ARCACHE_CACH (0x2 << MCFGR_ARCACHE_SHIFT)
423#define MCFGR_ARCACHE_RALL (0x4 << MCFGR_ARCACHE_SHIFT)
Kim Phillips8e8ec592011-03-13 16:54:26 +0800424
425/* AXI write cache control */
426#define MCFGR_AWCACHE_SHIFT 8
427#define MCFGR_AWCACHE_MASK (0xf << MCFGR_AWCACHE_SHIFT)
Horia Geant?f1096742015-07-17 16:54:52 +0300428#define MCFGR_AWCACHE_BUFF (0x1 << MCFGR_AWCACHE_SHIFT)
429#define MCFGR_AWCACHE_CACH (0x2 << MCFGR_AWCACHE_SHIFT)
430#define MCFGR_AWCACHE_WALL (0x8 << MCFGR_AWCACHE_SHIFT)
Kim Phillips8e8ec592011-03-13 16:54:26 +0800431
432/* AXI pipeline depth */
433#define MCFGR_AXIPIPE_SHIFT 4
434#define MCFGR_AXIPIPE_MASK (0xf << MCFGR_AXIPIPE_SHIFT)
435
436#define MCFGR_AXIPRI 0x00000008 /* Assert AXI priority sideband */
437#define MCFGR_BURST_64 0x00000001 /* Max burst size */
438
Ruchika Gupta17157c92014-06-23 17:42:33 +0530439/* JRSTART register offsets */
440#define JRSTART_JR0_START 0x00000001 /* Start Job ring 0 */
441#define JRSTART_JR1_START 0x00000002 /* Start Job ring 1 */
442#define JRSTART_JR2_START 0x00000004 /* Start Job ring 2 */
443#define JRSTART_JR3_START 0x00000008 /* Start Job ring 3 */
444
Kim Phillips8e8ec592011-03-13 16:54:26 +0800445/*
446 * caam_job_ring - direct job ring setup
447 * 1-4 possible per instantiation, base + 1000/2000/3000/4000
448 * Padded out to 0x1000
449 */
450struct caam_job_ring {
451 /* Input ring */
452 u64 inpring_base; /* IRBAx - Input desc ring baseaddr */
453 u32 rsvd1;
454 u32 inpring_size; /* IRSx - Input ring size */
455 u32 rsvd2;
456 u32 inpring_avail; /* IRSAx - Input ring room remaining */
457 u32 rsvd3;
458 u32 inpring_jobadd; /* IRJAx - Input ring jobs added */
459
460 /* Output Ring */
461 u64 outring_base; /* ORBAx - Output status ring base addr */
462 u32 rsvd4;
463 u32 outring_size; /* ORSx - Output ring size */
464 u32 rsvd5;
465 u32 outring_rmvd; /* ORJRx - Output ring jobs removed */
466 u32 rsvd6;
467 u32 outring_used; /* ORSFx - Output ring slots full */
468
469 /* Status/Configuration */
470 u32 rsvd7;
471 u32 jroutstatus; /* JRSTAx - JobR output status */
472 u32 rsvd8;
473 u32 jrintstatus; /* JRINTx - JobR interrupt status */
474 u32 rconfig_hi; /* JRxCFG - Ring configuration */
475 u32 rconfig_lo;
476
477 /* Indices. CAAM maintains as "heads" of each queue */
478 u32 rsvd9;
479 u32 inp_rdidx; /* IRRIx - Input ring read index */
480 u32 rsvd10;
481 u32 out_wtidx; /* ORWIx - Output ring write index */
482
483 /* Command/control */
484 u32 rsvd11;
485 u32 jrcommand; /* JRCRx - JobR command */
486
487 u32 rsvd12[932];
488
489 /* Performance Monitor f00-fff */
490 struct caam_perfmon perfmon;
491};
492
493#define JR_RINGSIZE_MASK 0x03ff
494/*
495 * jrstatus - Job Ring Output Status
496 * All values in lo word
497 * Also note, same values written out as status through QI
498 * in the command/status field of a frame descriptor
499 */
500#define JRSTA_SSRC_SHIFT 28
501#define JRSTA_SSRC_MASK 0xf0000000
502
503#define JRSTA_SSRC_NONE 0x00000000
504#define JRSTA_SSRC_CCB_ERROR 0x20000000
505#define JRSTA_SSRC_JUMP_HALT_USER 0x30000000
506#define JRSTA_SSRC_DECO 0x40000000
507#define JRSTA_SSRC_JRERROR 0x60000000
508#define JRSTA_SSRC_JUMP_HALT_CC 0x70000000
509
510#define JRSTA_DECOERR_JUMP 0x08000000
511#define JRSTA_DECOERR_INDEX_SHIFT 8
512#define JRSTA_DECOERR_INDEX_MASK 0xff00
513#define JRSTA_DECOERR_ERROR_MASK 0x00ff
514
515#define JRSTA_DECOERR_NONE 0x00
516#define JRSTA_DECOERR_LINKLEN 0x01
517#define JRSTA_DECOERR_LINKPTR 0x02
518#define JRSTA_DECOERR_JRCTRL 0x03
519#define JRSTA_DECOERR_DESCCMD 0x04
520#define JRSTA_DECOERR_ORDER 0x05
521#define JRSTA_DECOERR_KEYCMD 0x06
522#define JRSTA_DECOERR_LOADCMD 0x07
523#define JRSTA_DECOERR_STORECMD 0x08
524#define JRSTA_DECOERR_OPCMD 0x09
525#define JRSTA_DECOERR_FIFOLDCMD 0x0a
526#define JRSTA_DECOERR_FIFOSTCMD 0x0b
527#define JRSTA_DECOERR_MOVECMD 0x0c
528#define JRSTA_DECOERR_JUMPCMD 0x0d
529#define JRSTA_DECOERR_MATHCMD 0x0e
530#define JRSTA_DECOERR_SHASHCMD 0x0f
531#define JRSTA_DECOERR_SEQCMD 0x10
532#define JRSTA_DECOERR_DECOINTERNAL 0x11
533#define JRSTA_DECOERR_SHDESCHDR 0x12
534#define JRSTA_DECOERR_HDRLEN 0x13
535#define JRSTA_DECOERR_BURSTER 0x14
536#define JRSTA_DECOERR_DESCSIGNATURE 0x15
537#define JRSTA_DECOERR_DMA 0x16
538#define JRSTA_DECOERR_BURSTFIFO 0x17
539#define JRSTA_DECOERR_JRRESET 0x1a
540#define JRSTA_DECOERR_JOBFAIL 0x1b
541#define JRSTA_DECOERR_DNRERR 0x80
542#define JRSTA_DECOERR_UNDEFPCL 0x81
543#define JRSTA_DECOERR_PDBERR 0x82
544#define JRSTA_DECOERR_ANRPLY_LATE 0x83
545#define JRSTA_DECOERR_ANRPLY_REPLAY 0x84
546#define JRSTA_DECOERR_SEQOVF 0x85
547#define JRSTA_DECOERR_INVSIGN 0x86
548#define JRSTA_DECOERR_DSASIGN 0x87
549
550#define JRSTA_CCBERR_JUMP 0x08000000
551#define JRSTA_CCBERR_INDEX_MASK 0xff00
552#define JRSTA_CCBERR_INDEX_SHIFT 8
553#define JRSTA_CCBERR_CHAID_MASK 0x00f0
554#define JRSTA_CCBERR_CHAID_SHIFT 4
555#define JRSTA_CCBERR_ERRID_MASK 0x000f
556
557#define JRSTA_CCBERR_CHAID_AES (0x01 << JRSTA_CCBERR_CHAID_SHIFT)
558#define JRSTA_CCBERR_CHAID_DES (0x02 << JRSTA_CCBERR_CHAID_SHIFT)
559#define JRSTA_CCBERR_CHAID_ARC4 (0x03 << JRSTA_CCBERR_CHAID_SHIFT)
560#define JRSTA_CCBERR_CHAID_MD (0x04 << JRSTA_CCBERR_CHAID_SHIFT)
561#define JRSTA_CCBERR_CHAID_RNG (0x05 << JRSTA_CCBERR_CHAID_SHIFT)
562#define JRSTA_CCBERR_CHAID_SNOW (0x06 << JRSTA_CCBERR_CHAID_SHIFT)
563#define JRSTA_CCBERR_CHAID_KASUMI (0x07 << JRSTA_CCBERR_CHAID_SHIFT)
564#define JRSTA_CCBERR_CHAID_PK (0x08 << JRSTA_CCBERR_CHAID_SHIFT)
565#define JRSTA_CCBERR_CHAID_CRC (0x09 << JRSTA_CCBERR_CHAID_SHIFT)
566
567#define JRSTA_CCBERR_ERRID_NONE 0x00
568#define JRSTA_CCBERR_ERRID_MODE 0x01
569#define JRSTA_CCBERR_ERRID_DATASIZ 0x02
570#define JRSTA_CCBERR_ERRID_KEYSIZ 0x03
571#define JRSTA_CCBERR_ERRID_PKAMEMSZ 0x04
572#define JRSTA_CCBERR_ERRID_PKBMEMSZ 0x05
573#define JRSTA_CCBERR_ERRID_SEQUENCE 0x06
574#define JRSTA_CCBERR_ERRID_PKDIVZRO 0x07
575#define JRSTA_CCBERR_ERRID_PKMODEVN 0x08
576#define JRSTA_CCBERR_ERRID_KEYPARIT 0x09
577#define JRSTA_CCBERR_ERRID_ICVCHK 0x0a
578#define JRSTA_CCBERR_ERRID_HARDWARE 0x0b
579#define JRSTA_CCBERR_ERRID_CCMAAD 0x0c
580#define JRSTA_CCBERR_ERRID_INVCHA 0x0f
581
582#define JRINT_ERR_INDEX_MASK 0x3fff0000
583#define JRINT_ERR_INDEX_SHIFT 16
584#define JRINT_ERR_TYPE_MASK 0xf00
585#define JRINT_ERR_TYPE_SHIFT 8
586#define JRINT_ERR_HALT_MASK 0xc
587#define JRINT_ERR_HALT_SHIFT 2
588#define JRINT_ERR_HALT_INPROGRESS 0x4
589#define JRINT_ERR_HALT_COMPLETE 0x8
590#define JRINT_JR_ERROR 0x02
591#define JRINT_JR_INT 0x01
592
593#define JRINT_ERR_TYPE_WRITE 1
594#define JRINT_ERR_TYPE_BAD_INPADDR 3
595#define JRINT_ERR_TYPE_BAD_OUTADDR 4
596#define JRINT_ERR_TYPE_INV_INPWRT 5
597#define JRINT_ERR_TYPE_INV_OUTWRT 6
598#define JRINT_ERR_TYPE_RESET 7
599#define JRINT_ERR_TYPE_REMOVE_OFL 8
600#define JRINT_ERR_TYPE_ADD_OFL 9
601
602#define JRCFG_SOE 0x04
603#define JRCFG_ICEN 0x02
604#define JRCFG_IMSK 0x01
605#define JRCFG_ICDCT_SHIFT 8
606#define JRCFG_ICTT_SHIFT 16
607
608#define JRCR_RESET 0x01
609
610/*
611 * caam_assurance - Assurance Controller View
612 * base + 0x6000 padded out to 0x1000
613 */
614
615struct rtic_element {
616 u64 address;
617 u32 rsvd;
618 u32 length;
619};
620
621struct rtic_block {
622 struct rtic_element element[2];
623};
624
625struct rtic_memhash {
626 u32 memhash_be[32];
627 u32 memhash_le[32];
628};
629
630struct caam_assurance {
631 /* Status/Command/Watchdog */
632 u32 rsvd1;
633 u32 status; /* RSTA - Status */
634 u32 rsvd2;
635 u32 cmd; /* RCMD - Command */
636 u32 rsvd3;
637 u32 ctrl; /* RCTL - Control */
638 u32 rsvd4;
639 u32 throttle; /* RTHR - Throttle */
640 u32 rsvd5[2];
641 u64 watchdog; /* RWDOG - Watchdog Timer */
642 u32 rsvd6;
643 u32 rend; /* REND - Endian corrections */
644 u32 rsvd7[50];
645
646 /* Block access/configuration @ 100/110/120/130 */
647 struct rtic_block memblk[4]; /* Memory Blocks A-D */
648 u32 rsvd8[32];
649
650 /* Block hashes @ 200/300/400/500 */
651 struct rtic_memhash hash[4]; /* Block hash values A-D */
652 u32 rsvd_3[640];
653};
654
655/*
656 * caam_queue_if - QI configuration and control
657 * starts base + 0x7000, padded out to 0x1000 long
658 */
659
660struct caam_queue_if {
661 u32 qi_control_hi; /* QICTL - QI Control */
662 u32 qi_control_lo;
663 u32 rsvd1;
664 u32 qi_status; /* QISTA - QI Status */
665 u32 qi_deq_cfg_hi; /* QIDQC - QI Dequeue Configuration */
666 u32 qi_deq_cfg_lo;
667 u32 qi_enq_cfg_hi; /* QISEQC - QI Enqueue Command */
668 u32 qi_enq_cfg_lo;
669 u32 rsvd2[1016];
670};
671
672/* QI control bits - low word */
673#define QICTL_DQEN 0x01 /* Enable frame pop */
674#define QICTL_STOP 0x02 /* Stop dequeue/enqueue */
675#define QICTL_SOE 0x04 /* Stop on error */
676
677/* QI control bits - high word */
678#define QICTL_MBSI 0x01
679#define QICTL_MHWSI 0x02
680#define QICTL_MWSI 0x04
681#define QICTL_MDWSI 0x08
682#define QICTL_CBSI 0x10 /* CtrlDataByteSwapInput */
683#define QICTL_CHWSI 0x20 /* CtrlDataHalfSwapInput */
684#define QICTL_CWSI 0x40 /* CtrlDataWordSwapInput */
685#define QICTL_CDWSI 0x80 /* CtrlDataDWordSwapInput */
686#define QICTL_MBSO 0x0100
687#define QICTL_MHWSO 0x0200
688#define QICTL_MWSO 0x0400
689#define QICTL_MDWSO 0x0800
690#define QICTL_CBSO 0x1000 /* CtrlDataByteSwapOutput */
691#define QICTL_CHWSO 0x2000 /* CtrlDataHalfSwapOutput */
692#define QICTL_CWSO 0x4000 /* CtrlDataWordSwapOutput */
693#define QICTL_CDWSO 0x8000 /* CtrlDataDWordSwapOutput */
694#define QICTL_DMBS 0x010000
695#define QICTL_EPO 0x020000
696
697/* QI status bits */
698#define QISTA_PHRDERR 0x01 /* PreHeader Read Error */
699#define QISTA_CFRDERR 0x02 /* Compound Frame Read Error */
700#define QISTA_OFWRERR 0x04 /* Output Frame Read Error */
701#define QISTA_BPDERR 0x08 /* Buffer Pool Depleted */
702#define QISTA_BTSERR 0x10 /* Buffer Undersize */
703#define QISTA_CFWRERR 0x20 /* Compound Frame Write Err */
704#define QISTA_STOPD 0x80000000 /* QI Stopped (see QICTL) */
705
706/* deco_sg_table - DECO view of scatter/gather table */
707struct deco_sg_table {
708 u64 addr; /* Segment Address */
709 u32 elen; /* E, F bits + 30-bit length */
710 u32 bpid_offset; /* Buffer Pool ID + 16-bit length */
711};
712
713/*
714 * caam_deco - descriptor controller - CHA cluster block
715 *
716 * Only accessible when direct DECO access is turned on
717 * (done in DECORR, via MID programmed in DECOxMID
718 *
719 * 5 typical, base + 0x8000/9000/a000/b000
720 * Padded out to 0x1000 long
721 */
722struct caam_deco {
723 u32 rsvd1;
724 u32 cls1_mode; /* CxC1MR - Class 1 Mode */
725 u32 rsvd2;
726 u32 cls1_keysize; /* CxC1KSR - Class 1 Key Size */
727 u32 cls1_datasize_hi; /* CxC1DSR - Class 1 Data Size */
728 u32 cls1_datasize_lo;
729 u32 rsvd3;
730 u32 cls1_icvsize; /* CxC1ICVSR - Class 1 ICV size */
731 u32 rsvd4[5];
732 u32 cha_ctrl; /* CCTLR - CHA control */
733 u32 rsvd5;
734 u32 irq_crtl; /* CxCIRQ - CCB interrupt done/error/clear */
735 u32 rsvd6;
736 u32 clr_written; /* CxCWR - Clear-Written */
737 u32 ccb_status_hi; /* CxCSTA - CCB Status/Error */
738 u32 ccb_status_lo;
739 u32 rsvd7[3];
740 u32 aad_size; /* CxAADSZR - Current AAD Size */
741 u32 rsvd8;
742 u32 cls1_iv_size; /* CxC1IVSZR - Current Class 1 IV Size */
743 u32 rsvd9[7];
744 u32 pkha_a_size; /* PKASZRx - Size of PKHA A */
745 u32 rsvd10;
746 u32 pkha_b_size; /* PKBSZRx - Size of PKHA B */
747 u32 rsvd11;
748 u32 pkha_n_size; /* PKNSZRx - Size of PKHA N */
749 u32 rsvd12;
750 u32 pkha_e_size; /* PKESZRx - Size of PKHA E */
751 u32 rsvd13[24];
752 u32 cls1_ctx[16]; /* CxC1CTXR - Class 1 Context @100 */
753 u32 rsvd14[48];
754 u32 cls1_key[8]; /* CxC1KEYR - Class 1 Key @200 */
755 u32 rsvd15[121];
756 u32 cls2_mode; /* CxC2MR - Class 2 Mode */
757 u32 rsvd16;
758 u32 cls2_keysize; /* CxX2KSR - Class 2 Key Size */
759 u32 cls2_datasize_hi; /* CxC2DSR - Class 2 Data Size */
760 u32 cls2_datasize_lo;
761 u32 rsvd17;
762 u32 cls2_icvsize; /* CxC2ICVSZR - Class 2 ICV Size */
763 u32 rsvd18[56];
764 u32 cls2_ctx[18]; /* CxC2CTXR - Class 2 Context @500 */
765 u32 rsvd19[46];
766 u32 cls2_key[32]; /* CxC2KEYR - Class2 Key @600 */
767 u32 rsvd20[84];
768 u32 inp_infofifo_hi; /* CxIFIFO - Input Info FIFO @7d0 */
769 u32 inp_infofifo_lo;
770 u32 rsvd21[2];
771 u64 inp_datafifo; /* CxDFIFO - Input Data FIFO */
772 u32 rsvd22[2];
773 u64 out_datafifo; /* CxOFIFO - Output Data FIFO */
774 u32 rsvd23[2];
775 u32 jr_ctl_hi; /* CxJRR - JobR Control Register @800 */
776 u32 jr_ctl_lo;
777 u64 jr_descaddr; /* CxDADR - JobR Descriptor Address */
Alex Porosanu1005bcc2013-09-09 18:56:34 +0300778#define DECO_OP_STATUS_HI_ERR_MASK 0xF00000FF
Kim Phillips8e8ec592011-03-13 16:54:26 +0800779 u32 op_status_hi; /* DxOPSTA - DECO Operation Status */
780 u32 op_status_lo;
781 u32 rsvd24[2];
782 u32 liodn; /* DxLSR - DECO LIODN Status - non-seq */
783 u32 td_liodn; /* DxLSR - DECO LIODN Status - trustdesc */
784 u32 rsvd26[6];
785 u64 math[4]; /* DxMTH - Math register */
786 u32 rsvd27[8];
787 struct deco_sg_table gthr_tbl[4]; /* DxGTR - Gather Tables */
788 u32 rsvd28[16];
789 struct deco_sg_table sctr_tbl[4]; /* DxSTR - Scatter Tables */
790 u32 rsvd29[48];
791 u32 descbuf[64]; /* DxDESB - Descriptor buffer */
Ruchika Gupta997ad292013-07-04 11:26:03 +0530792 u32 rscvd30[193];
Alex Porosanu84cf4822013-09-09 18:56:30 +0300793#define DESC_DBG_DECO_STAT_HOST_ERR 0x00D00000
794#define DESC_DBG_DECO_STAT_VALID 0x80000000
795#define DESC_DBG_DECO_STAT_MASK 0x00F00000
Ruchika Gupta997ad292013-07-04 11:26:03 +0530796 u32 desc_dbg; /* DxDDR - DECO Debug Register */
797 u32 rsvd31[126];
Kim Phillips8e8ec592011-03-13 16:54:26 +0800798};
799
Ruchika Gupta997ad292013-07-04 11:26:03 +0530800#define DECO_JQCR_WHL 0x20000000
801#define DECO_JQCR_FOUR 0x10000000
802
Nitesh Narayan Lalfb4562b2014-09-01 15:00:44 +0530803#define JR_BLOCK_NUMBER 1
804#define ASSURE_BLOCK_NUMBER 6
805#define QI_BLOCK_NUMBER 7
806#define DECO_BLOCK_NUMBER 8
807#define PG_SIZE_4K 0x1000
808#define PG_SIZE_64K 0x10000
Kim Phillips8e8ec592011-03-13 16:54:26 +0800809#endif /* REGS_H */