qla_dfs.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. #include <linux/debugfs.h>
  9. #include <linux/seq_file.h>
  10. static struct dentry *qla2x00_dfs_root;
  11. static atomic_t qla2x00_dfs_root_count;
  12. static int
  13. qla2x00_dfs_fce_show(struct seq_file *s, void *unused)
  14. {
  15. scsi_qla_host_t *vha = s->private;
  16. uint32_t cnt;
  17. uint32_t *fce;
  18. uint64_t fce_start;
  19. struct qla_hw_data *ha = vha->hw;
  20. mutex_lock(&ha->fce_mutex);
  21. seq_puts(s, "FCE Trace Buffer\n");
  22. seq_printf(s, "In Pointer = %llx\n\n", (unsigned long long)ha->fce_wr);
  23. seq_printf(s, "Base = %llx\n\n", (unsigned long long) ha->fce_dma);
  24. seq_puts(s, "FCE Enable Registers\n");
  25. seq_printf(s, "%08x %08x %08x %08x %08x %08x\n",
  26. ha->fce_mb[0], ha->fce_mb[2], ha->fce_mb[3], ha->fce_mb[4],
  27. ha->fce_mb[5], ha->fce_mb[6]);
  28. fce = (uint32_t *) ha->fce;
  29. fce_start = (unsigned long long) ha->fce_dma;
  30. for (cnt = 0; cnt < fce_calc_size(ha->fce_bufs) / 4; cnt++) {
  31. if (cnt % 8 == 0)
  32. seq_printf(s, "\n%llx: ",
  33. (unsigned long long)((cnt * 4) + fce_start));
  34. else
  35. seq_putc(s, ' ');
  36. seq_printf(s, "%08x", *fce++);
  37. }
  38. seq_puts(s, "\nEnd\n");
  39. mutex_unlock(&ha->fce_mutex);
  40. return 0;
  41. }
  42. static int
  43. qla2x00_dfs_fce_open(struct inode *inode, struct file *file)
  44. {
  45. scsi_qla_host_t *vha = inode->i_private;
  46. struct qla_hw_data *ha = vha->hw;
  47. int rval;
  48. if (!ha->flags.fce_enabled)
  49. goto out;
  50. mutex_lock(&ha->fce_mutex);
  51. /* Pause tracing to flush FCE buffers. */
  52. rval = qla2x00_disable_fce_trace(vha, &ha->fce_wr, &ha->fce_rd);
  53. if (rval)
  54. ql_dbg(ql_dbg_user, vha, 0x705c,
  55. "DebugFS: Unable to disable FCE (%d).\n", rval);
  56. ha->flags.fce_enabled = 0;
  57. mutex_unlock(&ha->fce_mutex);
  58. out:
  59. return single_open(file, qla2x00_dfs_fce_show, vha);
  60. }
  61. static int
  62. qla2x00_dfs_fce_release(struct inode *inode, struct file *file)
  63. {
  64. scsi_qla_host_t *vha = inode->i_private;
  65. struct qla_hw_data *ha = vha->hw;
  66. int rval;
  67. if (ha->flags.fce_enabled)
  68. goto out;
  69. mutex_lock(&ha->fce_mutex);
  70. /* Re-enable FCE tracing. */
  71. ha->flags.fce_enabled = 1;
  72. memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
  73. rval = qla2x00_enable_fce_trace(vha, ha->fce_dma, ha->fce_bufs,
  74. ha->fce_mb, &ha->fce_bufs);
  75. if (rval) {
  76. ql_dbg(ql_dbg_user, vha, 0x700d,
  77. "DebugFS: Unable to reinitialize FCE (%d).\n", rval);
  78. ha->flags.fce_enabled = 0;
  79. }
  80. mutex_unlock(&ha->fce_mutex);
  81. out:
  82. return single_release(inode, file);
  83. }
  84. static const struct file_operations dfs_fce_ops = {
  85. .open = qla2x00_dfs_fce_open,
  86. .read = seq_read,
  87. .llseek = seq_lseek,
  88. .release = qla2x00_dfs_fce_release,
  89. };
  90. int
  91. qla2x00_dfs_setup(scsi_qla_host_t *vha)
  92. {
  93. struct qla_hw_data *ha = vha->hw;
  94. if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
  95. !IS_QLA27XX(ha))
  96. goto out;
  97. if (!ha->fce)
  98. goto out;
  99. if (qla2x00_dfs_root)
  100. goto create_dir;
  101. atomic_set(&qla2x00_dfs_root_count, 0);
  102. qla2x00_dfs_root = debugfs_create_dir(QLA2XXX_DRIVER_NAME, NULL);
  103. if (!qla2x00_dfs_root) {
  104. ql_log(ql_log_warn, vha, 0x00f7,
  105. "Unable to create debugfs root directory.\n");
  106. goto out;
  107. }
  108. create_dir:
  109. if (ha->dfs_dir)
  110. goto create_nodes;
  111. mutex_init(&ha->fce_mutex);
  112. ha->dfs_dir = debugfs_create_dir(vha->host_str, qla2x00_dfs_root);
  113. if (!ha->dfs_dir) {
  114. ql_log(ql_log_warn, vha, 0x00f8,
  115. "Unable to create debugfs ha directory.\n");
  116. goto out;
  117. }
  118. atomic_inc(&qla2x00_dfs_root_count);
  119. create_nodes:
  120. ha->dfs_fce = debugfs_create_file("fce", S_IRUSR, ha->dfs_dir, vha,
  121. &dfs_fce_ops);
  122. if (!ha->dfs_fce) {
  123. ql_log(ql_log_warn, vha, 0x00f9,
  124. "Unable to create debugfs fce node.\n");
  125. goto out;
  126. }
  127. out:
  128. return 0;
  129. }
  130. int
  131. qla2x00_dfs_remove(scsi_qla_host_t *vha)
  132. {
  133. struct qla_hw_data *ha = vha->hw;
  134. if (ha->dfs_fce) {
  135. debugfs_remove(ha->dfs_fce);
  136. ha->dfs_fce = NULL;
  137. }
  138. if (ha->dfs_dir) {
  139. debugfs_remove(ha->dfs_dir);
  140. ha->dfs_dir = NULL;
  141. atomic_dec(&qla2x00_dfs_root_count);
  142. }
  143. if (atomic_read(&qla2x00_dfs_root_count) == 0 &&
  144. qla2x00_dfs_root) {
  145. debugfs_remove(qla2x00_dfs_root);
  146. qla2x00_dfs_root = NULL;
  147. }
  148. return 0;
  149. }