lpfc_debugfs.c 127 KB

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