qedi_debugfs.c 5.5 KB

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