lpfc_debugfs.c 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871
  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 boundary */
  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 boundary */
  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. * ---------------------------------
  1005. * iDiag debugfs file access methods
  1006. * ---------------------------------
  1007. *
  1008. * All access methods are through the proper SLI4 PCI function's debugfs
  1009. * iDiag directory:
  1010. *
  1011. * /sys/kernel/debug/lpfc/fn<#>/iDiag
  1012. */
  1013. /**
  1014. * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
  1015. * @buf: The pointer to the user space buffer.
  1016. * @nbytes: The number of bytes in the user space buffer.
  1017. * @idiag_cmd: pointer to the idiag command struct.
  1018. *
  1019. * This routine reads data from debugfs user space buffer and parses the
  1020. * buffer for getting the idiag command and arguments. The while space in
  1021. * between the set of data is used as the parsing separator.
  1022. *
  1023. * This routine returns 0 when successful, it returns proper error code
  1024. * back to the user space in error conditions.
  1025. */
  1026. static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
  1027. struct lpfc_idiag_cmd *idiag_cmd)
  1028. {
  1029. char mybuf[64];
  1030. char *pbuf, *step_str;
  1031. int bsize, i;
  1032. /* Protect copy from user */
  1033. if (!access_ok(VERIFY_READ, buf, nbytes))
  1034. return -EFAULT;
  1035. memset(mybuf, 0, sizeof(mybuf));
  1036. memset(idiag_cmd, 0, sizeof(*idiag_cmd));
  1037. bsize = min(nbytes, (sizeof(mybuf)-1));
  1038. if (copy_from_user(mybuf, buf, bsize))
  1039. return -EFAULT;
  1040. pbuf = &mybuf[0];
  1041. step_str = strsep(&pbuf, "\t ");
  1042. /* The opcode must present */
  1043. if (!step_str)
  1044. return -EINVAL;
  1045. idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
  1046. if (idiag_cmd->opcode == 0)
  1047. return -EINVAL;
  1048. for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
  1049. step_str = strsep(&pbuf, "\t ");
  1050. if (!step_str)
  1051. return i;
  1052. idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
  1053. }
  1054. return i;
  1055. }
  1056. /**
  1057. * lpfc_idiag_open - idiag open debugfs
  1058. * @inode: The inode pointer that contains a pointer to phba.
  1059. * @file: The file pointer to attach the file operation.
  1060. *
  1061. * Description:
  1062. * This routine is the entry point for the debugfs open file operation. It
  1063. * gets the reference to phba from the i_private field in @inode, it then
  1064. * allocates buffer for the file operation, performs the necessary PCI config
  1065. * space read into the allocated buffer according to the idiag user command
  1066. * setup, and then returns a pointer to buffer in the private_data field in
  1067. * @file.
  1068. *
  1069. * Returns:
  1070. * This function returns zero if successful. On error it will return an
  1071. * negative error value.
  1072. **/
  1073. static int
  1074. lpfc_idiag_open(struct inode *inode, struct file *file)
  1075. {
  1076. struct lpfc_debug *debug;
  1077. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1078. if (!debug)
  1079. return -ENOMEM;
  1080. debug->i_private = inode->i_private;
  1081. debug->buffer = NULL;
  1082. file->private_data = debug;
  1083. return 0;
  1084. }
  1085. /**
  1086. * lpfc_idiag_release - Release idiag access file operation
  1087. * @inode: The inode pointer that contains a vport pointer. (unused)
  1088. * @file: The file pointer that contains the buffer to release.
  1089. *
  1090. * Description:
  1091. * This routine is the generic release routine for the idiag access file
  1092. * operation, it frees the buffer that was allocated when the debugfs file
  1093. * was opened.
  1094. *
  1095. * Returns:
  1096. * This function returns zero.
  1097. **/
  1098. static int
  1099. lpfc_idiag_release(struct inode *inode, struct file *file)
  1100. {
  1101. struct lpfc_debug *debug = file->private_data;
  1102. /* Free the buffers to the file operation */
  1103. kfree(debug->buffer);
  1104. kfree(debug);
  1105. return 0;
  1106. }
  1107. /**
  1108. * lpfc_idiag_cmd_release - Release idiag cmd access file operation
  1109. * @inode: The inode pointer that contains a vport pointer. (unused)
  1110. * @file: The file pointer that contains the buffer to release.
  1111. *
  1112. * Description:
  1113. * This routine frees the buffer that was allocated when the debugfs file
  1114. * was opened. It also reset the fields in the idiag command struct in the
  1115. * case of command for write operation.
  1116. *
  1117. * Returns:
  1118. * This function returns zero.
  1119. **/
  1120. static int
  1121. lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
  1122. {
  1123. struct lpfc_debug *debug = file->private_data;
  1124. if (debug->op == LPFC_IDIAG_OP_WR) {
  1125. switch (idiag.cmd.opcode) {
  1126. case LPFC_IDIAG_CMD_PCICFG_WR:
  1127. case LPFC_IDIAG_CMD_PCICFG_ST:
  1128. case LPFC_IDIAG_CMD_PCICFG_CL:
  1129. case LPFC_IDIAG_CMD_QUEACC_WR:
  1130. case LPFC_IDIAG_CMD_QUEACC_ST:
  1131. case LPFC_IDIAG_CMD_QUEACC_CL:
  1132. memset(&idiag, 0, sizeof(idiag));
  1133. break;
  1134. default:
  1135. break;
  1136. }
  1137. }
  1138. /* Free the buffers to the file operation */
  1139. kfree(debug->buffer);
  1140. kfree(debug);
  1141. return 0;
  1142. }
  1143. /**
  1144. * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
  1145. * @file: The file pointer to read from.
  1146. * @buf: The buffer to copy the data to.
  1147. * @nbytes: The number of bytes to read.
  1148. * @ppos: The position in the file to start reading from.
  1149. *
  1150. * Description:
  1151. * This routine reads data from the @phba pci config space according to the
  1152. * idiag command, and copies to user @buf. Depending on the PCI config space
  1153. * read command setup, it does either a single register read of a byte
  1154. * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
  1155. * registers from the 4K extended PCI config space.
  1156. *
  1157. * Returns:
  1158. * This function returns the amount of data that was read (this could be less
  1159. * than @nbytes if the end of the file was reached) or a negative error value.
  1160. **/
  1161. static ssize_t
  1162. lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
  1163. loff_t *ppos)
  1164. {
  1165. struct lpfc_debug *debug = file->private_data;
  1166. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1167. int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
  1168. int where, count;
  1169. char *pbuffer;
  1170. struct pci_dev *pdev;
  1171. uint32_t u32val;
  1172. uint16_t u16val;
  1173. uint8_t u8val;
  1174. pdev = phba->pcidev;
  1175. if (!pdev)
  1176. return 0;
  1177. /* This is a user read operation */
  1178. debug->op = LPFC_IDIAG_OP_RD;
  1179. if (!debug->buffer)
  1180. debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
  1181. if (!debug->buffer)
  1182. return 0;
  1183. pbuffer = debug->buffer;
  1184. if (*ppos)
  1185. return 0;
  1186. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1187. where = idiag.cmd.data[0];
  1188. count = idiag.cmd.data[1];
  1189. } else
  1190. return 0;
  1191. /* Read single PCI config space register */
  1192. switch (count) {
  1193. case SIZE_U8: /* byte (8 bits) */
  1194. pci_read_config_byte(pdev, where, &u8val);
  1195. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1196. "%03x: %02x\n", where, u8val);
  1197. break;
  1198. case SIZE_U16: /* word (16 bits) */
  1199. pci_read_config_word(pdev, where, &u16val);
  1200. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1201. "%03x: %04x\n", where, u16val);
  1202. break;
  1203. case SIZE_U32: /* double word (32 bits) */
  1204. pci_read_config_dword(pdev, where, &u32val);
  1205. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1206. "%03x: %08x\n", where, u32val);
  1207. break;
  1208. case LPFC_PCI_CFG_BROWSE: /* browse all */
  1209. goto pcicfg_browse;
  1210. break;
  1211. default:
  1212. /* illegal count */
  1213. len = 0;
  1214. break;
  1215. }
  1216. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1217. pcicfg_browse:
  1218. /* Browse all PCI config space registers */
  1219. offset_label = idiag.offset.last_rd;
  1220. offset = offset_label;
  1221. /* Read PCI config space */
  1222. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1223. "%03x: ", offset_label);
  1224. while (index > 0) {
  1225. pci_read_config_dword(pdev, offset, &u32val);
  1226. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1227. "%08x ", u32val);
  1228. offset += sizeof(uint32_t);
  1229. index -= sizeof(uint32_t);
  1230. if (!index)
  1231. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1232. "\n");
  1233. else if (!(index % (8 * sizeof(uint32_t)))) {
  1234. offset_label += (8 * sizeof(uint32_t));
  1235. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1236. "\n%03x: ", offset_label);
  1237. }
  1238. }
  1239. /* Set up the offset for next portion of pci cfg read */
  1240. idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
  1241. if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
  1242. idiag.offset.last_rd = 0;
  1243. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1244. }
  1245. /**
  1246. * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
  1247. * @file: The file pointer to read from.
  1248. * @buf: The buffer to copy the user data from.
  1249. * @nbytes: The number of bytes to get.
  1250. * @ppos: The position in the file to start reading from.
  1251. *
  1252. * This routine get the debugfs idiag command struct from user space and
  1253. * then perform the syntax check for PCI config space read or write command
  1254. * accordingly. In the case of PCI config space read command, it sets up
  1255. * the command in the idiag command struct for the debugfs read operation.
  1256. * In the case of PCI config space write operation, it executes the write
  1257. * operation into the PCI config space accordingly.
  1258. *
  1259. * It returns the @nbytges passing in from debugfs user space when successful.
  1260. * In case of error conditions, it returns proper error code back to the user
  1261. * space.
  1262. */
  1263. static ssize_t
  1264. lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
  1265. size_t nbytes, loff_t *ppos)
  1266. {
  1267. struct lpfc_debug *debug = file->private_data;
  1268. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1269. uint32_t where, value, count;
  1270. uint32_t u32val;
  1271. uint16_t u16val;
  1272. uint8_t u8val;
  1273. struct pci_dev *pdev;
  1274. int rc;
  1275. pdev = phba->pcidev;
  1276. if (!pdev)
  1277. return -EFAULT;
  1278. /* This is a user write operation */
  1279. debug->op = LPFC_IDIAG_OP_WR;
  1280. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  1281. if (rc < 0)
  1282. return rc;
  1283. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1284. /* Sanity check on PCI config read command line arguments */
  1285. if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
  1286. goto error_out;
  1287. /* Read command from PCI config space, set up command fields */
  1288. where = idiag.cmd.data[0];
  1289. count = idiag.cmd.data[1];
  1290. if (count == LPFC_PCI_CFG_BROWSE) {
  1291. if (where % sizeof(uint32_t))
  1292. goto error_out;
  1293. /* Starting offset to browse */
  1294. idiag.offset.last_rd = where;
  1295. } else if ((count != sizeof(uint8_t)) &&
  1296. (count != sizeof(uint16_t)) &&
  1297. (count != sizeof(uint32_t)))
  1298. goto error_out;
  1299. if (count == sizeof(uint8_t)) {
  1300. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1301. goto error_out;
  1302. if (where % sizeof(uint8_t))
  1303. goto error_out;
  1304. }
  1305. if (count == sizeof(uint16_t)) {
  1306. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1307. goto error_out;
  1308. if (where % sizeof(uint16_t))
  1309. goto error_out;
  1310. }
  1311. if (count == sizeof(uint32_t)) {
  1312. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1313. goto error_out;
  1314. if (where % sizeof(uint32_t))
  1315. goto error_out;
  1316. }
  1317. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
  1318. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
  1319. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1320. /* Sanity check on PCI config write command line arguments */
  1321. if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
  1322. goto error_out;
  1323. /* Write command to PCI config space, read-modify-write */
  1324. where = idiag.cmd.data[0];
  1325. count = idiag.cmd.data[1];
  1326. value = idiag.cmd.data[2];
  1327. /* Sanity checks */
  1328. if ((count != sizeof(uint8_t)) &&
  1329. (count != sizeof(uint16_t)) &&
  1330. (count != sizeof(uint32_t)))
  1331. goto error_out;
  1332. if (count == sizeof(uint8_t)) {
  1333. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1334. goto error_out;
  1335. if (where % sizeof(uint8_t))
  1336. goto error_out;
  1337. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1338. pci_write_config_byte(pdev, where,
  1339. (uint8_t)value);
  1340. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1341. rc = pci_read_config_byte(pdev, where, &u8val);
  1342. if (!rc) {
  1343. u8val |= (uint8_t)value;
  1344. pci_write_config_byte(pdev, where,
  1345. u8val);
  1346. }
  1347. }
  1348. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1349. rc = pci_read_config_byte(pdev, where, &u8val);
  1350. if (!rc) {
  1351. u8val &= (uint8_t)(~value);
  1352. pci_write_config_byte(pdev, where,
  1353. u8val);
  1354. }
  1355. }
  1356. }
  1357. if (count == sizeof(uint16_t)) {
  1358. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1359. goto error_out;
  1360. if (where % sizeof(uint16_t))
  1361. goto error_out;
  1362. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1363. pci_write_config_word(pdev, where,
  1364. (uint16_t)value);
  1365. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1366. rc = pci_read_config_word(pdev, where, &u16val);
  1367. if (!rc) {
  1368. u16val |= (uint16_t)value;
  1369. pci_write_config_word(pdev, where,
  1370. u16val);
  1371. }
  1372. }
  1373. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1374. rc = pci_read_config_word(pdev, where, &u16val);
  1375. if (!rc) {
  1376. u16val &= (uint16_t)(~value);
  1377. pci_write_config_word(pdev, where,
  1378. u16val);
  1379. }
  1380. }
  1381. }
  1382. if (count == sizeof(uint32_t)) {
  1383. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1384. goto error_out;
  1385. if (where % sizeof(uint32_t))
  1386. goto error_out;
  1387. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1388. pci_write_config_dword(pdev, where, value);
  1389. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1390. rc = pci_read_config_dword(pdev, where,
  1391. &u32val);
  1392. if (!rc) {
  1393. u32val |= value;
  1394. pci_write_config_dword(pdev, where,
  1395. u32val);
  1396. }
  1397. }
  1398. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1399. rc = pci_read_config_dword(pdev, where,
  1400. &u32val);
  1401. if (!rc) {
  1402. u32val &= ~value;
  1403. pci_write_config_dword(pdev, where,
  1404. u32val);
  1405. }
  1406. }
  1407. }
  1408. } else
  1409. /* All other opecodes are illegal for now */
  1410. goto error_out;
  1411. return nbytes;
  1412. error_out:
  1413. memset(&idiag, 0, sizeof(idiag));
  1414. return -EINVAL;
  1415. }
  1416. /**
  1417. * lpfc_idiag_queinfo_read - idiag debugfs read queue information
  1418. * @file: The file pointer to read from.
  1419. * @buf: The buffer to copy the data to.
  1420. * @nbytes: The number of bytes to read.
  1421. * @ppos: The position in the file to start reading from.
  1422. *
  1423. * Description:
  1424. * This routine reads data from the @phba SLI4 PCI function queue information,
  1425. * and copies to user @buf.
  1426. *
  1427. * Returns:
  1428. * This function returns the amount of data that was read (this could be less
  1429. * than @nbytes if the end of the file was reached) or a negative error value.
  1430. **/
  1431. static ssize_t
  1432. lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
  1433. loff_t *ppos)
  1434. {
  1435. struct lpfc_debug *debug = file->private_data;
  1436. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1437. int len = 0, fcp_qidx;
  1438. char *pbuffer;
  1439. if (!debug->buffer)
  1440. debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
  1441. if (!debug->buffer)
  1442. return 0;
  1443. pbuffer = debug->buffer;
  1444. if (*ppos)
  1445. return 0;
  1446. /* Get slow-path event queue information */
  1447. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1448. "Slow-path EQ information:\n");
  1449. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1450. "\tEQID[%02d], "
  1451. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1452. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1453. phba->sli4_hba.sp_eq->queue_id,
  1454. phba->sli4_hba.sp_eq->entry_count,
  1455. phba->sli4_hba.sp_eq->entry_size,
  1456. phba->sli4_hba.sp_eq->host_index,
  1457. phba->sli4_hba.sp_eq->hba_index);
  1458. /* Get fast-path event queue information */
  1459. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1460. "Fast-path EQ information:\n");
  1461. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
  1462. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1463. "\tEQID[%02d], "
  1464. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1465. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1466. phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
  1467. phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
  1468. phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
  1469. phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
  1470. phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
  1471. }
  1472. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1473. /* Get mailbox complete queue information */
  1474. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1475. "Slow-path MBX CQ information:\n");
  1476. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1477. "Associated EQID[%02d]:\n",
  1478. phba->sli4_hba.mbx_cq->assoc_qid);
  1479. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1480. "\tCQID[%02d], "
  1481. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1482. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1483. phba->sli4_hba.mbx_cq->queue_id,
  1484. phba->sli4_hba.mbx_cq->entry_count,
  1485. phba->sli4_hba.mbx_cq->entry_size,
  1486. phba->sli4_hba.mbx_cq->host_index,
  1487. phba->sli4_hba.mbx_cq->hba_index);
  1488. /* Get slow-path complete queue information */
  1489. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1490. "Slow-path ELS CQ information:\n");
  1491. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1492. "Associated EQID[%02d]:\n",
  1493. phba->sli4_hba.els_cq->assoc_qid);
  1494. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1495. "\tCQID [%02d], "
  1496. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1497. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1498. phba->sli4_hba.els_cq->queue_id,
  1499. phba->sli4_hba.els_cq->entry_count,
  1500. phba->sli4_hba.els_cq->entry_size,
  1501. phba->sli4_hba.els_cq->host_index,
  1502. phba->sli4_hba.els_cq->hba_index);
  1503. /* Get fast-path complete queue information */
  1504. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1505. "Fast-path FCP CQ information:\n");
  1506. fcp_qidx = 0;
  1507. do {
  1508. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1509. "Associated EQID[%02d]:\n",
  1510. phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
  1511. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1512. "\tCQID[%02d], "
  1513. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1514. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1515. phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
  1516. phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
  1517. phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
  1518. phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
  1519. phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
  1520. } while (++fcp_qidx < phba->cfg_fcp_eq_count);
  1521. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1522. /* Get mailbox queue information */
  1523. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1524. "Slow-path MBX MQ information:\n");
  1525. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1526. "Associated CQID[%02d]:\n",
  1527. phba->sli4_hba.mbx_wq->assoc_qid);
  1528. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1529. "\tWQID[%02d], "
  1530. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1531. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1532. phba->sli4_hba.mbx_wq->queue_id,
  1533. phba->sli4_hba.mbx_wq->entry_count,
  1534. phba->sli4_hba.mbx_wq->entry_size,
  1535. phba->sli4_hba.mbx_wq->host_index,
  1536. phba->sli4_hba.mbx_wq->hba_index);
  1537. /* Get slow-path work queue information */
  1538. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1539. "Slow-path ELS WQ information:\n");
  1540. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1541. "Associated CQID[%02d]:\n",
  1542. phba->sli4_hba.els_wq->assoc_qid);
  1543. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1544. "\tWQID[%02d], "
  1545. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1546. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1547. phba->sli4_hba.els_wq->queue_id,
  1548. phba->sli4_hba.els_wq->entry_count,
  1549. phba->sli4_hba.els_wq->entry_size,
  1550. phba->sli4_hba.els_wq->host_index,
  1551. phba->sli4_hba.els_wq->hba_index);
  1552. /* Get fast-path work queue information */
  1553. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1554. "Fast-path FCP WQ information:\n");
  1555. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) {
  1556. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1557. "Associated CQID[%02d]:\n",
  1558. phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
  1559. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1560. "\tWQID[%02d], "
  1561. "QE-COUNT[%04d], WQE-SIZE[%04d], "
  1562. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1563. phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
  1564. phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
  1565. phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
  1566. phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
  1567. phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
  1568. }
  1569. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1570. /* Get receive queue information */
  1571. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1572. "Slow-path RQ information:\n");
  1573. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1574. "Associated CQID[%02d]:\n",
  1575. phba->sli4_hba.hdr_rq->assoc_qid);
  1576. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1577. "\tHQID[%02d], "
  1578. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1579. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1580. phba->sli4_hba.hdr_rq->queue_id,
  1581. phba->sli4_hba.hdr_rq->entry_count,
  1582. phba->sli4_hba.hdr_rq->entry_size,
  1583. phba->sli4_hba.hdr_rq->host_index,
  1584. phba->sli4_hba.hdr_rq->hba_index);
  1585. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1586. "\tDQID[%02d], "
  1587. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1588. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1589. phba->sli4_hba.dat_rq->queue_id,
  1590. phba->sli4_hba.dat_rq->entry_count,
  1591. phba->sli4_hba.dat_rq->entry_size,
  1592. phba->sli4_hba.dat_rq->host_index,
  1593. phba->sli4_hba.dat_rq->hba_index);
  1594. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1595. }
  1596. /**
  1597. * lpfc_idiag_que_param_check - queue access command parameter sanity check
  1598. * @q: The pointer to queue structure.
  1599. * @index: The index into a queue entry.
  1600. * @count: The number of queue entries to access.
  1601. *
  1602. * Description:
  1603. * The routine performs sanity check on device queue access method commands.
  1604. *
  1605. * Returns:
  1606. * This function returns -EINVAL when fails the sanity check, otherwise, it
  1607. * returns 0.
  1608. **/
  1609. static int
  1610. lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
  1611. {
  1612. /* Only support single entry read or browsing */
  1613. if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
  1614. return -EINVAL;
  1615. if (index > q->entry_count - 1)
  1616. return -EINVAL;
  1617. return 0;
  1618. }
  1619. /**
  1620. * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
  1621. * @pbuffer: The pointer to buffer to copy the read data into.
  1622. * @pque: The pointer to the queue to be read.
  1623. * @index: The index into the queue entry.
  1624. *
  1625. * Description:
  1626. * This routine reads out a single entry from the given queue's index location
  1627. * and copies it into the buffer provided.
  1628. *
  1629. * Returns:
  1630. * This function returns 0 when it fails, otherwise, it returns the length of
  1631. * the data read into the buffer provided.
  1632. **/
  1633. static int
  1634. lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
  1635. uint32_t index)
  1636. {
  1637. int offset, esize;
  1638. uint32_t *pentry;
  1639. if (!pbuffer || !pque)
  1640. return 0;
  1641. esize = pque->entry_size;
  1642. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  1643. "QE-INDEX[%04d]:\n", index);
  1644. offset = 0;
  1645. pentry = pque->qe[index].address;
  1646. while (esize > 0) {
  1647. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  1648. "%08x ", *pentry);
  1649. pentry++;
  1650. offset += sizeof(uint32_t);
  1651. esize -= sizeof(uint32_t);
  1652. if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
  1653. len += snprintf(pbuffer+len,
  1654. LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  1655. }
  1656. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  1657. return len;
  1658. }
  1659. /**
  1660. * lpfc_idiag_queacc_read - idiag debugfs read port queue
  1661. * @file: The file pointer to read from.
  1662. * @buf: The buffer to copy the data to.
  1663. * @nbytes: The number of bytes to read.
  1664. * @ppos: The position in the file to start reading from.
  1665. *
  1666. * Description:
  1667. * This routine reads data from the @phba device queue memory according to the
  1668. * idiag command, and copies to user @buf. Depending on the queue dump read
  1669. * command setup, it does either a single queue entry read or browing through
  1670. * all entries of the queue.
  1671. *
  1672. * Returns:
  1673. * This function returns the amount of data that was read (this could be less
  1674. * than @nbytes if the end of the file was reached) or a negative error value.
  1675. **/
  1676. static ssize_t
  1677. lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
  1678. loff_t *ppos)
  1679. {
  1680. struct lpfc_debug *debug = file->private_data;
  1681. uint32_t last_index, index, count;
  1682. struct lpfc_queue *pque = NULL;
  1683. char *pbuffer;
  1684. int len = 0;
  1685. /* This is a user read operation */
  1686. debug->op = LPFC_IDIAG_OP_RD;
  1687. if (!debug->buffer)
  1688. debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
  1689. if (!debug->buffer)
  1690. return 0;
  1691. pbuffer = debug->buffer;
  1692. if (*ppos)
  1693. return 0;
  1694. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  1695. index = idiag.cmd.data[2];
  1696. count = idiag.cmd.data[3];
  1697. pque = (struct lpfc_queue *)idiag.ptr_private;
  1698. } else
  1699. return 0;
  1700. /* Browse the queue starting from index */
  1701. if (count == LPFC_QUE_ACC_BROWSE)
  1702. goto que_browse;
  1703. /* Read a single entry from the queue */
  1704. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  1705. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1706. que_browse:
  1707. /* Browse all entries from the queue */
  1708. last_index = idiag.offset.last_rd;
  1709. index = last_index;
  1710. while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
  1711. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  1712. index++;
  1713. if (index > pque->entry_count - 1)
  1714. break;
  1715. }
  1716. /* Set up the offset for next portion of pci cfg read */
  1717. if (index > pque->entry_count - 1)
  1718. index = 0;
  1719. idiag.offset.last_rd = index;
  1720. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1721. }
  1722. /**
  1723. * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
  1724. * @file: The file pointer to read from.
  1725. * @buf: The buffer to copy the user data from.
  1726. * @nbytes: The number of bytes to get.
  1727. * @ppos: The position in the file to start reading from.
  1728. *
  1729. * This routine get the debugfs idiag command struct from user space and then
  1730. * perform the syntax check for port queue read (dump) or write (set) command
  1731. * accordingly. In the case of port queue read command, it sets up the command
  1732. * in the idiag command struct for the following debugfs read operation. In
  1733. * the case of port queue write operation, it executes the write operation
  1734. * into the port queue entry accordingly.
  1735. *
  1736. * It returns the @nbytges passing in from debugfs user space when successful.
  1737. * In case of error conditions, it returns proper error code back to the user
  1738. * space.
  1739. **/
  1740. static ssize_t
  1741. lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
  1742. size_t nbytes, loff_t *ppos)
  1743. {
  1744. struct lpfc_debug *debug = file->private_data;
  1745. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1746. uint32_t qidx, quetp, queid, index, count, offset, value;
  1747. uint32_t *pentry;
  1748. struct lpfc_queue *pque;
  1749. int rc;
  1750. /* This is a user write operation */
  1751. debug->op = LPFC_IDIAG_OP_WR;
  1752. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  1753. if (rc < 0)
  1754. return rc;
  1755. /* Get and sanity check on command feilds */
  1756. quetp = idiag.cmd.data[0];
  1757. queid = idiag.cmd.data[1];
  1758. index = idiag.cmd.data[2];
  1759. count = idiag.cmd.data[3];
  1760. offset = idiag.cmd.data[4];
  1761. value = idiag.cmd.data[5];
  1762. /* Sanity check on command line arguments */
  1763. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  1764. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  1765. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  1766. if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
  1767. goto error_out;
  1768. if (count != 1)
  1769. goto error_out;
  1770. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  1771. if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
  1772. goto error_out;
  1773. } else
  1774. goto error_out;
  1775. switch (quetp) {
  1776. case LPFC_IDIAG_EQ:
  1777. /* Slow-path event queue */
  1778. if (phba->sli4_hba.sp_eq->queue_id == queid) {
  1779. /* Sanity check */
  1780. rc = lpfc_idiag_que_param_check(
  1781. phba->sli4_hba.sp_eq, index, count);
  1782. if (rc)
  1783. goto error_out;
  1784. idiag.ptr_private = phba->sli4_hba.sp_eq;
  1785. goto pass_check;
  1786. }
  1787. /* Fast-path event queue */
  1788. for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
  1789. if (phba->sli4_hba.fp_eq[qidx]->queue_id == queid) {
  1790. /* Sanity check */
  1791. rc = lpfc_idiag_que_param_check(
  1792. phba->sli4_hba.fp_eq[qidx],
  1793. index, count);
  1794. if (rc)
  1795. goto error_out;
  1796. idiag.ptr_private = phba->sli4_hba.fp_eq[qidx];
  1797. goto pass_check;
  1798. }
  1799. }
  1800. goto error_out;
  1801. break;
  1802. case LPFC_IDIAG_CQ:
  1803. /* MBX complete queue */
  1804. if (phba->sli4_hba.mbx_cq->queue_id == queid) {
  1805. /* Sanity check */
  1806. rc = lpfc_idiag_que_param_check(
  1807. phba->sli4_hba.mbx_cq, index, count);
  1808. if (rc)
  1809. goto error_out;
  1810. idiag.ptr_private = phba->sli4_hba.mbx_cq;
  1811. goto pass_check;
  1812. }
  1813. /* ELS complete queue */
  1814. if (phba->sli4_hba.els_cq->queue_id == queid) {
  1815. /* Sanity check */
  1816. rc = lpfc_idiag_que_param_check(
  1817. phba->sli4_hba.els_cq, index, count);
  1818. if (rc)
  1819. goto error_out;
  1820. idiag.ptr_private = phba->sli4_hba.els_cq;
  1821. goto pass_check;
  1822. }
  1823. /* FCP complete queue */
  1824. qidx = 0;
  1825. do {
  1826. if (phba->sli4_hba.fcp_cq[qidx]->queue_id == queid) {
  1827. /* Sanity check */
  1828. rc = lpfc_idiag_que_param_check(
  1829. phba->sli4_hba.fcp_cq[qidx],
  1830. index, count);
  1831. if (rc)
  1832. goto error_out;
  1833. idiag.ptr_private =
  1834. phba->sli4_hba.fcp_cq[qidx];
  1835. goto pass_check;
  1836. }
  1837. } while (++qidx < phba->cfg_fcp_eq_count);
  1838. goto error_out;
  1839. break;
  1840. case LPFC_IDIAG_MQ:
  1841. /* MBX work queue */
  1842. if (phba->sli4_hba.mbx_wq->queue_id == queid) {
  1843. /* Sanity check */
  1844. rc = lpfc_idiag_que_param_check(
  1845. phba->sli4_hba.mbx_wq, index, count);
  1846. if (rc)
  1847. goto error_out;
  1848. idiag.ptr_private = phba->sli4_hba.mbx_wq;
  1849. goto pass_check;
  1850. }
  1851. break;
  1852. case LPFC_IDIAG_WQ:
  1853. /* ELS work queue */
  1854. if (phba->sli4_hba.els_wq->queue_id == queid) {
  1855. /* Sanity check */
  1856. rc = lpfc_idiag_que_param_check(
  1857. phba->sli4_hba.els_wq, index, count);
  1858. if (rc)
  1859. goto error_out;
  1860. idiag.ptr_private = phba->sli4_hba.els_wq;
  1861. goto pass_check;
  1862. }
  1863. /* FCP work queue */
  1864. for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
  1865. if (phba->sli4_hba.fcp_wq[qidx]->queue_id == queid) {
  1866. /* Sanity check */
  1867. rc = lpfc_idiag_que_param_check(
  1868. phba->sli4_hba.fcp_wq[qidx],
  1869. index, count);
  1870. if (rc)
  1871. goto error_out;
  1872. idiag.ptr_private =
  1873. phba->sli4_hba.fcp_wq[qidx];
  1874. goto pass_check;
  1875. }
  1876. }
  1877. goto error_out;
  1878. break;
  1879. case LPFC_IDIAG_RQ:
  1880. /* HDR queue */
  1881. if (phba->sli4_hba.hdr_rq->queue_id == queid) {
  1882. /* Sanity check */
  1883. rc = lpfc_idiag_que_param_check(
  1884. phba->sli4_hba.hdr_rq, index, count);
  1885. if (rc)
  1886. goto error_out;
  1887. idiag.ptr_private = phba->sli4_hba.hdr_rq;
  1888. goto pass_check;
  1889. }
  1890. /* DAT queue */
  1891. if (phba->sli4_hba.dat_rq->queue_id == queid) {
  1892. /* Sanity check */
  1893. rc = lpfc_idiag_que_param_check(
  1894. phba->sli4_hba.dat_rq, index, count);
  1895. if (rc)
  1896. goto error_out;
  1897. idiag.ptr_private = phba->sli4_hba.dat_rq;
  1898. goto pass_check;
  1899. }
  1900. goto error_out;
  1901. break;
  1902. default:
  1903. goto error_out;
  1904. break;
  1905. }
  1906. pass_check:
  1907. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  1908. if (count == LPFC_QUE_ACC_BROWSE)
  1909. idiag.offset.last_rd = index;
  1910. }
  1911. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  1912. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  1913. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  1914. /* Additional sanity checks on write operation */
  1915. pque = (struct lpfc_queue *)idiag.ptr_private;
  1916. if (offset > pque->entry_size/sizeof(uint32_t) - 1)
  1917. goto error_out;
  1918. pentry = pque->qe[index].address;
  1919. pentry += offset;
  1920. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
  1921. *pentry = value;
  1922. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
  1923. *pentry |= value;
  1924. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
  1925. *pentry &= ~value;
  1926. }
  1927. return nbytes;
  1928. error_out:
  1929. /* Clean out command structure on command error out */
  1930. memset(&idiag, 0, sizeof(idiag));
  1931. return -EINVAL;
  1932. }
  1933. /**
  1934. * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
  1935. * @phba: The pointer to hba structure.
  1936. * @pbuffer: The pointer to the buffer to copy the data to.
  1937. * @len: The lenght of bytes to copied.
  1938. * @drbregid: The id to doorbell registers.
  1939. *
  1940. * Description:
  1941. * This routine reads a doorbell register and copies its content to the
  1942. * user buffer pointed to by @pbuffer.
  1943. *
  1944. * Returns:
  1945. * This function returns the amount of data that was copied into @pbuffer.
  1946. **/
  1947. static int
  1948. lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  1949. int len, uint32_t drbregid)
  1950. {
  1951. if (!pbuffer)
  1952. return 0;
  1953. switch (drbregid) {
  1954. case LPFC_DRB_EQCQ:
  1955. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  1956. "EQCQ-DRB-REG: 0x%08x\n",
  1957. readl(phba->sli4_hba.EQCQDBregaddr));
  1958. break;
  1959. case LPFC_DRB_MQ:
  1960. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  1961. "MQ-DRB-REG: 0x%08x\n",
  1962. readl(phba->sli4_hba.MQDBregaddr));
  1963. break;
  1964. case LPFC_DRB_WQ:
  1965. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  1966. "WQ-DRB-REG: 0x%08x\n",
  1967. readl(phba->sli4_hba.WQDBregaddr));
  1968. break;
  1969. case LPFC_DRB_RQ:
  1970. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  1971. "RQ-DRB-REG: 0x%08x\n",
  1972. readl(phba->sli4_hba.RQDBregaddr));
  1973. break;
  1974. default:
  1975. break;
  1976. }
  1977. return len;
  1978. }
  1979. /**
  1980. * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
  1981. * @file: The file pointer to read from.
  1982. * @buf: The buffer to copy the data to.
  1983. * @nbytes: The number of bytes to read.
  1984. * @ppos: The position in the file to start reading from.
  1985. *
  1986. * Description:
  1987. * This routine reads data from the @phba device doorbell register according
  1988. * to the idiag command, and copies to user @buf. Depending on the doorbell
  1989. * register read command setup, it does either a single doorbell register
  1990. * read or dump all doorbell registers.
  1991. *
  1992. * Returns:
  1993. * This function returns the amount of data that was read (this could be less
  1994. * than @nbytes if the end of the file was reached) or a negative error value.
  1995. **/
  1996. static ssize_t
  1997. lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
  1998. loff_t *ppos)
  1999. {
  2000. struct lpfc_debug *debug = file->private_data;
  2001. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2002. uint32_t drb_reg_id, i;
  2003. char *pbuffer;
  2004. int len = 0;
  2005. /* This is a user read operation */
  2006. debug->op = LPFC_IDIAG_OP_RD;
  2007. if (!debug->buffer)
  2008. debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
  2009. if (!debug->buffer)
  2010. return 0;
  2011. pbuffer = debug->buffer;
  2012. if (*ppos)
  2013. return 0;
  2014. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
  2015. drb_reg_id = idiag.cmd.data[0];
  2016. else
  2017. return 0;
  2018. if (drb_reg_id == LPFC_DRB_ACC_ALL)
  2019. for (i = 1; i <= LPFC_DRB_MAX; i++)
  2020. len = lpfc_idiag_drbacc_read_reg(phba,
  2021. pbuffer, len, i);
  2022. else
  2023. len = lpfc_idiag_drbacc_read_reg(phba,
  2024. pbuffer, len, drb_reg_id);
  2025. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2026. }
  2027. /**
  2028. * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
  2029. * @file: The file pointer to read from.
  2030. * @buf: The buffer to copy the user data from.
  2031. * @nbytes: The number of bytes to get.
  2032. * @ppos: The position in the file to start reading from.
  2033. *
  2034. * This routine get the debugfs idiag command struct from user space and then
  2035. * perform the syntax check for port doorbell register read (dump) or write
  2036. * (set) command accordingly. In the case of port queue read command, it sets
  2037. * up the command in the idiag command struct for the following debugfs read
  2038. * operation. In the case of port doorbell register write operation, it
  2039. * executes the write operation into the port doorbell register accordingly.
  2040. *
  2041. * It returns the @nbytges passing in from debugfs user space when successful.
  2042. * In case of error conditions, it returns proper error code back to the user
  2043. * space.
  2044. **/
  2045. static ssize_t
  2046. lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
  2047. size_t nbytes, loff_t *ppos)
  2048. {
  2049. struct lpfc_debug *debug = file->private_data;
  2050. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2051. uint32_t drb_reg_id, value, reg_val;
  2052. void __iomem *drb_reg;
  2053. int rc;
  2054. /* This is a user write operation */
  2055. debug->op = LPFC_IDIAG_OP_WR;
  2056. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2057. if (rc < 0)
  2058. return rc;
  2059. /* Sanity check on command line arguments */
  2060. drb_reg_id = idiag.cmd.data[0];
  2061. value = idiag.cmd.data[1];
  2062. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  2063. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  2064. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2065. if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
  2066. goto error_out;
  2067. if (drb_reg_id > LPFC_DRB_MAX)
  2068. goto error_out;
  2069. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
  2070. if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
  2071. goto error_out;
  2072. if ((drb_reg_id > LPFC_DRB_MAX) &&
  2073. (drb_reg_id != LPFC_DRB_ACC_ALL))
  2074. goto error_out;
  2075. } else
  2076. goto error_out;
  2077. /* Perform the write access operation */
  2078. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  2079. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  2080. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2081. switch (drb_reg_id) {
  2082. case LPFC_DRB_EQCQ:
  2083. drb_reg = phba->sli4_hba.EQCQDBregaddr;
  2084. break;
  2085. case LPFC_DRB_MQ:
  2086. drb_reg = phba->sli4_hba.MQDBregaddr;
  2087. break;
  2088. case LPFC_DRB_WQ:
  2089. drb_reg = phba->sli4_hba.WQDBregaddr;
  2090. break;
  2091. case LPFC_DRB_RQ:
  2092. drb_reg = phba->sli4_hba.RQDBregaddr;
  2093. break;
  2094. default:
  2095. goto error_out;
  2096. }
  2097. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
  2098. reg_val = value;
  2099. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
  2100. reg_val = readl(drb_reg);
  2101. reg_val |= value;
  2102. }
  2103. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2104. reg_val = readl(drb_reg);
  2105. reg_val &= ~value;
  2106. }
  2107. writel(reg_val, drb_reg);
  2108. readl(drb_reg); /* flush */
  2109. }
  2110. return nbytes;
  2111. error_out:
  2112. /* Clean out command structure on command error out */
  2113. memset(&idiag, 0, sizeof(idiag));
  2114. return -EINVAL;
  2115. }
  2116. #undef lpfc_debugfs_op_disc_trc
  2117. static const struct file_operations lpfc_debugfs_op_disc_trc = {
  2118. .owner = THIS_MODULE,
  2119. .open = lpfc_debugfs_disc_trc_open,
  2120. .llseek = lpfc_debugfs_lseek,
  2121. .read = lpfc_debugfs_read,
  2122. .release = lpfc_debugfs_release,
  2123. };
  2124. #undef lpfc_debugfs_op_nodelist
  2125. static const struct file_operations lpfc_debugfs_op_nodelist = {
  2126. .owner = THIS_MODULE,
  2127. .open = lpfc_debugfs_nodelist_open,
  2128. .llseek = lpfc_debugfs_lseek,
  2129. .read = lpfc_debugfs_read,
  2130. .release = lpfc_debugfs_release,
  2131. };
  2132. #undef lpfc_debugfs_op_hbqinfo
  2133. static const struct file_operations lpfc_debugfs_op_hbqinfo = {
  2134. .owner = THIS_MODULE,
  2135. .open = lpfc_debugfs_hbqinfo_open,
  2136. .llseek = lpfc_debugfs_lseek,
  2137. .read = lpfc_debugfs_read,
  2138. .release = lpfc_debugfs_release,
  2139. };
  2140. #undef lpfc_debugfs_op_dumpHBASlim
  2141. static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  2142. .owner = THIS_MODULE,
  2143. .open = lpfc_debugfs_dumpHBASlim_open,
  2144. .llseek = lpfc_debugfs_lseek,
  2145. .read = lpfc_debugfs_read,
  2146. .release = lpfc_debugfs_release,
  2147. };
  2148. #undef lpfc_debugfs_op_dumpHostSlim
  2149. static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  2150. .owner = THIS_MODULE,
  2151. .open = lpfc_debugfs_dumpHostSlim_open,
  2152. .llseek = lpfc_debugfs_lseek,
  2153. .read = lpfc_debugfs_read,
  2154. .release = lpfc_debugfs_release,
  2155. };
  2156. #undef lpfc_debugfs_op_dumpData
  2157. static const struct file_operations lpfc_debugfs_op_dumpData = {
  2158. .owner = THIS_MODULE,
  2159. .open = lpfc_debugfs_dumpData_open,
  2160. .llseek = lpfc_debugfs_lseek,
  2161. .read = lpfc_debugfs_read,
  2162. .write = lpfc_debugfs_dumpDataDif_write,
  2163. .release = lpfc_debugfs_dumpDataDif_release,
  2164. };
  2165. #undef lpfc_debugfs_op_dumpDif
  2166. static const struct file_operations lpfc_debugfs_op_dumpDif = {
  2167. .owner = THIS_MODULE,
  2168. .open = lpfc_debugfs_dumpDif_open,
  2169. .llseek = lpfc_debugfs_lseek,
  2170. .read = lpfc_debugfs_read,
  2171. .write = lpfc_debugfs_dumpDataDif_write,
  2172. .release = lpfc_debugfs_dumpDataDif_release,
  2173. };
  2174. #undef lpfc_debugfs_op_slow_ring_trc
  2175. static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  2176. .owner = THIS_MODULE,
  2177. .open = lpfc_debugfs_slow_ring_trc_open,
  2178. .llseek = lpfc_debugfs_lseek,
  2179. .read = lpfc_debugfs_read,
  2180. .release = lpfc_debugfs_release,
  2181. };
  2182. static struct dentry *lpfc_debugfs_root = NULL;
  2183. static atomic_t lpfc_debugfs_hba_count;
  2184. /*
  2185. * File operations for the iDiag debugfs
  2186. */
  2187. #undef lpfc_idiag_op_pciCfg
  2188. static const struct file_operations lpfc_idiag_op_pciCfg = {
  2189. .owner = THIS_MODULE,
  2190. .open = lpfc_idiag_open,
  2191. .llseek = lpfc_debugfs_lseek,
  2192. .read = lpfc_idiag_pcicfg_read,
  2193. .write = lpfc_idiag_pcicfg_write,
  2194. .release = lpfc_idiag_cmd_release,
  2195. };
  2196. #undef lpfc_idiag_op_queInfo
  2197. static const struct file_operations lpfc_idiag_op_queInfo = {
  2198. .owner = THIS_MODULE,
  2199. .open = lpfc_idiag_open,
  2200. .read = lpfc_idiag_queinfo_read,
  2201. .release = lpfc_idiag_release,
  2202. };
  2203. #undef lpfc_idiag_op_queacc
  2204. static const struct file_operations lpfc_idiag_op_queAcc = {
  2205. .owner = THIS_MODULE,
  2206. .open = lpfc_idiag_open,
  2207. .llseek = lpfc_debugfs_lseek,
  2208. .read = lpfc_idiag_queacc_read,
  2209. .write = lpfc_idiag_queacc_write,
  2210. .release = lpfc_idiag_cmd_release,
  2211. };
  2212. #undef lpfc_idiag_op_drbacc
  2213. static const struct file_operations lpfc_idiag_op_drbAcc = {
  2214. .owner = THIS_MODULE,
  2215. .open = lpfc_idiag_open,
  2216. .llseek = lpfc_debugfs_lseek,
  2217. .read = lpfc_idiag_drbacc_read,
  2218. .write = lpfc_idiag_drbacc_write,
  2219. .release = lpfc_idiag_cmd_release,
  2220. };
  2221. #endif
  2222. /**
  2223. * lpfc_debugfs_initialize - Initialize debugfs for a vport
  2224. * @vport: The vport pointer to initialize.
  2225. *
  2226. * Description:
  2227. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  2228. * If not already created, this routine will create the lpfc directory, and
  2229. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  2230. * also create each file used to access lpfc specific debugfs information.
  2231. **/
  2232. inline void
  2233. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  2234. {
  2235. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  2236. struct lpfc_hba *phba = vport->phba;
  2237. char name[64];
  2238. uint32_t num, i;
  2239. if (!lpfc_debugfs_enable)
  2240. return;
  2241. /* Setup lpfc root directory */
  2242. if (!lpfc_debugfs_root) {
  2243. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  2244. atomic_set(&lpfc_debugfs_hba_count, 0);
  2245. if (!lpfc_debugfs_root) {
  2246. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2247. "0408 Cannot create debugfs root\n");
  2248. goto debug_failed;
  2249. }
  2250. }
  2251. if (!lpfc_debugfs_start_time)
  2252. lpfc_debugfs_start_time = jiffies;
  2253. /* Setup funcX directory for specific HBA PCI function */
  2254. snprintf(name, sizeof(name), "fn%d", phba->brd_no);
  2255. if (!phba->hba_debugfs_root) {
  2256. phba->hba_debugfs_root =
  2257. debugfs_create_dir(name, lpfc_debugfs_root);
  2258. if (!phba->hba_debugfs_root) {
  2259. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2260. "0412 Cannot create debugfs hba\n");
  2261. goto debug_failed;
  2262. }
  2263. atomic_inc(&lpfc_debugfs_hba_count);
  2264. atomic_set(&phba->debugfs_vport_count, 0);
  2265. /* Setup hbqinfo */
  2266. snprintf(name, sizeof(name), "hbqinfo");
  2267. phba->debug_hbqinfo =
  2268. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2269. phba->hba_debugfs_root,
  2270. phba, &lpfc_debugfs_op_hbqinfo);
  2271. if (!phba->debug_hbqinfo) {
  2272. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2273. "0411 Cannot create debugfs hbqinfo\n");
  2274. goto debug_failed;
  2275. }
  2276. /* Setup dumpHBASlim */
  2277. if (phba->sli_rev < LPFC_SLI_REV4) {
  2278. snprintf(name, sizeof(name), "dumpHBASlim");
  2279. phba->debug_dumpHBASlim =
  2280. debugfs_create_file(name,
  2281. S_IFREG|S_IRUGO|S_IWUSR,
  2282. phba->hba_debugfs_root,
  2283. phba, &lpfc_debugfs_op_dumpHBASlim);
  2284. if (!phba->debug_dumpHBASlim) {
  2285. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2286. "0413 Cannot create debugfs "
  2287. "dumpHBASlim\n");
  2288. goto debug_failed;
  2289. }
  2290. } else
  2291. phba->debug_dumpHBASlim = NULL;
  2292. /* Setup dumpHostSlim */
  2293. if (phba->sli_rev < LPFC_SLI_REV4) {
  2294. snprintf(name, sizeof(name), "dumpHostSlim");
  2295. phba->debug_dumpHostSlim =
  2296. debugfs_create_file(name,
  2297. S_IFREG|S_IRUGO|S_IWUSR,
  2298. phba->hba_debugfs_root,
  2299. phba, &lpfc_debugfs_op_dumpHostSlim);
  2300. if (!phba->debug_dumpHostSlim) {
  2301. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2302. "0414 Cannot create debugfs "
  2303. "dumpHostSlim\n");
  2304. goto debug_failed;
  2305. }
  2306. } else
  2307. phba->debug_dumpHBASlim = NULL;
  2308. /* Setup dumpData */
  2309. snprintf(name, sizeof(name), "dumpData");
  2310. phba->debug_dumpData =
  2311. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2312. phba->hba_debugfs_root,
  2313. phba, &lpfc_debugfs_op_dumpData);
  2314. if (!phba->debug_dumpData) {
  2315. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2316. "0800 Cannot create debugfs dumpData\n");
  2317. goto debug_failed;
  2318. }
  2319. /* Setup dumpDif */
  2320. snprintf(name, sizeof(name), "dumpDif");
  2321. phba->debug_dumpDif =
  2322. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2323. phba->hba_debugfs_root,
  2324. phba, &lpfc_debugfs_op_dumpDif);
  2325. if (!phba->debug_dumpDif) {
  2326. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2327. "0801 Cannot create debugfs dumpDif\n");
  2328. goto debug_failed;
  2329. }
  2330. /* Setup slow ring trace */
  2331. if (lpfc_debugfs_max_slow_ring_trc) {
  2332. num = lpfc_debugfs_max_slow_ring_trc - 1;
  2333. if (num & lpfc_debugfs_max_slow_ring_trc) {
  2334. /* Change to be a power of 2 */
  2335. num = lpfc_debugfs_max_slow_ring_trc;
  2336. i = 0;
  2337. while (num > 1) {
  2338. num = num >> 1;
  2339. i++;
  2340. }
  2341. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  2342. printk(KERN_ERR
  2343. "lpfc_debugfs_max_disc_trc changed to "
  2344. "%d\n", lpfc_debugfs_max_disc_trc);
  2345. }
  2346. }
  2347. snprintf(name, sizeof(name), "slow_ring_trace");
  2348. phba->debug_slow_ring_trc =
  2349. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2350. phba->hba_debugfs_root,
  2351. phba, &lpfc_debugfs_op_slow_ring_trc);
  2352. if (!phba->debug_slow_ring_trc) {
  2353. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2354. "0415 Cannot create debugfs "
  2355. "slow_ring_trace\n");
  2356. goto debug_failed;
  2357. }
  2358. if (!phba->slow_ring_trc) {
  2359. phba->slow_ring_trc = kmalloc(
  2360. (sizeof(struct lpfc_debugfs_trc) *
  2361. lpfc_debugfs_max_slow_ring_trc),
  2362. GFP_KERNEL);
  2363. if (!phba->slow_ring_trc) {
  2364. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2365. "0416 Cannot create debugfs "
  2366. "slow_ring buffer\n");
  2367. goto debug_failed;
  2368. }
  2369. atomic_set(&phba->slow_ring_trc_cnt, 0);
  2370. memset(phba->slow_ring_trc, 0,
  2371. (sizeof(struct lpfc_debugfs_trc) *
  2372. lpfc_debugfs_max_slow_ring_trc));
  2373. }
  2374. }
  2375. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  2376. if (!vport->vport_debugfs_root) {
  2377. vport->vport_debugfs_root =
  2378. debugfs_create_dir(name, phba->hba_debugfs_root);
  2379. if (!vport->vport_debugfs_root) {
  2380. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2381. "0417 Can't create debugfs\n");
  2382. goto debug_failed;
  2383. }
  2384. atomic_inc(&phba->debugfs_vport_count);
  2385. }
  2386. if (lpfc_debugfs_max_disc_trc) {
  2387. num = lpfc_debugfs_max_disc_trc - 1;
  2388. if (num & lpfc_debugfs_max_disc_trc) {
  2389. /* Change to be a power of 2 */
  2390. num = lpfc_debugfs_max_disc_trc;
  2391. i = 0;
  2392. while (num > 1) {
  2393. num = num >> 1;
  2394. i++;
  2395. }
  2396. lpfc_debugfs_max_disc_trc = (1 << i);
  2397. printk(KERN_ERR
  2398. "lpfc_debugfs_max_disc_trc changed to %d\n",
  2399. lpfc_debugfs_max_disc_trc);
  2400. }
  2401. }
  2402. vport->disc_trc = kzalloc(
  2403. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  2404. GFP_KERNEL);
  2405. if (!vport->disc_trc) {
  2406. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2407. "0418 Cannot create debugfs disc trace "
  2408. "buffer\n");
  2409. goto debug_failed;
  2410. }
  2411. atomic_set(&vport->disc_trc_cnt, 0);
  2412. snprintf(name, sizeof(name), "discovery_trace");
  2413. vport->debug_disc_trc =
  2414. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2415. vport->vport_debugfs_root,
  2416. vport, &lpfc_debugfs_op_disc_trc);
  2417. if (!vport->debug_disc_trc) {
  2418. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2419. "0419 Cannot create debugfs "
  2420. "discovery_trace\n");
  2421. goto debug_failed;
  2422. }
  2423. snprintf(name, sizeof(name), "nodelist");
  2424. vport->debug_nodelist =
  2425. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2426. vport->vport_debugfs_root,
  2427. vport, &lpfc_debugfs_op_nodelist);
  2428. if (!vport->debug_nodelist) {
  2429. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2430. "0409 Can't create debugfs nodelist\n");
  2431. goto debug_failed;
  2432. }
  2433. /*
  2434. * iDiag debugfs root entry points for SLI4 device only
  2435. */
  2436. if (phba->sli_rev < LPFC_SLI_REV4)
  2437. goto debug_failed;
  2438. snprintf(name, sizeof(name), "iDiag");
  2439. if (!phba->idiag_root) {
  2440. phba->idiag_root =
  2441. debugfs_create_dir(name, phba->hba_debugfs_root);
  2442. if (!phba->idiag_root) {
  2443. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2444. "2922 Can't create idiag debugfs\n");
  2445. goto debug_failed;
  2446. }
  2447. /* Initialize iDiag data structure */
  2448. memset(&idiag, 0, sizeof(idiag));
  2449. }
  2450. /* iDiag read PCI config space */
  2451. snprintf(name, sizeof(name), "pciCfg");
  2452. if (!phba->idiag_pci_cfg) {
  2453. phba->idiag_pci_cfg =
  2454. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2455. phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
  2456. if (!phba->idiag_pci_cfg) {
  2457. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2458. "2923 Can't create idiag debugfs\n");
  2459. goto debug_failed;
  2460. }
  2461. idiag.offset.last_rd = 0;
  2462. }
  2463. /* iDiag get PCI function queue information */
  2464. snprintf(name, sizeof(name), "queInfo");
  2465. if (!phba->idiag_que_info) {
  2466. phba->idiag_que_info =
  2467. debugfs_create_file(name, S_IFREG|S_IRUGO,
  2468. phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
  2469. if (!phba->idiag_que_info) {
  2470. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2471. "2924 Can't create idiag debugfs\n");
  2472. goto debug_failed;
  2473. }
  2474. }
  2475. /* iDiag access PCI function queue */
  2476. snprintf(name, sizeof(name), "queAcc");
  2477. if (!phba->idiag_que_acc) {
  2478. phba->idiag_que_acc =
  2479. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2480. phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
  2481. if (!phba->idiag_que_acc) {
  2482. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2483. "2926 Can't create idiag debugfs\n");
  2484. goto debug_failed;
  2485. }
  2486. }
  2487. /* iDiag access PCI function doorbell registers */
  2488. snprintf(name, sizeof(name), "drbAcc");
  2489. if (!phba->idiag_drb_acc) {
  2490. phba->idiag_drb_acc =
  2491. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2492. phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
  2493. if (!phba->idiag_drb_acc) {
  2494. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2495. "2927 Can't create idiag debugfs\n");
  2496. goto debug_failed;
  2497. }
  2498. }
  2499. debug_failed:
  2500. return;
  2501. #endif
  2502. }
  2503. /**
  2504. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
  2505. * @vport: The vport pointer to remove from debugfs.
  2506. *
  2507. * Description:
  2508. * When Debugfs is configured this routine removes debugfs file system elements
  2509. * that are specific to this vport. It also checks to see if there are any
  2510. * users left for the debugfs directories associated with the HBA and driver. If
  2511. * this is the last user of the HBA directory or driver directory then it will
  2512. * remove those from the debugfs infrastructure as well.
  2513. **/
  2514. inline void
  2515. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  2516. {
  2517. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  2518. struct lpfc_hba *phba = vport->phba;
  2519. if (vport->disc_trc) {
  2520. kfree(vport->disc_trc);
  2521. vport->disc_trc = NULL;
  2522. }
  2523. if (vport->debug_disc_trc) {
  2524. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  2525. vport->debug_disc_trc = NULL;
  2526. }
  2527. if (vport->debug_nodelist) {
  2528. debugfs_remove(vport->debug_nodelist); /* nodelist */
  2529. vport->debug_nodelist = NULL;
  2530. }
  2531. if (vport->vport_debugfs_root) {
  2532. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  2533. vport->vport_debugfs_root = NULL;
  2534. atomic_dec(&phba->debugfs_vport_count);
  2535. }
  2536. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  2537. if (phba->debug_hbqinfo) {
  2538. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  2539. phba->debug_hbqinfo = NULL;
  2540. }
  2541. if (phba->debug_dumpHBASlim) {
  2542. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  2543. phba->debug_dumpHBASlim = NULL;
  2544. }
  2545. if (phba->debug_dumpHostSlim) {
  2546. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  2547. phba->debug_dumpHostSlim = NULL;
  2548. }
  2549. if (phba->debug_dumpData) {
  2550. debugfs_remove(phba->debug_dumpData); /* dumpData */
  2551. phba->debug_dumpData = NULL;
  2552. }
  2553. if (phba->debug_dumpDif) {
  2554. debugfs_remove(phba->debug_dumpDif); /* dumpDif */
  2555. phba->debug_dumpDif = NULL;
  2556. }
  2557. if (phba->slow_ring_trc) {
  2558. kfree(phba->slow_ring_trc);
  2559. phba->slow_ring_trc = NULL;
  2560. }
  2561. if (phba->debug_slow_ring_trc) {
  2562. /* slow_ring_trace */
  2563. debugfs_remove(phba->debug_slow_ring_trc);
  2564. phba->debug_slow_ring_trc = NULL;
  2565. }
  2566. /*
  2567. * iDiag release
  2568. */
  2569. if (phba->sli_rev == LPFC_SLI_REV4) {
  2570. if (phba->idiag_drb_acc) {
  2571. /* iDiag drbAcc */
  2572. debugfs_remove(phba->idiag_drb_acc);
  2573. phba->idiag_drb_acc = NULL;
  2574. }
  2575. if (phba->idiag_que_acc) {
  2576. /* iDiag queAcc */
  2577. debugfs_remove(phba->idiag_que_acc);
  2578. phba->idiag_que_acc = NULL;
  2579. }
  2580. if (phba->idiag_que_info) {
  2581. /* iDiag queInfo */
  2582. debugfs_remove(phba->idiag_que_info);
  2583. phba->idiag_que_info = NULL;
  2584. }
  2585. if (phba->idiag_pci_cfg) {
  2586. /* iDiag pciCfg */
  2587. debugfs_remove(phba->idiag_pci_cfg);
  2588. phba->idiag_pci_cfg = NULL;
  2589. }
  2590. /* Finally remove the iDiag debugfs root */
  2591. if (phba->idiag_root) {
  2592. /* iDiag root */
  2593. debugfs_remove(phba->idiag_root);
  2594. phba->idiag_root = NULL;
  2595. }
  2596. }
  2597. if (phba->hba_debugfs_root) {
  2598. debugfs_remove(phba->hba_debugfs_root); /* fnX */
  2599. phba->hba_debugfs_root = NULL;
  2600. atomic_dec(&lpfc_debugfs_hba_count);
  2601. }
  2602. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  2603. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  2604. lpfc_debugfs_root = NULL;
  2605. }
  2606. }
  2607. #endif
  2608. return;
  2609. }