1 /* 2 * QLogic iSCSI Offload Driver 3 * Copyright (c) 2016 Cavium Inc. 4 * 5 * This software is available under the terms of the GNU General Public License 6 * (GPL) Version 2, available from the file COPYING in the main directory of 7 * this source tree. 8 */ 9 10 #include "qedi.h" 11 #include "qedi_dbg.h" 12 13 #include <linux/uaccess.h> 14 #include <linux/debugfs.h> 15 #include <linux/module.h> 16 17 int qedi_do_not_recover; 18 static struct dentry *qedi_dbg_root; 19 20 void 21 qedi_dbg_host_init(struct qedi_dbg_ctx *qedi, 22 const struct qedi_debugfs_ops *dops, 23 const struct file_operations *fops) 24 { 25 char host_dirname[32]; 26 27 sprintf(host_dirname, "host%u", qedi->host_no); 28 qedi->bdf_dentry = debugfs_create_dir(host_dirname, qedi_dbg_root); 29 30 while (dops) { 31 if (!(dops->name)) 32 break; 33 34 debugfs_create_file(dops->name, 0600, qedi->bdf_dentry, qedi, 35 fops); 36 dops++; 37 fops++; 38 } 39 } 40 41 void 42 qedi_dbg_host_exit(struct qedi_dbg_ctx *qedi) 43 { 44 debugfs_remove_recursive(qedi->bdf_dentry); 45 qedi->bdf_dentry = NULL; 46 } 47 48 void 49 qedi_dbg_init(char *drv_name) 50 { 51 qedi_dbg_root = debugfs_create_dir(drv_name, NULL); 52 } 53 54 void 55 qedi_dbg_exit(void) 56 { 57 debugfs_remove_recursive(qedi_dbg_root); 58 qedi_dbg_root = NULL; 59 } 60 61 static ssize_t 62 qedi_dbg_do_not_recover_enable(struct qedi_dbg_ctx *qedi_dbg) 63 { 64 if (!qedi_do_not_recover) 65 qedi_do_not_recover = 1; 66 67 QEDI_INFO(qedi_dbg, QEDI_LOG_DEBUGFS, "do_not_recover=%d\n", 68 qedi_do_not_recover); 69 return 0; 70 } 71 72 static ssize_t 73 qedi_dbg_do_not_recover_disable(struct qedi_dbg_ctx *qedi_dbg) 74 { 75 if (qedi_do_not_recover) 76 qedi_do_not_recover = 0; 77 78 QEDI_INFO(qedi_dbg, QEDI_LOG_DEBUGFS, "do_not_recover=%d\n", 79 qedi_do_not_recover); 80 return 0; 81 } 82 83 static struct qedi_list_of_funcs qedi_dbg_do_not_recover_ops[] = { 84 { "enable", qedi_dbg_do_not_recover_enable }, 85 { "disable", qedi_dbg_do_not_recover_disable }, 86 { NULL, NULL } 87 }; 88 89 const struct qedi_debugfs_ops qedi_debugfs_ops[] = { 90 { "gbl_ctx", NULL }, 91 { "do_not_recover", qedi_dbg_do_not_recover_ops}, 92 { "io_trace", NULL }, 93 { NULL, NULL } 94 }; 95 96 static ssize_t 97 qedi_dbg_do_not_recover_cmd_write(struct file *filp, const char __user *buffer, 98 size_t count, loff_t *ppos) 99 { 100 size_t cnt = 0; 101 struct qedi_dbg_ctx *qedi_dbg = 102 (struct qedi_dbg_ctx *)filp->private_data; 103 struct qedi_list_of_funcs *lof = qedi_dbg_do_not_recover_ops; 104 105 if (*ppos) 106 return 0; 107 108 while (lof) { 109 if (!(lof->oper_str)) 110 break; 111 112 if (!strncmp(lof->oper_str, buffer, strlen(lof->oper_str))) { 113 cnt = lof->oper_func(qedi_dbg); 114 break; 115 } 116 117 lof++; 118 } 119 return (count - cnt); 120 } 121 122 static ssize_t 123 qedi_dbg_do_not_recover_cmd_read(struct file *filp, char __user *buffer, 124 size_t count, loff_t *ppos) 125 { 126 size_t cnt = 0; 127 128 if (*ppos) 129 return 0; 130 131 cnt = sprintf(buffer, "do_not_recover=%d\n", qedi_do_not_recover); 132 cnt = min_t(int, count, cnt - *ppos); 133 *ppos += cnt; 134 return cnt; 135 } 136 137 static int 138 qedi_gbl_ctx_show(struct seq_file *s, void *unused) 139 { 140 struct qedi_fastpath *fp = NULL; 141 struct qed_sb_info *sb_info = NULL; 142 struct status_block_e4 *sb = NULL; 143 struct global_queue *que = NULL; 144 int id; 145 u16 prod_idx; 146 struct qedi_ctx *qedi = s->private; 147 unsigned long flags; 148 149 seq_puts(s, " DUMP CQ CONTEXT:\n"); 150 151 for (id = 0; id < MIN_NUM_CPUS_MSIX(qedi); id++) { 152 spin_lock_irqsave(&qedi->hba_lock, flags); 153 seq_printf(s, "=========FAST CQ PATH [%d] ==========\n", id); 154 fp = &qedi->fp_array[id]; 155 sb_info = fp->sb_info; 156 sb = sb_info->sb_virt; 157 prod_idx = (sb->pi_array[QEDI_PROTO_CQ_PROD_IDX] & 158 STATUS_BLOCK_E4_PROD_INDEX_MASK); 159 seq_printf(s, "SB PROD IDX: %d\n", prod_idx); 160 que = qedi->global_queues[fp->sb_id]; 161 seq_printf(s, "DRV CONS IDX: %d\n", que->cq_cons_idx); 162 seq_printf(s, "CQ complete host memory: %d\n", fp->sb_id); 163 seq_puts(s, "=========== END ==================\n\n\n"); 164 spin_unlock_irqrestore(&qedi->hba_lock, flags); 165 } 166 return 0; 167 } 168 169 static int 170 qedi_dbg_gbl_ctx_open(struct inode *inode, struct file *file) 171 { 172 struct qedi_dbg_ctx *qedi_dbg = inode->i_private; 173 struct qedi_ctx *qedi = container_of(qedi_dbg, struct qedi_ctx, 174 dbg_ctx); 175 176 return single_open(file, qedi_gbl_ctx_show, qedi); 177 } 178 179 static int 180 qedi_io_trace_show(struct seq_file *s, void *unused) 181 { 182 int id, idx = 0; 183 struct qedi_ctx *qedi = s->private; 184 struct qedi_io_log *io_log; 185 unsigned long flags; 186 187 seq_puts(s, " DUMP IO LOGS:\n"); 188 spin_lock_irqsave(&qedi->io_trace_lock, flags); 189 idx = qedi->io_trace_idx; 190 for (id = 0; id < QEDI_IO_TRACE_SIZE; id++) { 191 io_log = &qedi->io_trace_buf[idx]; 192 seq_printf(s, "iodir-%d:", io_log->direction); 193 seq_printf(s, "tid-0x%x:", io_log->task_id); 194 seq_printf(s, "cid-0x%x:", io_log->cid); 195 seq_printf(s, "lun-%d:", io_log->lun); 196 seq_printf(s, "op-0x%02x:", io_log->op); 197 seq_printf(s, "0x%02x%02x%02x%02x:", io_log->lba[0], 198 io_log->lba[1], io_log->lba[2], io_log->lba[3]); 199 seq_printf(s, "buflen-%d:", io_log->bufflen); 200 seq_printf(s, "sgcnt-%d:", io_log->sg_count); 201 seq_printf(s, "res-0x%08x:", io_log->result); 202 seq_printf(s, "jif-%lu:", io_log->jiffies); 203 seq_printf(s, "blk_req_cpu-%d:", io_log->blk_req_cpu); 204 seq_printf(s, "req_cpu-%d:", io_log->req_cpu); 205 seq_printf(s, "intr_cpu-%d:", io_log->intr_cpu); 206 seq_printf(s, "blk_rsp_cpu-%d\n", io_log->blk_rsp_cpu); 207 208 idx++; 209 if (idx == QEDI_IO_TRACE_SIZE) 210 idx = 0; 211 } 212 spin_unlock_irqrestore(&qedi->io_trace_lock, flags); 213 return 0; 214 } 215 216 static int 217 qedi_dbg_io_trace_open(struct inode *inode, struct file *file) 218 { 219 struct qedi_dbg_ctx *qedi_dbg = inode->i_private; 220 struct qedi_ctx *qedi = container_of(qedi_dbg, struct qedi_ctx, 221 dbg_ctx); 222 223 return single_open(file, qedi_io_trace_show, qedi); 224 } 225 226 const struct file_operations qedi_dbg_fops[] = { 227 qedi_dbg_fileops_seq(qedi, gbl_ctx), 228 qedi_dbg_fileops(qedi, do_not_recover), 229 qedi_dbg_fileops_seq(qedi, io_trace), 230 { }, 231 }; 232