1 // SPDX-License-Identifier: GPL-2.0+
2 /* * CAAM control-plane driver backend
3 * Controller-level driver, kernel property detection, initialization
5 * Copyright 2008-2012 Freescale Semiconductor, Inc.
8 #include <linux/device.h>
9 #include <linux/of_address.h>
10 #include <linux/of_irq.h>
11 #include <linux/sys_soc.h>
17 #include "desc_constr.h"
21 EXPORT_SYMBOL(caam_little_end);
23 EXPORT_SYMBOL(caam_dpaa2);
25 EXPORT_SYMBOL(caam_imx);
32 * i.MX targets tend to have clock control subsystems that can
33 * enable/disable clocking to our device.
35 static inline struct clk *caam_drv_identify_clk(struct device *dev,
38 return caam_imx ? devm_clk_get(dev, clk_name) : NULL;
42 * Descriptor to instantiate RNG State Handle 0 in normal mode and
43 * load the JDKEK, TDKEK and TDSK registers
45 static void build_instantiation_desc(u32 *desc, int handle, int do_sk)
47 u32 *jump_cmd, op_flags;
49 init_job_desc(desc, 0);
51 op_flags = OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
52 (handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INIT;
54 /* INIT RNG in non-test mode */
55 append_operation(desc, op_flags);
57 if (!handle && do_sk) {
59 * For SH0, Secure Keys must be generated as well
63 jump_cmd = append_jump(desc, JUMP_CLASS_CLASS1);
64 set_jump_tgt_here(desc, jump_cmd);
67 * load 1 to clear written reg:
68 * resets the done interrrupt and returns the RNG to idle.
70 append_load_imm_u32(desc, 1, LDST_SRCDST_WORD_CLRW);
72 /* Initialize State Handle */
73 append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
77 append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
80 /* Descriptor for deinstantiation of State Handle 0 of the RNG block. */
81 static void build_deinstantiation_desc(u32 *desc, int handle)
83 init_job_desc(desc, 0);
85 /* Uninstantiate State Handle 0 */
86 append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
87 (handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INITFINAL);
89 append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
93 * run_descriptor_deco0 - runs a descriptor on DECO0, under direct control of
94 * the software (no JR/QI used).
95 * @ctrldev - pointer to device
96 * @status - descriptor status, after being run
98 * Return: - 0 if no error occurred
99 * - -ENODEV if the DECO couldn't be acquired
100 * - -EAGAIN if an error occurred while executing the descriptor
102 static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc,
105 struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
106 struct caam_ctrl __iomem *ctrl = ctrlpriv->ctrl;
107 struct caam_deco __iomem *deco = ctrlpriv->deco;
108 unsigned int timeout = 100000;
109 u32 deco_dbg_reg, flags;
113 if (ctrlpriv->virt_en == 1) {
114 clrsetbits_32(&ctrl->deco_rsr, 0, DECORSR_JR0);
116 while (!(rd_reg32(&ctrl->deco_rsr) & DECORSR_VALID) &&
123 clrsetbits_32(&ctrl->deco_rq, 0, DECORR_RQD0ENABLE);
125 while (!(rd_reg32(&ctrl->deco_rq) & DECORR_DEN0) &&
130 dev_err(ctrldev, "failed to acquire DECO 0\n");
131 clrsetbits_32(&ctrl->deco_rq, DECORR_RQD0ENABLE, 0);
135 for (i = 0; i < desc_len(desc); i++)
136 wr_reg32(&deco->descbuf[i], caam32_to_cpu(*(desc + i)));
138 flags = DECO_JQCR_WHL;
140 * If the descriptor length is longer than 4 words, then the
141 * FOUR bit in JRCTRL register must be set.
143 if (desc_len(desc) >= 4)
144 flags |= DECO_JQCR_FOUR;
146 /* Instruct the DECO to execute it */
147 clrsetbits_32(&deco->jr_ctl_hi, 0, flags);
151 deco_dbg_reg = rd_reg32(&deco->desc_dbg);
153 * If an error occured in the descriptor, then
154 * the DECO status field will be set to 0x0D
156 if ((deco_dbg_reg & DESC_DBG_DECO_STAT_MASK) ==
157 DESC_DBG_DECO_STAT_HOST_ERR)
160 } while ((deco_dbg_reg & DESC_DBG_DECO_STAT_VALID) && --timeout);
162 *status = rd_reg32(&deco->op_status_hi) &
163 DECO_OP_STATUS_HI_ERR_MASK;
165 if (ctrlpriv->virt_en == 1)
166 clrsetbits_32(&ctrl->deco_rsr, DECORSR_JR0, 0);
168 /* Mark the DECO as free */
169 clrsetbits_32(&ctrl->deco_rq, DECORR_RQD0ENABLE, 0);
178 * instantiate_rng - builds and executes a descriptor on DECO0,
179 * which initializes the RNG block.
180 * @ctrldev - pointer to device
181 * @state_handle_mask - bitmask containing the instantiation status
182 * for the RNG4 state handles which exist in
183 * the RNG4 block: 1 if it's been instantiated
184 * by an external entry, 0 otherwise.
185 * @gen_sk - generate data to be loaded into the JDKEK, TDKEK and TDSK;
186 * Caution: this can be done only once; if the keys need to be
187 * regenerated, a POR is required
189 * Return: - 0 if no error occurred
190 * - -ENOMEM if there isn't enough memory to allocate the descriptor
191 * - -ENODEV if DECO0 couldn't be acquired
192 * - -EAGAIN if an error occurred when executing the descriptor
193 * f.i. there was a RNG hardware error due to not "good enough"
194 * entropy being aquired.
196 static int instantiate_rng(struct device *ctrldev, int state_handle_mask,
199 struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
200 struct caam_ctrl __iomem *ctrl;
201 u32 *desc, status = 0, rdsta_val;
204 ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl;
205 desc = kmalloc(CAAM_CMD_SZ * 7, GFP_KERNEL);
209 for (sh_idx = 0; sh_idx < RNG4_MAX_HANDLES; sh_idx++) {
211 * If the corresponding bit is set, this state handle
212 * was initialized by somebody else, so it's left alone.
214 if ((1 << sh_idx) & state_handle_mask)
217 /* Create the descriptor for instantiating RNG State Handle */
218 build_instantiation_desc(desc, sh_idx, gen_sk);
220 /* Try to run it through DECO0 */
221 ret = run_descriptor_deco0(ctrldev, desc, &status);
224 * If ret is not 0, or descriptor status is not 0, then
225 * something went wrong. No need to try the next state
226 * handle (if available), bail out here.
227 * Also, if for some reason, the State Handle didn't get
228 * instantiated although the descriptor has finished
229 * without any error (HW optimizations for later
230 * CAAM eras), then try again.
235 rdsta_val = rd_reg32(&ctrl->r4tst[0].rdsta) & RDSTA_IFMASK;
236 if ((status && status != JRSTA_SSRC_JUMP_HALT_CC) ||
237 !(rdsta_val & (1 << sh_idx))) {
242 dev_info(ctrldev, "Instantiated RNG4 SH%d\n", sh_idx);
243 /* Clear the contents before recreating the descriptor */
244 memset(desc, 0x00, CAAM_CMD_SZ * 7);
253 * deinstantiate_rng - builds and executes a descriptor on DECO0,
254 * which deinitializes the RNG block.
255 * @ctrldev - pointer to device
256 * @state_handle_mask - bitmask containing the instantiation status
257 * for the RNG4 state handles which exist in
258 * the RNG4 block: 1 if it's been instantiated
260 * Return: - 0 if no error occurred
261 * - -ENOMEM if there isn't enough memory to allocate the descriptor
262 * - -ENODEV if DECO0 couldn't be acquired
263 * - -EAGAIN if an error occurred when executing the descriptor
265 static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask)
270 desc = kmalloc(CAAM_CMD_SZ * 3, GFP_KERNEL);
274 for (sh_idx = 0; sh_idx < RNG4_MAX_HANDLES; sh_idx++) {
276 * If the corresponding bit is set, then it means the state
277 * handle was initialized by us, and thus it needs to be
278 * deinitialized as well
280 if ((1 << sh_idx) & state_handle_mask) {
282 * Create the descriptor for deinstantating this state
285 build_deinstantiation_desc(desc, sh_idx);
287 /* Try to run it through DECO0 */
288 ret = run_descriptor_deco0(ctrldev, desc, &status);
291 (status && status != JRSTA_SSRC_JUMP_HALT_CC)) {
293 "Failed to deinstantiate RNG4 SH%d\n",
297 dev_info(ctrldev, "Deinstantiated RNG4 SH%d\n", sh_idx);
306 static int caam_remove(struct platform_device *pdev)
308 struct device *ctrldev;
309 struct caam_drv_private *ctrlpriv;
310 struct caam_ctrl __iomem *ctrl;
312 ctrldev = &pdev->dev;
313 ctrlpriv = dev_get_drvdata(ctrldev);
314 ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl;
316 /* Remove platform devices under the crypto node */
317 of_platform_depopulate(ctrldev);
319 #ifdef CONFIG_CAAM_QI
321 caam_qi_shutdown(ctrlpriv->qidev);
325 * De-initialize RNG state handles initialized by this driver.
326 * In case of SoCs with Management Complex, RNG is managed by MC f/w.
328 if (!ctrlpriv->mc_en && ctrlpriv->rng4_sh_init)
329 deinstantiate_rng(ctrldev, ctrlpriv->rng4_sh_init);
331 /* Shut down debug views */
332 #ifdef CONFIG_DEBUG_FS
333 debugfs_remove_recursive(ctrlpriv->dfs_root);
336 /* Unmap controller region */
339 /* shut clocks off before finalizing shutdown */
340 clk_disable_unprepare(ctrlpriv->caam_ipg);
341 if (ctrlpriv->caam_mem)
342 clk_disable_unprepare(ctrlpriv->caam_mem);
343 clk_disable_unprepare(ctrlpriv->caam_aclk);
344 if (ctrlpriv->caam_emi_slow)
345 clk_disable_unprepare(ctrlpriv->caam_emi_slow);
350 * kick_trng - sets the various parameters for enabling the initialization
351 * of the RNG4 block in CAAM
352 * @pdev - pointer to the platform device
353 * @ent_delay - Defines the length (in system clocks) of each entropy sample.
355 static void kick_trng(struct platform_device *pdev, int ent_delay)
357 struct device *ctrldev = &pdev->dev;
358 struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
359 struct caam_ctrl __iomem *ctrl;
360 struct rng4tst __iomem *r4tst;
363 ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl;
364 r4tst = &ctrl->r4tst[0];
366 /* put RNG4 into program mode */
367 clrsetbits_32(&r4tst->rtmctl, 0, RTMCTL_PRGM);
370 * Performance-wise, it does not make sense to
371 * set the delay to a value that is lower
372 * than the last one that worked (i.e. the state handles
373 * were instantiated properly. Thus, instead of wasting
374 * time trying to set the values controlling the sample
375 * frequency, the function simply returns.
377 val = (rd_reg32(&r4tst->rtsdctl) & RTSDCTL_ENT_DLY_MASK)
378 >> RTSDCTL_ENT_DLY_SHIFT;
379 if (ent_delay <= val)
382 val = rd_reg32(&r4tst->rtsdctl);
383 val = (val & ~RTSDCTL_ENT_DLY_MASK) |
384 (ent_delay << RTSDCTL_ENT_DLY_SHIFT);
385 wr_reg32(&r4tst->rtsdctl, val);
386 /* min. freq. count, equal to 1/4 of the entropy sample length */
387 wr_reg32(&r4tst->rtfrqmin, ent_delay >> 2);
388 /* disable maximum frequency count */
389 wr_reg32(&r4tst->rtfrqmax, RTFRQMAX_DISABLE);
390 /* read the control register */
391 val = rd_reg32(&r4tst->rtmctl);
394 * select raw sampling in both entropy shifter
395 * and statistical checker; ; put RNG4 into run mode
397 clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM, RTMCTL_SAMP_MODE_RAW_ES_SC);
400 static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl)
402 static const struct {
426 ccbvid = rd_reg32(&ctrl->perfmon.ccb_id);
427 era = (ccbvid & CCBVID_ERA_MASK) >> CCBVID_ERA_SHIFT;
428 if (era) /* This is '0' prior to CAAM ERA-6 */
431 id_ms = rd_reg32(&ctrl->perfmon.caam_id_ms);
432 ip_id = (id_ms & SECVID_MS_IPID_MASK) >> SECVID_MS_IPID_SHIFT;
433 maj_rev = (id_ms & SECVID_MS_MAJ_REV_MASK) >> SECVID_MS_MAJ_REV_SHIFT;
435 for (i = 0; i < ARRAY_SIZE(id); i++)
436 if (id[i].ip_id == ip_id && id[i].maj_rev == maj_rev)
443 * caam_get_era() - Return the ERA of the SEC on SoC, based
444 * on "sec-era" optional property in the DTS. This property is updated
446 * In case this property is not passed an attempt to retrieve the CAAM
447 * era via register reads will be made.
449 static int caam_get_era(struct caam_ctrl __iomem *ctrl)
451 struct device_node *caam_node;
455 caam_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
456 ret = of_property_read_u32(caam_node, "fsl,sec-era", &prop);
457 of_node_put(caam_node);
462 return caam_get_era_from_hw(ctrl);
465 static const struct of_device_id caam_match[] = {
467 .compatible = "fsl,sec-v4.0",
470 .compatible = "fsl,sec4.0",
474 MODULE_DEVICE_TABLE(of, caam_match);
476 /* Probe routine for CAAM top (controller) level */
477 static int caam_probe(struct platform_device *pdev)
479 int ret, ring, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN;
481 static const struct soc_device_attribute imx_soc[] = {
482 {.family = "Freescale i.MX"},
486 struct device_node *nprop, *np;
487 struct caam_ctrl __iomem *ctrl;
488 struct caam_drv_private *ctrlpriv;
490 #ifdef CONFIG_DEBUG_FS
491 struct caam_perfmon *perfmon;
493 u32 scfgr, comp_params;
496 int BLOCK_OFFSET = 0;
498 ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL);
503 dev_set_drvdata(dev, ctrlpriv);
504 nprop = pdev->dev.of_node;
506 caam_imx = (bool)soc_device_match(imx_soc);
508 /* Enable clocking */
509 clk = caam_drv_identify_clk(&pdev->dev, "ipg");
513 "can't identify CAAM ipg clk: %d\n", ret);
516 ctrlpriv->caam_ipg = clk;
518 if (!of_machine_is_compatible("fsl,imx7d") &&
519 !of_machine_is_compatible("fsl,imx7s")) {
520 clk = caam_drv_identify_clk(&pdev->dev, "mem");
524 "can't identify CAAM mem clk: %d\n", ret);
527 ctrlpriv->caam_mem = clk;
530 clk = caam_drv_identify_clk(&pdev->dev, "aclk");
534 "can't identify CAAM aclk clk: %d\n", ret);
537 ctrlpriv->caam_aclk = clk;
539 if (!of_machine_is_compatible("fsl,imx6ul") &&
540 !of_machine_is_compatible("fsl,imx7d") &&
541 !of_machine_is_compatible("fsl,imx7s")) {
542 clk = caam_drv_identify_clk(&pdev->dev, "emi_slow");
546 "can't identify CAAM emi_slow clk: %d\n", ret);
549 ctrlpriv->caam_emi_slow = clk;
552 ret = clk_prepare_enable(ctrlpriv->caam_ipg);
554 dev_err(&pdev->dev, "can't enable CAAM ipg clock: %d\n", ret);
558 if (ctrlpriv->caam_mem) {
559 ret = clk_prepare_enable(ctrlpriv->caam_mem);
561 dev_err(&pdev->dev, "can't enable CAAM secure mem clock: %d\n",
563 goto disable_caam_ipg;
567 ret = clk_prepare_enable(ctrlpriv->caam_aclk);
569 dev_err(&pdev->dev, "can't enable CAAM aclk clock: %d\n", ret);
570 goto disable_caam_mem;
573 if (ctrlpriv->caam_emi_slow) {
574 ret = clk_prepare_enable(ctrlpriv->caam_emi_slow);
576 dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n",
578 goto disable_caam_aclk;
582 /* Get configuration properties from device tree */
583 /* First, get register page */
584 ctrl = of_iomap(nprop, 0);
586 dev_err(dev, "caam: of_iomap() failed\n");
588 goto disable_caam_emi_slow;
591 caam_little_end = !(bool)(rd_reg32(&ctrl->perfmon.status) &
592 (CSTA_PLEND | CSTA_ALT_PLEND));
594 /* Finding the page size for using the CTPR_MS register */
595 comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ms);
596 pg_size = (comp_params & CTPR_MS_PG_SZ_MASK) >> CTPR_MS_PG_SZ_SHIFT;
598 /* Allocating the BLOCK_OFFSET based on the supported page size on
602 BLOCK_OFFSET = PG_SIZE_4K;
604 BLOCK_OFFSET = PG_SIZE_64K;
606 ctrlpriv->ctrl = (struct caam_ctrl __iomem __force *)ctrl;
607 ctrlpriv->assure = (struct caam_assurance __iomem __force *)
608 ((__force uint8_t *)ctrl +
609 BLOCK_OFFSET * ASSURE_BLOCK_NUMBER
611 ctrlpriv->deco = (struct caam_deco __iomem __force *)
612 ((__force uint8_t *)ctrl +
613 BLOCK_OFFSET * DECO_BLOCK_NUMBER
616 /* Get the IRQ of the controller (for security violations only) */
617 ctrlpriv->secvio_irq = irq_of_parse_and_map(nprop, 0);
620 * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
621 * long pointers in master configuration register.
622 * In case of SoCs with Management Complex, MC f/w performs
625 caam_dpaa2 = !!(comp_params & CTPR_MS_DPAA2);
626 np = of_find_compatible_node(NULL, NULL, "fsl,qoriq-mc");
627 ctrlpriv->mc_en = !!np;
630 if (!ctrlpriv->mc_en)
631 clrsetbits_32(&ctrl->mcr, MCFGR_AWCACHE_MASK | MCFGR_LONG_PTR,
632 MCFGR_AWCACHE_CACH | MCFGR_AWCACHE_BUFF |
633 MCFGR_WDENABLE | MCFGR_LARGE_BURST |
634 (sizeof(dma_addr_t) == sizeof(u64) ?
635 MCFGR_LONG_PTR : 0));
638 * Read the Compile Time paramters and SCFGR to determine
639 * if Virtualization is enabled for this platform
641 scfgr = rd_reg32(&ctrl->scfgr);
643 ctrlpriv->virt_en = 0;
644 if (comp_params & CTPR_MS_VIRT_EN_INCL) {
645 /* VIRT_EN_INCL = 1 & VIRT_EN_POR = 1 or
646 * VIRT_EN_INCL = 1 & VIRT_EN_POR = 0 & SCFGR_VIRT_EN = 1
648 if ((comp_params & CTPR_MS_VIRT_EN_POR) ||
649 (!(comp_params & CTPR_MS_VIRT_EN_POR) &&
650 (scfgr & SCFGR_VIRT_EN)))
651 ctrlpriv->virt_en = 1;
653 /* VIRT_EN_INCL = 0 && VIRT_EN_POR_VALUE = 1 */
654 if (comp_params & CTPR_MS_VIRT_EN_POR)
655 ctrlpriv->virt_en = 1;
658 if (ctrlpriv->virt_en == 1)
659 clrsetbits_32(&ctrl->jrstart, 0, JRSTART_JR0_START |
660 JRSTART_JR1_START | JRSTART_JR2_START |
663 if (sizeof(dma_addr_t) == sizeof(u64)) {
665 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(49));
666 else if (of_device_is_compatible(nprop, "fsl,sec-v5.0"))
667 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(40));
669 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(36));
671 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
674 dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret);
678 ctrlpriv->era = caam_get_era(ctrl);
680 ret = of_platform_populate(nprop, caam_match, NULL, dev);
682 dev_err(dev, "JR platform devices creation error\n");
686 #ifdef CONFIG_DEBUG_FS
688 * FIXME: needs better naming distinction, as some amalgamation of
689 * "caam" and nprop->full_name. The OF name isn't distinctive,
690 * but does separate instances
692 perfmon = (struct caam_perfmon __force *)&ctrl->perfmon;
694 ctrlpriv->dfs_root = debugfs_create_dir(dev_name(dev), NULL);
695 ctrlpriv->ctl = debugfs_create_dir("ctl", ctrlpriv->dfs_root);
699 for_each_available_child_of_node(nprop, np)
700 if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
701 of_device_is_compatible(np, "fsl,sec4.0-job-ring")) {
702 ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *)
703 ((__force uint8_t *)ctrl +
704 (ring + JR_BLOCK_NUMBER) *
707 ctrlpriv->total_jobrs++;
711 /* Check to see if (DPAA 1.x) QI present. If so, enable */
712 ctrlpriv->qi_present = !!(comp_params & CTPR_MS_QI_MASK);
713 if (ctrlpriv->qi_present && !caam_dpaa2) {
714 ctrlpriv->qi = (struct caam_queue_if __iomem __force *)
715 ((__force uint8_t *)ctrl +
716 BLOCK_OFFSET * QI_BLOCK_NUMBER
718 /* This is all that's required to physically enable QI */
719 wr_reg32(&ctrlpriv->qi->qi_control_lo, QICTL_DQEN);
721 /* If QMAN driver is present, init CAAM-QI backend */
722 #ifdef CONFIG_CAAM_QI
723 ret = caam_qi_init(pdev);
725 dev_err(dev, "caam qi i/f init failed: %d\n", ret);
729 /* If no QI and no rings specified, quit and go home */
730 if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
731 dev_err(dev, "no queues configured, terminating\n");
736 cha_vid_ls = rd_reg32(&ctrl->perfmon.cha_id_ls);
739 * If SEC has RNG version >= 4 and RNG state handle has not been
740 * already instantiated, do RNG instantiation
741 * In case of SoCs with Management Complex, RNG is managed by MC f/w.
743 if (!ctrlpriv->mc_en &&
744 (cha_vid_ls & CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT >= 4) {
745 ctrlpriv->rng4_sh_init =
746 rd_reg32(&ctrl->r4tst[0].rdsta);
748 * If the secure keys (TDKEK, JDKEK, TDSK), were already
749 * generated, signal this to the function that is instantiating
750 * the state handles. An error would occur if RNG4 attempts
751 * to regenerate these keys before the next POR.
753 gen_sk = ctrlpriv->rng4_sh_init & RDSTA_SKVN ? 0 : 1;
754 ctrlpriv->rng4_sh_init &= RDSTA_IFMASK;
757 rd_reg32(&ctrl->r4tst[0].rdsta) &
760 * If either SH were instantiated by somebody else
761 * (e.g. u-boot) then it is assumed that the entropy
762 * parameters are properly set and thus the function
763 * setting these (kick_trng(...)) is skipped.
764 * Also, if a handle was instantiated, do not change
765 * the TRNG parameters.
767 if (!(ctrlpriv->rng4_sh_init || inst_handles)) {
769 "Entropy delay = %u\n",
771 kick_trng(pdev, ent_delay);
775 * if instantiate_rng(...) fails, the loop will rerun
776 * and the kick_trng(...) function will modfiy the
777 * upper and lower limits of the entropy sampling
778 * interval, leading to a sucessful initialization of
781 ret = instantiate_rng(dev, inst_handles,
785 * if here, the loop will rerun,
786 * so don't hog the CPU
789 } while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX));
791 dev_err(dev, "failed to instantiate RNG");
795 * Set handles init'ed by this module as the complement of the
796 * already initialized ones
798 ctrlpriv->rng4_sh_init = ~ctrlpriv->rng4_sh_init & RDSTA_IFMASK;
800 /* Enable RDB bit so that RNG works faster */
801 clrsetbits_32(&ctrl->scfgr, 0, SCFGR_RDBENABLE);
804 /* NOTE: RTIC detection ought to go here, around Si time */
806 caam_id = (u64)rd_reg32(&ctrl->perfmon.caam_id_ms) << 32 |
807 (u64)rd_reg32(&ctrl->perfmon.caam_id_ls);
809 /* Report "alive" for developer to see */
810 dev_info(dev, "device ID = 0x%016llx (Era %d)\n", caam_id,
812 dev_info(dev, "job rings = %d, qi = %d\n",
813 ctrlpriv->total_jobrs, ctrlpriv->qi_present);
815 #ifdef CONFIG_DEBUG_FS
816 debugfs_create_file("rq_dequeued", S_IRUSR | S_IRGRP | S_IROTH,
817 ctrlpriv->ctl, &perfmon->req_dequeued,
819 debugfs_create_file("ob_rq_encrypted", S_IRUSR | S_IRGRP | S_IROTH,
820 ctrlpriv->ctl, &perfmon->ob_enc_req,
822 debugfs_create_file("ib_rq_decrypted", S_IRUSR | S_IRGRP | S_IROTH,
823 ctrlpriv->ctl, &perfmon->ib_dec_req,
825 debugfs_create_file("ob_bytes_encrypted", S_IRUSR | S_IRGRP | S_IROTH,
826 ctrlpriv->ctl, &perfmon->ob_enc_bytes,
828 debugfs_create_file("ob_bytes_protected", S_IRUSR | S_IRGRP | S_IROTH,
829 ctrlpriv->ctl, &perfmon->ob_prot_bytes,
831 debugfs_create_file("ib_bytes_decrypted", S_IRUSR | S_IRGRP | S_IROTH,
832 ctrlpriv->ctl, &perfmon->ib_dec_bytes,
834 debugfs_create_file("ib_bytes_validated", S_IRUSR | S_IRGRP | S_IROTH,
835 ctrlpriv->ctl, &perfmon->ib_valid_bytes,
838 /* Controller level - global status values */
839 debugfs_create_file("fault_addr", S_IRUSR | S_IRGRP | S_IROTH,
840 ctrlpriv->ctl, &perfmon->faultaddr,
842 debugfs_create_file("fault_detail", S_IRUSR | S_IRGRP | S_IROTH,
843 ctrlpriv->ctl, &perfmon->faultdetail,
845 debugfs_create_file("fault_status", S_IRUSR | S_IRGRP | S_IROTH,
846 ctrlpriv->ctl, &perfmon->status,
849 /* Internal covering keys (useful in non-secure mode only) */
850 ctrlpriv->ctl_kek_wrap.data = (__force void *)&ctrlpriv->ctrl->kek[0];
851 ctrlpriv->ctl_kek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
852 ctrlpriv->ctl_kek = debugfs_create_blob("kek",
856 &ctrlpriv->ctl_kek_wrap);
858 ctrlpriv->ctl_tkek_wrap.data = (__force void *)&ctrlpriv->ctrl->tkek[0];
859 ctrlpriv->ctl_tkek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
860 ctrlpriv->ctl_tkek = debugfs_create_blob("tkek",
864 &ctrlpriv->ctl_tkek_wrap);
866 ctrlpriv->ctl_tdsk_wrap.data = (__force void *)&ctrlpriv->ctrl->tdsk[0];
867 ctrlpriv->ctl_tdsk_wrap.size = KEK_KEY_SIZE * sizeof(u32);
868 ctrlpriv->ctl_tdsk = debugfs_create_blob("tdsk",
872 &ctrlpriv->ctl_tdsk_wrap);
882 disable_caam_emi_slow:
883 if (ctrlpriv->caam_emi_slow)
884 clk_disable_unprepare(ctrlpriv->caam_emi_slow);
886 clk_disable_unprepare(ctrlpriv->caam_aclk);
888 if (ctrlpriv->caam_mem)
889 clk_disable_unprepare(ctrlpriv->caam_mem);
891 clk_disable_unprepare(ctrlpriv->caam_ipg);
895 static struct platform_driver caam_driver = {
898 .of_match_table = caam_match,
901 .remove = caam_remove,
904 module_platform_driver(caam_driver);
906 MODULE_LICENSE("GPL");
907 MODULE_DESCRIPTION("FSL CAAM request backend");
908 MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");