lpfc_debugfs.c 40 KB

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