xref: /openbmc/linux/drivers/misc/cxl/debugfs.c (revision c819e2cf)
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 void cxl_stop_trace(struct cxl *adapter)
19 {
20 	int slice;
21 
22 	/* Stop the trace */
23 	cxl_p1_write(adapter, CXL_PSL_TRACE, 0x8000000000000017LL);
24 
25 	/* Stop the slice traces */
26 	spin_lock(&adapter->afu_list_lock);
27 	for (slice = 0; slice < adapter->slices; slice++) {
28 		if (adapter->afu[slice])
29 			cxl_p1n_write(adapter->afu[slice], CXL_PSL_SLICE_TRACE, 0x8000000000000000LL);
30 	}
31 	spin_unlock(&adapter->afu_list_lock);
32 }
33 
34 /* Helpers to export CXL mmaped IO registers via debugfs */
35 static int debugfs_io_u64_get(void *data, u64 *val)
36 {
37 	*val = in_be64((u64 __iomem *)data);
38 	return 0;
39 }
40 
41 static int debugfs_io_u64_set(void *data, u64 val)
42 {
43 	out_be64((u64 __iomem *)data, val);
44 	return 0;
45 }
46 DEFINE_SIMPLE_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set, "0x%016llx\n");
47 
48 static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
49 					    struct dentry *parent, u64 __iomem *value)
50 {
51 	return debugfs_create_file(name, mode, parent, (void *)value, &fops_io_x64);
52 }
53 
54 int cxl_debugfs_adapter_add(struct cxl *adapter)
55 {
56 	struct dentry *dir;
57 	char buf[32];
58 
59 	if (!cxl_debugfs)
60 		return -ENODEV;
61 
62 	snprintf(buf, 32, "card%i", adapter->adapter_num);
63 	dir = debugfs_create_dir(buf, cxl_debugfs);
64 	if (IS_ERR(dir))
65 		return PTR_ERR(dir);
66 	adapter->debugfs = dir;
67 
68 	debugfs_create_io_x64("fir1",     S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1));
69 	debugfs_create_io_x64("fir2",     S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2));
70 	debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL));
71 	debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
72 
73 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
74 
75 	return 0;
76 }
77 
78 void cxl_debugfs_adapter_remove(struct cxl *adapter)
79 {
80 	debugfs_remove_recursive(adapter->debugfs);
81 }
82 
83 int cxl_debugfs_afu_add(struct cxl_afu *afu)
84 {
85 	struct dentry *dir;
86 	char buf[32];
87 
88 	if (!afu->adapter->debugfs)
89 		return -ENODEV;
90 
91 	snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
92 	dir = debugfs_create_dir(buf, afu->adapter->debugfs);
93 	if (IS_ERR(dir))
94 		return PTR_ERR(dir);
95 	afu->debugfs = dir;
96 
97 	debugfs_create_io_x64("fir",        S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
98 	debugfs_create_io_x64("serr",       S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
99 	debugfs_create_io_x64("afu_debug",  S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
100 	debugfs_create_io_x64("sr",         S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
101 
102 	debugfs_create_io_x64("dsisr",      S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
103 	debugfs_create_io_x64("dar",        S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
104 	debugfs_create_io_x64("sstp0",      S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
105 	debugfs_create_io_x64("sstp1",      S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
106 	debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
107 
108 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
109 
110 	return 0;
111 }
112 
113 void cxl_debugfs_afu_remove(struct cxl_afu *afu)
114 {
115 	debugfs_remove_recursive(afu->debugfs);
116 }
117 
118 int __init cxl_debugfs_init(void)
119 {
120 	struct dentry *ent;
121 	ent = debugfs_create_dir("cxl", NULL);
122 	if (IS_ERR(ent))
123 		return PTR_ERR(ent);
124 	cxl_debugfs = ent;
125 
126 	return 0;
127 }
128 
129 void cxl_debugfs_exit(void)
130 {
131 	debugfs_remove_recursive(cxl_debugfs);
132 }
133