regs.h 29 KB

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