1 /* 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 16 static struct dentry *cxl_debugfs; 17 18 void cxl_stop_trace_psl9(struct cxl *adapter) 19 { 20 /* Stop the trace */ 21 cxl_p1_write(adapter, CXL_PSL9_TRACECFG, 0x4480000000000000ULL); 22 } 23 24 void cxl_stop_trace_psl8(struct cxl *adapter) 25 { 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 */ 41 static int debugfs_io_u64_get(void *data, u64 *val) 42 { 43 *val = in_be64((u64 __iomem *)data); 44 return 0; 45 } 46 47 static int debugfs_io_u64_set(void *data, u64 val) 48 { 49 out_be64((u64 __iomem *)data, val); 50 return 0; 51 } 52 DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set, 53 "0x%016llx\n"); 54 55 static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode, 56 struct dentry *parent, u64 __iomem *value) 57 { 58 return debugfs_create_file_unsafe(name, mode, parent, 59 (void __force *)value, &fops_io_x64); 60 } 61 62 void 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("fir_mask", 0400, dir, 66 _cxl_p1_addr(adapter, CXL_PSL9_FIR_MASK)); 67 debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR_CNTL)); 68 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_TRACECFG)); 69 debugfs_create_io_x64("debug", 0600, dir, 70 _cxl_p1_addr(adapter, CXL_PSL9_DEBUG)); 71 debugfs_create_io_x64("xsl-debug", 0600, dir, 72 _cxl_p1_addr(adapter, CXL_XSL9_DBG)); 73 } 74 75 void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir) 76 { 77 debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1)); 78 debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2)); 79 debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL)); 80 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE)); 81 } 82 83 void cxl_debugfs_add_adapter_regs_xsl(struct cxl *adapter, struct dentry *dir) 84 { 85 debugfs_create_io_x64("fec", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_XSL_FEC)); 86 } 87 88 int cxl_debugfs_adapter_add(struct cxl *adapter) 89 { 90 struct dentry *dir; 91 char buf[32]; 92 93 if (!cxl_debugfs) 94 return -ENODEV; 95 96 snprintf(buf, 32, "card%i", adapter->adapter_num); 97 dir = debugfs_create_dir(buf, cxl_debugfs); 98 if (IS_ERR(dir)) 99 return PTR_ERR(dir); 100 adapter->debugfs = dir; 101 102 debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE)); 103 104 if (adapter->native->sl_ops->debugfs_add_adapter_regs) 105 adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir); 106 return 0; 107 } 108 109 void cxl_debugfs_adapter_remove(struct cxl *adapter) 110 { 111 debugfs_remove_recursive(adapter->debugfs); 112 } 113 114 void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir) 115 { 116 debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An)); 117 } 118 119 void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir) 120 { 121 debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An)); 122 debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An)); 123 124 debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An)); 125 debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An)); 126 debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An)); 127 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE)); 128 } 129 130 int cxl_debugfs_afu_add(struct cxl_afu *afu) 131 { 132 struct dentry *dir; 133 char buf[32]; 134 135 if (!afu->adapter->debugfs) 136 return -ENODEV; 137 138 snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice); 139 dir = debugfs_create_dir(buf, afu->adapter->debugfs); 140 if (IS_ERR(dir)) 141 return PTR_ERR(dir); 142 afu->debugfs = dir; 143 144 debugfs_create_io_x64("sr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An)); 145 debugfs_create_io_x64("dsisr", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An)); 146 debugfs_create_io_x64("dar", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An)); 147 148 debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An)); 149 150 if (afu->adapter->native->sl_ops->debugfs_add_afu_regs) 151 afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir); 152 153 return 0; 154 } 155 156 void cxl_debugfs_afu_remove(struct cxl_afu *afu) 157 { 158 debugfs_remove_recursive(afu->debugfs); 159 } 160 161 int __init cxl_debugfs_init(void) 162 { 163 struct dentry *ent; 164 165 if (!cpu_has_feature(CPU_FTR_HVMODE)) 166 return 0; 167 168 ent = debugfs_create_dir("cxl", NULL); 169 if (IS_ERR(ent)) 170 return PTR_ERR(ent); 171 cxl_debugfs = ent; 172 173 return 0; 174 } 175 176 void cxl_debugfs_exit(void) 177 { 178 debugfs_remove_recursive(cxl_debugfs); 179 } 180