lpfc_debugfs.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2007-2008 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. /**
  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 hierarchy 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 discovery events.
  62. * To enable the discovery trace, the following 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. * slow_ring_trace
  70. * This is an ACSII readable file that contains a trace of the last
  71. * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
  72. * To enable the slow ring trace, the following module parameters must be set:
  73. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  74. * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
  75. * the HBA. X MUST also be a power of 2.
  76. */
  77. static int lpfc_debugfs_enable = 1;
  78. module_param(lpfc_debugfs_enable, int, 0);
  79. MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
  80. /* This MUST be a power of 2 */
  81. static int lpfc_debugfs_max_disc_trc;
  82. module_param(lpfc_debugfs_max_disc_trc, int, 0);
  83. MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
  84. "Set debugfs discovery trace depth");
  85. /* This MUST be a power of 2 */
  86. static int lpfc_debugfs_max_slow_ring_trc;
  87. module_param(lpfc_debugfs_max_slow_ring_trc, int, 0);
  88. MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
  89. "Set debugfs slow ring trace depth");
  90. int lpfc_debugfs_mask_disc_trc;
  91. module_param(lpfc_debugfs_mask_disc_trc, int, 0);
  92. MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
  93. "Set debugfs discovery trace mask");
  94. #include <linux/debugfs.h>
  95. /* size of output line, for discovery_trace and slow_ring_trace */
  96. #define LPFC_DEBUG_TRC_ENTRY_SIZE 100
  97. /* nodelist output buffer size */
  98. #define LPFC_NODELIST_SIZE 8192
  99. #define LPFC_NODELIST_ENTRY_SIZE 120
  100. /* dumpHBASlim output buffer size */
  101. #define LPFC_DUMPHBASLIM_SIZE 4096
  102. /* dumpHostSlim output buffer size */
  103. #define LPFC_DUMPHOSTSLIM_SIZE 4096
  104. /* hbqinfo output buffer size */
  105. #define LPFC_HBQINFO_SIZE 8192
  106. struct lpfc_debug {
  107. char *buffer;
  108. int len;
  109. };
  110. static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  111. static unsigned long lpfc_debugfs_start_time = 0L;
  112. /**
  113. * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer.
  114. * @vport: The vport to gather the log info from.
  115. * @buf: The buffer to dump log into.
  116. * @size: The maximum amount of data to process.
  117. *
  118. * Description:
  119. * This routine gathers the lpfc discovery debugfs data from the @vport and
  120. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  121. * in the log and process the log until the end of the buffer. Then it will
  122. * gather from the beginning of the log and process until the current entry.
  123. *
  124. * Notes:
  125. * Discovery logging will be disabled while while this routine dumps the log.
  126. *
  127. * Return Value:
  128. * This routine returns the amount of bytes that were dumped into @buf and will
  129. * not exceed @size.
  130. **/
  131. static int
  132. lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
  133. {
  134. int i, index, len, enable;
  135. uint32_t ms;
  136. struct lpfc_debugfs_trc *dtp;
  137. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  138. enable = lpfc_debugfs_enable;
  139. lpfc_debugfs_enable = 0;
  140. len = 0;
  141. index = (atomic_read(&vport->disc_trc_cnt) + 1) &
  142. (lpfc_debugfs_max_disc_trc - 1);
  143. for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
  144. dtp = vport->disc_trc + i;
  145. if (!dtp->fmt)
  146. continue;
  147. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  148. snprintf(buffer,
  149. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  150. dtp->seq_cnt, ms, dtp->fmt);
  151. len += snprintf(buf+len, size-len, buffer,
  152. dtp->data1, dtp->data2, dtp->data3);
  153. }
  154. for (i = 0; i < index; i++) {
  155. dtp = vport->disc_trc + i;
  156. if (!dtp->fmt)
  157. continue;
  158. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  159. snprintf(buffer,
  160. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  161. dtp->seq_cnt, ms, dtp->fmt);
  162. len += snprintf(buf+len, size-len, buffer,
  163. dtp->data1, dtp->data2, dtp->data3);
  164. }
  165. lpfc_debugfs_enable = enable;
  166. return len;
  167. }
  168. /**
  169. * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer.
  170. * @phba: The HBA to gather the log info from.
  171. * @buf: The buffer to dump log into.
  172. * @size: The maximum amount of data to process.
  173. *
  174. * Description:
  175. * This routine gathers the lpfc slow ring debugfs data from the @phba and
  176. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  177. * in the log and process the log until the end of the buffer. Then it will
  178. * gather from the beginning of the log and process until the current entry.
  179. *
  180. * Notes:
  181. * Slow ring logging will be disabled while while this routine dumps the log.
  182. *
  183. * Return Value:
  184. * This routine returns the amount of bytes that were dumped into @buf and will
  185. * not exceed @size.
  186. **/
  187. static int
  188. lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
  189. {
  190. int i, index, len, enable;
  191. uint32_t ms;
  192. struct lpfc_debugfs_trc *dtp;
  193. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  194. enable = lpfc_debugfs_enable;
  195. lpfc_debugfs_enable = 0;
  196. len = 0;
  197. index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
  198. (lpfc_debugfs_max_slow_ring_trc - 1);
  199. for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
  200. dtp = phba->slow_ring_trc + i;
  201. if (!dtp->fmt)
  202. continue;
  203. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  204. snprintf(buffer,
  205. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  206. dtp->seq_cnt, ms, dtp->fmt);
  207. len += snprintf(buf+len, size-len, buffer,
  208. dtp->data1, dtp->data2, dtp->data3);
  209. }
  210. for (i = 0; i < index; i++) {
  211. dtp = phba->slow_ring_trc + i;
  212. if (!dtp->fmt)
  213. continue;
  214. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  215. snprintf(buffer,
  216. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  217. dtp->seq_cnt, ms, dtp->fmt);
  218. len += snprintf(buf+len, size-len, buffer,
  219. dtp->data1, dtp->data2, dtp->data3);
  220. }
  221. lpfc_debugfs_enable = enable;
  222. return len;
  223. }
  224. static int lpfc_debugfs_last_hbq = -1;
  225. /**
  226. * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer.
  227. * @phba: The HBA to gather host buffer info from.
  228. * @buf: The buffer to dump log into.
  229. * @size: The maximum amount of data to process.
  230. *
  231. * Description:
  232. * This routine dumps the host buffer queue info from the @phba to @buf up to
  233. * @size number of bytes. A header that describes the current hbq state will be
  234. * dumped to @buf first and then info on each hbq entry will be dumped to @buf
  235. * until @size bytes have been dumped or all the hbq info has been dumped.
  236. *
  237. * Notes:
  238. * This routine will rotate through each configured HBQ each time called.
  239. *
  240. * Return Value:
  241. * This routine returns the amount of bytes that were dumped into @buf and will
  242. * not exceed @size.
  243. **/
  244. static int
  245. lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
  246. {
  247. int len = 0;
  248. int cnt, i, j, found, posted, low;
  249. uint32_t phys, raw_index, getidx;
  250. struct lpfc_hbq_init *hip;
  251. struct hbq_s *hbqs;
  252. struct lpfc_hbq_entry *hbqe;
  253. struct lpfc_dmabuf *d_buf;
  254. struct hbq_dmabuf *hbq_buf;
  255. cnt = LPFC_HBQINFO_SIZE;
  256. spin_lock_irq(&phba->hbalock);
  257. /* toggle between multiple hbqs, if any */
  258. i = lpfc_sli_hbq_count();
  259. if (i > 1) {
  260. lpfc_debugfs_last_hbq++;
  261. if (lpfc_debugfs_last_hbq >= i)
  262. lpfc_debugfs_last_hbq = 0;
  263. }
  264. else
  265. lpfc_debugfs_last_hbq = 0;
  266. i = lpfc_debugfs_last_hbq;
  267. len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
  268. hbqs = &phba->hbqs[i];
  269. posted = 0;
  270. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
  271. posted++;
  272. hip = lpfc_hbq_defs[i];
  273. len += snprintf(buf+len, size-len,
  274. "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
  275. hip->hbq_index, hip->profile, hip->rn,
  276. hip->buffer_count, hip->init_count, hip->add_count, posted);
  277. raw_index = phba->hbq_get[i];
  278. getidx = le32_to_cpu(raw_index);
  279. len += snprintf(buf+len, size-len,
  280. "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
  281. hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
  282. hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
  283. hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
  284. for (j=0; j<hbqs->entry_count; j++) {
  285. len += snprintf(buf+len, size-len,
  286. "%03d: %08x %04x %05x ", j,
  287. le32_to_cpu(hbqe->bde.addrLow),
  288. le32_to_cpu(hbqe->bde.tus.w),
  289. le32_to_cpu(hbqe->buffer_tag));
  290. i = 0;
  291. found = 0;
  292. /* First calculate if slot has an associated posted buffer */
  293. low = hbqs->hbqPutIdx - posted;
  294. if (low >= 0) {
  295. if ((j >= hbqs->hbqPutIdx) || (j < low)) {
  296. len += snprintf(buf+len, size-len, "Unused\n");
  297. goto skipit;
  298. }
  299. }
  300. else {
  301. if ((j >= hbqs->hbqPutIdx) &&
  302. (j < (hbqs->entry_count+low))) {
  303. len += snprintf(buf+len, size-len, "Unused\n");
  304. goto skipit;
  305. }
  306. }
  307. /* Get the Buffer info for the posted buffer */
  308. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
  309. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  310. phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
  311. if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
  312. len += snprintf(buf+len, size-len,
  313. "Buf%d: %p %06x\n", i,
  314. hbq_buf->dbuf.virt, hbq_buf->tag);
  315. found = 1;
  316. break;
  317. }
  318. i++;
  319. }
  320. if (!found) {
  321. len += snprintf(buf+len, size-len, "No DMAinfo?\n");
  322. }
  323. skipit:
  324. hbqe++;
  325. if (len > LPFC_HBQINFO_SIZE - 54)
  326. break;
  327. }
  328. spin_unlock_irq(&phba->hbalock);
  329. return len;
  330. }
  331. static int lpfc_debugfs_last_hba_slim_off;
  332. /**
  333. * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer.
  334. * @phba: The HBA to gather SLIM info from.
  335. * @buf: The buffer to dump log into.
  336. * @size: The maximum amount of data to process.
  337. *
  338. * Description:
  339. * This routine dumps the current contents of HBA SLIM for the HBA associated
  340. * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
  341. *
  342. * Notes:
  343. * This routine will only dump up to 1024 bytes of data each time called and
  344. * should be called multiple times to dump the entire HBA SLIM.
  345. *
  346. * Return Value:
  347. * This routine returns the amount of bytes that were dumped into @buf and will
  348. * not exceed @size.
  349. **/
  350. static int
  351. lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
  352. {
  353. int len = 0;
  354. int i, off;
  355. uint32_t *ptr;
  356. char buffer[1024];
  357. off = 0;
  358. spin_lock_irq(&phba->hbalock);
  359. len += snprintf(buf+len, size-len, "HBA SLIM\n");
  360. lpfc_memcpy_from_slim(buffer,
  361. ((uint8_t *)phba->MBslimaddr) + lpfc_debugfs_last_hba_slim_off,
  362. 1024);
  363. ptr = (uint32_t *)&buffer[0];
  364. off = lpfc_debugfs_last_hba_slim_off;
  365. /* Set it up for the next time */
  366. lpfc_debugfs_last_hba_slim_off += 1024;
  367. if (lpfc_debugfs_last_hba_slim_off >= 4096)
  368. lpfc_debugfs_last_hba_slim_off = 0;
  369. i = 1024;
  370. while (i > 0) {
  371. len += snprintf(buf+len, size-len,
  372. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  373. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  374. *(ptr+5), *(ptr+6), *(ptr+7));
  375. ptr += 8;
  376. i -= (8 * sizeof(uint32_t));
  377. off += (8 * sizeof(uint32_t));
  378. }
  379. spin_unlock_irq(&phba->hbalock);
  380. return len;
  381. }
  382. /**
  383. * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer.
  384. * @phba: The HBA to gather Host SLIM info from.
  385. * @buf: The buffer to dump log into.
  386. * @size: The maximum amount of data to process.
  387. *
  388. * Description:
  389. * This routine dumps the current contents of host SLIM for the host associated
  390. * with @phba to @buf up to @size bytes of data. The dump will contain the
  391. * Mailbox, PCB, Rings, and Registers that are located in host memory.
  392. *
  393. * Return Value:
  394. * This routine returns the amount of bytes that were dumped into @buf and will
  395. * not exceed @size.
  396. **/
  397. static int
  398. lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
  399. {
  400. int len = 0;
  401. int i, off;
  402. uint32_t word0, word1, word2, word3;
  403. uint32_t *ptr;
  404. struct lpfc_pgp *pgpp;
  405. struct lpfc_sli *psli = &phba->sli;
  406. struct lpfc_sli_ring *pring;
  407. off = 0;
  408. spin_lock_irq(&phba->hbalock);
  409. len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
  410. ptr = (uint32_t *)phba->slim2p.virt;
  411. i = sizeof(MAILBOX_t);
  412. while (i > 0) {
  413. len += snprintf(buf+len, size-len,
  414. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  415. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  416. *(ptr+5), *(ptr+6), *(ptr+7));
  417. ptr += 8;
  418. i -= (8 * sizeof(uint32_t));
  419. off += (8 * sizeof(uint32_t));
  420. }
  421. len += snprintf(buf+len, size-len, "SLIM PCB\n");
  422. ptr = (uint32_t *)phba->pcb;
  423. i = sizeof(PCB_t);
  424. while (i > 0) {
  425. len += snprintf(buf+len, size-len,
  426. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  427. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  428. *(ptr+5), *(ptr+6), *(ptr+7));
  429. ptr += 8;
  430. i -= (8 * sizeof(uint32_t));
  431. off += (8 * sizeof(uint32_t));
  432. }
  433. for (i = 0; i < 4; i++) {
  434. pgpp = &phba->port_gp[i];
  435. pring = &psli->ring[i];
  436. len += snprintf(buf+len, size-len,
  437. "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
  438. "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
  439. i, pgpp->cmdGetInx, pring->numCiocb,
  440. pring->next_cmdidx, pring->local_getidx,
  441. pring->flag, pgpp->rspPutInx, pring->numRiocb);
  442. }
  443. word0 = readl(phba->HAregaddr);
  444. word1 = readl(phba->CAregaddr);
  445. word2 = readl(phba->HSregaddr);
  446. word3 = readl(phba->HCregaddr);
  447. len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x HC:%08x\n",
  448. word0, word1, word2, word3);
  449. spin_unlock_irq(&phba->hbalock);
  450. return len;
  451. }
  452. /**
  453. * lpfc_debugfs_nodelist_data - Dump target node list to a buffer.
  454. * @vport: The vport to gather target node info from.
  455. * @buf: The buffer to dump log into.
  456. * @size: The maximum amount of data to process.
  457. *
  458. * Description:
  459. * This routine dumps the current target node list associated with @vport to
  460. * @buf up to @size bytes of data. Each node entry in the dump will contain a
  461. * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
  462. *
  463. * Return Value:
  464. * This routine returns the amount of bytes that were dumped into @buf and will
  465. * not exceed @size.
  466. **/
  467. static int
  468. lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
  469. {
  470. int len = 0;
  471. int cnt;
  472. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  473. struct lpfc_nodelist *ndlp;
  474. unsigned char *statep, *name;
  475. cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
  476. spin_lock_irq(shost->host_lock);
  477. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  478. if (!cnt) {
  479. len += snprintf(buf+len, size-len,
  480. "Missing Nodelist Entries\n");
  481. break;
  482. }
  483. cnt--;
  484. switch (ndlp->nlp_state) {
  485. case NLP_STE_UNUSED_NODE:
  486. statep = "UNUSED";
  487. break;
  488. case NLP_STE_PLOGI_ISSUE:
  489. statep = "PLOGI ";
  490. break;
  491. case NLP_STE_ADISC_ISSUE:
  492. statep = "ADISC ";
  493. break;
  494. case NLP_STE_REG_LOGIN_ISSUE:
  495. statep = "REGLOG";
  496. break;
  497. case NLP_STE_PRLI_ISSUE:
  498. statep = "PRLI ";
  499. break;
  500. case NLP_STE_UNMAPPED_NODE:
  501. statep = "UNMAP ";
  502. break;
  503. case NLP_STE_MAPPED_NODE:
  504. statep = "MAPPED";
  505. break;
  506. case NLP_STE_NPR_NODE:
  507. statep = "NPR ";
  508. break;
  509. default:
  510. statep = "UNKNOWN";
  511. }
  512. len += snprintf(buf+len, size-len, "%s DID:x%06x ",
  513. statep, ndlp->nlp_DID);
  514. name = (unsigned char *)&ndlp->nlp_portname;
  515. len += snprintf(buf+len, size-len,
  516. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  517. *name, *(name+1), *(name+2), *(name+3),
  518. *(name+4), *(name+5), *(name+6), *(name+7));
  519. name = (unsigned char *)&ndlp->nlp_nodename;
  520. len += snprintf(buf+len, size-len,
  521. "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  522. *name, *(name+1), *(name+2), *(name+3),
  523. *(name+4), *(name+5), *(name+6), *(name+7));
  524. len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
  525. ndlp->nlp_rpi, ndlp->nlp_flag);
  526. if (!ndlp->nlp_type)
  527. len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
  528. if (ndlp->nlp_type & NLP_FC_NODE)
  529. len += snprintf(buf+len, size-len, "FC_NODE ");
  530. if (ndlp->nlp_type & NLP_FABRIC)
  531. len += snprintf(buf+len, size-len, "FABRIC ");
  532. if (ndlp->nlp_type & NLP_FCP_TARGET)
  533. len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
  534. ndlp->nlp_sid);
  535. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  536. len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
  537. len += snprintf(buf+len, size-len, "usgmap:%x ",
  538. ndlp->nlp_usg_map);
  539. len += snprintf(buf+len, size-len, "refcnt:%x",
  540. atomic_read(&ndlp->kref.refcount));
  541. len += snprintf(buf+len, size-len, "\n");
  542. }
  543. spin_unlock_irq(shost->host_lock);
  544. return len;
  545. }
  546. #endif
  547. /**
  548. * lpfc_debugfs_disc_trc - Store discovery trace log.
  549. * @vport: The vport to associate this trace string with for retrieval.
  550. * @mask: Log entry classification.
  551. * @fmt: Format string to be displayed when dumping the log.
  552. * @data1: 1st data parameter to be applied to @fmt.
  553. * @data2: 2nd data parameter to be applied to @fmt.
  554. * @data3: 3rd data parameter to be applied to @fmt.
  555. *
  556. * Description:
  557. * This routine is used by the driver code to add a debugfs log entry to the
  558. * discovery trace buffer associated with @vport. Only entries with a @mask that
  559. * match the current debugfs discovery mask will be saved. Entries that do not
  560. * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
  561. * printf when displaying the log.
  562. **/
  563. inline void
  564. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  565. uint32_t data1, uint32_t data2, uint32_t data3)
  566. {
  567. #ifdef CONFIG_LPFC_DEBUG_FS
  568. struct lpfc_debugfs_trc *dtp;
  569. int index;
  570. if (!(lpfc_debugfs_mask_disc_trc & mask))
  571. return;
  572. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  573. !vport || !vport->disc_trc)
  574. return;
  575. index = atomic_inc_return(&vport->disc_trc_cnt) &
  576. (lpfc_debugfs_max_disc_trc - 1);
  577. dtp = vport->disc_trc + index;
  578. dtp->fmt = fmt;
  579. dtp->data1 = data1;
  580. dtp->data2 = data2;
  581. dtp->data3 = data3;
  582. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  583. dtp->jif = jiffies;
  584. #endif
  585. return;
  586. }
  587. /**
  588. * lpfc_debugfs_slow_ring_trc - Store slow ring trace log.
  589. * @phba: The phba to associate this trace string with for retrieval.
  590. * @fmt: Format string to be displayed when dumping the log.
  591. * @data1: 1st data parameter to be applied to @fmt.
  592. * @data2: 2nd data parameter to be applied to @fmt.
  593. * @data3: 3rd data parameter to be applied to @fmt.
  594. *
  595. * Description:
  596. * This routine is used by the driver code to add a debugfs log entry to the
  597. * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
  598. * @data3 are used like printf when displaying the log.
  599. **/
  600. inline void
  601. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  602. uint32_t data1, uint32_t data2, uint32_t data3)
  603. {
  604. #ifdef CONFIG_LPFC_DEBUG_FS
  605. struct lpfc_debugfs_trc *dtp;
  606. int index;
  607. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  608. !phba || !phba->slow_ring_trc)
  609. return;
  610. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  611. (lpfc_debugfs_max_slow_ring_trc - 1);
  612. dtp = phba->slow_ring_trc + index;
  613. dtp->fmt = fmt;
  614. dtp->data1 = data1;
  615. dtp->data2 = data2;
  616. dtp->data3 = data3;
  617. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  618. dtp->jif = jiffies;
  619. #endif
  620. return;
  621. }
  622. #ifdef CONFIG_LPFC_DEBUG_FS
  623. /**
  624. * lpfc_debugfs_disc_trc_open - Open the discovery trace log.
  625. * @inode: The inode pointer that contains a vport pointer.
  626. * @file: The file pointer to attach the log output.
  627. *
  628. * Description:
  629. * This routine is the entry point for the debugfs open file operation. It gets
  630. * the vport from the i_private field in @inode, allocates the necessary buffer
  631. * for the log, fills the buffer from the in-memory log for this vport, and then
  632. * returns a pointer to that log in the private_data field in @file.
  633. *
  634. * Returns:
  635. * This function returns zero if successful. On error it will return an negative
  636. * error value.
  637. **/
  638. static int
  639. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  640. {
  641. struct lpfc_vport *vport = inode->i_private;
  642. struct lpfc_debug *debug;
  643. int size;
  644. int rc = -ENOMEM;
  645. if (!lpfc_debugfs_max_disc_trc) {
  646. rc = -ENOSPC;
  647. goto out;
  648. }
  649. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  650. if (!debug)
  651. goto out;
  652. /* Round to page boundary */
  653. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  654. size = PAGE_ALIGN(size);
  655. debug->buffer = kmalloc(size, GFP_KERNEL);
  656. if (!debug->buffer) {
  657. kfree(debug);
  658. goto out;
  659. }
  660. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  661. file->private_data = debug;
  662. rc = 0;
  663. out:
  664. return rc;
  665. }
  666. /**
  667. * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log.
  668. * @inode: The inode pointer that contains a vport pointer.
  669. * @file: The file pointer to attach the log output.
  670. *
  671. * Description:
  672. * This routine is the entry point for the debugfs open file operation. It gets
  673. * the vport from the i_private field in @inode, allocates the necessary buffer
  674. * for the log, fills the buffer from the in-memory log for this vport, and then
  675. * returns a pointer to that log in the private_data field in @file.
  676. *
  677. * Returns:
  678. * This function returns zero if successful. On error it will return an negative
  679. * error value.
  680. **/
  681. static int
  682. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  683. {
  684. struct lpfc_hba *phba = inode->i_private;
  685. struct lpfc_debug *debug;
  686. int size;
  687. int rc = -ENOMEM;
  688. if (!lpfc_debugfs_max_slow_ring_trc) {
  689. rc = -ENOSPC;
  690. goto out;
  691. }
  692. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  693. if (!debug)
  694. goto out;
  695. /* Round to page boundary */
  696. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  697. size = PAGE_ALIGN(size);
  698. debug->buffer = kmalloc(size, GFP_KERNEL);
  699. if (!debug->buffer) {
  700. kfree(debug);
  701. goto out;
  702. }
  703. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  704. file->private_data = debug;
  705. rc = 0;
  706. out:
  707. return rc;
  708. }
  709. /**
  710. * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer.
  711. * @inode: The inode pointer that contains a vport pointer.
  712. * @file: The file pointer to attach the log output.
  713. *
  714. * Description:
  715. * This routine is the entry point for the debugfs open file operation. It gets
  716. * the vport from the i_private field in @inode, allocates the necessary buffer
  717. * for the log, fills the buffer from the in-memory log for this vport, and then
  718. * returns a pointer to that log in the private_data field in @file.
  719. *
  720. * Returns:
  721. * This function returns zero if successful. On error it will return an negative
  722. * error value.
  723. **/
  724. static int
  725. lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
  726. {
  727. struct lpfc_hba *phba = inode->i_private;
  728. struct lpfc_debug *debug;
  729. int rc = -ENOMEM;
  730. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  731. if (!debug)
  732. goto out;
  733. /* Round to page boundary */
  734. debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
  735. if (!debug->buffer) {
  736. kfree(debug);
  737. goto out;
  738. }
  739. debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
  740. LPFC_HBQINFO_SIZE);
  741. file->private_data = debug;
  742. rc = 0;
  743. out:
  744. return rc;
  745. }
  746. /**
  747. * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer.
  748. * @inode: The inode pointer that contains a vport pointer.
  749. * @file: The file pointer to attach the log output.
  750. *
  751. * Description:
  752. * This routine is the entry point for the debugfs open file operation. It gets
  753. * the vport from the i_private field in @inode, allocates the necessary buffer
  754. * for the log, fills the buffer from the in-memory log for this vport, and then
  755. * returns a pointer to that log in the private_data field in @file.
  756. *
  757. * Returns:
  758. * This function returns zero if successful. On error it will return an negative
  759. * error value.
  760. **/
  761. static int
  762. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  763. {
  764. struct lpfc_hba *phba = inode->i_private;
  765. struct lpfc_debug *debug;
  766. int rc = -ENOMEM;
  767. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  768. if (!debug)
  769. goto out;
  770. /* Round to page boundary */
  771. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  772. if (!debug->buffer) {
  773. kfree(debug);
  774. goto out;
  775. }
  776. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  777. LPFC_DUMPHBASLIM_SIZE);
  778. file->private_data = debug;
  779. rc = 0;
  780. out:
  781. return rc;
  782. }
  783. /**
  784. * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer.
  785. * @inode: The inode pointer that contains a vport pointer.
  786. * @file: The file pointer to attach the log output.
  787. *
  788. * Description:
  789. * This routine is the entry point for the debugfs open file operation. It gets
  790. * the vport from the i_private field in @inode, allocates the necessary buffer
  791. * for the log, fills the buffer from the in-memory log for this vport, and then
  792. * returns a pointer to that log in the private_data field in @file.
  793. *
  794. * Returns:
  795. * This function returns zero if successful. On error it will return an negative
  796. * error value.
  797. **/
  798. static int
  799. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  800. {
  801. struct lpfc_hba *phba = inode->i_private;
  802. struct lpfc_debug *debug;
  803. int rc = -ENOMEM;
  804. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  805. if (!debug)
  806. goto out;
  807. /* Round to page boundary */
  808. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  809. if (!debug->buffer) {
  810. kfree(debug);
  811. goto out;
  812. }
  813. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  814. LPFC_DUMPHOSTSLIM_SIZE);
  815. file->private_data = debug;
  816. rc = 0;
  817. out:
  818. return rc;
  819. }
  820. /**
  821. * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file.
  822. * @inode: The inode pointer that contains a vport pointer.
  823. * @file: The file pointer to attach the log output.
  824. *
  825. * Description:
  826. * This routine is the entry point for the debugfs open file operation. It gets
  827. * the vport from the i_private field in @inode, allocates the necessary buffer
  828. * for the log, fills the buffer from the in-memory log for this vport, and then
  829. * returns a pointer to that log in the private_data field in @file.
  830. *
  831. * Returns:
  832. * This function returns zero if successful. On error it will return an negative
  833. * error value.
  834. **/
  835. static int
  836. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  837. {
  838. struct lpfc_vport *vport = inode->i_private;
  839. struct lpfc_debug *debug;
  840. int rc = -ENOMEM;
  841. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  842. if (!debug)
  843. goto out;
  844. /* Round to page boundary */
  845. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  846. if (!debug->buffer) {
  847. kfree(debug);
  848. goto out;
  849. }
  850. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  851. LPFC_NODELIST_SIZE);
  852. file->private_data = debug;
  853. rc = 0;
  854. out:
  855. return rc;
  856. }
  857. /**
  858. * lpfc_debugfs_lseek - Seek through a debugfs file.
  859. * @file: The file pointer to seek through.
  860. * @off: The offset to seek to or the amount to seek by.
  861. * @whence: Indicates how to seek.
  862. *
  863. * Description:
  864. * This routine is the entry point for the debugfs lseek file operation. The
  865. * @whence parameter indicates whether @off is the offset to directly seek to,
  866. * or if it is a value to seek forward or reverse by. This function figures out
  867. * what the new offset of the debugfs file will be and assigns that value to the
  868. * f_pos field of @file.
  869. *
  870. * Returns:
  871. * This function returns the new offset if successful and returns a negative
  872. * error if unable to process the seek.
  873. **/
  874. static loff_t
  875. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  876. {
  877. struct lpfc_debug *debug;
  878. loff_t pos = -1;
  879. debug = file->private_data;
  880. switch (whence) {
  881. case 0:
  882. pos = off;
  883. break;
  884. case 1:
  885. pos = file->f_pos + off;
  886. break;
  887. case 2:
  888. pos = debug->len - off;
  889. }
  890. return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
  891. }
  892. /**
  893. * lpfc_debugfs_read - Read a debugfs file.
  894. * @file: The file pointer to read from.
  895. * @buf: The buffer to copy the data to.
  896. * @nbytes: The number of bytes to read.
  897. * @ppos: The position in the file to start reading from.
  898. *
  899. * Description:
  900. * This routine reads data from from the buffer indicated in the private_data
  901. * field of @file. It will start reading at @ppos and copy up to @nbytes of
  902. * data to @buf.
  903. *
  904. * Returns:
  905. * This function returns the amount of data that was read (this could be less
  906. * than @nbytes if the end of the file was reached) or a negative error value.
  907. **/
  908. static ssize_t
  909. lpfc_debugfs_read(struct file *file, char __user *buf,
  910. size_t nbytes, loff_t *ppos)
  911. {
  912. struct lpfc_debug *debug = file->private_data;
  913. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  914. debug->len);
  915. }
  916. /**
  917. * lpfc_debugfs_release - Release the buffer used to store debugfs file data.
  918. * @inode: The inode pointer that contains a vport pointer. (unused)
  919. * @file: The file pointer that contains the buffer to release.
  920. *
  921. * Description:
  922. * This routine frees the buffer that was allocated when the debugfs file was
  923. * opened.
  924. *
  925. * Returns:
  926. * This function returns zero.
  927. **/
  928. static int
  929. lpfc_debugfs_release(struct inode *inode, struct file *file)
  930. {
  931. struct lpfc_debug *debug = file->private_data;
  932. kfree(debug->buffer);
  933. kfree(debug);
  934. return 0;
  935. }
  936. #undef lpfc_debugfs_op_disc_trc
  937. static struct file_operations lpfc_debugfs_op_disc_trc = {
  938. .owner = THIS_MODULE,
  939. .open = lpfc_debugfs_disc_trc_open,
  940. .llseek = lpfc_debugfs_lseek,
  941. .read = lpfc_debugfs_read,
  942. .release = lpfc_debugfs_release,
  943. };
  944. #undef lpfc_debugfs_op_nodelist
  945. static struct file_operations lpfc_debugfs_op_nodelist = {
  946. .owner = THIS_MODULE,
  947. .open = lpfc_debugfs_nodelist_open,
  948. .llseek = lpfc_debugfs_lseek,
  949. .read = lpfc_debugfs_read,
  950. .release = lpfc_debugfs_release,
  951. };
  952. #undef lpfc_debugfs_op_hbqinfo
  953. static struct file_operations lpfc_debugfs_op_hbqinfo = {
  954. .owner = THIS_MODULE,
  955. .open = lpfc_debugfs_hbqinfo_open,
  956. .llseek = lpfc_debugfs_lseek,
  957. .read = lpfc_debugfs_read,
  958. .release = lpfc_debugfs_release,
  959. };
  960. #undef lpfc_debugfs_op_dumpHBASlim
  961. static struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  962. .owner = THIS_MODULE,
  963. .open = lpfc_debugfs_dumpHBASlim_open,
  964. .llseek = lpfc_debugfs_lseek,
  965. .read = lpfc_debugfs_read,
  966. .release = lpfc_debugfs_release,
  967. };
  968. #undef lpfc_debugfs_op_dumpHostSlim
  969. static struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  970. .owner = THIS_MODULE,
  971. .open = lpfc_debugfs_dumpHostSlim_open,
  972. .llseek = lpfc_debugfs_lseek,
  973. .read = lpfc_debugfs_read,
  974. .release = lpfc_debugfs_release,
  975. };
  976. #undef lpfc_debugfs_op_slow_ring_trc
  977. static struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  978. .owner = THIS_MODULE,
  979. .open = lpfc_debugfs_slow_ring_trc_open,
  980. .llseek = lpfc_debugfs_lseek,
  981. .read = lpfc_debugfs_read,
  982. .release = lpfc_debugfs_release,
  983. };
  984. static struct dentry *lpfc_debugfs_root = NULL;
  985. static atomic_t lpfc_debugfs_hba_count;
  986. #endif
  987. /**
  988. * lpfc_debugfs_initialize - Initialize debugfs for a vport.
  989. * @vport: The vport pointer to initialize.
  990. *
  991. * Description:
  992. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  993. * If not already created, this routine will create the lpfc directory, and
  994. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  995. * also create each file used to access lpfc specific debugfs information.
  996. **/
  997. inline void
  998. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  999. {
  1000. #ifdef CONFIG_LPFC_DEBUG_FS
  1001. struct lpfc_hba *phba = vport->phba;
  1002. char name[64];
  1003. uint32_t num, i;
  1004. if (!lpfc_debugfs_enable)
  1005. return;
  1006. /* Setup lpfc root directory */
  1007. if (!lpfc_debugfs_root) {
  1008. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  1009. atomic_set(&lpfc_debugfs_hba_count, 0);
  1010. if (!lpfc_debugfs_root) {
  1011. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1012. "0409 Cannot create debugfs root\n");
  1013. goto debug_failed;
  1014. }
  1015. }
  1016. if (!lpfc_debugfs_start_time)
  1017. lpfc_debugfs_start_time = jiffies;
  1018. /* Setup lpfcX directory for specific HBA */
  1019. snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
  1020. if (!phba->hba_debugfs_root) {
  1021. phba->hba_debugfs_root =
  1022. debugfs_create_dir(name, lpfc_debugfs_root);
  1023. if (!phba->hba_debugfs_root) {
  1024. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1025. "0409 Cannot create debugfs hba\n");
  1026. goto debug_failed;
  1027. }
  1028. atomic_inc(&lpfc_debugfs_hba_count);
  1029. atomic_set(&phba->debugfs_vport_count, 0);
  1030. /* Setup hbqinfo */
  1031. snprintf(name, sizeof(name), "hbqinfo");
  1032. phba->debug_hbqinfo =
  1033. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1034. phba->hba_debugfs_root,
  1035. phba, &lpfc_debugfs_op_hbqinfo);
  1036. if (!phba->debug_hbqinfo) {
  1037. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1038. "0409 Cannot create debugfs hbqinfo\n");
  1039. goto debug_failed;
  1040. }
  1041. /* Setup dumpHBASlim */
  1042. snprintf(name, sizeof(name), "dumpHBASlim");
  1043. phba->debug_dumpHBASlim =
  1044. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1045. phba->hba_debugfs_root,
  1046. phba, &lpfc_debugfs_op_dumpHBASlim);
  1047. if (!phba->debug_dumpHBASlim) {
  1048. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1049. "0409 Cannot create debugfs dumpHBASlim\n");
  1050. goto debug_failed;
  1051. }
  1052. /* Setup dumpHostSlim */
  1053. snprintf(name, sizeof(name), "dumpHostSlim");
  1054. phba->debug_dumpHostSlim =
  1055. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1056. phba->hba_debugfs_root,
  1057. phba, &lpfc_debugfs_op_dumpHostSlim);
  1058. if (!phba->debug_dumpHostSlim) {
  1059. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1060. "0409 Cannot create debugfs dumpHostSlim\n");
  1061. goto debug_failed;
  1062. }
  1063. /* Setup slow ring trace */
  1064. if (lpfc_debugfs_max_slow_ring_trc) {
  1065. num = lpfc_debugfs_max_slow_ring_trc - 1;
  1066. if (num & lpfc_debugfs_max_slow_ring_trc) {
  1067. /* Change to be a power of 2 */
  1068. num = lpfc_debugfs_max_slow_ring_trc;
  1069. i = 0;
  1070. while (num > 1) {
  1071. num = num >> 1;
  1072. i++;
  1073. }
  1074. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  1075. printk(KERN_ERR
  1076. "lpfc_debugfs_max_disc_trc changed to "
  1077. "%d\n", lpfc_debugfs_max_disc_trc);
  1078. }
  1079. }
  1080. snprintf(name, sizeof(name), "slow_ring_trace");
  1081. phba->debug_slow_ring_trc =
  1082. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1083. phba->hba_debugfs_root,
  1084. phba, &lpfc_debugfs_op_slow_ring_trc);
  1085. if (!phba->debug_slow_ring_trc) {
  1086. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1087. "0409 Cannot create debugfs "
  1088. "slow_ring_trace\n");
  1089. goto debug_failed;
  1090. }
  1091. if (!phba->slow_ring_trc) {
  1092. phba->slow_ring_trc = kmalloc(
  1093. (sizeof(struct lpfc_debugfs_trc) *
  1094. lpfc_debugfs_max_slow_ring_trc),
  1095. GFP_KERNEL);
  1096. if (!phba->slow_ring_trc) {
  1097. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1098. "0409 Cannot create debugfs "
  1099. "slow_ring buffer\n");
  1100. goto debug_failed;
  1101. }
  1102. atomic_set(&phba->slow_ring_trc_cnt, 0);
  1103. memset(phba->slow_ring_trc, 0,
  1104. (sizeof(struct lpfc_debugfs_trc) *
  1105. lpfc_debugfs_max_slow_ring_trc));
  1106. }
  1107. }
  1108. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  1109. if (!vport->vport_debugfs_root) {
  1110. vport->vport_debugfs_root =
  1111. debugfs_create_dir(name, phba->hba_debugfs_root);
  1112. if (!vport->vport_debugfs_root) {
  1113. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1114. "0409 Cant create debugfs");
  1115. goto debug_failed;
  1116. }
  1117. atomic_inc(&phba->debugfs_vport_count);
  1118. }
  1119. if (lpfc_debugfs_max_disc_trc) {
  1120. num = lpfc_debugfs_max_disc_trc - 1;
  1121. if (num & lpfc_debugfs_max_disc_trc) {
  1122. /* Change to be a power of 2 */
  1123. num = lpfc_debugfs_max_disc_trc;
  1124. i = 0;
  1125. while (num > 1) {
  1126. num = num >> 1;
  1127. i++;
  1128. }
  1129. lpfc_debugfs_max_disc_trc = (1 << i);
  1130. printk(KERN_ERR
  1131. "lpfc_debugfs_max_disc_trc changed to %d\n",
  1132. lpfc_debugfs_max_disc_trc);
  1133. }
  1134. }
  1135. vport->disc_trc = kzalloc(
  1136. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  1137. GFP_KERNEL);
  1138. if (!vport->disc_trc) {
  1139. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1140. "0409 Cannot create debugfs disc trace "
  1141. "buffer\n");
  1142. goto debug_failed;
  1143. }
  1144. atomic_set(&vport->disc_trc_cnt, 0);
  1145. snprintf(name, sizeof(name), "discovery_trace");
  1146. vport->debug_disc_trc =
  1147. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1148. vport->vport_debugfs_root,
  1149. vport, &lpfc_debugfs_op_disc_trc);
  1150. if (!vport->debug_disc_trc) {
  1151. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1152. "0409 Cannot create debugfs "
  1153. "discovery_trace\n");
  1154. goto debug_failed;
  1155. }
  1156. snprintf(name, sizeof(name), "nodelist");
  1157. vport->debug_nodelist =
  1158. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1159. vport->vport_debugfs_root,
  1160. vport, &lpfc_debugfs_op_nodelist);
  1161. if (!vport->debug_nodelist) {
  1162. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1163. "0409 Cant create debugfs nodelist");
  1164. goto debug_failed;
  1165. }
  1166. debug_failed:
  1167. return;
  1168. #endif
  1169. }
  1170. /**
  1171. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport.
  1172. * @vport: The vport pointer to remove from debugfs.
  1173. *
  1174. * Description:
  1175. * When Debugfs is configured this routine removes debugfs file system elements
  1176. * that are specific to this vport. It also checks to see if there are any
  1177. * users left for the debugfs directories associated with the HBA and driver. If
  1178. * this is the last user of the HBA directory or driver directory then it will
  1179. * remove those from the debugfs infrastructure as well.
  1180. **/
  1181. inline void
  1182. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  1183. {
  1184. #ifdef CONFIG_LPFC_DEBUG_FS
  1185. struct lpfc_hba *phba = vport->phba;
  1186. if (vport->disc_trc) {
  1187. kfree(vport->disc_trc);
  1188. vport->disc_trc = NULL;
  1189. }
  1190. if (vport->debug_disc_trc) {
  1191. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  1192. vport->debug_disc_trc = NULL;
  1193. }
  1194. if (vport->debug_nodelist) {
  1195. debugfs_remove(vport->debug_nodelist); /* nodelist */
  1196. vport->debug_nodelist = NULL;
  1197. }
  1198. if (vport->vport_debugfs_root) {
  1199. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  1200. vport->vport_debugfs_root = NULL;
  1201. atomic_dec(&phba->debugfs_vport_count);
  1202. }
  1203. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  1204. if (phba->debug_hbqinfo) {
  1205. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  1206. phba->debug_hbqinfo = NULL;
  1207. }
  1208. if (phba->debug_dumpHBASlim) {
  1209. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  1210. phba->debug_dumpHBASlim = NULL;
  1211. }
  1212. if (phba->debug_dumpHostSlim) {
  1213. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  1214. phba->debug_dumpHostSlim = NULL;
  1215. }
  1216. if (phba->slow_ring_trc) {
  1217. kfree(phba->slow_ring_trc);
  1218. phba->slow_ring_trc = NULL;
  1219. }
  1220. if (phba->debug_slow_ring_trc) {
  1221. /* slow_ring_trace */
  1222. debugfs_remove(phba->debug_slow_ring_trc);
  1223. phba->debug_slow_ring_trc = NULL;
  1224. }
  1225. if (phba->hba_debugfs_root) {
  1226. debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
  1227. phba->hba_debugfs_root = NULL;
  1228. atomic_dec(&lpfc_debugfs_hba_count);
  1229. }
  1230. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  1231. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  1232. lpfc_debugfs_root = NULL;
  1233. }
  1234. }
  1235. #endif
  1236. return;
  1237. }