lpfc_debugfs.c 26 KB

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