lpfc_debugfs.c 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170
  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. #include "lpfc_bsg.h"
  49. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  50. /*
  51. * debugfs interface
  52. *
  53. * To access this interface the user should:
  54. * # mount -t debugfs none /sys/kernel/debug
  55. *
  56. * The lpfc debugfs directory hierarchy is:
  57. * /sys/kernel/debug/lpfc/fnX/vportY
  58. * where X is the lpfc hba function unique_id
  59. * where Y is the vport VPI on that hba
  60. *
  61. * Debugging services available per vport:
  62. * discovery_trace
  63. * This is an ACSII readable file that contains a trace of the last
  64. * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
  65. * See lpfc_debugfs.h for different categories of discovery events.
  66. * To enable the discovery trace, the following module parameters must be set:
  67. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  68. * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
  69. * EACH vport. X MUST also be a power of 2.
  70. * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
  71. * lpfc_debugfs.h .
  72. *
  73. * slow_ring_trace
  74. * This is an ACSII readable file that contains a trace of the last
  75. * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
  76. * To enable the slow ring trace, the following module parameters must be set:
  77. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  78. * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
  79. * the HBA. X MUST also be a power of 2.
  80. */
  81. static int lpfc_debugfs_enable = 1;
  82. module_param(lpfc_debugfs_enable, int, S_IRUGO);
  83. MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
  84. /* This MUST be a power of 2 */
  85. static int lpfc_debugfs_max_disc_trc;
  86. module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
  87. MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
  88. "Set debugfs discovery trace depth");
  89. /* This MUST be a power of 2 */
  90. static int lpfc_debugfs_max_slow_ring_trc;
  91. module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
  92. MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
  93. "Set debugfs slow ring trace depth");
  94. static int lpfc_debugfs_mask_disc_trc;
  95. module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
  96. MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
  97. "Set debugfs discovery trace mask");
  98. #include <linux/debugfs.h>
  99. static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  100. static unsigned long lpfc_debugfs_start_time = 0L;
  101. /* iDiag */
  102. static struct lpfc_idiag idiag;
  103. /**
  104. * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
  105. * @vport: The vport to gather the log info from.
  106. * @buf: The buffer to dump log into.
  107. * @size: The maximum amount of data to process.
  108. *
  109. * Description:
  110. * This routine gathers the lpfc discovery debugfs data from the @vport and
  111. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  112. * in the log and process the log until the end of the buffer. Then it will
  113. * gather from the beginning of the log and process until the current entry.
  114. *
  115. * Notes:
  116. * Discovery logging will be disabled while while this routine dumps the log.
  117. *
  118. * Return Value:
  119. * This routine returns the amount of bytes that were dumped into @buf and will
  120. * not exceed @size.
  121. **/
  122. static int
  123. lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
  124. {
  125. int i, index, len, enable;
  126. uint32_t ms;
  127. struct lpfc_debugfs_trc *dtp;
  128. char *buffer;
  129. buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
  130. if (!buffer)
  131. return 0;
  132. enable = lpfc_debugfs_enable;
  133. lpfc_debugfs_enable = 0;
  134. len = 0;
  135. index = (atomic_read(&vport->disc_trc_cnt) + 1) &
  136. (lpfc_debugfs_max_disc_trc - 1);
  137. for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
  138. dtp = vport->disc_trc + i;
  139. if (!dtp->fmt)
  140. continue;
  141. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  142. snprintf(buffer,
  143. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  144. dtp->seq_cnt, ms, dtp->fmt);
  145. len += snprintf(buf+len, size-len, buffer,
  146. dtp->data1, dtp->data2, dtp->data3);
  147. }
  148. for (i = 0; i < index; i++) {
  149. dtp = vport->disc_trc + i;
  150. if (!dtp->fmt)
  151. continue;
  152. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  153. snprintf(buffer,
  154. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  155. dtp->seq_cnt, ms, dtp->fmt);
  156. len += snprintf(buf+len, size-len, buffer,
  157. dtp->data1, dtp->data2, dtp->data3);
  158. }
  159. lpfc_debugfs_enable = enable;
  160. kfree(buffer);
  161. return len;
  162. }
  163. /**
  164. * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
  165. * @phba: The HBA to gather the log info from.
  166. * @buf: The buffer to dump log into.
  167. * @size: The maximum amount of data to process.
  168. *
  169. * Description:
  170. * This routine gathers the lpfc slow ring debugfs data from the @phba and
  171. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  172. * in the log and process the log until the end of the buffer. Then it will
  173. * gather from the beginning of the log and process until the current entry.
  174. *
  175. * Notes:
  176. * Slow ring logging will be disabled while while this routine dumps the log.
  177. *
  178. * Return Value:
  179. * This routine returns the amount of bytes that were dumped into @buf and will
  180. * not exceed @size.
  181. **/
  182. static int
  183. lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
  184. {
  185. int i, index, len, enable;
  186. uint32_t ms;
  187. struct lpfc_debugfs_trc *dtp;
  188. char *buffer;
  189. buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
  190. if (!buffer)
  191. return 0;
  192. enable = lpfc_debugfs_enable;
  193. lpfc_debugfs_enable = 0;
  194. len = 0;
  195. index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
  196. (lpfc_debugfs_max_slow_ring_trc - 1);
  197. for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
  198. dtp = phba->slow_ring_trc + i;
  199. if (!dtp->fmt)
  200. continue;
  201. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  202. snprintf(buffer,
  203. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  204. dtp->seq_cnt, ms, dtp->fmt);
  205. len += snprintf(buf+len, size-len, buffer,
  206. dtp->data1, dtp->data2, dtp->data3);
  207. }
  208. for (i = 0; i < index; i++) {
  209. dtp = phba->slow_ring_trc + i;
  210. if (!dtp->fmt)
  211. continue;
  212. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  213. snprintf(buffer,
  214. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  215. dtp->seq_cnt, ms, dtp->fmt);
  216. len += snprintf(buf+len, size-len, buffer,
  217. dtp->data1, dtp->data2, dtp->data3);
  218. }
  219. lpfc_debugfs_enable = enable;
  220. kfree(buffer);
  221. return len;
  222. }
  223. static int lpfc_debugfs_last_hbq = -1;
  224. /**
  225. * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
  226. * @phba: The HBA to gather host buffer info from.
  227. * @buf: The buffer to dump log into.
  228. * @size: The maximum amount of data to process.
  229. *
  230. * Description:
  231. * This routine dumps the host buffer queue info from the @phba to @buf up to
  232. * @size number of bytes. A header that describes the current hbq state will be
  233. * dumped to @buf first and then info on each hbq entry will be dumped to @buf
  234. * until @size bytes have been dumped or all the hbq info has been dumped.
  235. *
  236. * Notes:
  237. * This routine will rotate through each configured HBQ each time called.
  238. *
  239. * Return Value:
  240. * This routine returns the amount of bytes that were dumped into @buf and will
  241. * not exceed @size.
  242. **/
  243. static int
  244. lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
  245. {
  246. int len = 0;
  247. int cnt, i, j, found, posted, low;
  248. uint32_t phys, raw_index, getidx;
  249. struct lpfc_hbq_init *hip;
  250. struct hbq_s *hbqs;
  251. struct lpfc_hbq_entry *hbqe;
  252. struct lpfc_dmabuf *d_buf;
  253. struct hbq_dmabuf *hbq_buf;
  254. if (phba->sli_rev != 3)
  255. return 0;
  256. cnt = LPFC_HBQINFO_SIZE;
  257. spin_lock_irq(&phba->hbalock);
  258. /* toggle between multiple hbqs, if any */
  259. i = lpfc_sli_hbq_count();
  260. if (i > 1) {
  261. lpfc_debugfs_last_hbq++;
  262. if (lpfc_debugfs_last_hbq >= i)
  263. lpfc_debugfs_last_hbq = 0;
  264. }
  265. else
  266. lpfc_debugfs_last_hbq = 0;
  267. i = lpfc_debugfs_last_hbq;
  268. len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
  269. hbqs = &phba->hbqs[i];
  270. posted = 0;
  271. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
  272. posted++;
  273. hip = lpfc_hbq_defs[i];
  274. len += snprintf(buf+len, size-len,
  275. "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
  276. hip->hbq_index, hip->profile, hip->rn,
  277. hip->buffer_count, hip->init_count, hip->add_count, posted);
  278. raw_index = phba->hbq_get[i];
  279. getidx = le32_to_cpu(raw_index);
  280. len += snprintf(buf+len, size-len,
  281. "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
  282. hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
  283. hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
  284. hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
  285. for (j=0; j<hbqs->entry_count; j++) {
  286. len += snprintf(buf+len, size-len,
  287. "%03d: %08x %04x %05x ", j,
  288. le32_to_cpu(hbqe->bde.addrLow),
  289. le32_to_cpu(hbqe->bde.tus.w),
  290. le32_to_cpu(hbqe->buffer_tag));
  291. i = 0;
  292. found = 0;
  293. /* First calculate if slot has an associated posted buffer */
  294. low = hbqs->hbqPutIdx - posted;
  295. if (low >= 0) {
  296. if ((j >= hbqs->hbqPutIdx) || (j < low)) {
  297. len += snprintf(buf+len, size-len, "Unused\n");
  298. goto skipit;
  299. }
  300. }
  301. else {
  302. if ((j >= hbqs->hbqPutIdx) &&
  303. (j < (hbqs->entry_count+low))) {
  304. len += snprintf(buf+len, size-len, "Unused\n");
  305. goto skipit;
  306. }
  307. }
  308. /* Get the Buffer info for the posted buffer */
  309. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
  310. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  311. phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
  312. if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
  313. len += snprintf(buf+len, size-len,
  314. "Buf%d: %p %06x\n", i,
  315. hbq_buf->dbuf.virt, hbq_buf->tag);
  316. found = 1;
  317. break;
  318. }
  319. i++;
  320. }
  321. if (!found) {
  322. len += snprintf(buf+len, size-len, "No DMAinfo?\n");
  323. }
  324. skipit:
  325. hbqe++;
  326. if (len > LPFC_HBQINFO_SIZE - 54)
  327. break;
  328. }
  329. spin_unlock_irq(&phba->hbalock);
  330. return len;
  331. }
  332. static int lpfc_debugfs_last_hba_slim_off;
  333. /**
  334. * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
  335. * @phba: The HBA to gather SLIM info from.
  336. * @buf: The buffer to dump log into.
  337. * @size: The maximum amount of data to process.
  338. *
  339. * Description:
  340. * This routine dumps the current contents of HBA SLIM for the HBA associated
  341. * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
  342. *
  343. * Notes:
  344. * This routine will only dump up to 1024 bytes of data each time called and
  345. * should be called multiple times to dump the entire HBA SLIM.
  346. *
  347. * Return Value:
  348. * This routine returns the amount of bytes that were dumped into @buf and will
  349. * not exceed @size.
  350. **/
  351. static int
  352. lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
  353. {
  354. int len = 0;
  355. int i, off;
  356. uint32_t *ptr;
  357. char *buffer;
  358. buffer = kmalloc(1024, GFP_KERNEL);
  359. if (!buffer)
  360. return 0;
  361. off = 0;
  362. spin_lock_irq(&phba->hbalock);
  363. len += snprintf(buf+len, size-len, "HBA SLIM\n");
  364. lpfc_memcpy_from_slim(buffer,
  365. phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
  366. ptr = (uint32_t *)&buffer[0];
  367. off = lpfc_debugfs_last_hba_slim_off;
  368. /* Set it up for the next time */
  369. lpfc_debugfs_last_hba_slim_off += 1024;
  370. if (lpfc_debugfs_last_hba_slim_off >= 4096)
  371. lpfc_debugfs_last_hba_slim_off = 0;
  372. i = 1024;
  373. while (i > 0) {
  374. len += snprintf(buf+len, size-len,
  375. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  376. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  377. *(ptr+5), *(ptr+6), *(ptr+7));
  378. ptr += 8;
  379. i -= (8 * sizeof(uint32_t));
  380. off += (8 * sizeof(uint32_t));
  381. }
  382. spin_unlock_irq(&phba->hbalock);
  383. kfree(buffer);
  384. return len;
  385. }
  386. /**
  387. * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
  388. * @phba: The HBA to gather Host SLIM info from.
  389. * @buf: The buffer to dump log into.
  390. * @size: The maximum amount of data to process.
  391. *
  392. * Description:
  393. * This routine dumps the current contents of host SLIM for the host associated
  394. * with @phba to @buf up to @size bytes of data. The dump will contain the
  395. * Mailbox, PCB, Rings, and Registers that are located in host memory.
  396. *
  397. * Return Value:
  398. * This routine returns the amount of bytes that were dumped into @buf and will
  399. * not exceed @size.
  400. **/
  401. static int
  402. lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
  403. {
  404. int len = 0;
  405. int i, off;
  406. uint32_t word0, word1, word2, word3;
  407. uint32_t *ptr;
  408. struct lpfc_pgp *pgpp;
  409. struct lpfc_sli *psli = &phba->sli;
  410. struct lpfc_sli_ring *pring;
  411. off = 0;
  412. spin_lock_irq(&phba->hbalock);
  413. len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
  414. ptr = (uint32_t *)phba->slim2p.virt;
  415. i = sizeof(MAILBOX_t);
  416. while (i > 0) {
  417. len += snprintf(buf+len, size-len,
  418. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  419. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  420. *(ptr+5), *(ptr+6), *(ptr+7));
  421. ptr += 8;
  422. i -= (8 * sizeof(uint32_t));
  423. off += (8 * sizeof(uint32_t));
  424. }
  425. len += snprintf(buf+len, size-len, "SLIM PCB\n");
  426. ptr = (uint32_t *)phba->pcb;
  427. i = sizeof(PCB_t);
  428. while (i > 0) {
  429. len += snprintf(buf+len, size-len,
  430. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  431. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  432. *(ptr+5), *(ptr+6), *(ptr+7));
  433. ptr += 8;
  434. i -= (8 * sizeof(uint32_t));
  435. off += (8 * sizeof(uint32_t));
  436. }
  437. for (i = 0; i < 4; i++) {
  438. pgpp = &phba->port_gp[i];
  439. pring = &psli->ring[i];
  440. len += snprintf(buf+len, size-len,
  441. "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
  442. "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
  443. i, pgpp->cmdGetInx, pring->numCiocb,
  444. pring->next_cmdidx, pring->local_getidx,
  445. pring->flag, pgpp->rspPutInx, pring->numRiocb);
  446. }
  447. if (phba->sli_rev <= LPFC_SLI_REV3) {
  448. word0 = readl(phba->HAregaddr);
  449. word1 = readl(phba->CAregaddr);
  450. word2 = readl(phba->HSregaddr);
  451. word3 = readl(phba->HCregaddr);
  452. len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
  453. "HC:%08x\n", word0, word1, word2, word3);
  454. }
  455. spin_unlock_irq(&phba->hbalock);
  456. return len;
  457. }
  458. /**
  459. * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
  460. * @vport: The vport to gather target node info from.
  461. * @buf: The buffer to dump log into.
  462. * @size: The maximum amount of data to process.
  463. *
  464. * Description:
  465. * This routine dumps the current target node list associated with @vport to
  466. * @buf up to @size bytes of data. Each node entry in the dump will contain a
  467. * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
  468. *
  469. * Return Value:
  470. * This routine returns the amount of bytes that were dumped into @buf and will
  471. * not exceed @size.
  472. **/
  473. static int
  474. lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
  475. {
  476. int len = 0;
  477. int cnt;
  478. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  479. struct lpfc_nodelist *ndlp;
  480. unsigned char *statep, *name;
  481. cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
  482. spin_lock_irq(shost->host_lock);
  483. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  484. if (!cnt) {
  485. len += snprintf(buf+len, size-len,
  486. "Missing Nodelist Entries\n");
  487. break;
  488. }
  489. cnt--;
  490. switch (ndlp->nlp_state) {
  491. case NLP_STE_UNUSED_NODE:
  492. statep = "UNUSED";
  493. break;
  494. case NLP_STE_PLOGI_ISSUE:
  495. statep = "PLOGI ";
  496. break;
  497. case NLP_STE_ADISC_ISSUE:
  498. statep = "ADISC ";
  499. break;
  500. case NLP_STE_REG_LOGIN_ISSUE:
  501. statep = "REGLOG";
  502. break;
  503. case NLP_STE_PRLI_ISSUE:
  504. statep = "PRLI ";
  505. break;
  506. case NLP_STE_UNMAPPED_NODE:
  507. statep = "UNMAP ";
  508. break;
  509. case NLP_STE_MAPPED_NODE:
  510. statep = "MAPPED";
  511. break;
  512. case NLP_STE_NPR_NODE:
  513. statep = "NPR ";
  514. break;
  515. default:
  516. statep = "UNKNOWN";
  517. }
  518. len += snprintf(buf+len, size-len, "%s DID:x%06x ",
  519. statep, ndlp->nlp_DID);
  520. name = (unsigned char *)&ndlp->nlp_portname;
  521. len += snprintf(buf+len, size-len,
  522. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  523. *name, *(name+1), *(name+2), *(name+3),
  524. *(name+4), *(name+5), *(name+6), *(name+7));
  525. name = (unsigned char *)&ndlp->nlp_nodename;
  526. len += snprintf(buf+len, size-len,
  527. "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  528. *name, *(name+1), *(name+2), *(name+3),
  529. *(name+4), *(name+5), *(name+6), *(name+7));
  530. len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
  531. ndlp->nlp_rpi, ndlp->nlp_flag);
  532. if (!ndlp->nlp_type)
  533. len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
  534. if (ndlp->nlp_type & NLP_FC_NODE)
  535. len += snprintf(buf+len, size-len, "FC_NODE ");
  536. if (ndlp->nlp_type & NLP_FABRIC)
  537. len += snprintf(buf+len, size-len, "FABRIC ");
  538. if (ndlp->nlp_type & NLP_FCP_TARGET)
  539. len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
  540. ndlp->nlp_sid);
  541. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  542. len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
  543. len += snprintf(buf+len, size-len, "usgmap:%x ",
  544. ndlp->nlp_usg_map);
  545. len += snprintf(buf+len, size-len, "refcnt:%x",
  546. atomic_read(&ndlp->kref.refcount));
  547. len += snprintf(buf+len, size-len, "\n");
  548. }
  549. spin_unlock_irq(shost->host_lock);
  550. return len;
  551. }
  552. #endif
  553. /**
  554. * lpfc_debugfs_disc_trc - Store discovery trace log
  555. * @vport: The vport to associate this trace string with for retrieval.
  556. * @mask: Log entry classification.
  557. * @fmt: Format string to be displayed when dumping the log.
  558. * @data1: 1st data parameter to be applied to @fmt.
  559. * @data2: 2nd data parameter to be applied to @fmt.
  560. * @data3: 3rd data parameter to be applied to @fmt.
  561. *
  562. * Description:
  563. * This routine is used by the driver code to add a debugfs log entry to the
  564. * discovery trace buffer associated with @vport. Only entries with a @mask that
  565. * match the current debugfs discovery mask will be saved. Entries that do not
  566. * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
  567. * printf when displaying the log.
  568. **/
  569. inline void
  570. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  571. uint32_t data1, uint32_t data2, uint32_t data3)
  572. {
  573. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  574. struct lpfc_debugfs_trc *dtp;
  575. int index;
  576. if (!(lpfc_debugfs_mask_disc_trc & mask))
  577. return;
  578. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  579. !vport || !vport->disc_trc)
  580. return;
  581. index = atomic_inc_return(&vport->disc_trc_cnt) &
  582. (lpfc_debugfs_max_disc_trc - 1);
  583. dtp = vport->disc_trc + index;
  584. dtp->fmt = fmt;
  585. dtp->data1 = data1;
  586. dtp->data2 = data2;
  587. dtp->data3 = data3;
  588. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  589. dtp->jif = jiffies;
  590. #endif
  591. return;
  592. }
  593. /**
  594. * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
  595. * @phba: The phba to associate this trace string with for retrieval.
  596. * @fmt: Format string to be displayed when dumping the log.
  597. * @data1: 1st data parameter to be applied to @fmt.
  598. * @data2: 2nd data parameter to be applied to @fmt.
  599. * @data3: 3rd data parameter to be applied to @fmt.
  600. *
  601. * Description:
  602. * This routine is used by the driver code to add a debugfs log entry to the
  603. * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
  604. * @data3 are used like printf when displaying the log.
  605. **/
  606. inline void
  607. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  608. uint32_t data1, uint32_t data2, uint32_t data3)
  609. {
  610. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  611. struct lpfc_debugfs_trc *dtp;
  612. int index;
  613. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  614. !phba || !phba->slow_ring_trc)
  615. return;
  616. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  617. (lpfc_debugfs_max_slow_ring_trc - 1);
  618. dtp = phba->slow_ring_trc + index;
  619. dtp->fmt = fmt;
  620. dtp->data1 = data1;
  621. dtp->data2 = data2;
  622. dtp->data3 = data3;
  623. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  624. dtp->jif = jiffies;
  625. #endif
  626. return;
  627. }
  628. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  629. /**
  630. * lpfc_debugfs_disc_trc_open - Open the discovery trace log
  631. * @inode: The inode pointer that contains a vport pointer.
  632. * @file: The file pointer to attach the log output.
  633. *
  634. * Description:
  635. * This routine is the entry point for the debugfs open file operation. It gets
  636. * the vport from the i_private field in @inode, allocates the necessary buffer
  637. * for the log, fills the buffer from the in-memory log for this vport, and then
  638. * returns a pointer to that log in the private_data field in @file.
  639. *
  640. * Returns:
  641. * This function returns zero if successful. On error it will return an negative
  642. * error value.
  643. **/
  644. static int
  645. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  646. {
  647. struct lpfc_vport *vport = inode->i_private;
  648. struct lpfc_debug *debug;
  649. int size;
  650. int rc = -ENOMEM;
  651. if (!lpfc_debugfs_max_disc_trc) {
  652. rc = -ENOSPC;
  653. goto out;
  654. }
  655. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  656. if (!debug)
  657. goto out;
  658. /* Round to page boundary */
  659. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  660. size = PAGE_ALIGN(size);
  661. debug->buffer = kmalloc(size, GFP_KERNEL);
  662. if (!debug->buffer) {
  663. kfree(debug);
  664. goto out;
  665. }
  666. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  667. file->private_data = debug;
  668. rc = 0;
  669. out:
  670. return rc;
  671. }
  672. /**
  673. * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
  674. * @inode: The inode pointer that contains a vport pointer.
  675. * @file: The file pointer to attach the log output.
  676. *
  677. * Description:
  678. * This routine is the entry point for the debugfs open file operation. It gets
  679. * the vport from the i_private field in @inode, allocates the necessary buffer
  680. * for the log, fills the buffer from the in-memory log for this vport, and then
  681. * returns a pointer to that log in the private_data field in @file.
  682. *
  683. * Returns:
  684. * This function returns zero if successful. On error it will return an negative
  685. * error value.
  686. **/
  687. static int
  688. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  689. {
  690. struct lpfc_hba *phba = inode->i_private;
  691. struct lpfc_debug *debug;
  692. int size;
  693. int rc = -ENOMEM;
  694. if (!lpfc_debugfs_max_slow_ring_trc) {
  695. rc = -ENOSPC;
  696. goto out;
  697. }
  698. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  699. if (!debug)
  700. goto out;
  701. /* Round to page boundary */
  702. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  703. size = PAGE_ALIGN(size);
  704. debug->buffer = kmalloc(size, GFP_KERNEL);
  705. if (!debug->buffer) {
  706. kfree(debug);
  707. goto out;
  708. }
  709. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  710. file->private_data = debug;
  711. rc = 0;
  712. out:
  713. return rc;
  714. }
  715. /**
  716. * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
  717. * @inode: The inode pointer that contains a vport pointer.
  718. * @file: The file pointer to attach the log output.
  719. *
  720. * Description:
  721. * This routine is the entry point for the debugfs open file operation. It gets
  722. * the vport from the i_private field in @inode, allocates the necessary buffer
  723. * for the log, fills the buffer from the in-memory log for this vport, and then
  724. * returns a pointer to that log in the private_data field in @file.
  725. *
  726. * Returns:
  727. * This function returns zero if successful. On error it will return an negative
  728. * error value.
  729. **/
  730. static int
  731. lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
  732. {
  733. struct lpfc_hba *phba = inode->i_private;
  734. struct lpfc_debug *debug;
  735. int rc = -ENOMEM;
  736. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  737. if (!debug)
  738. goto out;
  739. /* Round to page boundary */
  740. debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
  741. if (!debug->buffer) {
  742. kfree(debug);
  743. goto out;
  744. }
  745. debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
  746. LPFC_HBQINFO_SIZE);
  747. file->private_data = debug;
  748. rc = 0;
  749. out:
  750. return rc;
  751. }
  752. /**
  753. * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
  754. * @inode: The inode pointer that contains a vport pointer.
  755. * @file: The file pointer to attach the log output.
  756. *
  757. * Description:
  758. * This routine is the entry point for the debugfs open file operation. It gets
  759. * the vport from the i_private field in @inode, allocates the necessary buffer
  760. * for the log, fills the buffer from the in-memory log for this vport, and then
  761. * returns a pointer to that log in the private_data field in @file.
  762. *
  763. * Returns:
  764. * This function returns zero if successful. On error it will return an negative
  765. * error value.
  766. **/
  767. static int
  768. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  769. {
  770. struct lpfc_hba *phba = inode->i_private;
  771. struct lpfc_debug *debug;
  772. int rc = -ENOMEM;
  773. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  774. if (!debug)
  775. goto out;
  776. /* Round to page boundary */
  777. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  778. if (!debug->buffer) {
  779. kfree(debug);
  780. goto out;
  781. }
  782. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  783. LPFC_DUMPHBASLIM_SIZE);
  784. file->private_data = debug;
  785. rc = 0;
  786. out:
  787. return rc;
  788. }
  789. /**
  790. * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
  791. * @inode: The inode pointer that contains a vport pointer.
  792. * @file: The file pointer to attach the log output.
  793. *
  794. * Description:
  795. * This routine is the entry point for the debugfs open file operation. It gets
  796. * the vport from the i_private field in @inode, allocates the necessary buffer
  797. * for the log, fills the buffer from the in-memory log for this vport, and then
  798. * returns a pointer to that log in the private_data field in @file.
  799. *
  800. * Returns:
  801. * This function returns zero if successful. On error it will return an negative
  802. * error value.
  803. **/
  804. static int
  805. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  806. {
  807. struct lpfc_hba *phba = inode->i_private;
  808. struct lpfc_debug *debug;
  809. int rc = -ENOMEM;
  810. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  811. if (!debug)
  812. goto out;
  813. /* Round to page boundary */
  814. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  815. if (!debug->buffer) {
  816. kfree(debug);
  817. goto out;
  818. }
  819. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  820. LPFC_DUMPHOSTSLIM_SIZE);
  821. file->private_data = debug;
  822. rc = 0;
  823. out:
  824. return rc;
  825. }
  826. static int
  827. lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
  828. {
  829. struct lpfc_debug *debug;
  830. int rc = -ENOMEM;
  831. if (!_dump_buf_data)
  832. return -EBUSY;
  833. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  834. if (!debug)
  835. goto out;
  836. /* Round to page boundary */
  837. printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
  838. __func__, _dump_buf_data);
  839. debug->buffer = _dump_buf_data;
  840. if (!debug->buffer) {
  841. kfree(debug);
  842. goto out;
  843. }
  844. debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
  845. file->private_data = debug;
  846. rc = 0;
  847. out:
  848. return rc;
  849. }
  850. static int
  851. lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
  852. {
  853. struct lpfc_debug *debug;
  854. int rc = -ENOMEM;
  855. if (!_dump_buf_dif)
  856. return -EBUSY;
  857. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  858. if (!debug)
  859. goto out;
  860. /* Round to page boundary */
  861. printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
  862. __func__, _dump_buf_dif, file->f_dentry->d_name.name);
  863. debug->buffer = _dump_buf_dif;
  864. if (!debug->buffer) {
  865. kfree(debug);
  866. goto out;
  867. }
  868. debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
  869. file->private_data = debug;
  870. rc = 0;
  871. out:
  872. return rc;
  873. }
  874. static ssize_t
  875. lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
  876. size_t nbytes, loff_t *ppos)
  877. {
  878. /*
  879. * The Data/DIF buffers only save one failing IO
  880. * The write op is used as a reset mechanism after an IO has
  881. * already been saved to the next one can be saved
  882. */
  883. spin_lock(&_dump_buf_lock);
  884. memset((void *)_dump_buf_data, 0,
  885. ((1 << PAGE_SHIFT) << _dump_buf_data_order));
  886. memset((void *)_dump_buf_dif, 0,
  887. ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
  888. _dump_buf_done = 0;
  889. spin_unlock(&_dump_buf_lock);
  890. return nbytes;
  891. }
  892. /**
  893. * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
  894. * @inode: The inode pointer that contains a vport pointer.
  895. * @file: The file pointer to attach the log output.
  896. *
  897. * Description:
  898. * This routine is the entry point for the debugfs open file operation. It gets
  899. * the vport from the i_private field in @inode, allocates the necessary buffer
  900. * for the log, fills the buffer from the in-memory log for this vport, and then
  901. * returns a pointer to that log in the private_data field in @file.
  902. *
  903. * Returns:
  904. * This function returns zero if successful. On error it will return an negative
  905. * error value.
  906. **/
  907. static int
  908. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  909. {
  910. struct lpfc_vport *vport = inode->i_private;
  911. struct lpfc_debug *debug;
  912. int rc = -ENOMEM;
  913. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  914. if (!debug)
  915. goto out;
  916. /* Round to page boundary */
  917. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  918. if (!debug->buffer) {
  919. kfree(debug);
  920. goto out;
  921. }
  922. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  923. LPFC_NODELIST_SIZE);
  924. file->private_data = debug;
  925. rc = 0;
  926. out:
  927. return rc;
  928. }
  929. /**
  930. * lpfc_debugfs_lseek - Seek through a debugfs file
  931. * @file: The file pointer to seek through.
  932. * @off: The offset to seek to or the amount to seek by.
  933. * @whence: Indicates how to seek.
  934. *
  935. * Description:
  936. * This routine is the entry point for the debugfs lseek file operation. The
  937. * @whence parameter indicates whether @off is the offset to directly seek to,
  938. * or if it is a value to seek forward or reverse by. This function figures out
  939. * what the new offset of the debugfs file will be and assigns that value to the
  940. * f_pos field of @file.
  941. *
  942. * Returns:
  943. * This function returns the new offset if successful and returns a negative
  944. * error if unable to process the seek.
  945. **/
  946. static loff_t
  947. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  948. {
  949. struct lpfc_debug *debug;
  950. loff_t pos = -1;
  951. debug = file->private_data;
  952. switch (whence) {
  953. case 0:
  954. pos = off;
  955. break;
  956. case 1:
  957. pos = file->f_pos + off;
  958. break;
  959. case 2:
  960. pos = debug->len - off;
  961. }
  962. return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
  963. }
  964. /**
  965. * lpfc_debugfs_read - Read a debugfs file
  966. * @file: The file pointer to read from.
  967. * @buf: The buffer to copy the data to.
  968. * @nbytes: The number of bytes to read.
  969. * @ppos: The position in the file to start reading from.
  970. *
  971. * Description:
  972. * This routine reads data from from the buffer indicated in the private_data
  973. * field of @file. It will start reading at @ppos and copy up to @nbytes of
  974. * data to @buf.
  975. *
  976. * Returns:
  977. * This function returns the amount of data that was read (this could be less
  978. * than @nbytes if the end of the file was reached) or a negative error value.
  979. **/
  980. static ssize_t
  981. lpfc_debugfs_read(struct file *file, char __user *buf,
  982. size_t nbytes, loff_t *ppos)
  983. {
  984. struct lpfc_debug *debug = file->private_data;
  985. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  986. debug->len);
  987. }
  988. /**
  989. * lpfc_debugfs_release - Release the buffer used to store debugfs file data
  990. * @inode: The inode pointer that contains a vport pointer. (unused)
  991. * @file: The file pointer that contains the buffer to release.
  992. *
  993. * Description:
  994. * This routine frees the buffer that was allocated when the debugfs file was
  995. * opened.
  996. *
  997. * Returns:
  998. * This function returns zero.
  999. **/
  1000. static int
  1001. lpfc_debugfs_release(struct inode *inode, struct file *file)
  1002. {
  1003. struct lpfc_debug *debug = file->private_data;
  1004. kfree(debug->buffer);
  1005. kfree(debug);
  1006. return 0;
  1007. }
  1008. static int
  1009. lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
  1010. {
  1011. struct lpfc_debug *debug = file->private_data;
  1012. debug->buffer = NULL;
  1013. kfree(debug);
  1014. return 0;
  1015. }
  1016. /*
  1017. * ---------------------------------
  1018. * iDiag debugfs file access methods
  1019. * ---------------------------------
  1020. *
  1021. * All access methods are through the proper SLI4 PCI function's debugfs
  1022. * iDiag directory:
  1023. *
  1024. * /sys/kernel/debug/lpfc/fn<#>/iDiag
  1025. */
  1026. /**
  1027. * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
  1028. * @buf: The pointer to the user space buffer.
  1029. * @nbytes: The number of bytes in the user space buffer.
  1030. * @idiag_cmd: pointer to the idiag command struct.
  1031. *
  1032. * This routine reads data from debugfs user space buffer and parses the
  1033. * buffer for getting the idiag command and arguments. The while space in
  1034. * between the set of data is used as the parsing separator.
  1035. *
  1036. * This routine returns 0 when successful, it returns proper error code
  1037. * back to the user space in error conditions.
  1038. */
  1039. static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
  1040. struct lpfc_idiag_cmd *idiag_cmd)
  1041. {
  1042. char mybuf[64];
  1043. char *pbuf, *step_str;
  1044. int i;
  1045. size_t bsize;
  1046. /* Protect copy from user */
  1047. if (!access_ok(VERIFY_READ, buf, nbytes))
  1048. return -EFAULT;
  1049. memset(mybuf, 0, sizeof(mybuf));
  1050. memset(idiag_cmd, 0, sizeof(*idiag_cmd));
  1051. bsize = min(nbytes, (sizeof(mybuf)-1));
  1052. if (copy_from_user(mybuf, buf, bsize))
  1053. return -EFAULT;
  1054. pbuf = &mybuf[0];
  1055. step_str = strsep(&pbuf, "\t ");
  1056. /* The opcode must present */
  1057. if (!step_str)
  1058. return -EINVAL;
  1059. idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
  1060. if (idiag_cmd->opcode == 0)
  1061. return -EINVAL;
  1062. for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
  1063. step_str = strsep(&pbuf, "\t ");
  1064. if (!step_str)
  1065. return i;
  1066. idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
  1067. }
  1068. return i;
  1069. }
  1070. /**
  1071. * lpfc_idiag_open - idiag open debugfs
  1072. * @inode: The inode pointer that contains a pointer to phba.
  1073. * @file: The file pointer to attach the file operation.
  1074. *
  1075. * Description:
  1076. * This routine is the entry point for the debugfs open file operation. It
  1077. * gets the reference to phba from the i_private field in @inode, it then
  1078. * allocates buffer for the file operation, performs the necessary PCI config
  1079. * space read into the allocated buffer according to the idiag user command
  1080. * setup, and then returns a pointer to buffer in the private_data field in
  1081. * @file.
  1082. *
  1083. * Returns:
  1084. * This function returns zero if successful. On error it will return an
  1085. * negative error value.
  1086. **/
  1087. static int
  1088. lpfc_idiag_open(struct inode *inode, struct file *file)
  1089. {
  1090. struct lpfc_debug *debug;
  1091. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1092. if (!debug)
  1093. return -ENOMEM;
  1094. debug->i_private = inode->i_private;
  1095. debug->buffer = NULL;
  1096. file->private_data = debug;
  1097. return 0;
  1098. }
  1099. /**
  1100. * lpfc_idiag_release - Release idiag access file operation
  1101. * @inode: The inode pointer that contains a vport pointer. (unused)
  1102. * @file: The file pointer that contains the buffer to release.
  1103. *
  1104. * Description:
  1105. * This routine is the generic release routine for the idiag access file
  1106. * operation, it frees the buffer that was allocated when the debugfs file
  1107. * was opened.
  1108. *
  1109. * Returns:
  1110. * This function returns zero.
  1111. **/
  1112. static int
  1113. lpfc_idiag_release(struct inode *inode, struct file *file)
  1114. {
  1115. struct lpfc_debug *debug = file->private_data;
  1116. /* Free the buffers to the file operation */
  1117. kfree(debug->buffer);
  1118. kfree(debug);
  1119. return 0;
  1120. }
  1121. /**
  1122. * lpfc_idiag_cmd_release - Release idiag cmd access file operation
  1123. * @inode: The inode pointer that contains a vport pointer. (unused)
  1124. * @file: The file pointer that contains the buffer to release.
  1125. *
  1126. * Description:
  1127. * This routine frees the buffer that was allocated when the debugfs file
  1128. * was opened. It also reset the fields in the idiag command struct in the
  1129. * case of command for write operation.
  1130. *
  1131. * Returns:
  1132. * This function returns zero.
  1133. **/
  1134. static int
  1135. lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
  1136. {
  1137. struct lpfc_debug *debug = file->private_data;
  1138. if (debug->op == LPFC_IDIAG_OP_WR) {
  1139. switch (idiag.cmd.opcode) {
  1140. case LPFC_IDIAG_CMD_PCICFG_WR:
  1141. case LPFC_IDIAG_CMD_PCICFG_ST:
  1142. case LPFC_IDIAG_CMD_PCICFG_CL:
  1143. case LPFC_IDIAG_CMD_QUEACC_WR:
  1144. case LPFC_IDIAG_CMD_QUEACC_ST:
  1145. case LPFC_IDIAG_CMD_QUEACC_CL:
  1146. memset(&idiag, 0, sizeof(idiag));
  1147. break;
  1148. default:
  1149. break;
  1150. }
  1151. }
  1152. /* Free the buffers to the file operation */
  1153. kfree(debug->buffer);
  1154. kfree(debug);
  1155. return 0;
  1156. }
  1157. /**
  1158. * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
  1159. * @file: The file pointer to read from.
  1160. * @buf: The buffer to copy the data to.
  1161. * @nbytes: The number of bytes to read.
  1162. * @ppos: The position in the file to start reading from.
  1163. *
  1164. * Description:
  1165. * This routine reads data from the @phba pci config space according to the
  1166. * idiag command, and copies to user @buf. Depending on the PCI config space
  1167. * read command setup, it does either a single register read of a byte
  1168. * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
  1169. * registers from the 4K extended PCI config space.
  1170. *
  1171. * Returns:
  1172. * This function returns the amount of data that was read (this could be less
  1173. * than @nbytes if the end of the file was reached) or a negative error value.
  1174. **/
  1175. static ssize_t
  1176. lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
  1177. loff_t *ppos)
  1178. {
  1179. struct lpfc_debug *debug = file->private_data;
  1180. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1181. int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
  1182. int where, count;
  1183. char *pbuffer;
  1184. struct pci_dev *pdev;
  1185. uint32_t u32val;
  1186. uint16_t u16val;
  1187. uint8_t u8val;
  1188. pdev = phba->pcidev;
  1189. if (!pdev)
  1190. return 0;
  1191. /* This is a user read operation */
  1192. debug->op = LPFC_IDIAG_OP_RD;
  1193. if (!debug->buffer)
  1194. debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
  1195. if (!debug->buffer)
  1196. return 0;
  1197. pbuffer = debug->buffer;
  1198. if (*ppos)
  1199. return 0;
  1200. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1201. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  1202. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  1203. } else
  1204. return 0;
  1205. /* Read single PCI config space register */
  1206. switch (count) {
  1207. case SIZE_U8: /* byte (8 bits) */
  1208. pci_read_config_byte(pdev, where, &u8val);
  1209. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1210. "%03x: %02x\n", where, u8val);
  1211. break;
  1212. case SIZE_U16: /* word (16 bits) */
  1213. pci_read_config_word(pdev, where, &u16val);
  1214. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1215. "%03x: %04x\n", where, u16val);
  1216. break;
  1217. case SIZE_U32: /* double word (32 bits) */
  1218. pci_read_config_dword(pdev, where, &u32val);
  1219. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1220. "%03x: %08x\n", where, u32val);
  1221. break;
  1222. case LPFC_PCI_CFG_BROWSE: /* browse all */
  1223. goto pcicfg_browse;
  1224. break;
  1225. default:
  1226. /* illegal count */
  1227. len = 0;
  1228. break;
  1229. }
  1230. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1231. pcicfg_browse:
  1232. /* Browse all PCI config space registers */
  1233. offset_label = idiag.offset.last_rd;
  1234. offset = offset_label;
  1235. /* Read PCI config space */
  1236. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1237. "%03x: ", offset_label);
  1238. while (index > 0) {
  1239. pci_read_config_dword(pdev, offset, &u32val);
  1240. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1241. "%08x ", u32val);
  1242. offset += sizeof(uint32_t);
  1243. if (offset >= LPFC_PCI_CFG_SIZE) {
  1244. len += snprintf(pbuffer+len,
  1245. LPFC_PCI_CFG_SIZE-len, "\n");
  1246. break;
  1247. }
  1248. index -= sizeof(uint32_t);
  1249. if (!index)
  1250. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1251. "\n");
  1252. else if (!(index % (8 * sizeof(uint32_t)))) {
  1253. offset_label += (8 * sizeof(uint32_t));
  1254. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1255. "\n%03x: ", offset_label);
  1256. }
  1257. }
  1258. /* Set up the offset for next portion of pci cfg read */
  1259. if (index == 0) {
  1260. idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
  1261. if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
  1262. idiag.offset.last_rd = 0;
  1263. } else
  1264. idiag.offset.last_rd = 0;
  1265. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1266. }
  1267. /**
  1268. * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
  1269. * @file: The file pointer to read from.
  1270. * @buf: The buffer to copy the user data from.
  1271. * @nbytes: The number of bytes to get.
  1272. * @ppos: The position in the file to start reading from.
  1273. *
  1274. * This routine get the debugfs idiag command struct from user space and
  1275. * then perform the syntax check for PCI config space read or write command
  1276. * accordingly. In the case of PCI config space read command, it sets up
  1277. * the command in the idiag command struct for the debugfs read operation.
  1278. * In the case of PCI config space write operation, it executes the write
  1279. * operation into the PCI config space accordingly.
  1280. *
  1281. * It returns the @nbytges passing in from debugfs user space when successful.
  1282. * In case of error conditions, it returns proper error code back to the user
  1283. * space.
  1284. */
  1285. static ssize_t
  1286. lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
  1287. size_t nbytes, loff_t *ppos)
  1288. {
  1289. struct lpfc_debug *debug = file->private_data;
  1290. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1291. uint32_t where, value, count;
  1292. uint32_t u32val;
  1293. uint16_t u16val;
  1294. uint8_t u8val;
  1295. struct pci_dev *pdev;
  1296. int rc;
  1297. pdev = phba->pcidev;
  1298. if (!pdev)
  1299. return -EFAULT;
  1300. /* This is a user write operation */
  1301. debug->op = LPFC_IDIAG_OP_WR;
  1302. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  1303. if (rc < 0)
  1304. return rc;
  1305. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1306. /* Sanity check on PCI config read command line arguments */
  1307. if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
  1308. goto error_out;
  1309. /* Read command from PCI config space, set up command fields */
  1310. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  1311. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  1312. if (count == LPFC_PCI_CFG_BROWSE) {
  1313. if (where % sizeof(uint32_t))
  1314. goto error_out;
  1315. /* Starting offset to browse */
  1316. idiag.offset.last_rd = where;
  1317. } else if ((count != sizeof(uint8_t)) &&
  1318. (count != sizeof(uint16_t)) &&
  1319. (count != sizeof(uint32_t)))
  1320. goto error_out;
  1321. if (count == sizeof(uint8_t)) {
  1322. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1323. goto error_out;
  1324. if (where % sizeof(uint8_t))
  1325. goto error_out;
  1326. }
  1327. if (count == sizeof(uint16_t)) {
  1328. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1329. goto error_out;
  1330. if (where % sizeof(uint16_t))
  1331. goto error_out;
  1332. }
  1333. if (count == sizeof(uint32_t)) {
  1334. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1335. goto error_out;
  1336. if (where % sizeof(uint32_t))
  1337. goto error_out;
  1338. }
  1339. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
  1340. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
  1341. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1342. /* Sanity check on PCI config write command line arguments */
  1343. if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
  1344. goto error_out;
  1345. /* Write command to PCI config space, read-modify-write */
  1346. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  1347. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  1348. value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
  1349. /* Sanity checks */
  1350. if ((count != sizeof(uint8_t)) &&
  1351. (count != sizeof(uint16_t)) &&
  1352. (count != sizeof(uint32_t)))
  1353. goto error_out;
  1354. if (count == sizeof(uint8_t)) {
  1355. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1356. goto error_out;
  1357. if (where % sizeof(uint8_t))
  1358. goto error_out;
  1359. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1360. pci_write_config_byte(pdev, where,
  1361. (uint8_t)value);
  1362. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1363. rc = pci_read_config_byte(pdev, where, &u8val);
  1364. if (!rc) {
  1365. u8val |= (uint8_t)value;
  1366. pci_write_config_byte(pdev, where,
  1367. u8val);
  1368. }
  1369. }
  1370. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1371. rc = pci_read_config_byte(pdev, where, &u8val);
  1372. if (!rc) {
  1373. u8val &= (uint8_t)(~value);
  1374. pci_write_config_byte(pdev, where,
  1375. u8val);
  1376. }
  1377. }
  1378. }
  1379. if (count == sizeof(uint16_t)) {
  1380. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1381. goto error_out;
  1382. if (where % sizeof(uint16_t))
  1383. goto error_out;
  1384. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1385. pci_write_config_word(pdev, where,
  1386. (uint16_t)value);
  1387. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1388. rc = pci_read_config_word(pdev, where, &u16val);
  1389. if (!rc) {
  1390. u16val |= (uint16_t)value;
  1391. pci_write_config_word(pdev, where,
  1392. u16val);
  1393. }
  1394. }
  1395. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1396. rc = pci_read_config_word(pdev, where, &u16val);
  1397. if (!rc) {
  1398. u16val &= (uint16_t)(~value);
  1399. pci_write_config_word(pdev, where,
  1400. u16val);
  1401. }
  1402. }
  1403. }
  1404. if (count == sizeof(uint32_t)) {
  1405. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1406. goto error_out;
  1407. if (where % sizeof(uint32_t))
  1408. goto error_out;
  1409. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1410. pci_write_config_dword(pdev, where, value);
  1411. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1412. rc = pci_read_config_dword(pdev, where,
  1413. &u32val);
  1414. if (!rc) {
  1415. u32val |= value;
  1416. pci_write_config_dword(pdev, where,
  1417. u32val);
  1418. }
  1419. }
  1420. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1421. rc = pci_read_config_dword(pdev, where,
  1422. &u32val);
  1423. if (!rc) {
  1424. u32val &= ~value;
  1425. pci_write_config_dword(pdev, where,
  1426. u32val);
  1427. }
  1428. }
  1429. }
  1430. } else
  1431. /* All other opecodes are illegal for now */
  1432. goto error_out;
  1433. return nbytes;
  1434. error_out:
  1435. memset(&idiag, 0, sizeof(idiag));
  1436. return -EINVAL;
  1437. }
  1438. /**
  1439. * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
  1440. * @file: The file pointer to read from.
  1441. * @buf: The buffer to copy the data to.
  1442. * @nbytes: The number of bytes to read.
  1443. * @ppos: The position in the file to start reading from.
  1444. *
  1445. * Description:
  1446. * This routine reads data from the @phba pci bar memory mapped space
  1447. * according to the idiag command, and copies to user @buf.
  1448. *
  1449. * Returns:
  1450. * This function returns the amount of data that was read (this could be less
  1451. * than @nbytes if the end of the file was reached) or a negative error value.
  1452. **/
  1453. static ssize_t
  1454. lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
  1455. loff_t *ppos)
  1456. {
  1457. struct lpfc_debug *debug = file->private_data;
  1458. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1459. int offset_label, offset, offset_run, len = 0, index;
  1460. int bar_num, acc_range, bar_size;
  1461. char *pbuffer;
  1462. void __iomem *mem_mapped_bar;
  1463. uint32_t if_type;
  1464. struct pci_dev *pdev;
  1465. uint32_t u32val;
  1466. pdev = phba->pcidev;
  1467. if (!pdev)
  1468. return 0;
  1469. /* This is a user read operation */
  1470. debug->op = LPFC_IDIAG_OP_RD;
  1471. if (!debug->buffer)
  1472. debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
  1473. if (!debug->buffer)
  1474. return 0;
  1475. pbuffer = debug->buffer;
  1476. if (*ppos)
  1477. return 0;
  1478. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  1479. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  1480. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  1481. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  1482. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  1483. } else
  1484. return 0;
  1485. if (acc_range == 0)
  1486. return 0;
  1487. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  1488. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  1489. if (bar_num == IDIAG_BARACC_BAR_0)
  1490. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1491. else if (bar_num == IDIAG_BARACC_BAR_1)
  1492. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  1493. else if (bar_num == IDIAG_BARACC_BAR_2)
  1494. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  1495. else
  1496. return 0;
  1497. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  1498. if (bar_num == IDIAG_BARACC_BAR_0)
  1499. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1500. else
  1501. return 0;
  1502. } else
  1503. return 0;
  1504. /* Read single PCI bar space register */
  1505. if (acc_range == SINGLE_WORD) {
  1506. offset_run = offset;
  1507. u32val = readl(mem_mapped_bar + offset_run);
  1508. len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1509. "%05x: %08x\n", offset_run, u32val);
  1510. } else
  1511. goto baracc_browse;
  1512. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1513. baracc_browse:
  1514. /* Browse all PCI bar space registers */
  1515. offset_label = idiag.offset.last_rd;
  1516. offset_run = offset_label;
  1517. /* Read PCI bar memory mapped space */
  1518. len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1519. "%05x: ", offset_label);
  1520. index = LPFC_PCI_BAR_RD_SIZE;
  1521. while (index > 0) {
  1522. u32val = readl(mem_mapped_bar + offset_run);
  1523. len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1524. "%08x ", u32val);
  1525. offset_run += sizeof(uint32_t);
  1526. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  1527. if (offset_run >= bar_size) {
  1528. len += snprintf(pbuffer+len,
  1529. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  1530. break;
  1531. }
  1532. } else {
  1533. if (offset_run >= offset +
  1534. (acc_range * sizeof(uint32_t))) {
  1535. len += snprintf(pbuffer+len,
  1536. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  1537. break;
  1538. }
  1539. }
  1540. index -= sizeof(uint32_t);
  1541. if (!index)
  1542. len += snprintf(pbuffer+len,
  1543. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  1544. else if (!(index % (8 * sizeof(uint32_t)))) {
  1545. offset_label += (8 * sizeof(uint32_t));
  1546. len += snprintf(pbuffer+len,
  1547. LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1548. "\n%05x: ", offset_label);
  1549. }
  1550. }
  1551. /* Set up the offset for next portion of pci bar read */
  1552. if (index == 0) {
  1553. idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
  1554. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  1555. if (idiag.offset.last_rd >= bar_size)
  1556. idiag.offset.last_rd = 0;
  1557. } else {
  1558. if (offset_run >= offset +
  1559. (acc_range * sizeof(uint32_t)))
  1560. idiag.offset.last_rd = offset;
  1561. }
  1562. } else {
  1563. if (acc_range == LPFC_PCI_BAR_BROWSE)
  1564. idiag.offset.last_rd = 0;
  1565. else
  1566. idiag.offset.last_rd = offset;
  1567. }
  1568. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1569. }
  1570. /**
  1571. * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
  1572. * @file: The file pointer to read from.
  1573. * @buf: The buffer to copy the user data from.
  1574. * @nbytes: The number of bytes to get.
  1575. * @ppos: The position in the file to start reading from.
  1576. *
  1577. * This routine get the debugfs idiag command struct from user space and
  1578. * then perform the syntax check for PCI bar memory mapped space read or
  1579. * write command accordingly. In the case of PCI bar memory mapped space
  1580. * read command, it sets up the command in the idiag command struct for
  1581. * the debugfs read operation. In the case of PCI bar memorpy mapped space
  1582. * write operation, it executes the write operation into the PCI bar memory
  1583. * mapped space accordingly.
  1584. *
  1585. * It returns the @nbytges passing in from debugfs user space when successful.
  1586. * In case of error conditions, it returns proper error code back to the user
  1587. * space.
  1588. */
  1589. static ssize_t
  1590. lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
  1591. size_t nbytes, loff_t *ppos)
  1592. {
  1593. struct lpfc_debug *debug = file->private_data;
  1594. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1595. uint32_t bar_num, bar_size, offset, value, acc_range;
  1596. struct pci_dev *pdev;
  1597. void __iomem *mem_mapped_bar;
  1598. uint32_t if_type;
  1599. uint32_t u32val;
  1600. int rc;
  1601. pdev = phba->pcidev;
  1602. if (!pdev)
  1603. return -EFAULT;
  1604. /* This is a user write operation */
  1605. debug->op = LPFC_IDIAG_OP_WR;
  1606. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  1607. if (rc < 0)
  1608. return rc;
  1609. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  1610. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  1611. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  1612. if ((bar_num != IDIAG_BARACC_BAR_0) &&
  1613. (bar_num != IDIAG_BARACC_BAR_1) &&
  1614. (bar_num != IDIAG_BARACC_BAR_2))
  1615. goto error_out;
  1616. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  1617. if (bar_num != IDIAG_BARACC_BAR_0)
  1618. goto error_out;
  1619. } else
  1620. goto error_out;
  1621. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  1622. if (bar_num == IDIAG_BARACC_BAR_0) {
  1623. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1624. LPFC_PCI_IF0_BAR0_SIZE;
  1625. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1626. } else if (bar_num == IDIAG_BARACC_BAR_1) {
  1627. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1628. LPFC_PCI_IF0_BAR1_SIZE;
  1629. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  1630. } else if (bar_num == IDIAG_BARACC_BAR_2) {
  1631. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1632. LPFC_PCI_IF0_BAR2_SIZE;
  1633. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  1634. } else
  1635. goto error_out;
  1636. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  1637. if (bar_num == IDIAG_BARACC_BAR_0) {
  1638. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1639. LPFC_PCI_IF2_BAR0_SIZE;
  1640. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1641. } else
  1642. goto error_out;
  1643. } else
  1644. goto error_out;
  1645. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  1646. if (offset % sizeof(uint32_t))
  1647. goto error_out;
  1648. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  1649. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  1650. /* Sanity check on PCI config read command line arguments */
  1651. if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
  1652. goto error_out;
  1653. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  1654. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  1655. if (offset > bar_size - sizeof(uint32_t))
  1656. goto error_out;
  1657. /* Starting offset to browse */
  1658. idiag.offset.last_rd = offset;
  1659. } else if (acc_range > SINGLE_WORD) {
  1660. if (offset + acc_range * sizeof(uint32_t) > bar_size)
  1661. goto error_out;
  1662. /* Starting offset to browse */
  1663. idiag.offset.last_rd = offset;
  1664. } else if (acc_range != SINGLE_WORD)
  1665. goto error_out;
  1666. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
  1667. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
  1668. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  1669. /* Sanity check on PCI bar write command line arguments */
  1670. if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
  1671. goto error_out;
  1672. /* Write command to PCI bar space, read-modify-write */
  1673. acc_range = SINGLE_WORD;
  1674. value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
  1675. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
  1676. writel(value, mem_mapped_bar + offset);
  1677. readl(mem_mapped_bar + offset);
  1678. }
  1679. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
  1680. u32val = readl(mem_mapped_bar + offset);
  1681. u32val |= value;
  1682. writel(u32val, mem_mapped_bar + offset);
  1683. readl(mem_mapped_bar + offset);
  1684. }
  1685. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  1686. u32val = readl(mem_mapped_bar + offset);
  1687. u32val &= ~value;
  1688. writel(u32val, mem_mapped_bar + offset);
  1689. readl(mem_mapped_bar + offset);
  1690. }
  1691. } else
  1692. /* All other opecodes are illegal for now */
  1693. goto error_out;
  1694. return nbytes;
  1695. error_out:
  1696. memset(&idiag, 0, sizeof(idiag));
  1697. return -EINVAL;
  1698. }
  1699. /**
  1700. * lpfc_idiag_queinfo_read - idiag debugfs read queue information
  1701. * @file: The file pointer to read from.
  1702. * @buf: The buffer to copy the data to.
  1703. * @nbytes: The number of bytes to read.
  1704. * @ppos: The position in the file to start reading from.
  1705. *
  1706. * Description:
  1707. * This routine reads data from the @phba SLI4 PCI function queue information,
  1708. * and copies to user @buf.
  1709. *
  1710. * Returns:
  1711. * This function returns the amount of data that was read (this could be less
  1712. * than @nbytes if the end of the file was reached) or a negative error value.
  1713. **/
  1714. static ssize_t
  1715. lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
  1716. loff_t *ppos)
  1717. {
  1718. struct lpfc_debug *debug = file->private_data;
  1719. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1720. int len = 0, fcp_qidx;
  1721. char *pbuffer;
  1722. if (!debug->buffer)
  1723. debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
  1724. if (!debug->buffer)
  1725. return 0;
  1726. pbuffer = debug->buffer;
  1727. if (*ppos)
  1728. return 0;
  1729. /* Get slow-path event queue information */
  1730. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1731. "Slow-path EQ information:\n");
  1732. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1733. "\tEQID[%02d], "
  1734. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1735. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1736. phba->sli4_hba.sp_eq->queue_id,
  1737. phba->sli4_hba.sp_eq->entry_count,
  1738. phba->sli4_hba.sp_eq->entry_size,
  1739. phba->sli4_hba.sp_eq->host_index,
  1740. phba->sli4_hba.sp_eq->hba_index);
  1741. /* Get fast-path event queue information */
  1742. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1743. "Fast-path EQ information:\n");
  1744. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
  1745. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1746. "\tEQID[%02d], "
  1747. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1748. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1749. phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
  1750. phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
  1751. phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
  1752. phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
  1753. phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
  1754. }
  1755. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1756. /* Get mailbox complete queue information */
  1757. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1758. "Slow-path MBX CQ information:\n");
  1759. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1760. "Associated EQID[%02d]:\n",
  1761. phba->sli4_hba.mbx_cq->assoc_qid);
  1762. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1763. "\tCQID[%02d], "
  1764. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1765. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1766. phba->sli4_hba.mbx_cq->queue_id,
  1767. phba->sli4_hba.mbx_cq->entry_count,
  1768. phba->sli4_hba.mbx_cq->entry_size,
  1769. phba->sli4_hba.mbx_cq->host_index,
  1770. phba->sli4_hba.mbx_cq->hba_index);
  1771. /* Get slow-path complete queue information */
  1772. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1773. "Slow-path ELS CQ information:\n");
  1774. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1775. "Associated EQID[%02d]:\n",
  1776. phba->sli4_hba.els_cq->assoc_qid);
  1777. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1778. "\tCQID [%02d], "
  1779. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1780. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1781. phba->sli4_hba.els_cq->queue_id,
  1782. phba->sli4_hba.els_cq->entry_count,
  1783. phba->sli4_hba.els_cq->entry_size,
  1784. phba->sli4_hba.els_cq->host_index,
  1785. phba->sli4_hba.els_cq->hba_index);
  1786. /* Get fast-path complete queue information */
  1787. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1788. "Fast-path FCP CQ information:\n");
  1789. fcp_qidx = 0;
  1790. do {
  1791. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1792. "Associated EQID[%02d]:\n",
  1793. phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
  1794. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1795. "\tCQID[%02d], "
  1796. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1797. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1798. phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
  1799. phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
  1800. phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
  1801. phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
  1802. phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
  1803. } while (++fcp_qidx < phba->cfg_fcp_eq_count);
  1804. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1805. /* Get mailbox queue information */
  1806. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1807. "Slow-path MBX MQ information:\n");
  1808. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1809. "Associated CQID[%02d]:\n",
  1810. phba->sli4_hba.mbx_wq->assoc_qid);
  1811. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1812. "\tWQID[%02d], "
  1813. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1814. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1815. phba->sli4_hba.mbx_wq->queue_id,
  1816. phba->sli4_hba.mbx_wq->entry_count,
  1817. phba->sli4_hba.mbx_wq->entry_size,
  1818. phba->sli4_hba.mbx_wq->host_index,
  1819. phba->sli4_hba.mbx_wq->hba_index);
  1820. /* Get slow-path work queue information */
  1821. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1822. "Slow-path ELS WQ information:\n");
  1823. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1824. "Associated CQID[%02d]:\n",
  1825. phba->sli4_hba.els_wq->assoc_qid);
  1826. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1827. "\tWQID[%02d], "
  1828. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1829. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1830. phba->sli4_hba.els_wq->queue_id,
  1831. phba->sli4_hba.els_wq->entry_count,
  1832. phba->sli4_hba.els_wq->entry_size,
  1833. phba->sli4_hba.els_wq->host_index,
  1834. phba->sli4_hba.els_wq->hba_index);
  1835. /* Get fast-path work queue information */
  1836. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1837. "Fast-path FCP WQ information:\n");
  1838. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) {
  1839. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1840. "Associated CQID[%02d]:\n",
  1841. phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
  1842. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1843. "\tWQID[%02d], "
  1844. "QE-COUNT[%04d], WQE-SIZE[%04d], "
  1845. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1846. phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
  1847. phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
  1848. phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
  1849. phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
  1850. phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
  1851. }
  1852. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1853. /* Get receive queue information */
  1854. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1855. "Slow-path RQ information:\n");
  1856. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1857. "Associated CQID[%02d]:\n",
  1858. phba->sli4_hba.hdr_rq->assoc_qid);
  1859. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1860. "\tHQID[%02d], "
  1861. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1862. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1863. phba->sli4_hba.hdr_rq->queue_id,
  1864. phba->sli4_hba.hdr_rq->entry_count,
  1865. phba->sli4_hba.hdr_rq->entry_size,
  1866. phba->sli4_hba.hdr_rq->host_index,
  1867. phba->sli4_hba.hdr_rq->hba_index);
  1868. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1869. "\tDQID[%02d], "
  1870. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1871. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1872. phba->sli4_hba.dat_rq->queue_id,
  1873. phba->sli4_hba.dat_rq->entry_count,
  1874. phba->sli4_hba.dat_rq->entry_size,
  1875. phba->sli4_hba.dat_rq->host_index,
  1876. phba->sli4_hba.dat_rq->hba_index);
  1877. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1878. }
  1879. /**
  1880. * lpfc_idiag_que_param_check - queue access command parameter sanity check
  1881. * @q: The pointer to queue structure.
  1882. * @index: The index into a queue entry.
  1883. * @count: The number of queue entries to access.
  1884. *
  1885. * Description:
  1886. * The routine performs sanity check on device queue access method commands.
  1887. *
  1888. * Returns:
  1889. * This function returns -EINVAL when fails the sanity check, otherwise, it
  1890. * returns 0.
  1891. **/
  1892. static int
  1893. lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
  1894. {
  1895. /* Only support single entry read or browsing */
  1896. if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
  1897. return -EINVAL;
  1898. if (index > q->entry_count - 1)
  1899. return -EINVAL;
  1900. return 0;
  1901. }
  1902. /**
  1903. * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
  1904. * @pbuffer: The pointer to buffer to copy the read data into.
  1905. * @pque: The pointer to the queue to be read.
  1906. * @index: The index into the queue entry.
  1907. *
  1908. * Description:
  1909. * This routine reads out a single entry from the given queue's index location
  1910. * and copies it into the buffer provided.
  1911. *
  1912. * Returns:
  1913. * This function returns 0 when it fails, otherwise, it returns the length of
  1914. * the data read into the buffer provided.
  1915. **/
  1916. static int
  1917. lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
  1918. uint32_t index)
  1919. {
  1920. int offset, esize;
  1921. uint32_t *pentry;
  1922. if (!pbuffer || !pque)
  1923. return 0;
  1924. esize = pque->entry_size;
  1925. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  1926. "QE-INDEX[%04d]:\n", index);
  1927. offset = 0;
  1928. pentry = pque->qe[index].address;
  1929. while (esize > 0) {
  1930. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  1931. "%08x ", *pentry);
  1932. pentry++;
  1933. offset += sizeof(uint32_t);
  1934. esize -= sizeof(uint32_t);
  1935. if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
  1936. len += snprintf(pbuffer+len,
  1937. LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  1938. }
  1939. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  1940. return len;
  1941. }
  1942. /**
  1943. * lpfc_idiag_queacc_read - idiag debugfs read port queue
  1944. * @file: The file pointer to read from.
  1945. * @buf: The buffer to copy the data to.
  1946. * @nbytes: The number of bytes to read.
  1947. * @ppos: The position in the file to start reading from.
  1948. *
  1949. * Description:
  1950. * This routine reads data from the @phba device queue memory according to the
  1951. * idiag command, and copies to user @buf. Depending on the queue dump read
  1952. * command setup, it does either a single queue entry read or browing through
  1953. * all entries of the queue.
  1954. *
  1955. * Returns:
  1956. * This function returns the amount of data that was read (this could be less
  1957. * than @nbytes if the end of the file was reached) or a negative error value.
  1958. **/
  1959. static ssize_t
  1960. lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
  1961. loff_t *ppos)
  1962. {
  1963. struct lpfc_debug *debug = file->private_data;
  1964. uint32_t last_index, index, count;
  1965. struct lpfc_queue *pque = NULL;
  1966. char *pbuffer;
  1967. int len = 0;
  1968. /* This is a user read operation */
  1969. debug->op = LPFC_IDIAG_OP_RD;
  1970. if (!debug->buffer)
  1971. debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
  1972. if (!debug->buffer)
  1973. return 0;
  1974. pbuffer = debug->buffer;
  1975. if (*ppos)
  1976. return 0;
  1977. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  1978. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  1979. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  1980. pque = (struct lpfc_queue *)idiag.ptr_private;
  1981. } else
  1982. return 0;
  1983. /* Browse the queue starting from index */
  1984. if (count == LPFC_QUE_ACC_BROWSE)
  1985. goto que_browse;
  1986. /* Read a single entry from the queue */
  1987. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  1988. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1989. que_browse:
  1990. /* Browse all entries from the queue */
  1991. last_index = idiag.offset.last_rd;
  1992. index = last_index;
  1993. while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
  1994. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  1995. index++;
  1996. if (index > pque->entry_count - 1)
  1997. break;
  1998. }
  1999. /* Set up the offset for next portion of pci cfg read */
  2000. if (index > pque->entry_count - 1)
  2001. index = 0;
  2002. idiag.offset.last_rd = index;
  2003. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2004. }
  2005. /**
  2006. * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
  2007. * @file: The file pointer to read from.
  2008. * @buf: The buffer to copy the user data from.
  2009. * @nbytes: The number of bytes to get.
  2010. * @ppos: The position in the file to start reading from.
  2011. *
  2012. * This routine get the debugfs idiag command struct from user space and then
  2013. * perform the syntax check for port queue read (dump) or write (set) command
  2014. * accordingly. In the case of port queue read command, it sets up the command
  2015. * in the idiag command struct for the following debugfs read operation. In
  2016. * the case of port queue write operation, it executes the write operation
  2017. * into the port queue entry accordingly.
  2018. *
  2019. * It returns the @nbytges passing in from debugfs user space when successful.
  2020. * In case of error conditions, it returns proper error code back to the user
  2021. * space.
  2022. **/
  2023. static ssize_t
  2024. lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
  2025. size_t nbytes, loff_t *ppos)
  2026. {
  2027. struct lpfc_debug *debug = file->private_data;
  2028. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2029. uint32_t qidx, quetp, queid, index, count, offset, value;
  2030. uint32_t *pentry;
  2031. struct lpfc_queue *pque;
  2032. int rc;
  2033. /* This is a user write operation */
  2034. debug->op = LPFC_IDIAG_OP_WR;
  2035. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2036. if (rc < 0)
  2037. return rc;
  2038. /* Get and sanity check on command feilds */
  2039. quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
  2040. queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
  2041. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  2042. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  2043. offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
  2044. value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
  2045. /* Sanity check on command line arguments */
  2046. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  2047. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  2048. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  2049. if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
  2050. goto error_out;
  2051. if (count != 1)
  2052. goto error_out;
  2053. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  2054. if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
  2055. goto error_out;
  2056. } else
  2057. goto error_out;
  2058. switch (quetp) {
  2059. case LPFC_IDIAG_EQ:
  2060. /* Slow-path event queue */
  2061. if (phba->sli4_hba.sp_eq->queue_id == queid) {
  2062. /* Sanity check */
  2063. rc = lpfc_idiag_que_param_check(
  2064. phba->sli4_hba.sp_eq, index, count);
  2065. if (rc)
  2066. goto error_out;
  2067. idiag.ptr_private = phba->sli4_hba.sp_eq;
  2068. goto pass_check;
  2069. }
  2070. /* Fast-path event queue */
  2071. for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
  2072. if (phba->sli4_hba.fp_eq[qidx]->queue_id == queid) {
  2073. /* Sanity check */
  2074. rc = lpfc_idiag_que_param_check(
  2075. phba->sli4_hba.fp_eq[qidx],
  2076. index, count);
  2077. if (rc)
  2078. goto error_out;
  2079. idiag.ptr_private = phba->sli4_hba.fp_eq[qidx];
  2080. goto pass_check;
  2081. }
  2082. }
  2083. goto error_out;
  2084. break;
  2085. case LPFC_IDIAG_CQ:
  2086. /* MBX complete queue */
  2087. if (phba->sli4_hba.mbx_cq->queue_id == queid) {
  2088. /* Sanity check */
  2089. rc = lpfc_idiag_que_param_check(
  2090. phba->sli4_hba.mbx_cq, index, count);
  2091. if (rc)
  2092. goto error_out;
  2093. idiag.ptr_private = phba->sli4_hba.mbx_cq;
  2094. goto pass_check;
  2095. }
  2096. /* ELS complete queue */
  2097. if (phba->sli4_hba.els_cq->queue_id == queid) {
  2098. /* Sanity check */
  2099. rc = lpfc_idiag_que_param_check(
  2100. phba->sli4_hba.els_cq, index, count);
  2101. if (rc)
  2102. goto error_out;
  2103. idiag.ptr_private = phba->sli4_hba.els_cq;
  2104. goto pass_check;
  2105. }
  2106. /* FCP complete queue */
  2107. qidx = 0;
  2108. do {
  2109. if (phba->sli4_hba.fcp_cq[qidx]->queue_id == queid) {
  2110. /* Sanity check */
  2111. rc = lpfc_idiag_que_param_check(
  2112. phba->sli4_hba.fcp_cq[qidx],
  2113. index, count);
  2114. if (rc)
  2115. goto error_out;
  2116. idiag.ptr_private =
  2117. phba->sli4_hba.fcp_cq[qidx];
  2118. goto pass_check;
  2119. }
  2120. } while (++qidx < phba->cfg_fcp_eq_count);
  2121. goto error_out;
  2122. break;
  2123. case LPFC_IDIAG_MQ:
  2124. /* MBX work queue */
  2125. if (phba->sli4_hba.mbx_wq->queue_id == queid) {
  2126. /* Sanity check */
  2127. rc = lpfc_idiag_que_param_check(
  2128. phba->sli4_hba.mbx_wq, index, count);
  2129. if (rc)
  2130. goto error_out;
  2131. idiag.ptr_private = phba->sli4_hba.mbx_wq;
  2132. goto pass_check;
  2133. }
  2134. break;
  2135. case LPFC_IDIAG_WQ:
  2136. /* ELS work queue */
  2137. if (phba->sli4_hba.els_wq->queue_id == queid) {
  2138. /* Sanity check */
  2139. rc = lpfc_idiag_que_param_check(
  2140. phba->sli4_hba.els_wq, index, count);
  2141. if (rc)
  2142. goto error_out;
  2143. idiag.ptr_private = phba->sli4_hba.els_wq;
  2144. goto pass_check;
  2145. }
  2146. /* FCP work queue */
  2147. for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
  2148. if (phba->sli4_hba.fcp_wq[qidx]->queue_id == queid) {
  2149. /* Sanity check */
  2150. rc = lpfc_idiag_que_param_check(
  2151. phba->sli4_hba.fcp_wq[qidx],
  2152. index, count);
  2153. if (rc)
  2154. goto error_out;
  2155. idiag.ptr_private =
  2156. phba->sli4_hba.fcp_wq[qidx];
  2157. goto pass_check;
  2158. }
  2159. }
  2160. goto error_out;
  2161. break;
  2162. case LPFC_IDIAG_RQ:
  2163. /* HDR queue */
  2164. if (phba->sli4_hba.hdr_rq->queue_id == queid) {
  2165. /* Sanity check */
  2166. rc = lpfc_idiag_que_param_check(
  2167. phba->sli4_hba.hdr_rq, index, count);
  2168. if (rc)
  2169. goto error_out;
  2170. idiag.ptr_private = phba->sli4_hba.hdr_rq;
  2171. goto pass_check;
  2172. }
  2173. /* DAT queue */
  2174. if (phba->sli4_hba.dat_rq->queue_id == queid) {
  2175. /* Sanity check */
  2176. rc = lpfc_idiag_que_param_check(
  2177. phba->sli4_hba.dat_rq, index, count);
  2178. if (rc)
  2179. goto error_out;
  2180. idiag.ptr_private = phba->sli4_hba.dat_rq;
  2181. goto pass_check;
  2182. }
  2183. goto error_out;
  2184. break;
  2185. default:
  2186. goto error_out;
  2187. break;
  2188. }
  2189. pass_check:
  2190. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  2191. if (count == LPFC_QUE_ACC_BROWSE)
  2192. idiag.offset.last_rd = index;
  2193. }
  2194. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  2195. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  2196. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  2197. /* Additional sanity checks on write operation */
  2198. pque = (struct lpfc_queue *)idiag.ptr_private;
  2199. if (offset > pque->entry_size/sizeof(uint32_t) - 1)
  2200. goto error_out;
  2201. pentry = pque->qe[index].address;
  2202. pentry += offset;
  2203. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
  2204. *pentry = value;
  2205. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
  2206. *pentry |= value;
  2207. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
  2208. *pentry &= ~value;
  2209. }
  2210. return nbytes;
  2211. error_out:
  2212. /* Clean out command structure on command error out */
  2213. memset(&idiag, 0, sizeof(idiag));
  2214. return -EINVAL;
  2215. }
  2216. /**
  2217. * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
  2218. * @phba: The pointer to hba structure.
  2219. * @pbuffer: The pointer to the buffer to copy the data to.
  2220. * @len: The lenght of bytes to copied.
  2221. * @drbregid: The id to doorbell registers.
  2222. *
  2223. * Description:
  2224. * This routine reads a doorbell register and copies its content to the
  2225. * user buffer pointed to by @pbuffer.
  2226. *
  2227. * Returns:
  2228. * This function returns the amount of data that was copied into @pbuffer.
  2229. **/
  2230. static int
  2231. lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  2232. int len, uint32_t drbregid)
  2233. {
  2234. if (!pbuffer)
  2235. return 0;
  2236. switch (drbregid) {
  2237. case LPFC_DRB_EQCQ:
  2238. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2239. "EQCQ-DRB-REG: 0x%08x\n",
  2240. readl(phba->sli4_hba.EQCQDBregaddr));
  2241. break;
  2242. case LPFC_DRB_MQ:
  2243. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2244. "MQ-DRB-REG: 0x%08x\n",
  2245. readl(phba->sli4_hba.MQDBregaddr));
  2246. break;
  2247. case LPFC_DRB_WQ:
  2248. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2249. "WQ-DRB-REG: 0x%08x\n",
  2250. readl(phba->sli4_hba.WQDBregaddr));
  2251. break;
  2252. case LPFC_DRB_RQ:
  2253. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2254. "RQ-DRB-REG: 0x%08x\n",
  2255. readl(phba->sli4_hba.RQDBregaddr));
  2256. break;
  2257. default:
  2258. break;
  2259. }
  2260. return len;
  2261. }
  2262. /**
  2263. * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
  2264. * @file: The file pointer to read from.
  2265. * @buf: The buffer to copy the data to.
  2266. * @nbytes: The number of bytes to read.
  2267. * @ppos: The position in the file to start reading from.
  2268. *
  2269. * Description:
  2270. * This routine reads data from the @phba device doorbell register according
  2271. * to the idiag command, and copies to user @buf. Depending on the doorbell
  2272. * register read command setup, it does either a single doorbell register
  2273. * read or dump all doorbell registers.
  2274. *
  2275. * Returns:
  2276. * This function returns the amount of data that was read (this could be less
  2277. * than @nbytes if the end of the file was reached) or a negative error value.
  2278. **/
  2279. static ssize_t
  2280. lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
  2281. loff_t *ppos)
  2282. {
  2283. struct lpfc_debug *debug = file->private_data;
  2284. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2285. uint32_t drb_reg_id, i;
  2286. char *pbuffer;
  2287. int len = 0;
  2288. /* This is a user read operation */
  2289. debug->op = LPFC_IDIAG_OP_RD;
  2290. if (!debug->buffer)
  2291. debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
  2292. if (!debug->buffer)
  2293. return 0;
  2294. pbuffer = debug->buffer;
  2295. if (*ppos)
  2296. return 0;
  2297. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
  2298. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  2299. else
  2300. return 0;
  2301. if (drb_reg_id == LPFC_DRB_ACC_ALL)
  2302. for (i = 1; i <= LPFC_DRB_MAX; i++)
  2303. len = lpfc_idiag_drbacc_read_reg(phba,
  2304. pbuffer, len, i);
  2305. else
  2306. len = lpfc_idiag_drbacc_read_reg(phba,
  2307. pbuffer, len, drb_reg_id);
  2308. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2309. }
  2310. /**
  2311. * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
  2312. * @file: The file pointer to read from.
  2313. * @buf: The buffer to copy the user data from.
  2314. * @nbytes: The number of bytes to get.
  2315. * @ppos: The position in the file to start reading from.
  2316. *
  2317. * This routine get the debugfs idiag command struct from user space and then
  2318. * perform the syntax check for port doorbell register read (dump) or write
  2319. * (set) command accordingly. In the case of port queue read command, it sets
  2320. * up the command in the idiag command struct for the following debugfs read
  2321. * operation. In the case of port doorbell register write operation, it
  2322. * executes the write operation into the port doorbell register accordingly.
  2323. *
  2324. * It returns the @nbytges passing in from debugfs user space when successful.
  2325. * In case of error conditions, it returns proper error code back to the user
  2326. * space.
  2327. **/
  2328. static ssize_t
  2329. lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
  2330. size_t nbytes, loff_t *ppos)
  2331. {
  2332. struct lpfc_debug *debug = file->private_data;
  2333. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2334. uint32_t drb_reg_id, value, reg_val = 0;
  2335. void __iomem *drb_reg;
  2336. int rc;
  2337. /* This is a user write operation */
  2338. debug->op = LPFC_IDIAG_OP_WR;
  2339. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2340. if (rc < 0)
  2341. return rc;
  2342. /* Sanity check on command line arguments */
  2343. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  2344. value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
  2345. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  2346. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  2347. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2348. if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
  2349. goto error_out;
  2350. if (drb_reg_id > LPFC_DRB_MAX)
  2351. goto error_out;
  2352. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
  2353. if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
  2354. goto error_out;
  2355. if ((drb_reg_id > LPFC_DRB_MAX) &&
  2356. (drb_reg_id != LPFC_DRB_ACC_ALL))
  2357. goto error_out;
  2358. } else
  2359. goto error_out;
  2360. /* Perform the write access operation */
  2361. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  2362. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  2363. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2364. switch (drb_reg_id) {
  2365. case LPFC_DRB_EQCQ:
  2366. drb_reg = phba->sli4_hba.EQCQDBregaddr;
  2367. break;
  2368. case LPFC_DRB_MQ:
  2369. drb_reg = phba->sli4_hba.MQDBregaddr;
  2370. break;
  2371. case LPFC_DRB_WQ:
  2372. drb_reg = phba->sli4_hba.WQDBregaddr;
  2373. break;
  2374. case LPFC_DRB_RQ:
  2375. drb_reg = phba->sli4_hba.RQDBregaddr;
  2376. break;
  2377. default:
  2378. goto error_out;
  2379. }
  2380. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
  2381. reg_val = value;
  2382. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
  2383. reg_val = readl(drb_reg);
  2384. reg_val |= value;
  2385. }
  2386. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2387. reg_val = readl(drb_reg);
  2388. reg_val &= ~value;
  2389. }
  2390. writel(reg_val, drb_reg);
  2391. readl(drb_reg); /* flush */
  2392. }
  2393. return nbytes;
  2394. error_out:
  2395. /* Clean out command structure on command error out */
  2396. memset(&idiag, 0, sizeof(idiag));
  2397. return -EINVAL;
  2398. }
  2399. /**
  2400. * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
  2401. * @phba: The pointer to hba structure.
  2402. * @pbuffer: The pointer to the buffer to copy the data to.
  2403. * @len: The lenght of bytes to copied.
  2404. * @drbregid: The id to doorbell registers.
  2405. *
  2406. * Description:
  2407. * This routine reads a control register and copies its content to the
  2408. * user buffer pointed to by @pbuffer.
  2409. *
  2410. * Returns:
  2411. * This function returns the amount of data that was copied into @pbuffer.
  2412. **/
  2413. static int
  2414. lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  2415. int len, uint32_t ctlregid)
  2416. {
  2417. if (!pbuffer)
  2418. return 0;
  2419. switch (ctlregid) {
  2420. case LPFC_CTL_PORT_SEM:
  2421. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2422. "Port SemReg: 0x%08x\n",
  2423. readl(phba->sli4_hba.conf_regs_memmap_p +
  2424. LPFC_CTL_PORT_SEM_OFFSET));
  2425. break;
  2426. case LPFC_CTL_PORT_STA:
  2427. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2428. "Port StaReg: 0x%08x\n",
  2429. readl(phba->sli4_hba.conf_regs_memmap_p +
  2430. LPFC_CTL_PORT_STA_OFFSET));
  2431. break;
  2432. case LPFC_CTL_PORT_CTL:
  2433. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2434. "Port CtlReg: 0x%08x\n",
  2435. readl(phba->sli4_hba.conf_regs_memmap_p +
  2436. LPFC_CTL_PORT_CTL_OFFSET));
  2437. break;
  2438. case LPFC_CTL_PORT_ER1:
  2439. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2440. "Port Er1Reg: 0x%08x\n",
  2441. readl(phba->sli4_hba.conf_regs_memmap_p +
  2442. LPFC_CTL_PORT_ER1_OFFSET));
  2443. break;
  2444. case LPFC_CTL_PORT_ER2:
  2445. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2446. "Port Er2Reg: 0x%08x\n",
  2447. readl(phba->sli4_hba.conf_regs_memmap_p +
  2448. LPFC_CTL_PORT_ER2_OFFSET));
  2449. break;
  2450. case LPFC_CTL_PDEV_CTL:
  2451. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2452. "PDev CtlReg: 0x%08x\n",
  2453. readl(phba->sli4_hba.conf_regs_memmap_p +
  2454. LPFC_CTL_PDEV_CTL_OFFSET));
  2455. break;
  2456. default:
  2457. break;
  2458. }
  2459. return len;
  2460. }
  2461. /**
  2462. * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
  2463. * @file: The file pointer to read from.
  2464. * @buf: The buffer to copy the data to.
  2465. * @nbytes: The number of bytes to read.
  2466. * @ppos: The position in the file to start reading from.
  2467. *
  2468. * Description:
  2469. * This routine reads data from the @phba port and device registers according
  2470. * to the idiag command, and copies to user @buf.
  2471. *
  2472. * Returns:
  2473. * This function returns the amount of data that was read (this could be less
  2474. * than @nbytes if the end of the file was reached) or a negative error value.
  2475. **/
  2476. static ssize_t
  2477. lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
  2478. loff_t *ppos)
  2479. {
  2480. struct lpfc_debug *debug = file->private_data;
  2481. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2482. uint32_t ctl_reg_id, i;
  2483. char *pbuffer;
  2484. int len = 0;
  2485. /* This is a user read operation */
  2486. debug->op = LPFC_IDIAG_OP_RD;
  2487. if (!debug->buffer)
  2488. debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
  2489. if (!debug->buffer)
  2490. return 0;
  2491. pbuffer = debug->buffer;
  2492. if (*ppos)
  2493. return 0;
  2494. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
  2495. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  2496. else
  2497. return 0;
  2498. if (ctl_reg_id == LPFC_CTL_ACC_ALL)
  2499. for (i = 1; i <= LPFC_CTL_MAX; i++)
  2500. len = lpfc_idiag_ctlacc_read_reg(phba,
  2501. pbuffer, len, i);
  2502. else
  2503. len = lpfc_idiag_ctlacc_read_reg(phba,
  2504. pbuffer, len, ctl_reg_id);
  2505. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2506. }
  2507. /**
  2508. * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
  2509. * @file: The file pointer to read from.
  2510. * @buf: The buffer to copy the user data from.
  2511. * @nbytes: The number of bytes to get.
  2512. * @ppos: The position in the file to start reading from.
  2513. *
  2514. * This routine get the debugfs idiag command struct from user space and then
  2515. * perform the syntax check for port and device control register read (dump)
  2516. * or write (set) command accordingly.
  2517. *
  2518. * It returns the @nbytges passing in from debugfs user space when successful.
  2519. * In case of error conditions, it returns proper error code back to the user
  2520. * space.
  2521. **/
  2522. static ssize_t
  2523. lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
  2524. size_t nbytes, loff_t *ppos)
  2525. {
  2526. struct lpfc_debug *debug = file->private_data;
  2527. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2528. uint32_t ctl_reg_id, value, reg_val = 0;
  2529. void __iomem *ctl_reg;
  2530. int rc;
  2531. /* This is a user write operation */
  2532. debug->op = LPFC_IDIAG_OP_WR;
  2533. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2534. if (rc < 0)
  2535. return rc;
  2536. /* Sanity check on command line arguments */
  2537. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  2538. value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
  2539. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  2540. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  2541. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  2542. if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
  2543. goto error_out;
  2544. if (ctl_reg_id > LPFC_CTL_MAX)
  2545. goto error_out;
  2546. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
  2547. if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
  2548. goto error_out;
  2549. if ((ctl_reg_id > LPFC_CTL_MAX) &&
  2550. (ctl_reg_id != LPFC_CTL_ACC_ALL))
  2551. goto error_out;
  2552. } else
  2553. goto error_out;
  2554. /* Perform the write access operation */
  2555. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  2556. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  2557. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  2558. switch (ctl_reg_id) {
  2559. case LPFC_CTL_PORT_SEM:
  2560. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2561. LPFC_CTL_PORT_SEM_OFFSET;
  2562. break;
  2563. case LPFC_CTL_PORT_STA:
  2564. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2565. LPFC_CTL_PORT_STA_OFFSET;
  2566. break;
  2567. case LPFC_CTL_PORT_CTL:
  2568. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2569. LPFC_CTL_PORT_CTL_OFFSET;
  2570. break;
  2571. case LPFC_CTL_PORT_ER1:
  2572. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2573. LPFC_CTL_PORT_ER1_OFFSET;
  2574. break;
  2575. case LPFC_CTL_PORT_ER2:
  2576. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2577. LPFC_CTL_PORT_ER2_OFFSET;
  2578. break;
  2579. case LPFC_CTL_PDEV_CTL:
  2580. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2581. LPFC_CTL_PDEV_CTL_OFFSET;
  2582. break;
  2583. default:
  2584. goto error_out;
  2585. }
  2586. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
  2587. reg_val = value;
  2588. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
  2589. reg_val = readl(ctl_reg);
  2590. reg_val |= value;
  2591. }
  2592. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  2593. reg_val = readl(ctl_reg);
  2594. reg_val &= ~value;
  2595. }
  2596. writel(reg_val, ctl_reg);
  2597. readl(ctl_reg); /* flush */
  2598. }
  2599. return nbytes;
  2600. error_out:
  2601. /* Clean out command structure on command error out */
  2602. memset(&idiag, 0, sizeof(idiag));
  2603. return -EINVAL;
  2604. }
  2605. /**
  2606. * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
  2607. * @phba: Pointer to HBA context object.
  2608. * @pbuffer: Pointer to data buffer.
  2609. *
  2610. * Description:
  2611. * This routine gets the driver mailbox access debugfs setup information.
  2612. *
  2613. * Returns:
  2614. * This function returns the amount of data that was read (this could be less
  2615. * than @nbytes if the end of the file was reached) or a negative error value.
  2616. **/
  2617. static int
  2618. lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
  2619. {
  2620. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  2621. int len = 0;
  2622. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  2623. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  2624. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  2625. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  2626. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2627. "mbx_dump_map: 0x%08x\n", mbx_dump_map);
  2628. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2629. "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
  2630. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2631. "mbx_word_cnt: %04d\n", mbx_word_cnt);
  2632. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2633. "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
  2634. return len;
  2635. }
  2636. /**
  2637. * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
  2638. * @file: The file pointer to read from.
  2639. * @buf: The buffer to copy the data to.
  2640. * @nbytes: The number of bytes to read.
  2641. * @ppos: The position in the file to start reading from.
  2642. *
  2643. * Description:
  2644. * This routine reads data from the @phba driver mailbox access debugfs setup
  2645. * information.
  2646. *
  2647. * Returns:
  2648. * This function returns the amount of data that was read (this could be less
  2649. * than @nbytes if the end of the file was reached) or a negative error value.
  2650. **/
  2651. static ssize_t
  2652. lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
  2653. loff_t *ppos)
  2654. {
  2655. struct lpfc_debug *debug = file->private_data;
  2656. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2657. char *pbuffer;
  2658. int len = 0;
  2659. /* This is a user read operation */
  2660. debug->op = LPFC_IDIAG_OP_RD;
  2661. if (!debug->buffer)
  2662. debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
  2663. if (!debug->buffer)
  2664. return 0;
  2665. pbuffer = debug->buffer;
  2666. if (*ppos)
  2667. return 0;
  2668. if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
  2669. (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
  2670. return 0;
  2671. len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
  2672. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2673. }
  2674. /**
  2675. * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
  2676. * @file: The file pointer to read from.
  2677. * @buf: The buffer to copy the user data from.
  2678. * @nbytes: The number of bytes to get.
  2679. * @ppos: The position in the file to start reading from.
  2680. *
  2681. * This routine get the debugfs idiag command struct from user space and then
  2682. * perform the syntax check for driver mailbox command (dump) and sets up the
  2683. * necessary states in the idiag command struct accordingly.
  2684. *
  2685. * It returns the @nbytges passing in from debugfs user space when successful.
  2686. * In case of error conditions, it returns proper error code back to the user
  2687. * space.
  2688. **/
  2689. static ssize_t
  2690. lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
  2691. size_t nbytes, loff_t *ppos)
  2692. {
  2693. struct lpfc_debug *debug = file->private_data;
  2694. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  2695. int rc;
  2696. /* This is a user write operation */
  2697. debug->op = LPFC_IDIAG_OP_WR;
  2698. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2699. if (rc < 0)
  2700. return rc;
  2701. /* Sanity check on command line arguments */
  2702. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  2703. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  2704. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  2705. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  2706. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
  2707. if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
  2708. goto error_out;
  2709. if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
  2710. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  2711. goto error_out;
  2712. if (mbx_word_cnt > sizeof(MAILBOX_t))
  2713. goto error_out;
  2714. } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
  2715. if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
  2716. goto error_out;
  2717. if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
  2718. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  2719. goto error_out;
  2720. if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
  2721. goto error_out;
  2722. if (mbx_mbox_cmd != 0x9b)
  2723. goto error_out;
  2724. } else
  2725. goto error_out;
  2726. if (mbx_word_cnt == 0)
  2727. goto error_out;
  2728. if (rc != LPFC_MBX_DMP_ARG)
  2729. goto error_out;
  2730. if (mbx_mbox_cmd & ~0xff)
  2731. goto error_out;
  2732. /* condition for stop mailbox dump */
  2733. if (mbx_dump_cnt == 0)
  2734. goto reset_out;
  2735. return nbytes;
  2736. reset_out:
  2737. /* Clean out command structure on command error out */
  2738. memset(&idiag, 0, sizeof(idiag));
  2739. return nbytes;
  2740. error_out:
  2741. /* Clean out command structure on command error out */
  2742. memset(&idiag, 0, sizeof(idiag));
  2743. return -EINVAL;
  2744. }
  2745. /**
  2746. * lpfc_idiag_extacc_avail_get - get the available extents information
  2747. * @phba: pointer to lpfc hba data structure.
  2748. * @pbuffer: pointer to internal buffer.
  2749. * @len: length into the internal buffer data has been copied.
  2750. *
  2751. * Description:
  2752. * This routine is to get the available extent information.
  2753. *
  2754. * Returns:
  2755. * overall lenth of the data read into the internal buffer.
  2756. **/
  2757. static int
  2758. lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
  2759. {
  2760. uint16_t ext_cnt, ext_size;
  2761. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2762. "\nAvailable Extents Information:\n");
  2763. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2764. "\tPort Available VPI extents: ");
  2765. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
  2766. &ext_cnt, &ext_size);
  2767. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2768. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  2769. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2770. "\tPort Available VFI extents: ");
  2771. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
  2772. &ext_cnt, &ext_size);
  2773. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2774. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  2775. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2776. "\tPort Available RPI extents: ");
  2777. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
  2778. &ext_cnt, &ext_size);
  2779. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2780. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  2781. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2782. "\tPort Available XRI extents: ");
  2783. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
  2784. &ext_cnt, &ext_size);
  2785. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2786. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  2787. return len;
  2788. }
  2789. /**
  2790. * lpfc_idiag_extacc_alloc_get - get the allocated extents information
  2791. * @phba: pointer to lpfc hba data structure.
  2792. * @pbuffer: pointer to internal buffer.
  2793. * @len: length into the internal buffer data has been copied.
  2794. *
  2795. * Description:
  2796. * This routine is to get the allocated extent information.
  2797. *
  2798. * Returns:
  2799. * overall lenth of the data read into the internal buffer.
  2800. **/
  2801. static int
  2802. lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
  2803. {
  2804. uint16_t ext_cnt, ext_size;
  2805. int rc;
  2806. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2807. "\nAllocated Extents Information:\n");
  2808. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2809. "\tHost Allocated VPI extents: ");
  2810. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
  2811. &ext_cnt, &ext_size);
  2812. if (!rc)
  2813. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2814. "Port %d Extent %3d, Size %3d\n",
  2815. phba->brd_no, ext_cnt, ext_size);
  2816. else
  2817. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2818. "N/A\n");
  2819. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2820. "\tHost Allocated VFI extents: ");
  2821. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
  2822. &ext_cnt, &ext_size);
  2823. if (!rc)
  2824. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2825. "Port %d Extent %3d, Size %3d\n",
  2826. phba->brd_no, ext_cnt, ext_size);
  2827. else
  2828. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2829. "N/A\n");
  2830. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2831. "\tHost Allocated RPI extents: ");
  2832. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
  2833. &ext_cnt, &ext_size);
  2834. if (!rc)
  2835. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2836. "Port %d Extent %3d, Size %3d\n",
  2837. phba->brd_no, ext_cnt, ext_size);
  2838. else
  2839. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2840. "N/A\n");
  2841. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2842. "\tHost Allocated XRI extents: ");
  2843. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
  2844. &ext_cnt, &ext_size);
  2845. if (!rc)
  2846. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2847. "Port %d Extent %3d, Size %3d\n",
  2848. phba->brd_no, ext_cnt, ext_size);
  2849. else
  2850. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2851. "N/A\n");
  2852. return len;
  2853. }
  2854. /**
  2855. * lpfc_idiag_extacc_drivr_get - get driver extent information
  2856. * @phba: pointer to lpfc hba data structure.
  2857. * @pbuffer: pointer to internal buffer.
  2858. * @len: length into the internal buffer data has been copied.
  2859. *
  2860. * Description:
  2861. * This routine is to get the driver extent information.
  2862. *
  2863. * Returns:
  2864. * overall lenth of the data read into the internal buffer.
  2865. **/
  2866. static int
  2867. lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
  2868. {
  2869. struct lpfc_rsrc_blks *rsrc_blks;
  2870. int index;
  2871. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2872. "\nDriver Extents Information:\n");
  2873. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2874. "\tVPI extents:\n");
  2875. index = 0;
  2876. list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
  2877. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2878. "\t\tBlock %3d: Start %4d, Count %4d\n",
  2879. index, rsrc_blks->rsrc_start,
  2880. rsrc_blks->rsrc_size);
  2881. index++;
  2882. }
  2883. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2884. "\tVFI extents:\n");
  2885. index = 0;
  2886. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
  2887. list) {
  2888. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2889. "\t\tBlock %3d: Start %4d, Count %4d\n",
  2890. index, rsrc_blks->rsrc_start,
  2891. rsrc_blks->rsrc_size);
  2892. index++;
  2893. }
  2894. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2895. "\tRPI extents:\n");
  2896. index = 0;
  2897. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
  2898. list) {
  2899. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2900. "\t\tBlock %3d: Start %4d, Count %4d\n",
  2901. index, rsrc_blks->rsrc_start,
  2902. rsrc_blks->rsrc_size);
  2903. index++;
  2904. }
  2905. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2906. "\tXRI extents:\n");
  2907. index = 0;
  2908. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
  2909. list) {
  2910. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2911. "\t\tBlock %3d: Start %4d, Count %4d\n",
  2912. index, rsrc_blks->rsrc_start,
  2913. rsrc_blks->rsrc_size);
  2914. index++;
  2915. }
  2916. return len;
  2917. }
  2918. /**
  2919. * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
  2920. * @file: The file pointer to read from.
  2921. * @buf: The buffer to copy the user data from.
  2922. * @nbytes: The number of bytes to get.
  2923. * @ppos: The position in the file to start reading from.
  2924. *
  2925. * This routine get the debugfs idiag command struct from user space and then
  2926. * perform the syntax check for extent information access commands and sets
  2927. * up the necessary states in the idiag command struct accordingly.
  2928. *
  2929. * It returns the @nbytges passing in from debugfs user space when successful.
  2930. * In case of error conditions, it returns proper error code back to the user
  2931. * space.
  2932. **/
  2933. static ssize_t
  2934. lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
  2935. size_t nbytes, loff_t *ppos)
  2936. {
  2937. struct lpfc_debug *debug = file->private_data;
  2938. uint32_t ext_map;
  2939. int rc;
  2940. /* This is a user write operation */
  2941. debug->op = LPFC_IDIAG_OP_WR;
  2942. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2943. if (rc < 0)
  2944. return rc;
  2945. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  2946. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  2947. goto error_out;
  2948. if (rc != LPFC_EXT_ACC_CMD_ARG)
  2949. goto error_out;
  2950. if (!(ext_map & LPFC_EXT_ACC_ALL))
  2951. goto error_out;
  2952. return nbytes;
  2953. error_out:
  2954. /* Clean out command structure on command error out */
  2955. memset(&idiag, 0, sizeof(idiag));
  2956. return -EINVAL;
  2957. }
  2958. /**
  2959. * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
  2960. * @file: The file pointer to read from.
  2961. * @buf: The buffer to copy the data to.
  2962. * @nbytes: The number of bytes to read.
  2963. * @ppos: The position in the file to start reading from.
  2964. *
  2965. * Description:
  2966. * This routine reads data from the proper extent information according to
  2967. * the idiag command, and copies to user @buf.
  2968. *
  2969. * Returns:
  2970. * This function returns the amount of data that was read (this could be less
  2971. * than @nbytes if the end of the file was reached) or a negative error value.
  2972. **/
  2973. static ssize_t
  2974. lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
  2975. loff_t *ppos)
  2976. {
  2977. struct lpfc_debug *debug = file->private_data;
  2978. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2979. char *pbuffer;
  2980. uint32_t ext_map;
  2981. int len = 0;
  2982. /* This is a user read operation */
  2983. debug->op = LPFC_IDIAG_OP_RD;
  2984. if (!debug->buffer)
  2985. debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
  2986. if (!debug->buffer)
  2987. return 0;
  2988. pbuffer = debug->buffer;
  2989. if (*ppos)
  2990. return 0;
  2991. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  2992. return 0;
  2993. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  2994. if (ext_map & LPFC_EXT_ACC_AVAIL)
  2995. len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
  2996. if (ext_map & LPFC_EXT_ACC_ALLOC)
  2997. len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
  2998. if (ext_map & LPFC_EXT_ACC_DRIVR)
  2999. len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
  3000. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3001. }
  3002. #undef lpfc_debugfs_op_disc_trc
  3003. static const struct file_operations lpfc_debugfs_op_disc_trc = {
  3004. .owner = THIS_MODULE,
  3005. .open = lpfc_debugfs_disc_trc_open,
  3006. .llseek = lpfc_debugfs_lseek,
  3007. .read = lpfc_debugfs_read,
  3008. .release = lpfc_debugfs_release,
  3009. };
  3010. #undef lpfc_debugfs_op_nodelist
  3011. static const struct file_operations lpfc_debugfs_op_nodelist = {
  3012. .owner = THIS_MODULE,
  3013. .open = lpfc_debugfs_nodelist_open,
  3014. .llseek = lpfc_debugfs_lseek,
  3015. .read = lpfc_debugfs_read,
  3016. .release = lpfc_debugfs_release,
  3017. };
  3018. #undef lpfc_debugfs_op_hbqinfo
  3019. static const struct file_operations lpfc_debugfs_op_hbqinfo = {
  3020. .owner = THIS_MODULE,
  3021. .open = lpfc_debugfs_hbqinfo_open,
  3022. .llseek = lpfc_debugfs_lseek,
  3023. .read = lpfc_debugfs_read,
  3024. .release = lpfc_debugfs_release,
  3025. };
  3026. #undef lpfc_debugfs_op_dumpHBASlim
  3027. static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  3028. .owner = THIS_MODULE,
  3029. .open = lpfc_debugfs_dumpHBASlim_open,
  3030. .llseek = lpfc_debugfs_lseek,
  3031. .read = lpfc_debugfs_read,
  3032. .release = lpfc_debugfs_release,
  3033. };
  3034. #undef lpfc_debugfs_op_dumpHostSlim
  3035. static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  3036. .owner = THIS_MODULE,
  3037. .open = lpfc_debugfs_dumpHostSlim_open,
  3038. .llseek = lpfc_debugfs_lseek,
  3039. .read = lpfc_debugfs_read,
  3040. .release = lpfc_debugfs_release,
  3041. };
  3042. #undef lpfc_debugfs_op_dumpData
  3043. static const struct file_operations lpfc_debugfs_op_dumpData = {
  3044. .owner = THIS_MODULE,
  3045. .open = lpfc_debugfs_dumpData_open,
  3046. .llseek = lpfc_debugfs_lseek,
  3047. .read = lpfc_debugfs_read,
  3048. .write = lpfc_debugfs_dumpDataDif_write,
  3049. .release = lpfc_debugfs_dumpDataDif_release,
  3050. };
  3051. #undef lpfc_debugfs_op_dumpDif
  3052. static const struct file_operations lpfc_debugfs_op_dumpDif = {
  3053. .owner = THIS_MODULE,
  3054. .open = lpfc_debugfs_dumpDif_open,
  3055. .llseek = lpfc_debugfs_lseek,
  3056. .read = lpfc_debugfs_read,
  3057. .write = lpfc_debugfs_dumpDataDif_write,
  3058. .release = lpfc_debugfs_dumpDataDif_release,
  3059. };
  3060. #undef lpfc_debugfs_op_slow_ring_trc
  3061. static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  3062. .owner = THIS_MODULE,
  3063. .open = lpfc_debugfs_slow_ring_trc_open,
  3064. .llseek = lpfc_debugfs_lseek,
  3065. .read = lpfc_debugfs_read,
  3066. .release = lpfc_debugfs_release,
  3067. };
  3068. static struct dentry *lpfc_debugfs_root = NULL;
  3069. static atomic_t lpfc_debugfs_hba_count;
  3070. /*
  3071. * File operations for the iDiag debugfs
  3072. */
  3073. #undef lpfc_idiag_op_pciCfg
  3074. static const struct file_operations lpfc_idiag_op_pciCfg = {
  3075. .owner = THIS_MODULE,
  3076. .open = lpfc_idiag_open,
  3077. .llseek = lpfc_debugfs_lseek,
  3078. .read = lpfc_idiag_pcicfg_read,
  3079. .write = lpfc_idiag_pcicfg_write,
  3080. .release = lpfc_idiag_cmd_release,
  3081. };
  3082. #undef lpfc_idiag_op_barAcc
  3083. static const struct file_operations lpfc_idiag_op_barAcc = {
  3084. .owner = THIS_MODULE,
  3085. .open = lpfc_idiag_open,
  3086. .llseek = lpfc_debugfs_lseek,
  3087. .read = lpfc_idiag_baracc_read,
  3088. .write = lpfc_idiag_baracc_write,
  3089. .release = lpfc_idiag_cmd_release,
  3090. };
  3091. #undef lpfc_idiag_op_queInfo
  3092. static const struct file_operations lpfc_idiag_op_queInfo = {
  3093. .owner = THIS_MODULE,
  3094. .open = lpfc_idiag_open,
  3095. .read = lpfc_idiag_queinfo_read,
  3096. .release = lpfc_idiag_release,
  3097. };
  3098. #undef lpfc_idiag_op_queAcc
  3099. static const struct file_operations lpfc_idiag_op_queAcc = {
  3100. .owner = THIS_MODULE,
  3101. .open = lpfc_idiag_open,
  3102. .llseek = lpfc_debugfs_lseek,
  3103. .read = lpfc_idiag_queacc_read,
  3104. .write = lpfc_idiag_queacc_write,
  3105. .release = lpfc_idiag_cmd_release,
  3106. };
  3107. #undef lpfc_idiag_op_drbAcc
  3108. static const struct file_operations lpfc_idiag_op_drbAcc = {
  3109. .owner = THIS_MODULE,
  3110. .open = lpfc_idiag_open,
  3111. .llseek = lpfc_debugfs_lseek,
  3112. .read = lpfc_idiag_drbacc_read,
  3113. .write = lpfc_idiag_drbacc_write,
  3114. .release = lpfc_idiag_cmd_release,
  3115. };
  3116. #undef lpfc_idiag_op_ctlAcc
  3117. static const struct file_operations lpfc_idiag_op_ctlAcc = {
  3118. .owner = THIS_MODULE,
  3119. .open = lpfc_idiag_open,
  3120. .llseek = lpfc_debugfs_lseek,
  3121. .read = lpfc_idiag_ctlacc_read,
  3122. .write = lpfc_idiag_ctlacc_write,
  3123. .release = lpfc_idiag_cmd_release,
  3124. };
  3125. #undef lpfc_idiag_op_mbxAcc
  3126. static const struct file_operations lpfc_idiag_op_mbxAcc = {
  3127. .owner = THIS_MODULE,
  3128. .open = lpfc_idiag_open,
  3129. .llseek = lpfc_debugfs_lseek,
  3130. .read = lpfc_idiag_mbxacc_read,
  3131. .write = lpfc_idiag_mbxacc_write,
  3132. .release = lpfc_idiag_cmd_release,
  3133. };
  3134. #undef lpfc_idiag_op_extAcc
  3135. static const struct file_operations lpfc_idiag_op_extAcc = {
  3136. .owner = THIS_MODULE,
  3137. .open = lpfc_idiag_open,
  3138. .llseek = lpfc_debugfs_lseek,
  3139. .read = lpfc_idiag_extacc_read,
  3140. .write = lpfc_idiag_extacc_write,
  3141. .release = lpfc_idiag_cmd_release,
  3142. };
  3143. #endif
  3144. /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
  3145. * @phba: Pointer to HBA context object.
  3146. * @dmabuf: Pointer to a DMA buffer descriptor.
  3147. *
  3148. * Description:
  3149. * This routine dump a bsg pass-through non-embedded mailbox command with
  3150. * external buffer.
  3151. **/
  3152. void
  3153. lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
  3154. enum mbox_type mbox_tp, enum dma_type dma_tp,
  3155. enum sta_type sta_tp,
  3156. struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
  3157. {
  3158. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3159. uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
  3160. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  3161. int len = 0;
  3162. uint32_t do_dump = 0;
  3163. uint32_t *pword;
  3164. uint32_t i;
  3165. if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
  3166. return;
  3167. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  3168. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  3169. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  3170. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  3171. if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
  3172. (*mbx_dump_cnt == 0) ||
  3173. (*mbx_word_cnt == 0))
  3174. return;
  3175. if (*mbx_mbox_cmd != 0x9B)
  3176. return;
  3177. if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
  3178. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
  3179. do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
  3180. printk(KERN_ERR "\nRead mbox command (x%x), "
  3181. "nemb:0x%x, extbuf_cnt:%d:\n",
  3182. sta_tp, nemb_tp, ext_buf);
  3183. }
  3184. }
  3185. if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
  3186. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
  3187. do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
  3188. printk(KERN_ERR "\nRead mbox buffer (x%x), "
  3189. "nemb:0x%x, extbuf_seq:%d:\n",
  3190. sta_tp, nemb_tp, ext_buf);
  3191. }
  3192. }
  3193. if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
  3194. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
  3195. do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
  3196. printk(KERN_ERR "\nWrite mbox command (x%x), "
  3197. "nemb:0x%x, extbuf_cnt:%d:\n",
  3198. sta_tp, nemb_tp, ext_buf);
  3199. }
  3200. }
  3201. if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
  3202. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
  3203. do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
  3204. printk(KERN_ERR "\nWrite mbox buffer (x%x), "
  3205. "nemb:0x%x, extbuf_seq:%d:\n",
  3206. sta_tp, nemb_tp, ext_buf);
  3207. }
  3208. }
  3209. /* dump buffer content */
  3210. if (do_dump) {
  3211. pword = (uint32_t *)dmabuf->virt;
  3212. for (i = 0; i < *mbx_word_cnt; i++) {
  3213. if (!(i % 8)) {
  3214. if (i != 0)
  3215. printk(KERN_ERR "%s\n", line_buf);
  3216. len = 0;
  3217. len += snprintf(line_buf+len,
  3218. LPFC_MBX_ACC_LBUF_SZ-len,
  3219. "%03d: ", i);
  3220. }
  3221. len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  3222. "%08x ", (uint32_t)*pword);
  3223. pword++;
  3224. }
  3225. if ((i - 1) % 8)
  3226. printk(KERN_ERR "%s\n", line_buf);
  3227. (*mbx_dump_cnt)--;
  3228. }
  3229. /* Clean out command structure on reaching dump count */
  3230. if (*mbx_dump_cnt == 0)
  3231. memset(&idiag, 0, sizeof(idiag));
  3232. return;
  3233. #endif
  3234. }
  3235. /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
  3236. * @phba: Pointer to HBA context object.
  3237. * @dmabuf: Pointer to a DMA buffer descriptor.
  3238. *
  3239. * Description:
  3240. * This routine dump a pass-through non-embedded mailbox command from issue
  3241. * mailbox command.
  3242. **/
  3243. void
  3244. lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
  3245. {
  3246. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3247. uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
  3248. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  3249. int len = 0;
  3250. uint32_t *pword;
  3251. uint8_t *pbyte;
  3252. uint32_t i, j;
  3253. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
  3254. return;
  3255. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  3256. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  3257. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  3258. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  3259. if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
  3260. (*mbx_dump_cnt == 0) ||
  3261. (*mbx_word_cnt == 0))
  3262. return;
  3263. if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
  3264. (*mbx_mbox_cmd != pmbox->mbxCommand))
  3265. return;
  3266. /* dump buffer content */
  3267. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
  3268. printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
  3269. pmbox->mbxCommand);
  3270. pword = (uint32_t *)pmbox;
  3271. for (i = 0; i < *mbx_word_cnt; i++) {
  3272. if (!(i % 8)) {
  3273. if (i != 0)
  3274. printk(KERN_ERR "%s\n", line_buf);
  3275. len = 0;
  3276. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  3277. len += snprintf(line_buf+len,
  3278. LPFC_MBX_ACC_LBUF_SZ-len,
  3279. "%03d: ", i);
  3280. }
  3281. len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  3282. "%08x ",
  3283. ((uint32_t)*pword) & 0xffffffff);
  3284. pword++;
  3285. }
  3286. if ((i - 1) % 8)
  3287. printk(KERN_ERR "%s\n", line_buf);
  3288. printk(KERN_ERR "\n");
  3289. }
  3290. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
  3291. printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
  3292. pmbox->mbxCommand);
  3293. pbyte = (uint8_t *)pmbox;
  3294. for (i = 0; i < *mbx_word_cnt; i++) {
  3295. if (!(i % 8)) {
  3296. if (i != 0)
  3297. printk(KERN_ERR "%s\n", line_buf);
  3298. len = 0;
  3299. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  3300. len += snprintf(line_buf+len,
  3301. LPFC_MBX_ACC_LBUF_SZ-len,
  3302. "%03d: ", i);
  3303. }
  3304. for (j = 0; j < 4; j++) {
  3305. len += snprintf(line_buf+len,
  3306. LPFC_MBX_ACC_LBUF_SZ-len,
  3307. "%02x",
  3308. ((uint8_t)*pbyte) & 0xff);
  3309. pbyte++;
  3310. }
  3311. len += snprintf(line_buf+len,
  3312. LPFC_MBX_ACC_LBUF_SZ-len, " ");
  3313. }
  3314. if ((i - 1) % 8)
  3315. printk(KERN_ERR "%s\n", line_buf);
  3316. printk(KERN_ERR "\n");
  3317. }
  3318. (*mbx_dump_cnt)--;
  3319. /* Clean out command structure on reaching dump count */
  3320. if (*mbx_dump_cnt == 0)
  3321. memset(&idiag, 0, sizeof(idiag));
  3322. return;
  3323. #endif
  3324. }
  3325. /**
  3326. * lpfc_debugfs_initialize - Initialize debugfs for a vport
  3327. * @vport: The vport pointer to initialize.
  3328. *
  3329. * Description:
  3330. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  3331. * If not already created, this routine will create the lpfc directory, and
  3332. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  3333. * also create each file used to access lpfc specific debugfs information.
  3334. **/
  3335. inline void
  3336. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  3337. {
  3338. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3339. struct lpfc_hba *phba = vport->phba;
  3340. char name[64];
  3341. uint32_t num, i;
  3342. if (!lpfc_debugfs_enable)
  3343. return;
  3344. /* Setup lpfc root directory */
  3345. if (!lpfc_debugfs_root) {
  3346. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  3347. atomic_set(&lpfc_debugfs_hba_count, 0);
  3348. if (!lpfc_debugfs_root) {
  3349. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3350. "0408 Cannot create debugfs root\n");
  3351. goto debug_failed;
  3352. }
  3353. }
  3354. if (!lpfc_debugfs_start_time)
  3355. lpfc_debugfs_start_time = jiffies;
  3356. /* Setup funcX directory for specific HBA PCI function */
  3357. snprintf(name, sizeof(name), "fn%d", phba->brd_no);
  3358. if (!phba->hba_debugfs_root) {
  3359. phba->hba_debugfs_root =
  3360. debugfs_create_dir(name, lpfc_debugfs_root);
  3361. if (!phba->hba_debugfs_root) {
  3362. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3363. "0412 Cannot create debugfs hba\n");
  3364. goto debug_failed;
  3365. }
  3366. atomic_inc(&lpfc_debugfs_hba_count);
  3367. atomic_set(&phba->debugfs_vport_count, 0);
  3368. /* Setup hbqinfo */
  3369. snprintf(name, sizeof(name), "hbqinfo");
  3370. phba->debug_hbqinfo =
  3371. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3372. phba->hba_debugfs_root,
  3373. phba, &lpfc_debugfs_op_hbqinfo);
  3374. if (!phba->debug_hbqinfo) {
  3375. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3376. "0411 Cannot create debugfs hbqinfo\n");
  3377. goto debug_failed;
  3378. }
  3379. /* Setup dumpHBASlim */
  3380. if (phba->sli_rev < LPFC_SLI_REV4) {
  3381. snprintf(name, sizeof(name), "dumpHBASlim");
  3382. phba->debug_dumpHBASlim =
  3383. debugfs_create_file(name,
  3384. S_IFREG|S_IRUGO|S_IWUSR,
  3385. phba->hba_debugfs_root,
  3386. phba, &lpfc_debugfs_op_dumpHBASlim);
  3387. if (!phba->debug_dumpHBASlim) {
  3388. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3389. "0413 Cannot create debugfs "
  3390. "dumpHBASlim\n");
  3391. goto debug_failed;
  3392. }
  3393. } else
  3394. phba->debug_dumpHBASlim = NULL;
  3395. /* Setup dumpHostSlim */
  3396. if (phba->sli_rev < LPFC_SLI_REV4) {
  3397. snprintf(name, sizeof(name), "dumpHostSlim");
  3398. phba->debug_dumpHostSlim =
  3399. debugfs_create_file(name,
  3400. S_IFREG|S_IRUGO|S_IWUSR,
  3401. phba->hba_debugfs_root,
  3402. phba, &lpfc_debugfs_op_dumpHostSlim);
  3403. if (!phba->debug_dumpHostSlim) {
  3404. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3405. "0414 Cannot create debugfs "
  3406. "dumpHostSlim\n");
  3407. goto debug_failed;
  3408. }
  3409. } else
  3410. phba->debug_dumpHBASlim = NULL;
  3411. /* Setup dumpData */
  3412. snprintf(name, sizeof(name), "dumpData");
  3413. phba->debug_dumpData =
  3414. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3415. phba->hba_debugfs_root,
  3416. phba, &lpfc_debugfs_op_dumpData);
  3417. if (!phba->debug_dumpData) {
  3418. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3419. "0800 Cannot create debugfs dumpData\n");
  3420. goto debug_failed;
  3421. }
  3422. /* Setup dumpDif */
  3423. snprintf(name, sizeof(name), "dumpDif");
  3424. phba->debug_dumpDif =
  3425. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3426. phba->hba_debugfs_root,
  3427. phba, &lpfc_debugfs_op_dumpDif);
  3428. if (!phba->debug_dumpDif) {
  3429. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3430. "0801 Cannot create debugfs dumpDif\n");
  3431. goto debug_failed;
  3432. }
  3433. /* Setup slow ring trace */
  3434. if (lpfc_debugfs_max_slow_ring_trc) {
  3435. num = lpfc_debugfs_max_slow_ring_trc - 1;
  3436. if (num & lpfc_debugfs_max_slow_ring_trc) {
  3437. /* Change to be a power of 2 */
  3438. num = lpfc_debugfs_max_slow_ring_trc;
  3439. i = 0;
  3440. while (num > 1) {
  3441. num = num >> 1;
  3442. i++;
  3443. }
  3444. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  3445. printk(KERN_ERR
  3446. "lpfc_debugfs_max_disc_trc changed to "
  3447. "%d\n", lpfc_debugfs_max_disc_trc);
  3448. }
  3449. }
  3450. snprintf(name, sizeof(name), "slow_ring_trace");
  3451. phba->debug_slow_ring_trc =
  3452. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3453. phba->hba_debugfs_root,
  3454. phba, &lpfc_debugfs_op_slow_ring_trc);
  3455. if (!phba->debug_slow_ring_trc) {
  3456. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3457. "0415 Cannot create debugfs "
  3458. "slow_ring_trace\n");
  3459. goto debug_failed;
  3460. }
  3461. if (!phba->slow_ring_trc) {
  3462. phba->slow_ring_trc = kmalloc(
  3463. (sizeof(struct lpfc_debugfs_trc) *
  3464. lpfc_debugfs_max_slow_ring_trc),
  3465. GFP_KERNEL);
  3466. if (!phba->slow_ring_trc) {
  3467. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3468. "0416 Cannot create debugfs "
  3469. "slow_ring buffer\n");
  3470. goto debug_failed;
  3471. }
  3472. atomic_set(&phba->slow_ring_trc_cnt, 0);
  3473. memset(phba->slow_ring_trc, 0,
  3474. (sizeof(struct lpfc_debugfs_trc) *
  3475. lpfc_debugfs_max_slow_ring_trc));
  3476. }
  3477. }
  3478. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  3479. if (!vport->vport_debugfs_root) {
  3480. vport->vport_debugfs_root =
  3481. debugfs_create_dir(name, phba->hba_debugfs_root);
  3482. if (!vport->vport_debugfs_root) {
  3483. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3484. "0417 Can't create debugfs\n");
  3485. goto debug_failed;
  3486. }
  3487. atomic_inc(&phba->debugfs_vport_count);
  3488. }
  3489. if (lpfc_debugfs_max_disc_trc) {
  3490. num = lpfc_debugfs_max_disc_trc - 1;
  3491. if (num & lpfc_debugfs_max_disc_trc) {
  3492. /* Change to be a power of 2 */
  3493. num = lpfc_debugfs_max_disc_trc;
  3494. i = 0;
  3495. while (num > 1) {
  3496. num = num >> 1;
  3497. i++;
  3498. }
  3499. lpfc_debugfs_max_disc_trc = (1 << i);
  3500. printk(KERN_ERR
  3501. "lpfc_debugfs_max_disc_trc changed to %d\n",
  3502. lpfc_debugfs_max_disc_trc);
  3503. }
  3504. }
  3505. vport->disc_trc = kzalloc(
  3506. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  3507. GFP_KERNEL);
  3508. if (!vport->disc_trc) {
  3509. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3510. "0418 Cannot create debugfs disc trace "
  3511. "buffer\n");
  3512. goto debug_failed;
  3513. }
  3514. atomic_set(&vport->disc_trc_cnt, 0);
  3515. snprintf(name, sizeof(name), "discovery_trace");
  3516. vport->debug_disc_trc =
  3517. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3518. vport->vport_debugfs_root,
  3519. vport, &lpfc_debugfs_op_disc_trc);
  3520. if (!vport->debug_disc_trc) {
  3521. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3522. "0419 Cannot create debugfs "
  3523. "discovery_trace\n");
  3524. goto debug_failed;
  3525. }
  3526. snprintf(name, sizeof(name), "nodelist");
  3527. vport->debug_nodelist =
  3528. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3529. vport->vport_debugfs_root,
  3530. vport, &lpfc_debugfs_op_nodelist);
  3531. if (!vport->debug_nodelist) {
  3532. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3533. "2985 Can't create debugfs nodelist\n");
  3534. goto debug_failed;
  3535. }
  3536. /*
  3537. * iDiag debugfs root entry points for SLI4 device only
  3538. */
  3539. if (phba->sli_rev < LPFC_SLI_REV4)
  3540. goto debug_failed;
  3541. snprintf(name, sizeof(name), "iDiag");
  3542. if (!phba->idiag_root) {
  3543. phba->idiag_root =
  3544. debugfs_create_dir(name, phba->hba_debugfs_root);
  3545. if (!phba->idiag_root) {
  3546. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3547. "2922 Can't create idiag debugfs\n");
  3548. goto debug_failed;
  3549. }
  3550. /* Initialize iDiag data structure */
  3551. memset(&idiag, 0, sizeof(idiag));
  3552. }
  3553. /* iDiag read PCI config space */
  3554. snprintf(name, sizeof(name), "pciCfg");
  3555. if (!phba->idiag_pci_cfg) {
  3556. phba->idiag_pci_cfg =
  3557. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3558. phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
  3559. if (!phba->idiag_pci_cfg) {
  3560. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3561. "2923 Can't create idiag debugfs\n");
  3562. goto debug_failed;
  3563. }
  3564. idiag.offset.last_rd = 0;
  3565. }
  3566. /* iDiag PCI BAR access */
  3567. snprintf(name, sizeof(name), "barAcc");
  3568. if (!phba->idiag_bar_acc) {
  3569. phba->idiag_bar_acc =
  3570. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3571. phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
  3572. if (!phba->idiag_bar_acc) {
  3573. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3574. "3056 Can't create idiag debugfs\n");
  3575. goto debug_failed;
  3576. }
  3577. idiag.offset.last_rd = 0;
  3578. }
  3579. /* iDiag get PCI function queue information */
  3580. snprintf(name, sizeof(name), "queInfo");
  3581. if (!phba->idiag_que_info) {
  3582. phba->idiag_que_info =
  3583. debugfs_create_file(name, S_IFREG|S_IRUGO,
  3584. phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
  3585. if (!phba->idiag_que_info) {
  3586. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3587. "2924 Can't create idiag debugfs\n");
  3588. goto debug_failed;
  3589. }
  3590. }
  3591. /* iDiag access PCI function queue */
  3592. snprintf(name, sizeof(name), "queAcc");
  3593. if (!phba->idiag_que_acc) {
  3594. phba->idiag_que_acc =
  3595. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3596. phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
  3597. if (!phba->idiag_que_acc) {
  3598. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3599. "2926 Can't create idiag debugfs\n");
  3600. goto debug_failed;
  3601. }
  3602. }
  3603. /* iDiag access PCI function doorbell registers */
  3604. snprintf(name, sizeof(name), "drbAcc");
  3605. if (!phba->idiag_drb_acc) {
  3606. phba->idiag_drb_acc =
  3607. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3608. phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
  3609. if (!phba->idiag_drb_acc) {
  3610. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3611. "2927 Can't create idiag debugfs\n");
  3612. goto debug_failed;
  3613. }
  3614. }
  3615. /* iDiag access PCI function control registers */
  3616. snprintf(name, sizeof(name), "ctlAcc");
  3617. if (!phba->idiag_ctl_acc) {
  3618. phba->idiag_ctl_acc =
  3619. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3620. phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
  3621. if (!phba->idiag_ctl_acc) {
  3622. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3623. "2981 Can't create idiag debugfs\n");
  3624. goto debug_failed;
  3625. }
  3626. }
  3627. /* iDiag access mbox commands */
  3628. snprintf(name, sizeof(name), "mbxAcc");
  3629. if (!phba->idiag_mbx_acc) {
  3630. phba->idiag_mbx_acc =
  3631. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3632. phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
  3633. if (!phba->idiag_mbx_acc) {
  3634. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3635. "2980 Can't create idiag debugfs\n");
  3636. goto debug_failed;
  3637. }
  3638. }
  3639. /* iDiag extents access commands */
  3640. if (phba->sli4_hba.extents_in_use) {
  3641. snprintf(name, sizeof(name), "extAcc");
  3642. if (!phba->idiag_ext_acc) {
  3643. phba->idiag_ext_acc =
  3644. debugfs_create_file(name,
  3645. S_IFREG|S_IRUGO|S_IWUSR,
  3646. phba->idiag_root, phba,
  3647. &lpfc_idiag_op_extAcc);
  3648. if (!phba->idiag_ext_acc) {
  3649. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3650. "2986 Cant create "
  3651. "idiag debugfs\n");
  3652. goto debug_failed;
  3653. }
  3654. }
  3655. }
  3656. debug_failed:
  3657. return;
  3658. #endif
  3659. }
  3660. /**
  3661. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
  3662. * @vport: The vport pointer to remove from debugfs.
  3663. *
  3664. * Description:
  3665. * When Debugfs is configured this routine removes debugfs file system elements
  3666. * that are specific to this vport. It also checks to see if there are any
  3667. * users left for the debugfs directories associated with the HBA and driver. If
  3668. * this is the last user of the HBA directory or driver directory then it will
  3669. * remove those from the debugfs infrastructure as well.
  3670. **/
  3671. inline void
  3672. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  3673. {
  3674. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3675. struct lpfc_hba *phba = vport->phba;
  3676. if (vport->disc_trc) {
  3677. kfree(vport->disc_trc);
  3678. vport->disc_trc = NULL;
  3679. }
  3680. if (vport->debug_disc_trc) {
  3681. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  3682. vport->debug_disc_trc = NULL;
  3683. }
  3684. if (vport->debug_nodelist) {
  3685. debugfs_remove(vport->debug_nodelist); /* nodelist */
  3686. vport->debug_nodelist = NULL;
  3687. }
  3688. if (vport->vport_debugfs_root) {
  3689. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  3690. vport->vport_debugfs_root = NULL;
  3691. atomic_dec(&phba->debugfs_vport_count);
  3692. }
  3693. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  3694. if (phba->debug_hbqinfo) {
  3695. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  3696. phba->debug_hbqinfo = NULL;
  3697. }
  3698. if (phba->debug_dumpHBASlim) {
  3699. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  3700. phba->debug_dumpHBASlim = NULL;
  3701. }
  3702. if (phba->debug_dumpHostSlim) {
  3703. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  3704. phba->debug_dumpHostSlim = NULL;
  3705. }
  3706. if (phba->debug_dumpData) {
  3707. debugfs_remove(phba->debug_dumpData); /* dumpData */
  3708. phba->debug_dumpData = NULL;
  3709. }
  3710. if (phba->debug_dumpDif) {
  3711. debugfs_remove(phba->debug_dumpDif); /* dumpDif */
  3712. phba->debug_dumpDif = NULL;
  3713. }
  3714. if (phba->slow_ring_trc) {
  3715. kfree(phba->slow_ring_trc);
  3716. phba->slow_ring_trc = NULL;
  3717. }
  3718. if (phba->debug_slow_ring_trc) {
  3719. /* slow_ring_trace */
  3720. debugfs_remove(phba->debug_slow_ring_trc);
  3721. phba->debug_slow_ring_trc = NULL;
  3722. }
  3723. /*
  3724. * iDiag release
  3725. */
  3726. if (phba->sli_rev == LPFC_SLI_REV4) {
  3727. if (phba->idiag_ext_acc) {
  3728. /* iDiag extAcc */
  3729. debugfs_remove(phba->idiag_ext_acc);
  3730. phba->idiag_ext_acc = NULL;
  3731. }
  3732. if (phba->idiag_mbx_acc) {
  3733. /* iDiag mbxAcc */
  3734. debugfs_remove(phba->idiag_mbx_acc);
  3735. phba->idiag_mbx_acc = NULL;
  3736. }
  3737. if (phba->idiag_ctl_acc) {
  3738. /* iDiag ctlAcc */
  3739. debugfs_remove(phba->idiag_ctl_acc);
  3740. phba->idiag_ctl_acc = NULL;
  3741. }
  3742. if (phba->idiag_drb_acc) {
  3743. /* iDiag drbAcc */
  3744. debugfs_remove(phba->idiag_drb_acc);
  3745. phba->idiag_drb_acc = NULL;
  3746. }
  3747. if (phba->idiag_que_acc) {
  3748. /* iDiag queAcc */
  3749. debugfs_remove(phba->idiag_que_acc);
  3750. phba->idiag_que_acc = NULL;
  3751. }
  3752. if (phba->idiag_que_info) {
  3753. /* iDiag queInfo */
  3754. debugfs_remove(phba->idiag_que_info);
  3755. phba->idiag_que_info = NULL;
  3756. }
  3757. if (phba->idiag_bar_acc) {
  3758. /* iDiag barAcc */
  3759. debugfs_remove(phba->idiag_bar_acc);
  3760. phba->idiag_bar_acc = NULL;
  3761. }
  3762. if (phba->idiag_pci_cfg) {
  3763. /* iDiag pciCfg */
  3764. debugfs_remove(phba->idiag_pci_cfg);
  3765. phba->idiag_pci_cfg = NULL;
  3766. }
  3767. /* Finally remove the iDiag debugfs root */
  3768. if (phba->idiag_root) {
  3769. /* iDiag root */
  3770. debugfs_remove(phba->idiag_root);
  3771. phba->idiag_root = NULL;
  3772. }
  3773. }
  3774. if (phba->hba_debugfs_root) {
  3775. debugfs_remove(phba->hba_debugfs_root); /* fnX */
  3776. phba->hba_debugfs_root = NULL;
  3777. atomic_dec(&lpfc_debugfs_hba_count);
  3778. }
  3779. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  3780. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  3781. lpfc_debugfs_root = NULL;
  3782. }
  3783. }
  3784. #endif
  3785. return;
  3786. }