ctrl.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  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_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_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 = "i.MX8Q*", .data = &caam_imx8ulp_data },
  488. { .soc_id = "VF*", .data = &caam_vf610_data },
  489. { .family = "Freescale i.MX" },
  490. { /* sentinel */ }
  491. };
  492. static void disable_clocks(void *data)
  493. {
  494. struct caam_drv_private *ctrlpriv = data;
  495. clk_bulk_disable_unprepare(ctrlpriv->num_clks, ctrlpriv->clks);
  496. }
  497. static int init_clocks(struct device *dev, const struct caam_imx_data *data)
  498. {
  499. struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  500. int ret;
  501. ctrlpriv->num_clks = data->num_clks;
  502. ctrlpriv->clks = devm_kmemdup_array(dev, data->clks,
  503. data->num_clks, sizeof(*data->clks),
  504. GFP_KERNEL);
  505. if (!ctrlpriv->clks)
  506. return -ENOMEM;
  507. ret = devm_clk_bulk_get(dev, ctrlpriv->num_clks, ctrlpriv->clks);
  508. if (ret) {
  509. dev_err(dev,
  510. "Failed to request all necessary clocks\n");
  511. return ret;
  512. }
  513. ret = clk_bulk_prepare_enable(ctrlpriv->num_clks, ctrlpriv->clks);
  514. if (ret) {
  515. dev_err(dev,
  516. "Failed to prepare/enable all necessary clocks\n");
  517. return ret;
  518. }
  519. return devm_add_action_or_reset(dev, disable_clocks, ctrlpriv);
  520. }
  521. static void caam_remove_debugfs(void *root)
  522. {
  523. debugfs_remove_recursive(root);
  524. }
  525. #ifdef CONFIG_FSL_MC_BUS
  526. static bool check_version(struct fsl_mc_version *mc_version, u32 major,
  527. u32 minor, u32 revision)
  528. {
  529. if (mc_version->major > major)
  530. return true;
  531. if (mc_version->major == major) {
  532. if (mc_version->minor > minor)
  533. return true;
  534. if (mc_version->minor == minor &&
  535. mc_version->revision > revision)
  536. return true;
  537. }
  538. return false;
  539. }
  540. #endif
  541. static bool needs_entropy_delay_adjustment(void)
  542. {
  543. if (of_machine_is_compatible("fsl,imx6sx"))
  544. return true;
  545. return false;
  546. }
  547. static int caam_ctrl_rng_init(struct device *dev)
  548. {
  549. struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  550. struct caam_ctrl __iomem *ctrl = ctrlpriv->ctrl;
  551. int ret, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN;
  552. u8 rng_vid;
  553. if (ctrlpriv->era < 10) {
  554. struct caam_perfmon __iomem *perfmon;
  555. perfmon = ctrlpriv->total_jobrs ?
  556. (struct caam_perfmon __iomem *)&ctrlpriv->jr[0]->perfmon :
  557. (struct caam_perfmon __iomem *)&ctrl->perfmon;
  558. rng_vid = (rd_reg32(&perfmon->cha_id_ls) &
  559. CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT;
  560. } else {
  561. struct version_regs __iomem *vreg;
  562. vreg = ctrlpriv->total_jobrs ?
  563. (struct version_regs __iomem *)&ctrlpriv->jr[0]->vreg :
  564. (struct version_regs __iomem *)&ctrl->vreg;
  565. rng_vid = (rd_reg32(&vreg->rng) & CHA_VER_VID_MASK) >>
  566. CHA_VER_VID_SHIFT;
  567. }
  568. /*
  569. * If SEC has RNG version >= 4 and RNG state handle has not been
  570. * already instantiated, do RNG instantiation
  571. * In case of SoCs with Management Complex, RNG is managed by MC f/w.
  572. */
  573. if (!(ctrlpriv->mc_en && ctrlpriv->pr_support) && rng_vid >= 4) {
  574. ctrlpriv->rng4_sh_init =
  575. rd_reg32(&ctrl->r4tst[0].rdsta);
  576. /*
  577. * If the secure keys (TDKEK, JDKEK, TDSK), were already
  578. * generated, signal this to the function that is instantiating
  579. * the state handles. An error would occur if RNG4 attempts
  580. * to regenerate these keys before the next POR.
  581. */
  582. gen_sk = ctrlpriv->rng4_sh_init & RDSTA_SKVN ? 0 : 1;
  583. ctrlpriv->rng4_sh_init &= RDSTA_MASK;
  584. do {
  585. int inst_handles =
  586. rd_reg32(&ctrl->r4tst[0].rdsta) & RDSTA_MASK;
  587. /*
  588. * If either SH were instantiated by somebody else
  589. * (e.g. u-boot) then it is assumed that the entropy
  590. * parameters are properly set and thus the function
  591. * setting these (kick_trng(...)) is skipped.
  592. * Also, if a handle was instantiated, do not change
  593. * the TRNG parameters.
  594. */
  595. if (needs_entropy_delay_adjustment())
  596. ent_delay = 12000;
  597. if (!inst_handles) {
  598. dev_info(dev,
  599. "Entropy delay = %u\n",
  600. ent_delay);
  601. kick_trng(dev, ent_delay);
  602. ent_delay = ent_delay * 2;
  603. }
  604. /*
  605. * if instantiate_rng(...) fails, the loop will rerun
  606. * and the kick_trng(...) function will modify the
  607. * upper and lower limits of the entropy sampling
  608. * interval, leading to a successful initialization of
  609. * the RNG.
  610. */
  611. ret = instantiate_rng(dev, inst_handles,
  612. gen_sk);
  613. /*
  614. * Entropy delay is determined via TRNG characterization.
  615. * TRNG characterization is run across different voltages
  616. * and temperatures.
  617. * If worst case value for ent_dly is identified,
  618. * the loop can be skipped for that platform.
  619. */
  620. if (needs_entropy_delay_adjustment())
  621. break;
  622. if (ret == -EAGAIN)
  623. /*
  624. * if here, the loop will rerun,
  625. * so don't hog the CPU
  626. */
  627. cpu_relax();
  628. } while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX));
  629. if (ret) {
  630. dev_err(dev, "failed to instantiate RNG");
  631. return ret;
  632. }
  633. /*
  634. * Set handles initialized by this module as the complement of
  635. * the already initialized ones
  636. */
  637. ctrlpriv->rng4_sh_init = ~ctrlpriv->rng4_sh_init & RDSTA_MASK;
  638. /* Enable RDB bit so that RNG works faster */
  639. clrsetbits_32(&ctrl->scfgr, 0, SCFGR_RDBENABLE);
  640. }
  641. return 0;
  642. }
  643. /* Indicate if the internal state of the CAAM is lost during PM */
  644. static int caam_off_during_pm(void)
  645. {
  646. bool not_off_during_pm = of_machine_is_compatible("fsl,imx6q") ||
  647. of_machine_is_compatible("fsl,imx6qp") ||
  648. of_machine_is_compatible("fsl,imx6dl");
  649. return not_off_during_pm ? 0 : 1;
  650. }
  651. static void caam_state_save(struct device *dev)
  652. {
  653. struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  654. struct caam_ctl_state *state = &ctrlpriv->state;
  655. struct caam_ctrl __iomem *ctrl = ctrlpriv->ctrl;
  656. u32 deco_inst, jr_inst;
  657. int i;
  658. state->mcr = rd_reg32(&ctrl->mcr);
  659. state->scfgr = rd_reg32(&ctrl->scfgr);
  660. deco_inst = (rd_reg32(&ctrl->perfmon.cha_num_ms) &
  661. CHA_ID_MS_DECO_MASK) >> CHA_ID_MS_DECO_SHIFT;
  662. for (i = 0; i < deco_inst; i++) {
  663. state->deco_mid[i].liodn_ms =
  664. rd_reg32(&ctrl->deco_mid[i].liodn_ms);
  665. state->deco_mid[i].liodn_ls =
  666. rd_reg32(&ctrl->deco_mid[i].liodn_ls);
  667. }
  668. jr_inst = (rd_reg32(&ctrl->perfmon.cha_num_ms) &
  669. CHA_ID_MS_JR_MASK) >> CHA_ID_MS_JR_SHIFT;
  670. for (i = 0; i < jr_inst; i++) {
  671. state->jr_mid[i].liodn_ms =
  672. rd_reg32(&ctrl->jr_mid[i].liodn_ms);
  673. state->jr_mid[i].liodn_ls =
  674. rd_reg32(&ctrl->jr_mid[i].liodn_ls);
  675. }
  676. }
  677. static void caam_state_restore(const struct device *dev)
  678. {
  679. const struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  680. const struct caam_ctl_state *state = &ctrlpriv->state;
  681. struct caam_ctrl __iomem *ctrl = ctrlpriv->ctrl;
  682. u32 deco_inst, jr_inst;
  683. int i;
  684. wr_reg32(&ctrl->mcr, state->mcr);
  685. wr_reg32(&ctrl->scfgr, state->scfgr);
  686. deco_inst = (rd_reg32(&ctrl->perfmon.cha_num_ms) &
  687. CHA_ID_MS_DECO_MASK) >> CHA_ID_MS_DECO_SHIFT;
  688. for (i = 0; i < deco_inst; i++) {
  689. wr_reg32(&ctrl->deco_mid[i].liodn_ms,
  690. state->deco_mid[i].liodn_ms);
  691. wr_reg32(&ctrl->deco_mid[i].liodn_ls,
  692. state->deco_mid[i].liodn_ls);
  693. }
  694. jr_inst = (rd_reg32(&ctrl->perfmon.cha_num_ms) &
  695. CHA_ID_MS_JR_MASK) >> CHA_ID_MS_JR_SHIFT;
  696. for (i = 0; i < jr_inst; i++) {
  697. wr_reg32(&ctrl->jr_mid[i].liodn_ms,
  698. state->jr_mid[i].liodn_ms);
  699. wr_reg32(&ctrl->jr_mid[i].liodn_ls,
  700. state->jr_mid[i].liodn_ls);
  701. }
  702. if (ctrlpriv->virt_en == 1)
  703. clrsetbits_32(&ctrl->jrstart, 0, JRSTART_JR0_START |
  704. JRSTART_JR1_START | JRSTART_JR2_START |
  705. JRSTART_JR3_START);
  706. }
  707. static int caam_ctrl_suspend(struct device *dev)
  708. {
  709. const struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  710. if (ctrlpriv->caam_off_during_pm && !ctrlpriv->no_page0)
  711. caam_state_save(dev);
  712. return 0;
  713. }
  714. static int caam_ctrl_resume(struct device *dev)
  715. {
  716. struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev);
  717. int ret = 0;
  718. if (ctrlpriv->caam_off_during_pm && !ctrlpriv->no_page0) {
  719. caam_state_restore(dev);
  720. /* HW and rng will be reset so deinstantiation can be removed */
  721. devm_remove_action(dev, devm_deinstantiate_rng, dev);
  722. ret = caam_ctrl_rng_init(dev);
  723. }
  724. return ret;
  725. }
  726. static DEFINE_SIMPLE_DEV_PM_OPS(caam_ctrl_pm_ops, caam_ctrl_suspend, caam_ctrl_resume);
  727. /* Probe routine for CAAM top (controller) level */
  728. static int caam_probe(struct platform_device *pdev)
  729. {
  730. int ret, ring;
  731. u64 caam_id;
  732. const struct soc_device_attribute *imx_soc_match;
  733. struct device *dev;
  734. struct device_node *nprop, *np;
  735. struct caam_ctrl __iomem *ctrl;
  736. struct caam_drv_private *ctrlpriv;
  737. struct caam_perfmon __iomem *perfmon;
  738. struct dentry *dfs_root;
  739. u32 scfgr, comp_params;
  740. int pg_size;
  741. int BLOCK_OFFSET = 0;
  742. bool reg_access = true;
  743. const struct caam_imx_data *imx_soc_data;
  744. ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL);
  745. if (!ctrlpriv)
  746. return -ENOMEM;
  747. dev = &pdev->dev;
  748. dev_set_drvdata(dev, ctrlpriv);
  749. nprop = pdev->dev.of_node;
  750. imx_soc_match = soc_device_match(caam_imx_soc_table);
  751. if (!imx_soc_match && of_match_node(imx8m_machine_match, of_root))
  752. return -EPROBE_DEFER;
  753. caam_imx = (bool)imx_soc_match;
  754. ctrlpriv->caam_off_during_pm = caam_imx && caam_off_during_pm();
  755. if (imx_soc_match) {
  756. /*
  757. * Until Layerscape and i.MX OP-TEE get in sync,
  758. * only i.MX OP-TEE use cases disallow access to
  759. * caam page 0 (controller) registers.
  760. */
  761. np = of_find_compatible_node(NULL, NULL, "linaro,optee-tz");
  762. ctrlpriv->optee_en = !!np;
  763. of_node_put(np);
  764. reg_access = !ctrlpriv->optee_en;
  765. if (!imx_soc_match->data) {
  766. dev_err(dev, "No clock data provided for i.MX SoC");
  767. return -EINVAL;
  768. }
  769. imx_soc_data = imx_soc_match->data;
  770. reg_access = reg_access && imx_soc_data->page0_access;
  771. ctrlpriv->no_page0 = !reg_access;
  772. /*
  773. * CAAM clocks cannot be controlled from kernel.
  774. */
  775. if (!imx_soc_data->num_clks)
  776. goto iomap_ctrl;
  777. ret = init_clocks(dev, imx_soc_match->data);
  778. if (ret)
  779. return ret;
  780. }
  781. iomap_ctrl:
  782. /* Get configuration properties from device tree */
  783. /* First, get register page */
  784. ctrl = devm_of_iomap(dev, nprop, 0, NULL);
  785. ret = PTR_ERR_OR_ZERO(ctrl);
  786. if (ret) {
  787. dev_err(dev, "caam: of_iomap() failed\n");
  788. return ret;
  789. }
  790. ring = 0;
  791. for_each_available_child_of_node(nprop, np)
  792. if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
  793. of_device_is_compatible(np, "fsl,sec4.0-job-ring")) {
  794. u32 reg;
  795. if (of_property_read_u32_index(np, "reg", 0, &reg)) {
  796. dev_err(dev, "%s read reg property error\n",
  797. np->full_name);
  798. continue;
  799. }
  800. ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *)
  801. ((__force uint8_t *)ctrl + reg);
  802. ctrlpriv->total_jobrs++;
  803. ring++;
  804. }
  805. /*
  806. * Wherever possible, instead of accessing registers from the global page,
  807. * use the alias registers in the first (cf. DT nodes order)
  808. * job ring's page.
  809. */
  810. perfmon = ring ? (struct caam_perfmon __iomem *)&ctrlpriv->jr[0]->perfmon :
  811. (struct caam_perfmon __iomem *)&ctrl->perfmon;
  812. caam_little_end = !(bool)(rd_reg32(&perfmon->status) &
  813. (CSTA_PLEND | CSTA_ALT_PLEND));
  814. comp_params = rd_reg32(&perfmon->comp_parms_ms);
  815. if (reg_access && comp_params & CTPR_MS_PS &&
  816. rd_reg32(&ctrl->mcr) & MCFGR_LONG_PTR)
  817. caam_ptr_sz = sizeof(u64);
  818. else
  819. caam_ptr_sz = sizeof(u32);
  820. caam_dpaa2 = !!(comp_params & CTPR_MS_DPAA2);
  821. ctrlpriv->qi_present = !!(comp_params & CTPR_MS_QI_MASK);
  822. #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI
  823. /* If (DPAA 1.x) QI present, check whether dependencies are available */
  824. if (ctrlpriv->qi_present && !caam_dpaa2) {
  825. ret = qman_is_probed();
  826. if (!ret) {
  827. return -EPROBE_DEFER;
  828. } else if (ret < 0) {
  829. dev_err(dev, "failing probe due to qman probe error\n");
  830. return -ENODEV;
  831. }
  832. ret = qman_portals_probed();
  833. if (!ret) {
  834. return -EPROBE_DEFER;
  835. } else if (ret < 0) {
  836. dev_err(dev, "failing probe due to qman portals probe error\n");
  837. return -ENODEV;
  838. }
  839. }
  840. #endif
  841. /* Allocating the BLOCK_OFFSET based on the supported page size on
  842. * the platform
  843. */
  844. pg_size = (comp_params & CTPR_MS_PG_SZ_MASK) >> CTPR_MS_PG_SZ_SHIFT;
  845. if (pg_size == 0)
  846. BLOCK_OFFSET = PG_SIZE_4K;
  847. else
  848. BLOCK_OFFSET = PG_SIZE_64K;
  849. ctrlpriv->ctrl = (struct caam_ctrl __iomem __force *)ctrl;
  850. ctrlpriv->assure = (struct caam_assurance __iomem __force *)
  851. ((__force uint8_t *)ctrl +
  852. BLOCK_OFFSET * ASSURE_BLOCK_NUMBER
  853. );
  854. ctrlpriv->deco = (struct caam_deco __iomem __force *)
  855. ((__force uint8_t *)ctrl +
  856. BLOCK_OFFSET * DECO_BLOCK_NUMBER
  857. );
  858. /* Get the IRQ of the controller (for security violations only) */
  859. ctrlpriv->secvio_irq = irq_of_parse_and_map(nprop, 0);
  860. np = of_find_compatible_node(NULL, NULL, "fsl,qoriq-mc");
  861. ctrlpriv->mc_en = !!np;
  862. of_node_put(np);
  863. #ifdef CONFIG_FSL_MC_BUS
  864. if (ctrlpriv->mc_en) {
  865. struct fsl_mc_version *mc_version;
  866. mc_version = fsl_mc_get_version();
  867. if (mc_version)
  868. ctrlpriv->pr_support = check_version(mc_version, 10, 20,
  869. 0);
  870. else
  871. return -EPROBE_DEFER;
  872. }
  873. #endif
  874. if (!reg_access)
  875. goto set_dma_mask;
  876. /*
  877. * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
  878. * long pointers in master configuration register.
  879. * In case of SoCs with Management Complex, MC f/w performs
  880. * the configuration.
  881. */
  882. if (!ctrlpriv->mc_en)
  883. clrsetbits_32(&ctrl->mcr, MCFGR_AWCACHE_MASK,
  884. MCFGR_AWCACHE_CACH | MCFGR_AWCACHE_BUFF |
  885. MCFGR_WDENABLE | MCFGR_LARGE_BURST);
  886. handle_imx6_err005766(&ctrl->mcr);
  887. /*
  888. * Read the Compile Time parameters and SCFGR to determine
  889. * if virtualization is enabled for this platform
  890. */
  891. scfgr = rd_reg32(&ctrl->scfgr);
  892. ctrlpriv->virt_en = 0;
  893. if (comp_params & CTPR_MS_VIRT_EN_INCL) {
  894. /* VIRT_EN_INCL = 1 & VIRT_EN_POR = 1 or
  895. * VIRT_EN_INCL = 1 & VIRT_EN_POR = 0 & SCFGR_VIRT_EN = 1
  896. */
  897. if ((comp_params & CTPR_MS_VIRT_EN_POR) ||
  898. (!(comp_params & CTPR_MS_VIRT_EN_POR) &&
  899. (scfgr & SCFGR_VIRT_EN)))
  900. ctrlpriv->virt_en = 1;
  901. } else {
  902. /* VIRT_EN_INCL = 0 && VIRT_EN_POR_VALUE = 1 */
  903. if (comp_params & CTPR_MS_VIRT_EN_POR)
  904. ctrlpriv->virt_en = 1;
  905. }
  906. if (ctrlpriv->virt_en == 1)
  907. clrsetbits_32(&ctrl->jrstart, 0, JRSTART_JR0_START |
  908. JRSTART_JR1_START | JRSTART_JR2_START |
  909. JRSTART_JR3_START);
  910. set_dma_mask:
  911. ret = dma_set_mask_and_coherent(dev, caam_get_dma_mask(dev));
  912. if (ret) {
  913. dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret);
  914. return ret;
  915. }
  916. ctrlpriv->era = caam_get_era(perfmon);
  917. ctrlpriv->domain = iommu_get_domain_for_dev(dev);
  918. dfs_root = debugfs_create_dir(dev_name(dev), NULL);
  919. if (IS_ENABLED(CONFIG_DEBUG_FS)) {
  920. ret = devm_add_action_or_reset(dev, caam_remove_debugfs,
  921. dfs_root);
  922. if (ret)
  923. return ret;
  924. }
  925. caam_debugfs_init(ctrlpriv, perfmon, dfs_root);
  926. /* Check to see if (DPAA 1.x) QI present. If so, enable */
  927. if (ctrlpriv->qi_present && !caam_dpaa2) {
  928. ctrlpriv->qi = (struct caam_queue_if __iomem __force *)
  929. ((__force uint8_t *)ctrl +
  930. BLOCK_OFFSET * QI_BLOCK_NUMBER
  931. );
  932. /* This is all that's required to physically enable QI */
  933. wr_reg32(&ctrlpriv->qi->qi_control_lo, QICTL_DQEN);
  934. /* If QMAN driver is present, init CAAM-QI backend */
  935. #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI
  936. ret = caam_qi_init(pdev);
  937. if (ret)
  938. dev_err(dev, "caam qi i/f init failed: %d\n", ret);
  939. #endif
  940. }
  941. /* If no QI and no rings specified, quit and go home */
  942. if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
  943. dev_err(dev, "no queues configured, terminating\n");
  944. return -ENOMEM;
  945. }
  946. comp_params = rd_reg32(&perfmon->comp_parms_ls);
  947. ctrlpriv->blob_present = !!(comp_params & CTPR_LS_BLOB);
  948. /*
  949. * Some SoCs like the LS1028A (non-E) indicate CTPR_LS_BLOB support,
  950. * but fail when actually using it due to missing AES support, so
  951. * check both here.
  952. */
  953. if (ctrlpriv->era < 10) {
  954. ctrlpriv->blob_present = ctrlpriv->blob_present &&
  955. (rd_reg32(&perfmon->cha_num_ls) & CHA_ID_LS_AES_MASK);
  956. } else {
  957. struct version_regs __iomem *vreg;
  958. vreg = ctrlpriv->total_jobrs ?
  959. (struct version_regs __iomem *)&ctrlpriv->jr[0]->vreg :
  960. (struct version_regs __iomem *)&ctrl->vreg;
  961. ctrlpriv->blob_present = ctrlpriv->blob_present &&
  962. (rd_reg32(&vreg->aesa) & CHA_VER_MISC_AES_NUM_MASK);
  963. }
  964. if (reg_access) {
  965. ret = caam_ctrl_rng_init(dev);
  966. if (ret)
  967. return ret;
  968. }
  969. caam_id = (u64)rd_reg32(&perfmon->caam_id_ms) << 32 |
  970. (u64)rd_reg32(&perfmon->caam_id_ls);
  971. /* Report "alive" for developer to see */
  972. dev_info(dev, "device ID = 0x%016llx (Era %d)\n", caam_id,
  973. ctrlpriv->era);
  974. dev_info(dev, "job rings = %d, qi = %d\n",
  975. ctrlpriv->total_jobrs, ctrlpriv->qi_present);
  976. ret = devm_of_platform_populate(dev);
  977. if (ret)
  978. dev_err(dev, "JR platform devices creation error\n");
  979. return ret;
  980. }
  981. static struct platform_driver caam_driver = {
  982. .driver = {
  983. .name = "caam",
  984. .of_match_table = caam_match,
  985. .pm = pm_ptr(&caam_ctrl_pm_ops),
  986. },
  987. .probe = caam_probe,
  988. };
  989. module_platform_driver(caam_driver);
  990. MODULE_LICENSE("GPL");
  991. MODULE_DESCRIPTION("FSL CAAM request backend");
  992. MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");