blob: 1fda22c24c93eeee183cc9d9a62b4b4ded41094d [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Ian Munsief204e0b2014-10-08 19:55:02 +11002/*
3 * Copyright 2014 IBM Corp.
Ian Munsief204e0b2014-10-08 19:55:02 +11004 */
5
6#include <linux/debugfs.h>
7#include <linux/kernel.h>
8#include <linux/slab.h>
9
10#include "cxl.h"
11
12static struct dentry *cxl_debugfs;
13
Ian Munsief204e0b2014-10-08 19:55:02 +110014/* Helpers to export CXL mmaped IO registers via debugfs */
15static int debugfs_io_u64_get(void *data, u64 *val)
16{
17 *val = in_be64((u64 __iomem *)data);
18 return 0;
19}
20
21static int debugfs_io_u64_set(void *data, u64 val)
22{
23 out_be64((u64 __iomem *)data, val);
24 return 0;
25}
Andrew Donnellan3382a622016-11-22 21:13:27 +110026DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
27 "0x%016llx\n");
Ian Munsief204e0b2014-10-08 19:55:02 +110028
29static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
30 struct dentry *parent, u64 __iomem *value)
31{
Andrew Donnellan3382a622016-11-22 21:13:27 +110032 return debugfs_create_file_unsafe(name, mode, parent,
33 (void __force *)value, &fops_io_x64);
Ian Munsief204e0b2014-10-08 19:55:02 +110034}
35
Christophe Lombardf24be422017-04-12 16:34:07 +020036void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)
37{
38 debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR1));
Vaibhav Jain8f6a9042017-10-09 23:26:27 +053039 debugfs_create_io_x64("fir_mask", 0400, dir,
40 _cxl_p1_addr(adapter, CXL_PSL9_FIR_MASK));
Christophe Lombardf24be422017-04-12 16:34:07 +020041 debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR_CNTL));
42 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_TRACECFG));
Vaibhav Jain1cafc6292017-09-20 11:53:22 +053043 debugfs_create_io_x64("debug", 0600, dir,
44 _cxl_p1_addr(adapter, CXL_PSL9_DEBUG));
45 debugfs_create_io_x64("xsl-debug", 0600, dir,
46 _cxl_p1_addr(adapter, CXL_XSL9_DBG));
Christophe Lombardf24be422017-04-12 16:34:07 +020047}
48
Christophe Lombard64663f32017-04-07 16:11:57 +020049void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
Frederic Barrat6d382612016-05-24 03:39:18 +100050{
51 debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1));
52 debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2));
53 debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL));
54 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
55}
56
Ian Munsief204e0b2014-10-08 19:55:02 +110057int cxl_debugfs_adapter_add(struct cxl *adapter)
58{
59 struct dentry *dir;
60 char buf[32];
61
62 if (!cxl_debugfs)
63 return -ENODEV;
64
65 snprintf(buf, 32, "card%i", adapter->adapter_num);
66 dir = debugfs_create_dir(buf, cxl_debugfs);
67 if (IS_ERR(dir))
68 return PTR_ERR(dir);
69 adapter->debugfs = dir;
70
Ian Munsief204e0b2014-10-08 19:55:02 +110071 debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
72
Christophe Lombardbdd2e712017-04-07 16:11:56 +020073 if (adapter->native->sl_ops->debugfs_add_adapter_regs)
74 adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
Ian Munsief204e0b2014-10-08 19:55:02 +110075 return 0;
76}
77
78void cxl_debugfs_adapter_remove(struct cxl *adapter)
79{
80 debugfs_remove_recursive(adapter->debugfs);
81}
82
Christophe Lombardf24be422017-04-12 16:34:07 +020083void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir)
84{
85 debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
86}
87
Christophe Lombard64663f32017-04-07 16:11:57 +020088void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
Frederic Barrat6d382612016-05-24 03:39:18 +100089{
Christophe Lombardabd1d992017-04-07 16:11:58 +020090 debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
91 debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
92
Frederic Barrat6d382612016-05-24 03:39:18 +100093 debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
94 debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
95 debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
96 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
97}
98
Ian Munsief204e0b2014-10-08 19:55:02 +110099int cxl_debugfs_afu_add(struct cxl_afu *afu)
100{
101 struct dentry *dir;
102 char buf[32];
103
104 if (!afu->adapter->debugfs)
105 return -ENODEV;
106
107 snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
108 dir = debugfs_create_dir(buf, afu->adapter->debugfs);
109 if (IS_ERR(dir))
110 return PTR_ERR(dir);
111 afu->debugfs = dir;
112
Ian Munsief204e0b2014-10-08 19:55:02 +1100113 debugfs_create_io_x64("sr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
Ian Munsief204e0b2014-10-08 19:55:02 +1100114 debugfs_create_io_x64("dsisr", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
115 debugfs_create_io_x64("dar", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
Christophe Lombardabd1d992017-04-07 16:11:58 +0200116
Ian Munsief204e0b2014-10-08 19:55:02 +1100117 debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
118
Christophe Lombardbdd2e712017-04-07 16:11:56 +0200119 if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
120 afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
Ian Munsief204e0b2014-10-08 19:55:02 +1100121
122 return 0;
123}
124
125void cxl_debugfs_afu_remove(struct cxl_afu *afu)
126{
127 debugfs_remove_recursive(afu->debugfs);
128}
129
130int __init cxl_debugfs_init(void)
131{
132 struct dentry *ent;
Frederic Barratea2d1f92016-03-04 12:26:30 +0100133
134 if (!cpu_has_feature(CPU_FTR_HVMODE))
135 return 0;
136
Ian Munsief204e0b2014-10-08 19:55:02 +1100137 ent = debugfs_create_dir("cxl", NULL);
138 if (IS_ERR(ent))
139 return PTR_ERR(ent);
140 cxl_debugfs = ent;
141
142 return 0;
143}
144
145void cxl_debugfs_exit(void)
146{
147 debugfs_remove_recursive(cxl_debugfs);
148}