regs.h 28 KB

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