xref: /openbmc/linux/drivers/crypto/caam/debugfs.c (revision 11696c5e)
1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /* Copyright 2019, 2023 NXP */
3 
4 #include <linux/debugfs.h>
5 #include "compat.h"
6 #include "debugfs.h"
7 #include "regs.h"
8 #include "intern.h"
9 
10 static int caam_debugfs_u64_get(void *data, u64 *val)
11 {
12 	*val = caam64_to_cpu(*(u64 *)data);
13 	return 0;
14 }
15 
16 static int caam_debugfs_u32_get(void *data, u64 *val)
17 {
18 	*val = caam32_to_cpu(*(u32 *)data);
19 	return 0;
20 }
21 
22 DEFINE_DEBUGFS_ATTRIBUTE(caam_fops_u32_ro, caam_debugfs_u32_get, NULL, "%llu\n");
23 DEFINE_DEBUGFS_ATTRIBUTE(caam_fops_u64_ro, caam_debugfs_u64_get, NULL, "%llu\n");
24 
25 #ifdef CONFIG_CAAM_QI
26 /*
27  * This is a counter for the number of times the congestion group (where all
28  * the request and response queueus are) reached congestion. Incremented
29  * each time the congestion callback is called with congested == true.
30  */
31 static u64 times_congested;
32 
33 void caam_debugfs_qi_congested(void)
34 {
35 	times_congested++;
36 }
37 
38 void caam_debugfs_qi_init(struct caam_drv_private *ctrlpriv)
39 {
40 	debugfs_create_file("qi_congested", 0444, ctrlpriv->ctl,
41 			    &times_congested, &caam_fops_u64_ro);
42 }
43 #endif
44 
45 void caam_debugfs_init(struct caam_drv_private *ctrlpriv,
46 		       struct caam_perfmon __force *perfmon,
47 		       struct dentry *root)
48 {
49 	/*
50 	 * FIXME: needs better naming distinction, as some amalgamation of
51 	 * "caam" and nprop->full_name. The OF name isn't distinctive,
52 	 * but does separate instances
53 	 */
54 
55 	ctrlpriv->ctl = debugfs_create_dir("ctl", root);
56 
57 	debugfs_create_file("rq_dequeued", 0444, ctrlpriv->ctl,
58 			    &perfmon->req_dequeued, &caam_fops_u64_ro);
59 	debugfs_create_file("ob_rq_encrypted", 0444, ctrlpriv->ctl,
60 			    &perfmon->ob_enc_req, &caam_fops_u64_ro);
61 	debugfs_create_file("ib_rq_decrypted", 0444, ctrlpriv->ctl,
62 			    &perfmon->ib_dec_req, &caam_fops_u64_ro);
63 	debugfs_create_file("ob_bytes_encrypted", 0444, ctrlpriv->ctl,
64 			    &perfmon->ob_enc_bytes, &caam_fops_u64_ro);
65 	debugfs_create_file("ob_bytes_protected", 0444, ctrlpriv->ctl,
66 			    &perfmon->ob_prot_bytes, &caam_fops_u64_ro);
67 	debugfs_create_file("ib_bytes_decrypted", 0444, ctrlpriv->ctl,
68 			    &perfmon->ib_dec_bytes, &caam_fops_u64_ro);
69 	debugfs_create_file("ib_bytes_validated", 0444, ctrlpriv->ctl,
70 			    &perfmon->ib_valid_bytes, &caam_fops_u64_ro);
71 
72 	/* Controller level - global status values */
73 	debugfs_create_file("fault_addr", 0444, ctrlpriv->ctl,
74 			    &perfmon->faultaddr, &caam_fops_u32_ro);
75 	debugfs_create_file("fault_detail", 0444, ctrlpriv->ctl,
76 			    &perfmon->faultdetail, &caam_fops_u32_ro);
77 	debugfs_create_file("fault_status", 0444, ctrlpriv->ctl,
78 			    &perfmon->status, &caam_fops_u32_ro);
79 
80 	if (ctrlpriv->optee_en)
81 		return;
82 
83 	/* Internal covering keys (useful in non-secure mode only) */
84 	ctrlpriv->ctl_kek_wrap.data = (__force void *)&ctrlpriv->ctrl->kek[0];
85 	ctrlpriv->ctl_kek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
86 	debugfs_create_blob("kek", 0444, ctrlpriv->ctl,
87 			    &ctrlpriv->ctl_kek_wrap);
88 
89 	ctrlpriv->ctl_tkek_wrap.data = (__force void *)&ctrlpriv->ctrl->tkek[0];
90 	ctrlpriv->ctl_tkek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
91 	debugfs_create_blob("tkek", 0444, ctrlpriv->ctl,
92 			    &ctrlpriv->ctl_tkek_wrap);
93 
94 	ctrlpriv->ctl_tdsk_wrap.data = (__force void *)&ctrlpriv->ctrl->tdsk[0];
95 	ctrlpriv->ctl_tdsk_wrap.size = KEK_KEY_SIZE * sizeof(u32);
96 	debugfs_create_blob("tdsk", 0444, ctrlpriv->ctl,
97 			    &ctrlpriv->ctl_tdsk_wrap);
98 }
99