lpfc_debugfs.c 29 KB

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