lpfc_debugfs.c 44 KB

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