lpfc_debugfs.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2007-2011 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * *
  8. * This program is free software; you can redistribute it and/or *
  9. * modify it under the terms of version 2 of the GNU General *
  10. * Public License as published by the Free Software Foundation. *
  11. * This program is distributed in the hope that it will be useful. *
  12. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  13. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  14. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  15. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  16. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  17. * more details, a copy of which can be found in the file COPYING *
  18. * included with this package. *
  19. *******************************************************************/
  20. #include <linux/blkdev.h>
  21. #include <linux/delay.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/idr.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/kthread.h>
  26. #include <linux/slab.h>
  27. #include <linux/pci.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/ctype.h>
  30. #include <scsi/scsi.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include "lpfc_hw4.h"
  35. #include "lpfc_hw.h"
  36. #include "lpfc_sli.h"
  37. #include "lpfc_sli4.h"
  38. #include "lpfc_nl.h"
  39. #include "lpfc_disc.h"
  40. #include "lpfc_scsi.h"
  41. #include "lpfc.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_crtn.h"
  44. #include "lpfc_vport.h"
  45. #include "lpfc_version.h"
  46. #include "lpfc_compat.h"
  47. #include "lpfc_debugfs.h"
  48. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  49. /*
  50. * debugfs interface
  51. *
  52. * To access this interface the user should:
  53. * # mount -t debugfs none /sys/kernel/debug
  54. *
  55. * The lpfc debugfs directory hierarchy is:
  56. * /sys/kernel/debug/lpfc/fnX/vportY
  57. * where X is the lpfc hba function unique_id
  58. * where Y is the vport VPI on that hba
  59. *
  60. * Debugging services available per vport:
  61. * discovery_trace
  62. * This is an ACSII readable file that contains a trace of the last
  63. * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
  64. * See lpfc_debugfs.h for different categories of discovery events.
  65. * To enable the discovery trace, the following module parameters must be set:
  66. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  67. * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
  68. * EACH vport. X MUST also be a power of 2.
  69. * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
  70. * lpfc_debugfs.h .
  71. *
  72. * slow_ring_trace
  73. * This is an ACSII readable file that contains a trace of the last
  74. * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
  75. * To enable the slow ring trace, the following module parameters must be set:
  76. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  77. * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
  78. * the HBA. X MUST also be a power of 2.
  79. */
  80. static int lpfc_debugfs_enable = 1;
  81. module_param(lpfc_debugfs_enable, int, S_IRUGO);
  82. MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
  83. /* This MUST be a power of 2 */
  84. static int lpfc_debugfs_max_disc_trc;
  85. module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
  86. MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
  87. "Set debugfs discovery trace depth");
  88. /* This MUST be a power of 2 */
  89. static int lpfc_debugfs_max_slow_ring_trc;
  90. module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
  91. MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
  92. "Set debugfs slow ring trace depth");
  93. static int lpfc_debugfs_mask_disc_trc;
  94. module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
  95. MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
  96. "Set debugfs discovery trace mask");
  97. #include <linux/debugfs.h>
  98. static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  99. static unsigned long lpfc_debugfs_start_time = 0L;
  100. /* iDiag */
  101. static struct lpfc_idiag idiag;
  102. /**
  103. * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
  104. * @vport: The vport to gather the log info from.
  105. * @buf: The buffer to dump log into.
  106. * @size: The maximum amount of data to process.
  107. *
  108. * Description:
  109. * This routine gathers the lpfc discovery debugfs data from the @vport and
  110. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  111. * in the log and process the log until the end of the buffer. Then it will
  112. * gather from the beginning of the log and process until the current entry.
  113. *
  114. * Notes:
  115. * Discovery logging will be disabled while while this routine dumps the log.
  116. *
  117. * Return Value:
  118. * This routine returns the amount of bytes that were dumped into @buf and will
  119. * not exceed @size.
  120. **/
  121. static int
  122. lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
  123. {
  124. int i, index, len, enable;
  125. uint32_t ms;
  126. struct lpfc_debugfs_trc *dtp;
  127. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  128. enable = lpfc_debugfs_enable;
  129. lpfc_debugfs_enable = 0;
  130. len = 0;
  131. index = (atomic_read(&vport->disc_trc_cnt) + 1) &
  132. (lpfc_debugfs_max_disc_trc - 1);
  133. for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
  134. dtp = vport->disc_trc + i;
  135. if (!dtp->fmt)
  136. continue;
  137. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  138. snprintf(buffer,
  139. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  140. dtp->seq_cnt, ms, dtp->fmt);
  141. len += snprintf(buf+len, size-len, buffer,
  142. dtp->data1, dtp->data2, dtp->data3);
  143. }
  144. for (i = 0; i < index; 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. lpfc_debugfs_enable = enable;
  156. return len;
  157. }
  158. /**
  159. * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
  160. * @phba: The HBA to gather the log info from.
  161. * @buf: The buffer to dump log into.
  162. * @size: The maximum amount of data to process.
  163. *
  164. * Description:
  165. * This routine gathers the lpfc slow ring debugfs data from the @phba and
  166. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  167. * in the log and process the log until the end of the buffer. Then it will
  168. * gather from the beginning of the log and process until the current entry.
  169. *
  170. * Notes:
  171. * Slow ring logging will be disabled while while this routine dumps the log.
  172. *
  173. * Return Value:
  174. * This routine returns the amount of bytes that were dumped into @buf and will
  175. * not exceed @size.
  176. **/
  177. static int
  178. lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
  179. {
  180. int i, index, len, enable;
  181. uint32_t ms;
  182. struct lpfc_debugfs_trc *dtp;
  183. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  184. enable = lpfc_debugfs_enable;
  185. lpfc_debugfs_enable = 0;
  186. len = 0;
  187. index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
  188. (lpfc_debugfs_max_slow_ring_trc - 1);
  189. for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
  190. dtp = phba->slow_ring_trc + i;
  191. if (!dtp->fmt)
  192. continue;
  193. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  194. snprintf(buffer,
  195. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  196. dtp->seq_cnt, ms, dtp->fmt);
  197. len += snprintf(buf+len, size-len, buffer,
  198. dtp->data1, dtp->data2, dtp->data3);
  199. }
  200. for (i = 0; i < index; 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. lpfc_debugfs_enable = enable;
  212. return len;
  213. }
  214. static int lpfc_debugfs_last_hbq = -1;
  215. /**
  216. * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
  217. * @phba: The HBA to gather host buffer info from.
  218. * @buf: The buffer to dump log into.
  219. * @size: The maximum amount of data to process.
  220. *
  221. * Description:
  222. * This routine dumps the host buffer queue info from the @phba to @buf up to
  223. * @size number of bytes. A header that describes the current hbq state will be
  224. * dumped to @buf first and then info on each hbq entry will be dumped to @buf
  225. * until @size bytes have been dumped or all the hbq info has been dumped.
  226. *
  227. * Notes:
  228. * This routine will rotate through each configured HBQ each time called.
  229. *
  230. * Return Value:
  231. * This routine returns the amount of bytes that were dumped into @buf and will
  232. * not exceed @size.
  233. **/
  234. static int
  235. lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
  236. {
  237. int len = 0;
  238. int cnt, i, j, found, posted, low;
  239. uint32_t phys, raw_index, getidx;
  240. struct lpfc_hbq_init *hip;
  241. struct hbq_s *hbqs;
  242. struct lpfc_hbq_entry *hbqe;
  243. struct lpfc_dmabuf *d_buf;
  244. struct hbq_dmabuf *hbq_buf;
  245. if (phba->sli_rev != 3)
  246. return 0;
  247. cnt = LPFC_HBQINFO_SIZE;
  248. spin_lock_irq(&phba->hbalock);
  249. /* toggle between multiple hbqs, if any */
  250. i = lpfc_sli_hbq_count();
  251. if (i > 1) {
  252. lpfc_debugfs_last_hbq++;
  253. if (lpfc_debugfs_last_hbq >= i)
  254. lpfc_debugfs_last_hbq = 0;
  255. }
  256. else
  257. lpfc_debugfs_last_hbq = 0;
  258. i = lpfc_debugfs_last_hbq;
  259. len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
  260. hbqs = &phba->hbqs[i];
  261. posted = 0;
  262. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
  263. posted++;
  264. hip = lpfc_hbq_defs[i];
  265. len += snprintf(buf+len, size-len,
  266. "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
  267. hip->hbq_index, hip->profile, hip->rn,
  268. hip->buffer_count, hip->init_count, hip->add_count, posted);
  269. raw_index = phba->hbq_get[i];
  270. getidx = le32_to_cpu(raw_index);
  271. len += snprintf(buf+len, size-len,
  272. "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
  273. hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
  274. hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
  275. hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
  276. for (j=0; j<hbqs->entry_count; j++) {
  277. len += snprintf(buf+len, size-len,
  278. "%03d: %08x %04x %05x ", j,
  279. le32_to_cpu(hbqe->bde.addrLow),
  280. le32_to_cpu(hbqe->bde.tus.w),
  281. le32_to_cpu(hbqe->buffer_tag));
  282. i = 0;
  283. found = 0;
  284. /* First calculate if slot has an associated posted buffer */
  285. low = hbqs->hbqPutIdx - posted;
  286. if (low >= 0) {
  287. if ((j >= hbqs->hbqPutIdx) || (j < low)) {
  288. len += snprintf(buf+len, size-len, "Unused\n");
  289. goto skipit;
  290. }
  291. }
  292. else {
  293. if ((j >= hbqs->hbqPutIdx) &&
  294. (j < (hbqs->entry_count+low))) {
  295. len += snprintf(buf+len, size-len, "Unused\n");
  296. goto skipit;
  297. }
  298. }
  299. /* Get the Buffer info for the posted buffer */
  300. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
  301. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  302. phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
  303. if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
  304. len += snprintf(buf+len, size-len,
  305. "Buf%d: %p %06x\n", i,
  306. hbq_buf->dbuf.virt, hbq_buf->tag);
  307. found = 1;
  308. break;
  309. }
  310. i++;
  311. }
  312. if (!found) {
  313. len += snprintf(buf+len, size-len, "No DMAinfo?\n");
  314. }
  315. skipit:
  316. hbqe++;
  317. if (len > LPFC_HBQINFO_SIZE - 54)
  318. break;
  319. }
  320. spin_unlock_irq(&phba->hbalock);
  321. return len;
  322. }
  323. static int lpfc_debugfs_last_hba_slim_off;
  324. /**
  325. * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
  326. * @phba: The HBA to gather SLIM info from.
  327. * @buf: The buffer to dump log into.
  328. * @size: The maximum amount of data to process.
  329. *
  330. * Description:
  331. * This routine dumps the current contents of HBA SLIM for the HBA associated
  332. * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
  333. *
  334. * Notes:
  335. * This routine will only dump up to 1024 bytes of data each time called and
  336. * should be called multiple times to dump the entire HBA SLIM.
  337. *
  338. * Return Value:
  339. * This routine returns the amount of bytes that were dumped into @buf and will
  340. * not exceed @size.
  341. **/
  342. static int
  343. lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
  344. {
  345. int len = 0;
  346. int i, off;
  347. uint32_t *ptr;
  348. char buffer[1024];
  349. off = 0;
  350. spin_lock_irq(&phba->hbalock);
  351. len += snprintf(buf+len, size-len, "HBA SLIM\n");
  352. lpfc_memcpy_from_slim(buffer,
  353. phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
  354. ptr = (uint32_t *)&buffer[0];
  355. off = lpfc_debugfs_last_hba_slim_off;
  356. /* Set it up for the next time */
  357. lpfc_debugfs_last_hba_slim_off += 1024;
  358. if (lpfc_debugfs_last_hba_slim_off >= 4096)
  359. lpfc_debugfs_last_hba_slim_off = 0;
  360. i = 1024;
  361. while (i > 0) {
  362. len += snprintf(buf+len, size-len,
  363. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  364. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  365. *(ptr+5), *(ptr+6), *(ptr+7));
  366. ptr += 8;
  367. i -= (8 * sizeof(uint32_t));
  368. off += (8 * sizeof(uint32_t));
  369. }
  370. spin_unlock_irq(&phba->hbalock);
  371. return len;
  372. }
  373. /**
  374. * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
  375. * @phba: The HBA to gather Host SLIM info from.
  376. * @buf: The buffer to dump log into.
  377. * @size: The maximum amount of data to process.
  378. *
  379. * Description:
  380. * This routine dumps the current contents of host SLIM for the host associated
  381. * with @phba to @buf up to @size bytes of data. The dump will contain the
  382. * Mailbox, PCB, Rings, and Registers that are located in host memory.
  383. *
  384. * Return Value:
  385. * This routine returns the amount of bytes that were dumped into @buf and will
  386. * not exceed @size.
  387. **/
  388. static int
  389. lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
  390. {
  391. int len = 0;
  392. int i, off;
  393. uint32_t word0, word1, word2, word3;
  394. uint32_t *ptr;
  395. struct lpfc_pgp *pgpp;
  396. struct lpfc_sli *psli = &phba->sli;
  397. struct lpfc_sli_ring *pring;
  398. off = 0;
  399. spin_lock_irq(&phba->hbalock);
  400. len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
  401. ptr = (uint32_t *)phba->slim2p.virt;
  402. i = sizeof(MAILBOX_t);
  403. while (i > 0) {
  404. len += snprintf(buf+len, size-len,
  405. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  406. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  407. *(ptr+5), *(ptr+6), *(ptr+7));
  408. ptr += 8;
  409. i -= (8 * sizeof(uint32_t));
  410. off += (8 * sizeof(uint32_t));
  411. }
  412. len += snprintf(buf+len, size-len, "SLIM PCB\n");
  413. ptr = (uint32_t *)phba->pcb;
  414. i = sizeof(PCB_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. for (i = 0; i < 4; i++) {
  425. pgpp = &phba->port_gp[i];
  426. pring = &psli->ring[i];
  427. len += snprintf(buf+len, size-len,
  428. "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
  429. "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
  430. i, pgpp->cmdGetInx, pring->numCiocb,
  431. pring->next_cmdidx, pring->local_getidx,
  432. pring->flag, pgpp->rspPutInx, pring->numRiocb);
  433. }
  434. if (phba->sli_rev <= LPFC_SLI_REV3) {
  435. word0 = readl(phba->HAregaddr);
  436. word1 = readl(phba->CAregaddr);
  437. word2 = readl(phba->HSregaddr);
  438. word3 = readl(phba->HCregaddr);
  439. len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
  440. "HC:%08x\n", word0, word1, word2, word3);
  441. }
  442. spin_unlock_irq(&phba->hbalock);
  443. return len;
  444. }
  445. /**
  446. * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
  447. * @vport: The vport to gather target node info from.
  448. * @buf: The buffer to dump log into.
  449. * @size: The maximum amount of data to process.
  450. *
  451. * Description:
  452. * This routine dumps the current target node list associated with @vport to
  453. * @buf up to @size bytes of data. Each node entry in the dump will contain a
  454. * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
  455. *
  456. * Return Value:
  457. * This routine returns the amount of bytes that were dumped into @buf and will
  458. * not exceed @size.
  459. **/
  460. static int
  461. lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
  462. {
  463. int len = 0;
  464. int cnt;
  465. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  466. struct lpfc_nodelist *ndlp;
  467. unsigned char *statep, *name;
  468. cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
  469. spin_lock_irq(shost->host_lock);
  470. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  471. if (!cnt) {
  472. len += snprintf(buf+len, size-len,
  473. "Missing Nodelist Entries\n");
  474. break;
  475. }
  476. cnt--;
  477. switch (ndlp->nlp_state) {
  478. case NLP_STE_UNUSED_NODE:
  479. statep = "UNUSED";
  480. break;
  481. case NLP_STE_PLOGI_ISSUE:
  482. statep = "PLOGI ";
  483. break;
  484. case NLP_STE_ADISC_ISSUE:
  485. statep = "ADISC ";
  486. break;
  487. case NLP_STE_REG_LOGIN_ISSUE:
  488. statep = "REGLOG";
  489. break;
  490. case NLP_STE_PRLI_ISSUE:
  491. statep = "PRLI ";
  492. break;
  493. case NLP_STE_UNMAPPED_NODE:
  494. statep = "UNMAP ";
  495. break;
  496. case NLP_STE_MAPPED_NODE:
  497. statep = "MAPPED";
  498. break;
  499. case NLP_STE_NPR_NODE:
  500. statep = "NPR ";
  501. break;
  502. default:
  503. statep = "UNKNOWN";
  504. }
  505. len += snprintf(buf+len, size-len, "%s DID:x%06x ",
  506. statep, ndlp->nlp_DID);
  507. name = (unsigned char *)&ndlp->nlp_portname;
  508. len += snprintf(buf+len, size-len,
  509. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  510. *name, *(name+1), *(name+2), *(name+3),
  511. *(name+4), *(name+5), *(name+6), *(name+7));
  512. name = (unsigned char *)&ndlp->nlp_nodename;
  513. len += snprintf(buf+len, size-len,
  514. "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  515. *name, *(name+1), *(name+2), *(name+3),
  516. *(name+4), *(name+5), *(name+6), *(name+7));
  517. len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
  518. ndlp->nlp_rpi, ndlp->nlp_flag);
  519. if (!ndlp->nlp_type)
  520. len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
  521. if (ndlp->nlp_type & NLP_FC_NODE)
  522. len += snprintf(buf+len, size-len, "FC_NODE ");
  523. if (ndlp->nlp_type & NLP_FABRIC)
  524. len += snprintf(buf+len, size-len, "FABRIC ");
  525. if (ndlp->nlp_type & NLP_FCP_TARGET)
  526. len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
  527. ndlp->nlp_sid);
  528. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  529. len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
  530. len += snprintf(buf+len, size-len, "usgmap:%x ",
  531. ndlp->nlp_usg_map);
  532. len += snprintf(buf+len, size-len, "refcnt:%x",
  533. atomic_read(&ndlp->kref.refcount));
  534. len += snprintf(buf+len, size-len, "\n");
  535. }
  536. spin_unlock_irq(shost->host_lock);
  537. return len;
  538. }
  539. #endif
  540. /**
  541. * lpfc_debugfs_disc_trc - Store discovery trace log
  542. * @vport: The vport to associate this trace string with for retrieval.
  543. * @mask: Log entry classification.
  544. * @fmt: Format string to be displayed when dumping the log.
  545. * @data1: 1st data parameter to be applied to @fmt.
  546. * @data2: 2nd data parameter to be applied to @fmt.
  547. * @data3: 3rd data parameter to be applied to @fmt.
  548. *
  549. * Description:
  550. * This routine is used by the driver code to add a debugfs log entry to the
  551. * discovery trace buffer associated with @vport. Only entries with a @mask that
  552. * match the current debugfs discovery mask will be saved. Entries that do not
  553. * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
  554. * printf when displaying the log.
  555. **/
  556. inline void
  557. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  558. uint32_t data1, uint32_t data2, uint32_t data3)
  559. {
  560. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  561. struct lpfc_debugfs_trc *dtp;
  562. int index;
  563. if (!(lpfc_debugfs_mask_disc_trc & mask))
  564. return;
  565. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  566. !vport || !vport->disc_trc)
  567. return;
  568. index = atomic_inc_return(&vport->disc_trc_cnt) &
  569. (lpfc_debugfs_max_disc_trc - 1);
  570. dtp = vport->disc_trc + index;
  571. dtp->fmt = fmt;
  572. dtp->data1 = data1;
  573. dtp->data2 = data2;
  574. dtp->data3 = data3;
  575. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  576. dtp->jif = jiffies;
  577. #endif
  578. return;
  579. }
  580. /**
  581. * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
  582. * @phba: The phba to associate this trace string with for retrieval.
  583. * @fmt: Format string to be displayed when dumping the log.
  584. * @data1: 1st data parameter to be applied to @fmt.
  585. * @data2: 2nd data parameter to be applied to @fmt.
  586. * @data3: 3rd data parameter to be applied to @fmt.
  587. *
  588. * Description:
  589. * This routine is used by the driver code to add a debugfs log entry to the
  590. * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
  591. * @data3 are used like printf when displaying the log.
  592. **/
  593. inline void
  594. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  595. uint32_t data1, uint32_t data2, uint32_t data3)
  596. {
  597. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  598. struct lpfc_debugfs_trc *dtp;
  599. int index;
  600. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  601. !phba || !phba->slow_ring_trc)
  602. return;
  603. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  604. (lpfc_debugfs_max_slow_ring_trc - 1);
  605. dtp = phba->slow_ring_trc + index;
  606. dtp->fmt = fmt;
  607. dtp->data1 = data1;
  608. dtp->data2 = data2;
  609. dtp->data3 = data3;
  610. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  611. dtp->jif = jiffies;
  612. #endif
  613. return;
  614. }
  615. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  616. /**
  617. * lpfc_debugfs_disc_trc_open - Open the discovery trace log
  618. * @inode: The inode pointer that contains a vport pointer.
  619. * @file: The file pointer to attach the log output.
  620. *
  621. * Description:
  622. * This routine is the entry point for the debugfs open file operation. It gets
  623. * the vport from the i_private field in @inode, allocates the necessary buffer
  624. * for the log, fills the buffer from the in-memory log for this vport, and then
  625. * returns a pointer to that log in the private_data field in @file.
  626. *
  627. * Returns:
  628. * This function returns zero if successful. On error it will return an negative
  629. * error value.
  630. **/
  631. static int
  632. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  633. {
  634. struct lpfc_vport *vport = inode->i_private;
  635. struct lpfc_debug *debug;
  636. int size;
  637. int rc = -ENOMEM;
  638. if (!lpfc_debugfs_max_disc_trc) {
  639. rc = -ENOSPC;
  640. goto out;
  641. }
  642. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  643. if (!debug)
  644. goto out;
  645. /* Round to page boundary */
  646. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  647. size = PAGE_ALIGN(size);
  648. debug->buffer = kmalloc(size, GFP_KERNEL);
  649. if (!debug->buffer) {
  650. kfree(debug);
  651. goto out;
  652. }
  653. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  654. file->private_data = debug;
  655. rc = 0;
  656. out:
  657. return rc;
  658. }
  659. /**
  660. * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
  661. * @inode: The inode pointer that contains a vport pointer.
  662. * @file: The file pointer to attach the log output.
  663. *
  664. * Description:
  665. * This routine is the entry point for the debugfs open file operation. It gets
  666. * the vport from the i_private field in @inode, allocates the necessary buffer
  667. * for the log, fills the buffer from the in-memory log for this vport, and then
  668. * returns a pointer to that log in the private_data field in @file.
  669. *
  670. * Returns:
  671. * This function returns zero if successful. On error it will return an negative
  672. * error value.
  673. **/
  674. static int
  675. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  676. {
  677. struct lpfc_hba *phba = inode->i_private;
  678. struct lpfc_debug *debug;
  679. int size;
  680. int rc = -ENOMEM;
  681. if (!lpfc_debugfs_max_slow_ring_trc) {
  682. rc = -ENOSPC;
  683. goto out;
  684. }
  685. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  686. if (!debug)
  687. goto out;
  688. /* Round to page boundary */
  689. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  690. size = PAGE_ALIGN(size);
  691. debug->buffer = kmalloc(size, GFP_KERNEL);
  692. if (!debug->buffer) {
  693. kfree(debug);
  694. goto out;
  695. }
  696. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  697. file->private_data = debug;
  698. rc = 0;
  699. out:
  700. return rc;
  701. }
  702. /**
  703. * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
  704. * @inode: The inode pointer that contains a vport pointer.
  705. * @file: The file pointer to attach the log output.
  706. *
  707. * Description:
  708. * This routine is the entry point for the debugfs open file operation. It gets
  709. * the vport from the i_private field in @inode, allocates the necessary buffer
  710. * for the log, fills the buffer from the in-memory log for this vport, and then
  711. * returns a pointer to that log in the private_data field in @file.
  712. *
  713. * Returns:
  714. * This function returns zero if successful. On error it will return an negative
  715. * error value.
  716. **/
  717. static int
  718. lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
  719. {
  720. struct lpfc_hba *phba = inode->i_private;
  721. struct lpfc_debug *debug;
  722. int rc = -ENOMEM;
  723. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  724. if (!debug)
  725. goto out;
  726. /* Round to page boundary */
  727. debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
  728. if (!debug->buffer) {
  729. kfree(debug);
  730. goto out;
  731. }
  732. debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
  733. LPFC_HBQINFO_SIZE);
  734. file->private_data = debug;
  735. rc = 0;
  736. out:
  737. return rc;
  738. }
  739. /**
  740. * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
  741. * @inode: The inode pointer that contains a vport pointer.
  742. * @file: The file pointer to attach the log output.
  743. *
  744. * Description:
  745. * This routine is the entry point for the debugfs open file operation. It gets
  746. * the vport from the i_private field in @inode, allocates the necessary buffer
  747. * for the log, fills the buffer from the in-memory log for this vport, and then
  748. * returns a pointer to that log in the private_data field in @file.
  749. *
  750. * Returns:
  751. * This function returns zero if successful. On error it will return an negative
  752. * error value.
  753. **/
  754. static int
  755. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  756. {
  757. struct lpfc_hba *phba = inode->i_private;
  758. struct lpfc_debug *debug;
  759. int rc = -ENOMEM;
  760. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  761. if (!debug)
  762. goto out;
  763. /* Round to page boundary */
  764. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  765. if (!debug->buffer) {
  766. kfree(debug);
  767. goto out;
  768. }
  769. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  770. LPFC_DUMPHBASLIM_SIZE);
  771. file->private_data = debug;
  772. rc = 0;
  773. out:
  774. return rc;
  775. }
  776. /**
  777. * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
  778. * @inode: The inode pointer that contains a vport pointer.
  779. * @file: The file pointer to attach the log output.
  780. *
  781. * Description:
  782. * This routine is the entry point for the debugfs open file operation. It gets
  783. * the vport from the i_private field in @inode, allocates the necessary buffer
  784. * for the log, fills the buffer from the in-memory log for this vport, and then
  785. * returns a pointer to that log in the private_data field in @file.
  786. *
  787. * Returns:
  788. * This function returns zero if successful. On error it will return an negative
  789. * error value.
  790. **/
  791. static int
  792. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  793. {
  794. struct lpfc_hba *phba = inode->i_private;
  795. struct lpfc_debug *debug;
  796. int rc = -ENOMEM;
  797. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  798. if (!debug)
  799. goto out;
  800. /* Round to page boundary */
  801. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  802. if (!debug->buffer) {
  803. kfree(debug);
  804. goto out;
  805. }
  806. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  807. LPFC_DUMPHOSTSLIM_SIZE);
  808. file->private_data = debug;
  809. rc = 0;
  810. out:
  811. return rc;
  812. }
  813. static int
  814. lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
  815. {
  816. struct lpfc_debug *debug;
  817. int rc = -ENOMEM;
  818. if (!_dump_buf_data)
  819. return -EBUSY;
  820. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  821. if (!debug)
  822. goto out;
  823. /* Round to page boundry */
  824. printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
  825. __func__, _dump_buf_data);
  826. debug->buffer = _dump_buf_data;
  827. if (!debug->buffer) {
  828. kfree(debug);
  829. goto out;
  830. }
  831. debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
  832. file->private_data = debug;
  833. rc = 0;
  834. out:
  835. return rc;
  836. }
  837. static int
  838. lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
  839. {
  840. struct lpfc_debug *debug;
  841. int rc = -ENOMEM;
  842. if (!_dump_buf_dif)
  843. return -EBUSY;
  844. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  845. if (!debug)
  846. goto out;
  847. /* Round to page boundry */
  848. printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
  849. __func__, _dump_buf_dif, file->f_dentry->d_name.name);
  850. debug->buffer = _dump_buf_dif;
  851. if (!debug->buffer) {
  852. kfree(debug);
  853. goto out;
  854. }
  855. debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
  856. file->private_data = debug;
  857. rc = 0;
  858. out:
  859. return rc;
  860. }
  861. static ssize_t
  862. lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
  863. size_t nbytes, loff_t *ppos)
  864. {
  865. /*
  866. * The Data/DIF buffers only save one failing IO
  867. * The write op is used as a reset mechanism after an IO has
  868. * already been saved to the next one can be saved
  869. */
  870. spin_lock(&_dump_buf_lock);
  871. memset((void *)_dump_buf_data, 0,
  872. ((1 << PAGE_SHIFT) << _dump_buf_data_order));
  873. memset((void *)_dump_buf_dif, 0,
  874. ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
  875. _dump_buf_done = 0;
  876. spin_unlock(&_dump_buf_lock);
  877. return nbytes;
  878. }
  879. /**
  880. * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
  881. * @inode: The inode pointer that contains a vport pointer.
  882. * @file: The file pointer to attach the log output.
  883. *
  884. * Description:
  885. * This routine is the entry point for the debugfs open file operation. It gets
  886. * the vport from the i_private field in @inode, allocates the necessary buffer
  887. * for the log, fills the buffer from the in-memory log for this vport, and then
  888. * returns a pointer to that log in the private_data field in @file.
  889. *
  890. * Returns:
  891. * This function returns zero if successful. On error it will return an negative
  892. * error value.
  893. **/
  894. static int
  895. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  896. {
  897. struct lpfc_vport *vport = inode->i_private;
  898. struct lpfc_debug *debug;
  899. int rc = -ENOMEM;
  900. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  901. if (!debug)
  902. goto out;
  903. /* Round to page boundary */
  904. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  905. if (!debug->buffer) {
  906. kfree(debug);
  907. goto out;
  908. }
  909. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  910. LPFC_NODELIST_SIZE);
  911. file->private_data = debug;
  912. rc = 0;
  913. out:
  914. return rc;
  915. }
  916. /**
  917. * lpfc_debugfs_lseek - Seek through a debugfs file
  918. * @file: The file pointer to seek through.
  919. * @off: The offset to seek to or the amount to seek by.
  920. * @whence: Indicates how to seek.
  921. *
  922. * Description:
  923. * This routine is the entry point for the debugfs lseek file operation. The
  924. * @whence parameter indicates whether @off is the offset to directly seek to,
  925. * or if it is a value to seek forward or reverse by. This function figures out
  926. * what the new offset of the debugfs file will be and assigns that value to the
  927. * f_pos field of @file.
  928. *
  929. * Returns:
  930. * This function returns the new offset if successful and returns a negative
  931. * error if unable to process the seek.
  932. **/
  933. static loff_t
  934. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  935. {
  936. struct lpfc_debug *debug;
  937. loff_t pos = -1;
  938. debug = file->private_data;
  939. switch (whence) {
  940. case 0:
  941. pos = off;
  942. break;
  943. case 1:
  944. pos = file->f_pos + off;
  945. break;
  946. case 2:
  947. pos = debug->len - off;
  948. }
  949. return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
  950. }
  951. /**
  952. * lpfc_debugfs_read - Read a debugfs file
  953. * @file: The file pointer to read from.
  954. * @buf: The buffer to copy the data to.
  955. * @nbytes: The number of bytes to read.
  956. * @ppos: The position in the file to start reading from.
  957. *
  958. * Description:
  959. * This routine reads data from from the buffer indicated in the private_data
  960. * field of @file. It will start reading at @ppos and copy up to @nbytes of
  961. * data to @buf.
  962. *
  963. * Returns:
  964. * This function returns the amount of data that was read (this could be less
  965. * than @nbytes if the end of the file was reached) or a negative error value.
  966. **/
  967. static ssize_t
  968. lpfc_debugfs_read(struct file *file, char __user *buf,
  969. size_t nbytes, loff_t *ppos)
  970. {
  971. struct lpfc_debug *debug = file->private_data;
  972. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  973. debug->len);
  974. }
  975. /**
  976. * lpfc_debugfs_release - Release the buffer used to store debugfs file data
  977. * @inode: The inode pointer that contains a vport pointer. (unused)
  978. * @file: The file pointer that contains the buffer to release.
  979. *
  980. * Description:
  981. * This routine frees the buffer that was allocated when the debugfs file was
  982. * opened.
  983. *
  984. * Returns:
  985. * This function returns zero.
  986. **/
  987. static int
  988. lpfc_debugfs_release(struct inode *inode, struct file *file)
  989. {
  990. struct lpfc_debug *debug = file->private_data;
  991. kfree(debug->buffer);
  992. kfree(debug);
  993. return 0;
  994. }
  995. static int
  996. lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
  997. {
  998. struct lpfc_debug *debug = file->private_data;
  999. debug->buffer = NULL;
  1000. kfree(debug);
  1001. return 0;
  1002. }
  1003. /*
  1004. * iDiag debugfs file access methods
  1005. */
  1006. /*
  1007. * iDiag PCI config space register access methods:
  1008. *
  1009. * The PCI config space register accessees of read, write, read-modify-write
  1010. * for set bits, and read-modify-write for clear bits to SLI4 PCI functions
  1011. * are provided. In the proper SLI4 PCI function's debugfs iDiag directory,
  1012. *
  1013. * /sys/kernel/debug/lpfc/fn<#>/iDiag
  1014. *
  1015. * the access is through the debugfs entry pciCfg:
  1016. *
  1017. * 1. For PCI config space register read access, there are two read methods:
  1018. * A) read a single PCI config space register in the size of a byte
  1019. * (8 bits), a word (16 bits), or a dword (32 bits); or B) browse through
  1020. * the 4K extended PCI config space.
  1021. *
  1022. * A) Read a single PCI config space register consists of two steps:
  1023. *
  1024. * Step-1: Set up PCI config space register read command, the command
  1025. * syntax is,
  1026. *
  1027. * echo 1 <where> <count> > pciCfg
  1028. *
  1029. * where, 1 is the iDiag command for PCI config space read, <where> is the
  1030. * offset from the beginning of the device's PCI config space to read from,
  1031. * and <count> is the size of PCI config space register data to read back,
  1032. * it will be 1 for reading a byte (8 bits), 2 for reading a word (16 bits
  1033. * or 2 bytes), or 4 for reading a dword (32 bits or 4 bytes).
  1034. *
  1035. * Setp-2: Perform the debugfs read operation to execute the idiag command
  1036. * set up in Step-1,
  1037. *
  1038. * cat pciCfg
  1039. *
  1040. * Examples:
  1041. * To read PCI device's vendor-id and device-id from PCI config space,
  1042. *
  1043. * echo 1 0 4 > pciCfg
  1044. * cat pciCfg
  1045. *
  1046. * To read PCI device's currnt command from config space,
  1047. *
  1048. * echo 1 4 2 > pciCfg
  1049. * cat pciCfg
  1050. *
  1051. * B) Browse through the entire 4K extended PCI config space also consists
  1052. * of two steps:
  1053. *
  1054. * Step-1: Set up PCI config space register browsing command, the command
  1055. * syntax is,
  1056. *
  1057. * echo 1 0 4096 > pciCfg
  1058. *
  1059. * where, 1 is the iDiag command for PCI config space read, 0 must be used
  1060. * as the offset for PCI config space register browse, and 4096 must be
  1061. * used as the count for PCI config space register browse.
  1062. *
  1063. * Step-2: Repeately issue the debugfs read operation to browse through
  1064. * the entire PCI config space registers:
  1065. *
  1066. * cat pciCfg
  1067. * cat pciCfg
  1068. * cat pciCfg
  1069. * ...
  1070. *
  1071. * When browsing to the end of the 4K PCI config space, the browse method
  1072. * shall wrap around to start reading from beginning again, and again...
  1073. *
  1074. * 2. For PCI config space register write access, it supports a single PCI
  1075. * config space register write in the size of a byte (8 bits), a word
  1076. * (16 bits), or a dword (32 bits). The command syntax is,
  1077. *
  1078. * echo 2 <where> <count> <value> > pciCfg
  1079. *
  1080. * where, 2 is the iDiag command for PCI config space write, <where> is
  1081. * the offset from the beginning of the device's PCI config space to write
  1082. * into, <count> is the size of data to write into the PCI config space,
  1083. * it will be 1 for writing a byte (8 bits), 2 for writing a word (16 bits
  1084. * or 2 bytes), or 4 for writing a dword (32 bits or 4 bytes), and <value>
  1085. * is the data to be written into the PCI config space register at the
  1086. * offset.
  1087. *
  1088. * Examples:
  1089. * To disable PCI device's interrupt assertion,
  1090. *
  1091. * 1) Read in device's PCI config space register command field <cmd>:
  1092. *
  1093. * echo 1 4 2 > pciCfg
  1094. * cat pciCfg
  1095. *
  1096. * 2) Set bit 10 (Interrupt Disable bit) in the <cmd>:
  1097. *
  1098. * <cmd> = <cmd> | (1 < 10)
  1099. *
  1100. * 3) Write the modified command back:
  1101. *
  1102. * echo 2 4 2 <cmd> > pciCfg
  1103. *
  1104. * 3. For PCI config space register set bits access, it supports a single PCI
  1105. * config space register set bits in the size of a byte (8 bits), a word
  1106. * (16 bits), or a dword (32 bits). The command syntax is,
  1107. *
  1108. * echo 3 <where> <count> <bitmask> > pciCfg
  1109. *
  1110. * where, 3 is the iDiag command for PCI config space set bits, <where> is
  1111. * the offset from the beginning of the device's PCI config space to set
  1112. * bits into, <count> is the size of the bitmask to set into the PCI config
  1113. * space, it will be 1 for setting a byte (8 bits), 2 for setting a word
  1114. * (16 bits or 2 bytes), or 4 for setting a dword (32 bits or 4 bytes), and
  1115. * <bitmask> is the bitmask, indicating the bits to be set into the PCI
  1116. * config space register at the offset. The logic performed to the content
  1117. * of the PCI config space register, regval, is,
  1118. *
  1119. * regval |= <bitmask>
  1120. *
  1121. * 4. For PCI config space register clear bits access, it supports a single
  1122. * PCI config space register clear bits in the size of a byte (8 bits),
  1123. * a word (16 bits), or a dword (32 bits). The command syntax is,
  1124. *
  1125. * echo 4 <where> <count> <bitmask> > pciCfg
  1126. *
  1127. * where, 4 is the iDiag command for PCI config space clear bits, <where>
  1128. * is the offset from the beginning of the device's PCI config space to
  1129. * clear bits from, <count> is the size of the bitmask to set into the PCI
  1130. * config space, it will be 1 for setting a byte (8 bits), 2 for setting
  1131. * a word(16 bits or 2 bytes), or 4 for setting a dword (32 bits or 4
  1132. * bytes), and <bitmask> is the bitmask, indicating the bits to be cleared
  1133. * from the PCI config space register at the offset. the logic performed
  1134. * to the content of the PCI config space register, regval, is,
  1135. *
  1136. * regval &= ~<bitmask>
  1137. *
  1138. * Note, for all single register read, write, set bits, or clear bits access,
  1139. * the offset (<where>) must be aligned with the size of the data:
  1140. *
  1141. * For data size of byte (8 bits), the offset must be aligned to the byte
  1142. * boundary; for data size of word (16 bits), the offset must be aligned
  1143. * to the word boundary; while for data size of dword (32 bits), the offset
  1144. * must be aligned to the dword boundary. Otherwise, the interface will
  1145. * return the error:
  1146. *
  1147. * "-bash: echo: write error: Invalid argument".
  1148. *
  1149. * For example:
  1150. *
  1151. * echo 1 2 4 > pciCfg
  1152. * -bash: echo: write error: Invalid argument
  1153. *
  1154. * Note also, all of the numbers in the command fields for all read, write,
  1155. * set bits, and clear bits PCI config space register command fields can be
  1156. * either decimal or hex.
  1157. *
  1158. * For example,
  1159. * echo 1 0 4096 > pciCfg
  1160. *
  1161. * will be the same as
  1162. * echo 1 0 0x1000 > pciCfg
  1163. *
  1164. * And,
  1165. * echo 2 155 1 10 > pciCfg
  1166. *
  1167. * will be
  1168. * echo 2 0x9b 1 0xa > pciCfg
  1169. */
  1170. /**
  1171. * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
  1172. * @buf: The pointer to the user space buffer.
  1173. * @nbytes: The number of bytes in the user space buffer.
  1174. * @idiag_cmd: pointer to the idiag command struct.
  1175. *
  1176. * This routine reads data from debugfs user space buffer and parses the
  1177. * buffer for getting the idiag command and arguments. The while space in
  1178. * between the set of data is used as the parsing separator.
  1179. *
  1180. * This routine returns 0 when successful, it returns proper error code
  1181. * back to the user space in error conditions.
  1182. */
  1183. static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
  1184. struct lpfc_idiag_cmd *idiag_cmd)
  1185. {
  1186. char mybuf[64];
  1187. char *pbuf, *step_str;
  1188. int bsize, i;
  1189. /* Protect copy from user */
  1190. if (!access_ok(VERIFY_READ, buf, nbytes))
  1191. return -EFAULT;
  1192. memset(mybuf, 0, sizeof(mybuf));
  1193. memset(idiag_cmd, 0, sizeof(*idiag_cmd));
  1194. bsize = min(nbytes, (sizeof(mybuf)-1));
  1195. if (copy_from_user(mybuf, buf, bsize))
  1196. return -EFAULT;
  1197. pbuf = &mybuf[0];
  1198. step_str = strsep(&pbuf, "\t ");
  1199. /* The opcode must present */
  1200. if (!step_str)
  1201. return -EINVAL;
  1202. idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
  1203. if (idiag_cmd->opcode == 0)
  1204. return -EINVAL;
  1205. for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
  1206. step_str = strsep(&pbuf, "\t ");
  1207. if (!step_str)
  1208. return 0;
  1209. idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
  1210. }
  1211. return 0;
  1212. }
  1213. /**
  1214. * lpfc_idiag_open - idiag open debugfs
  1215. * @inode: The inode pointer that contains a pointer to phba.
  1216. * @file: The file pointer to attach the file operation.
  1217. *
  1218. * Description:
  1219. * This routine is the entry point for the debugfs open file operation. It
  1220. * gets the reference to phba from the i_private field in @inode, it then
  1221. * allocates buffer for the file operation, performs the necessary PCI config
  1222. * space read into the allocated buffer according to the idiag user command
  1223. * setup, and then returns a pointer to buffer in the private_data field in
  1224. * @file.
  1225. *
  1226. * Returns:
  1227. * This function returns zero if successful. On error it will return an
  1228. * negative error value.
  1229. **/
  1230. static int
  1231. lpfc_idiag_open(struct inode *inode, struct file *file)
  1232. {
  1233. struct lpfc_debug *debug;
  1234. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1235. if (!debug)
  1236. return -ENOMEM;
  1237. debug->i_private = inode->i_private;
  1238. debug->buffer = NULL;
  1239. file->private_data = debug;
  1240. return 0;
  1241. }
  1242. /**
  1243. * lpfc_idiag_release - Release idiag access file operation
  1244. * @inode: The inode pointer that contains a vport pointer. (unused)
  1245. * @file: The file pointer that contains the buffer to release.
  1246. *
  1247. * Description:
  1248. * This routine is the generic release routine for the idiag access file
  1249. * operation, it frees the buffer that was allocated when the debugfs file
  1250. * was opened.
  1251. *
  1252. * Returns:
  1253. * This function returns zero.
  1254. **/
  1255. static int
  1256. lpfc_idiag_release(struct inode *inode, struct file *file)
  1257. {
  1258. struct lpfc_debug *debug = file->private_data;
  1259. /* Free the buffers to the file operation */
  1260. kfree(debug->buffer);
  1261. kfree(debug);
  1262. return 0;
  1263. }
  1264. /**
  1265. * lpfc_idiag_cmd_release - Release idiag cmd access file operation
  1266. * @inode: The inode pointer that contains a vport pointer. (unused)
  1267. * @file: The file pointer that contains the buffer to release.
  1268. *
  1269. * Description:
  1270. * This routine frees the buffer that was allocated when the debugfs file
  1271. * was opened. It also reset the fields in the idiag command struct in the
  1272. * case the command is not continuous browsing of the data structure.
  1273. *
  1274. * Returns:
  1275. * This function returns zero.
  1276. **/
  1277. static int
  1278. lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
  1279. {
  1280. struct lpfc_debug *debug = file->private_data;
  1281. /* Read PCI config register, if not read all, clear command fields */
  1282. if ((debug->op == LPFC_IDIAG_OP_RD) &&
  1283. (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD))
  1284. if ((idiag.cmd.data[1] == sizeof(uint8_t)) ||
  1285. (idiag.cmd.data[1] == sizeof(uint16_t)) ||
  1286. (idiag.cmd.data[1] == sizeof(uint32_t)))
  1287. memset(&idiag, 0, sizeof(idiag));
  1288. /* Write PCI config register, clear command fields */
  1289. if ((debug->op == LPFC_IDIAG_OP_WR) &&
  1290. (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR))
  1291. memset(&idiag, 0, sizeof(idiag));
  1292. /* Free the buffers to the file operation */
  1293. kfree(debug->buffer);
  1294. kfree(debug);
  1295. return 0;
  1296. }
  1297. /**
  1298. * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
  1299. * @file: The file pointer to read from.
  1300. * @buf: The buffer to copy the data to.
  1301. * @nbytes: The number of bytes to read.
  1302. * @ppos: The position in the file to start reading from.
  1303. *
  1304. * Description:
  1305. * This routine reads data from the @phba pci config space according to the
  1306. * idiag command, and copies to user @buf. Depending on the PCI config space
  1307. * read command setup, it does either a single register read of a byte
  1308. * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
  1309. * registers from the 4K extended PCI config space.
  1310. *
  1311. * Returns:
  1312. * This function returns the amount of data that was read (this could be less
  1313. * than @nbytes if the end of the file was reached) or a negative error value.
  1314. **/
  1315. static ssize_t
  1316. lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
  1317. loff_t *ppos)
  1318. {
  1319. struct lpfc_debug *debug = file->private_data;
  1320. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1321. int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
  1322. int where, count;
  1323. char *pbuffer;
  1324. struct pci_dev *pdev;
  1325. uint32_t u32val;
  1326. uint16_t u16val;
  1327. uint8_t u8val;
  1328. pdev = phba->pcidev;
  1329. if (!pdev)
  1330. return 0;
  1331. /* This is a user read operation */
  1332. debug->op = LPFC_IDIAG_OP_RD;
  1333. if (!debug->buffer)
  1334. debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
  1335. if (!debug->buffer)
  1336. return 0;
  1337. pbuffer = debug->buffer;
  1338. if (*ppos)
  1339. return 0;
  1340. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1341. where = idiag.cmd.data[0];
  1342. count = idiag.cmd.data[1];
  1343. } else
  1344. return 0;
  1345. /* Read single PCI config space register */
  1346. switch (count) {
  1347. case SIZE_U8: /* byte (8 bits) */
  1348. pci_read_config_byte(pdev, where, &u8val);
  1349. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1350. "%03x: %02x\n", where, u8val);
  1351. break;
  1352. case SIZE_U16: /* word (16 bits) */
  1353. pci_read_config_word(pdev, where, &u16val);
  1354. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1355. "%03x: %04x\n", where, u16val);
  1356. break;
  1357. case SIZE_U32: /* double word (32 bits) */
  1358. pci_read_config_dword(pdev, where, &u32val);
  1359. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1360. "%03x: %08x\n", where, u32val);
  1361. break;
  1362. case LPFC_PCI_CFG_SIZE: /* browse all */
  1363. goto pcicfg_browse;
  1364. break;
  1365. default:
  1366. /* illegal count */
  1367. len = 0;
  1368. break;
  1369. }
  1370. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1371. pcicfg_browse:
  1372. /* Browse all PCI config space registers */
  1373. offset_label = idiag.offset.last_rd;
  1374. offset = offset_label;
  1375. /* Read PCI config space */
  1376. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1377. "%03x: ", offset_label);
  1378. while (index > 0) {
  1379. pci_read_config_dword(pdev, offset, &u32val);
  1380. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1381. "%08x ", u32val);
  1382. offset += sizeof(uint32_t);
  1383. index -= sizeof(uint32_t);
  1384. if (!index)
  1385. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1386. "\n");
  1387. else if (!(index % (8 * sizeof(uint32_t)))) {
  1388. offset_label += (8 * sizeof(uint32_t));
  1389. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1390. "\n%03x: ", offset_label);
  1391. }
  1392. }
  1393. /* Set up the offset for next portion of pci cfg read */
  1394. idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
  1395. if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
  1396. idiag.offset.last_rd = 0;
  1397. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1398. }
  1399. /**
  1400. * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
  1401. * @file: The file pointer to read from.
  1402. * @buf: The buffer to copy the user data from.
  1403. * @nbytes: The number of bytes to get.
  1404. * @ppos: The position in the file to start reading from.
  1405. *
  1406. * This routine get the debugfs idiag command struct from user space and
  1407. * then perform the syntax check for PCI config space read or write command
  1408. * accordingly. In the case of PCI config space read command, it sets up
  1409. * the command in the idiag command struct for the debugfs read operation.
  1410. * In the case of PCI config space write operation, it executes the write
  1411. * operation into the PCI config space accordingly.
  1412. *
  1413. * It returns the @nbytges passing in from debugfs user space when successful.
  1414. * In case of error conditions, it returns proper error code back to the user
  1415. * space.
  1416. */
  1417. static ssize_t
  1418. lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
  1419. size_t nbytes, loff_t *ppos)
  1420. {
  1421. struct lpfc_debug *debug = file->private_data;
  1422. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1423. uint32_t where, value, count;
  1424. uint32_t u32val;
  1425. uint16_t u16val;
  1426. uint8_t u8val;
  1427. struct pci_dev *pdev;
  1428. int rc;
  1429. pdev = phba->pcidev;
  1430. if (!pdev)
  1431. return -EFAULT;
  1432. /* This is a user write operation */
  1433. debug->op = LPFC_IDIAG_OP_WR;
  1434. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  1435. if (rc)
  1436. return rc;
  1437. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1438. /* Read command from PCI config space, set up command fields */
  1439. where = idiag.cmd.data[0];
  1440. count = idiag.cmd.data[1];
  1441. if (count == LPFC_PCI_CFG_SIZE) {
  1442. if (where != 0)
  1443. goto error_out;
  1444. } else if ((count != sizeof(uint8_t)) &&
  1445. (count != sizeof(uint16_t)) &&
  1446. (count != sizeof(uint32_t)))
  1447. goto error_out;
  1448. if (count == sizeof(uint8_t)) {
  1449. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1450. goto error_out;
  1451. if (where % sizeof(uint8_t))
  1452. goto error_out;
  1453. }
  1454. if (count == sizeof(uint16_t)) {
  1455. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1456. goto error_out;
  1457. if (where % sizeof(uint16_t))
  1458. goto error_out;
  1459. }
  1460. if (count == sizeof(uint32_t)) {
  1461. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1462. goto error_out;
  1463. if (where % sizeof(uint32_t))
  1464. goto error_out;
  1465. }
  1466. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
  1467. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
  1468. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1469. /* Write command to PCI config space, read-modify-write */
  1470. where = idiag.cmd.data[0];
  1471. count = idiag.cmd.data[1];
  1472. value = idiag.cmd.data[2];
  1473. /* Sanity checks */
  1474. if ((count != sizeof(uint8_t)) &&
  1475. (count != sizeof(uint16_t)) &&
  1476. (count != sizeof(uint32_t)))
  1477. goto error_out;
  1478. if (count == sizeof(uint8_t)) {
  1479. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1480. goto error_out;
  1481. if (where % sizeof(uint8_t))
  1482. goto error_out;
  1483. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1484. pci_write_config_byte(pdev, where,
  1485. (uint8_t)value);
  1486. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1487. rc = pci_read_config_byte(pdev, where, &u8val);
  1488. if (!rc) {
  1489. u8val |= (uint8_t)value;
  1490. pci_write_config_byte(pdev, where,
  1491. u8val);
  1492. }
  1493. }
  1494. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1495. rc = pci_read_config_byte(pdev, where, &u8val);
  1496. if (!rc) {
  1497. u8val &= (uint8_t)(~value);
  1498. pci_write_config_byte(pdev, where,
  1499. u8val);
  1500. }
  1501. }
  1502. }
  1503. if (count == sizeof(uint16_t)) {
  1504. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1505. goto error_out;
  1506. if (where % sizeof(uint16_t))
  1507. goto error_out;
  1508. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1509. pci_write_config_word(pdev, where,
  1510. (uint16_t)value);
  1511. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1512. rc = pci_read_config_word(pdev, where, &u16val);
  1513. if (!rc) {
  1514. u16val |= (uint16_t)value;
  1515. pci_write_config_word(pdev, where,
  1516. u16val);
  1517. }
  1518. }
  1519. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1520. rc = pci_read_config_word(pdev, where, &u16val);
  1521. if (!rc) {
  1522. u16val &= (uint16_t)(~value);
  1523. pci_write_config_word(pdev, where,
  1524. u16val);
  1525. }
  1526. }
  1527. }
  1528. if (count == sizeof(uint32_t)) {
  1529. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1530. goto error_out;
  1531. if (where % sizeof(uint32_t))
  1532. goto error_out;
  1533. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1534. pci_write_config_dword(pdev, where, value);
  1535. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1536. rc = pci_read_config_dword(pdev, where,
  1537. &u32val);
  1538. if (!rc) {
  1539. u32val |= value;
  1540. pci_write_config_dword(pdev, where,
  1541. u32val);
  1542. }
  1543. }
  1544. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1545. rc = pci_read_config_dword(pdev, where,
  1546. &u32val);
  1547. if (!rc) {
  1548. u32val &= ~value;
  1549. pci_write_config_dword(pdev, where,
  1550. u32val);
  1551. }
  1552. }
  1553. }
  1554. } else
  1555. /* All other opecodes are illegal for now */
  1556. goto error_out;
  1557. return nbytes;
  1558. error_out:
  1559. memset(&idiag, 0, sizeof(idiag));
  1560. return -EINVAL;
  1561. }
  1562. /**
  1563. * lpfc_idiag_queinfo_read - idiag debugfs read queue information
  1564. * @file: The file pointer to read from.
  1565. * @buf: The buffer to copy the data to.
  1566. * @nbytes: The number of bytes to read.
  1567. * @ppos: The position in the file to start reading from.
  1568. *
  1569. * Description:
  1570. * This routine reads data from the @phba SLI4 PCI function queue information,
  1571. * and copies to user @buf.
  1572. *
  1573. * Returns:
  1574. * This function returns the amount of data that was read (this could be less
  1575. * than @nbytes if the end of the file was reached) or a negative error value.
  1576. **/
  1577. static ssize_t
  1578. lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
  1579. loff_t *ppos)
  1580. {
  1581. struct lpfc_debug *debug = file->private_data;
  1582. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1583. int len = 0, fcp_qidx;
  1584. char *pbuffer;
  1585. if (!debug->buffer)
  1586. debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
  1587. if (!debug->buffer)
  1588. return 0;
  1589. pbuffer = debug->buffer;
  1590. if (*ppos)
  1591. return 0;
  1592. /* Get slow-path event queue information */
  1593. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1594. "Slow-path EQ information:\n");
  1595. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1596. "\tID [%02d], EQE-COUNT [%04d], "
  1597. "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
  1598. phba->sli4_hba.sp_eq->queue_id,
  1599. phba->sli4_hba.sp_eq->entry_count,
  1600. phba->sli4_hba.sp_eq->host_index,
  1601. phba->sli4_hba.sp_eq->hba_index);
  1602. /* Get fast-path event queue information */
  1603. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1604. "Fast-path EQ information:\n");
  1605. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
  1606. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1607. "\tID [%02d], EQE-COUNT [%04d], "
  1608. "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
  1609. phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
  1610. phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
  1611. phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
  1612. phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
  1613. }
  1614. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1615. /* Get mailbox complete queue information */
  1616. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1617. "Mailbox CQ information:\n");
  1618. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1619. "\t\tAssociated EQ-ID [%02d]:\n",
  1620. phba->sli4_hba.mbx_cq->assoc_qid);
  1621. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1622. "\tID [%02d], CQE-COUNT [%04d], "
  1623. "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
  1624. phba->sli4_hba.mbx_cq->queue_id,
  1625. phba->sli4_hba.mbx_cq->entry_count,
  1626. phba->sli4_hba.mbx_cq->host_index,
  1627. phba->sli4_hba.mbx_cq->hba_index);
  1628. /* Get slow-path complete queue information */
  1629. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1630. "Slow-path CQ information:\n");
  1631. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1632. "\t\tAssociated EQ-ID [%02d]:\n",
  1633. phba->sli4_hba.els_cq->assoc_qid);
  1634. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1635. "\tID [%02d], CQE-COUNT [%04d], "
  1636. "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
  1637. phba->sli4_hba.els_cq->queue_id,
  1638. phba->sli4_hba.els_cq->entry_count,
  1639. phba->sli4_hba.els_cq->host_index,
  1640. phba->sli4_hba.els_cq->hba_index);
  1641. /* Get fast-path complete queue information */
  1642. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1643. "Fast-path CQ information:\n");
  1644. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
  1645. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1646. "\t\tAssociated EQ-ID [%02d]:\n",
  1647. phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
  1648. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1649. "\tID [%02d], EQE-COUNT [%04d], "
  1650. "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
  1651. phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
  1652. phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
  1653. phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
  1654. phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
  1655. }
  1656. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1657. /* Get mailbox queue information */
  1658. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1659. "Mailbox MQ information:\n");
  1660. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1661. "\t\tAssociated CQ-ID [%02d]:\n",
  1662. phba->sli4_hba.mbx_wq->assoc_qid);
  1663. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1664. "\tID [%02d], MQE-COUNT [%04d], "
  1665. "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
  1666. phba->sli4_hba.mbx_wq->queue_id,
  1667. phba->sli4_hba.mbx_wq->entry_count,
  1668. phba->sli4_hba.mbx_wq->host_index,
  1669. phba->sli4_hba.mbx_wq->hba_index);
  1670. /* Get slow-path work queue information */
  1671. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1672. "Slow-path WQ information:\n");
  1673. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1674. "\t\tAssociated CQ-ID [%02d]:\n",
  1675. phba->sli4_hba.els_wq->assoc_qid);
  1676. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1677. "\tID [%02d], WQE-COUNT [%04d], "
  1678. "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
  1679. phba->sli4_hba.els_wq->queue_id,
  1680. phba->sli4_hba.els_wq->entry_count,
  1681. phba->sli4_hba.els_wq->host_index,
  1682. phba->sli4_hba.els_wq->hba_index);
  1683. /* Get fast-path work queue information */
  1684. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1685. "Fast-path WQ information:\n");
  1686. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) {
  1687. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1688. "\t\tAssociated CQ-ID [%02d]:\n",
  1689. phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
  1690. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1691. "\tID [%02d], WQE-COUNT [%04d], "
  1692. "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
  1693. phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
  1694. phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
  1695. phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
  1696. phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
  1697. }
  1698. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1699. /* Get receive queue information */
  1700. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1701. "Slow-path RQ information:\n");
  1702. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1703. "\t\tAssociated CQ-ID [%02d]:\n",
  1704. phba->sli4_hba.hdr_rq->assoc_qid);
  1705. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1706. "\tID [%02d], RHQE-COUNT [%04d], "
  1707. "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
  1708. phba->sli4_hba.hdr_rq->queue_id,
  1709. phba->sli4_hba.hdr_rq->entry_count,
  1710. phba->sli4_hba.hdr_rq->host_index,
  1711. phba->sli4_hba.hdr_rq->hba_index);
  1712. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1713. "\tID [%02d], RDQE-COUNT [%04d], "
  1714. "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
  1715. phba->sli4_hba.dat_rq->queue_id,
  1716. phba->sli4_hba.dat_rq->entry_count,
  1717. phba->sli4_hba.dat_rq->host_index,
  1718. phba->sli4_hba.dat_rq->hba_index);
  1719. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1720. }
  1721. #undef lpfc_debugfs_op_disc_trc
  1722. static const struct file_operations lpfc_debugfs_op_disc_trc = {
  1723. .owner = THIS_MODULE,
  1724. .open = lpfc_debugfs_disc_trc_open,
  1725. .llseek = lpfc_debugfs_lseek,
  1726. .read = lpfc_debugfs_read,
  1727. .release = lpfc_debugfs_release,
  1728. };
  1729. #undef lpfc_debugfs_op_nodelist
  1730. static const struct file_operations lpfc_debugfs_op_nodelist = {
  1731. .owner = THIS_MODULE,
  1732. .open = lpfc_debugfs_nodelist_open,
  1733. .llseek = lpfc_debugfs_lseek,
  1734. .read = lpfc_debugfs_read,
  1735. .release = lpfc_debugfs_release,
  1736. };
  1737. #undef lpfc_debugfs_op_hbqinfo
  1738. static const struct file_operations lpfc_debugfs_op_hbqinfo = {
  1739. .owner = THIS_MODULE,
  1740. .open = lpfc_debugfs_hbqinfo_open,
  1741. .llseek = lpfc_debugfs_lseek,
  1742. .read = lpfc_debugfs_read,
  1743. .release = lpfc_debugfs_release,
  1744. };
  1745. #undef lpfc_debugfs_op_dumpHBASlim
  1746. static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  1747. .owner = THIS_MODULE,
  1748. .open = lpfc_debugfs_dumpHBASlim_open,
  1749. .llseek = lpfc_debugfs_lseek,
  1750. .read = lpfc_debugfs_read,
  1751. .release = lpfc_debugfs_release,
  1752. };
  1753. #undef lpfc_debugfs_op_dumpHostSlim
  1754. static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  1755. .owner = THIS_MODULE,
  1756. .open = lpfc_debugfs_dumpHostSlim_open,
  1757. .llseek = lpfc_debugfs_lseek,
  1758. .read = lpfc_debugfs_read,
  1759. .release = lpfc_debugfs_release,
  1760. };
  1761. #undef lpfc_debugfs_op_dumpData
  1762. static const struct file_operations lpfc_debugfs_op_dumpData = {
  1763. .owner = THIS_MODULE,
  1764. .open = lpfc_debugfs_dumpData_open,
  1765. .llseek = lpfc_debugfs_lseek,
  1766. .read = lpfc_debugfs_read,
  1767. .write = lpfc_debugfs_dumpDataDif_write,
  1768. .release = lpfc_debugfs_dumpDataDif_release,
  1769. };
  1770. #undef lpfc_debugfs_op_dumpDif
  1771. static const struct file_operations lpfc_debugfs_op_dumpDif = {
  1772. .owner = THIS_MODULE,
  1773. .open = lpfc_debugfs_dumpDif_open,
  1774. .llseek = lpfc_debugfs_lseek,
  1775. .read = lpfc_debugfs_read,
  1776. .write = lpfc_debugfs_dumpDataDif_write,
  1777. .release = lpfc_debugfs_dumpDataDif_release,
  1778. };
  1779. #undef lpfc_debugfs_op_slow_ring_trc
  1780. static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  1781. .owner = THIS_MODULE,
  1782. .open = lpfc_debugfs_slow_ring_trc_open,
  1783. .llseek = lpfc_debugfs_lseek,
  1784. .read = lpfc_debugfs_read,
  1785. .release = lpfc_debugfs_release,
  1786. };
  1787. static struct dentry *lpfc_debugfs_root = NULL;
  1788. static atomic_t lpfc_debugfs_hba_count;
  1789. /*
  1790. * File operations for the iDiag debugfs
  1791. */
  1792. #undef lpfc_idiag_op_pciCfg
  1793. static const struct file_operations lpfc_idiag_op_pciCfg = {
  1794. .owner = THIS_MODULE,
  1795. .open = lpfc_idiag_open,
  1796. .llseek = lpfc_debugfs_lseek,
  1797. .read = lpfc_idiag_pcicfg_read,
  1798. .write = lpfc_idiag_pcicfg_write,
  1799. .release = lpfc_idiag_cmd_release,
  1800. };
  1801. #undef lpfc_idiag_op_queInfo
  1802. static const struct file_operations lpfc_idiag_op_queInfo = {
  1803. .owner = THIS_MODULE,
  1804. .open = lpfc_idiag_open,
  1805. .read = lpfc_idiag_queinfo_read,
  1806. .release = lpfc_idiag_release,
  1807. };
  1808. #endif
  1809. /**
  1810. * lpfc_debugfs_initialize - Initialize debugfs for a vport
  1811. * @vport: The vport pointer to initialize.
  1812. *
  1813. * Description:
  1814. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  1815. * If not already created, this routine will create the lpfc directory, and
  1816. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  1817. * also create each file used to access lpfc specific debugfs information.
  1818. **/
  1819. inline void
  1820. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  1821. {
  1822. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1823. struct lpfc_hba *phba = vport->phba;
  1824. char name[64];
  1825. uint32_t num, i;
  1826. if (!lpfc_debugfs_enable)
  1827. return;
  1828. /* Setup lpfc root directory */
  1829. if (!lpfc_debugfs_root) {
  1830. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  1831. atomic_set(&lpfc_debugfs_hba_count, 0);
  1832. if (!lpfc_debugfs_root) {
  1833. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1834. "0408 Cannot create debugfs root\n");
  1835. goto debug_failed;
  1836. }
  1837. }
  1838. if (!lpfc_debugfs_start_time)
  1839. lpfc_debugfs_start_time = jiffies;
  1840. /* Setup funcX directory for specific HBA PCI function */
  1841. snprintf(name, sizeof(name), "fn%d", phba->brd_no);
  1842. if (!phba->hba_debugfs_root) {
  1843. phba->hba_debugfs_root =
  1844. debugfs_create_dir(name, lpfc_debugfs_root);
  1845. if (!phba->hba_debugfs_root) {
  1846. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1847. "0412 Cannot create debugfs hba\n");
  1848. goto debug_failed;
  1849. }
  1850. atomic_inc(&lpfc_debugfs_hba_count);
  1851. atomic_set(&phba->debugfs_vport_count, 0);
  1852. /* Setup hbqinfo */
  1853. snprintf(name, sizeof(name), "hbqinfo");
  1854. phba->debug_hbqinfo =
  1855. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1856. phba->hba_debugfs_root,
  1857. phba, &lpfc_debugfs_op_hbqinfo);
  1858. if (!phba->debug_hbqinfo) {
  1859. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1860. "0411 Cannot create debugfs hbqinfo\n");
  1861. goto debug_failed;
  1862. }
  1863. /* Setup dumpHBASlim */
  1864. if (phba->sli_rev < LPFC_SLI_REV4) {
  1865. snprintf(name, sizeof(name), "dumpHBASlim");
  1866. phba->debug_dumpHBASlim =
  1867. debugfs_create_file(name,
  1868. S_IFREG|S_IRUGO|S_IWUSR,
  1869. phba->hba_debugfs_root,
  1870. phba, &lpfc_debugfs_op_dumpHBASlim);
  1871. if (!phba->debug_dumpHBASlim) {
  1872. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1873. "0413 Cannot create debugfs "
  1874. "dumpHBASlim\n");
  1875. goto debug_failed;
  1876. }
  1877. } else
  1878. phba->debug_dumpHBASlim = NULL;
  1879. /* Setup dumpHostSlim */
  1880. if (phba->sli_rev < LPFC_SLI_REV4) {
  1881. snprintf(name, sizeof(name), "dumpHostSlim");
  1882. phba->debug_dumpHostSlim =
  1883. debugfs_create_file(name,
  1884. S_IFREG|S_IRUGO|S_IWUSR,
  1885. phba->hba_debugfs_root,
  1886. phba, &lpfc_debugfs_op_dumpHostSlim);
  1887. if (!phba->debug_dumpHostSlim) {
  1888. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1889. "0414 Cannot create debugfs "
  1890. "dumpHostSlim\n");
  1891. goto debug_failed;
  1892. }
  1893. } else
  1894. phba->debug_dumpHBASlim = NULL;
  1895. /* Setup dumpData */
  1896. snprintf(name, sizeof(name), "dumpData");
  1897. phba->debug_dumpData =
  1898. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1899. phba->hba_debugfs_root,
  1900. phba, &lpfc_debugfs_op_dumpData);
  1901. if (!phba->debug_dumpData) {
  1902. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1903. "0800 Cannot create debugfs dumpData\n");
  1904. goto debug_failed;
  1905. }
  1906. /* Setup dumpDif */
  1907. snprintf(name, sizeof(name), "dumpDif");
  1908. phba->debug_dumpDif =
  1909. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1910. phba->hba_debugfs_root,
  1911. phba, &lpfc_debugfs_op_dumpDif);
  1912. if (!phba->debug_dumpDif) {
  1913. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1914. "0801 Cannot create debugfs dumpDif\n");
  1915. goto debug_failed;
  1916. }
  1917. /* Setup slow ring trace */
  1918. if (lpfc_debugfs_max_slow_ring_trc) {
  1919. num = lpfc_debugfs_max_slow_ring_trc - 1;
  1920. if (num & lpfc_debugfs_max_slow_ring_trc) {
  1921. /* Change to be a power of 2 */
  1922. num = lpfc_debugfs_max_slow_ring_trc;
  1923. i = 0;
  1924. while (num > 1) {
  1925. num = num >> 1;
  1926. i++;
  1927. }
  1928. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  1929. printk(KERN_ERR
  1930. "lpfc_debugfs_max_disc_trc changed to "
  1931. "%d\n", lpfc_debugfs_max_disc_trc);
  1932. }
  1933. }
  1934. snprintf(name, sizeof(name), "slow_ring_trace");
  1935. phba->debug_slow_ring_trc =
  1936. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  1937. phba->hba_debugfs_root,
  1938. phba, &lpfc_debugfs_op_slow_ring_trc);
  1939. if (!phba->debug_slow_ring_trc) {
  1940. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1941. "0415 Cannot create debugfs "
  1942. "slow_ring_trace\n");
  1943. goto debug_failed;
  1944. }
  1945. if (!phba->slow_ring_trc) {
  1946. phba->slow_ring_trc = kmalloc(
  1947. (sizeof(struct lpfc_debugfs_trc) *
  1948. lpfc_debugfs_max_slow_ring_trc),
  1949. GFP_KERNEL);
  1950. if (!phba->slow_ring_trc) {
  1951. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1952. "0416 Cannot create debugfs "
  1953. "slow_ring buffer\n");
  1954. goto debug_failed;
  1955. }
  1956. atomic_set(&phba->slow_ring_trc_cnt, 0);
  1957. memset(phba->slow_ring_trc, 0,
  1958. (sizeof(struct lpfc_debugfs_trc) *
  1959. lpfc_debugfs_max_slow_ring_trc));
  1960. }
  1961. }
  1962. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  1963. if (!vport->vport_debugfs_root) {
  1964. vport->vport_debugfs_root =
  1965. debugfs_create_dir(name, phba->hba_debugfs_root);
  1966. if (!vport->vport_debugfs_root) {
  1967. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1968. "0417 Cant create debugfs\n");
  1969. goto debug_failed;
  1970. }
  1971. atomic_inc(&phba->debugfs_vport_count);
  1972. }
  1973. if (lpfc_debugfs_max_disc_trc) {
  1974. num = lpfc_debugfs_max_disc_trc - 1;
  1975. if (num & lpfc_debugfs_max_disc_trc) {
  1976. /* Change to be a power of 2 */
  1977. num = lpfc_debugfs_max_disc_trc;
  1978. i = 0;
  1979. while (num > 1) {
  1980. num = num >> 1;
  1981. i++;
  1982. }
  1983. lpfc_debugfs_max_disc_trc = (1 << i);
  1984. printk(KERN_ERR
  1985. "lpfc_debugfs_max_disc_trc changed to %d\n",
  1986. lpfc_debugfs_max_disc_trc);
  1987. }
  1988. }
  1989. vport->disc_trc = kzalloc(
  1990. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  1991. GFP_KERNEL);
  1992. if (!vport->disc_trc) {
  1993. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1994. "0418 Cannot create debugfs disc trace "
  1995. "buffer\n");
  1996. goto debug_failed;
  1997. }
  1998. atomic_set(&vport->disc_trc_cnt, 0);
  1999. snprintf(name, sizeof(name), "discovery_trace");
  2000. vport->debug_disc_trc =
  2001. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2002. vport->vport_debugfs_root,
  2003. vport, &lpfc_debugfs_op_disc_trc);
  2004. if (!vport->debug_disc_trc) {
  2005. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2006. "0419 Cannot create debugfs "
  2007. "discovery_trace\n");
  2008. goto debug_failed;
  2009. }
  2010. snprintf(name, sizeof(name), "nodelist");
  2011. vport->debug_nodelist =
  2012. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2013. vport->vport_debugfs_root,
  2014. vport, &lpfc_debugfs_op_nodelist);
  2015. if (!vport->debug_nodelist) {
  2016. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2017. "0409 Cant create debugfs nodelist\n");
  2018. goto debug_failed;
  2019. }
  2020. /*
  2021. * iDiag debugfs root entry points for SLI4 device only
  2022. */
  2023. if (phba->sli_rev < LPFC_SLI_REV4)
  2024. goto debug_failed;
  2025. snprintf(name, sizeof(name), "iDiag");
  2026. if (!phba->idiag_root) {
  2027. phba->idiag_root =
  2028. debugfs_create_dir(name, phba->hba_debugfs_root);
  2029. if (!phba->idiag_root) {
  2030. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2031. "2922 Can't create idiag debugfs\n");
  2032. goto debug_failed;
  2033. }
  2034. /* Initialize iDiag data structure */
  2035. memset(&idiag, 0, sizeof(idiag));
  2036. }
  2037. /* iDiag read PCI config space */
  2038. snprintf(name, sizeof(name), "pciCfg");
  2039. if (!phba->idiag_pci_cfg) {
  2040. phba->idiag_pci_cfg =
  2041. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2042. phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
  2043. if (!phba->idiag_pci_cfg) {
  2044. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2045. "2923 Can't create idiag debugfs\n");
  2046. goto debug_failed;
  2047. }
  2048. idiag.offset.last_rd = 0;
  2049. }
  2050. /* iDiag get PCI function queue information */
  2051. snprintf(name, sizeof(name), "queInfo");
  2052. if (!phba->idiag_que_info) {
  2053. phba->idiag_que_info =
  2054. debugfs_create_file(name, S_IFREG|S_IRUGO,
  2055. phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
  2056. if (!phba->idiag_que_info) {
  2057. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2058. "2924 Can't create idiag debugfs\n");
  2059. goto debug_failed;
  2060. }
  2061. }
  2062. debug_failed:
  2063. return;
  2064. #endif
  2065. }
  2066. /**
  2067. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
  2068. * @vport: The vport pointer to remove from debugfs.
  2069. *
  2070. * Description:
  2071. * When Debugfs is configured this routine removes debugfs file system elements
  2072. * that are specific to this vport. It also checks to see if there are any
  2073. * users left for the debugfs directories associated with the HBA and driver. If
  2074. * this is the last user of the HBA directory or driver directory then it will
  2075. * remove those from the debugfs infrastructure as well.
  2076. **/
  2077. inline void
  2078. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  2079. {
  2080. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  2081. struct lpfc_hba *phba = vport->phba;
  2082. if (vport->disc_trc) {
  2083. kfree(vport->disc_trc);
  2084. vport->disc_trc = NULL;
  2085. }
  2086. if (vport->debug_disc_trc) {
  2087. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  2088. vport->debug_disc_trc = NULL;
  2089. }
  2090. if (vport->debug_nodelist) {
  2091. debugfs_remove(vport->debug_nodelist); /* nodelist */
  2092. vport->debug_nodelist = NULL;
  2093. }
  2094. if (vport->vport_debugfs_root) {
  2095. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  2096. vport->vport_debugfs_root = NULL;
  2097. atomic_dec(&phba->debugfs_vport_count);
  2098. }
  2099. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  2100. if (phba->debug_hbqinfo) {
  2101. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  2102. phba->debug_hbqinfo = NULL;
  2103. }
  2104. if (phba->debug_dumpHBASlim) {
  2105. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  2106. phba->debug_dumpHBASlim = NULL;
  2107. }
  2108. if (phba->debug_dumpHostSlim) {
  2109. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  2110. phba->debug_dumpHostSlim = NULL;
  2111. }
  2112. if (phba->debug_dumpData) {
  2113. debugfs_remove(phba->debug_dumpData); /* dumpData */
  2114. phba->debug_dumpData = NULL;
  2115. }
  2116. if (phba->debug_dumpDif) {
  2117. debugfs_remove(phba->debug_dumpDif); /* dumpDif */
  2118. phba->debug_dumpDif = NULL;
  2119. }
  2120. if (phba->slow_ring_trc) {
  2121. kfree(phba->slow_ring_trc);
  2122. phba->slow_ring_trc = NULL;
  2123. }
  2124. if (phba->debug_slow_ring_trc) {
  2125. /* slow_ring_trace */
  2126. debugfs_remove(phba->debug_slow_ring_trc);
  2127. phba->debug_slow_ring_trc = NULL;
  2128. }
  2129. /*
  2130. * iDiag release
  2131. */
  2132. if (phba->sli_rev == LPFC_SLI_REV4) {
  2133. if (phba->idiag_que_info) {
  2134. /* iDiag queInfo */
  2135. debugfs_remove(phba->idiag_que_info);
  2136. phba->idiag_que_info = NULL;
  2137. }
  2138. if (phba->idiag_pci_cfg) {
  2139. /* iDiag pciCfg */
  2140. debugfs_remove(phba->idiag_pci_cfg);
  2141. phba->idiag_pci_cfg = NULL;
  2142. }
  2143. /* Finally remove the iDiag debugfs root */
  2144. if (phba->idiag_root) {
  2145. /* iDiag root */
  2146. debugfs_remove(phba->idiag_root);
  2147. phba->idiag_root = NULL;
  2148. }
  2149. }
  2150. if (phba->hba_debugfs_root) {
  2151. debugfs_remove(phba->hba_debugfs_root); /* fnX */
  2152. phba->hba_debugfs_root = NULL;
  2153. atomic_dec(&lpfc_debugfs_hba_count);
  2154. }
  2155. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  2156. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  2157. lpfc_debugfs_root = NULL;
  2158. }
  2159. }
  2160. #endif
  2161. return;
  2162. }