Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Copyright (c) Rockchip Electronics Co., Ltd. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/sem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "procfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) static const char *alg_type2name[ALG_TYPE_MAX] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	[ALG_TYPE_HASH]   = "HASH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	[ALG_TYPE_HMAC]   = "HMAC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	[ALG_TYPE_CIPHER] = "CIPHER",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	[ALG_TYPE_ASYM]   = "ASYM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	[ALG_TYPE_AEAD]   = "AEAD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static void crypto_show_clock(struct seq_file *p, struct clk_bulk_data *clk_bulks, int clks_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	seq_puts(p, "clock info:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	for (i = 0; i < clks_num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		seq_printf(p, "\t%-10s %ld\n", clk_bulks[i].id, clk_get_rate(clk_bulks[i].clk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	seq_puts(p, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static void crypto_show_stat(struct seq_file *p, struct rk_crypto_stat *stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	/* show statistic info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	seq_puts(p, "Statistic info:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	seq_printf(p, "\tbusy_cnt      : %llu\n", stat->busy_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	seq_printf(p, "\tequeue_cnt    : %llu\n", stat->equeue_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	seq_printf(p, "\tdequeue_cnt   : %llu\n", stat->dequeue_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	seq_printf(p, "\tdone_cnt      : %llu\n", stat->done_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	seq_printf(p, "\tcomplete_cnt  : %llu\n", stat->complete_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	seq_printf(p, "\tfake_cnt      : %llu\n", stat->fake_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	seq_printf(p, "\tirq_cnt       : %llu\n", stat->irq_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	seq_printf(p, "\ttimeout_cnt   : %llu\n", stat->timeout_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	seq_printf(p, "\terror_cnt     : %llu\n", stat->error_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	seq_printf(p, "\tlast_error    : %d\n",   stat->last_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	seq_puts(p, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static void crypto_show_queue_info(struct seq_file *p, struct rk_crypto_dev *rk_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	bool busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	u32 qlen, max_qlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	spin_lock_irqsave(&rk_dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	qlen     = rk_dev->queue.qlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	max_qlen = rk_dev->queue.max_qlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	busy     = rk_dev->busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	spin_unlock_irqrestore(&rk_dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	seq_printf(p, "Crypto queue usage [%u/%u], ever_max = %llu, status: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		   qlen, max_qlen, rk_dev->stat.ever_queue_max, busy ? "busy" : "idle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	seq_puts(p, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static void crypto_show_valid_algo_single(struct seq_file *p, enum alg_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 					  struct rk_crypto_algt **algs, u32 algs_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct rk_crypto_algt *tmp_algs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	seq_printf(p, "\t%s:\n", alg_type2name[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	for (i = 0; i < algs_num; i++, algs++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		tmp_algs = *algs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		if (!(tmp_algs->valid_flag) || tmp_algs->type != type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		seq_printf(p, "\t\t%s\n", tmp_algs->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	seq_puts(p, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static void crypto_show_valid_algos(struct seq_file *p, struct rk_crypto_soc_data *soc_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	u32 algs_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct rk_crypto_algt **algs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	seq_puts(p, "Valid algorithms:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	algs = soc_data->hw_get_algts(&algs_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (!algs || algs_num == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	crypto_show_valid_algo_single(p, ALG_TYPE_CIPHER, algs, algs_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	crypto_show_valid_algo_single(p, ALG_TYPE_AEAD,   algs, algs_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	crypto_show_valid_algo_single(p, ALG_TYPE_HASH,   algs, algs_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	crypto_show_valid_algo_single(p, ALG_TYPE_HMAC,   algs, algs_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	crypto_show_valid_algo_single(p, ALG_TYPE_ASYM,   algs, algs_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int crypto_show_all(struct seq_file *p, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct rk_crypto_dev *rk_dev = p->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct rk_crypto_soc_data *soc_data = rk_dev->soc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct rk_crypto_stat *stat = &rk_dev->stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	seq_printf(p, "Rockchip Crypto Version: %s\n\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		   soc_data->crypto_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	seq_printf(p, "use_soft_aes192 : %s\n\n", soc_data->use_soft_aes192 ? "true" : "false");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	crypto_show_clock(p, rk_dev->clk_bulks, rk_dev->clks_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	crypto_show_valid_algos(p, soc_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	crypto_show_stat(p, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	crypto_show_queue_info(p, rk_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int crypto_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct rk_crypto_dev *data = PDE_DATA(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return single_open(file, crypto_show_all, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static const struct proc_ops ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	.proc_open    = crypto_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	.proc_read    = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	.proc_lseek   = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	.proc_release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int rkcrypto_proc_init(struct rk_crypto_dev *rk_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	rk_dev->procfs = proc_create_data(rk_dev->name, 0, NULL, &ops, rk_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (!rk_dev->procfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) void rkcrypto_proc_cleanup(struct rk_crypto_dev *rk_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (rk_dev->procfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		remove_proc_entry(rk_dev->name, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	rk_dev->procfs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #endif /* CONFIG_PROC_FS */