lpfc_debugfs.c 44 KB

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