lpfc_debugfs.c 131 KB

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