xref: /linux/drivers/misc/cxl/debugfs.c (revision 1420edf7a3fbc9b8b0bbe24c3724d582dd4def28)
1 /*
2  * Copyright 2014 IBM Corp.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version
7  * 2 of the License, or (at your option) any later version.
8  */
9 
10 #include <linux/debugfs.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 
14 #include "cxl.h"
15 
16 static struct dentry *cxl_debugfs;
17 
18 /* Helpers to export CXL mmaped IO registers via debugfs */
19 static int debugfs_io_u64_get(void *data, u64 *val)
20 {
21 	*val = in_be64((u64 __iomem *)data);
22 	return 0;
23 }
24 
25 static int debugfs_io_u64_set(void *data, u64 val)
26 {
27 	out_be64((u64 __iomem *)data, val);
28 	return 0;
29 }
30 DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
31 			 "0x%016llx\n");
32 
33 static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
34 					    struct dentry *parent, u64 __iomem *value)
35 {
36 	return debugfs_create_file_unsafe(name, mode, parent,
37 					  (void __force *)value, &fops_io_x64);
38 }
39 
40 void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)
41 {
42 	debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR1));
43 	debugfs_create_io_x64("fir_mask", 0400, dir,
44 			      _cxl_p1_addr(adapter, CXL_PSL9_FIR_MASK));
45 	debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR_CNTL));
46 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_TRACECFG));
47 	debugfs_create_io_x64("debug", 0600, dir,
48 			      _cxl_p1_addr(adapter, CXL_PSL9_DEBUG));
49 	debugfs_create_io_x64("xsl-debug", 0600, dir,
50 			      _cxl_p1_addr(adapter, CXL_XSL9_DBG));
51 }
52 
53 void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
54 {
55 	debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1));
56 	debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2));
57 	debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL));
58 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
59 }
60 
61 void cxl_debugfs_add_adapter_regs_xsl(struct cxl *adapter, struct dentry *dir)
62 {
63 	debugfs_create_io_x64("fec", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_XSL_FEC));
64 }
65 
66 int cxl_debugfs_adapter_add(struct cxl *adapter)
67 {
68 	struct dentry *dir;
69 	char buf[32];
70 
71 	if (!cxl_debugfs)
72 		return -ENODEV;
73 
74 	snprintf(buf, 32, "card%i", adapter->adapter_num);
75 	dir = debugfs_create_dir(buf, cxl_debugfs);
76 	if (IS_ERR(dir))
77 		return PTR_ERR(dir);
78 	adapter->debugfs = dir;
79 
80 	debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
81 
82 	if (adapter->native->sl_ops->debugfs_add_adapter_regs)
83 		adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
84 	return 0;
85 }
86 
87 void cxl_debugfs_adapter_remove(struct cxl *adapter)
88 {
89 	debugfs_remove_recursive(adapter->debugfs);
90 }
91 
92 void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir)
93 {
94 	debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
95 }
96 
97 void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
98 {
99 	debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
100 	debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
101 
102 	debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
103 	debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
104 	debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
105 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
106 }
107 
108 int cxl_debugfs_afu_add(struct cxl_afu *afu)
109 {
110 	struct dentry *dir;
111 	char buf[32];
112 
113 	if (!afu->adapter->debugfs)
114 		return -ENODEV;
115 
116 	snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
117 	dir = debugfs_create_dir(buf, afu->adapter->debugfs);
118 	if (IS_ERR(dir))
119 		return PTR_ERR(dir);
120 	afu->debugfs = dir;
121 
122 	debugfs_create_io_x64("sr",         S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
123 	debugfs_create_io_x64("dsisr",      S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
124 	debugfs_create_io_x64("dar",        S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
125 
126 	debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
127 
128 	if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
129 		afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
130 
131 	return 0;
132 }
133 
134 void cxl_debugfs_afu_remove(struct cxl_afu *afu)
135 {
136 	debugfs_remove_recursive(afu->debugfs);
137 }
138 
139 int __init cxl_debugfs_init(void)
140 {
141 	struct dentry *ent;
142 
143 	if (!cpu_has_feature(CPU_FTR_HVMODE))
144 		return 0;
145 
146 	ent = debugfs_create_dir("cxl", NULL);
147 	if (IS_ERR(ent))
148 		return PTR_ERR(ent);
149 	cxl_debugfs = ent;
150 
151 	return 0;
152 }
153 
154 void cxl_debugfs_exit(void)
155 {
156 	debugfs_remove_recursive(cxl_debugfs);
157 }
158