snic_debugfs.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. * Copyright 2014 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/errno.h>
  19. #include <linux/debugfs.h>
  20. #include "snic.h"
  21. /*
  22. * snic_debugfs_init - Initialize debugfs for snic debug logging
  23. *
  24. * Description:
  25. * When Debugfs is configured this routine sets up fnic debugfs
  26. * filesystem. If not already created. this routine will crate the
  27. * fnic directory and statistics directory for trace buffer and
  28. * stats logging
  29. */
  30. int
  31. snic_debugfs_init(void)
  32. {
  33. int rc = -1;
  34. struct dentry *de = NULL;
  35. de = debugfs_create_dir("snic", NULL);
  36. if (!de) {
  37. SNIC_DBG("Cannot create debugfs root\n");
  38. return rc;
  39. }
  40. snic_glob->trc_root = de;
  41. de = debugfs_create_dir("statistics", snic_glob->trc_root);
  42. if (!de) {
  43. SNIC_DBG("Cannot create Statistics directory\n");
  44. return rc;
  45. }
  46. snic_glob->stats_root = de;
  47. rc = 0;
  48. return rc;
  49. } /* end of snic_debugfs_init */
  50. /*
  51. * snic_debugfs_term - Tear down debugfs intrastructure
  52. *
  53. * Description:
  54. * When Debufs is configured this routine removes debugfs file system
  55. * elements that are specific to snic
  56. */
  57. void
  58. snic_debugfs_term(void)
  59. {
  60. debugfs_remove(snic_glob->stats_root);
  61. snic_glob->stats_root = NULL;
  62. debugfs_remove(snic_glob->trc_root);
  63. snic_glob->trc_root = NULL;
  64. }
  65. /*
  66. * snic_reset_stats_open - Open the reset_stats file
  67. */
  68. static int
  69. snic_reset_stats_open(struct inode *inode, struct file *filp)
  70. {
  71. SNIC_BUG_ON(!inode->i_private);
  72. filp->private_data = inode->i_private;
  73. return 0;
  74. }
  75. /*
  76. * snic_reset_stats_read - Read a reset_stats debugfs file
  77. * @filp: The file pointer to read from.
  78. * @ubuf: The buffer tocopy the data to.
  79. * @cnt: The number of bytes to read.
  80. * @ppos: The position in the file to start reading frm.
  81. *
  82. * Description:
  83. * This routine reads value of variable reset_stats
  84. * and stores into local @buf. It will start reading file @ppos and
  85. * copy up to @cnt of data to @ubuf from @buf.
  86. *
  87. * Returns:
  88. * This function returns the amount of data that was read.
  89. */
  90. static ssize_t
  91. snic_reset_stats_read(struct file *filp,
  92. char __user *ubuf,
  93. size_t cnt,
  94. loff_t *ppos)
  95. {
  96. struct snic *snic = (struct snic *) filp->private_data;
  97. char buf[64];
  98. int len;
  99. len = sprintf(buf, "%u\n", snic->reset_stats);
  100. return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
  101. }
  102. /*
  103. * snic_reset_stats_write - Write to reset_stats debugfs file
  104. * @filp: The file pointer to write from
  105. * @ubuf: The buffer to copy the data from.
  106. * @cnt: The number of bytes to write.
  107. * @ppos: The position in the file to start writing to.
  108. *
  109. * Description:
  110. * This routine writes data from user buffer @ubuf to buffer @buf and
  111. * resets cumulative stats of snic.
  112. *
  113. * Returns:
  114. * This function returns the amount of data that was written.
  115. */
  116. static ssize_t
  117. snic_reset_stats_write(struct file *filp,
  118. const char __user *ubuf,
  119. size_t cnt,
  120. loff_t *ppos)
  121. {
  122. struct snic *snic = (struct snic *) filp->private_data;
  123. struct snic_stats *stats = &snic->s_stats;
  124. u64 *io_stats_p = (u64 *) &stats->io;
  125. u64 *fw_stats_p = (u64 *) &stats->fw;
  126. char buf[64];
  127. unsigned long val;
  128. int ret;
  129. if (cnt >= sizeof(buf))
  130. return -EINVAL;
  131. if (copy_from_user(&buf, ubuf, cnt))
  132. return -EFAULT;
  133. buf[cnt] = '\0';
  134. ret = kstrtoul(buf, 10, &val);
  135. if (ret < 0)
  136. return ret;
  137. snic->reset_stats = val;
  138. if (snic->reset_stats) {
  139. /* Skip variable is used to avoid descrepancies to Num IOs
  140. * and IO Completions stats. Skip incrementing No IO Compls
  141. * for pending active IOs after reset_stats
  142. */
  143. atomic64_set(&snic->io_cmpl_skip,
  144. atomic64_read(&stats->io.active));
  145. memset(&stats->abts, 0, sizeof(struct snic_abort_stats));
  146. memset(&stats->reset, 0, sizeof(struct snic_reset_stats));
  147. memset(&stats->misc, 0, sizeof(struct snic_misc_stats));
  148. memset(io_stats_p+1,
  149. 0,
  150. sizeof(struct snic_io_stats) - sizeof(u64));
  151. memset(fw_stats_p+1,
  152. 0,
  153. sizeof(struct snic_fw_stats) - sizeof(u64));
  154. }
  155. (*ppos)++;
  156. SNIC_HOST_INFO(snic->shost, "Reset Op: Driver statistics.\n");
  157. return cnt;
  158. }
  159. static int
  160. snic_reset_stats_release(struct inode *inode, struct file *filp)
  161. {
  162. filp->private_data = NULL;
  163. return 0;
  164. }
  165. /*
  166. * snic_stats_show - Formats and prints per host specific driver stats.
  167. */
  168. static int
  169. snic_stats_show(struct seq_file *sfp, void *data)
  170. {
  171. struct snic *snic = (struct snic *) sfp->private;
  172. struct snic_stats *stats = &snic->s_stats;
  173. struct timespec last_isr_tms, last_ack_tms;
  174. u64 maxio_tm;
  175. int i;
  176. /* Dump IO Stats */
  177. seq_printf(sfp,
  178. "------------------------------------------\n"
  179. "\t\t IO Statistics\n"
  180. "------------------------------------------\n");
  181. maxio_tm = (u64) atomic64_read(&stats->io.max_time);
  182. seq_printf(sfp,
  183. "Active IOs : %lld\n"
  184. "Max Active IOs : %lld\n"
  185. "Total IOs : %lld\n"
  186. "IOs Completed : %lld\n"
  187. "IOs Failed : %lld\n"
  188. "IOs Not Found : %lld\n"
  189. "Memory Alloc Failures : %lld\n"
  190. "REQs Null : %lld\n"
  191. "SCSI Cmd Pointers Null : %lld\n"
  192. "Max SGL for any IO : %lld\n"
  193. "Max IO Size : %lld Sectors\n"
  194. "Max Queuing Time : %lld\n"
  195. "Max Completion Time : %lld\n"
  196. "Max IO Process Time(FW) : %lld (%u msec)\n",
  197. (u64) atomic64_read(&stats->io.active),
  198. (u64) atomic64_read(&stats->io.max_active),
  199. (u64) atomic64_read(&stats->io.num_ios),
  200. (u64) atomic64_read(&stats->io.compl),
  201. (u64) atomic64_read(&stats->io.fail),
  202. (u64) atomic64_read(&stats->io.io_not_found),
  203. (u64) atomic64_read(&stats->io.alloc_fail),
  204. (u64) atomic64_read(&stats->io.req_null),
  205. (u64) atomic64_read(&stats->io.sc_null),
  206. (u64) atomic64_read(&stats->io.max_sgl),
  207. (u64) atomic64_read(&stats->io.max_io_sz),
  208. (u64) atomic64_read(&stats->io.max_qtime),
  209. (u64) atomic64_read(&stats->io.max_cmpl_time),
  210. maxio_tm,
  211. jiffies_to_msecs(maxio_tm));
  212. seq_puts(sfp, "\nSGL Counters\n");
  213. for (i = 0; i < SNIC_MAX_SG_DESC_CNT; i++) {
  214. seq_printf(sfp,
  215. "%10lld ",
  216. (u64) atomic64_read(&stats->io.sgl_cnt[i]));
  217. if ((i + 1) % 8 == 0)
  218. seq_puts(sfp, "\n");
  219. }
  220. /* Dump Abort Stats */
  221. seq_printf(sfp,
  222. "\n-------------------------------------------\n"
  223. "\t\t Abort Statistics\n"
  224. "---------------------------------------------\n");
  225. seq_printf(sfp,
  226. "Aborts : %lld\n"
  227. "Aborts Fail : %lld\n"
  228. "Aborts Driver Timeout : %lld\n"
  229. "Abort FW Timeout : %lld\n"
  230. "Abort IO NOT Found : %lld\n"
  231. "Abort Queuing Failed : %lld\n",
  232. (u64) atomic64_read(&stats->abts.num),
  233. (u64) atomic64_read(&stats->abts.fail),
  234. (u64) atomic64_read(&stats->abts.drv_tmo),
  235. (u64) atomic64_read(&stats->abts.fw_tmo),
  236. (u64) atomic64_read(&stats->abts.io_not_found),
  237. (u64) atomic64_read(&stats->abts.q_fail));
  238. /* Dump Reset Stats */
  239. seq_printf(sfp,
  240. "\n-------------------------------------------\n"
  241. "\t\t Reset Statistics\n"
  242. "---------------------------------------------\n");
  243. seq_printf(sfp,
  244. "HBA Resets : %lld\n"
  245. "HBA Reset Cmpls : %lld\n"
  246. "HBA Reset Fail : %lld\n",
  247. (u64) atomic64_read(&stats->reset.hba_resets),
  248. (u64) atomic64_read(&stats->reset.hba_reset_cmpl),
  249. (u64) atomic64_read(&stats->reset.hba_reset_fail));
  250. /* Dump Firmware Stats */
  251. seq_printf(sfp,
  252. "\n-------------------------------------------\n"
  253. "\t\t Firmware Statistics\n"
  254. "---------------------------------------------\n");
  255. seq_printf(sfp,
  256. "Active FW Requests : %lld\n"
  257. "Max FW Requests : %lld\n"
  258. "FW Out Of Resource Errs : %lld\n"
  259. "FW IO Errors : %lld\n"
  260. "FW SCSI Errors : %lld\n",
  261. (u64) atomic64_read(&stats->fw.actv_reqs),
  262. (u64) atomic64_read(&stats->fw.max_actv_reqs),
  263. (u64) atomic64_read(&stats->fw.out_of_res),
  264. (u64) atomic64_read(&stats->fw.io_errs),
  265. (u64) atomic64_read(&stats->fw.scsi_errs));
  266. /* Dump Miscellenous Stats */
  267. seq_printf(sfp,
  268. "\n---------------------------------------------\n"
  269. "\t\t Other Statistics\n"
  270. "\n---------------------------------------------\n");
  271. jiffies_to_timespec(stats->misc.last_isr_time, &last_isr_tms);
  272. jiffies_to_timespec(stats->misc.last_ack_time, &last_ack_tms);
  273. seq_printf(sfp,
  274. "Last ISR Time : %llu (%8lu.%8lu)\n"
  275. "Last Ack Time : %llu (%8lu.%8lu)\n"
  276. "Ack ISRs : %llu\n"
  277. "IO Cmpl ISRs : %llu\n"
  278. "Err Notify ISRs : %llu\n"
  279. "Max CQ Entries : %lld\n"
  280. "Data Count Mismatch : %lld\n"
  281. "IOs w/ Timeout Status : %lld\n"
  282. "IOs w/ Aborted Status : %lld\n"
  283. "IOs w/ SGL Invalid Stat : %lld\n"
  284. "WQ Desc Alloc Fail : %lld\n"
  285. "Queue Full : %lld\n"
  286. "Queue Ramp Up : %lld\n"
  287. "Queue Ramp Down : %lld\n"
  288. "Queue Last Queue Depth : %lld\n"
  289. "Target Not Ready : %lld\n",
  290. (u64) stats->misc.last_isr_time,
  291. last_isr_tms.tv_sec, last_isr_tms.tv_nsec,
  292. (u64)stats->misc.last_ack_time,
  293. last_ack_tms.tv_sec, last_ack_tms.tv_nsec,
  294. (u64) atomic64_read(&stats->misc.ack_isr_cnt),
  295. (u64) atomic64_read(&stats->misc.cmpl_isr_cnt),
  296. (u64) atomic64_read(&stats->misc.errnotify_isr_cnt),
  297. (u64) atomic64_read(&stats->misc.max_cq_ents),
  298. (u64) atomic64_read(&stats->misc.data_cnt_mismat),
  299. (u64) atomic64_read(&stats->misc.io_tmo),
  300. (u64) atomic64_read(&stats->misc.io_aborted),
  301. (u64) atomic64_read(&stats->misc.sgl_inval),
  302. (u64) atomic64_read(&stats->misc.wq_alloc_fail),
  303. (u64) atomic64_read(&stats->misc.qfull),
  304. (u64) atomic64_read(&stats->misc.qsz_rampup),
  305. (u64) atomic64_read(&stats->misc.qsz_rampdown),
  306. (u64) atomic64_read(&stats->misc.last_qsz),
  307. (u64) atomic64_read(&stats->misc.tgt_not_rdy));
  308. return 0;
  309. }
  310. /*
  311. * snic_stats_open - Open the stats file for specific host
  312. *
  313. * Description:
  314. * This routine opens a debugfs file stats of specific host
  315. */
  316. static int
  317. snic_stats_open(struct inode *inode, struct file *filp)
  318. {
  319. return single_open(filp, snic_stats_show, inode->i_private);
  320. }
  321. static const struct file_operations snic_stats_fops = {
  322. .owner = THIS_MODULE,
  323. .open = snic_stats_open,
  324. .read = seq_read,
  325. .llseek = seq_lseek,
  326. .release = single_release,
  327. };
  328. static const struct file_operations snic_reset_stats_fops = {
  329. .owner = THIS_MODULE,
  330. .open = snic_reset_stats_open,
  331. .read = snic_reset_stats_read,
  332. .write = snic_reset_stats_write,
  333. .release = snic_reset_stats_release,
  334. };
  335. /*
  336. * snic_stats_init - Initialize stats struct and create stats file
  337. * per snic
  338. *
  339. * Description:
  340. * When debugfs is cofigured this routine sets up the stats file per snic
  341. * It will create file stats and reset_stats under statistics/host# directory
  342. * to log per snic stats
  343. */
  344. int
  345. snic_stats_debugfs_init(struct snic *snic)
  346. {
  347. int rc = -1;
  348. char name[16];
  349. struct dentry *de = NULL;
  350. snprintf(name, sizeof(name), "host%d", snic->shost->host_no);
  351. if (!snic_glob->stats_root) {
  352. SNIC_DBG("snic_stats root doesn't exist\n");
  353. return rc;
  354. }
  355. de = debugfs_create_dir(name, snic_glob->stats_root);
  356. if (!de) {
  357. SNIC_DBG("Cannot create host directory\n");
  358. return rc;
  359. }
  360. snic->stats_host = de;
  361. de = debugfs_create_file("stats",
  362. S_IFREG|S_IRUGO,
  363. snic->stats_host,
  364. snic,
  365. &snic_stats_fops);
  366. if (!de) {
  367. SNIC_DBG("Cannot create host's stats file\n");
  368. return rc;
  369. }
  370. snic->stats_file = de;
  371. de = debugfs_create_file("reset_stats",
  372. S_IFREG|S_IRUGO|S_IWUSR,
  373. snic->stats_host,
  374. snic,
  375. &snic_reset_stats_fops);
  376. if (!de) {
  377. SNIC_DBG("Cannot create host's reset_stats file\n");
  378. return rc;
  379. }
  380. snic->reset_stats_file = de;
  381. rc = 0;
  382. return rc;
  383. } /* end of snic_stats_debugfs_init */
  384. /*
  385. * snic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
  386. *
  387. * Description:
  388. * When Debufs is configured this routine removes debugfs file system
  389. * elements that are specific to to snic stats
  390. */
  391. void
  392. snic_stats_debugfs_remove(struct snic *snic)
  393. {
  394. debugfs_remove(snic->stats_file);
  395. snic->stats_file = NULL;
  396. debugfs_remove(snic->reset_stats_file);
  397. snic->reset_stats_file = NULL;
  398. debugfs_remove(snic->stats_host);
  399. snic->stats_host = NULL;
  400. }
  401. /* Trace Facility related API */
  402. static void *
  403. snic_trc_seq_start(struct seq_file *sfp, loff_t *pos)
  404. {
  405. return &snic_glob->trc;
  406. }
  407. static void *
  408. snic_trc_seq_next(struct seq_file *sfp, void *data, loff_t *pos)
  409. {
  410. return NULL;
  411. }
  412. static void
  413. snic_trc_seq_stop(struct seq_file *sfp, void *data)
  414. {
  415. }
  416. #define SNIC_TRC_PBLEN 256
  417. static int
  418. snic_trc_seq_show(struct seq_file *sfp, void *data)
  419. {
  420. char buf[SNIC_TRC_PBLEN];
  421. if (snic_get_trc_data(buf, SNIC_TRC_PBLEN) > 0)
  422. seq_printf(sfp, "%s\n", buf);
  423. return 0;
  424. }
  425. static const struct seq_operations snic_trc_seq_ops = {
  426. .start = snic_trc_seq_start,
  427. .next = snic_trc_seq_next,
  428. .stop = snic_trc_seq_stop,
  429. .show = snic_trc_seq_show,
  430. };
  431. static int
  432. snic_trc_open(struct inode *inode, struct file *filp)
  433. {
  434. return seq_open(filp, &snic_trc_seq_ops);
  435. }
  436. static const struct file_operations snic_trc_fops = {
  437. .owner = THIS_MODULE,
  438. .open = snic_trc_open,
  439. .read = seq_read,
  440. .llseek = seq_lseek,
  441. .release = seq_release,
  442. };
  443. /*
  444. * snic_trc_debugfs_init : creates trace/tracing_enable files for trace
  445. * under debugfs
  446. */
  447. int
  448. snic_trc_debugfs_init(void)
  449. {
  450. struct dentry *de = NULL;
  451. int ret = -1;
  452. if (!snic_glob->trc_root) {
  453. SNIC_ERR("Debugfs root directory for snic doesn't exist.\n");
  454. return ret;
  455. }
  456. de = debugfs_create_bool("tracing_enable",
  457. S_IFREG | S_IRUGO | S_IWUSR,
  458. snic_glob->trc_root,
  459. &snic_glob->trc.enable);
  460. if (!de) {
  461. SNIC_ERR("Can't create trace_enable file.\n");
  462. return ret;
  463. }
  464. snic_glob->trc.trc_enable = de;
  465. de = debugfs_create_file("trace",
  466. S_IFREG | S_IRUGO | S_IWUSR,
  467. snic_glob->trc_root,
  468. NULL,
  469. &snic_trc_fops);
  470. if (!de) {
  471. SNIC_ERR("Cann't create trace file.\n");
  472. return ret;
  473. }
  474. snic_glob->trc.trc_file = de;
  475. ret = 0;
  476. return ret;
  477. } /* end of snic_trc_debugfs_init */
  478. /*
  479. * snic_trc_debugfs_term : cleans up the files created for trace under debugfs
  480. */
  481. void
  482. snic_trc_debugfs_term(void)
  483. {
  484. debugfs_remove(snic_glob->trc.trc_file);
  485. snic_glob->trc.trc_file = NULL;
  486. debugfs_remove(snic_glob->trc.trc_enable);
  487. snic_glob->trc.trc_enable = NULL;
  488. }