lpfc_debugfs.c 131 KB

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