qla_dfs.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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_tgt_sess_show(struct seq_file *s, void *unused)
  14. {
  15. scsi_qla_host_t *vha = s->private;
  16. struct qla_hw_data *ha = vha->hw;
  17. unsigned long flags;
  18. struct qla_tgt_sess *sess = NULL;
  19. struct qla_tgt *tgt= vha->vha_tgt.qla_tgt;
  20. seq_printf(s, "%s\n",vha->host_str);
  21. if (tgt) {
  22. seq_printf(s, "Port ID Port Name Handle\n");
  23. spin_lock_irqsave(&ha->tgt.sess_lock, flags);
  24. list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) {
  25. seq_printf(s, "%02x:%02x:%02x %8phC %d\n",
  26. sess->s_id.b.domain,sess->s_id.b.area,
  27. sess->s_id.b.al_pa, sess->port_name,
  28. sess->loop_id);
  29. }
  30. spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
  31. }
  32. return 0;
  33. }
  34. static int
  35. qla2x00_dfs_tgt_sess_open(struct inode *inode, struct file *file)
  36. {
  37. scsi_qla_host_t *vha = inode->i_private;
  38. return single_open(file, qla2x00_dfs_tgt_sess_show, vha);
  39. }
  40. static const struct file_operations dfs_tgt_sess_ops = {
  41. .open = qla2x00_dfs_tgt_sess_open,
  42. .read = seq_read,
  43. .llseek = seq_lseek,
  44. .release = single_release,
  45. };
  46. static int
  47. qla_dfs_fw_resource_cnt_show(struct seq_file *s, void *unused)
  48. {
  49. struct scsi_qla_host *vha = s->private;
  50. struct qla_hw_data *ha = vha->hw;
  51. seq_puts(s, "FW Resource count\n\n");
  52. seq_printf(s, "Original TGT exchg count[%d]\n",
  53. ha->orig_fw_tgt_xcb_count);
  54. seq_printf(s, "current TGT exchg count[%d]\n",
  55. ha->cur_fw_tgt_xcb_count);
  56. seq_printf(s, "original Initiator Exchange count[%d]\n",
  57. ha->orig_fw_xcb_count);
  58. seq_printf(s, "Current Initiator Exchange count[%d]\n",
  59. ha->cur_fw_xcb_count);
  60. seq_printf(s, "Original IOCB count[%d]\n", ha->orig_fw_iocb_count);
  61. seq_printf(s, "Current IOCB count[%d]\n", ha->cur_fw_iocb_count);
  62. seq_printf(s, "MAX VP count[%d]\n", ha->max_npiv_vports);
  63. seq_printf(s, "MAX FCF count[%d]\n", ha->fw_max_fcf_count);
  64. return 0;
  65. }
  66. static int
  67. qla_dfs_fw_resource_cnt_open(struct inode *inode, struct file *file)
  68. {
  69. struct scsi_qla_host *vha = inode->i_private;
  70. return single_open(file, qla_dfs_fw_resource_cnt_show, vha);
  71. }
  72. static const struct file_operations dfs_fw_resource_cnt_ops = {
  73. .open = qla_dfs_fw_resource_cnt_open,
  74. .read = seq_read,
  75. .llseek = seq_lseek,
  76. .release = single_release,
  77. };
  78. static int
  79. qla_dfs_tgt_counters_show(struct seq_file *s, void *unused)
  80. {
  81. struct scsi_qla_host *vha = s->private;
  82. seq_puts(s, "Target Counters\n");
  83. seq_printf(s, "qla_core_sbt_cmd = %lld\n",
  84. vha->tgt_counters.qla_core_sbt_cmd);
  85. seq_printf(s, "qla_core_ret_sta_ctio = %lld\n",
  86. vha->tgt_counters.qla_core_ret_sta_ctio);
  87. seq_printf(s, "qla_core_ret_ctio = %lld\n",
  88. vha->tgt_counters.qla_core_ret_ctio);
  89. seq_printf(s, "core_qla_que_buf = %lld\n",
  90. vha->tgt_counters.core_qla_que_buf);
  91. seq_printf(s, "core_qla_snd_status = %lld\n",
  92. vha->tgt_counters.core_qla_snd_status);
  93. seq_printf(s, "core_qla_free_cmd = %lld\n",
  94. vha->tgt_counters.core_qla_free_cmd);
  95. seq_printf(s, "num alloc iocb failed = %lld\n",
  96. vha->tgt_counters.num_alloc_iocb_failed);
  97. seq_printf(s, "num term exchange sent = %lld\n",
  98. vha->tgt_counters.num_term_xchg_sent);
  99. seq_printf(s, "num Q full sent = %lld\n",
  100. vha->tgt_counters.num_q_full_sent);
  101. return 0;
  102. }
  103. static int
  104. qla_dfs_tgt_counters_open(struct inode *inode, struct file *file)
  105. {
  106. struct scsi_qla_host *vha = inode->i_private;
  107. return single_open(file, qla_dfs_tgt_counters_show, vha);
  108. }
  109. static const struct file_operations dfs_tgt_counters_ops = {
  110. .open = qla_dfs_tgt_counters_open,
  111. .read = seq_read,
  112. .llseek = seq_lseek,
  113. .release = single_release,
  114. };
  115. static int
  116. qla2x00_dfs_fce_show(struct seq_file *s, void *unused)
  117. {
  118. scsi_qla_host_t *vha = s->private;
  119. uint32_t cnt;
  120. uint32_t *fce;
  121. uint64_t fce_start;
  122. struct qla_hw_data *ha = vha->hw;
  123. mutex_lock(&ha->fce_mutex);
  124. seq_puts(s, "FCE Trace Buffer\n");
  125. seq_printf(s, "In Pointer = %llx\n\n", (unsigned long long)ha->fce_wr);
  126. seq_printf(s, "Base = %llx\n\n", (unsigned long long) ha->fce_dma);
  127. seq_puts(s, "FCE Enable Registers\n");
  128. seq_printf(s, "%08x %08x %08x %08x %08x %08x\n",
  129. ha->fce_mb[0], ha->fce_mb[2], ha->fce_mb[3], ha->fce_mb[4],
  130. ha->fce_mb[5], ha->fce_mb[6]);
  131. fce = (uint32_t *) ha->fce;
  132. fce_start = (unsigned long long) ha->fce_dma;
  133. for (cnt = 0; cnt < fce_calc_size(ha->fce_bufs) / 4; cnt++) {
  134. if (cnt % 8 == 0)
  135. seq_printf(s, "\n%llx: ",
  136. (unsigned long long)((cnt * 4) + fce_start));
  137. else
  138. seq_putc(s, ' ');
  139. seq_printf(s, "%08x", *fce++);
  140. }
  141. seq_puts(s, "\nEnd\n");
  142. mutex_unlock(&ha->fce_mutex);
  143. return 0;
  144. }
  145. static int
  146. qla2x00_dfs_fce_open(struct inode *inode, struct file *file)
  147. {
  148. scsi_qla_host_t *vha = inode->i_private;
  149. struct qla_hw_data *ha = vha->hw;
  150. int rval;
  151. if (!ha->flags.fce_enabled)
  152. goto out;
  153. mutex_lock(&ha->fce_mutex);
  154. /* Pause tracing to flush FCE buffers. */
  155. rval = qla2x00_disable_fce_trace(vha, &ha->fce_wr, &ha->fce_rd);
  156. if (rval)
  157. ql_dbg(ql_dbg_user, vha, 0x705c,
  158. "DebugFS: Unable to disable FCE (%d).\n", rval);
  159. ha->flags.fce_enabled = 0;
  160. mutex_unlock(&ha->fce_mutex);
  161. out:
  162. return single_open(file, qla2x00_dfs_fce_show, vha);
  163. }
  164. static int
  165. qla2x00_dfs_fce_release(struct inode *inode, struct file *file)
  166. {
  167. scsi_qla_host_t *vha = inode->i_private;
  168. struct qla_hw_data *ha = vha->hw;
  169. int rval;
  170. if (ha->flags.fce_enabled)
  171. goto out;
  172. mutex_lock(&ha->fce_mutex);
  173. /* Re-enable FCE tracing. */
  174. ha->flags.fce_enabled = 1;
  175. memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
  176. rval = qla2x00_enable_fce_trace(vha, ha->fce_dma, ha->fce_bufs,
  177. ha->fce_mb, &ha->fce_bufs);
  178. if (rval) {
  179. ql_dbg(ql_dbg_user, vha, 0x700d,
  180. "DebugFS: Unable to reinitialize FCE (%d).\n", rval);
  181. ha->flags.fce_enabled = 0;
  182. }
  183. mutex_unlock(&ha->fce_mutex);
  184. out:
  185. return single_release(inode, file);
  186. }
  187. static const struct file_operations dfs_fce_ops = {
  188. .open = qla2x00_dfs_fce_open,
  189. .read = seq_read,
  190. .llseek = seq_lseek,
  191. .release = qla2x00_dfs_fce_release,
  192. };
  193. int
  194. qla2x00_dfs_setup(scsi_qla_host_t *vha)
  195. {
  196. struct qla_hw_data *ha = vha->hw;
  197. if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
  198. !IS_QLA27XX(ha))
  199. goto out;
  200. if (!ha->fce)
  201. goto out;
  202. if (qla2x00_dfs_root)
  203. goto create_dir;
  204. atomic_set(&qla2x00_dfs_root_count, 0);
  205. qla2x00_dfs_root = debugfs_create_dir(QLA2XXX_DRIVER_NAME, NULL);
  206. if (!qla2x00_dfs_root) {
  207. ql_log(ql_log_warn, vha, 0x00f7,
  208. "Unable to create debugfs root directory.\n");
  209. goto out;
  210. }
  211. create_dir:
  212. if (ha->dfs_dir)
  213. goto create_nodes;
  214. mutex_init(&ha->fce_mutex);
  215. ha->dfs_dir = debugfs_create_dir(vha->host_str, qla2x00_dfs_root);
  216. if (!ha->dfs_dir) {
  217. ql_log(ql_log_warn, vha, 0x00f8,
  218. "Unable to create debugfs ha directory.\n");
  219. goto out;
  220. }
  221. atomic_inc(&qla2x00_dfs_root_count);
  222. create_nodes:
  223. ha->dfs_fw_resource_cnt = debugfs_create_file("fw_resource_count",
  224. S_IRUSR, ha->dfs_dir, vha, &dfs_fw_resource_cnt_ops);
  225. if (!ha->dfs_fw_resource_cnt) {
  226. ql_log(ql_log_warn, vha, 0x00fd,
  227. "Unable to create debugFS fw_resource_count node.\n");
  228. goto out;
  229. }
  230. ha->dfs_tgt_counters = debugfs_create_file("tgt_counters", S_IRUSR,
  231. ha->dfs_dir, vha, &dfs_tgt_counters_ops);
  232. if (!ha->dfs_tgt_counters) {
  233. ql_log(ql_log_warn, vha, 0xd301,
  234. "Unable to create debugFS tgt_counters node.\n");
  235. goto out;
  236. }
  237. ha->dfs_fce = debugfs_create_file("fce", S_IRUSR, ha->dfs_dir, vha,
  238. &dfs_fce_ops);
  239. if (!ha->dfs_fce) {
  240. ql_log(ql_log_warn, vha, 0x00f9,
  241. "Unable to create debugfs fce node.\n");
  242. goto out;
  243. }
  244. ha->tgt.dfs_tgt_sess = debugfs_create_file("tgt_sess",
  245. S_IRUSR, ha->dfs_dir, vha, &dfs_tgt_sess_ops);
  246. if (!ha->tgt.dfs_tgt_sess) {
  247. ql_log(ql_log_warn, vha, 0xffff,
  248. "Unable to create debugFS tgt_sess node.\n");
  249. goto out;
  250. }
  251. out:
  252. return 0;
  253. }
  254. int
  255. qla2x00_dfs_remove(scsi_qla_host_t *vha)
  256. {
  257. struct qla_hw_data *ha = vha->hw;
  258. if (ha->tgt.dfs_tgt_sess) {
  259. debugfs_remove(ha->tgt.dfs_tgt_sess);
  260. ha->tgt.dfs_tgt_sess = NULL;
  261. }
  262. if (ha->dfs_fw_resource_cnt) {
  263. debugfs_remove(ha->dfs_fw_resource_cnt);
  264. ha->dfs_fw_resource_cnt = NULL;
  265. }
  266. if (ha->dfs_tgt_counters) {
  267. debugfs_remove(ha->dfs_tgt_counters);
  268. ha->dfs_tgt_counters = NULL;
  269. }
  270. if (ha->dfs_fce) {
  271. debugfs_remove(ha->dfs_fce);
  272. ha->dfs_fce = NULL;
  273. }
  274. if (ha->dfs_dir) {
  275. debugfs_remove(ha->dfs_dir);
  276. ha->dfs_dir = NULL;
  277. atomic_dec(&qla2x00_dfs_root_count);
  278. }
  279. if (atomic_read(&qla2x00_dfs_root_count) == 0 &&
  280. qla2x00_dfs_root) {
  281. debugfs_remove(qla2x00_dfs_root);
  282. qla2x00_dfs_root = NULL;
  283. }
  284. return 0;
  285. }