qedi_debugfs.c 5.9 KB

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