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