lpfc_debugfs.c 132 KB

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