lpfc_debugfs.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  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, "usgmap:%x ",
  449. ndlp->nlp_usg_map);
  450. len += snprintf(buf+len, size-len, "refcnt:%x",
  451. atomic_read(&ndlp->kref.refcount));
  452. len += snprintf(buf+len, size-len, "\n");
  453. }
  454. spin_unlock_irq(shost->host_lock);
  455. return len;
  456. }
  457. #endif
  458. inline void
  459. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  460. uint32_t data1, uint32_t data2, uint32_t data3)
  461. {
  462. #ifdef CONFIG_LPFC_DEBUG_FS
  463. struct lpfc_debugfs_trc *dtp;
  464. int index;
  465. if (!(lpfc_debugfs_mask_disc_trc & mask))
  466. return;
  467. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  468. !vport || !vport->disc_trc)
  469. return;
  470. index = atomic_inc_return(&vport->disc_trc_cnt) &
  471. (lpfc_debugfs_max_disc_trc - 1);
  472. dtp = vport->disc_trc + index;
  473. dtp->fmt = fmt;
  474. dtp->data1 = data1;
  475. dtp->data2 = data2;
  476. dtp->data3 = data3;
  477. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  478. dtp->jif = jiffies;
  479. #endif
  480. return;
  481. }
  482. inline void
  483. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  484. uint32_t data1, uint32_t data2, uint32_t data3)
  485. {
  486. #ifdef CONFIG_LPFC_DEBUG_FS
  487. struct lpfc_debugfs_trc *dtp;
  488. int index;
  489. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  490. !phba || !phba->slow_ring_trc)
  491. return;
  492. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  493. (lpfc_debugfs_max_slow_ring_trc - 1);
  494. dtp = phba->slow_ring_trc + index;
  495. dtp->fmt = fmt;
  496. dtp->data1 = data1;
  497. dtp->data2 = data2;
  498. dtp->data3 = data3;
  499. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  500. dtp->jif = jiffies;
  501. #endif
  502. return;
  503. }
  504. #ifdef CONFIG_LPFC_DEBUG_FS
  505. static int
  506. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  507. {
  508. struct lpfc_vport *vport = inode->i_private;
  509. struct lpfc_debug *debug;
  510. int size;
  511. int rc = -ENOMEM;
  512. if (!lpfc_debugfs_max_disc_trc) {
  513. rc = -ENOSPC;
  514. goto out;
  515. }
  516. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  517. if (!debug)
  518. goto out;
  519. /* Round to page boundry */
  520. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  521. size = PAGE_ALIGN(size);
  522. debug->buffer = kmalloc(size, GFP_KERNEL);
  523. if (!debug->buffer) {
  524. kfree(debug);
  525. goto out;
  526. }
  527. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  528. file->private_data = debug;
  529. rc = 0;
  530. out:
  531. return rc;
  532. }
  533. static int
  534. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  535. {
  536. struct lpfc_hba *phba = inode->i_private;
  537. struct lpfc_debug *debug;
  538. int size;
  539. int rc = -ENOMEM;
  540. if (!lpfc_debugfs_max_slow_ring_trc) {
  541. rc = -ENOSPC;
  542. goto out;
  543. }
  544. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  545. if (!debug)
  546. goto out;
  547. /* Round to page boundry */
  548. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  549. size = PAGE_ALIGN(size);
  550. debug->buffer = kmalloc(size, GFP_KERNEL);
  551. if (!debug->buffer) {
  552. kfree(debug);
  553. goto out;
  554. }
  555. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  556. file->private_data = debug;
  557. rc = 0;
  558. out:
  559. return rc;
  560. }
  561. static int
  562. lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
  563. {
  564. struct lpfc_hba *phba = inode->i_private;
  565. struct lpfc_debug *debug;
  566. int rc = -ENOMEM;
  567. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  568. if (!debug)
  569. goto out;
  570. /* Round to page boundry */
  571. debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
  572. if (!debug->buffer) {
  573. kfree(debug);
  574. goto out;
  575. }
  576. debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
  577. LPFC_HBQINFO_SIZE);
  578. file->private_data = debug;
  579. rc = 0;
  580. out:
  581. return rc;
  582. }
  583. static int
  584. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  585. {
  586. struct lpfc_hba *phba = inode->i_private;
  587. struct lpfc_debug *debug;
  588. int rc = -ENOMEM;
  589. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  590. if (!debug)
  591. goto out;
  592. /* Round to page boundry */
  593. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  594. if (!debug->buffer) {
  595. kfree(debug);
  596. goto out;
  597. }
  598. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  599. LPFC_DUMPHBASLIM_SIZE);
  600. file->private_data = debug;
  601. rc = 0;
  602. out:
  603. return rc;
  604. }
  605. static int
  606. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  607. {
  608. struct lpfc_hba *phba = inode->i_private;
  609. struct lpfc_debug *debug;
  610. int rc = -ENOMEM;
  611. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  612. if (!debug)
  613. goto out;
  614. /* Round to page boundry */
  615. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  616. if (!debug->buffer) {
  617. kfree(debug);
  618. goto out;
  619. }
  620. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  621. LPFC_DUMPHOSTSLIM_SIZE);
  622. file->private_data = debug;
  623. rc = 0;
  624. out:
  625. return rc;
  626. }
  627. static int
  628. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  629. {
  630. struct lpfc_vport *vport = inode->i_private;
  631. struct lpfc_debug *debug;
  632. int rc = -ENOMEM;
  633. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  634. if (!debug)
  635. goto out;
  636. /* Round to page boundry */
  637. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  638. if (!debug->buffer) {
  639. kfree(debug);
  640. goto out;
  641. }
  642. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  643. LPFC_NODELIST_SIZE);
  644. file->private_data = debug;
  645. rc = 0;
  646. out:
  647. return rc;
  648. }
  649. static loff_t
  650. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  651. {
  652. struct lpfc_debug *debug;
  653. loff_t pos = -1;
  654. debug = file->private_data;
  655. switch (whence) {
  656. case 0:
  657. pos = off;
  658. break;
  659. case 1:
  660. pos = file->f_pos + off;
  661. break;
  662. case 2:
  663. pos = debug->len - off;
  664. }
  665. return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
  666. }
  667. static ssize_t
  668. lpfc_debugfs_read(struct file *file, char __user *buf,
  669. size_t nbytes, loff_t *ppos)
  670. {
  671. struct lpfc_debug *debug = file->private_data;
  672. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  673. debug->len);
  674. }
  675. static int
  676. lpfc_debugfs_release(struct inode *inode, struct file *file)
  677. {
  678. struct lpfc_debug *debug = file->private_data;
  679. kfree(debug->buffer);
  680. kfree(debug);
  681. return 0;
  682. }
  683. #undef lpfc_debugfs_op_disc_trc
  684. static struct file_operations lpfc_debugfs_op_disc_trc = {
  685. .owner = THIS_MODULE,
  686. .open = lpfc_debugfs_disc_trc_open,
  687. .llseek = lpfc_debugfs_lseek,
  688. .read = lpfc_debugfs_read,
  689. .release = lpfc_debugfs_release,
  690. };
  691. #undef lpfc_debugfs_op_nodelist
  692. static struct file_operations lpfc_debugfs_op_nodelist = {
  693. .owner = THIS_MODULE,
  694. .open = lpfc_debugfs_nodelist_open,
  695. .llseek = lpfc_debugfs_lseek,
  696. .read = lpfc_debugfs_read,
  697. .release = lpfc_debugfs_release,
  698. };
  699. #undef lpfc_debugfs_op_hbqinfo
  700. static struct file_operations lpfc_debugfs_op_hbqinfo = {
  701. .owner = THIS_MODULE,
  702. .open = lpfc_debugfs_hbqinfo_open,
  703. .llseek = lpfc_debugfs_lseek,
  704. .read = lpfc_debugfs_read,
  705. .release = lpfc_debugfs_release,
  706. };
  707. #undef lpfc_debugfs_op_dumpHBASlim
  708. static struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  709. .owner = THIS_MODULE,
  710. .open = lpfc_debugfs_dumpHBASlim_open,
  711. .llseek = lpfc_debugfs_lseek,
  712. .read = lpfc_debugfs_read,
  713. .release = lpfc_debugfs_release,
  714. };
  715. #undef lpfc_debugfs_op_dumpHostSlim
  716. static struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  717. .owner = THIS_MODULE,
  718. .open = lpfc_debugfs_dumpHostSlim_open,
  719. .llseek = lpfc_debugfs_lseek,
  720. .read = lpfc_debugfs_read,
  721. .release = lpfc_debugfs_release,
  722. };
  723. #undef lpfc_debugfs_op_slow_ring_trc
  724. static struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  725. .owner = THIS_MODULE,
  726. .open = lpfc_debugfs_slow_ring_trc_open,
  727. .llseek = lpfc_debugfs_lseek,
  728. .read = lpfc_debugfs_read,
  729. .release = lpfc_debugfs_release,
  730. };
  731. static struct dentry *lpfc_debugfs_root = NULL;
  732. static atomic_t lpfc_debugfs_hba_count;
  733. #endif
  734. inline void
  735. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  736. {
  737. #ifdef CONFIG_LPFC_DEBUG_FS
  738. struct lpfc_hba *phba = vport->phba;
  739. char name[64];
  740. uint32_t num, i;
  741. if (!lpfc_debugfs_enable)
  742. return;
  743. /* Setup lpfc root directory */
  744. if (!lpfc_debugfs_root) {
  745. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  746. atomic_set(&lpfc_debugfs_hba_count, 0);
  747. if (!lpfc_debugfs_root) {
  748. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  749. "0409 Cannot create debugfs root\n");
  750. goto debug_failed;
  751. }
  752. }
  753. if (!lpfc_debugfs_start_time)
  754. lpfc_debugfs_start_time = jiffies;
  755. /* Setup lpfcX directory for specific HBA */
  756. snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
  757. if (!phba->hba_debugfs_root) {
  758. phba->hba_debugfs_root =
  759. debugfs_create_dir(name, lpfc_debugfs_root);
  760. if (!phba->hba_debugfs_root) {
  761. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  762. "0409 Cannot create debugfs hba\n");
  763. goto debug_failed;
  764. }
  765. atomic_inc(&lpfc_debugfs_hba_count);
  766. atomic_set(&phba->debugfs_vport_count, 0);
  767. /* Setup hbqinfo */
  768. snprintf(name, sizeof(name), "hbqinfo");
  769. phba->debug_hbqinfo =
  770. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  771. phba->hba_debugfs_root,
  772. phba, &lpfc_debugfs_op_hbqinfo);
  773. if (!phba->debug_hbqinfo) {
  774. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  775. "0409 Cannot create debugfs hbqinfo\n");
  776. goto debug_failed;
  777. }
  778. /* Setup dumpHBASlim */
  779. snprintf(name, sizeof(name), "dumpHBASlim");
  780. phba->debug_dumpHBASlim =
  781. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  782. phba->hba_debugfs_root,
  783. phba, &lpfc_debugfs_op_dumpHBASlim);
  784. if (!phba->debug_dumpHBASlim) {
  785. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  786. "0409 Cannot create debugfs dumpHBASlim\n");
  787. goto debug_failed;
  788. }
  789. /* Setup dumpHostSlim */
  790. snprintf(name, sizeof(name), "dumpHostSlim");
  791. phba->debug_dumpHostSlim =
  792. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  793. phba->hba_debugfs_root,
  794. phba, &lpfc_debugfs_op_dumpHostSlim);
  795. if (!phba->debug_dumpHostSlim) {
  796. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  797. "0409 Cannot create debugfs dumpHostSlim\n");
  798. goto debug_failed;
  799. }
  800. /* Setup slow ring trace */
  801. if (lpfc_debugfs_max_slow_ring_trc) {
  802. num = lpfc_debugfs_max_slow_ring_trc - 1;
  803. if (num & lpfc_debugfs_max_slow_ring_trc) {
  804. /* Change to be a power of 2 */
  805. num = lpfc_debugfs_max_slow_ring_trc;
  806. i = 0;
  807. while (num > 1) {
  808. num = num >> 1;
  809. i++;
  810. }
  811. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  812. printk(KERN_ERR
  813. "lpfc_debugfs_max_disc_trc changed to "
  814. "%d\n", lpfc_debugfs_max_disc_trc);
  815. }
  816. }
  817. snprintf(name, sizeof(name), "slow_ring_trace");
  818. phba->debug_slow_ring_trc =
  819. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  820. phba->hba_debugfs_root,
  821. phba, &lpfc_debugfs_op_slow_ring_trc);
  822. if (!phba->debug_slow_ring_trc) {
  823. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  824. "0409 Cannot create debugfs "
  825. "slow_ring_trace\n");
  826. goto debug_failed;
  827. }
  828. if (!phba->slow_ring_trc) {
  829. phba->slow_ring_trc = kmalloc(
  830. (sizeof(struct lpfc_debugfs_trc) *
  831. lpfc_debugfs_max_slow_ring_trc),
  832. GFP_KERNEL);
  833. if (!phba->slow_ring_trc) {
  834. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  835. "0409 Cannot create debugfs "
  836. "slow_ring buffer\n");
  837. goto debug_failed;
  838. }
  839. atomic_set(&phba->slow_ring_trc_cnt, 0);
  840. memset(phba->slow_ring_trc, 0,
  841. (sizeof(struct lpfc_debugfs_trc) *
  842. lpfc_debugfs_max_slow_ring_trc));
  843. }
  844. }
  845. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  846. if (!vport->vport_debugfs_root) {
  847. vport->vport_debugfs_root =
  848. debugfs_create_dir(name, phba->hba_debugfs_root);
  849. if (!vport->vport_debugfs_root) {
  850. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  851. "0409 Cant create debugfs");
  852. goto debug_failed;
  853. }
  854. atomic_inc(&phba->debugfs_vport_count);
  855. }
  856. if (lpfc_debugfs_max_disc_trc) {
  857. num = lpfc_debugfs_max_disc_trc - 1;
  858. if (num & lpfc_debugfs_max_disc_trc) {
  859. /* Change to be a power of 2 */
  860. num = lpfc_debugfs_max_disc_trc;
  861. i = 0;
  862. while (num > 1) {
  863. num = num >> 1;
  864. i++;
  865. }
  866. lpfc_debugfs_max_disc_trc = (1 << i);
  867. printk(KERN_ERR
  868. "lpfc_debugfs_max_disc_trc changed to %d\n",
  869. lpfc_debugfs_max_disc_trc);
  870. }
  871. }
  872. vport->disc_trc = kzalloc(
  873. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  874. GFP_KERNEL);
  875. if (!vport->disc_trc) {
  876. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  877. "0409 Cannot create debugfs disc trace "
  878. "buffer\n");
  879. goto debug_failed;
  880. }
  881. atomic_set(&vport->disc_trc_cnt, 0);
  882. snprintf(name, sizeof(name), "discovery_trace");
  883. vport->debug_disc_trc =
  884. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  885. vport->vport_debugfs_root,
  886. vport, &lpfc_debugfs_op_disc_trc);
  887. if (!vport->debug_disc_trc) {
  888. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  889. "0409 Cannot create debugfs "
  890. "discovery_trace\n");
  891. goto debug_failed;
  892. }
  893. snprintf(name, sizeof(name), "nodelist");
  894. vport->debug_nodelist =
  895. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  896. vport->vport_debugfs_root,
  897. vport, &lpfc_debugfs_op_nodelist);
  898. if (!vport->debug_nodelist) {
  899. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  900. "0409 Cant create debugfs nodelist");
  901. goto debug_failed;
  902. }
  903. debug_failed:
  904. return;
  905. #endif
  906. }
  907. inline void
  908. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  909. {
  910. #ifdef CONFIG_LPFC_DEBUG_FS
  911. struct lpfc_hba *phba = vport->phba;
  912. if (vport->disc_trc) {
  913. kfree(vport->disc_trc);
  914. vport->disc_trc = NULL;
  915. }
  916. if (vport->debug_disc_trc) {
  917. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  918. vport->debug_disc_trc = NULL;
  919. }
  920. if (vport->debug_nodelist) {
  921. debugfs_remove(vport->debug_nodelist); /* nodelist */
  922. vport->debug_nodelist = NULL;
  923. }
  924. if (vport->vport_debugfs_root) {
  925. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  926. vport->vport_debugfs_root = NULL;
  927. atomic_dec(&phba->debugfs_vport_count);
  928. }
  929. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  930. if (phba->debug_hbqinfo) {
  931. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  932. phba->debug_hbqinfo = NULL;
  933. }
  934. if (phba->debug_dumpHBASlim) {
  935. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  936. phba->debug_dumpHBASlim = NULL;
  937. }
  938. if (phba->debug_dumpHostSlim) {
  939. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  940. phba->debug_dumpHostSlim = NULL;
  941. }
  942. if (phba->slow_ring_trc) {
  943. kfree(phba->slow_ring_trc);
  944. phba->slow_ring_trc = NULL;
  945. }
  946. if (phba->debug_slow_ring_trc) {
  947. /* slow_ring_trace */
  948. debugfs_remove(phba->debug_slow_ring_trc);
  949. phba->debug_slow_ring_trc = NULL;
  950. }
  951. if (phba->hba_debugfs_root) {
  952. debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
  953. phba->hba_debugfs_root = NULL;
  954. atomic_dec(&lpfc_debugfs_hba_count);
  955. }
  956. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  957. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  958. lpfc_debugfs_root = NULL;
  959. }
  960. }
  961. #endif
  962. return;
  963. }