regs.h 29 KB

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