lpfc_debugfs.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2007 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 <linux/version.h>
  30. #include <scsi/scsi.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.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. /* 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 hierachy 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
  62. * discovery events. To enable the discovery trace, the following
  63. * 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. static int lpfc_debugfs_enable = 1;
  71. module_param(lpfc_debugfs_enable, int, 0);
  72. MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
  73. /* This MUST be a power of 2 */
  74. static int lpfc_debugfs_max_disc_trc;
  75. module_param(lpfc_debugfs_max_disc_trc, int, 0);
  76. MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
  77. "Set debugfs discovery trace depth");
  78. /* This MUST be a power of 2 */
  79. static int lpfc_debugfs_max_slow_ring_trc;
  80. module_param(lpfc_debugfs_max_slow_ring_trc, int, 0);
  81. MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
  82. "Set debugfs slow ring trace depth");
  83. int lpfc_debugfs_mask_disc_trc;
  84. module_param(lpfc_debugfs_mask_disc_trc, int, 0);
  85. MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
  86. "Set debugfs discovery trace mask");
  87. #include <linux/debugfs.h>
  88. /* size of output line, for discovery_trace and slow_ring_trace */
  89. #define LPFC_DEBUG_TRC_ENTRY_SIZE 100
  90. /* nodelist output buffer size */
  91. #define LPFC_NODELIST_SIZE 8192
  92. #define LPFC_NODELIST_ENTRY_SIZE 120
  93. /* dumpHBASlim output buffer size */
  94. #define LPFC_DUMPHBASLIM_SIZE 4096
  95. /* dumpHostSlim output buffer size */
  96. #define LPFC_DUMPHOSTSLIM_SIZE 4096
  97. /* hbqinfo output buffer size */
  98. #define LPFC_HBQINFO_SIZE 8192
  99. struct lpfc_debug {
  100. char *buffer;
  101. int len;
  102. };
  103. static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  104. static unsigned long lpfc_debugfs_start_time = 0L;
  105. static int
  106. lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
  107. {
  108. int i, index, len, enable;
  109. uint32_t ms;
  110. struct lpfc_debugfs_trc *dtp;
  111. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  112. enable = lpfc_debugfs_enable;
  113. lpfc_debugfs_enable = 0;
  114. len = 0;
  115. index = (atomic_read(&vport->disc_trc_cnt) + 1) &
  116. (lpfc_debugfs_max_disc_trc - 1);
  117. for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
  118. dtp = vport->disc_trc + i;
  119. if (!dtp->fmt)
  120. continue;
  121. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  122. snprintf(buffer,
  123. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  124. dtp->seq_cnt, ms, dtp->fmt);
  125. len += snprintf(buf+len, size-len, buffer,
  126. dtp->data1, dtp->data2, dtp->data3);
  127. }
  128. for (i = 0; i < index; i++) {
  129. dtp = vport->disc_trc + i;
  130. if (!dtp->fmt)
  131. continue;
  132. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  133. snprintf(buffer,
  134. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  135. dtp->seq_cnt, ms, dtp->fmt);
  136. len += snprintf(buf+len, size-len, buffer,
  137. dtp->data1, dtp->data2, dtp->data3);
  138. }
  139. lpfc_debugfs_enable = enable;
  140. return len;
  141. }
  142. static int
  143. lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
  144. {
  145. int i, index, len, enable;
  146. uint32_t ms;
  147. struct lpfc_debugfs_trc *dtp;
  148. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  149. enable = lpfc_debugfs_enable;
  150. lpfc_debugfs_enable = 0;
  151. len = 0;
  152. index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
  153. (lpfc_debugfs_max_slow_ring_trc - 1);
  154. for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
  155. dtp = phba->slow_ring_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. for (i = 0; i < index; i++) {
  166. dtp = phba->slow_ring_trc + i;
  167. if (!dtp->fmt)
  168. continue;
  169. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  170. snprintf(buffer,
  171. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  172. dtp->seq_cnt, ms, dtp->fmt);
  173. len += snprintf(buf+len, size-len, buffer,
  174. dtp->data1, dtp->data2, dtp->data3);
  175. }
  176. lpfc_debugfs_enable = enable;
  177. return len;
  178. }
  179. static int lpfc_debugfs_last_hbq = -1;
  180. static int
  181. lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
  182. {
  183. int len = 0;
  184. int cnt, i, j, found, posted, low;
  185. uint32_t phys, raw_index, getidx;
  186. struct lpfc_hbq_init *hip;
  187. struct hbq_s *hbqs;
  188. struct lpfc_hbq_entry *hbqe;
  189. struct lpfc_dmabuf *d_buf;
  190. struct hbq_dmabuf *hbq_buf;
  191. cnt = LPFC_HBQINFO_SIZE;
  192. spin_lock_irq(&phba->hbalock);
  193. /* toggle between multiple hbqs, if any */
  194. i = lpfc_sli_hbq_count();
  195. if (i > 1) {
  196. lpfc_debugfs_last_hbq++;
  197. if (lpfc_debugfs_last_hbq >= i)
  198. lpfc_debugfs_last_hbq = 0;
  199. }
  200. else
  201. lpfc_debugfs_last_hbq = 0;
  202. i = lpfc_debugfs_last_hbq;
  203. len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
  204. hbqs = &phba->hbqs[i];
  205. posted = 0;
  206. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
  207. posted++;
  208. hip = lpfc_hbq_defs[i];
  209. len += snprintf(buf+len, size-len,
  210. "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
  211. hip->hbq_index, hip->profile, hip->rn,
  212. hip->buffer_count, hip->init_count, hip->add_count, posted);
  213. raw_index = phba->hbq_get[i];
  214. getidx = le32_to_cpu(raw_index);
  215. len += snprintf(buf+len, size-len,
  216. "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
  217. hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
  218. hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
  219. hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
  220. for (j=0; j<hbqs->entry_count; j++) {
  221. len += snprintf(buf+len, size-len,
  222. "%03d: %08x %04x %05x ", j,
  223. le32_to_cpu(hbqe->bde.addrLow),
  224. le32_to_cpu(hbqe->bde.tus.w),
  225. le32_to_cpu(hbqe->buffer_tag));
  226. i = 0;
  227. found = 0;
  228. /* First calculate if slot has an associated posted buffer */
  229. low = hbqs->hbqPutIdx - posted;
  230. if (low >= 0) {
  231. if ((j >= hbqs->hbqPutIdx) || (j < low)) {
  232. len += snprintf(buf+len, size-len, "Unused\n");
  233. goto skipit;
  234. }
  235. }
  236. else {
  237. if ((j >= hbqs->hbqPutIdx) &&
  238. (j < (hbqs->entry_count+low))) {
  239. len += snprintf(buf+len, size-len, "Unused\n");
  240. goto skipit;
  241. }
  242. }
  243. /* Get the Buffer info for the posted buffer */
  244. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
  245. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  246. phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
  247. if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
  248. len += snprintf(buf+len, size-len,
  249. "Buf%d: %p %06x\n", i,
  250. hbq_buf->dbuf.virt, hbq_buf->tag);
  251. found = 1;
  252. break;
  253. }
  254. i++;
  255. }
  256. if (!found) {
  257. len += snprintf(buf+len, size-len, "No DMAinfo?\n");
  258. }
  259. skipit:
  260. hbqe++;
  261. if (len > LPFC_HBQINFO_SIZE - 54)
  262. break;
  263. }
  264. spin_unlock_irq(&phba->hbalock);
  265. return len;
  266. }
  267. static int lpfc_debugfs_last_hba_slim_off;
  268. static int
  269. lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
  270. {
  271. int len = 0;
  272. int i, off;
  273. uint32_t *ptr;
  274. char buffer[1024];
  275. off = 0;
  276. spin_lock_irq(&phba->hbalock);
  277. len += snprintf(buf+len, size-len, "HBA SLIM\n");
  278. lpfc_memcpy_from_slim(buffer,
  279. ((uint8_t *)phba->MBslimaddr) + lpfc_debugfs_last_hba_slim_off,
  280. 1024);
  281. ptr = (uint32_t *)&buffer[0];
  282. off = lpfc_debugfs_last_hba_slim_off;
  283. /* Set it up for the next time */
  284. lpfc_debugfs_last_hba_slim_off += 1024;
  285. if (lpfc_debugfs_last_hba_slim_off >= 4096)
  286. lpfc_debugfs_last_hba_slim_off = 0;
  287. i = 1024;
  288. while (i > 0) {
  289. len += snprintf(buf+len, size-len,
  290. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  291. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  292. *(ptr+5), *(ptr+6), *(ptr+7));
  293. ptr += 8;
  294. i -= (8 * sizeof(uint32_t));
  295. off += (8 * sizeof(uint32_t));
  296. }
  297. spin_unlock_irq(&phba->hbalock);
  298. return len;
  299. }
  300. static int
  301. lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
  302. {
  303. int len = 0;
  304. int i, off;
  305. uint32_t word0, word1, word2, word3;
  306. uint32_t *ptr;
  307. struct lpfc_pgp *pgpp;
  308. struct lpfc_sli *psli = &phba->sli;
  309. struct lpfc_sli_ring *pring;
  310. off = 0;
  311. spin_lock_irq(&phba->hbalock);
  312. len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
  313. ptr = (uint32_t *)phba->slim2p;
  314. i = sizeof(MAILBOX_t);
  315. while (i > 0) {
  316. len += snprintf(buf+len, size-len,
  317. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  318. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  319. *(ptr+5), *(ptr+6), *(ptr+7));
  320. ptr += 8;
  321. i -= (8 * sizeof(uint32_t));
  322. off += (8 * sizeof(uint32_t));
  323. }
  324. len += snprintf(buf+len, size-len, "SLIM PCB\n");
  325. ptr = (uint32_t *)&phba->slim2p->pcb;
  326. i = sizeof(PCB_t);
  327. while (i > 0) {
  328. len += snprintf(buf+len, size-len,
  329. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  330. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  331. *(ptr+5), *(ptr+6), *(ptr+7));
  332. ptr += 8;
  333. i -= (8 * sizeof(uint32_t));
  334. off += (8 * sizeof(uint32_t));
  335. }
  336. pgpp = (struct lpfc_pgp *)&phba->slim2p->mbx.us.s3_pgp.port;
  337. pring = &psli->ring[0];
  338. len += snprintf(buf+len, size-len,
  339. "Ring 0: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  340. "RSP PutInx:%d Max:%d\n",
  341. pgpp->cmdGetInx, pring->numCiocb,
  342. pring->next_cmdidx, pring->local_getidx, pring->flag,
  343. pgpp->rspPutInx, pring->numRiocb);
  344. pgpp++;
  345. pring = &psli->ring[1];
  346. len += snprintf(buf+len, size-len,
  347. "Ring 1: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  348. "RSP PutInx:%d Max:%d\n",
  349. pgpp->cmdGetInx, pring->numCiocb,
  350. pring->next_cmdidx, pring->local_getidx, pring->flag,
  351. pgpp->rspPutInx, pring->numRiocb);
  352. pgpp++;
  353. pring = &psli->ring[2];
  354. len += snprintf(buf+len, size-len,
  355. "Ring 2: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  356. "RSP PutInx:%d Max:%d\n",
  357. pgpp->cmdGetInx, pring->numCiocb,
  358. pring->next_cmdidx, pring->local_getidx, pring->flag,
  359. pgpp->rspPutInx, pring->numRiocb);
  360. pgpp++;
  361. pring = &psli->ring[3];
  362. len += snprintf(buf+len, size-len,
  363. "Ring 3: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  364. "RSP PutInx:%d Max:%d\n",
  365. pgpp->cmdGetInx, pring->numCiocb,
  366. pring->next_cmdidx, pring->local_getidx, pring->flag,
  367. pgpp->rspPutInx, pring->numRiocb);
  368. ptr = (uint32_t *)&phba->slim2p->mbx.us.s3_pgp.hbq_get;
  369. word0 = readl(phba->HAregaddr);
  370. word1 = readl(phba->CAregaddr);
  371. word2 = readl(phba->HSregaddr);
  372. word3 = readl(phba->HCregaddr);
  373. len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x HC:%08x\n",
  374. word0, word1, word2, word3);
  375. spin_unlock_irq(&phba->hbalock);
  376. return len;
  377. }
  378. static int
  379. lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
  380. {
  381. int len = 0;
  382. int cnt;
  383. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  384. struct lpfc_nodelist *ndlp;
  385. unsigned char *statep, *name;
  386. cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
  387. spin_lock_irq(shost->host_lock);
  388. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  389. if (!cnt) {
  390. len += snprintf(buf+len, size-len,
  391. "Missing Nodelist Entries\n");
  392. break;
  393. }
  394. cnt--;
  395. switch (ndlp->nlp_state) {
  396. case NLP_STE_UNUSED_NODE:
  397. statep = "UNUSED";
  398. break;
  399. case NLP_STE_PLOGI_ISSUE:
  400. statep = "PLOGI ";
  401. break;
  402. case NLP_STE_ADISC_ISSUE:
  403. statep = "ADISC ";
  404. break;
  405. case NLP_STE_REG_LOGIN_ISSUE:
  406. statep = "REGLOG";
  407. break;
  408. case NLP_STE_PRLI_ISSUE:
  409. statep = "PRLI ";
  410. break;
  411. case NLP_STE_UNMAPPED_NODE:
  412. statep = "UNMAP ";
  413. break;
  414. case NLP_STE_MAPPED_NODE:
  415. statep = "MAPPED";
  416. break;
  417. case NLP_STE_NPR_NODE:
  418. statep = "NPR ";
  419. break;
  420. default:
  421. statep = "UNKNOWN";
  422. }
  423. len += snprintf(buf+len, size-len, "%s DID:x%06x ",
  424. statep, ndlp->nlp_DID);
  425. name = (unsigned char *)&ndlp->nlp_portname;
  426. len += snprintf(buf+len, size-len,
  427. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  428. *name, *(name+1), *(name+2), *(name+3),
  429. *(name+4), *(name+5), *(name+6), *(name+7));
  430. name = (unsigned char *)&ndlp->nlp_nodename;
  431. len += snprintf(buf+len, size-len,
  432. "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  433. *name, *(name+1), *(name+2), *(name+3),
  434. *(name+4), *(name+5), *(name+6), *(name+7));
  435. len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
  436. ndlp->nlp_rpi, ndlp->nlp_flag);
  437. if (!ndlp->nlp_type)
  438. len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
  439. if (ndlp->nlp_type & NLP_FC_NODE)
  440. len += snprintf(buf+len, size-len, "FC_NODE ");
  441. if (ndlp->nlp_type & NLP_FABRIC)
  442. len += snprintf(buf+len, size-len, "FABRIC ");
  443. if (ndlp->nlp_type & NLP_FCP_TARGET)
  444. len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
  445. ndlp->nlp_sid);
  446. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  447. len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
  448. len += snprintf(buf+len, size-len, "refcnt:%x",
  449. atomic_read(&ndlp->kref.refcount));
  450. len += snprintf(buf+len, size-len, "\n");
  451. }
  452. spin_unlock_irq(shost->host_lock);
  453. return len;
  454. }
  455. #endif
  456. inline void
  457. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  458. uint32_t data1, uint32_t data2, uint32_t data3)
  459. {
  460. #ifdef CONFIG_LPFC_DEBUG_FS
  461. struct lpfc_debugfs_trc *dtp;
  462. int index;
  463. if (!(lpfc_debugfs_mask_disc_trc & mask))
  464. return;
  465. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  466. !vport || !vport->disc_trc)
  467. return;
  468. index = atomic_inc_return(&vport->disc_trc_cnt) &
  469. (lpfc_debugfs_max_disc_trc - 1);
  470. dtp = vport->disc_trc + index;
  471. dtp->fmt = fmt;
  472. dtp->data1 = data1;
  473. dtp->data2 = data2;
  474. dtp->data3 = data3;
  475. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  476. dtp->jif = jiffies;
  477. #endif
  478. return;
  479. }
  480. inline void
  481. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  482. uint32_t data1, uint32_t data2, uint32_t data3)
  483. {
  484. #ifdef CONFIG_LPFC_DEBUG_FS
  485. struct lpfc_debugfs_trc *dtp;
  486. int index;
  487. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  488. !phba || !phba->slow_ring_trc)
  489. return;
  490. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  491. (lpfc_debugfs_max_slow_ring_trc - 1);
  492. dtp = phba->slow_ring_trc + index;
  493. dtp->fmt = fmt;
  494. dtp->data1 = data1;
  495. dtp->data2 = data2;
  496. dtp->data3 = data3;
  497. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  498. dtp->jif = jiffies;
  499. #endif
  500. return;
  501. }
  502. #ifdef CONFIG_LPFC_DEBUG_FS
  503. static int
  504. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  505. {
  506. struct lpfc_vport *vport = inode->i_private;
  507. struct lpfc_debug *debug;
  508. int size;
  509. int rc = -ENOMEM;
  510. if (!lpfc_debugfs_max_disc_trc) {
  511. rc = -ENOSPC;
  512. goto out;
  513. }
  514. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  515. if (!debug)
  516. goto out;
  517. /* Round to page boundry */
  518. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  519. size = PAGE_ALIGN(size);
  520. debug->buffer = kmalloc(size, GFP_KERNEL);
  521. if (!debug->buffer) {
  522. kfree(debug);
  523. goto out;
  524. }
  525. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  526. file->private_data = debug;
  527. rc = 0;
  528. out:
  529. return rc;
  530. }
  531. static int
  532. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  533. {
  534. struct lpfc_hba *phba = inode->i_private;
  535. struct lpfc_debug *debug;
  536. int size;
  537. int rc = -ENOMEM;
  538. if (!lpfc_debugfs_max_slow_ring_trc) {
  539. rc = -ENOSPC;
  540. goto out;
  541. }
  542. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  543. if (!debug)
  544. goto out;
  545. /* Round to page boundry */
  546. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  547. size = PAGE_ALIGN(size);
  548. debug->buffer = kmalloc(size, GFP_KERNEL);
  549. if (!debug->buffer) {
  550. kfree(debug);
  551. goto out;
  552. }
  553. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  554. file->private_data = debug;
  555. rc = 0;
  556. out:
  557. return rc;
  558. }
  559. static int
  560. lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
  561. {
  562. struct lpfc_hba *phba = inode->i_private;
  563. struct lpfc_debug *debug;
  564. int rc = -ENOMEM;
  565. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  566. if (!debug)
  567. goto out;
  568. /* Round to page boundry */
  569. debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
  570. if (!debug->buffer) {
  571. kfree(debug);
  572. goto out;
  573. }
  574. debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
  575. LPFC_HBQINFO_SIZE);
  576. file->private_data = debug;
  577. rc = 0;
  578. out:
  579. return rc;
  580. }
  581. static int
  582. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  583. {
  584. struct lpfc_hba *phba = inode->i_private;
  585. struct lpfc_debug *debug;
  586. int rc = -ENOMEM;
  587. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  588. if (!debug)
  589. goto out;
  590. /* Round to page boundry */
  591. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  592. if (!debug->buffer) {
  593. kfree(debug);
  594. goto out;
  595. }
  596. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  597. LPFC_DUMPHBASLIM_SIZE);
  598. file->private_data = debug;
  599. rc = 0;
  600. out:
  601. return rc;
  602. }
  603. static int
  604. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  605. {
  606. struct lpfc_hba *phba = inode->i_private;
  607. struct lpfc_debug *debug;
  608. int rc = -ENOMEM;
  609. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  610. if (!debug)
  611. goto out;
  612. /* Round to page boundry */
  613. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  614. if (!debug->buffer) {
  615. kfree(debug);
  616. goto out;
  617. }
  618. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  619. LPFC_DUMPHOSTSLIM_SIZE);
  620. file->private_data = debug;
  621. rc = 0;
  622. out:
  623. return rc;
  624. }
  625. static int
  626. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  627. {
  628. struct lpfc_vport *vport = inode->i_private;
  629. struct lpfc_debug *debug;
  630. int rc = -ENOMEM;
  631. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  632. if (!debug)
  633. goto out;
  634. /* Round to page boundry */
  635. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  636. if (!debug->buffer) {
  637. kfree(debug);
  638. goto out;
  639. }
  640. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  641. LPFC_NODELIST_SIZE);
  642. file->private_data = debug;
  643. rc = 0;
  644. out:
  645. return rc;
  646. }
  647. static loff_t
  648. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  649. {
  650. struct lpfc_debug *debug;
  651. loff_t pos = -1;
  652. debug = file->private_data;
  653. switch (whence) {
  654. case 0:
  655. pos = off;
  656. break;
  657. case 1:
  658. pos = file->f_pos + off;
  659. break;
  660. case 2:
  661. pos = debug->len - off;
  662. }
  663. return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
  664. }
  665. static ssize_t
  666. lpfc_debugfs_read(struct file *file, char __user *buf,
  667. size_t nbytes, loff_t *ppos)
  668. {
  669. struct lpfc_debug *debug = file->private_data;
  670. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  671. debug->len);
  672. }
  673. static int
  674. lpfc_debugfs_release(struct inode *inode, struct file *file)
  675. {
  676. struct lpfc_debug *debug = file->private_data;
  677. kfree(debug->buffer);
  678. kfree(debug);
  679. return 0;
  680. }
  681. #undef lpfc_debugfs_op_disc_trc
  682. static struct file_operations lpfc_debugfs_op_disc_trc = {
  683. .owner = THIS_MODULE,
  684. .open = lpfc_debugfs_disc_trc_open,
  685. .llseek = lpfc_debugfs_lseek,
  686. .read = lpfc_debugfs_read,
  687. .release = lpfc_debugfs_release,
  688. };
  689. #undef lpfc_debugfs_op_nodelist
  690. static struct file_operations lpfc_debugfs_op_nodelist = {
  691. .owner = THIS_MODULE,
  692. .open = lpfc_debugfs_nodelist_open,
  693. .llseek = lpfc_debugfs_lseek,
  694. .read = lpfc_debugfs_read,
  695. .release = lpfc_debugfs_release,
  696. };
  697. #undef lpfc_debugfs_op_hbqinfo
  698. static struct file_operations lpfc_debugfs_op_hbqinfo = {
  699. .owner = THIS_MODULE,
  700. .open = lpfc_debugfs_hbqinfo_open,
  701. .llseek = lpfc_debugfs_lseek,
  702. .read = lpfc_debugfs_read,
  703. .release = lpfc_debugfs_release,
  704. };
  705. #undef lpfc_debugfs_op_dumpHBASlim
  706. static struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  707. .owner = THIS_MODULE,
  708. .open = lpfc_debugfs_dumpHBASlim_open,
  709. .llseek = lpfc_debugfs_lseek,
  710. .read = lpfc_debugfs_read,
  711. .release = lpfc_debugfs_release,
  712. };
  713. #undef lpfc_debugfs_op_dumpHostSlim
  714. static struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  715. .owner = THIS_MODULE,
  716. .open = lpfc_debugfs_dumpHostSlim_open,
  717. .llseek = lpfc_debugfs_lseek,
  718. .read = lpfc_debugfs_read,
  719. .release = lpfc_debugfs_release,
  720. };
  721. #undef lpfc_debugfs_op_slow_ring_trc
  722. static struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  723. .owner = THIS_MODULE,
  724. .open = lpfc_debugfs_slow_ring_trc_open,
  725. .llseek = lpfc_debugfs_lseek,
  726. .read = lpfc_debugfs_read,
  727. .release = lpfc_debugfs_release,
  728. };
  729. static struct dentry *lpfc_debugfs_root = NULL;
  730. static atomic_t lpfc_debugfs_hba_count;
  731. #endif
  732. inline void
  733. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  734. {
  735. #ifdef CONFIG_LPFC_DEBUG_FS
  736. struct lpfc_hba *phba = vport->phba;
  737. char name[64];
  738. uint32_t num, i;
  739. if (!lpfc_debugfs_enable)
  740. return;
  741. /* Setup lpfc root directory */
  742. if (!lpfc_debugfs_root) {
  743. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  744. atomic_set(&lpfc_debugfs_hba_count, 0);
  745. if (!lpfc_debugfs_root) {
  746. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  747. "0409 Cannot create debugfs root\n");
  748. goto debug_failed;
  749. }
  750. }
  751. if (!lpfc_debugfs_start_time)
  752. lpfc_debugfs_start_time = jiffies;
  753. /* Setup lpfcX directory for specific HBA */
  754. snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
  755. if (!phba->hba_debugfs_root) {
  756. phba->hba_debugfs_root =
  757. debugfs_create_dir(name, lpfc_debugfs_root);
  758. if (!phba->hba_debugfs_root) {
  759. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  760. "0409 Cannot create debugfs hba\n");
  761. goto debug_failed;
  762. }
  763. atomic_inc(&lpfc_debugfs_hba_count);
  764. atomic_set(&phba->debugfs_vport_count, 0);
  765. /* Setup hbqinfo */
  766. snprintf(name, sizeof(name), "hbqinfo");
  767. phba->debug_hbqinfo =
  768. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  769. phba->hba_debugfs_root,
  770. phba, &lpfc_debugfs_op_hbqinfo);
  771. if (!phba->debug_hbqinfo) {
  772. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  773. "0409 Cannot create debugfs hbqinfo\n");
  774. goto debug_failed;
  775. }
  776. /* Setup dumpHBASlim */
  777. snprintf(name, sizeof(name), "dumpHBASlim");
  778. phba->debug_dumpHBASlim =
  779. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  780. phba->hba_debugfs_root,
  781. phba, &lpfc_debugfs_op_dumpHBASlim);
  782. if (!phba->debug_dumpHBASlim) {
  783. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  784. "0409 Cannot create debugfs dumpHBASlim\n");
  785. goto debug_failed;
  786. }
  787. /* Setup dumpHostSlim */
  788. snprintf(name, sizeof(name), "dumpHostSlim");
  789. phba->debug_dumpHostSlim =
  790. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  791. phba->hba_debugfs_root,
  792. phba, &lpfc_debugfs_op_dumpHostSlim);
  793. if (!phba->debug_dumpHostSlim) {
  794. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  795. "0409 Cannot create debugfs dumpHostSlim\n");
  796. goto debug_failed;
  797. }
  798. /* Setup slow ring trace */
  799. if (lpfc_debugfs_max_slow_ring_trc) {
  800. num = lpfc_debugfs_max_slow_ring_trc - 1;
  801. if (num & lpfc_debugfs_max_slow_ring_trc) {
  802. /* Change to be a power of 2 */
  803. num = lpfc_debugfs_max_slow_ring_trc;
  804. i = 0;
  805. while (num > 1) {
  806. num = num >> 1;
  807. i++;
  808. }
  809. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  810. printk(KERN_ERR
  811. "lpfc_debugfs_max_disc_trc changed to "
  812. "%d\n", lpfc_debugfs_max_disc_trc);
  813. }
  814. }
  815. snprintf(name, sizeof(name), "slow_ring_trace");
  816. phba->debug_slow_ring_trc =
  817. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  818. phba->hba_debugfs_root,
  819. phba, &lpfc_debugfs_op_slow_ring_trc);
  820. if (!phba->debug_slow_ring_trc) {
  821. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  822. "0409 Cannot create debugfs "
  823. "slow_ring_trace\n");
  824. goto debug_failed;
  825. }
  826. if (!phba->slow_ring_trc) {
  827. phba->slow_ring_trc = kmalloc(
  828. (sizeof(struct lpfc_debugfs_trc) *
  829. lpfc_debugfs_max_slow_ring_trc),
  830. GFP_KERNEL);
  831. if (!phba->slow_ring_trc) {
  832. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  833. "0409 Cannot create debugfs "
  834. "slow_ring buffer\n");
  835. goto debug_failed;
  836. }
  837. atomic_set(&phba->slow_ring_trc_cnt, 0);
  838. memset(phba->slow_ring_trc, 0,
  839. (sizeof(struct lpfc_debugfs_trc) *
  840. lpfc_debugfs_max_slow_ring_trc));
  841. }
  842. }
  843. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  844. if (!vport->vport_debugfs_root) {
  845. vport->vport_debugfs_root =
  846. debugfs_create_dir(name, phba->hba_debugfs_root);
  847. if (!vport->vport_debugfs_root) {
  848. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  849. "0409 Cant create debugfs");
  850. goto debug_failed;
  851. }
  852. atomic_inc(&phba->debugfs_vport_count);
  853. }
  854. if (lpfc_debugfs_max_disc_trc) {
  855. num = lpfc_debugfs_max_disc_trc - 1;
  856. if (num & lpfc_debugfs_max_disc_trc) {
  857. /* Change to be a power of 2 */
  858. num = lpfc_debugfs_max_disc_trc;
  859. i = 0;
  860. while (num > 1) {
  861. num = num >> 1;
  862. i++;
  863. }
  864. lpfc_debugfs_max_disc_trc = (1 << i);
  865. printk(KERN_ERR
  866. "lpfc_debugfs_max_disc_trc changed to %d\n",
  867. lpfc_debugfs_max_disc_trc);
  868. }
  869. }
  870. vport->disc_trc = kzalloc(
  871. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  872. GFP_KERNEL);
  873. if (!vport->disc_trc) {
  874. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  875. "0409 Cannot create debugfs disc trace "
  876. "buffer\n");
  877. goto debug_failed;
  878. }
  879. atomic_set(&vport->disc_trc_cnt, 0);
  880. snprintf(name, sizeof(name), "discovery_trace");
  881. vport->debug_disc_trc =
  882. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  883. vport->vport_debugfs_root,
  884. vport, &lpfc_debugfs_op_disc_trc);
  885. if (!vport->debug_disc_trc) {
  886. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  887. "0409 Cannot create debugfs "
  888. "discovery_trace\n");
  889. goto debug_failed;
  890. }
  891. snprintf(name, sizeof(name), "nodelist");
  892. vport->debug_nodelist =
  893. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  894. vport->vport_debugfs_root,
  895. vport, &lpfc_debugfs_op_nodelist);
  896. if (!vport->debug_nodelist) {
  897. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  898. "0409 Cant create debugfs nodelist");
  899. goto debug_failed;
  900. }
  901. debug_failed:
  902. return;
  903. #endif
  904. }
  905. inline void
  906. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  907. {
  908. #ifdef CONFIG_LPFC_DEBUG_FS
  909. struct lpfc_hba *phba = vport->phba;
  910. if (vport->disc_trc) {
  911. kfree(vport->disc_trc);
  912. vport->disc_trc = NULL;
  913. }
  914. if (vport->debug_disc_trc) {
  915. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  916. vport->debug_disc_trc = NULL;
  917. }
  918. if (vport->debug_nodelist) {
  919. debugfs_remove(vport->debug_nodelist); /* nodelist */
  920. vport->debug_nodelist = NULL;
  921. }
  922. if (vport->vport_debugfs_root) {
  923. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  924. vport->vport_debugfs_root = NULL;
  925. atomic_dec(&phba->debugfs_vport_count);
  926. }
  927. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  928. if (phba->debug_hbqinfo) {
  929. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  930. phba->debug_hbqinfo = NULL;
  931. }
  932. if (phba->debug_dumpHBASlim) {
  933. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  934. phba->debug_dumpHBASlim = NULL;
  935. }
  936. if (phba->debug_dumpHostSlim) {
  937. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  938. phba->debug_dumpHostSlim = NULL;
  939. }
  940. if (phba->slow_ring_trc) {
  941. kfree(phba->slow_ring_trc);
  942. phba->slow_ring_trc = NULL;
  943. }
  944. if (phba->debug_slow_ring_trc) {
  945. /* slow_ring_trace */
  946. debugfs_remove(phba->debug_slow_ring_trc);
  947. phba->debug_slow_ring_trc = NULL;
  948. }
  949. if (phba->hba_debugfs_root) {
  950. debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
  951. phba->hba_debugfs_root = NULL;
  952. atomic_dec(&lpfc_debugfs_hba_count);
  953. }
  954. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  955. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  956. lpfc_debugfs_root = NULL;
  957. }
  958. }
  959. #endif
  960. return;
  961. }