lpfc_debugfs.c 131 KB

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