fnic_trace.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /*
  2. * Copyright 2012 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/mempool.h>
  19. #include <linux/errno.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/kallsyms.h>
  22. #include "fnic_io.h"
  23. #include "fnic.h"
  24. unsigned int trace_max_pages;
  25. static int fnic_max_trace_entries;
  26. static unsigned long fnic_trace_buf_p;
  27. static DEFINE_SPINLOCK(fnic_trace_lock);
  28. static fnic_trace_dbg_t fnic_trace_entries;
  29. int fnic_tracing_enabled = 1;
  30. /*
  31. * fnic_trace_get_buf - Give buffer pointer to user to fill up trace information
  32. *
  33. * Description:
  34. * This routine gets next available trace buffer entry location @wr_idx
  35. * from allocated trace buffer pages and give that memory location
  36. * to user to store the trace information.
  37. *
  38. * Return Value:
  39. * This routine returns pointer to next available trace entry
  40. * @fnic_buf_head for user to fill trace information.
  41. */
  42. fnic_trace_data_t *fnic_trace_get_buf(void)
  43. {
  44. unsigned long fnic_buf_head;
  45. unsigned long flags;
  46. spin_lock_irqsave(&fnic_trace_lock, flags);
  47. /*
  48. * Get next available memory location for writing trace information
  49. * at @wr_idx and increment @wr_idx
  50. */
  51. fnic_buf_head =
  52. fnic_trace_entries.page_offset[fnic_trace_entries.wr_idx];
  53. fnic_trace_entries.wr_idx++;
  54. /*
  55. * Verify if trace buffer is full then change wd_idx to
  56. * start from zero
  57. */
  58. if (fnic_trace_entries.wr_idx >= fnic_max_trace_entries)
  59. fnic_trace_entries.wr_idx = 0;
  60. /*
  61. * Verify if write index @wr_idx and read index @rd_idx are same then
  62. * increment @rd_idx to move to next entry in trace buffer
  63. */
  64. if (fnic_trace_entries.wr_idx == fnic_trace_entries.rd_idx) {
  65. fnic_trace_entries.rd_idx++;
  66. if (fnic_trace_entries.rd_idx >= fnic_max_trace_entries)
  67. fnic_trace_entries.rd_idx = 0;
  68. }
  69. spin_unlock_irqrestore(&fnic_trace_lock, flags);
  70. return (fnic_trace_data_t *)fnic_buf_head;
  71. }
  72. /*
  73. * fnic_get_trace_data - Copy trace buffer to a memory file
  74. * @fnic_dbgfs_t: pointer to debugfs trace buffer
  75. *
  76. * Description:
  77. * This routine gathers the fnic trace debugfs data from the fnic_trace_data_t
  78. * buffer and dumps it to fnic_dbgfs_t. It will start at the rd_idx entry in
  79. * the log and process the log until the end of the buffer. Then it will gather
  80. * from the beginning of the log and process until the current entry @wr_idx.
  81. *
  82. * Return Value:
  83. * This routine returns the amount of bytes that were dumped into fnic_dbgfs_t
  84. */
  85. int fnic_get_trace_data(fnic_dbgfs_t *fnic_dbgfs_prt)
  86. {
  87. int rd_idx;
  88. int wr_idx;
  89. int len = 0;
  90. unsigned long flags;
  91. char str[KSYM_SYMBOL_LEN];
  92. struct timespec val;
  93. fnic_trace_data_t *tbp;
  94. spin_lock_irqsave(&fnic_trace_lock, flags);
  95. rd_idx = fnic_trace_entries.rd_idx;
  96. wr_idx = fnic_trace_entries.wr_idx;
  97. if (wr_idx < rd_idx) {
  98. while (1) {
  99. /* Start from read index @rd_idx */
  100. tbp = (fnic_trace_data_t *)
  101. fnic_trace_entries.page_offset[rd_idx];
  102. if (!tbp) {
  103. spin_unlock_irqrestore(&fnic_trace_lock, flags);
  104. return 0;
  105. }
  106. /* Convert function pointer to function name */
  107. if (sizeof(unsigned long) < 8) {
  108. sprint_symbol(str, tbp->fnaddr.low);
  109. jiffies_to_timespec(tbp->timestamp.low, &val);
  110. } else {
  111. sprint_symbol(str, tbp->fnaddr.val);
  112. jiffies_to_timespec(tbp->timestamp.val, &val);
  113. }
  114. /*
  115. * Dump trace buffer entry to memory file
  116. * and increment read index @rd_idx
  117. */
  118. len += snprintf(fnic_dbgfs_prt->buffer + len,
  119. (trace_max_pages * PAGE_SIZE * 3) - len,
  120. "%16lu.%16lu %-50s %8x %8x %16llx %16llx "
  121. "%16llx %16llx %16llx\n", val.tv_sec,
  122. val.tv_nsec, str, tbp->host_no, tbp->tag,
  123. tbp->data[0], tbp->data[1], tbp->data[2],
  124. tbp->data[3], tbp->data[4]);
  125. rd_idx++;
  126. /*
  127. * If rd_idx is reached to maximum trace entries
  128. * then move rd_idx to zero
  129. */
  130. if (rd_idx > (fnic_max_trace_entries-1))
  131. rd_idx = 0;
  132. /*
  133. * Continure dumpping trace buffer entries into
  134. * memory file till rd_idx reaches write index
  135. */
  136. if (rd_idx == wr_idx)
  137. break;
  138. }
  139. } else if (wr_idx > rd_idx) {
  140. while (1) {
  141. /* Start from read index @rd_idx */
  142. tbp = (fnic_trace_data_t *)
  143. fnic_trace_entries.page_offset[rd_idx];
  144. if (!tbp) {
  145. spin_unlock_irqrestore(&fnic_trace_lock, flags);
  146. return 0;
  147. }
  148. /* Convert function pointer to function name */
  149. if (sizeof(unsigned long) < 8) {
  150. sprint_symbol(str, tbp->fnaddr.low);
  151. jiffies_to_timespec(tbp->timestamp.low, &val);
  152. } else {
  153. sprint_symbol(str, tbp->fnaddr.val);
  154. jiffies_to_timespec(tbp->timestamp.val, &val);
  155. }
  156. /*
  157. * Dump trace buffer entry to memory file
  158. * and increment read index @rd_idx
  159. */
  160. len += snprintf(fnic_dbgfs_prt->buffer + len,
  161. (trace_max_pages * PAGE_SIZE * 3) - len,
  162. "%16lu.%16lu %-50s %8x %8x %16llx %16llx "
  163. "%16llx %16llx %16llx\n", val.tv_sec,
  164. val.tv_nsec, str, tbp->host_no, tbp->tag,
  165. tbp->data[0], tbp->data[1], tbp->data[2],
  166. tbp->data[3], tbp->data[4]);
  167. rd_idx++;
  168. /*
  169. * Continue dumpping trace buffer entries into
  170. * memory file till rd_idx reaches write index
  171. */
  172. if (rd_idx == wr_idx)
  173. break;
  174. }
  175. }
  176. spin_unlock_irqrestore(&fnic_trace_lock, flags);
  177. return len;
  178. }
  179. /*
  180. * fnic_get_stats_data - Copy fnic stats buffer to a memory file
  181. * @fnic_dbgfs_t: pointer to debugfs fnic stats buffer
  182. *
  183. * Description:
  184. * This routine gathers the fnic stats debugfs data from the fnic_stats struct
  185. * and dumps it to stats_debug_info.
  186. *
  187. * Return Value:
  188. * This routine returns the amount of bytes that were dumped into
  189. * stats_debug_info
  190. */
  191. int fnic_get_stats_data(struct stats_debug_info *debug,
  192. struct fnic_stats *stats)
  193. {
  194. int len = 0;
  195. int buf_size = debug->buf_size;
  196. struct timespec val1, val2;
  197. len = snprintf(debug->debug_buffer + len, buf_size - len,
  198. "------------------------------------------\n"
  199. "\t\tIO Statistics\n"
  200. "------------------------------------------\n");
  201. len += snprintf(debug->debug_buffer + len, buf_size - len,
  202. "Number of Active IOs: %lld\nMaximum Active IOs: %lld\n"
  203. "Number of IOs: %lld\nNumber of IO Completions: %lld\n"
  204. "Number of IO Failures: %lld\nNumber of IO NOT Found: %lld\n"
  205. "Number of Memory alloc Failures: %lld\n"
  206. "Number of IOREQ Null: %lld\n"
  207. "Number of SCSI cmd pointer Null: %lld\n",
  208. (u64)atomic64_read(&stats->io_stats.active_ios),
  209. (u64)atomic64_read(&stats->io_stats.max_active_ios),
  210. (u64)atomic64_read(&stats->io_stats.num_ios),
  211. (u64)atomic64_read(&stats->io_stats.io_completions),
  212. (u64)atomic64_read(&stats->io_stats.io_failures),
  213. (u64)atomic64_read(&stats->io_stats.io_not_found),
  214. (u64)atomic64_read(&stats->io_stats.alloc_failures),
  215. (u64)atomic64_read(&stats->io_stats.ioreq_null),
  216. (u64)atomic64_read(&stats->io_stats.sc_null));
  217. len += snprintf(debug->debug_buffer + len, buf_size - len,
  218. "\n------------------------------------------\n"
  219. "\t\tAbort Statistics\n"
  220. "------------------------------------------\n");
  221. len += snprintf(debug->debug_buffer + len, buf_size - len,
  222. "Number of Aborts: %lld\n"
  223. "Number of Abort Failures: %lld\n"
  224. "Number of Abort Driver Timeouts: %lld\n"
  225. "Number of Abort FW Timeouts: %lld\n"
  226. "Number of Abort IO NOT Found: %lld\n",
  227. (u64)atomic64_read(&stats->abts_stats.aborts),
  228. (u64)atomic64_read(&stats->abts_stats.abort_failures),
  229. (u64)atomic64_read(&stats->abts_stats.abort_drv_timeouts),
  230. (u64)atomic64_read(&stats->abts_stats.abort_fw_timeouts),
  231. (u64)atomic64_read(&stats->abts_stats.abort_io_not_found));
  232. len += snprintf(debug->debug_buffer + len, buf_size - len,
  233. "\n------------------------------------------\n"
  234. "\t\tTerminate Statistics\n"
  235. "------------------------------------------\n");
  236. len += snprintf(debug->debug_buffer + len, buf_size - len,
  237. "Number of Terminates: %lld\n"
  238. "Maximum Terminates: %lld\n"
  239. "Number of Terminate Driver Timeouts: %lld\n"
  240. "Number of Terminate FW Timeouts: %lld\n"
  241. "Number of Terminate IO NOT Found: %lld\n"
  242. "Number of Terminate Failures: %lld\n",
  243. (u64)atomic64_read(&stats->term_stats.terminates),
  244. (u64)atomic64_read(&stats->term_stats.max_terminates),
  245. (u64)atomic64_read(&stats->term_stats.terminate_drv_timeouts),
  246. (u64)atomic64_read(&stats->term_stats.terminate_fw_timeouts),
  247. (u64)atomic64_read(&stats->term_stats.terminate_io_not_found),
  248. (u64)atomic64_read(&stats->term_stats.terminate_failures));
  249. len += snprintf(debug->debug_buffer + len, buf_size - len,
  250. "\n------------------------------------------\n"
  251. "\t\tReset Statistics\n"
  252. "------------------------------------------\n");
  253. len += snprintf(debug->debug_buffer + len, buf_size - len,
  254. "Number of Device Resets: %lld\n"
  255. "Number of Device Reset Failures: %lld\n"
  256. "Number of Device Reset Aborts: %lld\n"
  257. "Number of Device Reset Timeouts: %lld\n"
  258. "Number of Device Reset Terminates: %lld\n"
  259. "Number of FW Resets: %lld\n"
  260. "Number of FW Reset Completions: %lld\n"
  261. "Number of FW Reset Failures: %lld\n"
  262. "Number of Fnic Reset: %lld\n"
  263. "Number of Fnic Reset Completions: %lld\n"
  264. "Number of Fnic Reset Failures: %lld\n",
  265. (u64)atomic64_read(&stats->reset_stats.device_resets),
  266. (u64)atomic64_read(&stats->reset_stats.device_reset_failures),
  267. (u64)atomic64_read(&stats->reset_stats.device_reset_aborts),
  268. (u64)atomic64_read(&stats->reset_stats.device_reset_timeouts),
  269. (u64)atomic64_read(
  270. &stats->reset_stats.device_reset_terminates),
  271. (u64)atomic64_read(&stats->reset_stats.fw_resets),
  272. (u64)atomic64_read(&stats->reset_stats.fw_reset_completions),
  273. (u64)atomic64_read(&stats->reset_stats.fw_reset_failures),
  274. (u64)atomic64_read(&stats->reset_stats.fnic_resets),
  275. (u64)atomic64_read(
  276. &stats->reset_stats.fnic_reset_completions),
  277. (u64)atomic64_read(&stats->reset_stats.fnic_reset_failures));
  278. len += snprintf(debug->debug_buffer + len, buf_size - len,
  279. "\n------------------------------------------\n"
  280. "\t\tFirmware Statistics\n"
  281. "------------------------------------------\n");
  282. len += snprintf(debug->debug_buffer + len, buf_size - len,
  283. "Number of Active FW Requests %lld\n"
  284. "Maximum FW Requests: %lld\n"
  285. "Number of FW out of resources: %lld\n"
  286. "Number of FW IO errors: %lld\n",
  287. (u64)atomic64_read(&stats->fw_stats.active_fw_reqs),
  288. (u64)atomic64_read(&stats->fw_stats.max_fw_reqs),
  289. (u64)atomic64_read(&stats->fw_stats.fw_out_of_resources),
  290. (u64)atomic64_read(&stats->fw_stats.io_fw_errs));
  291. len += snprintf(debug->debug_buffer + len, buf_size - len,
  292. "\n------------------------------------------\n"
  293. "\t\tVlan Discovery Statistics\n"
  294. "------------------------------------------\n");
  295. len += snprintf(debug->debug_buffer + len, buf_size - len,
  296. "Number of Vlan Discovery Requests Sent %lld\n"
  297. "Vlan Response Received with no FCF VLAN ID: %lld\n"
  298. "No solicitations recvd after vlan set, expiry count: %lld\n"
  299. "Flogi rejects count: %lld\n",
  300. (u64)atomic64_read(&stats->vlan_stats.vlan_disc_reqs),
  301. (u64)atomic64_read(&stats->vlan_stats.resp_withno_vlanID),
  302. (u64)atomic64_read(&stats->vlan_stats.sol_expiry_count),
  303. (u64)atomic64_read(&stats->vlan_stats.flogi_rejects));
  304. len += snprintf(debug->debug_buffer + len, buf_size - len,
  305. "\n------------------------------------------\n"
  306. "\t\tOther Important Statistics\n"
  307. "------------------------------------------\n");
  308. jiffies_to_timespec(stats->misc_stats.last_isr_time, &val1);
  309. jiffies_to_timespec(stats->misc_stats.last_ack_time, &val2);
  310. len += snprintf(debug->debug_buffer + len, buf_size - len,
  311. "Last ISR time: %llu (%8lu.%8lu)\n"
  312. "Last ACK time: %llu (%8lu.%8lu)\n"
  313. "Number of ISRs: %lld\n"
  314. "Maximum CQ Entries: %lld\n"
  315. "Number of ACK index out of range: %lld\n"
  316. "Number of data count mismatch: %lld\n"
  317. "Number of FCPIO Timeouts: %lld\n"
  318. "Number of FCPIO Aborted: %lld\n"
  319. "Number of SGL Invalid: %lld\n"
  320. "Number of Copy WQ Alloc Failures for ABTs: %lld\n"
  321. "Number of Copy WQ Alloc Failures for Device Reset: %lld\n"
  322. "Number of Copy WQ Alloc Failures for IOs: %lld\n"
  323. "Number of no icmnd itmf Completions: %lld\n"
  324. "Number of QUEUE Fulls: %lld\n"
  325. "Number of rport not ready: %lld\n"
  326. "Number of receive frame errors: %lld\n",
  327. (u64)stats->misc_stats.last_isr_time,
  328. val1.tv_sec, val1.tv_nsec,
  329. (u64)stats->misc_stats.last_ack_time,
  330. val2.tv_sec, val2.tv_nsec,
  331. (u64)atomic64_read(&stats->misc_stats.isr_count),
  332. (u64)atomic64_read(&stats->misc_stats.max_cq_entries),
  333. (u64)atomic64_read(&stats->misc_stats.ack_index_out_of_range),
  334. (u64)atomic64_read(&stats->misc_stats.data_count_mismatch),
  335. (u64)atomic64_read(&stats->misc_stats.fcpio_timeout),
  336. (u64)atomic64_read(&stats->misc_stats.fcpio_aborted),
  337. (u64)atomic64_read(&stats->misc_stats.sgl_invalid),
  338. (u64)atomic64_read(
  339. &stats->misc_stats.abts_cpwq_alloc_failures),
  340. (u64)atomic64_read(
  341. &stats->misc_stats.devrst_cpwq_alloc_failures),
  342. (u64)atomic64_read(&stats->misc_stats.io_cpwq_alloc_failures),
  343. (u64)atomic64_read(&stats->misc_stats.no_icmnd_itmf_cmpls),
  344. (u64)atomic64_read(&stats->misc_stats.queue_fulls),
  345. (u64)atomic64_read(&stats->misc_stats.rport_not_ready),
  346. (u64)atomic64_read(&stats->misc_stats.frame_errors));
  347. return len;
  348. }
  349. /*
  350. * fnic_trace_buf_init - Initialize fnic trace buffer logging facility
  351. *
  352. * Description:
  353. * Initialize trace buffer data structure by allocating required memory and
  354. * setting page_offset information for every trace entry by adding trace entry
  355. * length to previous page_offset value.
  356. */
  357. int fnic_trace_buf_init(void)
  358. {
  359. unsigned long fnic_buf_head;
  360. int i;
  361. int err = 0;
  362. trace_max_pages = fnic_trace_max_pages;
  363. fnic_max_trace_entries = (trace_max_pages * PAGE_SIZE)/
  364. FNIC_ENTRY_SIZE_BYTES;
  365. fnic_trace_buf_p = (unsigned long)vmalloc((trace_max_pages * PAGE_SIZE));
  366. if (!fnic_trace_buf_p) {
  367. printk(KERN_ERR PFX "Failed to allocate memory "
  368. "for fnic_trace_buf_p\n");
  369. err = -ENOMEM;
  370. goto err_fnic_trace_buf_init;
  371. }
  372. memset((void *)fnic_trace_buf_p, 0, (trace_max_pages * PAGE_SIZE));
  373. fnic_trace_entries.page_offset = vmalloc(fnic_max_trace_entries *
  374. sizeof(unsigned long));
  375. if (!fnic_trace_entries.page_offset) {
  376. printk(KERN_ERR PFX "Failed to allocate memory for"
  377. " page_offset\n");
  378. if (fnic_trace_buf_p) {
  379. vfree((void *)fnic_trace_buf_p);
  380. fnic_trace_buf_p = 0;
  381. }
  382. err = -ENOMEM;
  383. goto err_fnic_trace_buf_init;
  384. }
  385. memset((void *)fnic_trace_entries.page_offset, 0,
  386. (fnic_max_trace_entries * sizeof(unsigned long)));
  387. fnic_trace_entries.wr_idx = fnic_trace_entries.rd_idx = 0;
  388. fnic_buf_head = fnic_trace_buf_p;
  389. /*
  390. * Set page_offset field of fnic_trace_entries struct by
  391. * calculating memory location for every trace entry using
  392. * length of each trace entry
  393. */
  394. for (i = 0; i < fnic_max_trace_entries; i++) {
  395. fnic_trace_entries.page_offset[i] = fnic_buf_head;
  396. fnic_buf_head += FNIC_ENTRY_SIZE_BYTES;
  397. }
  398. err = fnic_trace_debugfs_init();
  399. if (err < 0) {
  400. printk(KERN_ERR PFX "Failed to initialize debugfs for tracing\n");
  401. goto err_fnic_trace_debugfs_init;
  402. }
  403. printk(KERN_INFO PFX "Successfully Initialized Trace Buffer\n");
  404. return err;
  405. err_fnic_trace_debugfs_init:
  406. fnic_trace_free();
  407. err_fnic_trace_buf_init:
  408. return err;
  409. }
  410. /*
  411. * fnic_trace_free - Free memory of fnic trace data structures.
  412. */
  413. void fnic_trace_free(void)
  414. {
  415. fnic_tracing_enabled = 0;
  416. fnic_trace_debugfs_terminate();
  417. if (fnic_trace_entries.page_offset) {
  418. vfree((void *)fnic_trace_entries.page_offset);
  419. fnic_trace_entries.page_offset = NULL;
  420. }
  421. if (fnic_trace_buf_p) {
  422. vfree((void *)fnic_trace_buf_p);
  423. fnic_trace_buf_p = 0;
  424. }
  425. printk(KERN_INFO PFX "Successfully Freed Trace Buffer\n");
  426. }