blob: 43a1a27c54d128c127d7d2a74ee1457d39efdfb6 [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 Lombard64663f32017-04-07 16:11:57 +020018void cxl_stop_trace_psl8(struct cxl *adapter)
Ian Munsief204e0b2014-10-08 19:55:02 +110019{
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 */
35static int debugfs_io_u64_get(void *data, u64 *val)
36{
37 *val = in_be64((u64 __iomem *)data);
38 return 0;
39}
40
41static int debugfs_io_u64_set(void *data, u64 val)
42{
43 out_be64((u64 __iomem *)data, val);
44 return 0;
45}
Andrew Donnellan3382a622016-11-22 21:13:27 +110046DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
47 "0x%016llx\n");
Ian Munsief204e0b2014-10-08 19:55:02 +110048
49static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
50 struct dentry *parent, u64 __iomem *value)
51{
Andrew Donnellan3382a622016-11-22 21:13:27 +110052 return debugfs_create_file_unsafe(name, mode, parent,
53 (void __force *)value, &fops_io_x64);
Ian Munsief204e0b2014-10-08 19:55:02 +110054}
55
Christophe Lombard64663f32017-04-07 16:11:57 +020056void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
Frederic Barrat6d382612016-05-24 03:39:18 +100057{
58 debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1));
59 debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2));
60 debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL));
61 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
62}
63
Christophe Lombardbdd2e712017-04-07 16:11:56 +020064void cxl_debugfs_add_adapter_regs_xsl(struct cxl *adapter, struct dentry *dir)
Frederic Barrat6d382612016-05-24 03:39:18 +100065{
66 debugfs_create_io_x64("fec", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_XSL_FEC));
67}
68
Ian Munsief204e0b2014-10-08 19:55:02 +110069int cxl_debugfs_adapter_add(struct cxl *adapter)
70{
71 struct dentry *dir;
72 char buf[32];
73
74 if (!cxl_debugfs)
75 return -ENODEV;
76
77 snprintf(buf, 32, "card%i", adapter->adapter_num);
78 dir = debugfs_create_dir(buf, cxl_debugfs);
79 if (IS_ERR(dir))
80 return PTR_ERR(dir);
81 adapter->debugfs = dir;
82
Ian Munsief204e0b2014-10-08 19:55:02 +110083 debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
84
Christophe Lombardbdd2e712017-04-07 16:11:56 +020085 if (adapter->native->sl_ops->debugfs_add_adapter_regs)
86 adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
Ian Munsief204e0b2014-10-08 19:55:02 +110087 return 0;
88}
89
90void cxl_debugfs_adapter_remove(struct cxl *adapter)
91{
92 debugfs_remove_recursive(adapter->debugfs);
93}
94
Christophe Lombard64663f32017-04-07 16:11:57 +020095void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
Frederic Barrat6d382612016-05-24 03:39:18 +100096{
Christophe Lombardabd1d992017-04-07 16:11:58 +020097 debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
98 debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
99
Frederic Barrat6d382612016-05-24 03:39:18 +1000100 debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
101 debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
102 debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
103 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
104}
105
Ian Munsief204e0b2014-10-08 19:55:02 +1100106int cxl_debugfs_afu_add(struct cxl_afu *afu)
107{
108 struct dentry *dir;
109 char buf[32];
110
111 if (!afu->adapter->debugfs)
112 return -ENODEV;
113
114 snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
115 dir = debugfs_create_dir(buf, afu->adapter->debugfs);
116 if (IS_ERR(dir))
117 return PTR_ERR(dir);
118 afu->debugfs = dir;
119
Ian Munsief204e0b2014-10-08 19:55:02 +1100120 debugfs_create_io_x64("sr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
Ian Munsief204e0b2014-10-08 19:55:02 +1100121 debugfs_create_io_x64("dsisr", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
122 debugfs_create_io_x64("dar", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
Christophe Lombardabd1d992017-04-07 16:11:58 +0200123
Ian Munsief204e0b2014-10-08 19:55:02 +1100124 debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
125
Christophe Lombardbdd2e712017-04-07 16:11:56 +0200126 if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
127 afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
Ian Munsief204e0b2014-10-08 19:55:02 +1100128
129 return 0;
130}
131
132void cxl_debugfs_afu_remove(struct cxl_afu *afu)
133{
134 debugfs_remove_recursive(afu->debugfs);
135}
136
137int __init cxl_debugfs_init(void)
138{
139 struct dentry *ent;
Frederic Barratea2d1f92016-03-04 12:26:30 +0100140
141 if (!cpu_has_feature(CPU_FTR_HVMODE))
142 return 0;
143
Ian Munsief204e0b2014-10-08 19:55:02 +1100144 ent = debugfs_create_dir("cxl", NULL);
145 if (IS_ERR(ent))
146 return PTR_ERR(ent);
147 cxl_debugfs = ent;
148
149 return 0;
150}
151
152void cxl_debugfs_exit(void)
153{
154 debugfs_remove_recursive(cxl_debugfs);
155}