blob: 1643850d2302d042349a1953fa81acdaf5eb7c1a [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
Ian Munsief204e0b2014-10-08 19:55:02 +110018/* Helpers to export CXL mmaped IO registers via debugfs */
19static int debugfs_io_u64_get(void *data, u64 *val)
20{
21 *val = in_be64((u64 __iomem *)data);
22 return 0;
23}
24
25static int debugfs_io_u64_set(void *data, u64 val)
26{
27 out_be64((u64 __iomem *)data, val);
28 return 0;
29}
Andrew Donnellan3382a622016-11-22 21:13:27 +110030DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
31 "0x%016llx\n");
Ian Munsief204e0b2014-10-08 19:55:02 +110032
33static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
34 struct dentry *parent, u64 __iomem *value)
35{
Andrew Donnellan3382a622016-11-22 21:13:27 +110036 return debugfs_create_file_unsafe(name, mode, parent,
37 (void __force *)value, &fops_io_x64);
Ian Munsief204e0b2014-10-08 19:55:02 +110038}
39
Christophe Lombardf24be422017-04-12 16:34:07 +020040void 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));
Vaibhav Jain8f6a9042017-10-09 23:26:27 +053043 debugfs_create_io_x64("fir_mask", 0400, dir,
44 _cxl_p1_addr(adapter, CXL_PSL9_FIR_MASK));
Christophe Lombardf24be422017-04-12 16:34:07 +020045 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));
Vaibhav Jain1cafc622017-09-20 11:53:22 +053047 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));
Christophe Lombardf24be422017-04-12 16:34:07 +020051}
52
Christophe Lombard64663f32017-04-07 16:11:57 +020053void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
Frederic Barrat6d382612016-05-24 03:39:18 +100054{
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
Christophe Lombardbdd2e712017-04-07 16:11:56 +020061void cxl_debugfs_add_adapter_regs_xsl(struct cxl *adapter, struct dentry *dir)
Frederic Barrat6d382612016-05-24 03:39:18 +100062{
63 debugfs_create_io_x64("fec", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_XSL_FEC));
64}
65
Ian Munsief204e0b2014-10-08 19:55:02 +110066int 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
Ian Munsief204e0b2014-10-08 19:55:02 +110080 debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
81
Christophe Lombardbdd2e712017-04-07 16:11:56 +020082 if (adapter->native->sl_ops->debugfs_add_adapter_regs)
83 adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
Ian Munsief204e0b2014-10-08 19:55:02 +110084 return 0;
85}
86
87void cxl_debugfs_adapter_remove(struct cxl *adapter)
88{
89 debugfs_remove_recursive(adapter->debugfs);
90}
91
Christophe Lombardf24be422017-04-12 16:34:07 +020092void 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
Christophe Lombard64663f32017-04-07 16:11:57 +020097void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
Frederic Barrat6d382612016-05-24 03:39:18 +100098{
Christophe Lombardabd1d992017-04-07 16:11:58 +020099 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
Frederic Barrat6d382612016-05-24 03:39:18 +1000102 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
Ian Munsief204e0b2014-10-08 19:55:02 +1100108int 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
Ian Munsief204e0b2014-10-08 19:55:02 +1100122 debugfs_create_io_x64("sr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
Ian Munsief204e0b2014-10-08 19:55:02 +1100123 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));
Christophe Lombardabd1d992017-04-07 16:11:58 +0200125
Ian Munsief204e0b2014-10-08 19:55:02 +1100126 debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
127
Christophe Lombardbdd2e712017-04-07 16:11:56 +0200128 if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
129 afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
Ian Munsief204e0b2014-10-08 19:55:02 +1100130
131 return 0;
132}
133
134void cxl_debugfs_afu_remove(struct cxl_afu *afu)
135{
136 debugfs_remove_recursive(afu->debugfs);
137}
138
139int __init cxl_debugfs_init(void)
140{
141 struct dentry *ent;
Frederic Barratea2d1f92016-03-04 12:26:30 +0100142
143 if (!cpu_has_feature(CPU_FTR_HVMODE))
144 return 0;
145
Ian Munsief204e0b2014-10-08 19:55:02 +1100146 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
154void cxl_debugfs_exit(void)
155{
156 debugfs_remove_recursive(cxl_debugfs);
157}