lpfc_debugfs.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2007-2008 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * *
  8. * This program is free software; you can redistribute it and/or *
  9. * modify it under the terms of version 2 of the GNU General *
  10. * Public License as published by the Free Software Foundation. *
  11. * This program is distributed in the hope that it will be useful. *
  12. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  13. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  14. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  15. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  16. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  17. * more details, a copy of which can be found in the file COPYING *
  18. * included with this package. *
  19. *******************************************************************/
  20. #include <linux/blkdev.h>
  21. #include <linux/delay.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/idr.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/kthread.h>
  26. #include <linux/pci.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/ctype.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/scsi_device.h>
  31. #include <scsi/scsi_host.h>
  32. #include <scsi/scsi_transport_fc.h>
  33. #include "lpfc_hw.h"
  34. #include "lpfc_sli.h"
  35. #include "lpfc_disc.h"
  36. #include "lpfc_scsi.h"
  37. #include "lpfc.h"
  38. #include "lpfc_logmsg.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_vport.h"
  41. #include "lpfc_version.h"
  42. #include "lpfc_compat.h"
  43. #include "lpfc_debugfs.h"
  44. #ifdef CONFIG_LPFC_DEBUG_FS
  45. /**
  46. * debugfs interface
  47. *
  48. * To access this interface the user should:
  49. * # mkdir /debug
  50. * # mount -t debugfs none /debug
  51. *
  52. * The lpfc debugfs directory hierarchy is:
  53. * lpfc/lpfcX/vportY
  54. * where X is the lpfc hba unique_id
  55. * where Y is the vport VPI on that hba
  56. *
  57. * Debugging services available per vport:
  58. * discovery_trace
  59. * This is an ACSII readable file that contains a trace of the last
  60. * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
  61. * See lpfc_debugfs.h for different categories of discovery events.
  62. * To enable the discovery trace, the following module parameters must be set:
  63. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  64. * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
  65. * EACH vport. X MUST also be a power of 2.
  66. * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
  67. * lpfc_debugfs.h .
  68. *
  69. * slow_ring_trace
  70. * This is an ACSII readable file that contains a trace of the last
  71. * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
  72. * To enable the slow ring trace, the following module parameters must be set:
  73. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  74. * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
  75. * the HBA. X MUST also be a power of 2.
  76. */
  77. static int lpfc_debugfs_enable = 1;
  78. module_param(lpfc_debugfs_enable, int, 0);
  79. MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
  80. /* This MUST be a power of 2 */
  81. static int lpfc_debugfs_max_disc_trc;
  82. module_param(lpfc_debugfs_max_disc_trc, int, 0);
  83. MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
  84. "Set debugfs discovery trace depth");
  85. /* This MUST be a power of 2 */
  86. static int lpfc_debugfs_max_slow_ring_trc;
  87. module_param(lpfc_debugfs_max_slow_ring_trc, int, 0);
  88. MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
  89. "Set debugfs slow ring trace depth");
  90. int lpfc_debugfs_mask_disc_trc;
  91. module_param(lpfc_debugfs_mask_disc_trc, int, 0);
  92. MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
  93. "Set debugfs discovery trace mask");
  94. #include <linux/debugfs.h>
  95. /* size of output line, for discovery_trace and slow_ring_trace */
  96. #define LPFC_DEBUG_TRC_ENTRY_SIZE 100
  97. /* nodelist output buffer size */
  98. #define LPFC_NODELIST_SIZE 8192
  99. #define LPFC_NODELIST_ENTRY_SIZE 120
  100. /* dumpHBASlim output buffer size */
  101. #define LPFC_DUMPHBASLIM_SIZE 4096
  102. /* dumpHostSlim output buffer size */
  103. #define LPFC_DUMPHOSTSLIM_SIZE 4096
  104. /* hbqinfo output buffer size */
  105. #define LPFC_HBQINFO_SIZE 8192
  106. struct lpfc_debug {
  107. char *buffer;
  108. int len;
  109. };
  110. static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  111. static unsigned long lpfc_debugfs_start_time = 0L;
  112. /**
  113. * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer.
  114. * @vport: The vport to gather the log info from.
  115. * @buf: The buffer to dump log into.
  116. * @size: The maximum amount of data to process.
  117. *
  118. * Description:
  119. * This routine gathers the lpfc discovery debugfs data from the @vport and
  120. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  121. * in the log and process the log until the end of the buffer. Then it will
  122. * gather from the beginning of the log and process until the current entry.
  123. *
  124. * Notes:
  125. * Discovery logging will be disabled while while this routine dumps the log.
  126. *
  127. * Return Value:
  128. * This routine returns the amount of bytes that were dumped into @buf and will
  129. * not exceed @size.
  130. **/
  131. static int
  132. lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
  133. {
  134. int i, index, len, enable;
  135. uint32_t ms;
  136. struct lpfc_debugfs_trc *dtp;
  137. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  138. enable = lpfc_debugfs_enable;
  139. lpfc_debugfs_enable = 0;
  140. len = 0;
  141. index = (atomic_read(&vport->disc_trc_cnt) + 1) &
  142. (lpfc_debugfs_max_disc_trc - 1);
  143. for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
  144. dtp = vport->disc_trc + i;
  145. if (!dtp->fmt)
  146. continue;
  147. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  148. snprintf(buffer,
  149. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  150. dtp->seq_cnt, ms, dtp->fmt);
  151. len += snprintf(buf+len, size-len, buffer,
  152. dtp->data1, dtp->data2, dtp->data3);
  153. }
  154. for (i = 0; i < index; i++) {
  155. dtp = vport->disc_trc + i;
  156. if (!dtp->fmt)
  157. continue;
  158. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  159. snprintf(buffer,
  160. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  161. dtp->seq_cnt, ms, dtp->fmt);
  162. len += snprintf(buf+len, size-len, buffer,
  163. dtp->data1, dtp->data2, dtp->data3);
  164. }
  165. lpfc_debugfs_enable = enable;
  166. return len;
  167. }
  168. /**
  169. * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer.
  170. * @phba: The HBA to gather the log info from.
  171. * @buf: The buffer to dump log into.
  172. * @size: The maximum amount of data to process.
  173. *
  174. * Description:
  175. * This routine gathers the lpfc slow ring debugfs data from the @phba and
  176. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  177. * in the log and process the log until the end of the buffer. Then it will
  178. * gather from the beginning of the log and process until the current entry.
  179. *
  180. * Notes:
  181. * Slow ring logging will be disabled while while this routine dumps the log.
  182. *
  183. * Return Value:
  184. * This routine returns the amount of bytes that were dumped into @buf and will
  185. * not exceed @size.
  186. **/
  187. static int
  188. lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
  189. {
  190. int i, index, len, enable;
  191. uint32_t ms;
  192. struct lpfc_debugfs_trc *dtp;
  193. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  194. enable = lpfc_debugfs_enable;
  195. lpfc_debugfs_enable = 0;
  196. len = 0;
  197. index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
  198. (lpfc_debugfs_max_slow_ring_trc - 1);
  199. for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
  200. dtp = phba->slow_ring_trc + i;
  201. if (!dtp->fmt)
  202. continue;
  203. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  204. snprintf(buffer,
  205. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  206. dtp->seq_cnt, ms, dtp->fmt);
  207. len += snprintf(buf+len, size-len, buffer,
  208. dtp->data1, dtp->data2, dtp->data3);
  209. }
  210. for (i = 0; i < index; i++) {
  211. dtp = phba->slow_ring_trc + i;
  212. if (!dtp->fmt)
  213. continue;
  214. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  215. snprintf(buffer,
  216. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  217. dtp->seq_cnt, ms, dtp->fmt);
  218. len += snprintf(buf+len, size-len, buffer,
  219. dtp->data1, dtp->data2, dtp->data3);
  220. }
  221. lpfc_debugfs_enable = enable;
  222. return len;
  223. }
  224. static int lpfc_debugfs_last_hbq = -1;
  225. /**
  226. * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer.
  227. * @phba: The HBA to gather host buffer info from.
  228. * @buf: The buffer to dump log into.
  229. * @size: The maximum amount of data to process.
  230. *
  231. * Description:
  232. * This routine dumps the host buffer queue info from the @phba to @buf up to
  233. * @size number of bytes. A header that describes the current hbq state will be
  234. * dumped to @buf first and then info on each hbq entry will be dumped to @buf
  235. * until @size bytes have been dumped or all the hbq info has been dumped.
  236. *
  237. * Notes:
  238. * This routine will rotate through each configured HBQ each time called.
  239. *
  240. * Return Value:
  241. * This routine returns the amount of bytes that were dumped into @buf and will
  242. * not exceed @size.
  243. **/
  244. static int
  245. lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
  246. {
  247. int len = 0;
  248. int cnt, i, j, found, posted, low;
  249. uint32_t phys, raw_index, getidx;
  250. struct lpfc_hbq_init *hip;
  251. struct hbq_s *hbqs;
  252. struct lpfc_hbq_entry *hbqe;
  253. struct lpfc_dmabuf *d_buf;
  254. struct hbq_dmabuf *hbq_buf;
  255. cnt = LPFC_HBQINFO_SIZE;
  256. spin_lock_irq(&phba->hbalock);
  257. /* toggle between multiple hbqs, if any */
  258. i = lpfc_sli_hbq_count();
  259. if (i > 1) {
  260. lpfc_debugfs_last_hbq++;
  261. if (lpfc_debugfs_last_hbq >= i)
  262. lpfc_debugfs_last_hbq = 0;
  263. }
  264. else
  265. lpfc_debugfs_last_hbq = 0;
  266. i = lpfc_debugfs_last_hbq;
  267. len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
  268. hbqs = &phba->hbqs[i];
  269. posted = 0;
  270. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
  271. posted++;
  272. hip = lpfc_hbq_defs[i];
  273. len += snprintf(buf+len, size-len,
  274. "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
  275. hip->hbq_index, hip->profile, hip->rn,
  276. hip->buffer_count, hip->init_count, hip->add_count, posted);
  277. raw_index = phba->hbq_get[i];
  278. getidx = le32_to_cpu(raw_index);
  279. len += snprintf(buf+len, size-len,
  280. "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
  281. hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
  282. hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
  283. hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
  284. for (j=0; j<hbqs->entry_count; j++) {
  285. len += snprintf(buf+len, size-len,
  286. "%03d: %08x %04x %05x ", j,
  287. le32_to_cpu(hbqe->bde.addrLow),
  288. le32_to_cpu(hbqe->bde.tus.w),
  289. le32_to_cpu(hbqe->buffer_tag));
  290. i = 0;
  291. found = 0;
  292. /* First calculate if slot has an associated posted buffer */
  293. low = hbqs->hbqPutIdx - posted;
  294. if (low >= 0) {
  295. if ((j >= hbqs->hbqPutIdx) || (j < low)) {
  296. len += snprintf(buf+len, size-len, "Unused\n");
  297. goto skipit;
  298. }
  299. }
  300. else {
  301. if ((j >= hbqs->hbqPutIdx) &&
  302. (j < (hbqs->entry_count+low))) {
  303. len += snprintf(buf+len, size-len, "Unused\n");
  304. goto skipit;
  305. }
  306. }
  307. /* Get the Buffer info for the posted buffer */
  308. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
  309. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  310. phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
  311. if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
  312. len += snprintf(buf+len, size-len,
  313. "Buf%d: %p %06x\n", i,
  314. hbq_buf->dbuf.virt, hbq_buf->tag);
  315. found = 1;
  316. break;
  317. }
  318. i++;
  319. }
  320. if (!found) {
  321. len += snprintf(buf+len, size-len, "No DMAinfo?\n");
  322. }
  323. skipit:
  324. hbqe++;
  325. if (len > LPFC_HBQINFO_SIZE - 54)
  326. break;
  327. }
  328. spin_unlock_irq(&phba->hbalock);
  329. return len;
  330. }
  331. static int lpfc_debugfs_last_hba_slim_off;
  332. /**
  333. * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer.
  334. * @phba: The HBA to gather SLIM info from.
  335. * @buf: The buffer to dump log into.
  336. * @size: The maximum amount of data to process.
  337. *
  338. * Description:
  339. * This routine dumps the current contents of HBA SLIM for the HBA associated
  340. * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
  341. *
  342. * Notes:
  343. * This routine will only dump up to 1024 bytes of data each time called and
  344. * should be called multiple times to dump the entire HBA SLIM.
  345. *
  346. * Return Value:
  347. * This routine returns the amount of bytes that were dumped into @buf and will
  348. * not exceed @size.
  349. **/
  350. static int
  351. lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
  352. {
  353. int len = 0;
  354. int i, off;
  355. uint32_t *ptr;
  356. char buffer[1024];
  357. off = 0;
  358. spin_lock_irq(&phba->hbalock);
  359. len += snprintf(buf+len, size-len, "HBA SLIM\n");
  360. lpfc_memcpy_from_slim(buffer,
  361. ((uint8_t *)phba->MBslimaddr) + lpfc_debugfs_last_hba_slim_off,
  362. 1024);
  363. ptr = (uint32_t *)&buffer[0];
  364. off = lpfc_debugfs_last_hba_slim_off;
  365. /* Set it up for the next time */
  366. lpfc_debugfs_last_hba_slim_off += 1024;
  367. if (lpfc_debugfs_last_hba_slim_off >= 4096)
  368. lpfc_debugfs_last_hba_slim_off = 0;
  369. i = 1024;
  370. while (i > 0) {
  371. len += snprintf(buf+len, size-len,
  372. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  373. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  374. *(ptr+5), *(ptr+6), *(ptr+7));
  375. ptr += 8;
  376. i -= (8 * sizeof(uint32_t));
  377. off += (8 * sizeof(uint32_t));
  378. }
  379. spin_unlock_irq(&phba->hbalock);
  380. return len;
  381. }
  382. /**
  383. * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer.
  384. * @phba: The HBA to gather Host SLIM info from.
  385. * @buf: The buffer to dump log into.
  386. * @size: The maximum amount of data to process.
  387. *
  388. * Description:
  389. * This routine dumps the current contents of host SLIM for the host associated
  390. * with @phba to @buf up to @size bytes of data. The dump will contain the
  391. * Mailbox, PCB, Rings, and Registers that are located in host memory.
  392. *
  393. * Return Value:
  394. * This routine returns the amount of bytes that were dumped into @buf and will
  395. * not exceed @size.
  396. **/
  397. static int
  398. lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
  399. {
  400. int len = 0;
  401. int i, off;
  402. uint32_t word0, word1, word2, word3;
  403. uint32_t *ptr;
  404. struct lpfc_pgp *pgpp;
  405. struct lpfc_sli *psli = &phba->sli;
  406. struct lpfc_sli_ring *pring;
  407. off = 0;
  408. spin_lock_irq(&phba->hbalock);
  409. len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
  410. ptr = (uint32_t *)phba->slim2p;
  411. i = sizeof(MAILBOX_t);
  412. while (i > 0) {
  413. len += snprintf(buf+len, size-len,
  414. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  415. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  416. *(ptr+5), *(ptr+6), *(ptr+7));
  417. ptr += 8;
  418. i -= (8 * sizeof(uint32_t));
  419. off += (8 * sizeof(uint32_t));
  420. }
  421. len += snprintf(buf+len, size-len, "SLIM PCB\n");
  422. ptr = (uint32_t *)&phba->slim2p->pcb;
  423. i = sizeof(PCB_t);
  424. while (i > 0) {
  425. len += snprintf(buf+len, size-len,
  426. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  427. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  428. *(ptr+5), *(ptr+6), *(ptr+7));
  429. ptr += 8;
  430. i -= (8 * sizeof(uint32_t));
  431. off += (8 * sizeof(uint32_t));
  432. }
  433. pgpp = (struct lpfc_pgp *)&phba->slim2p->mbx.us.s3_pgp.port;
  434. pring = &psli->ring[0];
  435. len += snprintf(buf+len, size-len,
  436. "Ring 0: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  437. "RSP PutInx:%d Max:%d\n",
  438. pgpp->cmdGetInx, pring->numCiocb,
  439. pring->next_cmdidx, pring->local_getidx, pring->flag,
  440. pgpp->rspPutInx, pring->numRiocb);
  441. pgpp++;
  442. pring = &psli->ring[1];
  443. len += snprintf(buf+len, size-len,
  444. "Ring 1: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  445. "RSP PutInx:%d Max:%d\n",
  446. pgpp->cmdGetInx, pring->numCiocb,
  447. pring->next_cmdidx, pring->local_getidx, pring->flag,
  448. pgpp->rspPutInx, pring->numRiocb);
  449. pgpp++;
  450. pring = &psli->ring[2];
  451. len += snprintf(buf+len, size-len,
  452. "Ring 2: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  453. "RSP PutInx:%d Max:%d\n",
  454. pgpp->cmdGetInx, pring->numCiocb,
  455. pring->next_cmdidx, pring->local_getidx, pring->flag,
  456. pgpp->rspPutInx, pring->numRiocb);
  457. pgpp++;
  458. pring = &psli->ring[3];
  459. len += snprintf(buf+len, size-len,
  460. "Ring 3: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  461. "RSP PutInx:%d Max:%d\n",
  462. pgpp->cmdGetInx, pring->numCiocb,
  463. pring->next_cmdidx, pring->local_getidx, pring->flag,
  464. pgpp->rspPutInx, pring->numRiocb);
  465. ptr = (uint32_t *)&phba->slim2p->mbx.us.s3_pgp.hbq_get;
  466. word0 = readl(phba->HAregaddr);
  467. word1 = readl(phba->CAregaddr);
  468. word2 = readl(phba->HSregaddr);
  469. word3 = readl(phba->HCregaddr);
  470. len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x HC:%08x\n",
  471. word0, word1, word2, word3);
  472. spin_unlock_irq(&phba->hbalock);
  473. return len;
  474. }
  475. /**
  476. * lpfc_debugfs_nodelist_data - Dump target node list to a buffer.
  477. * @vport: The vport to gather target node info from.
  478. * @buf: The buffer to dump log into.
  479. * @size: The maximum amount of data to process.
  480. *
  481. * Description:
  482. * This routine dumps the current target node list associated with @vport to
  483. * @buf up to @size bytes of data. Each node entry in the dump will contain a
  484. * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
  485. *
  486. * Return Value:
  487. * This routine returns the amount of bytes that were dumped into @buf and will
  488. * not exceed @size.
  489. **/
  490. static int
  491. lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
  492. {
  493. int len = 0;
  494. int cnt;
  495. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  496. struct lpfc_nodelist *ndlp;
  497. unsigned char *statep, *name;
  498. cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
  499. spin_lock_irq(shost->host_lock);
  500. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  501. if (!cnt) {
  502. len += snprintf(buf+len, size-len,
  503. "Missing Nodelist Entries\n");
  504. break;
  505. }
  506. cnt--;
  507. switch (ndlp->nlp_state) {
  508. case NLP_STE_UNUSED_NODE:
  509. statep = "UNUSED";
  510. break;
  511. case NLP_STE_PLOGI_ISSUE:
  512. statep = "PLOGI ";
  513. break;
  514. case NLP_STE_ADISC_ISSUE:
  515. statep = "ADISC ";
  516. break;
  517. case NLP_STE_REG_LOGIN_ISSUE:
  518. statep = "REGLOG";
  519. break;
  520. case NLP_STE_PRLI_ISSUE:
  521. statep = "PRLI ";
  522. break;
  523. case NLP_STE_UNMAPPED_NODE:
  524. statep = "UNMAP ";
  525. break;
  526. case NLP_STE_MAPPED_NODE:
  527. statep = "MAPPED";
  528. break;
  529. case NLP_STE_NPR_NODE:
  530. statep = "NPR ";
  531. break;
  532. default:
  533. statep = "UNKNOWN";
  534. }
  535. len += snprintf(buf+len, size-len, "%s DID:x%06x ",
  536. statep, ndlp->nlp_DID);
  537. name = (unsigned char *)&ndlp->nlp_portname;
  538. len += snprintf(buf+len, size-len,
  539. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  540. *name, *(name+1), *(name+2), *(name+3),
  541. *(name+4), *(name+5), *(name+6), *(name+7));
  542. name = (unsigned char *)&ndlp->nlp_nodename;
  543. len += snprintf(buf+len, size-len,
  544. "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  545. *name, *(name+1), *(name+2), *(name+3),
  546. *(name+4), *(name+5), *(name+6), *(name+7));
  547. len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
  548. ndlp->nlp_rpi, ndlp->nlp_flag);
  549. if (!ndlp->nlp_type)
  550. len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
  551. if (ndlp->nlp_type & NLP_FC_NODE)
  552. len += snprintf(buf+len, size-len, "FC_NODE ");
  553. if (ndlp->nlp_type & NLP_FABRIC)
  554. len += snprintf(buf+len, size-len, "FABRIC ");
  555. if (ndlp->nlp_type & NLP_FCP_TARGET)
  556. len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
  557. ndlp->nlp_sid);
  558. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  559. len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
  560. len += snprintf(buf+len, size-len, "usgmap:%x ",
  561. ndlp->nlp_usg_map);
  562. len += snprintf(buf+len, size-len, "refcnt:%x",
  563. atomic_read(&ndlp->kref.refcount));
  564. len += snprintf(buf+len, size-len, "\n");
  565. }
  566. spin_unlock_irq(shost->host_lock);
  567. return len;
  568. }
  569. #endif
  570. /**
  571. * lpfc_debugfs_disc_trc - Store discovery trace log.
  572. * @vport: The vport to associate this trace string with for retrieval.
  573. * @mask: Log entry classification.
  574. * @fmt: Format string to be displayed when dumping the log.
  575. * @data1: 1st data parameter to be applied to @fmt.
  576. * @data2: 2nd data parameter to be applied to @fmt.
  577. * @data3: 3rd data parameter to be applied to @fmt.
  578. *
  579. * Description:
  580. * This routine is used by the driver code to add a debugfs log entry to the
  581. * discovery trace buffer associated with @vport. Only entries with a @mask that
  582. * match the current debugfs discovery mask will be saved. Entries that do not
  583. * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
  584. * printf when displaying the log.
  585. **/
  586. inline void
  587. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  588. uint32_t data1, uint32_t data2, uint32_t data3)
  589. {
  590. #ifdef CONFIG_LPFC_DEBUG_FS
  591. struct lpfc_debugfs_trc *dtp;
  592. int index;
  593. if (!(lpfc_debugfs_mask_disc_trc & mask))
  594. return;
  595. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  596. !vport || !vport->disc_trc)
  597. return;
  598. index = atomic_inc_return(&vport->disc_trc_cnt) &
  599. (lpfc_debugfs_max_disc_trc - 1);
  600. dtp = vport->disc_trc + index;
  601. dtp->fmt = fmt;
  602. dtp->data1 = data1;
  603. dtp->data2 = data2;
  604. dtp->data3 = data3;
  605. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  606. dtp->jif = jiffies;
  607. #endif
  608. return;
  609. }
  610. /**
  611. * lpfc_debugfs_slow_ring_trc - Store slow ring trace log.
  612. * @phba: The phba to associate this trace string with for retrieval.
  613. * @fmt: Format string to be displayed when dumping the log.
  614. * @data1: 1st data parameter to be applied to @fmt.
  615. * @data2: 2nd data parameter to be applied to @fmt.
  616. * @data3: 3rd data parameter to be applied to @fmt.
  617. *
  618. * Description:
  619. * This routine is used by the driver code to add a debugfs log entry to the
  620. * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
  621. * @data3 are used like printf when displaying the log.
  622. **/
  623. inline void
  624. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  625. uint32_t data1, uint32_t data2, uint32_t data3)
  626. {
  627. #ifdef CONFIG_LPFC_DEBUG_FS
  628. struct lpfc_debugfs_trc *dtp;
  629. int index;
  630. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  631. !phba || !phba->slow_ring_trc)
  632. return;
  633. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  634. (lpfc_debugfs_max_slow_ring_trc - 1);
  635. dtp = phba->slow_ring_trc + index;
  636. dtp->fmt = fmt;
  637. dtp->data1 = data1;
  638. dtp->data2 = data2;
  639. dtp->data3 = data3;
  640. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  641. dtp->jif = jiffies;
  642. #endif
  643. return;
  644. }
  645. #ifdef CONFIG_LPFC_DEBUG_FS
  646. /**
  647. * lpfc_debugfs_disc_trc_open - Open the discovery trace log.
  648. * @inode: The inode pointer that contains a vport pointer.
  649. * @file: The file pointer to attach the log output.
  650. *
  651. * Description:
  652. * This routine is the entry point for the debugfs open file operation. It gets
  653. * the vport from the i_private field in @inode, allocates the necessary buffer
  654. * for the log, fills the buffer from the in-memory log for this vport, and then
  655. * returns a pointer to that log in the private_data field in @file.
  656. *
  657. * Returns:
  658. * This function returns zero if successful. On error it will return an negative
  659. * error value.
  660. **/
  661. static int
  662. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  663. {
  664. struct lpfc_vport *vport = inode->i_private;
  665. struct lpfc_debug *debug;
  666. int size;
  667. int rc = -ENOMEM;
  668. if (!lpfc_debugfs_max_disc_trc) {
  669. rc = -ENOSPC;
  670. goto out;
  671. }
  672. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  673. if (!debug)
  674. goto out;
  675. /* Round to page boundary */
  676. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  677. size = PAGE_ALIGN(size);
  678. debug->buffer = kmalloc(size, GFP_KERNEL);
  679. if (!debug->buffer) {
  680. kfree(debug);
  681. goto out;
  682. }
  683. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  684. file->private_data = debug;
  685. rc = 0;
  686. out:
  687. return rc;
  688. }
  689. /**
  690. * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log.
  691. * @inode: The inode pointer that contains a vport pointer.
  692. * @file: The file pointer to attach the log output.
  693. *
  694. * Description:
  695. * This routine is the entry point for the debugfs open file operation. It gets
  696. * the vport from the i_private field in @inode, allocates the necessary buffer
  697. * for the log, fills the buffer from the in-memory log for this vport, and then
  698. * returns a pointer to that log in the private_data field in @file.
  699. *
  700. * Returns:
  701. * This function returns zero if successful. On error it will return an negative
  702. * error value.
  703. **/
  704. static int
  705. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  706. {
  707. struct lpfc_hba *phba = inode->i_private;
  708. struct lpfc_debug *debug;
  709. int size;
  710. int rc = -ENOMEM;
  711. if (!lpfc_debugfs_max_slow_ring_trc) {
  712. rc = -ENOSPC;
  713. goto out;
  714. }
  715. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  716. if (!debug)
  717. goto out;
  718. /* Round to page boundary */
  719. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  720. size = PAGE_ALIGN(size);
  721. debug->buffer = kmalloc(size, GFP_KERNEL);
  722. if (!debug->buffer) {
  723. kfree(debug);
  724. goto out;
  725. }
  726. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  727. file->private_data = debug;
  728. rc = 0;
  729. out:
  730. return rc;
  731. }
  732. /**
  733. * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer.
  734. * @inode: The inode pointer that contains a vport pointer.
  735. * @file: The file pointer to attach the log output.
  736. *
  737. * Description:
  738. * This routine is the entry point for the debugfs open file operation. It gets
  739. * the vport from the i_private field in @inode, allocates the necessary buffer
  740. * for the log, fills the buffer from the in-memory log for this vport, and then
  741. * returns a pointer to that log in the private_data field in @file.
  742. *
  743. * Returns:
  744. * This function returns zero if successful. On error it will return an negative
  745. * error value.
  746. **/
  747. static int
  748. lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
  749. {
  750. struct lpfc_hba *phba = inode->i_private;
  751. struct lpfc_debug *debug;
  752. int rc = -ENOMEM;
  753. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  754. if (!debug)
  755. goto out;
  756. /* Round to page boundary */
  757. debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
  758. if (!debug->buffer) {
  759. kfree(debug);
  760. goto out;
  761. }
  762. debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
  763. LPFC_HBQINFO_SIZE);
  764. file->private_data = debug;
  765. rc = 0;
  766. out:
  767. return rc;
  768. }
  769. /**
  770. * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer.
  771. * @inode: The inode pointer that contains a vport pointer.
  772. * @file: The file pointer to attach the log output.
  773. *
  774. * Description:
  775. * This routine is the entry point for the debugfs open file operation. It gets
  776. * the vport from the i_private field in @inode, allocates the necessary buffer
  777. * for the log, fills the buffer from the in-memory log for this vport, and then
  778. * returns a pointer to that log in the private_data field in @file.
  779. *
  780. * Returns:
  781. * This function returns zero if successful. On error it will return an negative
  782. * error value.
  783. **/
  784. static int
  785. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  786. {
  787. struct lpfc_hba *phba = inode->i_private;
  788. struct lpfc_debug *debug;
  789. int rc = -ENOMEM;
  790. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  791. if (!debug)
  792. goto out;
  793. /* Round to page boundary */
  794. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  795. if (!debug->buffer) {
  796. kfree(debug);
  797. goto out;
  798. }
  799. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  800. LPFC_DUMPHBASLIM_SIZE);
  801. file->private_data = debug;
  802. rc = 0;
  803. out:
  804. return rc;
  805. }
  806. /**
  807. * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer.
  808. * @inode: The inode pointer that contains a vport pointer.
  809. * @file: The file pointer to attach the log output.
  810. *
  811. * Description:
  812. * This routine is the entry point for the debugfs open file operation. It gets
  813. * the vport from the i_private field in @inode, allocates the necessary buffer
  814. * for the log, fills the buffer from the in-memory log for this vport, and then
  815. * returns a pointer to that log in the private_data field in @file.
  816. *
  817. * Returns:
  818. * This function returns zero if successful. On error it will return an negative
  819. * error value.
  820. **/
  821. static int
  822. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  823. {
  824. struct lpfc_hba *phba = inode->i_private;
  825. struct lpfc_debug *debug;
  826. int rc = -ENOMEM;
  827. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  828. if (!debug)
  829. goto out;
  830. /* Round to page boundary */
  831. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  832. if (!debug->buffer) {
  833. kfree(debug);
  834. goto out;
  835. }
  836. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  837. LPFC_DUMPHOSTSLIM_SIZE);
  838. file->private_data = debug;
  839. rc = 0;
  840. out:
  841. return rc;
  842. }
  843. /**
  844. * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file.
  845. * @inode: The inode pointer that contains a vport pointer.
  846. * @file: The file pointer to attach the log output.
  847. *
  848. * Description:
  849. * This routine is the entry point for the debugfs open file operation. It gets
  850. * the vport from the i_private field in @inode, allocates the necessary buffer
  851. * for the log, fills the buffer from the in-memory log for this vport, and then
  852. * returns a pointer to that log in the private_data field in @file.
  853. *
  854. * Returns:
  855. * This function returns zero if successful. On error it will return an negative
  856. * error value.
  857. **/
  858. static int
  859. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  860. {
  861. struct lpfc_vport *vport = inode->i_private;
  862. struct lpfc_debug *debug;
  863. int rc = -ENOMEM;
  864. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  865. if (!debug)
  866. goto out;
  867. /* Round to page boundary */
  868. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  869. if (!debug->buffer) {
  870. kfree(debug);
  871. goto out;
  872. }
  873. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  874. LPFC_NODELIST_SIZE);
  875. file->private_data = debug;
  876. rc = 0;
  877. out:
  878. return rc;
  879. }
  880. /**
  881. * lpfc_debugfs_lseek - Seek through a debugfs file.
  882. * @file: The file pointer to seek through.
  883. * @off: The offset to seek to or the amount to seek by.
  884. * @whence: Indicates how to seek.
  885. *
  886. * Description:
  887. * This routine is the entry point for the debugfs lseek file operation. The
  888. * @whence parameter indicates whether @off is the offset to directly seek to,
  889. * or if it is a value to seek forward or reverse by. This function figures out
  890. * what the new offset of the debugfs file will be and assigns that value to the
  891. * f_pos field of @file.
  892. *
  893. * Returns:
  894. * This function returns the new offset if successful and returns a negative
  895. * error if unable to process the seek.
  896. **/
  897. static loff_t
  898. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  899. {
  900. struct lpfc_debug *debug;
  901. loff_t pos = -1;
  902. debug = file->private_data;
  903. switch (whence) {
  904. case 0:
  905. pos = off;
  906. break;
  907. case 1:
  908. pos = file->f_pos + off;
  909. break;
  910. case 2:
  911. pos = debug->len - off;
  912. }
  913. return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
  914. }
  915. /**
  916. * lpfc_debugfs_read - Read a debugfs file.
  917. * @file: The file pointer to read from.
  918. * @buf: The buffer to copy the data to.
  919. * @nbytes: The number of bytes to read.
  920. * @ppos: The position in the file to start reading from.
  921. *
  922. * Description:
  923. * This routine reads data from from the buffer indicated in the private_data
  924. * field of @file. It will start reading at @ppos and copy up to @nbytes of
  925. * data to @buf.
  926. *
  927. * Returns:
  928. * This function returns the amount of data that was read (this could be less
  929. * than @nbytes if the end of the file was reached) or a negative error value.
  930. **/
  931. static ssize_t
  932. lpfc_debugfs_read(struct file *file, char __user *buf,
  933. size_t nbytes, loff_t *ppos)
  934. {
  935. struct lpfc_debug *debug = file->private_data;
  936. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  937. debug->len);
  938. }
  939. /**
  940. * lpfc_debugfs_release - Release the buffer used to store debugfs file data.
  941. * @inode: The inode pointer that contains a vport pointer. (unused)
  942. * @file: The file pointer that contains the buffer to release.
  943. *
  944. * Description:
  945. * This routine frees the buffer that was allocated when the debugfs file was
  946. * opened.
  947. *
  948. * Returns:
  949. * This function returns zero.
  950. **/
  951. static int
  952. lpfc_debugfs_release(struct inode *inode, struct file *file)
  953. {
  954. struct lpfc_debug *debug = file->private_data;
  955. kfree(debug->buffer);
  956. kfree(debug);
  957. return 0;
  958. }
  959. #undef lpfc_debugfs_op_disc_trc
  960. static struct file_operations lpfc_debugfs_op_disc_trc = {
  961. .owner = THIS_MODULE,
  962. .open = lpfc_debugfs_disc_trc_open,
  963. .llseek = lpfc_debugfs_lseek,
  964. .read = lpfc_debugfs_read,
  965. .release = lpfc_debugfs_release,
  966. };
  967. #undef lpfc_debugfs_op_nodelist
  968. static struct file_operations lpfc_debugfs_op_nodelist = {
  969. .owner = THIS_MODULE,
  970. .open = lpfc_debugfs_nodelist_open,
  971. .llseek = lpfc_debugfs_lseek,
  972. .read = lpfc_debugfs_read,
  973. .release = lpfc_debugfs_release,
  974. };
  975. #undef lpfc_debugfs_op_hbqinfo
  976. static struct file_operations lpfc_debugfs_op_hbqinfo = {
  977. .owner = THIS_MODULE,
  978. .open = lpfc_debugfs_hbqinfo_open,
  979. .llseek = lpfc_debugfs_lseek,
  980. .read = lpfc_debugfs_read,
  981. .release = lpfc_debugfs_release,
  982. };
  983. #undef lpfc_debugfs_op_dumpHBASlim
  984. static struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  985. .owner = THIS_MODULE,
  986. .open = lpfc_debugfs_dumpHBASlim_open,
  987. .llseek = lpfc_debugfs_lseek,
  988. .read = lpfc_debugfs_read,
  989. .release = lpfc_debugfs_release,
  990. };
  991. #undef lpfc_debugfs_op_dumpHostSlim
  992. static struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  993. .owner = THIS_MODULE,
  994. .open = lpfc_debugfs_dumpHostSlim_open,
  995. .llseek = lpfc_debugfs_lseek,
  996. .read = lpfc_debugfs_read,
  997. .release = lpfc_debugfs_release,
  998. };
  999. #undef lpfc_debugfs_op_slow_ring_trc
  1000. static struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  1001. .owner = THIS_MODULE,
  1002. .open = lpfc_debugfs_slow_ring_trc_open,
  1003. .llseek = lpfc_debugfs_lseek,
  1004. .read = lpfc_debugfs_read,
  1005. .release = lpfc_debugfs_release,
  1006. };
  1007. static struct dentry *lpfc_debugfs_root = NULL;
  1008. static atomic_t lpfc_debugfs_hba_count;
  1009. #endif
  1010. /**
  1011. * lpfc_debugfs_initialize - Initialize debugfs for a vport.
  1012. * @vport: The vport pointer to initialize.
  1013. *
  1014. * Description:
  1015. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  1016. * If not already created, this routine will create the lpfc directory, and
  1017. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  1018. * also create each file used to access lpfc specific debugfs information.
  1019. **/
  1020. inline void
  1021. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  1022. {
  1023. #ifdef CONFIG_LPFC_DEBUG_FS
  1024. struct lpfc_hba *phba = vport->phba;
  1025. char name[64];
  1026. uint32_t num, i;
  1027. if (!lpfc_debugfs_enable)
  1028. return;
  1029. /* Setup lpfc root directory */
  1030. if (!lpfc_debugfs_root) {
  1031. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  1032. atomic_set(&lpfc_debugfs_hba_count, 0);
  1033. if (!lpfc_debugfs_root) {
  1034. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1035. "0409 Cannot create debugfs root\n");
  1036. goto debug_failed;
  1037. }
  1038. }
  1039. if (!lpfc_debugfs_start_time)
  1040. lpfc_debugfs_start_time = jiffies;
  1041. /* Setup lpfcX directory for specific HBA */
  1042. snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
  1043. if (!phba->hba_debugfs_root) {
  1044. phba->hba_debugfs_root =
  1045. debugfs_create_dir(name, lpfc_debugfs_root);
  1046. if (!phba->hba_debugfs_root) {
  1047. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1048. "0409 Cannot create debugfs hba\n");
  1049. goto debug_failed;
  1050. }
  1051. atomic_inc(&lpfc_debugfs_hba_count);
  1052. atomic_set(&phba->debugfs_vport_count, 0);
  1053. /* Setup hbqinfo */
  1054. snprintf(name, sizeof(name), "hbqinfo");
  1055. phba->debug_hbqinfo =
  1056. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1057. phba->hba_debugfs_root,
  1058. phba, &lpfc_debugfs_op_hbqinfo);
  1059. if (!phba->debug_hbqinfo) {
  1060. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1061. "0409 Cannot create debugfs hbqinfo\n");
  1062. goto debug_failed;
  1063. }
  1064. /* Setup dumpHBASlim */
  1065. snprintf(name, sizeof(name), "dumpHBASlim");
  1066. phba->debug_dumpHBASlim =
  1067. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1068. phba->hba_debugfs_root,
  1069. phba, &lpfc_debugfs_op_dumpHBASlim);
  1070. if (!phba->debug_dumpHBASlim) {
  1071. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1072. "0409 Cannot create debugfs dumpHBASlim\n");
  1073. goto debug_failed;
  1074. }
  1075. /* Setup dumpHostSlim */
  1076. snprintf(name, sizeof(name), "dumpHostSlim");
  1077. phba->debug_dumpHostSlim =
  1078. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1079. phba->hba_debugfs_root,
  1080. phba, &lpfc_debugfs_op_dumpHostSlim);
  1081. if (!phba->debug_dumpHostSlim) {
  1082. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1083. "0409 Cannot create debugfs dumpHostSlim\n");
  1084. goto debug_failed;
  1085. }
  1086. /* Setup slow ring trace */
  1087. if (lpfc_debugfs_max_slow_ring_trc) {
  1088. num = lpfc_debugfs_max_slow_ring_trc - 1;
  1089. if (num & lpfc_debugfs_max_slow_ring_trc) {
  1090. /* Change to be a power of 2 */
  1091. num = lpfc_debugfs_max_slow_ring_trc;
  1092. i = 0;
  1093. while (num > 1) {
  1094. num = num >> 1;
  1095. i++;
  1096. }
  1097. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  1098. printk(KERN_ERR
  1099. "lpfc_debugfs_max_disc_trc changed to "
  1100. "%d\n", lpfc_debugfs_max_disc_trc);
  1101. }
  1102. }
  1103. snprintf(name, sizeof(name), "slow_ring_trace");
  1104. phba->debug_slow_ring_trc =
  1105. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1106. phba->hba_debugfs_root,
  1107. phba, &lpfc_debugfs_op_slow_ring_trc);
  1108. if (!phba->debug_slow_ring_trc) {
  1109. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1110. "0409 Cannot create debugfs "
  1111. "slow_ring_trace\n");
  1112. goto debug_failed;
  1113. }
  1114. if (!phba->slow_ring_trc) {
  1115. phba->slow_ring_trc = kmalloc(
  1116. (sizeof(struct lpfc_debugfs_trc) *
  1117. lpfc_debugfs_max_slow_ring_trc),
  1118. GFP_KERNEL);
  1119. if (!phba->slow_ring_trc) {
  1120. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1121. "0409 Cannot create debugfs "
  1122. "slow_ring buffer\n");
  1123. goto debug_failed;
  1124. }
  1125. atomic_set(&phba->slow_ring_trc_cnt, 0);
  1126. memset(phba->slow_ring_trc, 0,
  1127. (sizeof(struct lpfc_debugfs_trc) *
  1128. lpfc_debugfs_max_slow_ring_trc));
  1129. }
  1130. }
  1131. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  1132. if (!vport->vport_debugfs_root) {
  1133. vport->vport_debugfs_root =
  1134. debugfs_create_dir(name, phba->hba_debugfs_root);
  1135. if (!vport->vport_debugfs_root) {
  1136. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1137. "0409 Cant create debugfs");
  1138. goto debug_failed;
  1139. }
  1140. atomic_inc(&phba->debugfs_vport_count);
  1141. }
  1142. if (lpfc_debugfs_max_disc_trc) {
  1143. num = lpfc_debugfs_max_disc_trc - 1;
  1144. if (num & lpfc_debugfs_max_disc_trc) {
  1145. /* Change to be a power of 2 */
  1146. num = lpfc_debugfs_max_disc_trc;
  1147. i = 0;
  1148. while (num > 1) {
  1149. num = num >> 1;
  1150. i++;
  1151. }
  1152. lpfc_debugfs_max_disc_trc = (1 << i);
  1153. printk(KERN_ERR
  1154. "lpfc_debugfs_max_disc_trc changed to %d\n",
  1155. lpfc_debugfs_max_disc_trc);
  1156. }
  1157. }
  1158. vport->disc_trc = kzalloc(
  1159. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  1160. GFP_KERNEL);
  1161. if (!vport->disc_trc) {
  1162. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1163. "0409 Cannot create debugfs disc trace "
  1164. "buffer\n");
  1165. goto debug_failed;
  1166. }
  1167. atomic_set(&vport->disc_trc_cnt, 0);
  1168. snprintf(name, sizeof(name), "discovery_trace");
  1169. vport->debug_disc_trc =
  1170. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1171. vport->vport_debugfs_root,
  1172. vport, &lpfc_debugfs_op_disc_trc);
  1173. if (!vport->debug_disc_trc) {
  1174. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1175. "0409 Cannot create debugfs "
  1176. "discovery_trace\n");
  1177. goto debug_failed;
  1178. }
  1179. snprintf(name, sizeof(name), "nodelist");
  1180. vport->debug_nodelist =
  1181. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1182. vport->vport_debugfs_root,
  1183. vport, &lpfc_debugfs_op_nodelist);
  1184. if (!vport->debug_nodelist) {
  1185. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1186. "0409 Cant create debugfs nodelist");
  1187. goto debug_failed;
  1188. }
  1189. debug_failed:
  1190. return;
  1191. #endif
  1192. }
  1193. /**
  1194. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport.
  1195. * @vport: The vport pointer to remove from debugfs.
  1196. *
  1197. * Description:
  1198. * When Debugfs is configured this routine removes debugfs file system elements
  1199. * that are specific to this vport. It also checks to see if there are any
  1200. * users left for the debugfs directories associated with the HBA and driver. If
  1201. * this is the last user of the HBA directory or driver directory then it will
  1202. * remove those from the debugfs infrastructure as well.
  1203. **/
  1204. inline void
  1205. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  1206. {
  1207. #ifdef CONFIG_LPFC_DEBUG_FS
  1208. struct lpfc_hba *phba = vport->phba;
  1209. if (vport->disc_trc) {
  1210. kfree(vport->disc_trc);
  1211. vport->disc_trc = NULL;
  1212. }
  1213. if (vport->debug_disc_trc) {
  1214. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  1215. vport->debug_disc_trc = NULL;
  1216. }
  1217. if (vport->debug_nodelist) {
  1218. debugfs_remove(vport->debug_nodelist); /* nodelist */
  1219. vport->debug_nodelist = NULL;
  1220. }
  1221. if (vport->vport_debugfs_root) {
  1222. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  1223. vport->vport_debugfs_root = NULL;
  1224. atomic_dec(&phba->debugfs_vport_count);
  1225. }
  1226. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  1227. if (phba->debug_hbqinfo) {
  1228. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  1229. phba->debug_hbqinfo = NULL;
  1230. }
  1231. if (phba->debug_dumpHBASlim) {
  1232. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  1233. phba->debug_dumpHBASlim = NULL;
  1234. }
  1235. if (phba->debug_dumpHostSlim) {
  1236. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  1237. phba->debug_dumpHostSlim = NULL;
  1238. }
  1239. if (phba->slow_ring_trc) {
  1240. kfree(phba->slow_ring_trc);
  1241. phba->slow_ring_trc = NULL;
  1242. }
  1243. if (phba->debug_slow_ring_trc) {
  1244. /* slow_ring_trace */
  1245. debugfs_remove(phba->debug_slow_ring_trc);
  1246. phba->debug_slow_ring_trc = NULL;
  1247. }
  1248. if (phba->hba_debugfs_root) {
  1249. debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
  1250. phba->hba_debugfs_root = NULL;
  1251. atomic_dec(&lpfc_debugfs_hba_count);
  1252. }
  1253. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  1254. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  1255. lpfc_debugfs_root = NULL;
  1256. }
  1257. }
  1258. #endif
  1259. return;
  1260. }