ctrl.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. * CAAM control-plane driver backend
  3. * Controller-level driver, kernel property detection, initialization
  4. *
  5. * Copyright 2008-2012 Freescale Semiconductor, Inc.
  6. */
  7. #include <linux/of_address.h>
  8. #include <linux/of_irq.h>
  9. #include "compat.h"
  10. #include "regs.h"
  11. #include "intern.h"
  12. #include "jr.h"
  13. #include "desc_constr.h"
  14. #include "error.h"
  15. /*
  16. * Descriptor to instantiate RNG State Handle 0 in normal mode and
  17. * load the JDKEK, TDKEK and TDSK registers
  18. */
  19. static void build_instantiation_desc(u32 *desc, int handle, int do_sk)
  20. {
  21. u32 *jump_cmd, op_flags;
  22. init_job_desc(desc, 0);
  23. op_flags = OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
  24. (handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INIT;
  25. /* INIT RNG in non-test mode */
  26. append_operation(desc, op_flags);
  27. if (!handle && do_sk) {
  28. /*
  29. * For SH0, Secure Keys must be generated as well
  30. */
  31. /* wait for done */
  32. jump_cmd = append_jump(desc, JUMP_CLASS_CLASS1);
  33. set_jump_tgt_here(desc, jump_cmd);
  34. /*
  35. * load 1 to clear written reg:
  36. * resets the done interrrupt and returns the RNG to idle.
  37. */
  38. append_load_imm_u32(desc, 1, LDST_SRCDST_WORD_CLRW);
  39. /* Initialize State Handle */
  40. append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
  41. OP_ALG_AAI_RNG4_SK);
  42. }
  43. append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
  44. }
  45. /* Descriptor for deinstantiation of State Handle 0 of the RNG block. */
  46. static void build_deinstantiation_desc(u32 *desc, int handle)
  47. {
  48. init_job_desc(desc, 0);
  49. /* Uninstantiate State Handle 0 */
  50. append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
  51. (handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INITFINAL);
  52. append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
  53. }
  54. /*
  55. * run_descriptor_deco0 - runs a descriptor on DECO0, under direct control of
  56. * the software (no JR/QI used).
  57. * @ctrldev - pointer to device
  58. * @status - descriptor status, after being run
  59. *
  60. * Return: - 0 if no error occurred
  61. * - -ENODEV if the DECO couldn't be acquired
  62. * - -EAGAIN if an error occurred while executing the descriptor
  63. */
  64. static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc,
  65. u32 *status)
  66. {
  67. struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
  68. struct caam_full __iomem *topregs;
  69. unsigned int timeout = 100000;
  70. u32 deco_dbg_reg, flags;
  71. int i;
  72. /* Set the bit to request direct access to DECO0 */
  73. topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
  74. setbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);
  75. while (!(rd_reg32(&topregs->ctrl.deco_rq) & DECORR_DEN0) &&
  76. --timeout)
  77. cpu_relax();
  78. if (!timeout) {
  79. dev_err(ctrldev, "failed to acquire DECO 0\n");
  80. clrbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);
  81. return -ENODEV;
  82. }
  83. for (i = 0; i < desc_len(desc); i++)
  84. wr_reg32(&topregs->deco.descbuf[i], *(desc + i));
  85. flags = DECO_JQCR_WHL;
  86. /*
  87. * If the descriptor length is longer than 4 words, then the
  88. * FOUR bit in JRCTRL register must be set.
  89. */
  90. if (desc_len(desc) >= 4)
  91. flags |= DECO_JQCR_FOUR;
  92. /* Instruct the DECO to execute it */
  93. wr_reg32(&topregs->deco.jr_ctl_hi, flags);
  94. timeout = 10000000;
  95. do {
  96. deco_dbg_reg = rd_reg32(&topregs->deco.desc_dbg);
  97. /*
  98. * If an error occured in the descriptor, then
  99. * the DECO status field will be set to 0x0D
  100. */
  101. if ((deco_dbg_reg & DESC_DBG_DECO_STAT_MASK) ==
  102. DESC_DBG_DECO_STAT_HOST_ERR)
  103. break;
  104. cpu_relax();
  105. } while ((deco_dbg_reg & DESC_DBG_DECO_STAT_VALID) && --timeout);
  106. *status = rd_reg32(&topregs->deco.op_status_hi) &
  107. DECO_OP_STATUS_HI_ERR_MASK;
  108. /* Mark the DECO as free */
  109. clrbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);
  110. if (!timeout)
  111. return -EAGAIN;
  112. return 0;
  113. }
  114. /*
  115. * instantiate_rng - builds and executes a descriptor on DECO0,
  116. * which initializes the RNG block.
  117. * @ctrldev - pointer to device
  118. * @state_handle_mask - bitmask containing the instantiation status
  119. * for the RNG4 state handles which exist in
  120. * the RNG4 block: 1 if it's been instantiated
  121. * by an external entry, 0 otherwise.
  122. * @gen_sk - generate data to be loaded into the JDKEK, TDKEK and TDSK;
  123. * Caution: this can be done only once; if the keys need to be
  124. * regenerated, a POR is required
  125. *
  126. * Return: - 0 if no error occurred
  127. * - -ENOMEM if there isn't enough memory to allocate the descriptor
  128. * - -ENODEV if DECO0 couldn't be acquired
  129. * - -EAGAIN if an error occurred when executing the descriptor
  130. * f.i. there was a RNG hardware error due to not "good enough"
  131. * entropy being aquired.
  132. */
  133. static int instantiate_rng(struct device *ctrldev, int state_handle_mask,
  134. int gen_sk)
  135. {
  136. struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
  137. struct caam_full __iomem *topregs;
  138. struct rng4tst __iomem *r4tst;
  139. u32 *desc, status, rdsta_val;
  140. int ret = 0, sh_idx;
  141. topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
  142. r4tst = &topregs->ctrl.r4tst[0];
  143. desc = kmalloc(CAAM_CMD_SZ * 7, GFP_KERNEL);
  144. if (!desc)
  145. return -ENOMEM;
  146. for (sh_idx = 0; sh_idx < RNG4_MAX_HANDLES; sh_idx++) {
  147. /*
  148. * If the corresponding bit is set, this state handle
  149. * was initialized by somebody else, so it's left alone.
  150. */
  151. if ((1 << sh_idx) & state_handle_mask)
  152. continue;
  153. /* Create the descriptor for instantiating RNG State Handle */
  154. build_instantiation_desc(desc, sh_idx, gen_sk);
  155. /* Try to run it through DECO0 */
  156. ret = run_descriptor_deco0(ctrldev, desc, &status);
  157. /*
  158. * If ret is not 0, or descriptor status is not 0, then
  159. * something went wrong. No need to try the next state
  160. * handle (if available), bail out here.
  161. * Also, if for some reason, the State Handle didn't get
  162. * instantiated although the descriptor has finished
  163. * without any error (HW optimizations for later
  164. * CAAM eras), then try again.
  165. */
  166. rdsta_val =
  167. rd_reg32(&topregs->ctrl.r4tst[0].rdsta) & RDSTA_IFMASK;
  168. if (status || !(rdsta_val & (1 << sh_idx)))
  169. ret = -EAGAIN;
  170. if (ret)
  171. break;
  172. dev_info(ctrldev, "Instantiated RNG4 SH%d\n", sh_idx);
  173. /* Clear the contents before recreating the descriptor */
  174. memset(desc, 0x00, CAAM_CMD_SZ * 7);
  175. }
  176. kfree(desc);
  177. return ret;
  178. }
  179. /*
  180. * deinstantiate_rng - builds and executes a descriptor on DECO0,
  181. * which deinitializes the RNG block.
  182. * @ctrldev - pointer to device
  183. * @state_handle_mask - bitmask containing the instantiation status
  184. * for the RNG4 state handles which exist in
  185. * the RNG4 block: 1 if it's been instantiated
  186. *
  187. * Return: - 0 if no error occurred
  188. * - -ENOMEM if there isn't enough memory to allocate the descriptor
  189. * - -ENODEV if DECO0 couldn't be acquired
  190. * - -EAGAIN if an error occurred when executing the descriptor
  191. */
  192. static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask)
  193. {
  194. u32 *desc, status;
  195. int sh_idx, ret = 0;
  196. desc = kmalloc(CAAM_CMD_SZ * 3, GFP_KERNEL);
  197. if (!desc)
  198. return -ENOMEM;
  199. for (sh_idx = 0; sh_idx < RNG4_MAX_HANDLES; sh_idx++) {
  200. /*
  201. * If the corresponding bit is set, then it means the state
  202. * handle was initialized by us, and thus it needs to be
  203. * deintialized as well
  204. */
  205. if ((1 << sh_idx) & state_handle_mask) {
  206. /*
  207. * Create the descriptor for deinstantating this state
  208. * handle
  209. */
  210. build_deinstantiation_desc(desc, sh_idx);
  211. /* Try to run it through DECO0 */
  212. ret = run_descriptor_deco0(ctrldev, desc, &status);
  213. if (ret || status) {
  214. dev_err(ctrldev,
  215. "Failed to deinstantiate RNG4 SH%d\n",
  216. sh_idx);
  217. break;
  218. }
  219. dev_info(ctrldev, "Deinstantiated RNG4 SH%d\n", sh_idx);
  220. }
  221. }
  222. kfree(desc);
  223. return ret;
  224. }
  225. static int caam_remove(struct platform_device *pdev)
  226. {
  227. struct device *ctrldev;
  228. struct caam_drv_private *ctrlpriv;
  229. struct caam_full __iomem *topregs;
  230. int ring, ret = 0;
  231. ctrldev = &pdev->dev;
  232. ctrlpriv = dev_get_drvdata(ctrldev);
  233. topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
  234. /* Remove platform devices for JobRs */
  235. for (ring = 0; ring < ctrlpriv->total_jobrs; ring++) {
  236. if (ctrlpriv->jrpdev[ring])
  237. of_device_unregister(ctrlpriv->jrpdev[ring]);
  238. }
  239. /* De-initialize RNG state handles initialized by this driver. */
  240. if (ctrlpriv->rng4_sh_init)
  241. deinstantiate_rng(ctrldev, ctrlpriv->rng4_sh_init);
  242. /* Shut down debug views */
  243. #ifdef CONFIG_DEBUG_FS
  244. debugfs_remove_recursive(ctrlpriv->dfs_root);
  245. #endif
  246. /* Unmap controller region */
  247. iounmap(&topregs->ctrl);
  248. kfree(ctrlpriv->jrpdev);
  249. kfree(ctrlpriv);
  250. return ret;
  251. }
  252. /*
  253. * kick_trng - sets the various parameters for enabling the initialization
  254. * of the RNG4 block in CAAM
  255. * @pdev - pointer to the platform device
  256. * @ent_delay - Defines the length (in system clocks) of each entropy sample.
  257. */
  258. static void kick_trng(struct platform_device *pdev, int ent_delay)
  259. {
  260. struct device *ctrldev = &pdev->dev;
  261. struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
  262. struct caam_full __iomem *topregs;
  263. struct rng4tst __iomem *r4tst;
  264. u32 val;
  265. topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
  266. r4tst = &topregs->ctrl.r4tst[0];
  267. /* put RNG4 into program mode */
  268. setbits32(&r4tst->rtmctl, RTMCTL_PRGM);
  269. /*
  270. * Performance-wise, it does not make sense to
  271. * set the delay to a value that is lower
  272. * than the last one that worked (i.e. the state handles
  273. * were instantiated properly. Thus, instead of wasting
  274. * time trying to set the values controlling the sample
  275. * frequency, the function simply returns.
  276. */
  277. val = (rd_reg32(&r4tst->rtsdctl) & RTSDCTL_ENT_DLY_MASK)
  278. >> RTSDCTL_ENT_DLY_SHIFT;
  279. if (ent_delay <= val) {
  280. /* put RNG4 into run mode */
  281. clrbits32(&r4tst->rtmctl, RTMCTL_PRGM);
  282. return;
  283. }
  284. val = rd_reg32(&r4tst->rtsdctl);
  285. val = (val & ~RTSDCTL_ENT_DLY_MASK) |
  286. (ent_delay << RTSDCTL_ENT_DLY_SHIFT);
  287. wr_reg32(&r4tst->rtsdctl, val);
  288. /* min. freq. count, equal to 1/4 of the entropy sample length */
  289. wr_reg32(&r4tst->rtfrqmin, ent_delay >> 2);
  290. /* max. freq. count, equal to 8 times the entropy sample length */
  291. wr_reg32(&r4tst->rtfrqmax, ent_delay << 3);
  292. /* put RNG4 into run mode */
  293. clrbits32(&r4tst->rtmctl, RTMCTL_PRGM);
  294. }
  295. /**
  296. * caam_get_era() - Return the ERA of the SEC on SoC, based
  297. * on "sec-era" propery in the DTS. This property is updated by u-boot.
  298. **/
  299. int caam_get_era(void)
  300. {
  301. struct device_node *caam_node;
  302. for_each_compatible_node(caam_node, NULL, "fsl,sec-v4.0") {
  303. const uint32_t *prop = (uint32_t *)of_get_property(caam_node,
  304. "fsl,sec-era",
  305. NULL);
  306. return prop ? *prop : -ENOTSUPP;
  307. }
  308. return -ENOTSUPP;
  309. }
  310. EXPORT_SYMBOL(caam_get_era);
  311. /* Probe routine for CAAM top (controller) level */
  312. static int caam_probe(struct platform_device *pdev)
  313. {
  314. int ret, ring, rspec, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN;
  315. u64 caam_id;
  316. struct device *dev;
  317. struct device_node *nprop, *np;
  318. struct caam_ctrl __iomem *ctrl;
  319. struct caam_full __iomem *topregs;
  320. struct caam_drv_private *ctrlpriv;
  321. #ifdef CONFIG_DEBUG_FS
  322. struct caam_perfmon *perfmon;
  323. #endif
  324. u64 cha_vid;
  325. ctrlpriv = kzalloc(sizeof(struct caam_drv_private), GFP_KERNEL);
  326. if (!ctrlpriv)
  327. return -ENOMEM;
  328. dev = &pdev->dev;
  329. dev_set_drvdata(dev, ctrlpriv);
  330. ctrlpriv->pdev = pdev;
  331. nprop = pdev->dev.of_node;
  332. /* Get configuration properties from device tree */
  333. /* First, get register page */
  334. ctrl = of_iomap(nprop, 0);
  335. if (ctrl == NULL) {
  336. dev_err(dev, "caam: of_iomap() failed\n");
  337. return -ENOMEM;
  338. }
  339. ctrlpriv->ctrl = (struct caam_ctrl __force *)ctrl;
  340. /* topregs used to derive pointers to CAAM sub-blocks only */
  341. topregs = (struct caam_full __iomem *)ctrl;
  342. /* Get the IRQ of the controller (for security violations only) */
  343. ctrlpriv->secvio_irq = irq_of_parse_and_map(nprop, 0);
  344. /*
  345. * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
  346. * long pointers in master configuration register
  347. */
  348. setbits32(&topregs->ctrl.mcr, MCFGR_WDENABLE |
  349. (sizeof(dma_addr_t) == sizeof(u64) ? MCFGR_LONG_PTR : 0));
  350. if (sizeof(dma_addr_t) == sizeof(u64))
  351. if (of_device_is_compatible(nprop, "fsl,sec-v5.0"))
  352. dma_set_mask(dev, DMA_BIT_MASK(40));
  353. else
  354. dma_set_mask(dev, DMA_BIT_MASK(36));
  355. else
  356. dma_set_mask(dev, DMA_BIT_MASK(32));
  357. /*
  358. * Detect and enable JobRs
  359. * First, find out how many ring spec'ed, allocate references
  360. * for all, then go probe each one.
  361. */
  362. rspec = 0;
  363. for_each_available_child_of_node(nprop, np)
  364. if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
  365. of_device_is_compatible(np, "fsl,sec4.0-job-ring"))
  366. rspec++;
  367. ctrlpriv->jrpdev = kzalloc(sizeof(struct platform_device *) * rspec,
  368. GFP_KERNEL);
  369. if (ctrlpriv->jrpdev == NULL) {
  370. iounmap(&topregs->ctrl);
  371. return -ENOMEM;
  372. }
  373. ring = 0;
  374. ctrlpriv->total_jobrs = 0;
  375. for_each_available_child_of_node(nprop, np)
  376. if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
  377. of_device_is_compatible(np, "fsl,sec4.0-job-ring")) {
  378. ctrlpriv->jrpdev[ring] =
  379. of_platform_device_create(np, NULL, dev);
  380. if (!ctrlpriv->jrpdev[ring]) {
  381. pr_warn("JR%d Platform device creation error\n",
  382. ring);
  383. continue;
  384. }
  385. ctrlpriv->total_jobrs++;
  386. ring++;
  387. }
  388. /* Check to see if QI present. If so, enable */
  389. ctrlpriv->qi_present = !!(rd_reg64(&topregs->ctrl.perfmon.comp_parms) &
  390. CTPR_QI_MASK);
  391. if (ctrlpriv->qi_present) {
  392. ctrlpriv->qi = (struct caam_queue_if __force *)&topregs->qi;
  393. /* This is all that's required to physically enable QI */
  394. wr_reg32(&topregs->qi.qi_control_lo, QICTL_DQEN);
  395. }
  396. /* If no QI and no rings specified, quit and go home */
  397. if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
  398. dev_err(dev, "no queues configured, terminating\n");
  399. caam_remove(pdev);
  400. return -ENOMEM;
  401. }
  402. cha_vid = rd_reg64(&topregs->ctrl.perfmon.cha_id);
  403. /*
  404. * If SEC has RNG version >= 4 and RNG state handle has not been
  405. * already instantiated, do RNG instantiation
  406. */
  407. if ((cha_vid & CHA_ID_RNG_MASK) >> CHA_ID_RNG_SHIFT >= 4) {
  408. ctrlpriv->rng4_sh_init =
  409. rd_reg32(&topregs->ctrl.r4tst[0].rdsta);
  410. /*
  411. * If the secure keys (TDKEK, JDKEK, TDSK), were already
  412. * generated, signal this to the function that is instantiating
  413. * the state handles. An error would occur if RNG4 attempts
  414. * to regenerate these keys before the next POR.
  415. */
  416. gen_sk = ctrlpriv->rng4_sh_init & RDSTA_SKVN ? 0 : 1;
  417. ctrlpriv->rng4_sh_init &= RDSTA_IFMASK;
  418. do {
  419. int inst_handles =
  420. rd_reg32(&topregs->ctrl.r4tst[0].rdsta) &
  421. RDSTA_IFMASK;
  422. /*
  423. * If either SH were instantiated by somebody else
  424. * (e.g. u-boot) then it is assumed that the entropy
  425. * parameters are properly set and thus the function
  426. * setting these (kick_trng(...)) is skipped.
  427. * Also, if a handle was instantiated, do not change
  428. * the TRNG parameters.
  429. */
  430. if (!(ctrlpriv->rng4_sh_init || inst_handles)) {
  431. kick_trng(pdev, ent_delay);
  432. ent_delay += 400;
  433. }
  434. /*
  435. * if instantiate_rng(...) fails, the loop will rerun
  436. * and the kick_trng(...) function will modfiy the
  437. * upper and lower limits of the entropy sampling
  438. * interval, leading to a sucessful initialization of
  439. * the RNG.
  440. */
  441. ret = instantiate_rng(dev, inst_handles,
  442. gen_sk);
  443. } while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX));
  444. if (ret) {
  445. dev_err(dev, "failed to instantiate RNG");
  446. caam_remove(pdev);
  447. return ret;
  448. }
  449. /*
  450. * Set handles init'ed by this module as the complement of the
  451. * already initialized ones
  452. */
  453. ctrlpriv->rng4_sh_init = ~ctrlpriv->rng4_sh_init & RDSTA_IFMASK;
  454. /* Enable RDB bit so that RNG works faster */
  455. setbits32(&topregs->ctrl.scfgr, SCFGR_RDBENABLE);
  456. }
  457. /* NOTE: RTIC detection ought to go here, around Si time */
  458. caam_id = rd_reg64(&topregs->ctrl.perfmon.caam_id);
  459. /* Report "alive" for developer to see */
  460. dev_info(dev, "device ID = 0x%016llx (Era %d)\n", caam_id,
  461. caam_get_era());
  462. dev_info(dev, "job rings = %d, qi = %d\n",
  463. ctrlpriv->total_jobrs, ctrlpriv->qi_present);
  464. #ifdef CONFIG_DEBUG_FS
  465. /*
  466. * FIXME: needs better naming distinction, as some amalgamation of
  467. * "caam" and nprop->full_name. The OF name isn't distinctive,
  468. * but does separate instances
  469. */
  470. perfmon = (struct caam_perfmon __force *)&ctrl->perfmon;
  471. ctrlpriv->dfs_root = debugfs_create_dir("caam", NULL);
  472. ctrlpriv->ctl = debugfs_create_dir("ctl", ctrlpriv->dfs_root);
  473. /* Controller-level - performance monitor counters */
  474. ctrlpriv->ctl_rq_dequeued =
  475. debugfs_create_u64("rq_dequeued",
  476. S_IRUSR | S_IRGRP | S_IROTH,
  477. ctrlpriv->ctl, &perfmon->req_dequeued);
  478. ctrlpriv->ctl_ob_enc_req =
  479. debugfs_create_u64("ob_rq_encrypted",
  480. S_IRUSR | S_IRGRP | S_IROTH,
  481. ctrlpriv->ctl, &perfmon->ob_enc_req);
  482. ctrlpriv->ctl_ib_dec_req =
  483. debugfs_create_u64("ib_rq_decrypted",
  484. S_IRUSR | S_IRGRP | S_IROTH,
  485. ctrlpriv->ctl, &perfmon->ib_dec_req);
  486. ctrlpriv->ctl_ob_enc_bytes =
  487. debugfs_create_u64("ob_bytes_encrypted",
  488. S_IRUSR | S_IRGRP | S_IROTH,
  489. ctrlpriv->ctl, &perfmon->ob_enc_bytes);
  490. ctrlpriv->ctl_ob_prot_bytes =
  491. debugfs_create_u64("ob_bytes_protected",
  492. S_IRUSR | S_IRGRP | S_IROTH,
  493. ctrlpriv->ctl, &perfmon->ob_prot_bytes);
  494. ctrlpriv->ctl_ib_dec_bytes =
  495. debugfs_create_u64("ib_bytes_decrypted",
  496. S_IRUSR | S_IRGRP | S_IROTH,
  497. ctrlpriv->ctl, &perfmon->ib_dec_bytes);
  498. ctrlpriv->ctl_ib_valid_bytes =
  499. debugfs_create_u64("ib_bytes_validated",
  500. S_IRUSR | S_IRGRP | S_IROTH,
  501. ctrlpriv->ctl, &perfmon->ib_valid_bytes);
  502. /* Controller level - global status values */
  503. ctrlpriv->ctl_faultaddr =
  504. debugfs_create_u64("fault_addr",
  505. S_IRUSR | S_IRGRP | S_IROTH,
  506. ctrlpriv->ctl, &perfmon->faultaddr);
  507. ctrlpriv->ctl_faultdetail =
  508. debugfs_create_u32("fault_detail",
  509. S_IRUSR | S_IRGRP | S_IROTH,
  510. ctrlpriv->ctl, &perfmon->faultdetail);
  511. ctrlpriv->ctl_faultstatus =
  512. debugfs_create_u32("fault_status",
  513. S_IRUSR | S_IRGRP | S_IROTH,
  514. ctrlpriv->ctl, &perfmon->status);
  515. /* Internal covering keys (useful in non-secure mode only) */
  516. ctrlpriv->ctl_kek_wrap.data = &ctrlpriv->ctrl->kek[0];
  517. ctrlpriv->ctl_kek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
  518. ctrlpriv->ctl_kek = debugfs_create_blob("kek",
  519. S_IRUSR |
  520. S_IRGRP | S_IROTH,
  521. ctrlpriv->ctl,
  522. &ctrlpriv->ctl_kek_wrap);
  523. ctrlpriv->ctl_tkek_wrap.data = &ctrlpriv->ctrl->tkek[0];
  524. ctrlpriv->ctl_tkek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
  525. ctrlpriv->ctl_tkek = debugfs_create_blob("tkek",
  526. S_IRUSR |
  527. S_IRGRP | S_IROTH,
  528. ctrlpriv->ctl,
  529. &ctrlpriv->ctl_tkek_wrap);
  530. ctrlpriv->ctl_tdsk_wrap.data = &ctrlpriv->ctrl->tdsk[0];
  531. ctrlpriv->ctl_tdsk_wrap.size = KEK_KEY_SIZE * sizeof(u32);
  532. ctrlpriv->ctl_tdsk = debugfs_create_blob("tdsk",
  533. S_IRUSR |
  534. S_IRGRP | S_IROTH,
  535. ctrlpriv->ctl,
  536. &ctrlpriv->ctl_tdsk_wrap);
  537. #endif
  538. return 0;
  539. }
  540. static struct of_device_id caam_match[] = {
  541. {
  542. .compatible = "fsl,sec-v4.0",
  543. },
  544. {
  545. .compatible = "fsl,sec4.0",
  546. },
  547. {},
  548. };
  549. MODULE_DEVICE_TABLE(of, caam_match);
  550. static struct platform_driver caam_driver = {
  551. .driver = {
  552. .name = "caam",
  553. .owner = THIS_MODULE,
  554. .of_match_table = caam_match,
  555. },
  556. .probe = caam_probe,
  557. .remove = caam_remove,
  558. };
  559. module_platform_driver(caam_driver);
  560. MODULE_LICENSE("GPL");
  561. MODULE_DESCRIPTION("FSL CAAM request backend");
  562. MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");