lpfc_debugfs.c 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604
  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;
  1047. loff_t pos = -1;
  1048. debug = file->private_data;
  1049. switch (whence) {
  1050. case 0:
  1051. pos = off;
  1052. break;
  1053. case 1:
  1054. pos = file->f_pos + off;
  1055. break;
  1056. case 2:
  1057. pos = debug->len - off;
  1058. }
  1059. return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
  1060. }
  1061. /**
  1062. * lpfc_debugfs_read - Read a debugfs file
  1063. * @file: The file pointer to read from.
  1064. * @buf: The buffer to copy the data to.
  1065. * @nbytes: The number of bytes to read.
  1066. * @ppos: The position in the file to start reading from.
  1067. *
  1068. * Description:
  1069. * This routine reads data from from the buffer indicated in the private_data
  1070. * field of @file. It will start reading at @ppos and copy up to @nbytes of
  1071. * data to @buf.
  1072. *
  1073. * Returns:
  1074. * This function returns the amount of data that was read (this could be less
  1075. * than @nbytes if the end of the file was reached) or a negative error value.
  1076. **/
  1077. static ssize_t
  1078. lpfc_debugfs_read(struct file *file, char __user *buf,
  1079. size_t nbytes, loff_t *ppos)
  1080. {
  1081. struct lpfc_debug *debug = file->private_data;
  1082. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  1083. debug->len);
  1084. }
  1085. /**
  1086. * lpfc_debugfs_release - Release the buffer used to store debugfs file data
  1087. * @inode: The inode pointer that contains a vport pointer. (unused)
  1088. * @file: The file pointer that contains the buffer to release.
  1089. *
  1090. * Description:
  1091. * This routine frees the buffer that was allocated when the debugfs file was
  1092. * opened.
  1093. *
  1094. * Returns:
  1095. * This function returns zero.
  1096. **/
  1097. static int
  1098. lpfc_debugfs_release(struct inode *inode, struct file *file)
  1099. {
  1100. struct lpfc_debug *debug = file->private_data;
  1101. kfree(debug->buffer);
  1102. kfree(debug);
  1103. return 0;
  1104. }
  1105. static int
  1106. lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
  1107. {
  1108. struct lpfc_debug *debug = file->private_data;
  1109. debug->buffer = NULL;
  1110. kfree(debug);
  1111. return 0;
  1112. }
  1113. /*
  1114. * ---------------------------------
  1115. * iDiag debugfs file access methods
  1116. * ---------------------------------
  1117. *
  1118. * All access methods are through the proper SLI4 PCI function's debugfs
  1119. * iDiag directory:
  1120. *
  1121. * /sys/kernel/debug/lpfc/fn<#>/iDiag
  1122. */
  1123. /**
  1124. * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
  1125. * @buf: The pointer to the user space buffer.
  1126. * @nbytes: The number of bytes in the user space buffer.
  1127. * @idiag_cmd: pointer to the idiag command struct.
  1128. *
  1129. * This routine reads data from debugfs user space buffer and parses the
  1130. * buffer for getting the idiag command and arguments. The while space in
  1131. * between the set of data is used as the parsing separator.
  1132. *
  1133. * This routine returns 0 when successful, it returns proper error code
  1134. * back to the user space in error conditions.
  1135. */
  1136. static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
  1137. struct lpfc_idiag_cmd *idiag_cmd)
  1138. {
  1139. char mybuf[64];
  1140. char *pbuf, *step_str;
  1141. int i;
  1142. size_t bsize;
  1143. /* Protect copy from user */
  1144. if (!access_ok(VERIFY_READ, buf, nbytes))
  1145. return -EFAULT;
  1146. memset(mybuf, 0, sizeof(mybuf));
  1147. memset(idiag_cmd, 0, sizeof(*idiag_cmd));
  1148. bsize = min(nbytes, (sizeof(mybuf)-1));
  1149. if (copy_from_user(mybuf, buf, bsize))
  1150. return -EFAULT;
  1151. pbuf = &mybuf[0];
  1152. step_str = strsep(&pbuf, "\t ");
  1153. /* The opcode must present */
  1154. if (!step_str)
  1155. return -EINVAL;
  1156. idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
  1157. if (idiag_cmd->opcode == 0)
  1158. return -EINVAL;
  1159. for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
  1160. step_str = strsep(&pbuf, "\t ");
  1161. if (!step_str)
  1162. return i;
  1163. idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
  1164. }
  1165. return i;
  1166. }
  1167. /**
  1168. * lpfc_idiag_open - idiag open debugfs
  1169. * @inode: The inode pointer that contains a pointer to phba.
  1170. * @file: The file pointer to attach the file operation.
  1171. *
  1172. * Description:
  1173. * This routine is the entry point for the debugfs open file operation. It
  1174. * gets the reference to phba from the i_private field in @inode, it then
  1175. * allocates buffer for the file operation, performs the necessary PCI config
  1176. * space read into the allocated buffer according to the idiag user command
  1177. * setup, and then returns a pointer to buffer in the private_data field in
  1178. * @file.
  1179. *
  1180. * Returns:
  1181. * This function returns zero if successful. On error it will return an
  1182. * negative error value.
  1183. **/
  1184. static int
  1185. lpfc_idiag_open(struct inode *inode, struct file *file)
  1186. {
  1187. struct lpfc_debug *debug;
  1188. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1189. if (!debug)
  1190. return -ENOMEM;
  1191. debug->i_private = inode->i_private;
  1192. debug->buffer = NULL;
  1193. file->private_data = debug;
  1194. return 0;
  1195. }
  1196. /**
  1197. * lpfc_idiag_release - Release idiag access file operation
  1198. * @inode: The inode pointer that contains a vport pointer. (unused)
  1199. * @file: The file pointer that contains the buffer to release.
  1200. *
  1201. * Description:
  1202. * This routine is the generic release routine for the idiag access file
  1203. * operation, it frees the buffer that was allocated when the debugfs file
  1204. * was opened.
  1205. *
  1206. * Returns:
  1207. * This function returns zero.
  1208. **/
  1209. static int
  1210. lpfc_idiag_release(struct inode *inode, struct file *file)
  1211. {
  1212. struct lpfc_debug *debug = file->private_data;
  1213. /* Free the buffers to the file operation */
  1214. kfree(debug->buffer);
  1215. kfree(debug);
  1216. return 0;
  1217. }
  1218. /**
  1219. * lpfc_idiag_cmd_release - Release idiag cmd access file operation
  1220. * @inode: The inode pointer that contains a vport pointer. (unused)
  1221. * @file: The file pointer that contains the buffer to release.
  1222. *
  1223. * Description:
  1224. * This routine frees the buffer that was allocated when the debugfs file
  1225. * was opened. It also reset the fields in the idiag command struct in the
  1226. * case of command for write operation.
  1227. *
  1228. * Returns:
  1229. * This function returns zero.
  1230. **/
  1231. static int
  1232. lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
  1233. {
  1234. struct lpfc_debug *debug = file->private_data;
  1235. if (debug->op == LPFC_IDIAG_OP_WR) {
  1236. switch (idiag.cmd.opcode) {
  1237. case LPFC_IDIAG_CMD_PCICFG_WR:
  1238. case LPFC_IDIAG_CMD_PCICFG_ST:
  1239. case LPFC_IDIAG_CMD_PCICFG_CL:
  1240. case LPFC_IDIAG_CMD_QUEACC_WR:
  1241. case LPFC_IDIAG_CMD_QUEACC_ST:
  1242. case LPFC_IDIAG_CMD_QUEACC_CL:
  1243. memset(&idiag, 0, sizeof(idiag));
  1244. break;
  1245. default:
  1246. break;
  1247. }
  1248. }
  1249. /* Free the buffers to the file operation */
  1250. kfree(debug->buffer);
  1251. kfree(debug);
  1252. return 0;
  1253. }
  1254. /**
  1255. * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
  1256. * @file: The file pointer to read from.
  1257. * @buf: The buffer to copy the data to.
  1258. * @nbytes: The number of bytes to read.
  1259. * @ppos: The position in the file to start reading from.
  1260. *
  1261. * Description:
  1262. * This routine reads data from the @phba pci config space according to the
  1263. * idiag command, and copies to user @buf. Depending on the PCI config space
  1264. * read command setup, it does either a single register read of a byte
  1265. * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
  1266. * registers from the 4K extended PCI config space.
  1267. *
  1268. * Returns:
  1269. * This function returns the amount of data that was read (this could be less
  1270. * than @nbytes if the end of the file was reached) or a negative error value.
  1271. **/
  1272. static ssize_t
  1273. lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
  1274. loff_t *ppos)
  1275. {
  1276. struct lpfc_debug *debug = file->private_data;
  1277. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1278. int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
  1279. int where, count;
  1280. char *pbuffer;
  1281. struct pci_dev *pdev;
  1282. uint32_t u32val;
  1283. uint16_t u16val;
  1284. uint8_t u8val;
  1285. pdev = phba->pcidev;
  1286. if (!pdev)
  1287. return 0;
  1288. /* This is a user read operation */
  1289. debug->op = LPFC_IDIAG_OP_RD;
  1290. if (!debug->buffer)
  1291. debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
  1292. if (!debug->buffer)
  1293. return 0;
  1294. pbuffer = debug->buffer;
  1295. if (*ppos)
  1296. return 0;
  1297. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1298. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  1299. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  1300. } else
  1301. return 0;
  1302. /* Read single PCI config space register */
  1303. switch (count) {
  1304. case SIZE_U8: /* byte (8 bits) */
  1305. pci_read_config_byte(pdev, where, &u8val);
  1306. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1307. "%03x: %02x\n", where, u8val);
  1308. break;
  1309. case SIZE_U16: /* word (16 bits) */
  1310. pci_read_config_word(pdev, where, &u16val);
  1311. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1312. "%03x: %04x\n", where, u16val);
  1313. break;
  1314. case SIZE_U32: /* double word (32 bits) */
  1315. pci_read_config_dword(pdev, where, &u32val);
  1316. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1317. "%03x: %08x\n", where, u32val);
  1318. break;
  1319. case LPFC_PCI_CFG_BROWSE: /* browse all */
  1320. goto pcicfg_browse;
  1321. break;
  1322. default:
  1323. /* illegal count */
  1324. len = 0;
  1325. break;
  1326. }
  1327. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1328. pcicfg_browse:
  1329. /* Browse all PCI config space registers */
  1330. offset_label = idiag.offset.last_rd;
  1331. offset = offset_label;
  1332. /* Read PCI config space */
  1333. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1334. "%03x: ", offset_label);
  1335. while (index > 0) {
  1336. pci_read_config_dword(pdev, offset, &u32val);
  1337. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1338. "%08x ", u32val);
  1339. offset += sizeof(uint32_t);
  1340. if (offset >= LPFC_PCI_CFG_SIZE) {
  1341. len += snprintf(pbuffer+len,
  1342. LPFC_PCI_CFG_SIZE-len, "\n");
  1343. break;
  1344. }
  1345. index -= sizeof(uint32_t);
  1346. if (!index)
  1347. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1348. "\n");
  1349. else if (!(index % (8 * sizeof(uint32_t)))) {
  1350. offset_label += (8 * sizeof(uint32_t));
  1351. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1352. "\n%03x: ", offset_label);
  1353. }
  1354. }
  1355. /* Set up the offset for next portion of pci cfg read */
  1356. if (index == 0) {
  1357. idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
  1358. if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
  1359. idiag.offset.last_rd = 0;
  1360. } else
  1361. idiag.offset.last_rd = 0;
  1362. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1363. }
  1364. /**
  1365. * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
  1366. * @file: The file pointer to read from.
  1367. * @buf: The buffer to copy the user data from.
  1368. * @nbytes: The number of bytes to get.
  1369. * @ppos: The position in the file to start reading from.
  1370. *
  1371. * This routine get the debugfs idiag command struct from user space and
  1372. * then perform the syntax check for PCI config space read or write command
  1373. * accordingly. In the case of PCI config space read command, it sets up
  1374. * the command in the idiag command struct for the debugfs read operation.
  1375. * In the case of PCI config space write operation, it executes the write
  1376. * operation into the PCI config space accordingly.
  1377. *
  1378. * It returns the @nbytges passing in from debugfs user space when successful.
  1379. * In case of error conditions, it returns proper error code back to the user
  1380. * space.
  1381. */
  1382. static ssize_t
  1383. lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
  1384. size_t nbytes, loff_t *ppos)
  1385. {
  1386. struct lpfc_debug *debug = file->private_data;
  1387. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1388. uint32_t where, value, count;
  1389. uint32_t u32val;
  1390. uint16_t u16val;
  1391. uint8_t u8val;
  1392. struct pci_dev *pdev;
  1393. int rc;
  1394. pdev = phba->pcidev;
  1395. if (!pdev)
  1396. return -EFAULT;
  1397. /* This is a user write operation */
  1398. debug->op = LPFC_IDIAG_OP_WR;
  1399. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  1400. if (rc < 0)
  1401. return rc;
  1402. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1403. /* Sanity check on PCI config read command line arguments */
  1404. if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
  1405. goto error_out;
  1406. /* Read command from PCI config space, set up command fields */
  1407. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  1408. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  1409. if (count == LPFC_PCI_CFG_BROWSE) {
  1410. if (where % sizeof(uint32_t))
  1411. goto error_out;
  1412. /* Starting offset to browse */
  1413. idiag.offset.last_rd = where;
  1414. } else if ((count != sizeof(uint8_t)) &&
  1415. (count != sizeof(uint16_t)) &&
  1416. (count != sizeof(uint32_t)))
  1417. goto error_out;
  1418. if (count == sizeof(uint8_t)) {
  1419. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1420. goto error_out;
  1421. if (where % sizeof(uint8_t))
  1422. goto error_out;
  1423. }
  1424. if (count == sizeof(uint16_t)) {
  1425. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1426. goto error_out;
  1427. if (where % sizeof(uint16_t))
  1428. goto error_out;
  1429. }
  1430. if (count == sizeof(uint32_t)) {
  1431. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1432. goto error_out;
  1433. if (where % sizeof(uint32_t))
  1434. goto error_out;
  1435. }
  1436. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
  1437. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
  1438. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1439. /* Sanity check on PCI config write command line arguments */
  1440. if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
  1441. goto error_out;
  1442. /* Write command to PCI config space, read-modify-write */
  1443. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  1444. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  1445. value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
  1446. /* Sanity checks */
  1447. if ((count != sizeof(uint8_t)) &&
  1448. (count != sizeof(uint16_t)) &&
  1449. (count != sizeof(uint32_t)))
  1450. goto error_out;
  1451. if (count == sizeof(uint8_t)) {
  1452. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1453. goto error_out;
  1454. if (where % sizeof(uint8_t))
  1455. goto error_out;
  1456. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1457. pci_write_config_byte(pdev, where,
  1458. (uint8_t)value);
  1459. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1460. rc = pci_read_config_byte(pdev, where, &u8val);
  1461. if (!rc) {
  1462. u8val |= (uint8_t)value;
  1463. pci_write_config_byte(pdev, where,
  1464. u8val);
  1465. }
  1466. }
  1467. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1468. rc = pci_read_config_byte(pdev, where, &u8val);
  1469. if (!rc) {
  1470. u8val &= (uint8_t)(~value);
  1471. pci_write_config_byte(pdev, where,
  1472. u8val);
  1473. }
  1474. }
  1475. }
  1476. if (count == sizeof(uint16_t)) {
  1477. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1478. goto error_out;
  1479. if (where % sizeof(uint16_t))
  1480. goto error_out;
  1481. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1482. pci_write_config_word(pdev, where,
  1483. (uint16_t)value);
  1484. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1485. rc = pci_read_config_word(pdev, where, &u16val);
  1486. if (!rc) {
  1487. u16val |= (uint16_t)value;
  1488. pci_write_config_word(pdev, where,
  1489. u16val);
  1490. }
  1491. }
  1492. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1493. rc = pci_read_config_word(pdev, where, &u16val);
  1494. if (!rc) {
  1495. u16val &= (uint16_t)(~value);
  1496. pci_write_config_word(pdev, where,
  1497. u16val);
  1498. }
  1499. }
  1500. }
  1501. if (count == sizeof(uint32_t)) {
  1502. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1503. goto error_out;
  1504. if (where % sizeof(uint32_t))
  1505. goto error_out;
  1506. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1507. pci_write_config_dword(pdev, where, value);
  1508. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1509. rc = pci_read_config_dword(pdev, where,
  1510. &u32val);
  1511. if (!rc) {
  1512. u32val |= value;
  1513. pci_write_config_dword(pdev, where,
  1514. u32val);
  1515. }
  1516. }
  1517. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1518. rc = pci_read_config_dword(pdev, where,
  1519. &u32val);
  1520. if (!rc) {
  1521. u32val &= ~value;
  1522. pci_write_config_dword(pdev, where,
  1523. u32val);
  1524. }
  1525. }
  1526. }
  1527. } else
  1528. /* All other opecodes are illegal for now */
  1529. goto error_out;
  1530. return nbytes;
  1531. error_out:
  1532. memset(&idiag, 0, sizeof(idiag));
  1533. return -EINVAL;
  1534. }
  1535. /**
  1536. * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
  1537. * @file: The file pointer to read from.
  1538. * @buf: The buffer to copy the data to.
  1539. * @nbytes: The number of bytes to read.
  1540. * @ppos: The position in the file to start reading from.
  1541. *
  1542. * Description:
  1543. * This routine reads data from the @phba pci bar memory mapped space
  1544. * according to the idiag command, and copies to user @buf.
  1545. *
  1546. * Returns:
  1547. * This function returns the amount of data that was read (this could be less
  1548. * than @nbytes if the end of the file was reached) or a negative error value.
  1549. **/
  1550. static ssize_t
  1551. lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
  1552. loff_t *ppos)
  1553. {
  1554. struct lpfc_debug *debug = file->private_data;
  1555. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1556. int offset_label, offset, offset_run, len = 0, index;
  1557. int bar_num, acc_range, bar_size;
  1558. char *pbuffer;
  1559. void __iomem *mem_mapped_bar;
  1560. uint32_t if_type;
  1561. struct pci_dev *pdev;
  1562. uint32_t u32val;
  1563. pdev = phba->pcidev;
  1564. if (!pdev)
  1565. return 0;
  1566. /* This is a user read operation */
  1567. debug->op = LPFC_IDIAG_OP_RD;
  1568. if (!debug->buffer)
  1569. debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
  1570. if (!debug->buffer)
  1571. return 0;
  1572. pbuffer = debug->buffer;
  1573. if (*ppos)
  1574. return 0;
  1575. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  1576. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  1577. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  1578. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  1579. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  1580. } else
  1581. return 0;
  1582. if (acc_range == 0)
  1583. return 0;
  1584. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  1585. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  1586. if (bar_num == IDIAG_BARACC_BAR_0)
  1587. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1588. else if (bar_num == IDIAG_BARACC_BAR_1)
  1589. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  1590. else if (bar_num == IDIAG_BARACC_BAR_2)
  1591. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  1592. else
  1593. return 0;
  1594. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  1595. if (bar_num == IDIAG_BARACC_BAR_0)
  1596. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1597. else
  1598. return 0;
  1599. } else
  1600. return 0;
  1601. /* Read single PCI bar space register */
  1602. if (acc_range == SINGLE_WORD) {
  1603. offset_run = offset;
  1604. u32val = readl(mem_mapped_bar + offset_run);
  1605. len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1606. "%05x: %08x\n", offset_run, u32val);
  1607. } else
  1608. goto baracc_browse;
  1609. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1610. baracc_browse:
  1611. /* Browse all PCI bar space registers */
  1612. offset_label = idiag.offset.last_rd;
  1613. offset_run = offset_label;
  1614. /* Read PCI bar memory mapped space */
  1615. len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1616. "%05x: ", offset_label);
  1617. index = LPFC_PCI_BAR_RD_SIZE;
  1618. while (index > 0) {
  1619. u32val = readl(mem_mapped_bar + offset_run);
  1620. len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1621. "%08x ", u32val);
  1622. offset_run += sizeof(uint32_t);
  1623. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  1624. if (offset_run >= bar_size) {
  1625. len += snprintf(pbuffer+len,
  1626. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  1627. break;
  1628. }
  1629. } else {
  1630. if (offset_run >= offset +
  1631. (acc_range * sizeof(uint32_t))) {
  1632. len += snprintf(pbuffer+len,
  1633. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  1634. break;
  1635. }
  1636. }
  1637. index -= sizeof(uint32_t);
  1638. if (!index)
  1639. len += snprintf(pbuffer+len,
  1640. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  1641. else if (!(index % (8 * sizeof(uint32_t)))) {
  1642. offset_label += (8 * sizeof(uint32_t));
  1643. len += snprintf(pbuffer+len,
  1644. LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1645. "\n%05x: ", offset_label);
  1646. }
  1647. }
  1648. /* Set up the offset for next portion of pci bar read */
  1649. if (index == 0) {
  1650. idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
  1651. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  1652. if (idiag.offset.last_rd >= bar_size)
  1653. idiag.offset.last_rd = 0;
  1654. } else {
  1655. if (offset_run >= offset +
  1656. (acc_range * sizeof(uint32_t)))
  1657. idiag.offset.last_rd = offset;
  1658. }
  1659. } else {
  1660. if (acc_range == LPFC_PCI_BAR_BROWSE)
  1661. idiag.offset.last_rd = 0;
  1662. else
  1663. idiag.offset.last_rd = offset;
  1664. }
  1665. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1666. }
  1667. /**
  1668. * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
  1669. * @file: The file pointer to read from.
  1670. * @buf: The buffer to copy the user data from.
  1671. * @nbytes: The number of bytes to get.
  1672. * @ppos: The position in the file to start reading from.
  1673. *
  1674. * This routine get the debugfs idiag command struct from user space and
  1675. * then perform the syntax check for PCI bar memory mapped space read or
  1676. * write command accordingly. In the case of PCI bar memory mapped space
  1677. * read command, it sets up the command in the idiag command struct for
  1678. * the debugfs read operation. In the case of PCI bar memorpy mapped space
  1679. * write operation, it executes the write operation into the PCI bar memory
  1680. * mapped space accordingly.
  1681. *
  1682. * It returns the @nbytges passing in from debugfs user space when successful.
  1683. * In case of error conditions, it returns proper error code back to the user
  1684. * space.
  1685. */
  1686. static ssize_t
  1687. lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
  1688. size_t nbytes, loff_t *ppos)
  1689. {
  1690. struct lpfc_debug *debug = file->private_data;
  1691. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1692. uint32_t bar_num, bar_size, offset, value, acc_range;
  1693. struct pci_dev *pdev;
  1694. void __iomem *mem_mapped_bar;
  1695. uint32_t if_type;
  1696. uint32_t u32val;
  1697. int rc;
  1698. pdev = phba->pcidev;
  1699. if (!pdev)
  1700. return -EFAULT;
  1701. /* This is a user write operation */
  1702. debug->op = LPFC_IDIAG_OP_WR;
  1703. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  1704. if (rc < 0)
  1705. return rc;
  1706. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  1707. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  1708. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  1709. if ((bar_num != IDIAG_BARACC_BAR_0) &&
  1710. (bar_num != IDIAG_BARACC_BAR_1) &&
  1711. (bar_num != IDIAG_BARACC_BAR_2))
  1712. goto error_out;
  1713. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  1714. if (bar_num != IDIAG_BARACC_BAR_0)
  1715. goto error_out;
  1716. } else
  1717. goto error_out;
  1718. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  1719. if (bar_num == IDIAG_BARACC_BAR_0) {
  1720. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1721. LPFC_PCI_IF0_BAR0_SIZE;
  1722. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1723. } else if (bar_num == IDIAG_BARACC_BAR_1) {
  1724. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1725. LPFC_PCI_IF0_BAR1_SIZE;
  1726. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  1727. } else if (bar_num == IDIAG_BARACC_BAR_2) {
  1728. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1729. LPFC_PCI_IF0_BAR2_SIZE;
  1730. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  1731. } else
  1732. goto error_out;
  1733. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  1734. if (bar_num == IDIAG_BARACC_BAR_0) {
  1735. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1736. LPFC_PCI_IF2_BAR0_SIZE;
  1737. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1738. } else
  1739. goto error_out;
  1740. } else
  1741. goto error_out;
  1742. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  1743. if (offset % sizeof(uint32_t))
  1744. goto error_out;
  1745. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  1746. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  1747. /* Sanity check on PCI config read command line arguments */
  1748. if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
  1749. goto error_out;
  1750. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  1751. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  1752. if (offset > bar_size - sizeof(uint32_t))
  1753. goto error_out;
  1754. /* Starting offset to browse */
  1755. idiag.offset.last_rd = offset;
  1756. } else if (acc_range > SINGLE_WORD) {
  1757. if (offset + acc_range * sizeof(uint32_t) > bar_size)
  1758. goto error_out;
  1759. /* Starting offset to browse */
  1760. idiag.offset.last_rd = offset;
  1761. } else if (acc_range != SINGLE_WORD)
  1762. goto error_out;
  1763. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
  1764. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
  1765. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  1766. /* Sanity check on PCI bar write command line arguments */
  1767. if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
  1768. goto error_out;
  1769. /* Write command to PCI bar space, read-modify-write */
  1770. acc_range = SINGLE_WORD;
  1771. value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
  1772. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
  1773. writel(value, mem_mapped_bar + offset);
  1774. readl(mem_mapped_bar + offset);
  1775. }
  1776. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
  1777. u32val = readl(mem_mapped_bar + offset);
  1778. u32val |= value;
  1779. writel(u32val, mem_mapped_bar + offset);
  1780. readl(mem_mapped_bar + offset);
  1781. }
  1782. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  1783. u32val = readl(mem_mapped_bar + offset);
  1784. u32val &= ~value;
  1785. writel(u32val, mem_mapped_bar + offset);
  1786. readl(mem_mapped_bar + offset);
  1787. }
  1788. } else
  1789. /* All other opecodes are illegal for now */
  1790. goto error_out;
  1791. return nbytes;
  1792. error_out:
  1793. memset(&idiag, 0, sizeof(idiag));
  1794. return -EINVAL;
  1795. }
  1796. /**
  1797. * lpfc_idiag_queinfo_read - idiag debugfs read queue information
  1798. * @file: The file pointer to read from.
  1799. * @buf: The buffer to copy the data to.
  1800. * @nbytes: The number of bytes to read.
  1801. * @ppos: The position in the file to start reading from.
  1802. *
  1803. * Description:
  1804. * This routine reads data from the @phba SLI4 PCI function queue information,
  1805. * and copies to user @buf.
  1806. *
  1807. * Returns:
  1808. * This function returns the amount of data that was read (this could be less
  1809. * than @nbytes if the end of the file was reached) or a negative error value.
  1810. **/
  1811. static ssize_t
  1812. lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
  1813. loff_t *ppos)
  1814. {
  1815. struct lpfc_debug *debug = file->private_data;
  1816. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1817. int len = 0;
  1818. char *pbuffer;
  1819. int x, cnt;
  1820. int max_cnt;
  1821. struct lpfc_queue *qp = NULL;
  1822. if (!debug->buffer)
  1823. debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
  1824. if (!debug->buffer)
  1825. return 0;
  1826. pbuffer = debug->buffer;
  1827. max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 128;
  1828. if (*ppos)
  1829. return 0;
  1830. spin_lock_irq(&phba->hbalock);
  1831. /* Fast-path event queue */
  1832. if (phba->sli4_hba.hba_eq && phba->cfg_fcp_io_channel) {
  1833. cnt = phba->cfg_fcp_io_channel;
  1834. for (x = 0; x < cnt; x++) {
  1835. /* Fast-path EQ */
  1836. qp = phba->sli4_hba.hba_eq[x];
  1837. if (!qp)
  1838. goto proc_cq;
  1839. len += snprintf(pbuffer+len,
  1840. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1841. "\nHBA EQ info: "
  1842. "EQ-STAT[max:x%x noE:x%x "
  1843. "bs:x%x proc:x%llx]\n",
  1844. qp->q_cnt_1, qp->q_cnt_2,
  1845. qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
  1846. len += snprintf(pbuffer+len,
  1847. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1848. "EQID[%02d], "
  1849. "QE-CNT[%04d], QE-SIZE[%04d], "
  1850. "HOST-IDX[%04d], PORT-IDX[%04d]",
  1851. qp->queue_id,
  1852. qp->entry_count,
  1853. qp->entry_size,
  1854. qp->host_index,
  1855. qp->hba_index);
  1856. /* Reset max counter */
  1857. qp->EQ_max_eqe = 0;
  1858. len += snprintf(pbuffer+len,
  1859. LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1860. if (len >= max_cnt)
  1861. goto too_big;
  1862. proc_cq:
  1863. /* Fast-path FCP CQ */
  1864. qp = phba->sli4_hba.fcp_cq[x];
  1865. len += snprintf(pbuffer+len,
  1866. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1867. "\tFCP CQ info: ");
  1868. len += snprintf(pbuffer+len,
  1869. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1870. "AssocEQID[%02d]: "
  1871. "CQ STAT[max:x%x relw:x%x "
  1872. "xabt:x%x wq:x%llx]\n",
  1873. qp->assoc_qid,
  1874. qp->q_cnt_1, qp->q_cnt_2,
  1875. qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
  1876. len += snprintf(pbuffer+len,
  1877. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1878. "\tCQID[%02d], "
  1879. "QE-CNT[%04d], QE-SIZE[%04d], "
  1880. "HOST-IDX[%04d], PORT-IDX[%04d]",
  1881. qp->queue_id, qp->entry_count,
  1882. qp->entry_size, qp->host_index,
  1883. qp->hba_index);
  1884. /* Reset max counter */
  1885. qp->CQ_max_cqe = 0;
  1886. len += snprintf(pbuffer+len,
  1887. LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1888. if (len >= max_cnt)
  1889. goto too_big;
  1890. /* Fast-path FCP WQ */
  1891. qp = phba->sli4_hba.fcp_wq[x];
  1892. len += snprintf(pbuffer+len,
  1893. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1894. "\t\tFCP WQ info: ");
  1895. len += snprintf(pbuffer+len,
  1896. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1897. "AssocCQID[%02d]: "
  1898. "WQ-STAT[oflow:x%x posted:x%llx]\n",
  1899. qp->assoc_qid,
  1900. qp->q_cnt_1, (unsigned long long)qp->q_cnt_4);
  1901. len += snprintf(pbuffer+len,
  1902. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1903. "\t\tWQID[%02d], "
  1904. "QE-CNT[%04d], QE-SIZE[%04d], "
  1905. "HOST-IDX[%04d], PORT-IDX[%04d]",
  1906. qp->queue_id,
  1907. qp->entry_count,
  1908. qp->entry_size,
  1909. qp->host_index,
  1910. qp->hba_index);
  1911. len += snprintf(pbuffer+len,
  1912. LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1913. if (len >= max_cnt)
  1914. goto too_big;
  1915. if (x)
  1916. continue;
  1917. /* Only EQ 0 has slow path CQs configured */
  1918. /* Slow-path mailbox CQ */
  1919. qp = phba->sli4_hba.mbx_cq;
  1920. if (qp) {
  1921. len += snprintf(pbuffer+len,
  1922. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1923. "\tMBX CQ info: ");
  1924. len += snprintf(pbuffer+len,
  1925. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1926. "AssocEQID[%02d]: "
  1927. "CQ-STAT[mbox:x%x relw:x%x "
  1928. "xabt:x%x wq:x%llx]\n",
  1929. qp->assoc_qid,
  1930. qp->q_cnt_1, qp->q_cnt_2,
  1931. qp->q_cnt_3,
  1932. (unsigned long long)qp->q_cnt_4);
  1933. len += snprintf(pbuffer+len,
  1934. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1935. "\tCQID[%02d], "
  1936. "QE-CNT[%04d], QE-SIZE[%04d], "
  1937. "HOST-IDX[%04d], PORT-IDX[%04d]",
  1938. qp->queue_id, qp->entry_count,
  1939. qp->entry_size, qp->host_index,
  1940. qp->hba_index);
  1941. len += snprintf(pbuffer+len,
  1942. LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1943. if (len >= max_cnt)
  1944. goto too_big;
  1945. }
  1946. /* Slow-path MBOX MQ */
  1947. qp = phba->sli4_hba.mbx_wq;
  1948. if (qp) {
  1949. len += snprintf(pbuffer+len,
  1950. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1951. "\t\tMBX MQ info: ");
  1952. len += snprintf(pbuffer+len,
  1953. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1954. "AssocCQID[%02d]:\n",
  1955. phba->sli4_hba.mbx_wq->assoc_qid);
  1956. len += snprintf(pbuffer+len,
  1957. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1958. "\t\tWQID[%02d], "
  1959. "QE-CNT[%04d], QE-SIZE[%04d], "
  1960. "HOST-IDX[%04d], PORT-IDX[%04d]",
  1961. qp->queue_id, qp->entry_count,
  1962. qp->entry_size, qp->host_index,
  1963. qp->hba_index);
  1964. len += snprintf(pbuffer+len,
  1965. LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1966. if (len >= max_cnt)
  1967. goto too_big;
  1968. }
  1969. /* Slow-path ELS response CQ */
  1970. qp = phba->sli4_hba.els_cq;
  1971. if (qp) {
  1972. len += snprintf(pbuffer+len,
  1973. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1974. "\tELS CQ info: ");
  1975. len += snprintf(pbuffer+len,
  1976. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1977. "AssocEQID[%02d]: "
  1978. "CQ-STAT[max:x%x relw:x%x "
  1979. "xabt:x%x wq:x%llx]\n",
  1980. qp->assoc_qid,
  1981. qp->q_cnt_1, qp->q_cnt_2,
  1982. qp->q_cnt_3,
  1983. (unsigned long long)qp->q_cnt_4);
  1984. len += snprintf(pbuffer+len,
  1985. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1986. "\tCQID [%02d], "
  1987. "QE-CNT[%04d], QE-SIZE[%04d], "
  1988. "HOST-IDX[%04d], PORT-IDX[%04d]",
  1989. qp->queue_id, qp->entry_count,
  1990. qp->entry_size, qp->host_index,
  1991. qp->hba_index);
  1992. /* Reset max counter */
  1993. qp->CQ_max_cqe = 0;
  1994. len += snprintf(pbuffer+len,
  1995. LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1996. if (len >= max_cnt)
  1997. goto too_big;
  1998. }
  1999. /* Slow-path ELS WQ */
  2000. qp = phba->sli4_hba.els_wq;
  2001. if (qp) {
  2002. len += snprintf(pbuffer+len,
  2003. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  2004. "\t\tELS WQ info: ");
  2005. len += snprintf(pbuffer+len,
  2006. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  2007. "AssocCQID[%02d]: "
  2008. " WQ-STAT[oflow:x%x "
  2009. "posted:x%llx]\n",
  2010. qp->assoc_qid,
  2011. qp->q_cnt_1,
  2012. (unsigned long long)qp->q_cnt_4);
  2013. len += snprintf(pbuffer+len,
  2014. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  2015. "\t\tWQID[%02d], "
  2016. "QE-CNT[%04d], QE-SIZE[%04d], "
  2017. "HOST-IDX[%04d], PORT-IDX[%04d]",
  2018. qp->queue_id, qp->entry_count,
  2019. qp->entry_size, qp->host_index,
  2020. qp->hba_index);
  2021. len += snprintf(pbuffer+len,
  2022. LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  2023. if (len >= max_cnt)
  2024. goto too_big;
  2025. }
  2026. if (phba->sli4_hba.hdr_rq && phba->sli4_hba.dat_rq) {
  2027. /* Slow-path RQ header */
  2028. qp = phba->sli4_hba.hdr_rq;
  2029. len += snprintf(pbuffer+len,
  2030. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  2031. "\t\tRQ info: ");
  2032. len += snprintf(pbuffer+len,
  2033. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  2034. "AssocCQID[%02d]: "
  2035. "RQ-STAT[nopost:x%x nobuf:x%x "
  2036. "trunc:x%x rcv:x%llx]\n",
  2037. qp->assoc_qid,
  2038. qp->q_cnt_1, qp->q_cnt_2,
  2039. qp->q_cnt_3,
  2040. (unsigned long long)qp->q_cnt_4);
  2041. len += snprintf(pbuffer+len,
  2042. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  2043. "\t\tHQID[%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. /* Slow-path RQ data */
  2052. qp = phba->sli4_hba.dat_rq;
  2053. len += snprintf(pbuffer+len,
  2054. LPFC_QUE_INFO_GET_BUF_SIZE-len,
  2055. "\t\tDQID[%02d], "
  2056. "QE-CNT[%04d], QE-SIZE[%04d], "
  2057. "HOST-IDX[%04d], PORT-IDX[%04d]\n",
  2058. qp->queue_id,
  2059. qp->entry_count,
  2060. qp->entry_size,
  2061. qp->host_index,
  2062. qp->hba_index);
  2063. len += snprintf(pbuffer+len,
  2064. LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  2065. }
  2066. }
  2067. }
  2068. spin_unlock_irq(&phba->hbalock);
  2069. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2070. too_big:
  2071. len += snprintf(pbuffer+len,
  2072. LPFC_QUE_INFO_GET_BUF_SIZE-len, "Truncated ...\n");
  2073. spin_unlock_irq(&phba->hbalock);
  2074. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2075. }
  2076. /**
  2077. * lpfc_idiag_que_param_check - queue access command parameter sanity check
  2078. * @q: The pointer to queue structure.
  2079. * @index: The index into a queue entry.
  2080. * @count: The number of queue entries to access.
  2081. *
  2082. * Description:
  2083. * The routine performs sanity check on device queue access method commands.
  2084. *
  2085. * Returns:
  2086. * This function returns -EINVAL when fails the sanity check, otherwise, it
  2087. * returns 0.
  2088. **/
  2089. static int
  2090. lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
  2091. {
  2092. /* Only support single entry read or browsing */
  2093. if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
  2094. return -EINVAL;
  2095. if (index > q->entry_count - 1)
  2096. return -EINVAL;
  2097. return 0;
  2098. }
  2099. /**
  2100. * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
  2101. * @pbuffer: The pointer to buffer to copy the read data into.
  2102. * @pque: The pointer to the queue to be read.
  2103. * @index: The index into the queue entry.
  2104. *
  2105. * Description:
  2106. * This routine reads out a single entry from the given queue's index location
  2107. * and copies it into the buffer provided.
  2108. *
  2109. * Returns:
  2110. * This function returns 0 when it fails, otherwise, it returns the length of
  2111. * the data read into the buffer provided.
  2112. **/
  2113. static int
  2114. lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
  2115. uint32_t index)
  2116. {
  2117. int offset, esize;
  2118. uint32_t *pentry;
  2119. if (!pbuffer || !pque)
  2120. return 0;
  2121. esize = pque->entry_size;
  2122. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  2123. "QE-INDEX[%04d]:\n", index);
  2124. offset = 0;
  2125. pentry = pque->qe[index].address;
  2126. while (esize > 0) {
  2127. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  2128. "%08x ", *pentry);
  2129. pentry++;
  2130. offset += sizeof(uint32_t);
  2131. esize -= sizeof(uint32_t);
  2132. if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
  2133. len += snprintf(pbuffer+len,
  2134. LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  2135. }
  2136. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  2137. return len;
  2138. }
  2139. /**
  2140. * lpfc_idiag_queacc_read - idiag debugfs read port queue
  2141. * @file: The file pointer to read from.
  2142. * @buf: The buffer to copy the data to.
  2143. * @nbytes: The number of bytes to read.
  2144. * @ppos: The position in the file to start reading from.
  2145. *
  2146. * Description:
  2147. * This routine reads data from the @phba device queue memory according to the
  2148. * idiag command, and copies to user @buf. Depending on the queue dump read
  2149. * command setup, it does either a single queue entry read or browing through
  2150. * all entries of the queue.
  2151. *
  2152. * Returns:
  2153. * This function returns the amount of data that was read (this could be less
  2154. * than @nbytes if the end of the file was reached) or a negative error value.
  2155. **/
  2156. static ssize_t
  2157. lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
  2158. loff_t *ppos)
  2159. {
  2160. struct lpfc_debug *debug = file->private_data;
  2161. uint32_t last_index, index, count;
  2162. struct lpfc_queue *pque = NULL;
  2163. char *pbuffer;
  2164. int len = 0;
  2165. /* This is a user read operation */
  2166. debug->op = LPFC_IDIAG_OP_RD;
  2167. if (!debug->buffer)
  2168. debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
  2169. if (!debug->buffer)
  2170. return 0;
  2171. pbuffer = debug->buffer;
  2172. if (*ppos)
  2173. return 0;
  2174. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  2175. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  2176. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  2177. pque = (struct lpfc_queue *)idiag.ptr_private;
  2178. } else
  2179. return 0;
  2180. /* Browse the queue starting from index */
  2181. if (count == LPFC_QUE_ACC_BROWSE)
  2182. goto que_browse;
  2183. /* Read a single entry from the queue */
  2184. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  2185. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2186. que_browse:
  2187. /* Browse all entries from the queue */
  2188. last_index = idiag.offset.last_rd;
  2189. index = last_index;
  2190. while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
  2191. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  2192. index++;
  2193. if (index > pque->entry_count - 1)
  2194. break;
  2195. }
  2196. /* Set up the offset for next portion of pci cfg read */
  2197. if (index > pque->entry_count - 1)
  2198. index = 0;
  2199. idiag.offset.last_rd = index;
  2200. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2201. }
  2202. /**
  2203. * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
  2204. * @file: The file pointer to read from.
  2205. * @buf: The buffer to copy the user data from.
  2206. * @nbytes: The number of bytes to get.
  2207. * @ppos: The position in the file to start reading from.
  2208. *
  2209. * This routine get the debugfs idiag command struct from user space and then
  2210. * perform the syntax check for port queue read (dump) or write (set) command
  2211. * accordingly. In the case of port queue read command, it sets up the command
  2212. * in the idiag command struct for the following debugfs read operation. In
  2213. * the case of port queue write operation, it executes the write operation
  2214. * into the port queue entry accordingly.
  2215. *
  2216. * It returns the @nbytges passing in from debugfs user space when successful.
  2217. * In case of error conditions, it returns proper error code back to the user
  2218. * space.
  2219. **/
  2220. static ssize_t
  2221. lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
  2222. size_t nbytes, loff_t *ppos)
  2223. {
  2224. struct lpfc_debug *debug = file->private_data;
  2225. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2226. uint32_t qidx, quetp, queid, index, count, offset, value;
  2227. uint32_t *pentry;
  2228. struct lpfc_queue *pque;
  2229. int rc;
  2230. /* This is a user write operation */
  2231. debug->op = LPFC_IDIAG_OP_WR;
  2232. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2233. if (rc < 0)
  2234. return rc;
  2235. /* Get and sanity check on command feilds */
  2236. quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
  2237. queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
  2238. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  2239. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  2240. offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
  2241. value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
  2242. /* Sanity check on command line arguments */
  2243. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  2244. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  2245. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  2246. if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
  2247. goto error_out;
  2248. if (count != 1)
  2249. goto error_out;
  2250. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  2251. if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
  2252. goto error_out;
  2253. } else
  2254. goto error_out;
  2255. switch (quetp) {
  2256. case LPFC_IDIAG_EQ:
  2257. /* HBA event queue */
  2258. if (phba->sli4_hba.hba_eq) {
  2259. for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
  2260. qidx++) {
  2261. if (phba->sli4_hba.hba_eq[qidx] &&
  2262. phba->sli4_hba.hba_eq[qidx]->queue_id ==
  2263. queid) {
  2264. /* Sanity check */
  2265. rc = lpfc_idiag_que_param_check(
  2266. phba->sli4_hba.hba_eq[qidx],
  2267. index, count);
  2268. if (rc)
  2269. goto error_out;
  2270. idiag.ptr_private =
  2271. phba->sli4_hba.hba_eq[qidx];
  2272. goto pass_check;
  2273. }
  2274. }
  2275. }
  2276. goto error_out;
  2277. break;
  2278. case LPFC_IDIAG_CQ:
  2279. /* MBX complete queue */
  2280. if (phba->sli4_hba.mbx_cq &&
  2281. phba->sli4_hba.mbx_cq->queue_id == queid) {
  2282. /* Sanity check */
  2283. rc = lpfc_idiag_que_param_check(
  2284. phba->sli4_hba.mbx_cq, index, count);
  2285. if (rc)
  2286. goto error_out;
  2287. idiag.ptr_private = phba->sli4_hba.mbx_cq;
  2288. goto pass_check;
  2289. }
  2290. /* ELS complete queue */
  2291. if (phba->sli4_hba.els_cq &&
  2292. phba->sli4_hba.els_cq->queue_id == queid) {
  2293. /* Sanity check */
  2294. rc = lpfc_idiag_que_param_check(
  2295. phba->sli4_hba.els_cq, index, count);
  2296. if (rc)
  2297. goto error_out;
  2298. idiag.ptr_private = phba->sli4_hba.els_cq;
  2299. goto pass_check;
  2300. }
  2301. /* FCP complete queue */
  2302. if (phba->sli4_hba.fcp_cq) {
  2303. qidx = 0;
  2304. do {
  2305. if (phba->sli4_hba.fcp_cq[qidx] &&
  2306. phba->sli4_hba.fcp_cq[qidx]->queue_id ==
  2307. queid) {
  2308. /* Sanity check */
  2309. rc = lpfc_idiag_que_param_check(
  2310. phba->sli4_hba.fcp_cq[qidx],
  2311. index, count);
  2312. if (rc)
  2313. goto error_out;
  2314. idiag.ptr_private =
  2315. phba->sli4_hba.fcp_cq[qidx];
  2316. goto pass_check;
  2317. }
  2318. } while (++qidx < phba->cfg_fcp_io_channel);
  2319. }
  2320. goto error_out;
  2321. break;
  2322. case LPFC_IDIAG_MQ:
  2323. /* MBX work queue */
  2324. if (phba->sli4_hba.mbx_wq &&
  2325. phba->sli4_hba.mbx_wq->queue_id == queid) {
  2326. /* Sanity check */
  2327. rc = lpfc_idiag_que_param_check(
  2328. phba->sli4_hba.mbx_wq, index, count);
  2329. if (rc)
  2330. goto error_out;
  2331. idiag.ptr_private = phba->sli4_hba.mbx_wq;
  2332. goto pass_check;
  2333. }
  2334. goto error_out;
  2335. break;
  2336. case LPFC_IDIAG_WQ:
  2337. /* ELS work queue */
  2338. if (phba->sli4_hba.els_wq &&
  2339. phba->sli4_hba.els_wq->queue_id == queid) {
  2340. /* Sanity check */
  2341. rc = lpfc_idiag_que_param_check(
  2342. phba->sli4_hba.els_wq, index, count);
  2343. if (rc)
  2344. goto error_out;
  2345. idiag.ptr_private = phba->sli4_hba.els_wq;
  2346. goto pass_check;
  2347. }
  2348. /* FCP work queue */
  2349. if (phba->sli4_hba.fcp_wq) {
  2350. for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
  2351. qidx++) {
  2352. if (!phba->sli4_hba.fcp_wq[qidx])
  2353. continue;
  2354. if (phba->sli4_hba.fcp_wq[qidx]->queue_id ==
  2355. queid) {
  2356. /* Sanity check */
  2357. rc = lpfc_idiag_que_param_check(
  2358. phba->sli4_hba.fcp_wq[qidx],
  2359. index, count);
  2360. if (rc)
  2361. goto error_out;
  2362. idiag.ptr_private =
  2363. phba->sli4_hba.fcp_wq[qidx];
  2364. goto pass_check;
  2365. }
  2366. }
  2367. }
  2368. goto error_out;
  2369. break;
  2370. case LPFC_IDIAG_RQ:
  2371. /* HDR queue */
  2372. if (phba->sli4_hba.hdr_rq &&
  2373. phba->sli4_hba.hdr_rq->queue_id == queid) {
  2374. /* Sanity check */
  2375. rc = lpfc_idiag_que_param_check(
  2376. phba->sli4_hba.hdr_rq, index, count);
  2377. if (rc)
  2378. goto error_out;
  2379. idiag.ptr_private = phba->sli4_hba.hdr_rq;
  2380. goto pass_check;
  2381. }
  2382. /* DAT queue */
  2383. if (phba->sli4_hba.dat_rq &&
  2384. phba->sli4_hba.dat_rq->queue_id == queid) {
  2385. /* Sanity check */
  2386. rc = lpfc_idiag_que_param_check(
  2387. phba->sli4_hba.dat_rq, index, count);
  2388. if (rc)
  2389. goto error_out;
  2390. idiag.ptr_private = phba->sli4_hba.dat_rq;
  2391. goto pass_check;
  2392. }
  2393. goto error_out;
  2394. break;
  2395. default:
  2396. goto error_out;
  2397. break;
  2398. }
  2399. pass_check:
  2400. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  2401. if (count == LPFC_QUE_ACC_BROWSE)
  2402. idiag.offset.last_rd = index;
  2403. }
  2404. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  2405. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  2406. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  2407. /* Additional sanity checks on write operation */
  2408. pque = (struct lpfc_queue *)idiag.ptr_private;
  2409. if (offset > pque->entry_size/sizeof(uint32_t) - 1)
  2410. goto error_out;
  2411. pentry = pque->qe[index].address;
  2412. pentry += offset;
  2413. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
  2414. *pentry = value;
  2415. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
  2416. *pentry |= value;
  2417. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
  2418. *pentry &= ~value;
  2419. }
  2420. return nbytes;
  2421. error_out:
  2422. /* Clean out command structure on command error out */
  2423. memset(&idiag, 0, sizeof(idiag));
  2424. return -EINVAL;
  2425. }
  2426. /**
  2427. * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
  2428. * @phba: The pointer to hba structure.
  2429. * @pbuffer: The pointer to the buffer to copy the data to.
  2430. * @len: The lenght of bytes to copied.
  2431. * @drbregid: The id to doorbell registers.
  2432. *
  2433. * Description:
  2434. * This routine reads a doorbell register and copies its content to the
  2435. * user buffer pointed to by @pbuffer.
  2436. *
  2437. * Returns:
  2438. * This function returns the amount of data that was copied into @pbuffer.
  2439. **/
  2440. static int
  2441. lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  2442. int len, uint32_t drbregid)
  2443. {
  2444. if (!pbuffer)
  2445. return 0;
  2446. switch (drbregid) {
  2447. case LPFC_DRB_EQCQ:
  2448. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2449. "EQCQ-DRB-REG: 0x%08x\n",
  2450. readl(phba->sli4_hba.EQCQDBregaddr));
  2451. break;
  2452. case LPFC_DRB_MQ:
  2453. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2454. "MQ-DRB-REG: 0x%08x\n",
  2455. readl(phba->sli4_hba.MQDBregaddr));
  2456. break;
  2457. case LPFC_DRB_WQ:
  2458. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2459. "WQ-DRB-REG: 0x%08x\n",
  2460. readl(phba->sli4_hba.WQDBregaddr));
  2461. break;
  2462. case LPFC_DRB_RQ:
  2463. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2464. "RQ-DRB-REG: 0x%08x\n",
  2465. readl(phba->sli4_hba.RQDBregaddr));
  2466. break;
  2467. default:
  2468. break;
  2469. }
  2470. return len;
  2471. }
  2472. /**
  2473. * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
  2474. * @file: The file pointer to read from.
  2475. * @buf: The buffer to copy the data to.
  2476. * @nbytes: The number of bytes to read.
  2477. * @ppos: The position in the file to start reading from.
  2478. *
  2479. * Description:
  2480. * This routine reads data from the @phba device doorbell register according
  2481. * to the idiag command, and copies to user @buf. Depending on the doorbell
  2482. * register read command setup, it does either a single doorbell register
  2483. * read or dump all doorbell registers.
  2484. *
  2485. * Returns:
  2486. * This function returns the amount of data that was read (this could be less
  2487. * than @nbytes if the end of the file was reached) or a negative error value.
  2488. **/
  2489. static ssize_t
  2490. lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
  2491. loff_t *ppos)
  2492. {
  2493. struct lpfc_debug *debug = file->private_data;
  2494. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2495. uint32_t drb_reg_id, i;
  2496. char *pbuffer;
  2497. int len = 0;
  2498. /* This is a user read operation */
  2499. debug->op = LPFC_IDIAG_OP_RD;
  2500. if (!debug->buffer)
  2501. debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
  2502. if (!debug->buffer)
  2503. return 0;
  2504. pbuffer = debug->buffer;
  2505. if (*ppos)
  2506. return 0;
  2507. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
  2508. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  2509. else
  2510. return 0;
  2511. if (drb_reg_id == LPFC_DRB_ACC_ALL)
  2512. for (i = 1; i <= LPFC_DRB_MAX; i++)
  2513. len = lpfc_idiag_drbacc_read_reg(phba,
  2514. pbuffer, len, i);
  2515. else
  2516. len = lpfc_idiag_drbacc_read_reg(phba,
  2517. pbuffer, len, drb_reg_id);
  2518. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2519. }
  2520. /**
  2521. * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
  2522. * @file: The file pointer to read from.
  2523. * @buf: The buffer to copy the user data from.
  2524. * @nbytes: The number of bytes to get.
  2525. * @ppos: The position in the file to start reading from.
  2526. *
  2527. * This routine get the debugfs idiag command struct from user space and then
  2528. * perform the syntax check for port doorbell register read (dump) or write
  2529. * (set) command accordingly. In the case of port queue read command, it sets
  2530. * up the command in the idiag command struct for the following debugfs read
  2531. * operation. In the case of port doorbell register write operation, it
  2532. * executes the write operation into the port doorbell register accordingly.
  2533. *
  2534. * It returns the @nbytges passing in from debugfs user space when successful.
  2535. * In case of error conditions, it returns proper error code back to the user
  2536. * space.
  2537. **/
  2538. static ssize_t
  2539. lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
  2540. size_t nbytes, loff_t *ppos)
  2541. {
  2542. struct lpfc_debug *debug = file->private_data;
  2543. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2544. uint32_t drb_reg_id, value, reg_val = 0;
  2545. void __iomem *drb_reg;
  2546. int rc;
  2547. /* This is a user write operation */
  2548. debug->op = LPFC_IDIAG_OP_WR;
  2549. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2550. if (rc < 0)
  2551. return rc;
  2552. /* Sanity check on command line arguments */
  2553. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  2554. value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
  2555. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  2556. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  2557. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2558. if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
  2559. goto error_out;
  2560. if (drb_reg_id > LPFC_DRB_MAX)
  2561. goto error_out;
  2562. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
  2563. if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
  2564. goto error_out;
  2565. if ((drb_reg_id > LPFC_DRB_MAX) &&
  2566. (drb_reg_id != LPFC_DRB_ACC_ALL))
  2567. goto error_out;
  2568. } else
  2569. goto error_out;
  2570. /* Perform the write access operation */
  2571. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  2572. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  2573. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2574. switch (drb_reg_id) {
  2575. case LPFC_DRB_EQCQ:
  2576. drb_reg = phba->sli4_hba.EQCQDBregaddr;
  2577. break;
  2578. case LPFC_DRB_MQ:
  2579. drb_reg = phba->sli4_hba.MQDBregaddr;
  2580. break;
  2581. case LPFC_DRB_WQ:
  2582. drb_reg = phba->sli4_hba.WQDBregaddr;
  2583. break;
  2584. case LPFC_DRB_RQ:
  2585. drb_reg = phba->sli4_hba.RQDBregaddr;
  2586. break;
  2587. default:
  2588. goto error_out;
  2589. }
  2590. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
  2591. reg_val = value;
  2592. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
  2593. reg_val = readl(drb_reg);
  2594. reg_val |= value;
  2595. }
  2596. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2597. reg_val = readl(drb_reg);
  2598. reg_val &= ~value;
  2599. }
  2600. writel(reg_val, drb_reg);
  2601. readl(drb_reg); /* flush */
  2602. }
  2603. return nbytes;
  2604. error_out:
  2605. /* Clean out command structure on command error out */
  2606. memset(&idiag, 0, sizeof(idiag));
  2607. return -EINVAL;
  2608. }
  2609. /**
  2610. * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
  2611. * @phba: The pointer to hba structure.
  2612. * @pbuffer: The pointer to the buffer to copy the data to.
  2613. * @len: The lenght of bytes to copied.
  2614. * @drbregid: The id to doorbell registers.
  2615. *
  2616. * Description:
  2617. * This routine reads a control register and copies its content to the
  2618. * user buffer pointed to by @pbuffer.
  2619. *
  2620. * Returns:
  2621. * This function returns the amount of data that was copied into @pbuffer.
  2622. **/
  2623. static int
  2624. lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  2625. int len, uint32_t ctlregid)
  2626. {
  2627. if (!pbuffer)
  2628. return 0;
  2629. switch (ctlregid) {
  2630. case LPFC_CTL_PORT_SEM:
  2631. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2632. "Port SemReg: 0x%08x\n",
  2633. readl(phba->sli4_hba.conf_regs_memmap_p +
  2634. LPFC_CTL_PORT_SEM_OFFSET));
  2635. break;
  2636. case LPFC_CTL_PORT_STA:
  2637. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2638. "Port StaReg: 0x%08x\n",
  2639. readl(phba->sli4_hba.conf_regs_memmap_p +
  2640. LPFC_CTL_PORT_STA_OFFSET));
  2641. break;
  2642. case LPFC_CTL_PORT_CTL:
  2643. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2644. "Port CtlReg: 0x%08x\n",
  2645. readl(phba->sli4_hba.conf_regs_memmap_p +
  2646. LPFC_CTL_PORT_CTL_OFFSET));
  2647. break;
  2648. case LPFC_CTL_PORT_ER1:
  2649. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2650. "Port Er1Reg: 0x%08x\n",
  2651. readl(phba->sli4_hba.conf_regs_memmap_p +
  2652. LPFC_CTL_PORT_ER1_OFFSET));
  2653. break;
  2654. case LPFC_CTL_PORT_ER2:
  2655. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2656. "Port Er2Reg: 0x%08x\n",
  2657. readl(phba->sli4_hba.conf_regs_memmap_p +
  2658. LPFC_CTL_PORT_ER2_OFFSET));
  2659. break;
  2660. case LPFC_CTL_PDEV_CTL:
  2661. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2662. "PDev CtlReg: 0x%08x\n",
  2663. readl(phba->sli4_hba.conf_regs_memmap_p +
  2664. LPFC_CTL_PDEV_CTL_OFFSET));
  2665. break;
  2666. default:
  2667. break;
  2668. }
  2669. return len;
  2670. }
  2671. /**
  2672. * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
  2673. * @file: The file pointer to read from.
  2674. * @buf: The buffer to copy the data to.
  2675. * @nbytes: The number of bytes to read.
  2676. * @ppos: The position in the file to start reading from.
  2677. *
  2678. * Description:
  2679. * This routine reads data from the @phba port and device registers according
  2680. * to the idiag command, and copies to user @buf.
  2681. *
  2682. * Returns:
  2683. * This function returns the amount of data that was read (this could be less
  2684. * than @nbytes if the end of the file was reached) or a negative error value.
  2685. **/
  2686. static ssize_t
  2687. lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
  2688. loff_t *ppos)
  2689. {
  2690. struct lpfc_debug *debug = file->private_data;
  2691. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2692. uint32_t ctl_reg_id, i;
  2693. char *pbuffer;
  2694. int len = 0;
  2695. /* This is a user read operation */
  2696. debug->op = LPFC_IDIAG_OP_RD;
  2697. if (!debug->buffer)
  2698. debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
  2699. if (!debug->buffer)
  2700. return 0;
  2701. pbuffer = debug->buffer;
  2702. if (*ppos)
  2703. return 0;
  2704. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
  2705. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  2706. else
  2707. return 0;
  2708. if (ctl_reg_id == LPFC_CTL_ACC_ALL)
  2709. for (i = 1; i <= LPFC_CTL_MAX; i++)
  2710. len = lpfc_idiag_ctlacc_read_reg(phba,
  2711. pbuffer, len, i);
  2712. else
  2713. len = lpfc_idiag_ctlacc_read_reg(phba,
  2714. pbuffer, len, ctl_reg_id);
  2715. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2716. }
  2717. /**
  2718. * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
  2719. * @file: The file pointer to read from.
  2720. * @buf: The buffer to copy the user data from.
  2721. * @nbytes: The number of bytes to get.
  2722. * @ppos: The position in the file to start reading from.
  2723. *
  2724. * This routine get the debugfs idiag command struct from user space and then
  2725. * perform the syntax check for port and device control register read (dump)
  2726. * or write (set) command accordingly.
  2727. *
  2728. * It returns the @nbytges passing in from debugfs user space when successful.
  2729. * In case of error conditions, it returns proper error code back to the user
  2730. * space.
  2731. **/
  2732. static ssize_t
  2733. lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
  2734. size_t nbytes, loff_t *ppos)
  2735. {
  2736. struct lpfc_debug *debug = file->private_data;
  2737. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2738. uint32_t ctl_reg_id, value, reg_val = 0;
  2739. void __iomem *ctl_reg;
  2740. int rc;
  2741. /* This is a user write operation */
  2742. debug->op = LPFC_IDIAG_OP_WR;
  2743. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2744. if (rc < 0)
  2745. return rc;
  2746. /* Sanity check on command line arguments */
  2747. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  2748. value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
  2749. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  2750. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  2751. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  2752. if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
  2753. goto error_out;
  2754. if (ctl_reg_id > LPFC_CTL_MAX)
  2755. goto error_out;
  2756. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
  2757. if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
  2758. goto error_out;
  2759. if ((ctl_reg_id > LPFC_CTL_MAX) &&
  2760. (ctl_reg_id != LPFC_CTL_ACC_ALL))
  2761. goto error_out;
  2762. } else
  2763. goto error_out;
  2764. /* Perform the write access operation */
  2765. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  2766. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  2767. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  2768. switch (ctl_reg_id) {
  2769. case LPFC_CTL_PORT_SEM:
  2770. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2771. LPFC_CTL_PORT_SEM_OFFSET;
  2772. break;
  2773. case LPFC_CTL_PORT_STA:
  2774. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2775. LPFC_CTL_PORT_STA_OFFSET;
  2776. break;
  2777. case LPFC_CTL_PORT_CTL:
  2778. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2779. LPFC_CTL_PORT_CTL_OFFSET;
  2780. break;
  2781. case LPFC_CTL_PORT_ER1:
  2782. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2783. LPFC_CTL_PORT_ER1_OFFSET;
  2784. break;
  2785. case LPFC_CTL_PORT_ER2:
  2786. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2787. LPFC_CTL_PORT_ER2_OFFSET;
  2788. break;
  2789. case LPFC_CTL_PDEV_CTL:
  2790. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2791. LPFC_CTL_PDEV_CTL_OFFSET;
  2792. break;
  2793. default:
  2794. goto error_out;
  2795. }
  2796. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
  2797. reg_val = value;
  2798. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
  2799. reg_val = readl(ctl_reg);
  2800. reg_val |= value;
  2801. }
  2802. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  2803. reg_val = readl(ctl_reg);
  2804. reg_val &= ~value;
  2805. }
  2806. writel(reg_val, ctl_reg);
  2807. readl(ctl_reg); /* flush */
  2808. }
  2809. return nbytes;
  2810. error_out:
  2811. /* Clean out command structure on command error out */
  2812. memset(&idiag, 0, sizeof(idiag));
  2813. return -EINVAL;
  2814. }
  2815. /**
  2816. * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
  2817. * @phba: Pointer to HBA context object.
  2818. * @pbuffer: Pointer to data buffer.
  2819. *
  2820. * Description:
  2821. * This routine gets the driver mailbox access debugfs setup information.
  2822. *
  2823. * Returns:
  2824. * This function returns the amount of data that was read (this could be less
  2825. * than @nbytes if the end of the file was reached) or a negative error value.
  2826. **/
  2827. static int
  2828. lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
  2829. {
  2830. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  2831. int len = 0;
  2832. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  2833. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  2834. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  2835. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  2836. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2837. "mbx_dump_map: 0x%08x\n", mbx_dump_map);
  2838. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2839. "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
  2840. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2841. "mbx_word_cnt: %04d\n", mbx_word_cnt);
  2842. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2843. "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
  2844. return len;
  2845. }
  2846. /**
  2847. * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
  2848. * @file: The file pointer to read from.
  2849. * @buf: The buffer to copy the data to.
  2850. * @nbytes: The number of bytes to read.
  2851. * @ppos: The position in the file to start reading from.
  2852. *
  2853. * Description:
  2854. * This routine reads data from the @phba driver mailbox access debugfs setup
  2855. * information.
  2856. *
  2857. * Returns:
  2858. * This function returns the amount of data that was read (this could be less
  2859. * than @nbytes if the end of the file was reached) or a negative error value.
  2860. **/
  2861. static ssize_t
  2862. lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
  2863. loff_t *ppos)
  2864. {
  2865. struct lpfc_debug *debug = file->private_data;
  2866. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2867. char *pbuffer;
  2868. int len = 0;
  2869. /* This is a user read operation */
  2870. debug->op = LPFC_IDIAG_OP_RD;
  2871. if (!debug->buffer)
  2872. debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
  2873. if (!debug->buffer)
  2874. return 0;
  2875. pbuffer = debug->buffer;
  2876. if (*ppos)
  2877. return 0;
  2878. if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
  2879. (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
  2880. return 0;
  2881. len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
  2882. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2883. }
  2884. /**
  2885. * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
  2886. * @file: The file pointer to read from.
  2887. * @buf: The buffer to copy the user data from.
  2888. * @nbytes: The number of bytes to get.
  2889. * @ppos: The position in the file to start reading from.
  2890. *
  2891. * This routine get the debugfs idiag command struct from user space and then
  2892. * perform the syntax check for driver mailbox command (dump) and sets up the
  2893. * necessary states in the idiag command struct accordingly.
  2894. *
  2895. * It returns the @nbytges passing in from debugfs user space when successful.
  2896. * In case of error conditions, it returns proper error code back to the user
  2897. * space.
  2898. **/
  2899. static ssize_t
  2900. lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
  2901. size_t nbytes, loff_t *ppos)
  2902. {
  2903. struct lpfc_debug *debug = file->private_data;
  2904. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  2905. int rc;
  2906. /* This is a user write operation */
  2907. debug->op = LPFC_IDIAG_OP_WR;
  2908. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2909. if (rc < 0)
  2910. return rc;
  2911. /* Sanity check on command line arguments */
  2912. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  2913. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  2914. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  2915. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  2916. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
  2917. if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
  2918. goto error_out;
  2919. if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
  2920. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  2921. goto error_out;
  2922. if (mbx_word_cnt > sizeof(MAILBOX_t))
  2923. goto error_out;
  2924. } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
  2925. if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
  2926. goto error_out;
  2927. if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
  2928. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  2929. goto error_out;
  2930. if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
  2931. goto error_out;
  2932. if (mbx_mbox_cmd != 0x9b)
  2933. goto error_out;
  2934. } else
  2935. goto error_out;
  2936. if (mbx_word_cnt == 0)
  2937. goto error_out;
  2938. if (rc != LPFC_MBX_DMP_ARG)
  2939. goto error_out;
  2940. if (mbx_mbox_cmd & ~0xff)
  2941. goto error_out;
  2942. /* condition for stop mailbox dump */
  2943. if (mbx_dump_cnt == 0)
  2944. goto reset_out;
  2945. return nbytes;
  2946. reset_out:
  2947. /* Clean out command structure on command error out */
  2948. memset(&idiag, 0, sizeof(idiag));
  2949. return nbytes;
  2950. error_out:
  2951. /* Clean out command structure on command error out */
  2952. memset(&idiag, 0, sizeof(idiag));
  2953. return -EINVAL;
  2954. }
  2955. /**
  2956. * lpfc_idiag_extacc_avail_get - get the available extents information
  2957. * @phba: pointer to lpfc hba data structure.
  2958. * @pbuffer: pointer to internal buffer.
  2959. * @len: length into the internal buffer data has been copied.
  2960. *
  2961. * Description:
  2962. * This routine is to get the available extent information.
  2963. *
  2964. * Returns:
  2965. * overall lenth of the data read into the internal buffer.
  2966. **/
  2967. static int
  2968. lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
  2969. {
  2970. uint16_t ext_cnt, ext_size;
  2971. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2972. "\nAvailable Extents Information:\n");
  2973. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2974. "\tPort Available VPI extents: ");
  2975. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
  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 VFI extents: ");
  2981. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
  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. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2986. "\tPort Available RPI extents: ");
  2987. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
  2988. &ext_cnt, &ext_size);
  2989. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2990. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  2991. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2992. "\tPort Available XRI extents: ");
  2993. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
  2994. &ext_cnt, &ext_size);
  2995. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2996. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  2997. return len;
  2998. }
  2999. /**
  3000. * lpfc_idiag_extacc_alloc_get - get the allocated extents information
  3001. * @phba: pointer to lpfc hba data structure.
  3002. * @pbuffer: pointer to internal buffer.
  3003. * @len: length into the internal buffer data has been copied.
  3004. *
  3005. * Description:
  3006. * This routine is to get the allocated extent information.
  3007. *
  3008. * Returns:
  3009. * overall lenth of the data read into the internal buffer.
  3010. **/
  3011. static int
  3012. lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
  3013. {
  3014. uint16_t ext_cnt, ext_size;
  3015. int rc;
  3016. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3017. "\nAllocated Extents Information:\n");
  3018. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3019. "\tHost Allocated VPI extents: ");
  3020. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
  3021. &ext_cnt, &ext_size);
  3022. if (!rc)
  3023. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3024. "Port %d Extent %3d, Size %3d\n",
  3025. phba->brd_no, ext_cnt, ext_size);
  3026. else
  3027. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3028. "N/A\n");
  3029. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3030. "\tHost Allocated VFI extents: ");
  3031. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
  3032. &ext_cnt, &ext_size);
  3033. if (!rc)
  3034. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3035. "Port %d Extent %3d, Size %3d\n",
  3036. phba->brd_no, ext_cnt, ext_size);
  3037. else
  3038. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3039. "N/A\n");
  3040. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3041. "\tHost Allocated RPI extents: ");
  3042. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
  3043. &ext_cnt, &ext_size);
  3044. if (!rc)
  3045. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3046. "Port %d Extent %3d, Size %3d\n",
  3047. phba->brd_no, ext_cnt, ext_size);
  3048. else
  3049. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3050. "N/A\n");
  3051. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3052. "\tHost Allocated XRI extents: ");
  3053. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
  3054. &ext_cnt, &ext_size);
  3055. if (!rc)
  3056. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3057. "Port %d Extent %3d, Size %3d\n",
  3058. phba->brd_no, ext_cnt, ext_size);
  3059. else
  3060. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3061. "N/A\n");
  3062. return len;
  3063. }
  3064. /**
  3065. * lpfc_idiag_extacc_drivr_get - get driver extent information
  3066. * @phba: pointer to lpfc hba data structure.
  3067. * @pbuffer: pointer to internal buffer.
  3068. * @len: length into the internal buffer data has been copied.
  3069. *
  3070. * Description:
  3071. * This routine is to get the driver extent information.
  3072. *
  3073. * Returns:
  3074. * overall lenth of the data read into the internal buffer.
  3075. **/
  3076. static int
  3077. lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
  3078. {
  3079. struct lpfc_rsrc_blks *rsrc_blks;
  3080. int index;
  3081. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3082. "\nDriver Extents Information:\n");
  3083. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3084. "\tVPI extents:\n");
  3085. index = 0;
  3086. list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
  3087. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3088. "\t\tBlock %3d: Start %4d, Count %4d\n",
  3089. index, rsrc_blks->rsrc_start,
  3090. rsrc_blks->rsrc_size);
  3091. index++;
  3092. }
  3093. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3094. "\tVFI extents:\n");
  3095. index = 0;
  3096. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
  3097. list) {
  3098. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3099. "\t\tBlock %3d: Start %4d, Count %4d\n",
  3100. index, rsrc_blks->rsrc_start,
  3101. rsrc_blks->rsrc_size);
  3102. index++;
  3103. }
  3104. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3105. "\tRPI extents:\n");
  3106. index = 0;
  3107. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
  3108. list) {
  3109. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3110. "\t\tBlock %3d: Start %4d, Count %4d\n",
  3111. index, rsrc_blks->rsrc_start,
  3112. rsrc_blks->rsrc_size);
  3113. index++;
  3114. }
  3115. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3116. "\tXRI extents:\n");
  3117. index = 0;
  3118. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
  3119. list) {
  3120. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  3121. "\t\tBlock %3d: Start %4d, Count %4d\n",
  3122. index, rsrc_blks->rsrc_start,
  3123. rsrc_blks->rsrc_size);
  3124. index++;
  3125. }
  3126. return len;
  3127. }
  3128. /**
  3129. * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
  3130. * @file: The file pointer to read from.
  3131. * @buf: The buffer to copy the user data from.
  3132. * @nbytes: The number of bytes to get.
  3133. * @ppos: The position in the file to start reading from.
  3134. *
  3135. * This routine get the debugfs idiag command struct from user space and then
  3136. * perform the syntax check for extent information access commands and sets
  3137. * up the necessary states in the idiag command struct accordingly.
  3138. *
  3139. * It returns the @nbytges passing in from debugfs user space when successful.
  3140. * In case of error conditions, it returns proper error code back to the user
  3141. * space.
  3142. **/
  3143. static ssize_t
  3144. lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
  3145. size_t nbytes, loff_t *ppos)
  3146. {
  3147. struct lpfc_debug *debug = file->private_data;
  3148. uint32_t ext_map;
  3149. int rc;
  3150. /* This is a user write operation */
  3151. debug->op = LPFC_IDIAG_OP_WR;
  3152. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  3153. if (rc < 0)
  3154. return rc;
  3155. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  3156. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  3157. goto error_out;
  3158. if (rc != LPFC_EXT_ACC_CMD_ARG)
  3159. goto error_out;
  3160. if (!(ext_map & LPFC_EXT_ACC_ALL))
  3161. goto error_out;
  3162. return nbytes;
  3163. error_out:
  3164. /* Clean out command structure on command error out */
  3165. memset(&idiag, 0, sizeof(idiag));
  3166. return -EINVAL;
  3167. }
  3168. /**
  3169. * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
  3170. * @file: The file pointer to read from.
  3171. * @buf: The buffer to copy the data to.
  3172. * @nbytes: The number of bytes to read.
  3173. * @ppos: The position in the file to start reading from.
  3174. *
  3175. * Description:
  3176. * This routine reads data from the proper extent information according to
  3177. * the idiag command, and copies to user @buf.
  3178. *
  3179. * Returns:
  3180. * This function returns the amount of data that was read (this could be less
  3181. * than @nbytes if the end of the file was reached) or a negative error value.
  3182. **/
  3183. static ssize_t
  3184. lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
  3185. loff_t *ppos)
  3186. {
  3187. struct lpfc_debug *debug = file->private_data;
  3188. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3189. char *pbuffer;
  3190. uint32_t ext_map;
  3191. int len = 0;
  3192. /* This is a user read operation */
  3193. debug->op = LPFC_IDIAG_OP_RD;
  3194. if (!debug->buffer)
  3195. debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
  3196. if (!debug->buffer)
  3197. return 0;
  3198. pbuffer = debug->buffer;
  3199. if (*ppos)
  3200. return 0;
  3201. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  3202. return 0;
  3203. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  3204. if (ext_map & LPFC_EXT_ACC_AVAIL)
  3205. len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
  3206. if (ext_map & LPFC_EXT_ACC_ALLOC)
  3207. len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
  3208. if (ext_map & LPFC_EXT_ACC_DRIVR)
  3209. len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
  3210. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3211. }
  3212. #undef lpfc_debugfs_op_disc_trc
  3213. static const struct file_operations lpfc_debugfs_op_disc_trc = {
  3214. .owner = THIS_MODULE,
  3215. .open = lpfc_debugfs_disc_trc_open,
  3216. .llseek = lpfc_debugfs_lseek,
  3217. .read = lpfc_debugfs_read,
  3218. .release = lpfc_debugfs_release,
  3219. };
  3220. #undef lpfc_debugfs_op_nodelist
  3221. static const struct file_operations lpfc_debugfs_op_nodelist = {
  3222. .owner = THIS_MODULE,
  3223. .open = lpfc_debugfs_nodelist_open,
  3224. .llseek = lpfc_debugfs_lseek,
  3225. .read = lpfc_debugfs_read,
  3226. .release = lpfc_debugfs_release,
  3227. };
  3228. #undef lpfc_debugfs_op_hbqinfo
  3229. static const struct file_operations lpfc_debugfs_op_hbqinfo = {
  3230. .owner = THIS_MODULE,
  3231. .open = lpfc_debugfs_hbqinfo_open,
  3232. .llseek = lpfc_debugfs_lseek,
  3233. .read = lpfc_debugfs_read,
  3234. .release = lpfc_debugfs_release,
  3235. };
  3236. #undef lpfc_debugfs_op_dumpHBASlim
  3237. static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  3238. .owner = THIS_MODULE,
  3239. .open = lpfc_debugfs_dumpHBASlim_open,
  3240. .llseek = lpfc_debugfs_lseek,
  3241. .read = lpfc_debugfs_read,
  3242. .release = lpfc_debugfs_release,
  3243. };
  3244. #undef lpfc_debugfs_op_dumpHostSlim
  3245. static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  3246. .owner = THIS_MODULE,
  3247. .open = lpfc_debugfs_dumpHostSlim_open,
  3248. .llseek = lpfc_debugfs_lseek,
  3249. .read = lpfc_debugfs_read,
  3250. .release = lpfc_debugfs_release,
  3251. };
  3252. #undef lpfc_debugfs_op_dumpData
  3253. static const struct file_operations lpfc_debugfs_op_dumpData = {
  3254. .owner = THIS_MODULE,
  3255. .open = lpfc_debugfs_dumpData_open,
  3256. .llseek = lpfc_debugfs_lseek,
  3257. .read = lpfc_debugfs_read,
  3258. .write = lpfc_debugfs_dumpDataDif_write,
  3259. .release = lpfc_debugfs_dumpDataDif_release,
  3260. };
  3261. #undef lpfc_debugfs_op_dumpDif
  3262. static const struct file_operations lpfc_debugfs_op_dumpDif = {
  3263. .owner = THIS_MODULE,
  3264. .open = lpfc_debugfs_dumpDif_open,
  3265. .llseek = lpfc_debugfs_lseek,
  3266. .read = lpfc_debugfs_read,
  3267. .write = lpfc_debugfs_dumpDataDif_write,
  3268. .release = lpfc_debugfs_dumpDataDif_release,
  3269. };
  3270. #undef lpfc_debugfs_op_dif_err
  3271. static const struct file_operations lpfc_debugfs_op_dif_err = {
  3272. .owner = THIS_MODULE,
  3273. .open = simple_open,
  3274. .llseek = lpfc_debugfs_lseek,
  3275. .read = lpfc_debugfs_dif_err_read,
  3276. .write = lpfc_debugfs_dif_err_write,
  3277. .release = lpfc_debugfs_dif_err_release,
  3278. };
  3279. #undef lpfc_debugfs_op_slow_ring_trc
  3280. static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  3281. .owner = THIS_MODULE,
  3282. .open = lpfc_debugfs_slow_ring_trc_open,
  3283. .llseek = lpfc_debugfs_lseek,
  3284. .read = lpfc_debugfs_read,
  3285. .release = lpfc_debugfs_release,
  3286. };
  3287. static struct dentry *lpfc_debugfs_root = NULL;
  3288. static atomic_t lpfc_debugfs_hba_count;
  3289. /*
  3290. * File operations for the iDiag debugfs
  3291. */
  3292. #undef lpfc_idiag_op_pciCfg
  3293. static const struct file_operations lpfc_idiag_op_pciCfg = {
  3294. .owner = THIS_MODULE,
  3295. .open = lpfc_idiag_open,
  3296. .llseek = lpfc_debugfs_lseek,
  3297. .read = lpfc_idiag_pcicfg_read,
  3298. .write = lpfc_idiag_pcicfg_write,
  3299. .release = lpfc_idiag_cmd_release,
  3300. };
  3301. #undef lpfc_idiag_op_barAcc
  3302. static const struct file_operations lpfc_idiag_op_barAcc = {
  3303. .owner = THIS_MODULE,
  3304. .open = lpfc_idiag_open,
  3305. .llseek = lpfc_debugfs_lseek,
  3306. .read = lpfc_idiag_baracc_read,
  3307. .write = lpfc_idiag_baracc_write,
  3308. .release = lpfc_idiag_cmd_release,
  3309. };
  3310. #undef lpfc_idiag_op_queInfo
  3311. static const struct file_operations lpfc_idiag_op_queInfo = {
  3312. .owner = THIS_MODULE,
  3313. .open = lpfc_idiag_open,
  3314. .read = lpfc_idiag_queinfo_read,
  3315. .release = lpfc_idiag_release,
  3316. };
  3317. #undef lpfc_idiag_op_queAcc
  3318. static const struct file_operations lpfc_idiag_op_queAcc = {
  3319. .owner = THIS_MODULE,
  3320. .open = lpfc_idiag_open,
  3321. .llseek = lpfc_debugfs_lseek,
  3322. .read = lpfc_idiag_queacc_read,
  3323. .write = lpfc_idiag_queacc_write,
  3324. .release = lpfc_idiag_cmd_release,
  3325. };
  3326. #undef lpfc_idiag_op_drbAcc
  3327. static const struct file_operations lpfc_idiag_op_drbAcc = {
  3328. .owner = THIS_MODULE,
  3329. .open = lpfc_idiag_open,
  3330. .llseek = lpfc_debugfs_lseek,
  3331. .read = lpfc_idiag_drbacc_read,
  3332. .write = lpfc_idiag_drbacc_write,
  3333. .release = lpfc_idiag_cmd_release,
  3334. };
  3335. #undef lpfc_idiag_op_ctlAcc
  3336. static const struct file_operations lpfc_idiag_op_ctlAcc = {
  3337. .owner = THIS_MODULE,
  3338. .open = lpfc_idiag_open,
  3339. .llseek = lpfc_debugfs_lseek,
  3340. .read = lpfc_idiag_ctlacc_read,
  3341. .write = lpfc_idiag_ctlacc_write,
  3342. .release = lpfc_idiag_cmd_release,
  3343. };
  3344. #undef lpfc_idiag_op_mbxAcc
  3345. static const struct file_operations lpfc_idiag_op_mbxAcc = {
  3346. .owner = THIS_MODULE,
  3347. .open = lpfc_idiag_open,
  3348. .llseek = lpfc_debugfs_lseek,
  3349. .read = lpfc_idiag_mbxacc_read,
  3350. .write = lpfc_idiag_mbxacc_write,
  3351. .release = lpfc_idiag_cmd_release,
  3352. };
  3353. #undef lpfc_idiag_op_extAcc
  3354. static const struct file_operations lpfc_idiag_op_extAcc = {
  3355. .owner = THIS_MODULE,
  3356. .open = lpfc_idiag_open,
  3357. .llseek = lpfc_debugfs_lseek,
  3358. .read = lpfc_idiag_extacc_read,
  3359. .write = lpfc_idiag_extacc_write,
  3360. .release = lpfc_idiag_cmd_release,
  3361. };
  3362. #endif
  3363. /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
  3364. * @phba: Pointer to HBA context object.
  3365. * @dmabuf: Pointer to a DMA buffer descriptor.
  3366. *
  3367. * Description:
  3368. * This routine dump a bsg pass-through non-embedded mailbox command with
  3369. * external buffer.
  3370. **/
  3371. void
  3372. lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
  3373. enum mbox_type mbox_tp, enum dma_type dma_tp,
  3374. enum sta_type sta_tp,
  3375. struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
  3376. {
  3377. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3378. uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
  3379. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  3380. int len = 0;
  3381. uint32_t do_dump = 0;
  3382. uint32_t *pword;
  3383. uint32_t i;
  3384. if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
  3385. return;
  3386. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  3387. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  3388. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  3389. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  3390. if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
  3391. (*mbx_dump_cnt == 0) ||
  3392. (*mbx_word_cnt == 0))
  3393. return;
  3394. if (*mbx_mbox_cmd != 0x9B)
  3395. return;
  3396. if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
  3397. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
  3398. do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
  3399. printk(KERN_ERR "\nRead mbox command (x%x), "
  3400. "nemb:0x%x, extbuf_cnt:%d:\n",
  3401. sta_tp, nemb_tp, ext_buf);
  3402. }
  3403. }
  3404. if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
  3405. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
  3406. do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
  3407. printk(KERN_ERR "\nRead mbox buffer (x%x), "
  3408. "nemb:0x%x, extbuf_seq:%d:\n",
  3409. sta_tp, nemb_tp, ext_buf);
  3410. }
  3411. }
  3412. if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
  3413. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
  3414. do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
  3415. printk(KERN_ERR "\nWrite mbox command (x%x), "
  3416. "nemb:0x%x, extbuf_cnt:%d:\n",
  3417. sta_tp, nemb_tp, ext_buf);
  3418. }
  3419. }
  3420. if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
  3421. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
  3422. do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
  3423. printk(KERN_ERR "\nWrite mbox buffer (x%x), "
  3424. "nemb:0x%x, extbuf_seq:%d:\n",
  3425. sta_tp, nemb_tp, ext_buf);
  3426. }
  3427. }
  3428. /* dump buffer content */
  3429. if (do_dump) {
  3430. pword = (uint32_t *)dmabuf->virt;
  3431. for (i = 0; i < *mbx_word_cnt; i++) {
  3432. if (!(i % 8)) {
  3433. if (i != 0)
  3434. printk(KERN_ERR "%s\n", line_buf);
  3435. len = 0;
  3436. len += snprintf(line_buf+len,
  3437. LPFC_MBX_ACC_LBUF_SZ-len,
  3438. "%03d: ", i);
  3439. }
  3440. len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  3441. "%08x ", (uint32_t)*pword);
  3442. pword++;
  3443. }
  3444. if ((i - 1) % 8)
  3445. printk(KERN_ERR "%s\n", line_buf);
  3446. (*mbx_dump_cnt)--;
  3447. }
  3448. /* Clean out command structure on reaching dump count */
  3449. if (*mbx_dump_cnt == 0)
  3450. memset(&idiag, 0, sizeof(idiag));
  3451. return;
  3452. #endif
  3453. }
  3454. /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
  3455. * @phba: Pointer to HBA context object.
  3456. * @dmabuf: Pointer to a DMA buffer descriptor.
  3457. *
  3458. * Description:
  3459. * This routine dump a pass-through non-embedded mailbox command from issue
  3460. * mailbox command.
  3461. **/
  3462. void
  3463. lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
  3464. {
  3465. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3466. uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
  3467. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  3468. int len = 0;
  3469. uint32_t *pword;
  3470. uint8_t *pbyte;
  3471. uint32_t i, j;
  3472. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
  3473. return;
  3474. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  3475. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  3476. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  3477. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  3478. if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
  3479. (*mbx_dump_cnt == 0) ||
  3480. (*mbx_word_cnt == 0))
  3481. return;
  3482. if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
  3483. (*mbx_mbox_cmd != pmbox->mbxCommand))
  3484. return;
  3485. /* dump buffer content */
  3486. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
  3487. printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
  3488. pmbox->mbxCommand);
  3489. pword = (uint32_t *)pmbox;
  3490. for (i = 0; i < *mbx_word_cnt; i++) {
  3491. if (!(i % 8)) {
  3492. if (i != 0)
  3493. printk(KERN_ERR "%s\n", line_buf);
  3494. len = 0;
  3495. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  3496. len += snprintf(line_buf+len,
  3497. LPFC_MBX_ACC_LBUF_SZ-len,
  3498. "%03d: ", i);
  3499. }
  3500. len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  3501. "%08x ",
  3502. ((uint32_t)*pword) & 0xffffffff);
  3503. pword++;
  3504. }
  3505. if ((i - 1) % 8)
  3506. printk(KERN_ERR "%s\n", line_buf);
  3507. printk(KERN_ERR "\n");
  3508. }
  3509. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
  3510. printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
  3511. pmbox->mbxCommand);
  3512. pbyte = (uint8_t *)pmbox;
  3513. for (i = 0; i < *mbx_word_cnt; i++) {
  3514. if (!(i % 8)) {
  3515. if (i != 0)
  3516. printk(KERN_ERR "%s\n", line_buf);
  3517. len = 0;
  3518. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  3519. len += snprintf(line_buf+len,
  3520. LPFC_MBX_ACC_LBUF_SZ-len,
  3521. "%03d: ", i);
  3522. }
  3523. for (j = 0; j < 4; j++) {
  3524. len += snprintf(line_buf+len,
  3525. LPFC_MBX_ACC_LBUF_SZ-len,
  3526. "%02x",
  3527. ((uint8_t)*pbyte) & 0xff);
  3528. pbyte++;
  3529. }
  3530. len += snprintf(line_buf+len,
  3531. LPFC_MBX_ACC_LBUF_SZ-len, " ");
  3532. }
  3533. if ((i - 1) % 8)
  3534. printk(KERN_ERR "%s\n", line_buf);
  3535. printk(KERN_ERR "\n");
  3536. }
  3537. (*mbx_dump_cnt)--;
  3538. /* Clean out command structure on reaching dump count */
  3539. if (*mbx_dump_cnt == 0)
  3540. memset(&idiag, 0, sizeof(idiag));
  3541. return;
  3542. #endif
  3543. }
  3544. /**
  3545. * lpfc_debugfs_initialize - Initialize debugfs for a vport
  3546. * @vport: The vport pointer to initialize.
  3547. *
  3548. * Description:
  3549. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  3550. * If not already created, this routine will create the lpfc directory, and
  3551. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  3552. * also create each file used to access lpfc specific debugfs information.
  3553. **/
  3554. inline void
  3555. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  3556. {
  3557. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3558. struct lpfc_hba *phba = vport->phba;
  3559. char name[64];
  3560. uint32_t num, i;
  3561. if (!lpfc_debugfs_enable)
  3562. return;
  3563. /* Setup lpfc root directory */
  3564. if (!lpfc_debugfs_root) {
  3565. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  3566. atomic_set(&lpfc_debugfs_hba_count, 0);
  3567. if (!lpfc_debugfs_root) {
  3568. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3569. "0408 Cannot create debugfs root\n");
  3570. goto debug_failed;
  3571. }
  3572. }
  3573. if (!lpfc_debugfs_start_time)
  3574. lpfc_debugfs_start_time = jiffies;
  3575. /* Setup funcX directory for specific HBA PCI function */
  3576. snprintf(name, sizeof(name), "fn%d", phba->brd_no);
  3577. if (!phba->hba_debugfs_root) {
  3578. phba->hba_debugfs_root =
  3579. debugfs_create_dir(name, lpfc_debugfs_root);
  3580. if (!phba->hba_debugfs_root) {
  3581. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3582. "0412 Cannot create debugfs hba\n");
  3583. goto debug_failed;
  3584. }
  3585. atomic_inc(&lpfc_debugfs_hba_count);
  3586. atomic_set(&phba->debugfs_vport_count, 0);
  3587. /* Setup hbqinfo */
  3588. snprintf(name, sizeof(name), "hbqinfo");
  3589. phba->debug_hbqinfo =
  3590. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3591. phba->hba_debugfs_root,
  3592. phba, &lpfc_debugfs_op_hbqinfo);
  3593. if (!phba->debug_hbqinfo) {
  3594. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3595. "0411 Cannot create debugfs hbqinfo\n");
  3596. goto debug_failed;
  3597. }
  3598. /* Setup dumpHBASlim */
  3599. if (phba->sli_rev < LPFC_SLI_REV4) {
  3600. snprintf(name, sizeof(name), "dumpHBASlim");
  3601. phba->debug_dumpHBASlim =
  3602. debugfs_create_file(name,
  3603. S_IFREG|S_IRUGO|S_IWUSR,
  3604. phba->hba_debugfs_root,
  3605. phba, &lpfc_debugfs_op_dumpHBASlim);
  3606. if (!phba->debug_dumpHBASlim) {
  3607. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3608. "0413 Cannot create debugfs "
  3609. "dumpHBASlim\n");
  3610. goto debug_failed;
  3611. }
  3612. } else
  3613. phba->debug_dumpHBASlim = NULL;
  3614. /* Setup dumpHostSlim */
  3615. if (phba->sli_rev < LPFC_SLI_REV4) {
  3616. snprintf(name, sizeof(name), "dumpHostSlim");
  3617. phba->debug_dumpHostSlim =
  3618. debugfs_create_file(name,
  3619. S_IFREG|S_IRUGO|S_IWUSR,
  3620. phba->hba_debugfs_root,
  3621. phba, &lpfc_debugfs_op_dumpHostSlim);
  3622. if (!phba->debug_dumpHostSlim) {
  3623. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3624. "0414 Cannot create debugfs "
  3625. "dumpHostSlim\n");
  3626. goto debug_failed;
  3627. }
  3628. } else
  3629. phba->debug_dumpHBASlim = NULL;
  3630. /* Setup dumpData */
  3631. snprintf(name, sizeof(name), "dumpData");
  3632. phba->debug_dumpData =
  3633. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3634. phba->hba_debugfs_root,
  3635. phba, &lpfc_debugfs_op_dumpData);
  3636. if (!phba->debug_dumpData) {
  3637. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3638. "0800 Cannot create debugfs dumpData\n");
  3639. goto debug_failed;
  3640. }
  3641. /* Setup dumpDif */
  3642. snprintf(name, sizeof(name), "dumpDif");
  3643. phba->debug_dumpDif =
  3644. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3645. phba->hba_debugfs_root,
  3646. phba, &lpfc_debugfs_op_dumpDif);
  3647. if (!phba->debug_dumpDif) {
  3648. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3649. "0801 Cannot create debugfs dumpDif\n");
  3650. goto debug_failed;
  3651. }
  3652. /* Setup DIF Error Injections */
  3653. snprintf(name, sizeof(name), "InjErrLBA");
  3654. phba->debug_InjErrLBA =
  3655. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3656. phba->hba_debugfs_root,
  3657. phba, &lpfc_debugfs_op_dif_err);
  3658. if (!phba->debug_InjErrLBA) {
  3659. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3660. "0807 Cannot create debugfs InjErrLBA\n");
  3661. goto debug_failed;
  3662. }
  3663. phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
  3664. snprintf(name, sizeof(name), "InjErrNPortID");
  3665. phba->debug_InjErrNPortID =
  3666. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3667. phba->hba_debugfs_root,
  3668. phba, &lpfc_debugfs_op_dif_err);
  3669. if (!phba->debug_InjErrNPortID) {
  3670. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3671. "0809 Cannot create debugfs InjErrNPortID\n");
  3672. goto debug_failed;
  3673. }
  3674. snprintf(name, sizeof(name), "InjErrWWPN");
  3675. phba->debug_InjErrWWPN =
  3676. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3677. phba->hba_debugfs_root,
  3678. phba, &lpfc_debugfs_op_dif_err);
  3679. if (!phba->debug_InjErrWWPN) {
  3680. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3681. "0810 Cannot create debugfs InjErrWWPN\n");
  3682. goto debug_failed;
  3683. }
  3684. snprintf(name, sizeof(name), "writeGuardInjErr");
  3685. phba->debug_writeGuard =
  3686. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3687. phba->hba_debugfs_root,
  3688. phba, &lpfc_debugfs_op_dif_err);
  3689. if (!phba->debug_writeGuard) {
  3690. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3691. "0802 Cannot create debugfs writeGuard\n");
  3692. goto debug_failed;
  3693. }
  3694. snprintf(name, sizeof(name), "writeAppInjErr");
  3695. phba->debug_writeApp =
  3696. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3697. phba->hba_debugfs_root,
  3698. phba, &lpfc_debugfs_op_dif_err);
  3699. if (!phba->debug_writeApp) {
  3700. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3701. "0803 Cannot create debugfs writeApp\n");
  3702. goto debug_failed;
  3703. }
  3704. snprintf(name, sizeof(name), "writeRefInjErr");
  3705. phba->debug_writeRef =
  3706. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3707. phba->hba_debugfs_root,
  3708. phba, &lpfc_debugfs_op_dif_err);
  3709. if (!phba->debug_writeRef) {
  3710. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3711. "0804 Cannot create debugfs writeRef\n");
  3712. goto debug_failed;
  3713. }
  3714. snprintf(name, sizeof(name), "readGuardInjErr");
  3715. phba->debug_readGuard =
  3716. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3717. phba->hba_debugfs_root,
  3718. phba, &lpfc_debugfs_op_dif_err);
  3719. if (!phba->debug_readGuard) {
  3720. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3721. "0808 Cannot create debugfs readGuard\n");
  3722. goto debug_failed;
  3723. }
  3724. snprintf(name, sizeof(name), "readAppInjErr");
  3725. phba->debug_readApp =
  3726. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3727. phba->hba_debugfs_root,
  3728. phba, &lpfc_debugfs_op_dif_err);
  3729. if (!phba->debug_readApp) {
  3730. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3731. "0805 Cannot create debugfs readApp\n");
  3732. goto debug_failed;
  3733. }
  3734. snprintf(name, sizeof(name), "readRefInjErr");
  3735. phba->debug_readRef =
  3736. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3737. phba->hba_debugfs_root,
  3738. phba, &lpfc_debugfs_op_dif_err);
  3739. if (!phba->debug_readRef) {
  3740. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3741. "0806 Cannot create debugfs readApp\n");
  3742. goto debug_failed;
  3743. }
  3744. /* Setup slow ring trace */
  3745. if (lpfc_debugfs_max_slow_ring_trc) {
  3746. num = lpfc_debugfs_max_slow_ring_trc - 1;
  3747. if (num & lpfc_debugfs_max_slow_ring_trc) {
  3748. /* Change to be a power of 2 */
  3749. num = lpfc_debugfs_max_slow_ring_trc;
  3750. i = 0;
  3751. while (num > 1) {
  3752. num = num >> 1;
  3753. i++;
  3754. }
  3755. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  3756. printk(KERN_ERR
  3757. "lpfc_debugfs_max_disc_trc changed to "
  3758. "%d\n", lpfc_debugfs_max_disc_trc);
  3759. }
  3760. }
  3761. snprintf(name, sizeof(name), "slow_ring_trace");
  3762. phba->debug_slow_ring_trc =
  3763. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3764. phba->hba_debugfs_root,
  3765. phba, &lpfc_debugfs_op_slow_ring_trc);
  3766. if (!phba->debug_slow_ring_trc) {
  3767. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3768. "0415 Cannot create debugfs "
  3769. "slow_ring_trace\n");
  3770. goto debug_failed;
  3771. }
  3772. if (!phba->slow_ring_trc) {
  3773. phba->slow_ring_trc = kmalloc(
  3774. (sizeof(struct lpfc_debugfs_trc) *
  3775. lpfc_debugfs_max_slow_ring_trc),
  3776. GFP_KERNEL);
  3777. if (!phba->slow_ring_trc) {
  3778. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3779. "0416 Cannot create debugfs "
  3780. "slow_ring buffer\n");
  3781. goto debug_failed;
  3782. }
  3783. atomic_set(&phba->slow_ring_trc_cnt, 0);
  3784. memset(phba->slow_ring_trc, 0,
  3785. (sizeof(struct lpfc_debugfs_trc) *
  3786. lpfc_debugfs_max_slow_ring_trc));
  3787. }
  3788. }
  3789. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  3790. if (!vport->vport_debugfs_root) {
  3791. vport->vport_debugfs_root =
  3792. debugfs_create_dir(name, phba->hba_debugfs_root);
  3793. if (!vport->vport_debugfs_root) {
  3794. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3795. "0417 Can't create debugfs\n");
  3796. goto debug_failed;
  3797. }
  3798. atomic_inc(&phba->debugfs_vport_count);
  3799. }
  3800. if (lpfc_debugfs_max_disc_trc) {
  3801. num = lpfc_debugfs_max_disc_trc - 1;
  3802. if (num & lpfc_debugfs_max_disc_trc) {
  3803. /* Change to be a power of 2 */
  3804. num = lpfc_debugfs_max_disc_trc;
  3805. i = 0;
  3806. while (num > 1) {
  3807. num = num >> 1;
  3808. i++;
  3809. }
  3810. lpfc_debugfs_max_disc_trc = (1 << i);
  3811. printk(KERN_ERR
  3812. "lpfc_debugfs_max_disc_trc changed to %d\n",
  3813. lpfc_debugfs_max_disc_trc);
  3814. }
  3815. }
  3816. vport->disc_trc = kzalloc(
  3817. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  3818. GFP_KERNEL);
  3819. if (!vport->disc_trc) {
  3820. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3821. "0418 Cannot create debugfs disc trace "
  3822. "buffer\n");
  3823. goto debug_failed;
  3824. }
  3825. atomic_set(&vport->disc_trc_cnt, 0);
  3826. snprintf(name, sizeof(name), "discovery_trace");
  3827. vport->debug_disc_trc =
  3828. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3829. vport->vport_debugfs_root,
  3830. vport, &lpfc_debugfs_op_disc_trc);
  3831. if (!vport->debug_disc_trc) {
  3832. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3833. "0419 Cannot create debugfs "
  3834. "discovery_trace\n");
  3835. goto debug_failed;
  3836. }
  3837. snprintf(name, sizeof(name), "nodelist");
  3838. vport->debug_nodelist =
  3839. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3840. vport->vport_debugfs_root,
  3841. vport, &lpfc_debugfs_op_nodelist);
  3842. if (!vport->debug_nodelist) {
  3843. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3844. "2985 Can't create debugfs nodelist\n");
  3845. goto debug_failed;
  3846. }
  3847. /*
  3848. * iDiag debugfs root entry points for SLI4 device only
  3849. */
  3850. if (phba->sli_rev < LPFC_SLI_REV4)
  3851. goto debug_failed;
  3852. snprintf(name, sizeof(name), "iDiag");
  3853. if (!phba->idiag_root) {
  3854. phba->idiag_root =
  3855. debugfs_create_dir(name, phba->hba_debugfs_root);
  3856. if (!phba->idiag_root) {
  3857. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3858. "2922 Can't create idiag debugfs\n");
  3859. goto debug_failed;
  3860. }
  3861. /* Initialize iDiag data structure */
  3862. memset(&idiag, 0, sizeof(idiag));
  3863. }
  3864. /* iDiag read PCI config space */
  3865. snprintf(name, sizeof(name), "pciCfg");
  3866. if (!phba->idiag_pci_cfg) {
  3867. phba->idiag_pci_cfg =
  3868. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3869. phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
  3870. if (!phba->idiag_pci_cfg) {
  3871. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3872. "2923 Can't create idiag debugfs\n");
  3873. goto debug_failed;
  3874. }
  3875. idiag.offset.last_rd = 0;
  3876. }
  3877. /* iDiag PCI BAR access */
  3878. snprintf(name, sizeof(name), "barAcc");
  3879. if (!phba->idiag_bar_acc) {
  3880. phba->idiag_bar_acc =
  3881. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3882. phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
  3883. if (!phba->idiag_bar_acc) {
  3884. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3885. "3056 Can't create idiag debugfs\n");
  3886. goto debug_failed;
  3887. }
  3888. idiag.offset.last_rd = 0;
  3889. }
  3890. /* iDiag get PCI function queue information */
  3891. snprintf(name, sizeof(name), "queInfo");
  3892. if (!phba->idiag_que_info) {
  3893. phba->idiag_que_info =
  3894. debugfs_create_file(name, S_IFREG|S_IRUGO,
  3895. phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
  3896. if (!phba->idiag_que_info) {
  3897. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3898. "2924 Can't create idiag debugfs\n");
  3899. goto debug_failed;
  3900. }
  3901. }
  3902. /* iDiag access PCI function queue */
  3903. snprintf(name, sizeof(name), "queAcc");
  3904. if (!phba->idiag_que_acc) {
  3905. phba->idiag_que_acc =
  3906. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3907. phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
  3908. if (!phba->idiag_que_acc) {
  3909. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3910. "2926 Can't create idiag debugfs\n");
  3911. goto debug_failed;
  3912. }
  3913. }
  3914. /* iDiag access PCI function doorbell registers */
  3915. snprintf(name, sizeof(name), "drbAcc");
  3916. if (!phba->idiag_drb_acc) {
  3917. phba->idiag_drb_acc =
  3918. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3919. phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
  3920. if (!phba->idiag_drb_acc) {
  3921. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3922. "2927 Can't create idiag debugfs\n");
  3923. goto debug_failed;
  3924. }
  3925. }
  3926. /* iDiag access PCI function control registers */
  3927. snprintf(name, sizeof(name), "ctlAcc");
  3928. if (!phba->idiag_ctl_acc) {
  3929. phba->idiag_ctl_acc =
  3930. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3931. phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
  3932. if (!phba->idiag_ctl_acc) {
  3933. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3934. "2981 Can't create idiag debugfs\n");
  3935. goto debug_failed;
  3936. }
  3937. }
  3938. /* iDiag access mbox commands */
  3939. snprintf(name, sizeof(name), "mbxAcc");
  3940. if (!phba->idiag_mbx_acc) {
  3941. phba->idiag_mbx_acc =
  3942. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3943. phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
  3944. if (!phba->idiag_mbx_acc) {
  3945. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3946. "2980 Can't create idiag debugfs\n");
  3947. goto debug_failed;
  3948. }
  3949. }
  3950. /* iDiag extents access commands */
  3951. if (phba->sli4_hba.extents_in_use) {
  3952. snprintf(name, sizeof(name), "extAcc");
  3953. if (!phba->idiag_ext_acc) {
  3954. phba->idiag_ext_acc =
  3955. debugfs_create_file(name,
  3956. S_IFREG|S_IRUGO|S_IWUSR,
  3957. phba->idiag_root, phba,
  3958. &lpfc_idiag_op_extAcc);
  3959. if (!phba->idiag_ext_acc) {
  3960. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3961. "2986 Cant create "
  3962. "idiag debugfs\n");
  3963. goto debug_failed;
  3964. }
  3965. }
  3966. }
  3967. debug_failed:
  3968. return;
  3969. #endif
  3970. }
  3971. /**
  3972. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
  3973. * @vport: The vport pointer to remove from debugfs.
  3974. *
  3975. * Description:
  3976. * When Debugfs is configured this routine removes debugfs file system elements
  3977. * that are specific to this vport. It also checks to see if there are any
  3978. * users left for the debugfs directories associated with the HBA and driver. If
  3979. * this is the last user of the HBA directory or driver directory then it will
  3980. * remove those from the debugfs infrastructure as well.
  3981. **/
  3982. inline void
  3983. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  3984. {
  3985. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3986. struct lpfc_hba *phba = vport->phba;
  3987. if (vport->disc_trc) {
  3988. kfree(vport->disc_trc);
  3989. vport->disc_trc = NULL;
  3990. }
  3991. if (vport->debug_disc_trc) {
  3992. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  3993. vport->debug_disc_trc = NULL;
  3994. }
  3995. if (vport->debug_nodelist) {
  3996. debugfs_remove(vport->debug_nodelist); /* nodelist */
  3997. vport->debug_nodelist = NULL;
  3998. }
  3999. if (vport->vport_debugfs_root) {
  4000. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  4001. vport->vport_debugfs_root = NULL;
  4002. atomic_dec(&phba->debugfs_vport_count);
  4003. }
  4004. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  4005. if (phba->debug_hbqinfo) {
  4006. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  4007. phba->debug_hbqinfo = NULL;
  4008. }
  4009. if (phba->debug_dumpHBASlim) {
  4010. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  4011. phba->debug_dumpHBASlim = NULL;
  4012. }
  4013. if (phba->debug_dumpHostSlim) {
  4014. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  4015. phba->debug_dumpHostSlim = NULL;
  4016. }
  4017. if (phba->debug_dumpData) {
  4018. debugfs_remove(phba->debug_dumpData); /* dumpData */
  4019. phba->debug_dumpData = NULL;
  4020. }
  4021. if (phba->debug_dumpDif) {
  4022. debugfs_remove(phba->debug_dumpDif); /* dumpDif */
  4023. phba->debug_dumpDif = NULL;
  4024. }
  4025. if (phba->debug_InjErrLBA) {
  4026. debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
  4027. phba->debug_InjErrLBA = NULL;
  4028. }
  4029. if (phba->debug_InjErrNPortID) { /* InjErrNPortID */
  4030. debugfs_remove(phba->debug_InjErrNPortID);
  4031. phba->debug_InjErrNPortID = NULL;
  4032. }
  4033. if (phba->debug_InjErrWWPN) {
  4034. debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
  4035. phba->debug_InjErrWWPN = NULL;
  4036. }
  4037. if (phba->debug_writeGuard) {
  4038. debugfs_remove(phba->debug_writeGuard); /* writeGuard */
  4039. phba->debug_writeGuard = NULL;
  4040. }
  4041. if (phba->debug_writeApp) {
  4042. debugfs_remove(phba->debug_writeApp); /* writeApp */
  4043. phba->debug_writeApp = NULL;
  4044. }
  4045. if (phba->debug_writeRef) {
  4046. debugfs_remove(phba->debug_writeRef); /* writeRef */
  4047. phba->debug_writeRef = NULL;
  4048. }
  4049. if (phba->debug_readGuard) {
  4050. debugfs_remove(phba->debug_readGuard); /* readGuard */
  4051. phba->debug_readGuard = NULL;
  4052. }
  4053. if (phba->debug_readApp) {
  4054. debugfs_remove(phba->debug_readApp); /* readApp */
  4055. phba->debug_readApp = NULL;
  4056. }
  4057. if (phba->debug_readRef) {
  4058. debugfs_remove(phba->debug_readRef); /* readRef */
  4059. phba->debug_readRef = NULL;
  4060. }
  4061. if (phba->slow_ring_trc) {
  4062. kfree(phba->slow_ring_trc);
  4063. phba->slow_ring_trc = NULL;
  4064. }
  4065. if (phba->debug_slow_ring_trc) {
  4066. /* slow_ring_trace */
  4067. debugfs_remove(phba->debug_slow_ring_trc);
  4068. phba->debug_slow_ring_trc = NULL;
  4069. }
  4070. /*
  4071. * iDiag release
  4072. */
  4073. if (phba->sli_rev == LPFC_SLI_REV4) {
  4074. if (phba->idiag_ext_acc) {
  4075. /* iDiag extAcc */
  4076. debugfs_remove(phba->idiag_ext_acc);
  4077. phba->idiag_ext_acc = NULL;
  4078. }
  4079. if (phba->idiag_mbx_acc) {
  4080. /* iDiag mbxAcc */
  4081. debugfs_remove(phba->idiag_mbx_acc);
  4082. phba->idiag_mbx_acc = NULL;
  4083. }
  4084. if (phba->idiag_ctl_acc) {
  4085. /* iDiag ctlAcc */
  4086. debugfs_remove(phba->idiag_ctl_acc);
  4087. phba->idiag_ctl_acc = NULL;
  4088. }
  4089. if (phba->idiag_drb_acc) {
  4090. /* iDiag drbAcc */
  4091. debugfs_remove(phba->idiag_drb_acc);
  4092. phba->idiag_drb_acc = NULL;
  4093. }
  4094. if (phba->idiag_que_acc) {
  4095. /* iDiag queAcc */
  4096. debugfs_remove(phba->idiag_que_acc);
  4097. phba->idiag_que_acc = NULL;
  4098. }
  4099. if (phba->idiag_que_info) {
  4100. /* iDiag queInfo */
  4101. debugfs_remove(phba->idiag_que_info);
  4102. phba->idiag_que_info = NULL;
  4103. }
  4104. if (phba->idiag_bar_acc) {
  4105. /* iDiag barAcc */
  4106. debugfs_remove(phba->idiag_bar_acc);
  4107. phba->idiag_bar_acc = NULL;
  4108. }
  4109. if (phba->idiag_pci_cfg) {
  4110. /* iDiag pciCfg */
  4111. debugfs_remove(phba->idiag_pci_cfg);
  4112. phba->idiag_pci_cfg = NULL;
  4113. }
  4114. /* Finally remove the iDiag debugfs root */
  4115. if (phba->idiag_root) {
  4116. /* iDiag root */
  4117. debugfs_remove(phba->idiag_root);
  4118. phba->idiag_root = NULL;
  4119. }
  4120. }
  4121. if (phba->hba_debugfs_root) {
  4122. debugfs_remove(phba->hba_debugfs_root); /* fnX */
  4123. phba->hba_debugfs_root = NULL;
  4124. atomic_dec(&lpfc_debugfs_hba_count);
  4125. }
  4126. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  4127. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  4128. lpfc_debugfs_root = NULL;
  4129. }
  4130. }
  4131. #endif
  4132. return;
  4133. }
  4134. /*
  4135. * Driver debug utility routines outside of debugfs. The debug utility
  4136. * routines implemented here is intended to be used in the instrumented
  4137. * debug driver for debugging host or port issues.
  4138. */
  4139. /**
  4140. * lpfc_debug_dump_all_queues - dump all the queues with a hba
  4141. * @phba: Pointer to HBA context object.
  4142. *
  4143. * This function dumps entries of all the queues asociated with the @phba.
  4144. **/
  4145. void
  4146. lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
  4147. {
  4148. int fcp_wqidx;
  4149. /*
  4150. * Dump Work Queues (WQs)
  4151. */
  4152. lpfc_debug_dump_mbx_wq(phba);
  4153. lpfc_debug_dump_els_wq(phba);
  4154. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
  4155. lpfc_debug_dump_fcp_wq(phba, fcp_wqidx);
  4156. lpfc_debug_dump_hdr_rq(phba);
  4157. lpfc_debug_dump_dat_rq(phba);
  4158. /*
  4159. * Dump Complete Queues (CQs)
  4160. */
  4161. lpfc_debug_dump_mbx_cq(phba);
  4162. lpfc_debug_dump_els_cq(phba);
  4163. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
  4164. lpfc_debug_dump_fcp_cq(phba, fcp_wqidx);
  4165. /*
  4166. * Dump Event Queues (EQs)
  4167. */
  4168. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
  4169. lpfc_debug_dump_hba_eq(phba, fcp_wqidx);
  4170. }