lpfc_debugfs.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  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. static 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. phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
  363. ptr = (uint32_t *)&buffer[0];
  364. off = lpfc_debugfs_last_hba_slim_off;
  365. /* Set it up for the next time */
  366. lpfc_debugfs_last_hba_slim_off += 1024;
  367. if (lpfc_debugfs_last_hba_slim_off >= 4096)
  368. lpfc_debugfs_last_hba_slim_off = 0;
  369. i = 1024;
  370. while (i > 0) {
  371. len += snprintf(buf+len, size-len,
  372. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  373. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  374. *(ptr+5), *(ptr+6), *(ptr+7));
  375. ptr += 8;
  376. i -= (8 * sizeof(uint32_t));
  377. off += (8 * sizeof(uint32_t));
  378. }
  379. spin_unlock_irq(&phba->hbalock);
  380. return len;
  381. }
  382. /**
  383. * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
  384. * @phba: The HBA to gather Host SLIM info from.
  385. * @buf: The buffer to dump log into.
  386. * @size: The maximum amount of data to process.
  387. *
  388. * Description:
  389. * This routine dumps the current contents of host SLIM for the host associated
  390. * with @phba to @buf up to @size bytes of data. The dump will contain the
  391. * Mailbox, PCB, Rings, and Registers that are located in host memory.
  392. *
  393. * Return Value:
  394. * This routine returns the amount of bytes that were dumped into @buf and will
  395. * not exceed @size.
  396. **/
  397. static int
  398. lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
  399. {
  400. int len = 0;
  401. int i, off;
  402. uint32_t word0, word1, word2, word3;
  403. uint32_t *ptr;
  404. struct lpfc_pgp *pgpp;
  405. struct lpfc_sli *psli = &phba->sli;
  406. struct lpfc_sli_ring *pring;
  407. off = 0;
  408. spin_lock_irq(&phba->hbalock);
  409. len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
  410. ptr = (uint32_t *)phba->slim2p.virt;
  411. i = sizeof(MAILBOX_t);
  412. while (i > 0) {
  413. len += snprintf(buf+len, size-len,
  414. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  415. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  416. *(ptr+5), *(ptr+6), *(ptr+7));
  417. ptr += 8;
  418. i -= (8 * sizeof(uint32_t));
  419. off += (8 * sizeof(uint32_t));
  420. }
  421. len += snprintf(buf+len, size-len, "SLIM PCB\n");
  422. ptr = (uint32_t *)phba->pcb;
  423. i = sizeof(PCB_t);
  424. while (i > 0) {
  425. len += snprintf(buf+len, size-len,
  426. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  427. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  428. *(ptr+5), *(ptr+6), *(ptr+7));
  429. ptr += 8;
  430. i -= (8 * sizeof(uint32_t));
  431. off += (8 * sizeof(uint32_t));
  432. }
  433. for (i = 0; i < 4; i++) {
  434. pgpp = &phba->port_gp[i];
  435. pring = &psli->ring[i];
  436. len += snprintf(buf+len, size-len,
  437. "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
  438. "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
  439. i, pgpp->cmdGetInx, pring->numCiocb,
  440. pring->next_cmdidx, pring->local_getidx,
  441. pring->flag, pgpp->rspPutInx, pring->numRiocb);
  442. }
  443. word0 = readl(phba->HAregaddr);
  444. word1 = readl(phba->CAregaddr);
  445. word2 = readl(phba->HSregaddr);
  446. word3 = readl(phba->HCregaddr);
  447. len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x HC:%08x\n",
  448. word0, word1, word2, word3);
  449. spin_unlock_irq(&phba->hbalock);
  450. return len;
  451. }
  452. /**
  453. * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
  454. * @vport: The vport to gather target node info from.
  455. * @buf: The buffer to dump log into.
  456. * @size: The maximum amount of data to process.
  457. *
  458. * Description:
  459. * This routine dumps the current target node list associated with @vport to
  460. * @buf up to @size bytes of data. Each node entry in the dump will contain a
  461. * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
  462. *
  463. * Return Value:
  464. * This routine returns the amount of bytes that were dumped into @buf and will
  465. * not exceed @size.
  466. **/
  467. static int
  468. lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
  469. {
  470. int len = 0;
  471. int cnt;
  472. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  473. struct lpfc_nodelist *ndlp;
  474. unsigned char *statep, *name;
  475. cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
  476. spin_lock_irq(shost->host_lock);
  477. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  478. if (!cnt) {
  479. len += snprintf(buf+len, size-len,
  480. "Missing Nodelist Entries\n");
  481. break;
  482. }
  483. cnt--;
  484. switch (ndlp->nlp_state) {
  485. case NLP_STE_UNUSED_NODE:
  486. statep = "UNUSED";
  487. break;
  488. case NLP_STE_PLOGI_ISSUE:
  489. statep = "PLOGI ";
  490. break;
  491. case NLP_STE_ADISC_ISSUE:
  492. statep = "ADISC ";
  493. break;
  494. case NLP_STE_REG_LOGIN_ISSUE:
  495. statep = "REGLOG";
  496. break;
  497. case NLP_STE_PRLI_ISSUE:
  498. statep = "PRLI ";
  499. break;
  500. case NLP_STE_UNMAPPED_NODE:
  501. statep = "UNMAP ";
  502. break;
  503. case NLP_STE_MAPPED_NODE:
  504. statep = "MAPPED";
  505. break;
  506. case NLP_STE_NPR_NODE:
  507. statep = "NPR ";
  508. break;
  509. default:
  510. statep = "UNKNOWN";
  511. }
  512. len += snprintf(buf+len, size-len, "%s DID:x%06x ",
  513. statep, ndlp->nlp_DID);
  514. name = (unsigned char *)&ndlp->nlp_portname;
  515. len += snprintf(buf+len, size-len,
  516. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  517. *name, *(name+1), *(name+2), *(name+3),
  518. *(name+4), *(name+5), *(name+6), *(name+7));
  519. name = (unsigned char *)&ndlp->nlp_nodename;
  520. len += snprintf(buf+len, size-len,
  521. "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  522. *name, *(name+1), *(name+2), *(name+3),
  523. *(name+4), *(name+5), *(name+6), *(name+7));
  524. len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
  525. ndlp->nlp_rpi, ndlp->nlp_flag);
  526. if (!ndlp->nlp_type)
  527. len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
  528. if (ndlp->nlp_type & NLP_FC_NODE)
  529. len += snprintf(buf+len, size-len, "FC_NODE ");
  530. if (ndlp->nlp_type & NLP_FABRIC)
  531. len += snprintf(buf+len, size-len, "FABRIC ");
  532. if (ndlp->nlp_type & NLP_FCP_TARGET)
  533. len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
  534. ndlp->nlp_sid);
  535. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  536. len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
  537. len += snprintf(buf+len, size-len, "usgmap:%x ",
  538. ndlp->nlp_usg_map);
  539. len += snprintf(buf+len, size-len, "refcnt:%x",
  540. atomic_read(&ndlp->kref.refcount));
  541. len += snprintf(buf+len, size-len, "\n");
  542. }
  543. spin_unlock_irq(shost->host_lock);
  544. return len;
  545. }
  546. #endif
  547. /**
  548. * lpfc_debugfs_disc_trc - Store discovery trace log
  549. * @vport: The vport to associate this trace string with for retrieval.
  550. * @mask: Log entry classification.
  551. * @fmt: Format string to be displayed when dumping the log.
  552. * @data1: 1st data parameter to be applied to @fmt.
  553. * @data2: 2nd data parameter to be applied to @fmt.
  554. * @data3: 3rd data parameter to be applied to @fmt.
  555. *
  556. * Description:
  557. * This routine is used by the driver code to add a debugfs log entry to the
  558. * discovery trace buffer associated with @vport. Only entries with a @mask that
  559. * match the current debugfs discovery mask will be saved. Entries that do not
  560. * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
  561. * printf when displaying the log.
  562. **/
  563. inline void
  564. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  565. uint32_t data1, uint32_t data2, uint32_t data3)
  566. {
  567. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  568. struct lpfc_debugfs_trc *dtp;
  569. int index;
  570. if (!(lpfc_debugfs_mask_disc_trc & mask))
  571. return;
  572. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  573. !vport || !vport->disc_trc)
  574. return;
  575. index = atomic_inc_return(&vport->disc_trc_cnt) &
  576. (lpfc_debugfs_max_disc_trc - 1);
  577. dtp = vport->disc_trc + index;
  578. dtp->fmt = fmt;
  579. dtp->data1 = data1;
  580. dtp->data2 = data2;
  581. dtp->data3 = data3;
  582. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  583. dtp->jif = jiffies;
  584. #endif
  585. return;
  586. }
  587. /**
  588. * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
  589. * @phba: The phba to associate this trace string with for retrieval.
  590. * @fmt: Format string to be displayed when dumping the log.
  591. * @data1: 1st data parameter to be applied to @fmt.
  592. * @data2: 2nd data parameter to be applied to @fmt.
  593. * @data3: 3rd data parameter to be applied to @fmt.
  594. *
  595. * Description:
  596. * This routine is used by the driver code to add a debugfs log entry to the
  597. * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
  598. * @data3 are used like printf when displaying the log.
  599. **/
  600. inline void
  601. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  602. uint32_t data1, uint32_t data2, uint32_t data3)
  603. {
  604. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  605. struct lpfc_debugfs_trc *dtp;
  606. int index;
  607. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  608. !phba || !phba->slow_ring_trc)
  609. return;
  610. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  611. (lpfc_debugfs_max_slow_ring_trc - 1);
  612. dtp = phba->slow_ring_trc + index;
  613. dtp->fmt = fmt;
  614. dtp->data1 = data1;
  615. dtp->data2 = data2;
  616. dtp->data3 = data3;
  617. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  618. dtp->jif = jiffies;
  619. #endif
  620. return;
  621. }
  622. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  623. /**
  624. * lpfc_debugfs_disc_trc_open - Open the discovery trace log
  625. * @inode: The inode pointer that contains a vport pointer.
  626. * @file: The file pointer to attach the log output.
  627. *
  628. * Description:
  629. * This routine is the entry point for the debugfs open file operation. It gets
  630. * the vport from the i_private field in @inode, allocates the necessary buffer
  631. * for the log, fills the buffer from the in-memory log for this vport, and then
  632. * returns a pointer to that log in the private_data field in @file.
  633. *
  634. * Returns:
  635. * This function returns zero if successful. On error it will return an negative
  636. * error value.
  637. **/
  638. static int
  639. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  640. {
  641. struct lpfc_vport *vport = inode->i_private;
  642. struct lpfc_debug *debug;
  643. int size;
  644. int rc = -ENOMEM;
  645. if (!lpfc_debugfs_max_disc_trc) {
  646. rc = -ENOSPC;
  647. goto out;
  648. }
  649. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  650. if (!debug)
  651. goto out;
  652. /* Round to page boundary */
  653. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  654. size = PAGE_ALIGN(size);
  655. debug->buffer = kmalloc(size, GFP_KERNEL);
  656. if (!debug->buffer) {
  657. kfree(debug);
  658. goto out;
  659. }
  660. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  661. file->private_data = debug;
  662. rc = 0;
  663. out:
  664. return rc;
  665. }
  666. /**
  667. * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
  668. * @inode: The inode pointer that contains a vport pointer.
  669. * @file: The file pointer to attach the log output.
  670. *
  671. * Description:
  672. * This routine is the entry point for the debugfs open file operation. It gets
  673. * the vport from the i_private field in @inode, allocates the necessary buffer
  674. * for the log, fills the buffer from the in-memory log for this vport, and then
  675. * returns a pointer to that log in the private_data field in @file.
  676. *
  677. * Returns:
  678. * This function returns zero if successful. On error it will return an negative
  679. * error value.
  680. **/
  681. static int
  682. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  683. {
  684. struct lpfc_hba *phba = inode->i_private;
  685. struct lpfc_debug *debug;
  686. int size;
  687. int rc = -ENOMEM;
  688. if (!lpfc_debugfs_max_slow_ring_trc) {
  689. rc = -ENOSPC;
  690. goto out;
  691. }
  692. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  693. if (!debug)
  694. goto out;
  695. /* Round to page boundary */
  696. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  697. size = PAGE_ALIGN(size);
  698. debug->buffer = kmalloc(size, GFP_KERNEL);
  699. if (!debug->buffer) {
  700. kfree(debug);
  701. goto out;
  702. }
  703. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  704. file->private_data = debug;
  705. rc = 0;
  706. out:
  707. return rc;
  708. }
  709. /**
  710. * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
  711. * @inode: The inode pointer that contains a vport pointer.
  712. * @file: The file pointer to attach the log output.
  713. *
  714. * Description:
  715. * This routine is the entry point for the debugfs open file operation. It gets
  716. * the vport from the i_private field in @inode, allocates the necessary buffer
  717. * for the log, fills the buffer from the in-memory log for this vport, and then
  718. * returns a pointer to that log in the private_data field in @file.
  719. *
  720. * Returns:
  721. * This function returns zero if successful. On error it will return an negative
  722. * error value.
  723. **/
  724. static int
  725. lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
  726. {
  727. struct lpfc_hba *phba = inode->i_private;
  728. struct lpfc_debug *debug;
  729. int rc = -ENOMEM;
  730. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  731. if (!debug)
  732. goto out;
  733. /* Round to page boundary */
  734. debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
  735. if (!debug->buffer) {
  736. kfree(debug);
  737. goto out;
  738. }
  739. debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
  740. LPFC_HBQINFO_SIZE);
  741. file->private_data = debug;
  742. rc = 0;
  743. out:
  744. return rc;
  745. }
  746. /**
  747. * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
  748. * @inode: The inode pointer that contains a vport pointer.
  749. * @file: The file pointer to attach the log output.
  750. *
  751. * Description:
  752. * This routine is the entry point for the debugfs open file operation. It gets
  753. * the vport from the i_private field in @inode, allocates the necessary buffer
  754. * for the log, fills the buffer from the in-memory log for this vport, and then
  755. * returns a pointer to that log in the private_data field in @file.
  756. *
  757. * Returns:
  758. * This function returns zero if successful. On error it will return an negative
  759. * error value.
  760. **/
  761. static int
  762. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  763. {
  764. struct lpfc_hba *phba = inode->i_private;
  765. struct lpfc_debug *debug;
  766. int rc = -ENOMEM;
  767. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  768. if (!debug)
  769. goto out;
  770. /* Round to page boundary */
  771. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  772. if (!debug->buffer) {
  773. kfree(debug);
  774. goto out;
  775. }
  776. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  777. LPFC_DUMPHBASLIM_SIZE);
  778. file->private_data = debug;
  779. rc = 0;
  780. out:
  781. return rc;
  782. }
  783. /**
  784. * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
  785. * @inode: The inode pointer that contains a vport pointer.
  786. * @file: The file pointer to attach the log output.
  787. *
  788. * Description:
  789. * This routine is the entry point for the debugfs open file operation. It gets
  790. * the vport from the i_private field in @inode, allocates the necessary buffer
  791. * for the log, fills the buffer from the in-memory log for this vport, and then
  792. * returns a pointer to that log in the private_data field in @file.
  793. *
  794. * Returns:
  795. * This function returns zero if successful. On error it will return an negative
  796. * error value.
  797. **/
  798. static int
  799. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  800. {
  801. struct lpfc_hba *phba = inode->i_private;
  802. struct lpfc_debug *debug;
  803. int rc = -ENOMEM;
  804. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  805. if (!debug)
  806. goto out;
  807. /* Round to page boundary */
  808. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  809. if (!debug->buffer) {
  810. kfree(debug);
  811. goto out;
  812. }
  813. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  814. LPFC_DUMPHOSTSLIM_SIZE);
  815. file->private_data = debug;
  816. rc = 0;
  817. out:
  818. return rc;
  819. }
  820. static int
  821. lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
  822. {
  823. struct lpfc_debug *debug;
  824. int rc = -ENOMEM;
  825. if (!_dump_buf_data)
  826. return -EBUSY;
  827. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  828. if (!debug)
  829. goto out;
  830. /* Round to page boundry */
  831. printk(KERN_ERR "BLKGRD %s: _dump_buf_data=0x%p\n",
  832. __func__, _dump_buf_data);
  833. debug->buffer = _dump_buf_data;
  834. if (!debug->buffer) {
  835. kfree(debug);
  836. goto out;
  837. }
  838. debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
  839. file->private_data = debug;
  840. rc = 0;
  841. out:
  842. return rc;
  843. }
  844. static int
  845. lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
  846. {
  847. struct lpfc_debug *debug;
  848. int rc = -ENOMEM;
  849. if (!_dump_buf_dif)
  850. return -EBUSY;
  851. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  852. if (!debug)
  853. goto out;
  854. /* Round to page boundry */
  855. printk(KERN_ERR "BLKGRD %s: _dump_buf_dif=0x%p file=%s\n", __func__,
  856. _dump_buf_dif, file->f_dentry->d_name.name);
  857. debug->buffer = _dump_buf_dif;
  858. if (!debug->buffer) {
  859. kfree(debug);
  860. goto out;
  861. }
  862. debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
  863. file->private_data = debug;
  864. rc = 0;
  865. out:
  866. return rc;
  867. }
  868. static ssize_t
  869. lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
  870. size_t nbytes, loff_t *ppos)
  871. {
  872. /*
  873. * The Data/DIF buffers only save one failing IO
  874. * The write op is used as a reset mechanism after an IO has
  875. * already been saved to the next one can be saved
  876. */
  877. spin_lock(&_dump_buf_lock);
  878. memset((void *)_dump_buf_data, 0,
  879. ((1 << PAGE_SHIFT) << _dump_buf_data_order));
  880. memset((void *)_dump_buf_dif, 0,
  881. ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
  882. _dump_buf_done = 0;
  883. spin_unlock(&_dump_buf_lock);
  884. return nbytes;
  885. }
  886. /**
  887. * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
  888. * @inode: The inode pointer that contains a vport pointer.
  889. * @file: The file pointer to attach the log output.
  890. *
  891. * Description:
  892. * This routine is the entry point for the debugfs open file operation. It gets
  893. * the vport from the i_private field in @inode, allocates the necessary buffer
  894. * for the log, fills the buffer from the in-memory log for this vport, and then
  895. * returns a pointer to that log in the private_data field in @file.
  896. *
  897. * Returns:
  898. * This function returns zero if successful. On error it will return an negative
  899. * error value.
  900. **/
  901. static int
  902. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  903. {
  904. struct lpfc_vport *vport = inode->i_private;
  905. struct lpfc_debug *debug;
  906. int rc = -ENOMEM;
  907. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  908. if (!debug)
  909. goto out;
  910. /* Round to page boundary */
  911. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  912. if (!debug->buffer) {
  913. kfree(debug);
  914. goto out;
  915. }
  916. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  917. LPFC_NODELIST_SIZE);
  918. file->private_data = debug;
  919. rc = 0;
  920. out:
  921. return rc;
  922. }
  923. /**
  924. * lpfc_debugfs_lseek - Seek through a debugfs file
  925. * @file: The file pointer to seek through.
  926. * @off: The offset to seek to or the amount to seek by.
  927. * @whence: Indicates how to seek.
  928. *
  929. * Description:
  930. * This routine is the entry point for the debugfs lseek file operation. The
  931. * @whence parameter indicates whether @off is the offset to directly seek to,
  932. * or if it is a value to seek forward or reverse by. This function figures out
  933. * what the new offset of the debugfs file will be and assigns that value to the
  934. * f_pos field of @file.
  935. *
  936. * Returns:
  937. * This function returns the new offset if successful and returns a negative
  938. * error if unable to process the seek.
  939. **/
  940. static loff_t
  941. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  942. {
  943. struct lpfc_debug *debug;
  944. loff_t pos = -1;
  945. debug = file->private_data;
  946. switch (whence) {
  947. case 0:
  948. pos = off;
  949. break;
  950. case 1:
  951. pos = file->f_pos + off;
  952. break;
  953. case 2:
  954. pos = debug->len - off;
  955. }
  956. return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
  957. }
  958. /**
  959. * lpfc_debugfs_read - Read a debugfs file
  960. * @file: The file pointer to read from.
  961. * @buf: The buffer to copy the data to.
  962. * @nbytes: The number of bytes to read.
  963. * @ppos: The position in the file to start reading from.
  964. *
  965. * Description:
  966. * This routine reads data from from the buffer indicated in the private_data
  967. * field of @file. It will start reading at @ppos and copy up to @nbytes of
  968. * data to @buf.
  969. *
  970. * Returns:
  971. * This function returns the amount of data that was read (this could be less
  972. * than @nbytes if the end of the file was reached) or a negative error value.
  973. **/
  974. static ssize_t
  975. lpfc_debugfs_read(struct file *file, char __user *buf,
  976. size_t nbytes, loff_t *ppos)
  977. {
  978. struct lpfc_debug *debug = file->private_data;
  979. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  980. debug->len);
  981. }
  982. /**
  983. * lpfc_debugfs_release - Release the buffer used to store debugfs file data
  984. * @inode: The inode pointer that contains a vport pointer. (unused)
  985. * @file: The file pointer that contains the buffer to release.
  986. *
  987. * Description:
  988. * This routine frees the buffer that was allocated when the debugfs file was
  989. * opened.
  990. *
  991. * Returns:
  992. * This function returns zero.
  993. **/
  994. static int
  995. lpfc_debugfs_release(struct inode *inode, struct file *file)
  996. {
  997. struct lpfc_debug *debug = file->private_data;
  998. kfree(debug->buffer);
  999. kfree(debug);
  1000. return 0;
  1001. }
  1002. static int
  1003. lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
  1004. {
  1005. struct lpfc_debug *debug = file->private_data;
  1006. debug->buffer = NULL;
  1007. kfree(debug);
  1008. return 0;
  1009. }
  1010. #undef lpfc_debugfs_op_disc_trc
  1011. static const struct file_operations lpfc_debugfs_op_disc_trc = {
  1012. .owner = THIS_MODULE,
  1013. .open = lpfc_debugfs_disc_trc_open,
  1014. .llseek = lpfc_debugfs_lseek,
  1015. .read = lpfc_debugfs_read,
  1016. .release = lpfc_debugfs_release,
  1017. };
  1018. #undef lpfc_debugfs_op_nodelist
  1019. static const struct file_operations lpfc_debugfs_op_nodelist = {
  1020. .owner = THIS_MODULE,
  1021. .open = lpfc_debugfs_nodelist_open,
  1022. .llseek = lpfc_debugfs_lseek,
  1023. .read = lpfc_debugfs_read,
  1024. .release = lpfc_debugfs_release,
  1025. };
  1026. #undef lpfc_debugfs_op_hbqinfo
  1027. static const struct file_operations lpfc_debugfs_op_hbqinfo = {
  1028. .owner = THIS_MODULE,
  1029. .open = lpfc_debugfs_hbqinfo_open,
  1030. .llseek = lpfc_debugfs_lseek,
  1031. .read = lpfc_debugfs_read,
  1032. .release = lpfc_debugfs_release,
  1033. };
  1034. #undef lpfc_debugfs_op_dumpHBASlim
  1035. static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  1036. .owner = THIS_MODULE,
  1037. .open = lpfc_debugfs_dumpHBASlim_open,
  1038. .llseek = lpfc_debugfs_lseek,
  1039. .read = lpfc_debugfs_read,
  1040. .release = lpfc_debugfs_release,
  1041. };
  1042. #undef lpfc_debugfs_op_dumpHostSlim
  1043. static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  1044. .owner = THIS_MODULE,
  1045. .open = lpfc_debugfs_dumpHostSlim_open,
  1046. .llseek = lpfc_debugfs_lseek,
  1047. .read = lpfc_debugfs_read,
  1048. .release = lpfc_debugfs_release,
  1049. };
  1050. #undef lpfc_debugfs_op_dumpData
  1051. static const struct file_operations lpfc_debugfs_op_dumpData = {
  1052. .owner = THIS_MODULE,
  1053. .open = lpfc_debugfs_dumpData_open,
  1054. .llseek = lpfc_debugfs_lseek,
  1055. .read = lpfc_debugfs_read,
  1056. .write = lpfc_debugfs_dumpDataDif_write,
  1057. .release = lpfc_debugfs_dumpDataDif_release,
  1058. };
  1059. #undef lpfc_debugfs_op_dumpDif
  1060. static const struct file_operations lpfc_debugfs_op_dumpDif = {
  1061. .owner = THIS_MODULE,
  1062. .open = lpfc_debugfs_dumpDif_open,
  1063. .llseek = lpfc_debugfs_lseek,
  1064. .read = lpfc_debugfs_read,
  1065. .write = lpfc_debugfs_dumpDataDif_write,
  1066. .release = lpfc_debugfs_dumpDataDif_release,
  1067. };
  1068. #undef lpfc_debugfs_op_slow_ring_trc
  1069. static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  1070. .owner = THIS_MODULE,
  1071. .open = lpfc_debugfs_slow_ring_trc_open,
  1072. .llseek = lpfc_debugfs_lseek,
  1073. .read = lpfc_debugfs_read,
  1074. .release = lpfc_debugfs_release,
  1075. };
  1076. static struct dentry *lpfc_debugfs_root = NULL;
  1077. static atomic_t lpfc_debugfs_hba_count;
  1078. #endif
  1079. /**
  1080. * lpfc_debugfs_initialize - Initialize debugfs for a vport
  1081. * @vport: The vport pointer to initialize.
  1082. *
  1083. * Description:
  1084. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  1085. * If not already created, this routine will create the lpfc directory, and
  1086. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  1087. * also create each file used to access lpfc specific debugfs information.
  1088. **/
  1089. inline void
  1090. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  1091. {
  1092. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1093. struct lpfc_hba *phba = vport->phba;
  1094. char name[64];
  1095. uint32_t num, i;
  1096. if (!lpfc_debugfs_enable)
  1097. return;
  1098. /* Setup lpfc root directory */
  1099. if (!lpfc_debugfs_root) {
  1100. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  1101. atomic_set(&lpfc_debugfs_hba_count, 0);
  1102. if (!lpfc_debugfs_root) {
  1103. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1104. "0408 Cannot create debugfs root\n");
  1105. goto debug_failed;
  1106. }
  1107. }
  1108. if (!lpfc_debugfs_start_time)
  1109. lpfc_debugfs_start_time = jiffies;
  1110. /* Setup lpfcX directory for specific HBA */
  1111. snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
  1112. if (!phba->hba_debugfs_root) {
  1113. phba->hba_debugfs_root =
  1114. debugfs_create_dir(name, lpfc_debugfs_root);
  1115. if (!phba->hba_debugfs_root) {
  1116. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1117. "0412 Cannot create debugfs hba\n");
  1118. goto debug_failed;
  1119. }
  1120. atomic_inc(&lpfc_debugfs_hba_count);
  1121. atomic_set(&phba->debugfs_vport_count, 0);
  1122. /* Setup hbqinfo */
  1123. snprintf(name, sizeof(name), "hbqinfo");
  1124. phba->debug_hbqinfo =
  1125. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1126. phba->hba_debugfs_root,
  1127. phba, &lpfc_debugfs_op_hbqinfo);
  1128. if (!phba->debug_hbqinfo) {
  1129. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1130. "0411 Cannot create debugfs hbqinfo\n");
  1131. goto debug_failed;
  1132. }
  1133. /* Setup dumpHBASlim */
  1134. snprintf(name, sizeof(name), "dumpHBASlim");
  1135. phba->debug_dumpHBASlim =
  1136. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1137. phba->hba_debugfs_root,
  1138. phba, &lpfc_debugfs_op_dumpHBASlim);
  1139. if (!phba->debug_dumpHBASlim) {
  1140. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1141. "0413 Cannot create debugfs dumpHBASlim\n");
  1142. goto debug_failed;
  1143. }
  1144. /* Setup dumpHostSlim */
  1145. snprintf(name, sizeof(name), "dumpHostSlim");
  1146. phba->debug_dumpHostSlim =
  1147. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1148. phba->hba_debugfs_root,
  1149. phba, &lpfc_debugfs_op_dumpHostSlim);
  1150. if (!phba->debug_dumpHostSlim) {
  1151. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1152. "0414 Cannot create debugfs dumpHostSlim\n");
  1153. goto debug_failed;
  1154. }
  1155. /* Setup dumpData */
  1156. snprintf(name, sizeof(name), "dumpData");
  1157. phba->debug_dumpData =
  1158. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1159. phba->hba_debugfs_root,
  1160. phba, &lpfc_debugfs_op_dumpData);
  1161. if (!phba->debug_dumpData) {
  1162. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1163. "0800 Cannot create debugfs dumpData\n");
  1164. goto debug_failed;
  1165. }
  1166. /* Setup dumpDif */
  1167. snprintf(name, sizeof(name), "dumpDif");
  1168. phba->debug_dumpDif =
  1169. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1170. phba->hba_debugfs_root,
  1171. phba, &lpfc_debugfs_op_dumpDif);
  1172. if (!phba->debug_dumpDif) {
  1173. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1174. "0801 Cannot create debugfs dumpDif\n");
  1175. goto debug_failed;
  1176. }
  1177. /* Setup slow ring trace */
  1178. if (lpfc_debugfs_max_slow_ring_trc) {
  1179. num = lpfc_debugfs_max_slow_ring_trc - 1;
  1180. if (num & lpfc_debugfs_max_slow_ring_trc) {
  1181. /* Change to be a power of 2 */
  1182. num = lpfc_debugfs_max_slow_ring_trc;
  1183. i = 0;
  1184. while (num > 1) {
  1185. num = num >> 1;
  1186. i++;
  1187. }
  1188. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  1189. printk(KERN_ERR
  1190. "lpfc_debugfs_max_disc_trc changed to "
  1191. "%d\n", lpfc_debugfs_max_disc_trc);
  1192. }
  1193. }
  1194. snprintf(name, sizeof(name), "slow_ring_trace");
  1195. phba->debug_slow_ring_trc =
  1196. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1197. phba->hba_debugfs_root,
  1198. phba, &lpfc_debugfs_op_slow_ring_trc);
  1199. if (!phba->debug_slow_ring_trc) {
  1200. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1201. "0415 Cannot create debugfs "
  1202. "slow_ring_trace\n");
  1203. goto debug_failed;
  1204. }
  1205. if (!phba->slow_ring_trc) {
  1206. phba->slow_ring_trc = kmalloc(
  1207. (sizeof(struct lpfc_debugfs_trc) *
  1208. lpfc_debugfs_max_slow_ring_trc),
  1209. GFP_KERNEL);
  1210. if (!phba->slow_ring_trc) {
  1211. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1212. "0416 Cannot create debugfs "
  1213. "slow_ring buffer\n");
  1214. goto debug_failed;
  1215. }
  1216. atomic_set(&phba->slow_ring_trc_cnt, 0);
  1217. memset(phba->slow_ring_trc, 0,
  1218. (sizeof(struct lpfc_debugfs_trc) *
  1219. lpfc_debugfs_max_slow_ring_trc));
  1220. }
  1221. }
  1222. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  1223. if (!vport->vport_debugfs_root) {
  1224. vport->vport_debugfs_root =
  1225. debugfs_create_dir(name, phba->hba_debugfs_root);
  1226. if (!vport->vport_debugfs_root) {
  1227. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1228. "0417 Cant create debugfs");
  1229. goto debug_failed;
  1230. }
  1231. atomic_inc(&phba->debugfs_vport_count);
  1232. }
  1233. if (lpfc_debugfs_max_disc_trc) {
  1234. num = lpfc_debugfs_max_disc_trc - 1;
  1235. if (num & lpfc_debugfs_max_disc_trc) {
  1236. /* Change to be a power of 2 */
  1237. num = lpfc_debugfs_max_disc_trc;
  1238. i = 0;
  1239. while (num > 1) {
  1240. num = num >> 1;
  1241. i++;
  1242. }
  1243. lpfc_debugfs_max_disc_trc = (1 << i);
  1244. printk(KERN_ERR
  1245. "lpfc_debugfs_max_disc_trc changed to %d\n",
  1246. lpfc_debugfs_max_disc_trc);
  1247. }
  1248. }
  1249. vport->disc_trc = kzalloc(
  1250. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  1251. GFP_KERNEL);
  1252. if (!vport->disc_trc) {
  1253. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1254. "0418 Cannot create debugfs disc trace "
  1255. "buffer\n");
  1256. goto debug_failed;
  1257. }
  1258. atomic_set(&vport->disc_trc_cnt, 0);
  1259. snprintf(name, sizeof(name), "discovery_trace");
  1260. vport->debug_disc_trc =
  1261. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1262. vport->vport_debugfs_root,
  1263. vport, &lpfc_debugfs_op_disc_trc);
  1264. if (!vport->debug_disc_trc) {
  1265. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1266. "0419 Cannot create debugfs "
  1267. "discovery_trace\n");
  1268. goto debug_failed;
  1269. }
  1270. snprintf(name, sizeof(name), "nodelist");
  1271. vport->debug_nodelist =
  1272. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1273. vport->vport_debugfs_root,
  1274. vport, &lpfc_debugfs_op_nodelist);
  1275. if (!vport->debug_nodelist) {
  1276. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1277. "0409 Cant create debugfs nodelist");
  1278. goto debug_failed;
  1279. }
  1280. debug_failed:
  1281. return;
  1282. #endif
  1283. }
  1284. /**
  1285. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
  1286. * @vport: The vport pointer to remove from debugfs.
  1287. *
  1288. * Description:
  1289. * When Debugfs is configured this routine removes debugfs file system elements
  1290. * that are specific to this vport. It also checks to see if there are any
  1291. * users left for the debugfs directories associated with the HBA and driver. If
  1292. * this is the last user of the HBA directory or driver directory then it will
  1293. * remove those from the debugfs infrastructure as well.
  1294. **/
  1295. inline void
  1296. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  1297. {
  1298. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1299. struct lpfc_hba *phba = vport->phba;
  1300. if (vport->disc_trc) {
  1301. kfree(vport->disc_trc);
  1302. vport->disc_trc = NULL;
  1303. }
  1304. if (vport->debug_disc_trc) {
  1305. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  1306. vport->debug_disc_trc = NULL;
  1307. }
  1308. if (vport->debug_nodelist) {
  1309. debugfs_remove(vport->debug_nodelist); /* nodelist */
  1310. vport->debug_nodelist = NULL;
  1311. }
  1312. if (vport->vport_debugfs_root) {
  1313. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  1314. vport->vport_debugfs_root = NULL;
  1315. atomic_dec(&phba->debugfs_vport_count);
  1316. }
  1317. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  1318. if (phba->debug_hbqinfo) {
  1319. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  1320. phba->debug_hbqinfo = NULL;
  1321. }
  1322. if (phba->debug_dumpHBASlim) {
  1323. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  1324. phba->debug_dumpHBASlim = NULL;
  1325. }
  1326. if (phba->debug_dumpHostSlim) {
  1327. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  1328. phba->debug_dumpHostSlim = NULL;
  1329. }
  1330. if (phba->debug_dumpData) {
  1331. debugfs_remove(phba->debug_dumpData); /* dumpData */
  1332. phba->debug_dumpData = NULL;
  1333. }
  1334. if (phba->debug_dumpDif) {
  1335. debugfs_remove(phba->debug_dumpDif); /* dumpDif */
  1336. phba->debug_dumpDif = NULL;
  1337. }
  1338. if (phba->slow_ring_trc) {
  1339. kfree(phba->slow_ring_trc);
  1340. phba->slow_ring_trc = NULL;
  1341. }
  1342. if (phba->debug_slow_ring_trc) {
  1343. /* slow_ring_trace */
  1344. debugfs_remove(phba->debug_slow_ring_trc);
  1345. phba->debug_slow_ring_trc = NULL;
  1346. }
  1347. if (phba->hba_debugfs_root) {
  1348. debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
  1349. phba->hba_debugfs_root = NULL;
  1350. atomic_dec(&lpfc_debugfs_hba_count);
  1351. }
  1352. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  1353. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  1354. lpfc_debugfs_root = NULL;
  1355. }
  1356. }
  1357. #endif
  1358. return;
  1359. }