qla_dfs.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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 fc_port *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_puts(s, "Port ID Port Name Handle\n");
  23. spin_lock_irqsave(&ha->tgt.sess_lock, flags);
  24. list_for_each_entry(sess, &vha->vp_fcports, list)
  25. seq_printf(s, "%02x:%02x:%02x %8phC %d\n",
  26. sess->d_id.b.domain, sess->d_id.b.area,
  27. sess->d_id.b.al_pa, sess->port_name,
  28. sess->loop_id);
  29. spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
  30. }
  31. return 0;
  32. }
  33. static int
  34. qla2x00_dfs_tgt_sess_open(struct inode *inode, struct file *file)
  35. {
  36. scsi_qla_host_t *vha = inode->i_private;
  37. return single_open(file, qla2x00_dfs_tgt_sess_show, vha);
  38. }
  39. static const struct file_operations dfs_tgt_sess_ops = {
  40. .open = qla2x00_dfs_tgt_sess_open,
  41. .read = seq_read,
  42. .llseek = seq_lseek,
  43. .release = single_release,
  44. };
  45. static int
  46. qla2x00_dfs_tgt_port_database_show(struct seq_file *s, void *unused)
  47. {
  48. scsi_qla_host_t *vha = s->private;
  49. struct qla_hw_data *ha = vha->hw;
  50. struct gid_list_info *gid_list;
  51. dma_addr_t gid_list_dma;
  52. fc_port_t fc_port;
  53. char *id_iter;
  54. int rc, i;
  55. uint16_t entries, loop_id;
  56. struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
  57. seq_printf(s, "%s\n", vha->host_str);
  58. if (tgt) {
  59. gid_list = dma_alloc_coherent(&ha->pdev->dev,
  60. qla2x00_gid_list_size(ha),
  61. &gid_list_dma, GFP_KERNEL);
  62. if (!gid_list) {
  63. ql_dbg(ql_dbg_user, vha, 0x7018,
  64. "DMA allocation failed for %u\n",
  65. qla2x00_gid_list_size(ha));
  66. return 0;
  67. }
  68. rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma,
  69. &entries);
  70. if (rc != QLA_SUCCESS)
  71. goto out_free_id_list;
  72. id_iter = (char *)gid_list;
  73. seq_puts(s, "Port Name Port ID Loop ID\n");
  74. for (i = 0; i < entries; i++) {
  75. struct gid_list_info *gid =
  76. (struct gid_list_info *)id_iter;
  77. loop_id = le16_to_cpu(gid->loop_id);
  78. memset(&fc_port, 0, sizeof(fc_port_t));
  79. fc_port.loop_id = loop_id;
  80. rc = qla24xx_gpdb_wait(vha, &fc_port, 0);
  81. seq_printf(s, "%8phC %02x%02x%02x %d\n",
  82. fc_port.port_name, fc_port.d_id.b.domain,
  83. fc_port.d_id.b.area, fc_port.d_id.b.al_pa,
  84. fc_port.loop_id);
  85. id_iter += ha->gid_list_info_size;
  86. }
  87. out_free_id_list:
  88. dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
  89. gid_list, gid_list_dma);
  90. }
  91. return 0;
  92. }
  93. static int
  94. qla2x00_dfs_tgt_port_database_open(struct inode *inode, struct file *file)
  95. {
  96. scsi_qla_host_t *vha = inode->i_private;
  97. return single_open(file, qla2x00_dfs_tgt_port_database_show, vha);
  98. }
  99. static const struct file_operations dfs_tgt_port_database_ops = {
  100. .open = qla2x00_dfs_tgt_port_database_open,
  101. .read = seq_read,
  102. .llseek = seq_lseek,
  103. .release = single_release,
  104. };
  105. static int
  106. qla_dfs_fw_resource_cnt_show(struct seq_file *s, void *unused)
  107. {
  108. struct scsi_qla_host *vha = s->private;
  109. struct qla_hw_data *ha = vha->hw;
  110. seq_puts(s, "FW Resource count\n\n");
  111. seq_printf(s, "Original TGT exchg count[%d]\n",
  112. ha->orig_fw_tgt_xcb_count);
  113. seq_printf(s, "current TGT exchg count[%d]\n",
  114. ha->cur_fw_tgt_xcb_count);
  115. seq_printf(s, "original Initiator Exchange count[%d]\n",
  116. ha->orig_fw_xcb_count);
  117. seq_printf(s, "Current Initiator Exchange count[%d]\n",
  118. ha->cur_fw_xcb_count);
  119. seq_printf(s, "Original IOCB count[%d]\n", ha->orig_fw_iocb_count);
  120. seq_printf(s, "Current IOCB count[%d]\n", ha->cur_fw_iocb_count);
  121. seq_printf(s, "MAX VP count[%d]\n", ha->max_npiv_vports);
  122. seq_printf(s, "MAX FCF count[%d]\n", ha->fw_max_fcf_count);
  123. return 0;
  124. }
  125. static int
  126. qla_dfs_fw_resource_cnt_open(struct inode *inode, struct file *file)
  127. {
  128. struct scsi_qla_host *vha = inode->i_private;
  129. return single_open(file, qla_dfs_fw_resource_cnt_show, vha);
  130. }
  131. static const struct file_operations dfs_fw_resource_cnt_ops = {
  132. .open = qla_dfs_fw_resource_cnt_open,
  133. .read = seq_read,
  134. .llseek = seq_lseek,
  135. .release = single_release,
  136. };
  137. static int
  138. qla_dfs_tgt_counters_show(struct seq_file *s, void *unused)
  139. {
  140. struct scsi_qla_host *vha = s->private;
  141. struct qla_qpair *qpair = vha->hw->base_qpair;
  142. uint64_t qla_core_sbt_cmd, core_qla_que_buf, qla_core_ret_ctio,
  143. core_qla_snd_status, qla_core_ret_sta_ctio, core_qla_free_cmd,
  144. num_q_full_sent, num_alloc_iocb_failed, num_term_xchg_sent;
  145. u16 i;
  146. qla_core_sbt_cmd = qpair->tgt_counters.qla_core_sbt_cmd;
  147. core_qla_que_buf = qpair->tgt_counters.core_qla_que_buf;
  148. qla_core_ret_ctio = qpair->tgt_counters.qla_core_ret_ctio;
  149. core_qla_snd_status = qpair->tgt_counters.core_qla_snd_status;
  150. qla_core_ret_sta_ctio = qpair->tgt_counters.qla_core_ret_sta_ctio;
  151. core_qla_free_cmd = qpair->tgt_counters.core_qla_free_cmd;
  152. num_q_full_sent = qpair->tgt_counters.num_q_full_sent;
  153. num_alloc_iocb_failed = qpair->tgt_counters.num_alloc_iocb_failed;
  154. num_term_xchg_sent = qpair->tgt_counters.num_term_xchg_sent;
  155. for (i = 0; i < vha->hw->max_qpairs; i++) {
  156. qpair = vha->hw->queue_pair_map[i];
  157. qla_core_sbt_cmd += qpair->tgt_counters.qla_core_sbt_cmd;
  158. core_qla_que_buf += qpair->tgt_counters.core_qla_que_buf;
  159. qla_core_ret_ctio += qpair->tgt_counters.qla_core_ret_ctio;
  160. core_qla_snd_status += qpair->tgt_counters.core_qla_snd_status;
  161. qla_core_ret_sta_ctio +=
  162. qpair->tgt_counters.qla_core_ret_sta_ctio;
  163. core_qla_free_cmd += qpair->tgt_counters.core_qla_free_cmd;
  164. num_q_full_sent += qpair->tgt_counters.num_q_full_sent;
  165. num_alloc_iocb_failed +=
  166. qpair->tgt_counters.num_alloc_iocb_failed;
  167. num_term_xchg_sent += qpair->tgt_counters.num_term_xchg_sent;
  168. }
  169. seq_puts(s, "Target Counters\n");
  170. seq_printf(s, "qla_core_sbt_cmd = %lld\n",
  171. qla_core_sbt_cmd);
  172. seq_printf(s, "qla_core_ret_sta_ctio = %lld\n",
  173. qla_core_ret_sta_ctio);
  174. seq_printf(s, "qla_core_ret_ctio = %lld\n",
  175. qla_core_ret_ctio);
  176. seq_printf(s, "core_qla_que_buf = %lld\n",
  177. core_qla_que_buf);
  178. seq_printf(s, "core_qla_snd_status = %lld\n",
  179. core_qla_snd_status);
  180. seq_printf(s, "core_qla_free_cmd = %lld\n",
  181. core_qla_free_cmd);
  182. seq_printf(s, "num alloc iocb failed = %lld\n",
  183. num_alloc_iocb_failed);
  184. seq_printf(s, "num term exchange sent = %lld\n",
  185. num_term_xchg_sent);
  186. seq_printf(s, "num Q full sent = %lld\n",
  187. num_q_full_sent);
  188. /* DIF stats */
  189. seq_printf(s, "DIF Inp Bytes = %lld\n",
  190. vha->qla_stats.qla_dif_stats.dif_input_bytes);
  191. seq_printf(s, "DIF Outp Bytes = %lld\n",
  192. vha->qla_stats.qla_dif_stats.dif_output_bytes);
  193. seq_printf(s, "DIF Inp Req = %lld\n",
  194. vha->qla_stats.qla_dif_stats.dif_input_requests);
  195. seq_printf(s, "DIF Outp Req = %lld\n",
  196. vha->qla_stats.qla_dif_stats.dif_output_requests);
  197. seq_printf(s, "DIF Guard err = %d\n",
  198. vha->qla_stats.qla_dif_stats.dif_guard_err);
  199. seq_printf(s, "DIF Ref tag err = %d\n",
  200. vha->qla_stats.qla_dif_stats.dif_ref_tag_err);
  201. seq_printf(s, "DIF App tag err = %d\n",
  202. vha->qla_stats.qla_dif_stats.dif_app_tag_err);
  203. return 0;
  204. }
  205. static int
  206. qla_dfs_tgt_counters_open(struct inode *inode, struct file *file)
  207. {
  208. struct scsi_qla_host *vha = inode->i_private;
  209. return single_open(file, qla_dfs_tgt_counters_show, vha);
  210. }
  211. static const struct file_operations dfs_tgt_counters_ops = {
  212. .open = qla_dfs_tgt_counters_open,
  213. .read = seq_read,
  214. .llseek = seq_lseek,
  215. .release = single_release,
  216. };
  217. static int
  218. qla2x00_dfs_fce_show(struct seq_file *s, void *unused)
  219. {
  220. scsi_qla_host_t *vha = s->private;
  221. uint32_t cnt;
  222. uint32_t *fce;
  223. uint64_t fce_start;
  224. struct qla_hw_data *ha = vha->hw;
  225. mutex_lock(&ha->fce_mutex);
  226. seq_puts(s, "FCE Trace Buffer\n");
  227. seq_printf(s, "In Pointer = %llx\n\n", (unsigned long long)ha->fce_wr);
  228. seq_printf(s, "Base = %llx\n\n", (unsigned long long) ha->fce_dma);
  229. seq_puts(s, "FCE Enable Registers\n");
  230. seq_printf(s, "%08x %08x %08x %08x %08x %08x\n",
  231. ha->fce_mb[0], ha->fce_mb[2], ha->fce_mb[3], ha->fce_mb[4],
  232. ha->fce_mb[5], ha->fce_mb[6]);
  233. fce = (uint32_t *) ha->fce;
  234. fce_start = (unsigned long long) ha->fce_dma;
  235. for (cnt = 0; cnt < fce_calc_size(ha->fce_bufs) / 4; cnt++) {
  236. if (cnt % 8 == 0)
  237. seq_printf(s, "\n%llx: ",
  238. (unsigned long long)((cnt * 4) + fce_start));
  239. else
  240. seq_putc(s, ' ');
  241. seq_printf(s, "%08x", *fce++);
  242. }
  243. seq_puts(s, "\nEnd\n");
  244. mutex_unlock(&ha->fce_mutex);
  245. return 0;
  246. }
  247. static int
  248. qla2x00_dfs_fce_open(struct inode *inode, struct file *file)
  249. {
  250. scsi_qla_host_t *vha = inode->i_private;
  251. struct qla_hw_data *ha = vha->hw;
  252. int rval;
  253. if (!ha->flags.fce_enabled)
  254. goto out;
  255. mutex_lock(&ha->fce_mutex);
  256. /* Pause tracing to flush FCE buffers. */
  257. rval = qla2x00_disable_fce_trace(vha, &ha->fce_wr, &ha->fce_rd);
  258. if (rval)
  259. ql_dbg(ql_dbg_user, vha, 0x705c,
  260. "DebugFS: Unable to disable FCE (%d).\n", rval);
  261. ha->flags.fce_enabled = 0;
  262. mutex_unlock(&ha->fce_mutex);
  263. out:
  264. return single_open(file, qla2x00_dfs_fce_show, vha);
  265. }
  266. static int
  267. qla2x00_dfs_fce_release(struct inode *inode, struct file *file)
  268. {
  269. scsi_qla_host_t *vha = inode->i_private;
  270. struct qla_hw_data *ha = vha->hw;
  271. int rval;
  272. if (ha->flags.fce_enabled)
  273. goto out;
  274. mutex_lock(&ha->fce_mutex);
  275. /* Re-enable FCE tracing. */
  276. ha->flags.fce_enabled = 1;
  277. memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
  278. rval = qla2x00_enable_fce_trace(vha, ha->fce_dma, ha->fce_bufs,
  279. ha->fce_mb, &ha->fce_bufs);
  280. if (rval) {
  281. ql_dbg(ql_dbg_user, vha, 0x700d,
  282. "DebugFS: Unable to reinitialize FCE (%d).\n", rval);
  283. ha->flags.fce_enabled = 0;
  284. }
  285. mutex_unlock(&ha->fce_mutex);
  286. out:
  287. return single_release(inode, file);
  288. }
  289. static const struct file_operations dfs_fce_ops = {
  290. .open = qla2x00_dfs_fce_open,
  291. .read = seq_read,
  292. .llseek = seq_lseek,
  293. .release = qla2x00_dfs_fce_release,
  294. };
  295. static int
  296. qla_dfs_naqp_show(struct seq_file *s, void *unused)
  297. {
  298. struct scsi_qla_host *vha = s->private;
  299. struct qla_hw_data *ha = vha->hw;
  300. seq_printf(s, "%d\n", ha->tgt.num_act_qpairs);
  301. return 0;
  302. }
  303. static int
  304. qla_dfs_naqp_open(struct inode *inode, struct file *file)
  305. {
  306. struct scsi_qla_host *vha = inode->i_private;
  307. return single_open(file, qla_dfs_naqp_show, vha);
  308. }
  309. static ssize_t
  310. qla_dfs_naqp_write(struct file *file, const char __user *buffer,
  311. size_t count, loff_t *pos)
  312. {
  313. struct seq_file *s = file->private_data;
  314. struct scsi_qla_host *vha = s->private;
  315. struct qla_hw_data *ha = vha->hw;
  316. char *buf;
  317. int rc = 0;
  318. unsigned long num_act_qp;
  319. if (!(IS_QLA27XX(ha) || IS_QLA83XX(ha))) {
  320. pr_err("host%ld: this adapter does not support Multi Q.",
  321. vha->host_no);
  322. return -EINVAL;
  323. }
  324. if (!vha->flags.qpairs_available) {
  325. pr_err("host%ld: Driver is not setup with Multi Q.",
  326. vha->host_no);
  327. return -EINVAL;
  328. }
  329. buf = memdup_user_nul(buffer, count);
  330. if (IS_ERR(buf)) {
  331. pr_err("host%ld: fail to copy user buffer.",
  332. vha->host_no);
  333. return PTR_ERR(buf);
  334. }
  335. num_act_qp = simple_strtoul(buf, NULL, 0);
  336. if (num_act_qp >= vha->hw->max_qpairs) {
  337. pr_err("User set invalid number of qpairs %lu. Max = %d",
  338. num_act_qp, vha->hw->max_qpairs);
  339. rc = -EINVAL;
  340. goto out_free;
  341. }
  342. if (num_act_qp != ha->tgt.num_act_qpairs) {
  343. ha->tgt.num_act_qpairs = num_act_qp;
  344. qlt_clr_qp_table(vha);
  345. }
  346. rc = count;
  347. out_free:
  348. kfree(buf);
  349. return rc;
  350. }
  351. static const struct file_operations dfs_naqp_ops = {
  352. .open = qla_dfs_naqp_open,
  353. .read = seq_read,
  354. .llseek = seq_lseek,
  355. .release = single_release,
  356. .write = qla_dfs_naqp_write,
  357. };
  358. int
  359. qla2x00_dfs_setup(scsi_qla_host_t *vha)
  360. {
  361. struct qla_hw_data *ha = vha->hw;
  362. if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
  363. !IS_QLA27XX(ha))
  364. goto out;
  365. if (!ha->fce)
  366. goto out;
  367. if (qla2x00_dfs_root)
  368. goto create_dir;
  369. atomic_set(&qla2x00_dfs_root_count, 0);
  370. qla2x00_dfs_root = debugfs_create_dir(QLA2XXX_DRIVER_NAME, NULL);
  371. if (!qla2x00_dfs_root) {
  372. ql_log(ql_log_warn, vha, 0x00f7,
  373. "Unable to create debugfs root directory.\n");
  374. goto out;
  375. }
  376. create_dir:
  377. if (ha->dfs_dir)
  378. goto create_nodes;
  379. mutex_init(&ha->fce_mutex);
  380. ha->dfs_dir = debugfs_create_dir(vha->host_str, qla2x00_dfs_root);
  381. if (!ha->dfs_dir) {
  382. ql_log(ql_log_warn, vha, 0x00f8,
  383. "Unable to create debugfs ha directory.\n");
  384. goto out;
  385. }
  386. atomic_inc(&qla2x00_dfs_root_count);
  387. create_nodes:
  388. ha->dfs_fw_resource_cnt = debugfs_create_file("fw_resource_count",
  389. S_IRUSR, ha->dfs_dir, vha, &dfs_fw_resource_cnt_ops);
  390. if (!ha->dfs_fw_resource_cnt) {
  391. ql_log(ql_log_warn, vha, 0x00fd,
  392. "Unable to create debugFS fw_resource_count node.\n");
  393. goto out;
  394. }
  395. ha->dfs_tgt_counters = debugfs_create_file("tgt_counters", S_IRUSR,
  396. ha->dfs_dir, vha, &dfs_tgt_counters_ops);
  397. if (!ha->dfs_tgt_counters) {
  398. ql_log(ql_log_warn, vha, 0xd301,
  399. "Unable to create debugFS tgt_counters node.\n");
  400. goto out;
  401. }
  402. ha->tgt.dfs_tgt_port_database = debugfs_create_file("tgt_port_database",
  403. S_IRUSR, ha->dfs_dir, vha, &dfs_tgt_port_database_ops);
  404. if (!ha->tgt.dfs_tgt_port_database) {
  405. ql_log(ql_log_warn, vha, 0xd03f,
  406. "Unable to create debugFS tgt_port_database node.\n");
  407. goto out;
  408. }
  409. ha->dfs_fce = debugfs_create_file("fce", S_IRUSR, ha->dfs_dir, vha,
  410. &dfs_fce_ops);
  411. if (!ha->dfs_fce) {
  412. ql_log(ql_log_warn, vha, 0x00f9,
  413. "Unable to create debugfs fce node.\n");
  414. goto out;
  415. }
  416. ha->tgt.dfs_tgt_sess = debugfs_create_file("tgt_sess",
  417. S_IRUSR, ha->dfs_dir, vha, &dfs_tgt_sess_ops);
  418. if (!ha->tgt.dfs_tgt_sess) {
  419. ql_log(ql_log_warn, vha, 0xd040,
  420. "Unable to create debugFS tgt_sess node.\n");
  421. goto out;
  422. }
  423. if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
  424. ha->tgt.dfs_naqp = debugfs_create_file("naqp",
  425. 0400, ha->dfs_dir, vha, &dfs_naqp_ops);
  426. if (!ha->tgt.dfs_naqp) {
  427. ql_log(ql_log_warn, vha, 0xd011,
  428. "Unable to create debugFS naqp node.\n");
  429. goto out;
  430. }
  431. }
  432. out:
  433. return 0;
  434. }
  435. int
  436. qla2x00_dfs_remove(scsi_qla_host_t *vha)
  437. {
  438. struct qla_hw_data *ha = vha->hw;
  439. if (ha->tgt.dfs_naqp) {
  440. debugfs_remove(ha->tgt.dfs_naqp);
  441. ha->tgt.dfs_naqp = NULL;
  442. }
  443. if (ha->tgt.dfs_tgt_sess) {
  444. debugfs_remove(ha->tgt.dfs_tgt_sess);
  445. ha->tgt.dfs_tgt_sess = NULL;
  446. }
  447. if (ha->tgt.dfs_tgt_port_database) {
  448. debugfs_remove(ha->tgt.dfs_tgt_port_database);
  449. ha->tgt.dfs_tgt_port_database = NULL;
  450. }
  451. if (ha->dfs_fw_resource_cnt) {
  452. debugfs_remove(ha->dfs_fw_resource_cnt);
  453. ha->dfs_fw_resource_cnt = NULL;
  454. }
  455. if (ha->dfs_tgt_counters) {
  456. debugfs_remove(ha->dfs_tgt_counters);
  457. ha->dfs_tgt_counters = NULL;
  458. }
  459. if (ha->dfs_fce) {
  460. debugfs_remove(ha->dfs_fce);
  461. ha->dfs_fce = NULL;
  462. }
  463. if (ha->dfs_dir) {
  464. debugfs_remove(ha->dfs_dir);
  465. ha->dfs_dir = NULL;
  466. atomic_dec(&qla2x00_dfs_root_count);
  467. }
  468. if (atomic_read(&qla2x00_dfs_root_count) == 0 &&
  469. qla2x00_dfs_root) {
  470. debugfs_remove(qla2x00_dfs_root);
  471. qla2x00_dfs_root = NULL;
  472. }
  473. return 0;
  474. }