lpfc_debugfs.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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_vport.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 = 0;
  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 = 0;
  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 = 0;
  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. static int lpfc_debugfs_mask_disc_trc = 0;
  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. /* dump_slim output buffer size */
  94. #define LPFC_DUMPSLIM_SIZE 4096
  95. struct lpfc_debug {
  96. char *buffer;
  97. int len;
  98. };
  99. atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  100. unsigned long lpfc_debugfs_start_time = 0L;
  101. static int
  102. lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
  103. {
  104. int i, index, len, enable;
  105. uint32_t ms;
  106. struct lpfc_debugfs_trc *dtp;
  107. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  108. enable = lpfc_debugfs_enable;
  109. lpfc_debugfs_enable = 0;
  110. len = 0;
  111. index = (atomic_read(&vport->disc_trc_cnt) + 1) &
  112. (lpfc_debugfs_max_disc_trc - 1);
  113. for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
  114. dtp = vport->disc_trc + i;
  115. if (!dtp->fmt)
  116. continue;
  117. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  118. snprintf(buffer,
  119. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  120. dtp->seq_cnt, ms, dtp->fmt);
  121. len += snprintf(buf+len, size-len, buffer,
  122. dtp->data1, dtp->data2, dtp->data3);
  123. }
  124. for (i = 0; i < index; i++) {
  125. dtp = vport->disc_trc + i;
  126. if (!dtp->fmt)
  127. continue;
  128. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  129. snprintf(buffer,
  130. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  131. dtp->seq_cnt, ms, dtp->fmt);
  132. len += snprintf(buf+len, size-len, buffer,
  133. dtp->data1, dtp->data2, dtp->data3);
  134. }
  135. lpfc_debugfs_enable = enable;
  136. return len;
  137. }
  138. static int
  139. lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
  140. {
  141. int i, index, len, enable;
  142. uint32_t ms;
  143. struct lpfc_debugfs_trc *dtp;
  144. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  145. enable = lpfc_debugfs_enable;
  146. lpfc_debugfs_enable = 0;
  147. len = 0;
  148. index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
  149. (lpfc_debugfs_max_slow_ring_trc - 1);
  150. for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
  151. dtp = phba->slow_ring_trc + i;
  152. if (!dtp->fmt)
  153. continue;
  154. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  155. snprintf(buffer,
  156. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  157. dtp->seq_cnt, ms, dtp->fmt);
  158. len += snprintf(buf+len, size-len, buffer,
  159. dtp->data1, dtp->data2, dtp->data3);
  160. }
  161. for (i = 0; i < index; i++) {
  162. dtp = phba->slow_ring_trc + i;
  163. if (!dtp->fmt)
  164. continue;
  165. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  166. snprintf(buffer,
  167. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  168. dtp->seq_cnt, ms, dtp->fmt);
  169. len += snprintf(buf+len, size-len, buffer,
  170. dtp->data1, dtp->data2, dtp->data3);
  171. }
  172. lpfc_debugfs_enable = enable;
  173. return len;
  174. }
  175. static int
  176. lpfc_debugfs_dumpslim_data(struct lpfc_hba *phba, char *buf, int size)
  177. {
  178. int len = 0;
  179. int cnt, i, off;
  180. uint32_t word0, word1, word2, word3;
  181. uint32_t *ptr;
  182. struct lpfc_pgp *pgpp;
  183. struct lpfc_sli *psli = &phba->sli;
  184. struct lpfc_sli_ring *pring;
  185. cnt = LPFC_DUMPSLIM_SIZE;
  186. off = 0;
  187. spin_lock_irq(&phba->hbalock);
  188. len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
  189. ptr = (uint32_t *)phba->slim2p;
  190. i = sizeof(MAILBOX_t);
  191. while (i > 0) {
  192. len += snprintf(buf+len, size-len,
  193. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  194. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  195. *(ptr+5), *(ptr+6), *(ptr+7));
  196. ptr += 8;
  197. i -= (8 * sizeof(uint32_t));
  198. off += (8 * sizeof(uint32_t));
  199. }
  200. len += snprintf(buf+len, size-len, "SLIM PCB\n");
  201. ptr = (uint32_t *)&phba->slim2p->pcb;
  202. i = sizeof(PCB_t);
  203. while (i > 0) {
  204. len += snprintf(buf+len, size-len,
  205. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  206. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  207. *(ptr+5), *(ptr+6), *(ptr+7));
  208. ptr += 8;
  209. i -= (8 * sizeof(uint32_t));
  210. off += (8 * sizeof(uint32_t));
  211. }
  212. pgpp = (struct lpfc_pgp *)&phba->slim2p->mbx.us.s3_pgp.port;
  213. pring = &psli->ring[0];
  214. len += snprintf(buf+len, size-len,
  215. "Ring 0: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  216. "RSP PutInx:%d Max:%d\n",
  217. pgpp->cmdGetInx, pring->numCiocb,
  218. pring->next_cmdidx, pring->local_getidx, pring->flag,
  219. pgpp->rspPutInx, pring->numRiocb);
  220. pgpp++;
  221. pring = &psli->ring[1];
  222. len += snprintf(buf+len, size-len,
  223. "Ring 1: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  224. "RSP PutInx:%d Max:%d\n",
  225. pgpp->cmdGetInx, pring->numCiocb,
  226. pring->next_cmdidx, pring->local_getidx, pring->flag,
  227. pgpp->rspPutInx, pring->numRiocb);
  228. pgpp++;
  229. pring = &psli->ring[2];
  230. len += snprintf(buf+len, size-len,
  231. "Ring 2: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  232. "RSP PutInx:%d Max:%d\n",
  233. pgpp->cmdGetInx, pring->numCiocb,
  234. pring->next_cmdidx, pring->local_getidx, pring->flag,
  235. pgpp->rspPutInx, pring->numRiocb);
  236. pgpp++;
  237. pring = &psli->ring[3];
  238. len += snprintf(buf+len, size-len,
  239. "Ring 3: CMD GetInx:%d (Max:%d Next:%d Local:%d flg:x%x) "
  240. "RSP PutInx:%d Max:%d\n",
  241. pgpp->cmdGetInx, pring->numCiocb,
  242. pring->next_cmdidx, pring->local_getidx, pring->flag,
  243. pgpp->rspPutInx, pring->numRiocb);
  244. ptr = (uint32_t *)&phba->slim2p->mbx.us.s3_pgp.hbq_get;
  245. word0 = readl(phba->HAregaddr);
  246. word1 = readl(phba->CAregaddr);
  247. word2 = readl(phba->HSregaddr);
  248. word3 = readl(phba->HCregaddr);
  249. len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x HC:%08x\n",
  250. word0, word1, word2, word3);
  251. spin_unlock_irq(&phba->hbalock);
  252. return len;
  253. }
  254. static int
  255. lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
  256. {
  257. int len = 0;
  258. int cnt;
  259. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  260. struct lpfc_nodelist *ndlp;
  261. unsigned char *statep, *name;
  262. cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
  263. spin_lock_irq(shost->host_lock);
  264. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  265. if (!cnt) {
  266. len += snprintf(buf+len, size-len,
  267. "Missing Nodelist Entries\n");
  268. break;
  269. }
  270. cnt--;
  271. switch (ndlp->nlp_state) {
  272. case NLP_STE_UNUSED_NODE:
  273. statep = "UNUSED";
  274. break;
  275. case NLP_STE_PLOGI_ISSUE:
  276. statep = "PLOGI ";
  277. break;
  278. case NLP_STE_ADISC_ISSUE:
  279. statep = "ADISC ";
  280. break;
  281. case NLP_STE_REG_LOGIN_ISSUE:
  282. statep = "REGLOG";
  283. break;
  284. case NLP_STE_PRLI_ISSUE:
  285. statep = "PRLI ";
  286. break;
  287. case NLP_STE_UNMAPPED_NODE:
  288. statep = "UNMAP ";
  289. break;
  290. case NLP_STE_MAPPED_NODE:
  291. statep = "MAPPED";
  292. break;
  293. case NLP_STE_NPR_NODE:
  294. statep = "NPR ";
  295. break;
  296. default:
  297. statep = "UNKNOWN";
  298. }
  299. len += snprintf(buf+len, size-len, "%s DID:x%06x ",
  300. statep, ndlp->nlp_DID);
  301. name = (unsigned char *)&ndlp->nlp_portname;
  302. len += snprintf(buf+len, size-len,
  303. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  304. *name, *(name+1), *(name+2), *(name+3),
  305. *(name+4), *(name+5), *(name+6), *(name+7));
  306. name = (unsigned char *)&ndlp->nlp_nodename;
  307. len += snprintf(buf+len, size-len,
  308. "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  309. *name, *(name+1), *(name+2), *(name+3),
  310. *(name+4), *(name+5), *(name+6), *(name+7));
  311. len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
  312. ndlp->nlp_rpi, ndlp->nlp_flag);
  313. if (!ndlp->nlp_type)
  314. len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
  315. if (ndlp->nlp_type & NLP_FC_NODE)
  316. len += snprintf(buf+len, size-len, "FC_NODE ");
  317. if (ndlp->nlp_type & NLP_FABRIC)
  318. len += snprintf(buf+len, size-len, "FABRIC ");
  319. if (ndlp->nlp_type & NLP_FCP_TARGET)
  320. len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
  321. ndlp->nlp_sid);
  322. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  323. len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
  324. len += snprintf(buf+len, size-len, "refcnt:%x",
  325. atomic_read(&ndlp->kref.refcount));
  326. len += snprintf(buf+len, size-len, "\n");
  327. }
  328. spin_unlock_irq(shost->host_lock);
  329. return len;
  330. }
  331. #endif
  332. inline void
  333. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  334. uint32_t data1, uint32_t data2, uint32_t data3)
  335. {
  336. #ifdef CONFIG_LPFC_DEBUG_FS
  337. struct lpfc_debugfs_trc *dtp;
  338. int index;
  339. if (!(lpfc_debugfs_mask_disc_trc & mask))
  340. return;
  341. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  342. !vport || !vport->disc_trc)
  343. return;
  344. index = atomic_inc_return(&vport->disc_trc_cnt) &
  345. (lpfc_debugfs_max_disc_trc - 1);
  346. dtp = vport->disc_trc + index;
  347. dtp->fmt = fmt;
  348. dtp->data1 = data1;
  349. dtp->data2 = data2;
  350. dtp->data3 = data3;
  351. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  352. dtp->jif = jiffies;
  353. #endif
  354. return;
  355. }
  356. inline void
  357. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  358. uint32_t data1, uint32_t data2, uint32_t data3)
  359. {
  360. #ifdef CONFIG_LPFC_DEBUG_FS
  361. struct lpfc_debugfs_trc *dtp;
  362. int index;
  363. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  364. !phba || !phba->slow_ring_trc)
  365. return;
  366. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  367. (lpfc_debugfs_max_slow_ring_trc - 1);
  368. dtp = phba->slow_ring_trc + index;
  369. dtp->fmt = fmt;
  370. dtp->data1 = data1;
  371. dtp->data2 = data2;
  372. dtp->data3 = data3;
  373. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  374. dtp->jif = jiffies;
  375. #endif
  376. return;
  377. }
  378. #ifdef CONFIG_LPFC_DEBUG_FS
  379. static int
  380. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  381. {
  382. struct lpfc_vport *vport = inode->i_private;
  383. struct lpfc_debug *debug;
  384. int size;
  385. int rc = -ENOMEM;
  386. if (!lpfc_debugfs_max_disc_trc) {
  387. rc = -ENOSPC;
  388. goto out;
  389. }
  390. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  391. if (!debug)
  392. goto out;
  393. /* Round to page boundry */
  394. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  395. size = PAGE_ALIGN(size);
  396. debug->buffer = kmalloc(size, GFP_KERNEL);
  397. if (!debug->buffer) {
  398. kfree(debug);
  399. goto out;
  400. }
  401. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  402. file->private_data = debug;
  403. rc = 0;
  404. out:
  405. return rc;
  406. }
  407. static int
  408. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  409. {
  410. struct lpfc_hba *phba = inode->i_private;
  411. struct lpfc_debug *debug;
  412. int size;
  413. int rc = -ENOMEM;
  414. if (!lpfc_debugfs_max_slow_ring_trc) {
  415. rc = -ENOSPC;
  416. goto out;
  417. }
  418. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  419. if (!debug)
  420. goto out;
  421. /* Round to page boundry */
  422. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  423. size = PAGE_ALIGN(size);
  424. debug->buffer = kmalloc(size, GFP_KERNEL);
  425. if (!debug->buffer) {
  426. kfree(debug);
  427. goto out;
  428. }
  429. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  430. file->private_data = debug;
  431. rc = 0;
  432. out:
  433. return rc;
  434. }
  435. static int
  436. lpfc_debugfs_dumpslim_open(struct inode *inode, struct file *file)
  437. {
  438. struct lpfc_hba *phba = inode->i_private;
  439. struct lpfc_debug *debug;
  440. int rc = -ENOMEM;
  441. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  442. if (!debug)
  443. goto out;
  444. /* Round to page boundry */
  445. debug->buffer = kmalloc(LPFC_DUMPSLIM_SIZE, GFP_KERNEL);
  446. if (!debug->buffer) {
  447. kfree(debug);
  448. goto out;
  449. }
  450. debug->len = lpfc_debugfs_dumpslim_data(phba, debug->buffer,
  451. LPFC_DUMPSLIM_SIZE);
  452. file->private_data = debug;
  453. rc = 0;
  454. out:
  455. return rc;
  456. }
  457. static int
  458. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  459. {
  460. struct lpfc_vport *vport = inode->i_private;
  461. struct lpfc_debug *debug;
  462. int rc = -ENOMEM;
  463. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  464. if (!debug)
  465. goto out;
  466. /* Round to page boundry */
  467. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  468. if (!debug->buffer) {
  469. kfree(debug);
  470. goto out;
  471. }
  472. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  473. LPFC_NODELIST_SIZE);
  474. file->private_data = debug;
  475. rc = 0;
  476. out:
  477. return rc;
  478. }
  479. static loff_t
  480. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  481. {
  482. struct lpfc_debug *debug;
  483. loff_t pos = -1;
  484. debug = file->private_data;
  485. switch (whence) {
  486. case 0:
  487. pos = off;
  488. break;
  489. case 1:
  490. pos = file->f_pos + off;
  491. break;
  492. case 2:
  493. pos = debug->len - off;
  494. }
  495. return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
  496. }
  497. static ssize_t
  498. lpfc_debugfs_read(struct file *file, char __user *buf,
  499. size_t nbytes, loff_t *ppos)
  500. {
  501. struct lpfc_debug *debug = file->private_data;
  502. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  503. debug->len);
  504. }
  505. static int
  506. lpfc_debugfs_release(struct inode *inode, struct file *file)
  507. {
  508. struct lpfc_debug *debug = file->private_data;
  509. kfree(debug->buffer);
  510. kfree(debug);
  511. return 0;
  512. }
  513. #undef lpfc_debugfs_op_disc_trc
  514. static struct file_operations lpfc_debugfs_op_disc_trc = {
  515. .owner = THIS_MODULE,
  516. .open = lpfc_debugfs_disc_trc_open,
  517. .llseek = lpfc_debugfs_lseek,
  518. .read = lpfc_debugfs_read,
  519. .release = lpfc_debugfs_release,
  520. };
  521. #undef lpfc_debugfs_op_nodelist
  522. static struct file_operations lpfc_debugfs_op_nodelist = {
  523. .owner = THIS_MODULE,
  524. .open = lpfc_debugfs_nodelist_open,
  525. .llseek = lpfc_debugfs_lseek,
  526. .read = lpfc_debugfs_read,
  527. .release = lpfc_debugfs_release,
  528. };
  529. #undef lpfc_debugfs_op_dumpslim
  530. static struct file_operations lpfc_debugfs_op_dumpslim = {
  531. .owner = THIS_MODULE,
  532. .open = lpfc_debugfs_dumpslim_open,
  533. .llseek = lpfc_debugfs_lseek,
  534. .read = lpfc_debugfs_read,
  535. .release = lpfc_debugfs_release,
  536. };
  537. #undef lpfc_debugfs_op_slow_ring_trc
  538. static struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  539. .owner = THIS_MODULE,
  540. .open = lpfc_debugfs_slow_ring_trc_open,
  541. .llseek = lpfc_debugfs_lseek,
  542. .read = lpfc_debugfs_read,
  543. .release = lpfc_debugfs_release,
  544. };
  545. static struct dentry *lpfc_debugfs_root = NULL;
  546. static atomic_t lpfc_debugfs_hba_count;
  547. #endif
  548. inline void
  549. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  550. {
  551. #ifdef CONFIG_LPFC_DEBUG_FS
  552. struct lpfc_hba *phba = vport->phba;
  553. char name[64];
  554. uint32_t num, i;
  555. if (!lpfc_debugfs_enable)
  556. return;
  557. /* Setup lpfc root directory */
  558. if (!lpfc_debugfs_root) {
  559. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  560. atomic_set(&lpfc_debugfs_hba_count, 0);
  561. if (!lpfc_debugfs_root) {
  562. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  563. "0409 Cannot create debugfs root\n");
  564. goto debug_failed;
  565. }
  566. }
  567. if (!lpfc_debugfs_start_time)
  568. lpfc_debugfs_start_time = jiffies;
  569. /* Setup lpfcX directory for specific HBA */
  570. snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
  571. if (!phba->hba_debugfs_root) {
  572. phba->hba_debugfs_root =
  573. debugfs_create_dir(name, lpfc_debugfs_root);
  574. if (!phba->hba_debugfs_root) {
  575. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  576. "0409 Cannot create debugfs hba\n");
  577. goto debug_failed;
  578. }
  579. atomic_inc(&lpfc_debugfs_hba_count);
  580. atomic_set(&phba->debugfs_vport_count, 0);
  581. /* Setup dumpslim */
  582. snprintf(name, sizeof(name), "dumpslim");
  583. phba->debug_dumpslim =
  584. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  585. phba->hba_debugfs_root,
  586. phba, &lpfc_debugfs_op_dumpslim);
  587. if (!phba->debug_dumpslim) {
  588. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  589. "0409 Cannot create debugfs dumpslim\n");
  590. goto debug_failed;
  591. }
  592. /* Setup slow ring trace */
  593. if (lpfc_debugfs_max_slow_ring_trc) {
  594. num = lpfc_debugfs_max_slow_ring_trc - 1;
  595. if (num & lpfc_debugfs_max_slow_ring_trc) {
  596. /* Change to be a power of 2 */
  597. num = lpfc_debugfs_max_slow_ring_trc;
  598. i = 0;
  599. while (num > 1) {
  600. num = num >> 1;
  601. i++;
  602. }
  603. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  604. printk(KERN_ERR
  605. "lpfc_debugfs_max_disc_trc changed to "
  606. "%d\n", lpfc_debugfs_max_disc_trc);
  607. }
  608. }
  609. snprintf(name, sizeof(name), "slow_ring_trace");
  610. phba->debug_slow_ring_trc =
  611. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  612. phba->hba_debugfs_root,
  613. phba, &lpfc_debugfs_op_slow_ring_trc);
  614. if (!phba->debug_slow_ring_trc) {
  615. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  616. "0409 Cannot create debugfs "
  617. "slow_ring_trace\n");
  618. goto debug_failed;
  619. }
  620. if (!phba->slow_ring_trc) {
  621. phba->slow_ring_trc = kmalloc(
  622. (sizeof(struct lpfc_debugfs_trc) *
  623. lpfc_debugfs_max_slow_ring_trc),
  624. GFP_KERNEL);
  625. if (!phba->slow_ring_trc) {
  626. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  627. "0409 Cannot create debugfs "
  628. "slow_ring buffer\n");
  629. goto debug_failed;
  630. }
  631. atomic_set(&phba->slow_ring_trc_cnt, 0);
  632. memset(phba->slow_ring_trc, 0,
  633. (sizeof(struct lpfc_debugfs_trc) *
  634. lpfc_debugfs_max_slow_ring_trc));
  635. }
  636. }
  637. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  638. if (!vport->vport_debugfs_root) {
  639. vport->vport_debugfs_root =
  640. debugfs_create_dir(name, phba->hba_debugfs_root);
  641. if (!vport->vport_debugfs_root) {
  642. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  643. "0409 Cant create debugfs");
  644. goto debug_failed;
  645. }
  646. atomic_inc(&phba->debugfs_vport_count);
  647. }
  648. if (lpfc_debugfs_max_disc_trc) {
  649. num = lpfc_debugfs_max_disc_trc - 1;
  650. if (num & lpfc_debugfs_max_disc_trc) {
  651. /* Change to be a power of 2 */
  652. num = lpfc_debugfs_max_disc_trc;
  653. i = 0;
  654. while (num > 1) {
  655. num = num >> 1;
  656. i++;
  657. }
  658. lpfc_debugfs_max_disc_trc = (1 << i);
  659. printk(KERN_ERR
  660. "lpfc_debugfs_max_disc_trc changed to %d\n",
  661. lpfc_debugfs_max_disc_trc);
  662. }
  663. }
  664. vport->disc_trc = kmalloc(
  665. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  666. GFP_KERNEL);
  667. if (!vport->disc_trc) {
  668. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  669. "0409 Cannot create debugfs disc trace "
  670. "buffer\n");
  671. goto debug_failed;
  672. }
  673. atomic_set(&vport->disc_trc_cnt, 0);
  674. memset(vport->disc_trc, 0,
  675. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc));
  676. snprintf(name, sizeof(name), "discovery_trace");
  677. vport->debug_disc_trc =
  678. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  679. vport->vport_debugfs_root,
  680. vport, &lpfc_debugfs_op_disc_trc);
  681. if (!vport->debug_disc_trc) {
  682. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  683. "0409 Cannot create debugfs "
  684. "discovery_trace\n");
  685. goto debug_failed;
  686. }
  687. snprintf(name, sizeof(name), "nodelist");
  688. vport->debug_nodelist =
  689. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  690. vport->vport_debugfs_root,
  691. vport, &lpfc_debugfs_op_nodelist);
  692. if (!vport->debug_nodelist) {
  693. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  694. "0409 Cant create debugfs nodelist");
  695. goto debug_failed;
  696. }
  697. debug_failed:
  698. return;
  699. #endif
  700. }
  701. inline void
  702. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  703. {
  704. #ifdef CONFIG_LPFC_DEBUG_FS
  705. struct lpfc_hba *phba = vport->phba;
  706. if (vport->disc_trc) {
  707. kfree(vport->disc_trc);
  708. vport->disc_trc = NULL;
  709. }
  710. if (vport->debug_disc_trc) {
  711. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  712. vport->debug_disc_trc = NULL;
  713. }
  714. if (vport->debug_nodelist) {
  715. debugfs_remove(vport->debug_nodelist); /* nodelist */
  716. vport->debug_nodelist = NULL;
  717. }
  718. if (vport->vport_debugfs_root) {
  719. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  720. vport->vport_debugfs_root = NULL;
  721. atomic_dec(&phba->debugfs_vport_count);
  722. }
  723. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  724. if (phba->debug_dumpslim) {
  725. debugfs_remove(phba->debug_dumpslim); /* dumpslim */
  726. phba->debug_dumpslim = NULL;
  727. }
  728. if (phba->slow_ring_trc) {
  729. kfree(phba->slow_ring_trc);
  730. phba->slow_ring_trc = NULL;
  731. }
  732. if (phba->debug_slow_ring_trc) {
  733. /* slow_ring_trace */
  734. debugfs_remove(phba->debug_slow_ring_trc);
  735. phba->debug_slow_ring_trc = NULL;
  736. }
  737. if (phba->hba_debugfs_root) {
  738. debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
  739. phba->hba_debugfs_root = NULL;
  740. atomic_dec(&lpfc_debugfs_hba_count);
  741. }
  742. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  743. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  744. lpfc_debugfs_root = NULL;
  745. }
  746. }
  747. #endif
  748. return;
  749. }