Lines Matching refs:ss
58 int sun8i_ss_get_engine_number(struct sun8i_ss_dev *ss) in sun8i_ss_get_engine_number() argument
60 return atomic_inc_return(&ss->flow) % MAXFLOW; in sun8i_ss_get_engine_number()
63 int sun8i_ss_run_task(struct sun8i_ss_dev *ss, struct sun8i_cipher_req_ctx *rctx, in sun8i_ss_run_task() argument
71 ss->flows[flow].stat_req++; in sun8i_ss_run_task()
102 mutex_lock(&ss->mlock); in sun8i_ss_run_task()
103 writel(rctx->p_key, ss->base + SS_KEY_ADR_REG); in sun8i_ss_run_task()
107 writel(rctx->p_iv, ss->base + SS_IV_ADR_REG); in sun8i_ss_run_task()
111 …writel(rctx->t_dst[i - 1].addr + rctx->t_dst[i - 1].len * 4 - rctx->ivlen, ss->base + SS_IV_ADR_RE… in sun8i_ss_run_task()
113 …writel(rctx->t_src[i - 1].addr + rctx->t_src[i - 1].len * 4 - rctx->ivlen, ss->base + SS_IV_ADR_RE… in sun8i_ss_run_task()
117 dev_dbg(ss->dev, in sun8i_ss_run_task()
124 writel(rctx->t_src[i].addr, ss->base + SS_SRC_ADR_REG); in sun8i_ss_run_task()
125 writel(rctx->t_dst[i].addr, ss->base + SS_DST_ADR_REG); in sun8i_ss_run_task()
126 writel(rctx->t_src[i].len, ss->base + SS_LEN_ADR_REG); in sun8i_ss_run_task()
128 reinit_completion(&ss->flows[flow].complete); in sun8i_ss_run_task()
129 ss->flows[flow].status = 0; in sun8i_ss_run_task()
132 writel(v, ss->base + SS_CTL_REG); in sun8i_ss_run_task()
133 mutex_unlock(&ss->mlock); in sun8i_ss_run_task()
134 wait_for_completion_interruptible_timeout(&ss->flows[flow].complete, in sun8i_ss_run_task()
136 if (ss->flows[flow].status == 0) { in sun8i_ss_run_task()
137 dev_err(ss->dev, "DMA timeout for %s\n", name); in sun8i_ss_run_task()
147 struct sun8i_ss_dev *ss = (struct sun8i_ss_dev *)data; in ss_irq_handler() local
151 p = readl(ss->base + SS_INT_STA_REG); in ss_irq_handler()
154 writel(BIT(flow), ss->base + SS_INT_STA_REG); in ss_irq_handler()
155 ss->flows[flow].status = 1; in ss_irq_handler()
156 complete(&ss->flows[flow].complete); in ss_irq_handler()
416 struct sun8i_ss_dev *ss = seq->private; in sun8i_ss_debugfs_show() local
420 seq_printf(seq, "Channel %d: nreq %lu\n", i, ss->flows[i].stat_req); in sun8i_ss_debugfs_show()
423 if (!ss_algs[i].ss) in sun8i_ss_debugfs_show()
452 static void sun8i_ss_free_flows(struct sun8i_ss_dev *ss, int i) in sun8i_ss_free_flows() argument
455 crypto_engine_exit(ss->flows[i].engine); in sun8i_ss_free_flows()
463 static int allocate_flows(struct sun8i_ss_dev *ss) in allocate_flows() argument
467 ss->flows = devm_kcalloc(ss->dev, MAXFLOW, sizeof(struct sun8i_ss_flow), in allocate_flows()
469 if (!ss->flows) in allocate_flows()
473 init_completion(&ss->flows[i].complete); in allocate_flows()
475 ss->flows[i].engine = crypto_engine_alloc_init(ss->dev, true); in allocate_flows()
476 if (!ss->flows[i].engine) { in allocate_flows()
477 dev_err(ss->dev, "Cannot allocate engine\n"); in allocate_flows()
482 err = crypto_engine_start(ss->flows[i].engine); in allocate_flows()
484 dev_err(ss->dev, "Cannot start engine\n"); in allocate_flows()
490 sun8i_ss_free_flows(ss, i); in allocate_flows()
500 struct sun8i_ss_dev *ss = dev_get_drvdata(dev); in sun8i_ss_pm_suspend() local
503 reset_control_assert(ss->reset); in sun8i_ss_pm_suspend()
505 clk_disable_unprepare(ss->ssclks[i]); in sun8i_ss_pm_suspend()
511 struct sun8i_ss_dev *ss = dev_get_drvdata(dev); in sun8i_ss_pm_resume() local
515 if (!ss->variant->ss_clks[i].name) in sun8i_ss_pm_resume()
517 err = clk_prepare_enable(ss->ssclks[i]); in sun8i_ss_pm_resume()
519 dev_err(ss->dev, "Cannot prepare_enable %s\n", in sun8i_ss_pm_resume()
520 ss->variant->ss_clks[i].name); in sun8i_ss_pm_resume()
524 err = reset_control_deassert(ss->reset); in sun8i_ss_pm_resume()
526 dev_err(ss->dev, "Cannot deassert reset control\n"); in sun8i_ss_pm_resume()
530 writel(BIT(0) | BIT(1), ss->base + SS_INT_CTL_REG); in sun8i_ss_pm_resume()
542 static int sun8i_ss_pm_init(struct sun8i_ss_dev *ss) in sun8i_ss_pm_init() argument
546 pm_runtime_use_autosuspend(ss->dev); in sun8i_ss_pm_init()
547 pm_runtime_set_autosuspend_delay(ss->dev, 2000); in sun8i_ss_pm_init()
549 err = pm_runtime_set_suspended(ss->dev); in sun8i_ss_pm_init()
552 pm_runtime_enable(ss->dev); in sun8i_ss_pm_init()
556 static void sun8i_ss_pm_exit(struct sun8i_ss_dev *ss) in sun8i_ss_pm_exit() argument
558 pm_runtime_disable(ss->dev); in sun8i_ss_pm_exit()
561 static int sun8i_ss_register_algs(struct sun8i_ss_dev *ss) in sun8i_ss_register_algs() argument
567 ss_algs[i].ss = ss; in sun8i_ss_register_algs()
571 ss_method = ss->variant->alg_cipher[id]; in sun8i_ss_register_algs()
573 dev_info(ss->dev, in sun8i_ss_register_algs()
576 ss_algs[i].ss = NULL; in sun8i_ss_register_algs()
580 ss_method = ss->variant->op_mode[id]; in sun8i_ss_register_algs()
582 dev_info(ss->dev, "DEBUG: Blockmode of %s not supported\n", in sun8i_ss_register_algs()
584 ss_algs[i].ss = NULL; in sun8i_ss_register_algs()
587 dev_info(ss->dev, "DEBUG: Register %s\n", in sun8i_ss_register_algs()
591 dev_err(ss->dev, "Fail to register %s\n", in sun8i_ss_register_algs()
593 ss_algs[i].ss = NULL; in sun8i_ss_register_algs()
600 dev_err(ss->dev, "Fail to register %s\n", in sun8i_ss_register_algs()
602 ss_algs[i].ss = NULL; in sun8i_ss_register_algs()
607 ss_method = ss->variant->alg_hash[id]; in sun8i_ss_register_algs()
609 dev_info(ss->dev, in sun8i_ss_register_algs()
612 ss_algs[i].ss = NULL; in sun8i_ss_register_algs()
615 dev_info(ss->dev, "Register %s\n", in sun8i_ss_register_algs()
619 dev_err(ss->dev, "ERROR: Fail to register %s\n", in sun8i_ss_register_algs()
621 ss_algs[i].ss = NULL; in sun8i_ss_register_algs()
626 ss_algs[i].ss = NULL; in sun8i_ss_register_algs()
627 dev_err(ss->dev, "ERROR: tried to register an unknown algo\n"); in sun8i_ss_register_algs()
633 static void sun8i_ss_unregister_algs(struct sun8i_ss_dev *ss) in sun8i_ss_unregister_algs() argument
638 if (!ss_algs[i].ss) in sun8i_ss_unregister_algs()
642 dev_info(ss->dev, "Unregister %d %s\n", i, in sun8i_ss_unregister_algs()
647 dev_info(ss->dev, "Unregister %d %s\n", i, in sun8i_ss_unregister_algs()
652 dev_info(ss->dev, "Unregister %d %s\n", i, in sun8i_ss_unregister_algs()
660 static int sun8i_ss_get_clks(struct sun8i_ss_dev *ss) in sun8i_ss_get_clks() argument
666 if (!ss->variant->ss_clks[i].name) in sun8i_ss_get_clks()
668 ss->ssclks[i] = devm_clk_get(ss->dev, ss->variant->ss_clks[i].name); in sun8i_ss_get_clks()
669 if (IS_ERR(ss->ssclks[i])) { in sun8i_ss_get_clks()
670 err = PTR_ERR(ss->ssclks[i]); in sun8i_ss_get_clks()
671 dev_err(ss->dev, "Cannot get %s SS clock err=%d\n", in sun8i_ss_get_clks()
672 ss->variant->ss_clks[i].name, err); in sun8i_ss_get_clks()
675 cr = clk_get_rate(ss->ssclks[i]); in sun8i_ss_get_clks()
678 if (ss->variant->ss_clks[i].freq > 0 && in sun8i_ss_get_clks()
679 cr != ss->variant->ss_clks[i].freq) { in sun8i_ss_get_clks()
680 dev_info(ss->dev, "Set %s clock to %lu (%lu Mhz) from %lu (%lu Mhz)\n", in sun8i_ss_get_clks()
681 ss->variant->ss_clks[i].name, in sun8i_ss_get_clks()
682 ss->variant->ss_clks[i].freq, in sun8i_ss_get_clks()
683 ss->variant->ss_clks[i].freq / 1000000, in sun8i_ss_get_clks()
685 err = clk_set_rate(ss->ssclks[i], ss->variant->ss_clks[i].freq); in sun8i_ss_get_clks()
687 dev_err(ss->dev, "Fail to set %s clk speed to %lu hz\n", in sun8i_ss_get_clks()
688 ss->variant->ss_clks[i].name, in sun8i_ss_get_clks()
689 ss->variant->ss_clks[i].freq); in sun8i_ss_get_clks()
691 if (ss->variant->ss_clks[i].max_freq > 0 && in sun8i_ss_get_clks()
692 cr > ss->variant->ss_clks[i].max_freq) in sun8i_ss_get_clks()
693 dev_warn(ss->dev, "Frequency for %s (%lu hz) is higher than datasheet's recommendation (%lu hz)", in sun8i_ss_get_clks()
694 ss->variant->ss_clks[i].name, cr, in sun8i_ss_get_clks()
695 ss->variant->ss_clks[i].max_freq); in sun8i_ss_get_clks()
702 struct sun8i_ss_dev *ss; in sun8i_ss_probe() local
706 ss = devm_kzalloc(&pdev->dev, sizeof(*ss), GFP_KERNEL); in sun8i_ss_probe()
707 if (!ss) in sun8i_ss_probe()
710 ss->dev = &pdev->dev; in sun8i_ss_probe()
711 platform_set_drvdata(pdev, ss); in sun8i_ss_probe()
713 ss->variant = of_device_get_match_data(&pdev->dev); in sun8i_ss_probe()
714 if (!ss->variant) { in sun8i_ss_probe()
719 ss->base = devm_platform_ioremap_resource(pdev, 0); in sun8i_ss_probe()
720 if (IS_ERR(ss->base)) in sun8i_ss_probe()
721 return PTR_ERR(ss->base); in sun8i_ss_probe()
723 err = sun8i_ss_get_clks(ss); in sun8i_ss_probe()
731 ss->reset = devm_reset_control_get(&pdev->dev, NULL); in sun8i_ss_probe()
732 if (IS_ERR(ss->reset)) in sun8i_ss_probe()
733 return dev_err_probe(&pdev->dev, PTR_ERR(ss->reset), in sun8i_ss_probe()
736 mutex_init(&ss->mlock); in sun8i_ss_probe()
738 err = allocate_flows(ss); in sun8i_ss_probe()
742 err = sun8i_ss_pm_init(ss); in sun8i_ss_probe()
746 err = devm_request_irq(&pdev->dev, irq, ss_irq_handler, 0, "sun8i-ss", ss); in sun8i_ss_probe()
748 dev_err(ss->dev, "Cannot request SecuritySystem IRQ (err=%d)\n", err); in sun8i_ss_probe()
752 err = sun8i_ss_register_algs(ss); in sun8i_ss_probe()
756 err = pm_runtime_resume_and_get(ss->dev); in sun8i_ss_probe()
760 v = readl(ss->base + SS_CTL_REG); in sun8i_ss_probe()
765 pm_runtime_put_sync(ss->dev); in sun8i_ss_probe()
769 ss->dbgfs_dir = debugfs_create_dir("sun8i-ss", NULL); in sun8i_ss_probe()
770 ss->dbgfs_stats = debugfs_create_file("stats", 0444, in sun8i_ss_probe()
771 ss->dbgfs_dir, ss, in sun8i_ss_probe()
777 sun8i_ss_unregister_algs(ss); in sun8i_ss_probe()
779 sun8i_ss_pm_exit(ss); in sun8i_ss_probe()
781 sun8i_ss_free_flows(ss, MAXFLOW - 1); in sun8i_ss_probe()
787 struct sun8i_ss_dev *ss = platform_get_drvdata(pdev); in sun8i_ss_remove() local
789 sun8i_ss_unregister_algs(ss); in sun8i_ss_remove()
792 debugfs_remove_recursive(ss->dbgfs_dir); in sun8i_ss_remove()
795 sun8i_ss_free_flows(ss, MAXFLOW - 1); in sun8i_ss_remove()
797 sun8i_ss_pm_exit(ss); in sun8i_ss_remove()