Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 IBM Corp. |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/debugfs.h> |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/slab.h> |
| 9 | |
| 10 | #include "cxl.h" |
| 11 | |
| 12 | static struct dentry *cxl_debugfs; |
| 13 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 14 | /* Helpers to export CXL mmaped IO registers via debugfs */ |
| 15 | static int debugfs_io_u64_get(void *data, u64 *val) |
| 16 | { |
| 17 | *val = in_be64((u64 __iomem *)data); |
| 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | static int debugfs_io_u64_set(void *data, u64 val) |
| 22 | { |
| 23 | out_be64((u64 __iomem *)data, val); |
| 24 | return 0; |
| 25 | } |
Andrew Donnellan | 3382a62 | 2016-11-22 21:13:27 +1100 | [diff] [blame] | 26 | DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set, |
| 27 | "0x%016llx\n"); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 28 | |
Greg Kroah-Hartman | 4a14abc | 2019-06-12 17:54:18 +0200 | [diff] [blame] | 29 | static void debugfs_create_io_x64(const char *name, umode_t mode, |
| 30 | struct dentry *parent, u64 __iomem *value) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 31 | { |
Greg Kroah-Hartman | 4a14abc | 2019-06-12 17:54:18 +0200 | [diff] [blame] | 32 | debugfs_create_file_unsafe(name, mode, parent, (void __force *)value, |
| 33 | &fops_io_x64); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 34 | } |
| 35 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame] | 36 | void 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 Jain | 8f6a904 | 2017-10-09 23:26:27 +0530 | [diff] [blame] | 39 | debugfs_create_io_x64("fir_mask", 0400, dir, |
| 40 | _cxl_p1_addr(adapter, CXL_PSL9_FIR_MASK)); |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame] | 41 | 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 Jain | 1cafc629 | 2017-09-20 11:53:22 +0530 | [diff] [blame] | 43 | 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 Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Christophe Lombard | 64663f3 | 2017-04-07 16:11:57 +0200 | [diff] [blame] | 49 | void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir) |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 50 | { |
| 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 | |
Greg Kroah-Hartman | 4a14abc | 2019-06-12 17:54:18 +0200 | [diff] [blame] | 57 | void cxl_debugfs_adapter_add(struct cxl *adapter) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 58 | { |
| 59 | struct dentry *dir; |
| 60 | char buf[32]; |
| 61 | |
| 62 | if (!cxl_debugfs) |
Greg Kroah-Hartman | 4a14abc | 2019-06-12 17:54:18 +0200 | [diff] [blame] | 63 | return; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 64 | |
| 65 | snprintf(buf, 32, "card%i", adapter->adapter_num); |
| 66 | dir = debugfs_create_dir(buf, cxl_debugfs); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 67 | adapter->debugfs = dir; |
| 68 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 69 | debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE)); |
| 70 | |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 71 | if (adapter->native->sl_ops->debugfs_add_adapter_regs) |
| 72 | adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void cxl_debugfs_adapter_remove(struct cxl *adapter) |
| 76 | { |
| 77 | debugfs_remove_recursive(adapter->debugfs); |
| 78 | } |
| 79 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame] | 80 | void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir) |
| 81 | { |
| 82 | debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An)); |
| 83 | } |
| 84 | |
Christophe Lombard | 64663f3 | 2017-04-07 16:11:57 +0200 | [diff] [blame] | 85 | void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir) |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 86 | { |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 87 | debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An)); |
| 88 | debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An)); |
| 89 | |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 90 | debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An)); |
| 91 | debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An)); |
| 92 | debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An)); |
| 93 | debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE)); |
| 94 | } |
| 95 | |
Greg Kroah-Hartman | 4a14abc | 2019-06-12 17:54:18 +0200 | [diff] [blame] | 96 | void cxl_debugfs_afu_add(struct cxl_afu *afu) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 97 | { |
| 98 | struct dentry *dir; |
| 99 | char buf[32]; |
| 100 | |
| 101 | if (!afu->adapter->debugfs) |
Greg Kroah-Hartman | 4a14abc | 2019-06-12 17:54:18 +0200 | [diff] [blame] | 102 | return; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 103 | |
| 104 | snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice); |
| 105 | dir = debugfs_create_dir(buf, afu->adapter->debugfs); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 106 | afu->debugfs = dir; |
| 107 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 108 | debugfs_create_io_x64("sr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An)); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 109 | debugfs_create_io_x64("dsisr", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An)); |
| 110 | debugfs_create_io_x64("dar", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An)); |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 111 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 112 | debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An)); |
| 113 | |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 114 | if (afu->adapter->native->sl_ops->debugfs_add_afu_regs) |
| 115 | afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void cxl_debugfs_afu_remove(struct cxl_afu *afu) |
| 119 | { |
| 120 | debugfs_remove_recursive(afu->debugfs); |
| 121 | } |
| 122 | |
Greg Kroah-Hartman | 4a14abc | 2019-06-12 17:54:18 +0200 | [diff] [blame] | 123 | void __init cxl_debugfs_init(void) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 124 | { |
Frederic Barrat | ea2d1f9 | 2016-03-04 12:26:30 +0100 | [diff] [blame] | 125 | if (!cpu_has_feature(CPU_FTR_HVMODE)) |
Greg Kroah-Hartman | 4a14abc | 2019-06-12 17:54:18 +0200 | [diff] [blame] | 126 | return; |
Frederic Barrat | ea2d1f9 | 2016-03-04 12:26:30 +0100 | [diff] [blame] | 127 | |
Greg Kroah-Hartman | 4a14abc | 2019-06-12 17:54:18 +0200 | [diff] [blame] | 128 | cxl_debugfs = debugfs_create_dir("cxl", NULL); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void cxl_debugfs_exit(void) |
| 132 | { |
| 133 | debugfs_remove_recursive(cxl_debugfs); |
| 134 | } |