0001
0002
0003
0004
0005
0006
0007 #include "qedi.h"
0008 #include "qedi_dbg.h"
0009
0010 #include <linux/uaccess.h>
0011 #include <linux/debugfs.h>
0012 #include <linux/module.h>
0013
0014 int qedi_do_not_recover;
0015 static struct dentry *qedi_dbg_root;
0016
0017 void
0018 qedi_dbg_host_init(struct qedi_dbg_ctx *qedi,
0019 const struct qedi_debugfs_ops *dops,
0020 const struct file_operations *fops)
0021 {
0022 char host_dirname[32];
0023
0024 sprintf(host_dirname, "host%u", qedi->host_no);
0025 qedi->bdf_dentry = debugfs_create_dir(host_dirname, qedi_dbg_root);
0026
0027 while (dops) {
0028 if (!(dops->name))
0029 break;
0030
0031 debugfs_create_file(dops->name, 0600, qedi->bdf_dentry, qedi,
0032 fops);
0033 dops++;
0034 fops++;
0035 }
0036 }
0037
0038 void
0039 qedi_dbg_host_exit(struct qedi_dbg_ctx *qedi)
0040 {
0041 debugfs_remove_recursive(qedi->bdf_dentry);
0042 qedi->bdf_dentry = NULL;
0043 }
0044
0045 void
0046 qedi_dbg_init(char *drv_name)
0047 {
0048 qedi_dbg_root = debugfs_create_dir(drv_name, NULL);
0049 }
0050
0051 void
0052 qedi_dbg_exit(void)
0053 {
0054 debugfs_remove_recursive(qedi_dbg_root);
0055 qedi_dbg_root = NULL;
0056 }
0057
0058 static ssize_t
0059 qedi_dbg_do_not_recover_enable(struct qedi_dbg_ctx *qedi_dbg)
0060 {
0061 if (!qedi_do_not_recover)
0062 qedi_do_not_recover = 1;
0063
0064 QEDI_INFO(qedi_dbg, QEDI_LOG_DEBUGFS, "do_not_recover=%d\n",
0065 qedi_do_not_recover);
0066 return 0;
0067 }
0068
0069 static ssize_t
0070 qedi_dbg_do_not_recover_disable(struct qedi_dbg_ctx *qedi_dbg)
0071 {
0072 if (qedi_do_not_recover)
0073 qedi_do_not_recover = 0;
0074
0075 QEDI_INFO(qedi_dbg, QEDI_LOG_DEBUGFS, "do_not_recover=%d\n",
0076 qedi_do_not_recover);
0077 return 0;
0078 }
0079
0080 static struct qedi_list_of_funcs qedi_dbg_do_not_recover_ops[] = {
0081 { "enable", qedi_dbg_do_not_recover_enable },
0082 { "disable", qedi_dbg_do_not_recover_disable },
0083 { NULL, NULL }
0084 };
0085
0086 const struct qedi_debugfs_ops qedi_debugfs_ops[] = {
0087 { "gbl_ctx", NULL },
0088 { "do_not_recover", qedi_dbg_do_not_recover_ops},
0089 { "io_trace", NULL },
0090 { NULL, NULL }
0091 };
0092
0093 static ssize_t
0094 qedi_dbg_do_not_recover_cmd_write(struct file *filp, const char __user *buffer,
0095 size_t count, loff_t *ppos)
0096 {
0097 size_t cnt = 0;
0098 struct qedi_dbg_ctx *qedi_dbg =
0099 (struct qedi_dbg_ctx *)filp->private_data;
0100 struct qedi_list_of_funcs *lof = qedi_dbg_do_not_recover_ops;
0101
0102 if (*ppos)
0103 return 0;
0104
0105 while (lof) {
0106 if (!(lof->oper_str))
0107 break;
0108
0109 if (!strncmp(lof->oper_str, buffer, strlen(lof->oper_str))) {
0110 cnt = lof->oper_func(qedi_dbg);
0111 break;
0112 }
0113
0114 lof++;
0115 }
0116 return (count - cnt);
0117 }
0118
0119 static ssize_t
0120 qedi_dbg_do_not_recover_cmd_read(struct file *filp, char __user *buffer,
0121 size_t count, loff_t *ppos)
0122 {
0123 size_t cnt = 0;
0124
0125 if (*ppos)
0126 return 0;
0127
0128 cnt = sprintf(buffer, "do_not_recover=%d\n", qedi_do_not_recover);
0129 cnt = min_t(int, count, cnt - *ppos);
0130 *ppos += cnt;
0131 return cnt;
0132 }
0133
0134 static int
0135 qedi_gbl_ctx_show(struct seq_file *s, void *unused)
0136 {
0137 struct qedi_fastpath *fp = NULL;
0138 struct qed_sb_info *sb_info = NULL;
0139 struct status_block *sb = NULL;
0140 struct global_queue *que = NULL;
0141 int id;
0142 u16 prod_idx;
0143 struct qedi_ctx *qedi = s->private;
0144 unsigned long flags;
0145
0146 seq_puts(s, " DUMP CQ CONTEXT:\n");
0147
0148 for (id = 0; id < MIN_NUM_CPUS_MSIX(qedi); id++) {
0149 spin_lock_irqsave(&qedi->hba_lock, flags);
0150 seq_printf(s, "=========FAST CQ PATH [%d] ==========\n", id);
0151 fp = &qedi->fp_array[id];
0152 sb_info = fp->sb_info;
0153 sb = sb_info->sb_virt;
0154 prod_idx = (sb->pi_array[QEDI_PROTO_CQ_PROD_IDX] &
0155 STATUS_BLOCK_PROD_INDEX_MASK);
0156 seq_printf(s, "SB PROD IDX: %d\n", prod_idx);
0157 que = qedi->global_queues[fp->sb_id];
0158 seq_printf(s, "DRV CONS IDX: %d\n", que->cq_cons_idx);
0159 seq_printf(s, "CQ complete host memory: %d\n", fp->sb_id);
0160 seq_puts(s, "=========== END ==================\n\n\n");
0161 spin_unlock_irqrestore(&qedi->hba_lock, flags);
0162 }
0163 return 0;
0164 }
0165
0166 static int
0167 qedi_dbg_gbl_ctx_open(struct inode *inode, struct file *file)
0168 {
0169 struct qedi_dbg_ctx *qedi_dbg = inode->i_private;
0170 struct qedi_ctx *qedi = container_of(qedi_dbg, struct qedi_ctx,
0171 dbg_ctx);
0172
0173 return single_open(file, qedi_gbl_ctx_show, qedi);
0174 }
0175
0176 static int
0177 qedi_io_trace_show(struct seq_file *s, void *unused)
0178 {
0179 int id, idx = 0;
0180 struct qedi_ctx *qedi = s->private;
0181 struct qedi_io_log *io_log;
0182 unsigned long flags;
0183
0184 seq_puts(s, " DUMP IO LOGS:\n");
0185 spin_lock_irqsave(&qedi->io_trace_lock, flags);
0186 idx = qedi->io_trace_idx;
0187 for (id = 0; id < QEDI_IO_TRACE_SIZE; id++) {
0188 io_log = &qedi->io_trace_buf[idx];
0189 seq_printf(s, "iodir-%d:", io_log->direction);
0190 seq_printf(s, "tid-0x%x:", io_log->task_id);
0191 seq_printf(s, "cid-0x%x:", io_log->cid);
0192 seq_printf(s, "lun-%d:", io_log->lun);
0193 seq_printf(s, "op-0x%02x:", io_log->op);
0194 seq_printf(s, "0x%02x%02x%02x%02x:", io_log->lba[0],
0195 io_log->lba[1], io_log->lba[2], io_log->lba[3]);
0196 seq_printf(s, "buflen-%d:", io_log->bufflen);
0197 seq_printf(s, "sgcnt-%d:", io_log->sg_count);
0198 seq_printf(s, "res-0x%08x:", io_log->result);
0199 seq_printf(s, "jif-%lu:", io_log->jiffies);
0200 seq_printf(s, "blk_req_cpu-%d:", io_log->blk_req_cpu);
0201 seq_printf(s, "req_cpu-%d:", io_log->req_cpu);
0202 seq_printf(s, "intr_cpu-%d:", io_log->intr_cpu);
0203 seq_printf(s, "blk_rsp_cpu-%d\n", io_log->blk_rsp_cpu);
0204
0205 idx++;
0206 if (idx == QEDI_IO_TRACE_SIZE)
0207 idx = 0;
0208 }
0209 spin_unlock_irqrestore(&qedi->io_trace_lock, flags);
0210 return 0;
0211 }
0212
0213 static int
0214 qedi_dbg_io_trace_open(struct inode *inode, struct file *file)
0215 {
0216 struct qedi_dbg_ctx *qedi_dbg = inode->i_private;
0217 struct qedi_ctx *qedi = container_of(qedi_dbg, struct qedi_ctx,
0218 dbg_ctx);
0219
0220 return single_open(file, qedi_io_trace_show, qedi);
0221 }
0222
0223 const struct file_operations qedi_dbg_fops[] = {
0224 qedi_dbg_fileops_seq(qedi, gbl_ctx),
0225 qedi_dbg_fileops(qedi, do_not_recover),
0226 qedi_dbg_fileops_seq(qedi, io_trace),
0227 { },
0228 };