Lines Matching refs:ce
131 int sun8i_ce_get_engine_number(struct sun8i_ce_dev *ce) in sun8i_ce_get_engine_number() argument
133 return atomic_inc_return(&ce->flow) % (MAXFLOW - 1); in sun8i_ce_get_engine_number()
136 int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name) in sun8i_ce_run_task() argument
140 struct ce_task *cet = ce->chanlist[flow].tl; in sun8i_ce_run_task()
143 ce->chanlist[flow].stat_req++; in sun8i_ce_run_task()
146 mutex_lock(&ce->mlock); in sun8i_ce_run_task()
148 v = readl(ce->base + CE_ICR); in sun8i_ce_run_task()
150 writel(v, ce->base + CE_ICR); in sun8i_ce_run_task()
152 reinit_completion(&ce->chanlist[flow].complete); in sun8i_ce_run_task()
153 writel(ce->chanlist[flow].t_phy, ce->base + CE_TDQ); in sun8i_ce_run_task()
155 ce->chanlist[flow].status = 0; in sun8i_ce_run_task()
162 v = 1 | ((le32_to_cpu(ce->chanlist[flow].tl->t_common_ctl) & 0x7F) << 8); in sun8i_ce_run_task()
163 writel(v, ce->base + CE_TLR); in sun8i_ce_run_task()
164 mutex_unlock(&ce->mlock); in sun8i_ce_run_task()
166 wait_for_completion_interruptible_timeout(&ce->chanlist[flow].complete, in sun8i_ce_run_task()
167 msecs_to_jiffies(ce->chanlist[flow].timeout)); in sun8i_ce_run_task()
169 if (ce->chanlist[flow].status == 0) { in sun8i_ce_run_task()
170 dev_err(ce->dev, "DMA timeout for %s (tm=%d) on flow %d\n", name, in sun8i_ce_run_task()
171 ce->chanlist[flow].timeout, flow); in sun8i_ce_run_task()
177 v = readl(ce->base + CE_ESR); in sun8i_ce_run_task()
178 switch (ce->variant->esr) { in sun8i_ce_run_task()
182 dev_err(ce->dev, "CE ERROR: %x for flow %x\n", v, flow); in sun8i_ce_run_task()
188 dev_err(ce->dev, "CE ERROR: algorithm not supported\n"); in sun8i_ce_run_task()
190 dev_err(ce->dev, "CE ERROR: data length error\n"); in sun8i_ce_run_task()
192 dev_err(ce->dev, "CE ERROR: keysram access error for AES\n"); in sun8i_ce_run_task()
200 dev_err(ce->dev, "CE ERROR: %x for flow %x\n", v, flow); in sun8i_ce_run_task()
206 dev_err(ce->dev, "CE ERROR: algorithm not supported\n"); in sun8i_ce_run_task()
208 dev_err(ce->dev, "CE ERROR: data length error\n"); in sun8i_ce_run_task()
210 dev_err(ce->dev, "CE ERROR: keysram access error for AES\n"); in sun8i_ce_run_task()
216 dev_err(ce->dev, "CE ERROR: %x for flow %x\n", v, flow); in sun8i_ce_run_task()
222 dev_err(ce->dev, "CE ERROR: algorithm not supported\n"); in sun8i_ce_run_task()
224 dev_err(ce->dev, "CE ERROR: data length error\n"); in sun8i_ce_run_task()
226 dev_err(ce->dev, "CE ERROR: keysram access error for AES\n"); in sun8i_ce_run_task()
228 dev_err(ce->dev, "CE ERROR: address invalid\n"); in sun8i_ce_run_task()
230 dev_err(ce->dev, "CE ERROR: key ladder configuration error\n"); in sun8i_ce_run_task()
239 struct sun8i_ce_dev *ce = (struct sun8i_ce_dev *)data; in ce_irq_handler() local
243 p = readl(ce->base + CE_ISR); in ce_irq_handler()
246 writel(BIT(flow), ce->base + CE_ISR); in ce_irq_handler()
247 ce->chanlist[flow].status = 1; in ce_irq_handler()
248 complete(&ce->chanlist[flow].complete); in ce_irq_handler()
568 struct sun8i_ce_dev *ce = seq->private; in sun8i_ce_debugfs_show() local
572 seq_printf(seq, "Channel %d: nreq %lu\n", i, ce->chanlist[i].stat_req); in sun8i_ce_debugfs_show()
575 if (!ce_algs[i].ce) in sun8i_ce_debugfs_show()
600 ce->hwrng_stat_req, ce->hwrng_stat_bytes); in sun8i_ce_debugfs_show()
608 static void sun8i_ce_free_chanlist(struct sun8i_ce_dev *ce, int i) in sun8i_ce_free_chanlist() argument
611 crypto_engine_exit(ce->chanlist[i].engine); in sun8i_ce_free_chanlist()
612 if (ce->chanlist[i].tl) in sun8i_ce_free_chanlist()
613 dma_free_coherent(ce->dev, sizeof(struct ce_task), in sun8i_ce_free_chanlist()
614 ce->chanlist[i].tl, in sun8i_ce_free_chanlist()
615 ce->chanlist[i].t_phy); in sun8i_ce_free_chanlist()
623 static int sun8i_ce_allocate_chanlist(struct sun8i_ce_dev *ce) in sun8i_ce_allocate_chanlist() argument
627 ce->chanlist = devm_kcalloc(ce->dev, MAXFLOW, in sun8i_ce_allocate_chanlist()
629 if (!ce->chanlist) in sun8i_ce_allocate_chanlist()
633 init_completion(&ce->chanlist[i].complete); in sun8i_ce_allocate_chanlist()
635 ce->chanlist[i].engine = crypto_engine_alloc_init(ce->dev, true); in sun8i_ce_allocate_chanlist()
636 if (!ce->chanlist[i].engine) { in sun8i_ce_allocate_chanlist()
637 dev_err(ce->dev, "Cannot allocate engine\n"); in sun8i_ce_allocate_chanlist()
642 err = crypto_engine_start(ce->chanlist[i].engine); in sun8i_ce_allocate_chanlist()
644 dev_err(ce->dev, "Cannot start engine\n"); in sun8i_ce_allocate_chanlist()
647 ce->chanlist[i].tl = dma_alloc_coherent(ce->dev, in sun8i_ce_allocate_chanlist()
649 &ce->chanlist[i].t_phy, in sun8i_ce_allocate_chanlist()
651 if (!ce->chanlist[i].tl) { in sun8i_ce_allocate_chanlist()
652 dev_err(ce->dev, "Cannot get DMA memory for task %d\n", in sun8i_ce_allocate_chanlist()
660 sun8i_ce_free_chanlist(ce, i); in sun8i_ce_allocate_chanlist()
670 struct sun8i_ce_dev *ce = dev_get_drvdata(dev); in sun8i_ce_pm_suspend() local
673 reset_control_assert(ce->reset); in sun8i_ce_pm_suspend()
675 clk_disable_unprepare(ce->ceclks[i]); in sun8i_ce_pm_suspend()
681 struct sun8i_ce_dev *ce = dev_get_drvdata(dev); in sun8i_ce_pm_resume() local
685 if (!ce->variant->ce_clks[i].name) in sun8i_ce_pm_resume()
687 err = clk_prepare_enable(ce->ceclks[i]); in sun8i_ce_pm_resume()
689 dev_err(ce->dev, "Cannot prepare_enable %s\n", in sun8i_ce_pm_resume()
690 ce->variant->ce_clks[i].name); in sun8i_ce_pm_resume()
694 err = reset_control_deassert(ce->reset); in sun8i_ce_pm_resume()
696 dev_err(ce->dev, "Cannot deassert reset control\n"); in sun8i_ce_pm_resume()
709 static int sun8i_ce_pm_init(struct sun8i_ce_dev *ce) in sun8i_ce_pm_init() argument
713 pm_runtime_use_autosuspend(ce->dev); in sun8i_ce_pm_init()
714 pm_runtime_set_autosuspend_delay(ce->dev, 2000); in sun8i_ce_pm_init()
716 err = pm_runtime_set_suspended(ce->dev); in sun8i_ce_pm_init()
719 pm_runtime_enable(ce->dev); in sun8i_ce_pm_init()
723 static void sun8i_ce_pm_exit(struct sun8i_ce_dev *ce) in sun8i_ce_pm_exit() argument
725 pm_runtime_disable(ce->dev); in sun8i_ce_pm_exit()
728 static int sun8i_ce_get_clks(struct sun8i_ce_dev *ce) in sun8i_ce_get_clks() argument
734 if (!ce->variant->ce_clks[i].name) in sun8i_ce_get_clks()
736 ce->ceclks[i] = devm_clk_get(ce->dev, ce->variant->ce_clks[i].name); in sun8i_ce_get_clks()
737 if (IS_ERR(ce->ceclks[i])) { in sun8i_ce_get_clks()
738 err = PTR_ERR(ce->ceclks[i]); in sun8i_ce_get_clks()
739 dev_err(ce->dev, "Cannot get %s CE clock err=%d\n", in sun8i_ce_get_clks()
740 ce->variant->ce_clks[i].name, err); in sun8i_ce_get_clks()
743 cr = clk_get_rate(ce->ceclks[i]); in sun8i_ce_get_clks()
746 if (ce->variant->ce_clks[i].freq > 0 && in sun8i_ce_get_clks()
747 cr != ce->variant->ce_clks[i].freq) { in sun8i_ce_get_clks()
748 dev_info(ce->dev, "Set %s clock to %lu (%lu Mhz) from %lu (%lu Mhz)\n", in sun8i_ce_get_clks()
749 ce->variant->ce_clks[i].name, in sun8i_ce_get_clks()
750 ce->variant->ce_clks[i].freq, in sun8i_ce_get_clks()
751 ce->variant->ce_clks[i].freq / 1000000, in sun8i_ce_get_clks()
753 err = clk_set_rate(ce->ceclks[i], ce->variant->ce_clks[i].freq); in sun8i_ce_get_clks()
755 dev_err(ce->dev, "Fail to set %s clk speed to %lu hz\n", in sun8i_ce_get_clks()
756 ce->variant->ce_clks[i].name, in sun8i_ce_get_clks()
757 ce->variant->ce_clks[i].freq); in sun8i_ce_get_clks()
759 if (ce->variant->ce_clks[i].max_freq > 0 && in sun8i_ce_get_clks()
760 cr > ce->variant->ce_clks[i].max_freq) in sun8i_ce_get_clks()
761 dev_warn(ce->dev, "Frequency for %s (%lu hz) is higher than datasheet's recommendation (%lu hz)", in sun8i_ce_get_clks()
762 ce->variant->ce_clks[i].name, cr, in sun8i_ce_get_clks()
763 ce->variant->ce_clks[i].max_freq); in sun8i_ce_get_clks()
768 static int sun8i_ce_register_algs(struct sun8i_ce_dev *ce) in sun8i_ce_register_algs() argument
774 ce_algs[i].ce = ce; in sun8i_ce_register_algs()
778 ce_method = ce->variant->alg_cipher[id]; in sun8i_ce_register_algs()
780 dev_dbg(ce->dev, in sun8i_ce_register_algs()
783 ce_algs[i].ce = NULL; in sun8i_ce_register_algs()
787 ce_method = ce->variant->op_mode[id]; in sun8i_ce_register_algs()
789 dev_dbg(ce->dev, "DEBUG: Blockmode of %s not supported\n", in sun8i_ce_register_algs()
791 ce_algs[i].ce = NULL; in sun8i_ce_register_algs()
794 dev_info(ce->dev, "Register %s\n", in sun8i_ce_register_algs()
798 dev_err(ce->dev, "ERROR: Fail to register %s\n", in sun8i_ce_register_algs()
800 ce_algs[i].ce = NULL; in sun8i_ce_register_algs()
806 ce_method = ce->variant->alg_hash[id]; in sun8i_ce_register_algs()
808 dev_info(ce->dev, in sun8i_ce_register_algs()
811 ce_algs[i].ce = NULL; in sun8i_ce_register_algs()
814 dev_info(ce->dev, "Register %s\n", in sun8i_ce_register_algs()
818 dev_err(ce->dev, "ERROR: Fail to register %s\n", in sun8i_ce_register_algs()
820 ce_algs[i].ce = NULL; in sun8i_ce_register_algs()
825 if (ce->variant->prng == CE_ID_NOTSUPP) { in sun8i_ce_register_algs()
826 dev_info(ce->dev, in sun8i_ce_register_algs()
829 ce_algs[i].ce = NULL; in sun8i_ce_register_algs()
832 dev_info(ce->dev, "Register %s\n", in sun8i_ce_register_algs()
836 dev_err(ce->dev, "Fail to register %s\n", in sun8i_ce_register_algs()
838 ce_algs[i].ce = NULL; in sun8i_ce_register_algs()
842 ce_algs[i].ce = NULL; in sun8i_ce_register_algs()
843 dev_err(ce->dev, "ERROR: tried to register an unknown algo\n"); in sun8i_ce_register_algs()
849 static void sun8i_ce_unregister_algs(struct sun8i_ce_dev *ce) in sun8i_ce_unregister_algs() argument
854 if (!ce_algs[i].ce) in sun8i_ce_unregister_algs()
858 dev_info(ce->dev, "Unregister %d %s\n", i, in sun8i_ce_unregister_algs()
863 dev_info(ce->dev, "Unregister %d %s\n", i, in sun8i_ce_unregister_algs()
868 dev_info(ce->dev, "Unregister %d %s\n", i, in sun8i_ce_unregister_algs()
878 struct sun8i_ce_dev *ce; in sun8i_ce_probe() local
882 ce = devm_kzalloc(&pdev->dev, sizeof(*ce), GFP_KERNEL); in sun8i_ce_probe()
883 if (!ce) in sun8i_ce_probe()
886 ce->dev = &pdev->dev; in sun8i_ce_probe()
887 platform_set_drvdata(pdev, ce); in sun8i_ce_probe()
889 ce->variant = of_device_get_match_data(&pdev->dev); in sun8i_ce_probe()
890 if (!ce->variant) { in sun8i_ce_probe()
895 ce->base = devm_platform_ioremap_resource(pdev, 0); in sun8i_ce_probe()
896 if (IS_ERR(ce->base)) in sun8i_ce_probe()
897 return PTR_ERR(ce->base); in sun8i_ce_probe()
899 err = sun8i_ce_get_clks(ce); in sun8i_ce_probe()
908 ce->reset = devm_reset_control_get(&pdev->dev, NULL); in sun8i_ce_probe()
909 if (IS_ERR(ce->reset)) in sun8i_ce_probe()
910 return dev_err_probe(&pdev->dev, PTR_ERR(ce->reset), in sun8i_ce_probe()
913 mutex_init(&ce->mlock); in sun8i_ce_probe()
914 mutex_init(&ce->rnglock); in sun8i_ce_probe()
916 err = sun8i_ce_allocate_chanlist(ce); in sun8i_ce_probe()
920 err = sun8i_ce_pm_init(ce); in sun8i_ce_probe()
925 "sun8i-ce-ns", ce); in sun8i_ce_probe()
927 dev_err(ce->dev, "Cannot request CryptoEngine Non-secure IRQ (err=%d)\n", err); in sun8i_ce_probe()
931 err = sun8i_ce_register_algs(ce); in sun8i_ce_probe()
935 err = pm_runtime_resume_and_get(ce->dev); in sun8i_ce_probe()
940 sun8i_ce_hwrng_register(ce); in sun8i_ce_probe()
943 v = readl(ce->base + CE_CTR); in sun8i_ce_probe()
948 pm_runtime_put_sync(ce->dev); in sun8i_ce_probe()
952 ce->dbgfs_dir = debugfs_create_dir("sun8i-ce", NULL); in sun8i_ce_probe()
953 ce->dbgfs_stats = debugfs_create_file("stats", 0444, in sun8i_ce_probe()
954 ce->dbgfs_dir, ce, in sun8i_ce_probe()
960 sun8i_ce_unregister_algs(ce); in sun8i_ce_probe()
962 sun8i_ce_pm_exit(ce); in sun8i_ce_probe()
964 sun8i_ce_free_chanlist(ce, MAXFLOW - 1); in sun8i_ce_probe()
970 struct sun8i_ce_dev *ce = platform_get_drvdata(pdev); in sun8i_ce_remove() local
973 sun8i_ce_hwrng_unregister(ce); in sun8i_ce_remove()
976 sun8i_ce_unregister_algs(ce); in sun8i_ce_remove()
979 debugfs_remove_recursive(ce->dbgfs_dir); in sun8i_ce_remove()
982 sun8i_ce_free_chanlist(ce, MAXFLOW - 1); in sun8i_ce_remove()
984 sun8i_ce_pm_exit(ce); in sun8i_ce_remove()