ctrl.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /* * CAAM control-plane driver backend
  3. * Controller-level driver, kernel property detection, initialization
  4. *
  5. * Copyright 2008-2012 Freescale Semiconductor, Inc.
  6. * Copyright 2018-2019, 2023 NXP
  7. */
  8. #include <linux/device.h>
  9. #include <linux/of_address.h>
  10. #include <linux/of_irq.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/sys_soc.h>
  13. #include <linux/fsl/mc.h>
  14. #include "compat.h"
  15. #include "debugfs.h"
  16. #include "regs.h"
  17. #include "intern.h"
  18. #include "jr.h"
  19. #include "desc_constr.h"
  20. #include "ctrl.h"
  21. bool caam_dpaa2;
  22. EXPORT_SYMBOL(caam_dpaa2);
  23. #ifdef CONFIG_CAAM_QI
  24. #include "qi.h"
  25. #endif
  26. /*
  27. * Descriptor to instantiate RNG State Handle 0 in normal mode and
  28. * load the JDKEK, TDKEK and TDSK registers
  29. */
  30. static void build_instantiation_desc(u32 *desc, int handle, int do_sk)
  31. {
  32. u32 *jump_cmd, op_flags;
  33. init_job_desc(desc, 0);
  34. op_flags = OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
  35. (handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INIT |
  36. OP_ALG_PR_ON;
  37. /* INIT RNG in non-test mode */
  38. append_operation(desc, op_flags);
  39. if (!handle && do_sk) {
  40. /*
  41. * For SH0, Secure Keys must be generated as well
  42. */
  43. /* wait for done */
  44. jump_cmd = append_jump(desc, JUMP_CLASS_CLASS1);
  45. set_jump_tgt_here(desc, jump_cmd);
  46. /*
  47. * load 1 to clear written reg:
  48. * resets the done interrupt and returns the RNG to idle.
  49. */
  50. append_load_imm_u32(desc, 1, LDST_SRCDST_WORD_CLRW);
  51. /* Initialize State Handle */
  52. append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
  53. OP_ALG_AAI_RNG4_SK);
  54. }
  55. append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
  56. }
  57. /* Descriptor for deinstantiation of State Handle 0 of the RNG block. */
  58. static void build_deinstantiation_desc(u32 *desc, int handle)
  59. {
  60. init_job_desc(desc, 0);
  61. /* Uninstantiate State Handle 0 */
  62. append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
  63. (handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INITFINAL);
  64. append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
  65. }
  66. #ifdef CONFIG_OF
  67. static const struct of_device_id imx8m_machine_match[] = {
  68. { .compatible = "fsl,imx8mm", },
  69. { .compatible = "fsl,imx8mn", },
  70. { .compatible = "fsl,imx8mp", },
  71. { .compatible = "fsl,imx8mq", },
  72. { .compatible = "fsl,imx8ulp", },
  73. { }
  74. };
  75. #endif
  76. /*
  77. * run_descriptor_deco0 - runs a descriptor on DECO0, under direct control of
  78. * the software (no JR/QI used).
  79. * @ctrldev - pointer to device
  80. * @status - descriptor status, after being run
  81. *
  82. * Return: - 0 if no error occurred
  83. * - -ENODEV if the DECO couldn't be acquired
  84. * - -EAGAIN if an error occurred while executing the descriptor
  85. */
  86. static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc,
  87. u32 *status)
  88. {
  89. struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
  90. struct caam_ctrl __iomem *ctrl = ctrlpriv->ctrl;
  91. struct caam_deco __iomem *deco = ctrlpriv->deco;
  92. unsigned int timeout = 100000;
  93. u32 deco_dbg_reg, deco_state, flags;
  94. int i;
  95. if (ctrlpriv->virt_en == 1 ||
  96. /*
  97. * Apparently on i.MX8M{Q,M,N,P} it doesn't matter if virt_en == 1
  98. * and the following steps should be performed regardless
  99. */
  100. of_match_node(imx8m_machine_match, of_root)) {
  101. clrsetbits_32(&ctrl->deco_rsr, 0, DECORSR_JR0);
  102. while (!(rd_reg32(&ctrl->deco_rsr) & DECORSR_VALID) &&
  103. --timeout)
  104. cpu_relax();
  105. timeout = 100000;
  106. }
  107. clrsetbits_32(&ctrl->deco_rq, 0, DECORR_RQD0ENABLE);
  108. while (!(rd_reg32(&ctrl->deco_rq) & DECORR_DEN0) &&
  109. --timeout)
  110. cpu_relax();
  111. if (!timeout) {
  112. dev_err(ctrldev, "failed to acquire DECO 0\n");
  113. clrsetbits_32(&ctrl->deco_rq, DECORR_RQD0ENABLE, 0);
  114. return -ENODEV;
  115. }
  116. for (i = 0; i < desc_len(desc); i++)
  117. wr_reg32(&deco->descbuf[i], caam32_to_cpu(*(desc + i)));
  118. flags = DECO_JQCR_WHL;
  119. /*
  120. * If the descriptor length is longer than 4 words, then the
  121. * FOUR bit in JRCTRL register must be set.
  122. */
  123. if (desc_len(desc) >= 4)
  124. flags |= DECO_JQCR_FOUR;
  125. /* Instruct the DECO to execute it */
  126. clrsetbits_32(&deco->jr_ctl_hi, 0, flags);
  127. timeout = 10000000;
  128. do {
  129. deco_dbg_reg = rd_reg32(&deco->desc_dbg);
  130. if (ctrlpriv->era < 10)
  131. deco_state = (deco_dbg_reg & DESC_DBG_DECO_STAT_MASK) >>
  132. DESC_DBG_DECO_STAT_SHIFT;
  133. else
  134. deco_state = (rd_reg32(&deco->dbg_exec) &
  135. DESC_DER_DECO_STAT_MASK) >>
  136. DESC_DER_DECO_STAT_SHIFT;
  137. /*
  138. * If an error occurred in the descriptor, then
  139. * the DECO status field will be set to 0x0D
  140. */
  141. if (deco_state == DECO_STAT_HOST_ERR)
  142. break;
  143. cpu_relax();
  144. } while ((deco_dbg_reg & DESC_DBG_DECO_STAT_VALID) && --timeout);
  145. *status = rd_reg32(&deco->op_status_hi) &
  146. DECO_OP_STATUS_HI_ERR_MASK;
  147. if (ctrlpriv->virt_en == 1)
  148. clrsetbits_32(&ctrl->deco_rsr, DECORSR_JR0, 0);
  149. /* Mark the DECO as free */
  150. clrsetbits_32(&ctrl->deco_rq, DECORR_RQD0ENABLE, 0);
  151. if (!timeout)
  152. return -EAGAIN;
  153. return 0;
  154. }
  155. /*
  156. * deinstantiate_rng - builds and executes a descriptor on DECO0,
  157. * which deinitializes the RNG block.
  158. * @ctrldev - pointer to device
  159. * @state_handle_mask - bitmask containing the instantiation status
  160. * for the RNG4 state handles which exist in
  161. * the RNG4 block: 1 if it's been instantiated
  162. *
  163. * Return: - 0 if no error occurred
  164. * - -ENOMEM if there isn't enough memory to allocate the descriptor
  165. * - -ENODEV if DECO0 couldn't be acquired
  166. * - -EAGAIN if an error occurred when executing the descriptor
  167. */
  168. static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask)
  169. {
  170. u32 *desc, status;
  171. int sh_idx, ret = 0;
  172. desc = kmalloc(CAAM_CMD_SZ * 3, GFP_KERNEL);
  173. if (!desc)
  174. return -ENOMEM;
  175. for (sh_idx = 0; sh_idx < RNG4_MAX_HANDLES; sh_idx++) {
  176. /*
  177. * If the corresponding bit is set, then it means the state
  178. * handle was initialized by us, and thus it needs to be
  179. * deinitialized as well
  180. */
  181. if ((1 << sh_idx) & state_handle_mask) {
  182. /*
  183. * Create the descriptor for deinstantating this state
  184. * handle
  185. */
  186. build_deinstantiation_desc(desc, sh_idx);
  187. /* Try to run it through DECO0 */
  188. ret = run_descriptor_deco0(ctrldev, desc, &status);
  189. if (ret ||
  190. (status && status != JRSTA_SSRC_JUMP_HALT_CC)) {
  191. dev_err(ctrldev,
  192. "Failed to deinstantiate RNG4 SH%d\n",
  193. sh_idx);
  194. break;
  195. }
  196. dev_info(ctrldev, "Deinstantiated RNG4 SH%d\n", sh_idx);
  197. }
  198. }
  199. kfree(desc);
  200. return ret;
  201. }
  202. static void devm_deinstantiate_rng(void *data)
  203. {
  204. struct device *ctrldev = data;
  205. struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
  206. /*
  207. * De-initialize RNG state handles initialized by this driver.
  208. * In case of SoCs with Management Complex, RNG is managed by MC f/w.
  209. */
  210. if (ctrlpriv->rng4_sh_init)
  211. deinstantiate_rng(ctrldev, ctrlpriv->rng4_sh_init);
  212. }
  213. /*
  214. * instantiate_rng - builds and executes a descriptor on DECO0,
  215. * which initializes the RNG block.
  216. * @ctrldev - pointer to device
  217. * @state_handle_mask - bitmask containing the instantiation status
  218. * for the RNG4 state handles which exist in
  219. * the RNG4 block: 1 if it's been instantiated
  220. * by an external entry, 0 otherwise.
  221. * @gen_sk - generate data to be loaded into the JDKEK, TDKEK and TDSK;
  222. * Caution: this can be done only once; if the keys need to be
  223. * regenerated, a POR is required
  224. *
  225. * Return: - 0 if no error occurred
  226. * - -ENOMEM if there isn't enough memory to allocate the descriptor
  227. * - -ENODEV if DECO0 couldn't be acquired
  228. * - -EAGAIN if an error occurred when executing the descriptor
  229. * f.i. there was a RNG hardware error due to not "good enough"
  230. * entropy being acquired.
  231. */
  232. static int instantiate_rng(struct device *ctrldev, int state_handle_mask,
  233. int gen_sk)
  234. {
  235. struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
  236. struct caam_ctrl __iomem *ctrl;
  237. u32 *desc, status = 0, rdsta_val;
  238. int ret = 0, sh_idx;
  239. ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl;
  240. desc = kmalloc(CAAM_CMD_SZ * 7, GFP_KERNEL);
  241. if (!desc)
  242. return -ENOMEM;
  243. for (sh_idx = 0; sh_idx < RNG4_MAX_HANDLES; sh_idx++) {
  244. const u32 rdsta_if = RDSTA_IF0 << sh_idx;
  245. const u32 rdsta_pr = RDSTA_PR0 << sh_idx;
  246. const u32 rdsta_mask = rdsta_if | rdsta_pr;
  247. /* Clear the contents before using the descriptor */
  248. memset(desc, 0x00, CAAM_CMD_SZ * 7);
  249. /*
  250. * If the corresponding bit is set, this state handle
  251. * was initialized by somebody else, so it's left alone.
  252. */
  253. if (rdsta_if & state_handle_mask) {
  254. if (rdsta_pr & state_handle_mask)
  255. continue;
  256. dev_info(ctrldev,
  257. "RNG4 SH%d was previously instantiated without prediction resistance. Tearing it down\n",
  258. sh_idx);
  259. ret = deinstantiate_rng(ctrldev, rdsta_if);
  260. if (ret)
  261. break;
  262. }
  263. /* Create the descriptor for instantiating RNG State Handle */
  264. build_instantiation_desc(desc, sh_idx, gen_sk);
  265. /* Try to run it through DECO0 */
  266. ret = run_descriptor_deco0(ctrldev, desc, &status);
  267. /*
  268. * If ret is not 0, or descriptor status is not 0, then
  269. * something went wrong. No need to try the next state
  270. * handle (if available), bail out here.
  271. * Also, if for some reason, the State Handle didn't get
  272. * instantiated although the descriptor has finished
  273. * without any error (HW optimizations for later
  274. * CAAM eras), then try again.
  275. */
  276. if (ret)
  277. break;
  278. rdsta_val = rd_reg32(&ctrl->r4tst[0].rdsta) & RDSTA_MASK;
  279. if ((status && status != JRSTA_SSRC_JUMP_HALT_CC) ||
  280. (rdsta_val & rdsta_mask) != rdsta_mask) {
  281. ret = -EAGAIN;
  282. break;
  283. }
  284. dev_info(ctrldev, "Instantiated RNG4 SH%d\n", sh_idx);
  285. }
  286. kfree(desc);
  287. if (ret)
  288. return ret;
  289. return devm_add_action_or_reset(ctrldev, devm_deinstantiate_rng, ctrldev);
  290. }
  291. /*
  292. * kick_trng - sets the various parameters for enabling the initialization
  293. * of the RNG4 block in CAAM
  294. * @dev - pointer to the controller device
  295. * @ent_delay - Defines the length (in system clocks) of each entropy sample.
  296. */
  297. static void kick_trng(struct device *dev, int ent_delay)
  298. {
  299. struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  300. struct caam_ctrl __iomem *ctrl;
  301. struct rng4tst __iomem *r4tst;
  302. u32 val, rtsdctl;
  303. ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl;
  304. r4tst = &ctrl->r4tst[0];
  305. /*
  306. * Setting both RTMCTL:PRGM and RTMCTL:TRNG_ACC causes TRNG to
  307. * properly invalidate the entropy in the entropy register and
  308. * force re-generation.
  309. */
  310. clrsetbits_32(&r4tst->rtmctl, 0, RTMCTL_PRGM | RTMCTL_ACC);
  311. /*
  312. * Performance-wise, it does not make sense to
  313. * set the delay to a value that is lower
  314. * than the last one that worked (i.e. the state handles
  315. * were instantiated properly).
  316. */
  317. rtsdctl = rd_reg32(&r4tst->rtsdctl);
  318. val = (rtsdctl & RTSDCTL_ENT_DLY_MASK) >> RTSDCTL_ENT_DLY_SHIFT;
  319. if (ent_delay > val) {
  320. val = ent_delay;
  321. /* min. freq. count, equal to 1/4 of the entropy sample length */
  322. wr_reg32(&r4tst->rtfrqmin, val >> 2);
  323. /* disable maximum frequency count */
  324. wr_reg32(&r4tst->rtfrqmax, RTFRQMAX_DISABLE);
  325. }
  326. wr_reg32(&r4tst->rtsdctl, (val << RTSDCTL_ENT_DLY_SHIFT) |
  327. RTSDCTL_SAMP_SIZE_VAL);
  328. /*
  329. * To avoid reprogramming the self-test parameters over and over again,
  330. * use RTSDCTL[SAMP_SIZE] as an indicator.
  331. */
  332. if ((rtsdctl & RTSDCTL_SAMP_SIZE_MASK) != RTSDCTL_SAMP_SIZE_VAL) {
  333. wr_reg32(&r4tst->rtscmisc, (2 << 16) | 32);
  334. wr_reg32(&r4tst->rtpkrrng, 570);
  335. wr_reg32(&r4tst->rtpkrmax, 1600);
  336. wr_reg32(&r4tst->rtscml, (122 << 16) | 317);
  337. wr_reg32(&r4tst->rtscrl[0], (80 << 16) | 107);
  338. wr_reg32(&r4tst->rtscrl[1], (57 << 16) | 62);
  339. wr_reg32(&r4tst->rtscrl[2], (39 << 16) | 39);
  340. wr_reg32(&r4tst->rtscrl[3], (27 << 16) | 26);
  341. wr_reg32(&r4tst->rtscrl[4], (19 << 16) | 18);
  342. wr_reg32(&r4tst->rtscrl[5], (18 << 16) | 17);
  343. }
  344. /*
  345. * select raw sampling in both entropy shifter
  346. * and statistical checker; ; put RNG4 into run mode
  347. */
  348. clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM | RTMCTL_ACC,
  349. RTMCTL_SAMP_MODE_RAW_ES_SC);
  350. }
  351. static int caam_get_era_from_hw(struct caam_perfmon __iomem *perfmon)
  352. {
  353. static const struct {
  354. u16 ip_id;
  355. u8 maj_rev;
  356. u8 era;
  357. } id[] = {
  358. {0x0A10, 1, 1},
  359. {0x0A10, 2, 2},
  360. {0x0A12, 1, 3},
  361. {0x0A14, 1, 3},
  362. {0x0A14, 2, 4},
  363. {0x0A16, 1, 4},
  364. {0x0A10, 3, 4},
  365. {0x0A11, 1, 4},
  366. {0x0A18, 1, 4},
  367. {0x0A11, 2, 5},
  368. {0x0A12, 2, 5},
  369. {0x0A13, 1, 5},
  370. {0x0A1C, 1, 5}
  371. };
  372. u32 ccbvid, id_ms;
  373. u8 maj_rev, era;
  374. u16 ip_id;
  375. int i;
  376. ccbvid = rd_reg32(&perfmon->ccb_id);
  377. era = (ccbvid & CCBVID_ERA_MASK) >> CCBVID_ERA_SHIFT;
  378. if (era) /* This is '0' prior to CAAM ERA-6 */
  379. return era;
  380. id_ms = rd_reg32(&perfmon->caam_id_ms);
  381. ip_id = (id_ms & SECVID_MS_IPID_MASK) >> SECVID_MS_IPID_SHIFT;
  382. maj_rev = (id_ms & SECVID_MS_MAJ_REV_MASK) >> SECVID_MS_MAJ_REV_SHIFT;
  383. for (i = 0; i < ARRAY_SIZE(id); i++)
  384. if (id[i].ip_id == ip_id && id[i].maj_rev == maj_rev)
  385. return id[i].era;
  386. return -ENOTSUPP;
  387. }
  388. /**
  389. * caam_get_era() - Return the ERA of the SEC on SoC, based
  390. * on "sec-era" optional property in the DTS. This property is updated
  391. * by u-boot.
  392. * In case this property is not passed an attempt to retrieve the CAAM
  393. * era via register reads will be made.
  394. *
  395. * @perfmon: Performance Monitor Registers
  396. */
  397. static int caam_get_era(struct caam_perfmon __iomem *perfmon)
  398. {
  399. struct device_node *caam_node;
  400. int ret;
  401. u32 prop;
  402. caam_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
  403. ret = of_property_read_u32(caam_node, "fsl,sec-era", &prop);
  404. of_node_put(caam_node);
  405. if (!ret)
  406. return prop;
  407. else
  408. return caam_get_era_from_hw(perfmon);
  409. }
  410. /*
  411. * ERRATA: imx6 devices (imx6D, imx6Q, imx6DL, imx6S, imx6DP and imx6QP)
  412. * have an issue wherein AXI bus transactions may not occur in the correct
  413. * order. This isn't a problem running single descriptors, but can be if
  414. * running multiple concurrent descriptors. Reworking the driver to throttle
  415. * to single requests is impractical, thus the workaround is to limit the AXI
  416. * pipeline to a depth of 1 (from it's default of 4) to preclude this situation
  417. * from occurring.
  418. */
  419. static void handle_imx6_err005766(u32 __iomem *mcr)
  420. {
  421. if (of_machine_is_compatible("fsl,imx6q") ||
  422. of_machine_is_compatible("fsl,imx6dl") ||
  423. of_machine_is_compatible("fsl,imx6qp"))
  424. clrsetbits_32(mcr, MCFGR_AXIPIPE_MASK,
  425. 1 << MCFGR_AXIPIPE_SHIFT);
  426. }
  427. static const struct of_device_id caam_match[] = {
  428. {
  429. .compatible = "fsl,sec-v4.0",
  430. },
  431. {
  432. .compatible = "fsl,sec4.0",
  433. },
  434. {},
  435. };
  436. MODULE_DEVICE_TABLE(of, caam_match);
  437. struct caam_imx_data {
  438. bool page0_access;
  439. const struct clk_bulk_data *clks;
  440. int num_clks;
  441. };
  442. static const struct clk_bulk_data caam_imx6_clks[] = {
  443. { .id = "ipg" },
  444. { .id = "mem" },
  445. { .id = "aclk" },
  446. { .id = "emi_slow" },
  447. };
  448. static const struct caam_imx_data caam_imx6_data = {
  449. .page0_access = true,
  450. .clks = caam_imx6_clks,
  451. .num_clks = ARRAY_SIZE(caam_imx6_clks),
  452. };
  453. static const struct clk_bulk_data caam_imx7_clks[] = {
  454. { .id = "ipg" },
  455. { .id = "aclk" },
  456. };
  457. static const struct caam_imx_data caam_imx7_data = {
  458. .page0_access = true,
  459. .clks = caam_imx7_clks,
  460. .num_clks = ARRAY_SIZE(caam_imx7_clks),
  461. };
  462. static const struct clk_bulk_data caam_imx6ul_clks[] = {
  463. { .id = "ipg" },
  464. { .id = "mem" },
  465. { .id = "aclk" },
  466. };
  467. static const struct caam_imx_data caam_imx6ul_data = {
  468. .page0_access = true,
  469. .clks = caam_imx6ul_clks,
  470. .num_clks = ARRAY_SIZE(caam_imx6ul_clks),
  471. };
  472. static const struct clk_bulk_data caam_vf610_clks[] = {
  473. { .id = "ipg" },
  474. };
  475. static const struct caam_imx_data caam_vf610_data = {
  476. .page0_access = true,
  477. .clks = caam_vf610_clks,
  478. .num_clks = ARRAY_SIZE(caam_vf610_clks),
  479. };
  480. static const struct caam_imx_data caam_imx8ulp_data;
  481. static const struct soc_device_attribute caam_imx_soc_table[] = {
  482. { .soc_id = "i.MX6UL", .data = &caam_imx6ul_data },
  483. { .soc_id = "i.MX6*", .data = &caam_imx6_data },
  484. { .soc_id = "i.MX7*", .data = &caam_imx7_data },
  485. { .soc_id = "i.MX8M*", .data = &caam_imx7_data },
  486. { .soc_id = "i.MX8ULP", .data = &caam_imx8ulp_data },
  487. { .soc_id = "VF*", .data = &caam_vf610_data },
  488. { .family = "Freescale i.MX" },
  489. { /* sentinel */ }
  490. };
  491. static void disable_clocks(void *data)
  492. {
  493. struct caam_drv_private *ctrlpriv = data;
  494. clk_bulk_disable_unprepare(ctrlpriv->num_clks, ctrlpriv->clks);
  495. }
  496. static int init_clocks(struct device *dev, const struct caam_imx_data *data)
  497. {
  498. struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  499. int ret;
  500. ctrlpriv->num_clks = data->num_clks;
  501. ctrlpriv->clks = devm_kmemdup(dev, data->clks,
  502. data->num_clks * sizeof(data->clks[0]),
  503. GFP_KERNEL);
  504. if (!ctrlpriv->clks)
  505. return -ENOMEM;
  506. ret = devm_clk_bulk_get(dev, ctrlpriv->num_clks, ctrlpriv->clks);
  507. if (ret) {
  508. dev_err(dev,
  509. "Failed to request all necessary clocks\n");
  510. return ret;
  511. }
  512. ret = clk_bulk_prepare_enable(ctrlpriv->num_clks, ctrlpriv->clks);
  513. if (ret) {
  514. dev_err(dev,
  515. "Failed to prepare/enable all necessary clocks\n");
  516. return ret;
  517. }
  518. return devm_add_action_or_reset(dev, disable_clocks, ctrlpriv);
  519. }
  520. static void caam_remove_debugfs(void *root)
  521. {
  522. debugfs_remove_recursive(root);
  523. }
  524. #ifdef CONFIG_FSL_MC_BUS
  525. static bool check_version(struct fsl_mc_version *mc_version, u32 major,
  526. u32 minor, u32 revision)
  527. {
  528. if (mc_version->major > major)
  529. return true;
  530. if (mc_version->major == major) {
  531. if (mc_version->minor > minor)
  532. return true;
  533. if (mc_version->minor == minor &&
  534. mc_version->revision > revision)
  535. return true;
  536. }
  537. return false;
  538. }
  539. #endif
  540. static bool needs_entropy_delay_adjustment(void)
  541. {
  542. if (of_machine_is_compatible("fsl,imx6sx"))
  543. return true;
  544. return false;
  545. }
  546. static int caam_ctrl_rng_init(struct device *dev)
  547. {
  548. struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  549. struct caam_ctrl __iomem *ctrl = ctrlpriv->ctrl;
  550. int ret, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN;
  551. u8 rng_vid;
  552. if (ctrlpriv->era < 10) {
  553. struct caam_perfmon __iomem *perfmon;
  554. perfmon = ctrlpriv->total_jobrs ?
  555. (struct caam_perfmon __iomem *)&ctrlpriv->jr[0]->perfmon :
  556. (struct caam_perfmon __iomem *)&ctrl->perfmon;
  557. rng_vid = (rd_reg32(&perfmon->cha_id_ls) &
  558. CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT;
  559. } else {
  560. struct version_regs __iomem *vreg;
  561. vreg = ctrlpriv->total_jobrs ?
  562. (struct version_regs __iomem *)&ctrlpriv->jr[0]->vreg :
  563. (struct version_regs __iomem *)&ctrl->vreg;
  564. rng_vid = (rd_reg32(&vreg->rng) & CHA_VER_VID_MASK) >>
  565. CHA_VER_VID_SHIFT;
  566. }
  567. /*
  568. * If SEC has RNG version >= 4 and RNG state handle has not been
  569. * already instantiated, do RNG instantiation
  570. * In case of SoCs with Management Complex, RNG is managed by MC f/w.
  571. */
  572. if (!(ctrlpriv->mc_en && ctrlpriv->pr_support) && rng_vid >= 4) {
  573. ctrlpriv->rng4_sh_init =
  574. rd_reg32(&ctrl->r4tst[0].rdsta);
  575. /*
  576. * If the secure keys (TDKEK, JDKEK, TDSK), were already
  577. * generated, signal this to the function that is instantiating
  578. * the state handles. An error would occur if RNG4 attempts
  579. * to regenerate these keys before the next POR.
  580. */
  581. gen_sk = ctrlpriv->rng4_sh_init & RDSTA_SKVN ? 0 : 1;
  582. ctrlpriv->rng4_sh_init &= RDSTA_MASK;
  583. do {
  584. int inst_handles =
  585. rd_reg32(&ctrl->r4tst[0].rdsta) & RDSTA_MASK;
  586. /*
  587. * If either SH were instantiated by somebody else
  588. * (e.g. u-boot) then it is assumed that the entropy
  589. * parameters are properly set and thus the function
  590. * setting these (kick_trng(...)) is skipped.
  591. * Also, if a handle was instantiated, do not change
  592. * the TRNG parameters.
  593. */
  594. if (needs_entropy_delay_adjustment())
  595. ent_delay = 12000;
  596. if (!(ctrlpriv->rng4_sh_init || inst_handles)) {
  597. dev_info(dev,
  598. "Entropy delay = %u\n",
  599. ent_delay);
  600. kick_trng(dev, ent_delay);
  601. ent_delay += 400;
  602. }
  603. /*
  604. * if instantiate_rng(...) fails, the loop will rerun
  605. * and the kick_trng(...) function will modify the
  606. * upper and lower limits of the entropy sampling
  607. * interval, leading to a successful initialization of
  608. * the RNG.
  609. */
  610. ret = instantiate_rng(dev, inst_handles,
  611. gen_sk);
  612. /*
  613. * Entropy delay is determined via TRNG characterization.
  614. * TRNG characterization is run across different voltages
  615. * and temperatures.
  616. * If worst case value for ent_dly is identified,
  617. * the loop can be skipped for that platform.
  618. */
  619. if (needs_entropy_delay_adjustment())
  620. break;
  621. if (ret == -EAGAIN)
  622. /*
  623. * if here, the loop will rerun,
  624. * so don't hog the CPU
  625. */
  626. cpu_relax();
  627. } while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX));
  628. if (ret) {
  629. dev_err(dev, "failed to instantiate RNG");
  630. return ret;
  631. }
  632. /*
  633. * Set handles initialized by this module as the complement of
  634. * the already initialized ones
  635. */
  636. ctrlpriv->rng4_sh_init = ~ctrlpriv->rng4_sh_init & RDSTA_MASK;
  637. /* Enable RDB bit so that RNG works faster */
  638. clrsetbits_32(&ctrl->scfgr, 0, SCFGR_RDBENABLE);
  639. }
  640. return 0;
  641. }
  642. /* Indicate if the internal state of the CAAM is lost during PM */
  643. static int caam_off_during_pm(void)
  644. {
  645. bool not_off_during_pm = of_machine_is_compatible("fsl,imx6q") ||
  646. of_machine_is_compatible("fsl,imx6qp") ||
  647. of_machine_is_compatible("fsl,imx6dl");
  648. return not_off_during_pm ? 0 : 1;
  649. }
  650. static void caam_state_save(struct device *dev)
  651. {
  652. struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  653. struct caam_ctl_state *state = &ctrlpriv->state;
  654. struct caam_ctrl __iomem *ctrl = ctrlpriv->ctrl;
  655. u32 deco_inst, jr_inst;
  656. int i;
  657. state->mcr = rd_reg32(&ctrl->mcr);
  658. state->scfgr = rd_reg32(&ctrl->scfgr);
  659. deco_inst = (rd_reg32(&ctrl->perfmon.cha_num_ms) &
  660. CHA_ID_MS_DECO_MASK) >> CHA_ID_MS_DECO_SHIFT;
  661. for (i = 0; i < deco_inst; i++) {
  662. state->deco_mid[i].liodn_ms =
  663. rd_reg32(&ctrl->deco_mid[i].liodn_ms);
  664. state->deco_mid[i].liodn_ls =
  665. rd_reg32(&ctrl->deco_mid[i].liodn_ls);
  666. }
  667. jr_inst = (rd_reg32(&ctrl->perfmon.cha_num_ms) &
  668. CHA_ID_MS_JR_MASK) >> CHA_ID_MS_JR_SHIFT;
  669. for (i = 0; i < jr_inst; i++) {
  670. state->jr_mid[i].liodn_ms =
  671. rd_reg32(&ctrl->jr_mid[i].liodn_ms);
  672. state->jr_mid[i].liodn_ls =
  673. rd_reg32(&ctrl->jr_mid[i].liodn_ls);
  674. }
  675. }
  676. static void caam_state_restore(const struct device *dev)
  677. {
  678. const struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  679. const struct caam_ctl_state *state = &ctrlpriv->state;
  680. struct caam_ctrl __iomem *ctrl = ctrlpriv->ctrl;
  681. u32 deco_inst, jr_inst;
  682. int i;
  683. wr_reg32(&ctrl->mcr, state->mcr);
  684. wr_reg32(&ctrl->scfgr, state->scfgr);
  685. deco_inst = (rd_reg32(&ctrl->perfmon.cha_num_ms) &
  686. CHA_ID_MS_DECO_MASK) >> CHA_ID_MS_DECO_SHIFT;
  687. for (i = 0; i < deco_inst; i++) {
  688. wr_reg32(&ctrl->deco_mid[i].liodn_ms,
  689. state->deco_mid[i].liodn_ms);
  690. wr_reg32(&ctrl->deco_mid[i].liodn_ls,
  691. state->deco_mid[i].liodn_ls);
  692. }
  693. jr_inst = (rd_reg32(&ctrl->perfmon.cha_num_ms) &
  694. CHA_ID_MS_JR_MASK) >> CHA_ID_MS_JR_SHIFT;
  695. for (i = 0; i < jr_inst; i++) {
  696. wr_reg32(&ctrl->jr_mid[i].liodn_ms,
  697. state->jr_mid[i].liodn_ms);
  698. wr_reg32(&ctrl->jr_mid[i].liodn_ls,
  699. state->jr_mid[i].liodn_ls);
  700. }
  701. if (ctrlpriv->virt_en == 1)
  702. clrsetbits_32(&ctrl->jrstart, 0, JRSTART_JR0_START |
  703. JRSTART_JR1_START | JRSTART_JR2_START |
  704. JRSTART_JR3_START);
  705. }
  706. static int caam_ctrl_suspend(struct device *dev)
  707. {
  708. const struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  709. if (ctrlpriv->caam_off_during_pm && !ctrlpriv->optee_en)
  710. caam_state_save(dev);
  711. return 0;
  712. }
  713. static int caam_ctrl_resume(struct device *dev)
  714. {
  715. struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  716. int ret = 0;
  717. if (ctrlpriv->caam_off_during_pm && !ctrlpriv->optee_en) {
  718. caam_state_restore(dev);
  719. /* HW and rng will be reset so deinstantiation can be removed */
  720. devm_remove_action(dev, devm_deinstantiate_rng, dev);
  721. ret = caam_ctrl_rng_init(dev);
  722. }
  723. return ret;
  724. }
  725. static DEFINE_SIMPLE_DEV_PM_OPS(caam_ctrl_pm_ops, caam_ctrl_suspend, caam_ctrl_resume);
  726. /* Probe routine for CAAM top (controller) level */
  727. static int caam_probe(struct platform_device *pdev)
  728. {
  729. int ret, ring;
  730. u64 caam_id;
  731. const struct soc_device_attribute *imx_soc_match;
  732. struct device *dev;
  733. struct device_node *nprop, *np;
  734. struct caam_ctrl __iomem *ctrl;
  735. struct caam_drv_private *ctrlpriv;
  736. struct caam_perfmon __iomem *perfmon;
  737. struct dentry *dfs_root;
  738. u32 scfgr, comp_params;
  739. int pg_size;
  740. int BLOCK_OFFSET = 0;
  741. bool reg_access = true;
  742. const struct caam_imx_data *imx_soc_data;
  743. ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL);
  744. if (!ctrlpriv)
  745. return -ENOMEM;
  746. dev = &pdev->dev;
  747. dev_set_drvdata(dev, ctrlpriv);
  748. nprop = pdev->dev.of_node;
  749. imx_soc_match = soc_device_match(caam_imx_soc_table);
  750. if (!imx_soc_match && of_match_node(imx8m_machine_match, of_root))
  751. return -EPROBE_DEFER;
  752. caam_imx = (bool)imx_soc_match;
  753. ctrlpriv->caam_off_during_pm = caam_imx && caam_off_during_pm();
  754. if (imx_soc_match) {
  755. /*
  756. * Until Layerscape and i.MX OP-TEE get in sync,
  757. * only i.MX OP-TEE use cases disallow access to
  758. * caam page 0 (controller) registers.
  759. */
  760. np = of_find_compatible_node(NULL, NULL, "linaro,optee-tz");
  761. ctrlpriv->optee_en = !!np;
  762. of_node_put(np);
  763. reg_access = !ctrlpriv->optee_en;
  764. if (!imx_soc_match->data) {
  765. dev_err(dev, "No clock data provided for i.MX SoC");
  766. return -EINVAL;
  767. }
  768. imx_soc_data = imx_soc_match->data;
  769. reg_access = reg_access && imx_soc_data->page0_access;
  770. /*
  771. * CAAM clocks cannot be controlled from kernel.
  772. */
  773. if (!imx_soc_data->num_clks)
  774. goto iomap_ctrl;
  775. ret = init_clocks(dev, imx_soc_match->data);
  776. if (ret)
  777. return ret;
  778. }
  779. iomap_ctrl:
  780. /* Get configuration properties from device tree */
  781. /* First, get register page */
  782. ctrl = devm_of_iomap(dev, nprop, 0, NULL);
  783. ret = PTR_ERR_OR_ZERO(ctrl);
  784. if (ret) {
  785. dev_err(dev, "caam: of_iomap() failed\n");
  786. return ret;
  787. }
  788. ring = 0;
  789. for_each_available_child_of_node(nprop, np)
  790. if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
  791. of_device_is_compatible(np, "fsl,sec4.0-job-ring")) {
  792. u32 reg;
  793. if (of_property_read_u32_index(np, "reg", 0, &reg)) {
  794. dev_err(dev, "%s read reg property error\n",
  795. np->full_name);
  796. continue;
  797. }
  798. ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *)
  799. ((__force uint8_t *)ctrl + reg);
  800. ctrlpriv->total_jobrs++;
  801. ring++;
  802. }
  803. /*
  804. * Wherever possible, instead of accessing registers from the global page,
  805. * use the alias registers in the first (cf. DT nodes order)
  806. * job ring's page.
  807. */
  808. perfmon = ring ? (struct caam_perfmon __iomem *)&ctrlpriv->jr[0]->perfmon :
  809. (struct caam_perfmon __iomem *)&ctrl->perfmon;
  810. caam_little_end = !(bool)(rd_reg32(&perfmon->status) &
  811. (CSTA_PLEND | CSTA_ALT_PLEND));
  812. comp_params = rd_reg32(&perfmon->comp_parms_ms);
  813. if (reg_access && comp_params & CTPR_MS_PS &&
  814. rd_reg32(&ctrl->mcr) & MCFGR_LONG_PTR)
  815. caam_ptr_sz = sizeof(u64);
  816. else
  817. caam_ptr_sz = sizeof(u32);
  818. caam_dpaa2 = !!(comp_params & CTPR_MS_DPAA2);
  819. ctrlpriv->qi_present = !!(comp_params & CTPR_MS_QI_MASK);
  820. #ifdef CONFIG_CAAM_QI
  821. /* If (DPAA 1.x) QI present, check whether dependencies are available */
  822. if (ctrlpriv->qi_present && !caam_dpaa2) {
  823. ret = qman_is_probed();
  824. if (!ret) {
  825. return -EPROBE_DEFER;
  826. } else if (ret < 0) {
  827. dev_err(dev, "failing probe due to qman probe error\n");
  828. return -ENODEV;
  829. }
  830. ret = qman_portals_probed();
  831. if (!ret) {
  832. return -EPROBE_DEFER;
  833. } else if (ret < 0) {
  834. dev_err(dev, "failing probe due to qman portals probe error\n");
  835. return -ENODEV;
  836. }
  837. }
  838. #endif
  839. /* Allocating the BLOCK_OFFSET based on the supported page size on
  840. * the platform
  841. */
  842. pg_size = (comp_params & CTPR_MS_PG_SZ_MASK) >> CTPR_MS_PG_SZ_SHIFT;
  843. if (pg_size == 0)
  844. BLOCK_OFFSET = PG_SIZE_4K;
  845. else
  846. BLOCK_OFFSET = PG_SIZE_64K;
  847. ctrlpriv->ctrl = (struct caam_ctrl __iomem __force *)ctrl;
  848. ctrlpriv->assure = (struct caam_assurance __iomem __force *)
  849. ((__force uint8_t *)ctrl +
  850. BLOCK_OFFSET * ASSURE_BLOCK_NUMBER
  851. );
  852. ctrlpriv->deco = (struct caam_deco __iomem __force *)
  853. ((__force uint8_t *)ctrl +
  854. BLOCK_OFFSET * DECO_BLOCK_NUMBER
  855. );
  856. /* Get the IRQ of the controller (for security violations only) */
  857. ctrlpriv->secvio_irq = irq_of_parse_and_map(nprop, 0);
  858. np = of_find_compatible_node(NULL, NULL, "fsl,qoriq-mc");
  859. ctrlpriv->mc_en = !!np;
  860. of_node_put(np);
  861. #ifdef CONFIG_FSL_MC_BUS
  862. if (ctrlpriv->mc_en) {
  863. struct fsl_mc_version *mc_version;
  864. mc_version = fsl_mc_get_version();
  865. if (mc_version)
  866. ctrlpriv->pr_support = check_version(mc_version, 10, 20,
  867. 0);
  868. else
  869. return -EPROBE_DEFER;
  870. }
  871. #endif
  872. if (!reg_access)
  873. goto set_dma_mask;
  874. /*
  875. * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
  876. * long pointers in master configuration register.
  877. * In case of SoCs with Management Complex, MC f/w performs
  878. * the configuration.
  879. */
  880. if (!ctrlpriv->mc_en)
  881. clrsetbits_32(&ctrl->mcr, MCFGR_AWCACHE_MASK,
  882. MCFGR_AWCACHE_CACH | MCFGR_AWCACHE_BUFF |
  883. MCFGR_WDENABLE | MCFGR_LARGE_BURST);
  884. handle_imx6_err005766(&ctrl->mcr);
  885. /*
  886. * Read the Compile Time parameters and SCFGR to determine
  887. * if virtualization is enabled for this platform
  888. */
  889. scfgr = rd_reg32(&ctrl->scfgr);
  890. ctrlpriv->virt_en = 0;
  891. if (comp_params & CTPR_MS_VIRT_EN_INCL) {
  892. /* VIRT_EN_INCL = 1 & VIRT_EN_POR = 1 or
  893. * VIRT_EN_INCL = 1 & VIRT_EN_POR = 0 & SCFGR_VIRT_EN = 1
  894. */
  895. if ((comp_params & CTPR_MS_VIRT_EN_POR) ||
  896. (!(comp_params & CTPR_MS_VIRT_EN_POR) &&
  897. (scfgr & SCFGR_VIRT_EN)))
  898. ctrlpriv->virt_en = 1;
  899. } else {
  900. /* VIRT_EN_INCL = 0 && VIRT_EN_POR_VALUE = 1 */
  901. if (comp_params & CTPR_MS_VIRT_EN_POR)
  902. ctrlpriv->virt_en = 1;
  903. }
  904. if (ctrlpriv->virt_en == 1)
  905. clrsetbits_32(&ctrl->jrstart, 0, JRSTART_JR0_START |
  906. JRSTART_JR1_START | JRSTART_JR2_START |
  907. JRSTART_JR3_START);
  908. set_dma_mask:
  909. ret = dma_set_mask_and_coherent(dev, caam_get_dma_mask(dev));
  910. if (ret) {
  911. dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret);
  912. return ret;
  913. }
  914. ctrlpriv->era = caam_get_era(perfmon);
  915. ctrlpriv->domain = iommu_get_domain_for_dev(dev);
  916. dfs_root = debugfs_create_dir(dev_name(dev), NULL);
  917. if (IS_ENABLED(CONFIG_DEBUG_FS)) {
  918. ret = devm_add_action_or_reset(dev, caam_remove_debugfs,
  919. dfs_root);
  920. if (ret)
  921. return ret;
  922. }
  923. caam_debugfs_init(ctrlpriv, perfmon, dfs_root);
  924. /* Check to see if (DPAA 1.x) QI present. If so, enable */
  925. if (ctrlpriv->qi_present && !caam_dpaa2) {
  926. ctrlpriv->qi = (struct caam_queue_if __iomem __force *)
  927. ((__force uint8_t *)ctrl +
  928. BLOCK_OFFSET * QI_BLOCK_NUMBER
  929. );
  930. /* This is all that's required to physically enable QI */
  931. wr_reg32(&ctrlpriv->qi->qi_control_lo, QICTL_DQEN);
  932. /* If QMAN driver is present, init CAAM-QI backend */
  933. #ifdef CONFIG_CAAM_QI
  934. ret = caam_qi_init(pdev);
  935. if (ret)
  936. dev_err(dev, "caam qi i/f init failed: %d\n", ret);
  937. #endif
  938. }
  939. /* If no QI and no rings specified, quit and go home */
  940. if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
  941. dev_err(dev, "no queues configured, terminating\n");
  942. return -ENOMEM;
  943. }
  944. comp_params = rd_reg32(&perfmon->comp_parms_ls);
  945. ctrlpriv->blob_present = !!(comp_params & CTPR_LS_BLOB);
  946. /*
  947. * Some SoCs like the LS1028A (non-E) indicate CTPR_LS_BLOB support,
  948. * but fail when actually using it due to missing AES support, so
  949. * check both here.
  950. */
  951. if (ctrlpriv->era < 10) {
  952. ctrlpriv->blob_present = ctrlpriv->blob_present &&
  953. (rd_reg32(&perfmon->cha_num_ls) & CHA_ID_LS_AES_MASK);
  954. } else {
  955. struct version_regs __iomem *vreg;
  956. vreg = ctrlpriv->total_jobrs ?
  957. (struct version_regs __iomem *)&ctrlpriv->jr[0]->vreg :
  958. (struct version_regs __iomem *)&ctrl->vreg;
  959. ctrlpriv->blob_present = ctrlpriv->blob_present &&
  960. (rd_reg32(&vreg->aesa) & CHA_VER_MISC_AES_NUM_MASK);
  961. }
  962. if (reg_access) {
  963. ret = caam_ctrl_rng_init(dev);
  964. if (ret)
  965. return ret;
  966. }
  967. caam_id = (u64)rd_reg32(&perfmon->caam_id_ms) << 32 |
  968. (u64)rd_reg32(&perfmon->caam_id_ls);
  969. /* Report "alive" for developer to see */
  970. dev_info(dev, "device ID = 0x%016llx (Era %d)\n", caam_id,
  971. ctrlpriv->era);
  972. dev_info(dev, "job rings = %d, qi = %d\n",
  973. ctrlpriv->total_jobrs, ctrlpriv->qi_present);
  974. ret = devm_of_platform_populate(dev);
  975. if (ret)
  976. dev_err(dev, "JR platform devices creation error\n");
  977. return ret;
  978. }
  979. static struct platform_driver caam_driver = {
  980. .driver = {
  981. .name = "caam",
  982. .of_match_table = caam_match,
  983. .pm = pm_ptr(&caam_ctrl_pm_ops),
  984. },
  985. .probe = caam_probe,
  986. };
  987. module_platform_driver(caam_driver);
  988. MODULE_LICENSE("GPL");
  989. MODULE_DESCRIPTION("FSL CAAM request backend");
  990. MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");