blob: eae9d749f9678d29627b85b162f60ae28a481c40 [file] [log] [blame]
Ian Munsief204e0b2014-10-08 19:55:02 +11001/*
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
16static struct dentry *cxl_debugfs;
17
Christophe Lombardf24be422017-04-12 16:34:07 +020018void cxl_stop_trace_psl9(struct cxl *adapter)
19{
20 /* Stop the trace */
21 cxl_p1_write(adapter, CXL_PSL9_TRACECFG, 0x4480000000000000ULL);
22}
23
Christophe Lombard64663f32017-04-07 16:11:57 +020024void cxl_stop_trace_psl8(struct cxl *adapter)
Ian Munsief204e0b2014-10-08 19:55:02 +110025{
26 int slice;
27
28 /* Stop the trace */
29 cxl_p1_write(adapter, CXL_PSL_TRACE, 0x8000000000000017LL);
30
31 /* Stop the slice traces */
32 spin_lock(&adapter->afu_list_lock);
33 for (slice = 0; slice < adapter->slices; slice++) {
34 if (adapter->afu[slice])
35 cxl_p1n_write(adapter->afu[slice], CXL_PSL_SLICE_TRACE, 0x8000000000000000LL);
36 }
37 spin_unlock(&adapter->afu_list_lock);
38}
39
40/* Helpers to export CXL mmaped IO registers via debugfs */
41static int debugfs_io_u64_get(void *data, u64 *val)
42{
43 *val = in_be64((u64 __iomem *)data);
44 return 0;
45}
46
47static int debugfs_io_u64_set(void *data, u64 val)
48{
49 out_be64((u64 __iomem *)data, val);
50 return 0;
51}
Andrew Donnellan3382a622016-11-22 21:13:27 +110052DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
53 "0x%016llx\n");
Ian Munsief204e0b2014-10-08 19:55:02 +110054
55static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
56 struct dentry *parent, u64 __iomem *value)
57{
Andrew Donnellan3382a622016-11-22 21:13:27 +110058 return debugfs_create_file_unsafe(name, mode, parent,
59 (void __force *)value, &fops_io_x64);
Ian Munsief204e0b2014-10-08 19:55:02 +110060}
61
Christophe Lombardf24be422017-04-12 16:34:07 +020062void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)
63{
64 debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR1));
65 debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR2));
66 debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR_CNTL));
67 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_TRACECFG));
68}
69
Christophe Lombard64663f32017-04-07 16:11:57 +020070void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
Frederic Barrat6d382612016-05-24 03:39:18 +100071{
72 debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1));
73 debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2));
74 debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL));
75 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
76}
77
Christophe Lombardbdd2e712017-04-07 16:11:56 +020078void cxl_debugfs_add_adapter_regs_xsl(struct cxl *adapter, struct dentry *dir)
Frederic Barrat6d382612016-05-24 03:39:18 +100079{
80 debugfs_create_io_x64("fec", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_XSL_FEC));
81}
82
Ian Munsief204e0b2014-10-08 19:55:02 +110083int cxl_debugfs_adapter_add(struct cxl *adapter)
84{
85 struct dentry *dir;
86 char buf[32];
87
88 if (!cxl_debugfs)
89 return -ENODEV;
90
91 snprintf(buf, 32, "card%i", adapter->adapter_num);
92 dir = debugfs_create_dir(buf, cxl_debugfs);
93 if (IS_ERR(dir))
94 return PTR_ERR(dir);
95 adapter->debugfs = dir;
96
Ian Munsief204e0b2014-10-08 19:55:02 +110097 debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
98
Christophe Lombardbdd2e712017-04-07 16:11:56 +020099 if (adapter->native->sl_ops->debugfs_add_adapter_regs)
100 adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
Ian Munsief204e0b2014-10-08 19:55:02 +1100101 return 0;
102}
103
104void cxl_debugfs_adapter_remove(struct cxl *adapter)
105{
106 debugfs_remove_recursive(adapter->debugfs);
107}
108
Christophe Lombardf24be422017-04-12 16:34:07 +0200109void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir)
110{
111 debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
112}
113
Christophe Lombard64663f32017-04-07 16:11:57 +0200114void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
Frederic Barrat6d382612016-05-24 03:39:18 +1000115{
Christophe Lombardabd1d992017-04-07 16:11:58 +0200116 debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
117 debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
118
Frederic Barrat6d382612016-05-24 03:39:18 +1000119 debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
120 debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
121 debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
122 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
123}
124
Ian Munsief204e0b2014-10-08 19:55:02 +1100125int cxl_debugfs_afu_add(struct cxl_afu *afu)
126{
127 struct dentry *dir;
128 char buf[32];
129
130 if (!afu->adapter->debugfs)
131 return -ENODEV;
132
133 snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
134 dir = debugfs_create_dir(buf, afu->adapter->debugfs);
135 if (IS_ERR(dir))
136 return PTR_ERR(dir);
137 afu->debugfs = dir;
138
Ian Munsief204e0b2014-10-08 19:55:02 +1100139 debugfs_create_io_x64("sr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
Ian Munsief204e0b2014-10-08 19:55:02 +1100140 debugfs_create_io_x64("dsisr", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
141 debugfs_create_io_x64("dar", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
Christophe Lombardabd1d992017-04-07 16:11:58 +0200142
Ian Munsief204e0b2014-10-08 19:55:02 +1100143 debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
144
Christophe Lombardbdd2e712017-04-07 16:11:56 +0200145 if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
146 afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
Ian Munsief204e0b2014-10-08 19:55:02 +1100147
148 return 0;
149}
150
151void cxl_debugfs_afu_remove(struct cxl_afu *afu)
152{
153 debugfs_remove_recursive(afu->debugfs);
154}
155
156int __init cxl_debugfs_init(void)
157{
158 struct dentry *ent;
Frederic Barratea2d1f92016-03-04 12:26:30 +0100159
160 if (!cpu_has_feature(CPU_FTR_HVMODE))
161 return 0;
162
Ian Munsief204e0b2014-10-08 19:55:02 +1100163 ent = debugfs_create_dir("cxl", NULL);
164 if (IS_ERR(ent))
165 return PTR_ERR(ent);
166 cxl_debugfs = ent;
167
168 return 0;
169}
170
171void cxl_debugfs_exit(void)
172{
173 debugfs_remove_recursive(cxl_debugfs);
174}