1 /* 2 * QLogic Fibre Channel HBA Driver 3 * Copyright (c) 2003-2014 QLogic Corporation 4 * 5 * See LICENSE.qla2xxx for copyright and licensing details. 6 */ 7 #include "qla_def.h" 8 9 #include <linux/debugfs.h> 10 #include <linux/seq_file.h> 11 12 static struct dentry *qla2x00_dfs_root; 13 static atomic_t qla2x00_dfs_root_count; 14 15 static int 16 qla_dfs_fw_resource_cnt_show(struct seq_file *s, void *unused) 17 { 18 struct scsi_qla_host *vha = s->private; 19 struct qla_hw_data *ha = vha->hw; 20 21 seq_puts(s, "FW Resource count\n\n"); 22 seq_printf(s, "Original TGT exchg count[%d]\n", 23 ha->orig_fw_tgt_xcb_count); 24 seq_printf(s, "current TGT exchg count[%d]\n", 25 ha->cur_fw_tgt_xcb_count); 26 seq_printf(s, "original Initiator Exchange count[%d]\n", 27 ha->orig_fw_xcb_count); 28 seq_printf(s, "Current Initiator Exchange count[%d]\n", 29 ha->cur_fw_xcb_count); 30 seq_printf(s, "Original IOCB count[%d]\n", ha->orig_fw_iocb_count); 31 seq_printf(s, "Current IOCB count[%d]\n", ha->cur_fw_iocb_count); 32 seq_printf(s, "MAX VP count[%d]\n", ha->max_npiv_vports); 33 seq_printf(s, "MAX FCF count[%d]\n", ha->fw_max_fcf_count); 34 35 return 0; 36 } 37 38 static int 39 qla_dfs_fw_resource_cnt_open(struct inode *inode, struct file *file) 40 { 41 struct scsi_qla_host *vha = inode->i_private; 42 return single_open(file, qla_dfs_fw_resource_cnt_show, vha); 43 } 44 45 static const struct file_operations dfs_fw_resource_cnt_ops = { 46 .open = qla_dfs_fw_resource_cnt_open, 47 .read = seq_read, 48 .llseek = seq_lseek, 49 .release = single_release, 50 }; 51 52 static int 53 qla_dfs_tgt_counters_show(struct seq_file *s, void *unused) 54 { 55 struct scsi_qla_host *vha = s->private; 56 57 seq_puts(s, "Target Counters\n"); 58 seq_printf(s, "qla_core_sbt_cmd = %lld\n", 59 vha->tgt_counters.qla_core_sbt_cmd); 60 seq_printf(s, "qla_core_ret_sta_ctio = %lld\n", 61 vha->tgt_counters.qla_core_ret_sta_ctio); 62 seq_printf(s, "qla_core_ret_ctio = %lld\n", 63 vha->tgt_counters.qla_core_ret_ctio); 64 seq_printf(s, "core_qla_que_buf = %lld\n", 65 vha->tgt_counters.core_qla_que_buf); 66 seq_printf(s, "core_qla_snd_status = %lld\n", 67 vha->tgt_counters.core_qla_snd_status); 68 seq_printf(s, "core_qla_free_cmd = %lld\n", 69 vha->tgt_counters.core_qla_free_cmd); 70 seq_printf(s, "num alloc iocb failed = %lld\n", 71 vha->tgt_counters.num_alloc_iocb_failed); 72 seq_printf(s, "num term exchange sent = %lld\n", 73 vha->tgt_counters.num_term_xchg_sent); 74 seq_printf(s, "num Q full sent = %lld\n", 75 vha->tgt_counters.num_q_full_sent); 76 77 return 0; 78 } 79 80 static int 81 qla_dfs_tgt_counters_open(struct inode *inode, struct file *file) 82 { 83 struct scsi_qla_host *vha = inode->i_private; 84 return single_open(file, qla_dfs_tgt_counters_show, vha); 85 } 86 87 static const struct file_operations dfs_tgt_counters_ops = { 88 .open = qla_dfs_tgt_counters_open, 89 .read = seq_read, 90 .llseek = seq_lseek, 91 .release = single_release, 92 }; 93 94 static int 95 qla2x00_dfs_fce_show(struct seq_file *s, void *unused) 96 { 97 scsi_qla_host_t *vha = s->private; 98 uint32_t cnt; 99 uint32_t *fce; 100 uint64_t fce_start; 101 struct qla_hw_data *ha = vha->hw; 102 103 mutex_lock(&ha->fce_mutex); 104 105 seq_puts(s, "FCE Trace Buffer\n"); 106 seq_printf(s, "In Pointer = %llx\n\n", (unsigned long long)ha->fce_wr); 107 seq_printf(s, "Base = %llx\n\n", (unsigned long long) ha->fce_dma); 108 seq_puts(s, "FCE Enable Registers\n"); 109 seq_printf(s, "%08x %08x %08x %08x %08x %08x\n", 110 ha->fce_mb[0], ha->fce_mb[2], ha->fce_mb[3], ha->fce_mb[4], 111 ha->fce_mb[5], ha->fce_mb[6]); 112 113 fce = (uint32_t *) ha->fce; 114 fce_start = (unsigned long long) ha->fce_dma; 115 for (cnt = 0; cnt < fce_calc_size(ha->fce_bufs) / 4; cnt++) { 116 if (cnt % 8 == 0) 117 seq_printf(s, "\n%llx: ", 118 (unsigned long long)((cnt * 4) + fce_start)); 119 else 120 seq_putc(s, ' '); 121 seq_printf(s, "%08x", *fce++); 122 } 123 124 seq_puts(s, "\nEnd\n"); 125 126 mutex_unlock(&ha->fce_mutex); 127 128 return 0; 129 } 130 131 static int 132 qla2x00_dfs_fce_open(struct inode *inode, struct file *file) 133 { 134 scsi_qla_host_t *vha = inode->i_private; 135 struct qla_hw_data *ha = vha->hw; 136 int rval; 137 138 if (!ha->flags.fce_enabled) 139 goto out; 140 141 mutex_lock(&ha->fce_mutex); 142 143 /* Pause tracing to flush FCE buffers. */ 144 rval = qla2x00_disable_fce_trace(vha, &ha->fce_wr, &ha->fce_rd); 145 if (rval) 146 ql_dbg(ql_dbg_user, vha, 0x705c, 147 "DebugFS: Unable to disable FCE (%d).\n", rval); 148 149 ha->flags.fce_enabled = 0; 150 151 mutex_unlock(&ha->fce_mutex); 152 out: 153 return single_open(file, qla2x00_dfs_fce_show, vha); 154 } 155 156 static int 157 qla2x00_dfs_fce_release(struct inode *inode, struct file *file) 158 { 159 scsi_qla_host_t *vha = inode->i_private; 160 struct qla_hw_data *ha = vha->hw; 161 int rval; 162 163 if (ha->flags.fce_enabled) 164 goto out; 165 166 mutex_lock(&ha->fce_mutex); 167 168 /* Re-enable FCE tracing. */ 169 ha->flags.fce_enabled = 1; 170 memset(ha->fce, 0, fce_calc_size(ha->fce_bufs)); 171 rval = qla2x00_enable_fce_trace(vha, ha->fce_dma, ha->fce_bufs, 172 ha->fce_mb, &ha->fce_bufs); 173 if (rval) { 174 ql_dbg(ql_dbg_user, vha, 0x700d, 175 "DebugFS: Unable to reinitialize FCE (%d).\n", rval); 176 ha->flags.fce_enabled = 0; 177 } 178 179 mutex_unlock(&ha->fce_mutex); 180 out: 181 return single_release(inode, file); 182 } 183 184 static const struct file_operations dfs_fce_ops = { 185 .open = qla2x00_dfs_fce_open, 186 .read = seq_read, 187 .llseek = seq_lseek, 188 .release = qla2x00_dfs_fce_release, 189 }; 190 191 int 192 qla2x00_dfs_setup(scsi_qla_host_t *vha) 193 { 194 struct qla_hw_data *ha = vha->hw; 195 196 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && 197 !IS_QLA27XX(ha)) 198 goto out; 199 if (!ha->fce) 200 goto out; 201 202 if (qla2x00_dfs_root) 203 goto create_dir; 204 205 atomic_set(&qla2x00_dfs_root_count, 0); 206 qla2x00_dfs_root = debugfs_create_dir(QLA2XXX_DRIVER_NAME, NULL); 207 if (!qla2x00_dfs_root) { 208 ql_log(ql_log_warn, vha, 0x00f7, 209 "Unable to create debugfs root directory.\n"); 210 goto out; 211 } 212 213 create_dir: 214 if (ha->dfs_dir) 215 goto create_nodes; 216 217 mutex_init(&ha->fce_mutex); 218 ha->dfs_dir = debugfs_create_dir(vha->host_str, qla2x00_dfs_root); 219 if (!ha->dfs_dir) { 220 ql_log(ql_log_warn, vha, 0x00f8, 221 "Unable to create debugfs ha directory.\n"); 222 goto out; 223 } 224 225 atomic_inc(&qla2x00_dfs_root_count); 226 227 create_nodes: 228 ha->dfs_fw_resource_cnt = debugfs_create_file("fw_resource_count", 229 S_IRUSR, ha->dfs_dir, vha, &dfs_fw_resource_cnt_ops); 230 if (!ha->dfs_fw_resource_cnt) { 231 ql_log(ql_log_warn, vha, 0x00fd, 232 "Unable to create debugFS fw_resource_count node.\n"); 233 goto out; 234 } 235 236 ha->dfs_tgt_counters = debugfs_create_file("tgt_counters", S_IRUSR, 237 ha->dfs_dir, vha, &dfs_tgt_counters_ops); 238 if (!ha->dfs_tgt_counters) { 239 ql_log(ql_log_warn, vha, 0xd301, 240 "Unable to create debugFS tgt_counters node.\n"); 241 goto out; 242 } 243 244 ha->dfs_fce = debugfs_create_file("fce", S_IRUSR, ha->dfs_dir, vha, 245 &dfs_fce_ops); 246 if (!ha->dfs_fce) { 247 ql_log(ql_log_warn, vha, 0x00f9, 248 "Unable to create debugfs fce node.\n"); 249 goto out; 250 } 251 out: 252 return 0; 253 } 254 255 int 256 qla2x00_dfs_remove(scsi_qla_host_t *vha) 257 { 258 struct qla_hw_data *ha = vha->hw; 259 260 if (ha->dfs_fw_resource_cnt) { 261 debugfs_remove(ha->dfs_fw_resource_cnt); 262 ha->dfs_fw_resource_cnt = NULL; 263 } 264 265 if (ha->dfs_tgt_counters) { 266 debugfs_remove(ha->dfs_tgt_counters); 267 ha->dfs_tgt_counters = NULL; 268 } 269 270 if (ha->dfs_fce) { 271 debugfs_remove(ha->dfs_fce); 272 ha->dfs_fce = NULL; 273 } 274 275 if (ha->dfs_dir) { 276 debugfs_remove(ha->dfs_dir); 277 ha->dfs_dir = NULL; 278 atomic_dec(&qla2x00_dfs_root_count); 279 } 280 281 if (atomic_read(&qla2x00_dfs_root_count) == 0 && 282 qla2x00_dfs_root) { 283 debugfs_remove(qla2x00_dfs_root); 284 qla2x00_dfs_root = NULL; 285 } 286 287 return 0; 288 } 289