lpfc_debugfs.c 44 KB

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