snic_debugfs.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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. (u64) atomic64_read(&stats->abts.num),
  232. (u64) atomic64_read(&stats->abts.fail),
  233. (u64) atomic64_read(&stats->abts.drv_tmo),
  234. (u64) atomic64_read(&stats->abts.fw_tmo),
  235. (u64) atomic64_read(&stats->abts.io_not_found));
  236. /* Dump Reset Stats */
  237. seq_printf(sfp,
  238. "\n-------------------------------------------\n"
  239. "\t\t Reset Statistics\n"
  240. "---------------------------------------------\n");
  241. seq_printf(sfp,
  242. "HBA Resets : %lld\n"
  243. "HBA Reset Cmpls : %lld\n"
  244. "HBA Reset Fail : %lld\n",
  245. (u64) atomic64_read(&stats->reset.hba_resets),
  246. (u64) atomic64_read(&stats->reset.hba_reset_cmpl),
  247. (u64) atomic64_read(&stats->reset.hba_reset_fail));
  248. /* Dump Firmware Stats */
  249. seq_printf(sfp,
  250. "\n-------------------------------------------\n"
  251. "\t\t Firmware Statistics\n"
  252. "---------------------------------------------\n");
  253. seq_printf(sfp,
  254. "Active FW Requests : %lld\n"
  255. "Max FW Requests : %lld\n"
  256. "FW Out Of Resource Errs : %lld\n"
  257. "FW IO Errors : %lld\n"
  258. "FW SCSI Errors : %lld\n",
  259. (u64) atomic64_read(&stats->fw.actv_reqs),
  260. (u64) atomic64_read(&stats->fw.max_actv_reqs),
  261. (u64) atomic64_read(&stats->fw.out_of_res),
  262. (u64) atomic64_read(&stats->fw.io_errs),
  263. (u64) atomic64_read(&stats->fw.scsi_errs));
  264. /* Dump Miscellenous Stats */
  265. seq_printf(sfp,
  266. "\n---------------------------------------------\n"
  267. "\t\t Other Statistics\n"
  268. "\n---------------------------------------------\n");
  269. jiffies_to_timespec(stats->misc.last_isr_time, &last_isr_tms);
  270. jiffies_to_timespec(stats->misc.last_ack_time, &last_ack_tms);
  271. seq_printf(sfp,
  272. "Last ISR Time : %llu (%8lu.%8lu)\n"
  273. "Last Ack Time : %llu (%8lu.%8lu)\n"
  274. "ISRs : %llu\n"
  275. "Max CQ Entries : %lld\n"
  276. "Data Count Mismatch : %lld\n"
  277. "IOs w/ Timeout Status : %lld\n"
  278. "IOs w/ Aborted Status : %lld\n"
  279. "IOs w/ SGL Invalid Stat : %lld\n"
  280. "WQ Desc Alloc Fail : %lld\n"
  281. "Queue Full : %lld\n"
  282. "Target Not Ready : %lld\n",
  283. (u64) stats->misc.last_isr_time,
  284. last_isr_tms.tv_sec, last_isr_tms.tv_nsec,
  285. (u64)stats->misc.last_ack_time,
  286. last_ack_tms.tv_sec, last_ack_tms.tv_nsec,
  287. (u64) atomic64_read(&stats->misc.isr_cnt),
  288. (u64) atomic64_read(&stats->misc.max_cq_ents),
  289. (u64) atomic64_read(&stats->misc.data_cnt_mismat),
  290. (u64) atomic64_read(&stats->misc.io_tmo),
  291. (u64) atomic64_read(&stats->misc.io_aborted),
  292. (u64) atomic64_read(&stats->misc.sgl_inval),
  293. (u64) atomic64_read(&stats->misc.wq_alloc_fail),
  294. (u64) atomic64_read(&stats->misc.qfull),
  295. (u64) atomic64_read(&stats->misc.tgt_not_rdy));
  296. return 0;
  297. }
  298. /*
  299. * snic_stats_open - Open the stats file for specific host
  300. *
  301. * Description:
  302. * This routine opens a debugfs file stats of specific host
  303. */
  304. static int
  305. snic_stats_open(struct inode *inode, struct file *filp)
  306. {
  307. return single_open(filp, snic_stats_show, inode->i_private);
  308. }
  309. static const struct file_operations snic_stats_fops = {
  310. .owner = THIS_MODULE,
  311. .open = snic_stats_open,
  312. .read = seq_read,
  313. .llseek = seq_lseek,
  314. .release = single_release,
  315. };
  316. static const struct file_operations snic_reset_stats_fops = {
  317. .owner = THIS_MODULE,
  318. .open = snic_reset_stats_open,
  319. .read = snic_reset_stats_read,
  320. .write = snic_reset_stats_write,
  321. .release = snic_reset_stats_release,
  322. };
  323. /*
  324. * snic_stats_init - Initialize stats struct and create stats file
  325. * per snic
  326. *
  327. * Description:
  328. * When debugfs is cofigured this routine sets up the stats file per snic
  329. * It will create file stats and reset_stats under statistics/host# directory
  330. * to log per snic stats
  331. */
  332. int
  333. snic_stats_debugfs_init(struct snic *snic)
  334. {
  335. int rc = -1;
  336. char name[16];
  337. struct dentry *de = NULL;
  338. snprintf(name, sizeof(name), "host%d", snic->shost->host_no);
  339. if (!snic_glob->stats_root) {
  340. SNIC_DBG("snic_stats root doesn't exist\n");
  341. return rc;
  342. }
  343. de = debugfs_create_dir(name, snic_glob->stats_root);
  344. if (!de) {
  345. SNIC_DBG("Cannot create host directory\n");
  346. return rc;
  347. }
  348. snic->stats_host = de;
  349. de = debugfs_create_file("stats",
  350. S_IFREG|S_IRUGO,
  351. snic->stats_host,
  352. snic,
  353. &snic_stats_fops);
  354. if (!de) {
  355. SNIC_DBG("Cannot create host's stats file\n");
  356. return rc;
  357. }
  358. snic->stats_file = de;
  359. de = debugfs_create_file("reset_stats",
  360. S_IFREG|S_IRUGO|S_IWUSR,
  361. snic->stats_host,
  362. snic,
  363. &snic_reset_stats_fops);
  364. if (!de) {
  365. SNIC_DBG("Cannot create host's reset_stats file\n");
  366. return rc;
  367. }
  368. snic->reset_stats_file = de;
  369. rc = 0;
  370. return rc;
  371. } /* end of snic_stats_debugfs_init */
  372. /*
  373. * snic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
  374. *
  375. * Description:
  376. * When Debufs is configured this routine removes debugfs file system
  377. * elements that are specific to to snic stats
  378. */
  379. void
  380. snic_stats_debugfs_remove(struct snic *snic)
  381. {
  382. debugfs_remove(snic->stats_file);
  383. snic->stats_file = NULL;
  384. debugfs_remove(snic->reset_stats_file);
  385. snic->reset_stats_file = NULL;
  386. debugfs_remove(snic->stats_host);
  387. snic->stats_host = NULL;
  388. }
  389. /* Trace Facility related API */
  390. static void *
  391. snic_trc_seq_start(struct seq_file *sfp, loff_t *pos)
  392. {
  393. return &snic_glob->trc;
  394. }
  395. static void *
  396. snic_trc_seq_next(struct seq_file *sfp, void *data, loff_t *pos)
  397. {
  398. return NULL;
  399. }
  400. static void
  401. snic_trc_seq_stop(struct seq_file *sfp, void *data)
  402. {
  403. }
  404. #define SNIC_TRC_PBLEN 256
  405. static int
  406. snic_trc_seq_show(struct seq_file *sfp, void *data)
  407. {
  408. char buf[SNIC_TRC_PBLEN];
  409. if (snic_get_trc_data(buf, SNIC_TRC_PBLEN) > 0)
  410. seq_printf(sfp, "%s\n", buf);
  411. return 0;
  412. }
  413. static const struct seq_operations snic_trc_seq_ops = {
  414. .start = snic_trc_seq_start,
  415. .next = snic_trc_seq_next,
  416. .stop = snic_trc_seq_stop,
  417. .show = snic_trc_seq_show,
  418. };
  419. static int
  420. snic_trc_open(struct inode *inode, struct file *filp)
  421. {
  422. return seq_open(filp, &snic_trc_seq_ops);
  423. }
  424. static const struct file_operations snic_trc_fops = {
  425. .owner = THIS_MODULE,
  426. .open = snic_trc_open,
  427. .read = seq_read,
  428. .llseek = seq_lseek,
  429. .release = seq_release,
  430. };
  431. /*
  432. * snic_trc_debugfs_init : creates trace/tracing_enable files for trace
  433. * under debugfs
  434. */
  435. int
  436. snic_trc_debugfs_init(void)
  437. {
  438. struct dentry *de = NULL;
  439. int ret = -1;
  440. if (!snic_glob->trc_root) {
  441. SNIC_ERR("Debugfs root directory for snic doesn't exist.\n");
  442. return ret;
  443. }
  444. de = debugfs_create_bool("tracing_enable",
  445. S_IFREG | S_IRUGO | S_IWUSR,
  446. snic_glob->trc_root,
  447. &snic_glob->trc.enable);
  448. if (!de) {
  449. SNIC_ERR("Can't create trace_enable file.\n");
  450. return ret;
  451. }
  452. snic_glob->trc.trc_enable = de;
  453. de = debugfs_create_file("trace",
  454. S_IFREG | S_IRUGO | S_IWUSR,
  455. snic_glob->trc_root,
  456. NULL,
  457. &snic_trc_fops);
  458. if (!de) {
  459. SNIC_ERR("Cann't create trace file.\n");
  460. return ret;
  461. }
  462. snic_glob->trc.trc_file = de;
  463. ret = 0;
  464. return ret;
  465. } /* end of snic_trc_debugfs_init */
  466. /*
  467. * snic_trc_debugfs_term : cleans up the files created for trace under debugfs
  468. */
  469. void
  470. snic_trc_debugfs_term(void)
  471. {
  472. debugfs_remove(snic_glob->trc.trc_file);
  473. snic_glob->trc.trc_file = NULL;
  474. debugfs_remove(snic_glob->trc.trc_enable);
  475. snic_glob->trc.trc_enable = NULL;
  476. }