lpfc_debugfs.c 171 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2007-2015 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * *
  10. * This program is free software; you can redistribute it and/or *
  11. * modify it under the terms of version 2 of the GNU General *
  12. * Public License as published by the Free Software Foundation. *
  13. * This program is distributed in the hope that it will be useful. *
  14. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  15. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  16. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  17. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  18. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  19. * more details, a copy of which can be found in the file COPYING *
  20. * included with this package. *
  21. *******************************************************************/
  22. #include <linux/blkdev.h>
  23. #include <linux/delay.h>
  24. #include <linux/module.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/idr.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/kthread.h>
  29. #include <linux/slab.h>
  30. #include <linux/pci.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/ctype.h>
  33. #include <scsi/scsi.h>
  34. #include <scsi/scsi_device.h>
  35. #include <scsi/scsi_host.h>
  36. #include <scsi/scsi_transport_fc.h>
  37. #include <scsi/fc/fc_fs.h>
  38. #include <linux/nvme-fc-driver.h>
  39. #include "lpfc_hw4.h"
  40. #include "lpfc_hw.h"
  41. #include "lpfc_sli.h"
  42. #include "lpfc_sli4.h"
  43. #include "lpfc_nl.h"
  44. #include "lpfc_disc.h"
  45. #include "lpfc.h"
  46. #include "lpfc_scsi.h"
  47. #include "lpfc_nvme.h"
  48. #include "lpfc_nvmet.h"
  49. #include "lpfc_logmsg.h"
  50. #include "lpfc_crtn.h"
  51. #include "lpfc_vport.h"
  52. #include "lpfc_version.h"
  53. #include "lpfc_compat.h"
  54. #include "lpfc_debugfs.h"
  55. #include "lpfc_bsg.h"
  56. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  57. /*
  58. * debugfs interface
  59. *
  60. * To access this interface the user should:
  61. * # mount -t debugfs none /sys/kernel/debug
  62. *
  63. * The lpfc debugfs directory hierarchy is:
  64. * /sys/kernel/debug/lpfc/fnX/vportY
  65. * where X is the lpfc hba function unique_id
  66. * where Y is the vport VPI on that hba
  67. *
  68. * Debugging services available per vport:
  69. * discovery_trace
  70. * This is an ACSII readable file that contains a trace of the last
  71. * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
  72. * See lpfc_debugfs.h for different categories of discovery events.
  73. * To enable the discovery trace, the following module parameters must be set:
  74. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  75. * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
  76. * EACH vport. X MUST also be a power of 2.
  77. * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
  78. * lpfc_debugfs.h .
  79. *
  80. * slow_ring_trace
  81. * This is an ACSII readable file that contains a trace of the last
  82. * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
  83. * To enable the slow ring trace, the following module parameters must be set:
  84. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  85. * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
  86. * the HBA. X MUST also be a power of 2.
  87. */
  88. static int lpfc_debugfs_enable = 1;
  89. module_param(lpfc_debugfs_enable, int, S_IRUGO);
  90. MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
  91. /* This MUST be a power of 2 */
  92. static int lpfc_debugfs_max_disc_trc;
  93. module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
  94. MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
  95. "Set debugfs discovery trace depth");
  96. /* This MUST be a power of 2 */
  97. static int lpfc_debugfs_max_slow_ring_trc;
  98. module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
  99. MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
  100. "Set debugfs slow ring trace depth");
  101. /* This MUST be a power of 2 */
  102. static int lpfc_debugfs_max_nvmeio_trc;
  103. module_param(lpfc_debugfs_max_nvmeio_trc, int, 0444);
  104. MODULE_PARM_DESC(lpfc_debugfs_max_nvmeio_trc,
  105. "Set debugfs NVME IO trace depth");
  106. static int lpfc_debugfs_mask_disc_trc;
  107. module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
  108. MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
  109. "Set debugfs discovery trace mask");
  110. #include <linux/debugfs.h>
  111. static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  112. static unsigned long lpfc_debugfs_start_time = 0L;
  113. /* iDiag */
  114. static struct lpfc_idiag idiag;
  115. /**
  116. * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
  117. * @vport: The vport to gather the log info from.
  118. * @buf: The buffer to dump log into.
  119. * @size: The maximum amount of data to process.
  120. *
  121. * Description:
  122. * This routine gathers the lpfc discovery debugfs data from the @vport and
  123. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  124. * in the log and process the log until the end of the buffer. Then it will
  125. * gather from the beginning of the log and process until the current entry.
  126. *
  127. * Notes:
  128. * Discovery logging will be disabled while while this routine dumps the log.
  129. *
  130. * Return Value:
  131. * This routine returns the amount of bytes that were dumped into @buf and will
  132. * not exceed @size.
  133. **/
  134. static int
  135. lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
  136. {
  137. int i, index, len, enable;
  138. uint32_t ms;
  139. struct lpfc_debugfs_trc *dtp;
  140. char *buffer;
  141. buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
  142. if (!buffer)
  143. return 0;
  144. enable = lpfc_debugfs_enable;
  145. lpfc_debugfs_enable = 0;
  146. len = 0;
  147. index = (atomic_read(&vport->disc_trc_cnt) + 1) &
  148. (lpfc_debugfs_max_disc_trc - 1);
  149. for (i = index; i < lpfc_debugfs_max_disc_trc; 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 += scnprintf(buf+len, size-len, buffer,
  158. dtp->data1, dtp->data2, dtp->data3);
  159. }
  160. for (i = 0; i < index; i++) {
  161. dtp = vport->disc_trc + i;
  162. if (!dtp->fmt)
  163. continue;
  164. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  165. snprintf(buffer,
  166. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  167. dtp->seq_cnt, ms, dtp->fmt);
  168. len += scnprintf(buf+len, size-len, buffer,
  169. dtp->data1, dtp->data2, dtp->data3);
  170. }
  171. lpfc_debugfs_enable = enable;
  172. kfree(buffer);
  173. return len;
  174. }
  175. /**
  176. * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
  177. * @phba: The HBA to gather the log info from.
  178. * @buf: The buffer to dump log into.
  179. * @size: The maximum amount of data to process.
  180. *
  181. * Description:
  182. * This routine gathers the lpfc slow ring debugfs data from the @phba and
  183. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  184. * in the log and process the log until the end of the buffer. Then it will
  185. * gather from the beginning of the log and process until the current entry.
  186. *
  187. * Notes:
  188. * Slow ring logging will be disabled while while this routine dumps the log.
  189. *
  190. * Return Value:
  191. * This routine returns the amount of bytes that were dumped into @buf and will
  192. * not exceed @size.
  193. **/
  194. static int
  195. lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
  196. {
  197. int i, index, len, enable;
  198. uint32_t ms;
  199. struct lpfc_debugfs_trc *dtp;
  200. char *buffer;
  201. buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
  202. if (!buffer)
  203. return 0;
  204. enable = lpfc_debugfs_enable;
  205. lpfc_debugfs_enable = 0;
  206. len = 0;
  207. index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
  208. (lpfc_debugfs_max_slow_ring_trc - 1);
  209. for (i = index; i < lpfc_debugfs_max_slow_ring_trc; 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 += scnprintf(buf+len, size-len, buffer,
  218. dtp->data1, dtp->data2, dtp->data3);
  219. }
  220. for (i = 0; i < index; i++) {
  221. dtp = phba->slow_ring_trc + i;
  222. if (!dtp->fmt)
  223. continue;
  224. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  225. snprintf(buffer,
  226. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  227. dtp->seq_cnt, ms, dtp->fmt);
  228. len += scnprintf(buf+len, size-len, buffer,
  229. dtp->data1, dtp->data2, dtp->data3);
  230. }
  231. lpfc_debugfs_enable = enable;
  232. kfree(buffer);
  233. return len;
  234. }
  235. static int lpfc_debugfs_last_hbq = -1;
  236. /**
  237. * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
  238. * @phba: The HBA to gather host buffer info from.
  239. * @buf: The buffer to dump log into.
  240. * @size: The maximum amount of data to process.
  241. *
  242. * Description:
  243. * This routine dumps the host buffer queue info from the @phba to @buf up to
  244. * @size number of bytes. A header that describes the current hbq state will be
  245. * dumped to @buf first and then info on each hbq entry will be dumped to @buf
  246. * until @size bytes have been dumped or all the hbq info has been dumped.
  247. *
  248. * Notes:
  249. * This routine will rotate through each configured HBQ each time called.
  250. *
  251. * Return Value:
  252. * This routine returns the amount of bytes that were dumped into @buf and will
  253. * not exceed @size.
  254. **/
  255. static int
  256. lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
  257. {
  258. int len = 0;
  259. int i, j, found, posted, low;
  260. uint32_t phys, raw_index, getidx;
  261. struct lpfc_hbq_init *hip;
  262. struct hbq_s *hbqs;
  263. struct lpfc_hbq_entry *hbqe;
  264. struct lpfc_dmabuf *d_buf;
  265. struct hbq_dmabuf *hbq_buf;
  266. if (phba->sli_rev != 3)
  267. return 0;
  268. spin_lock_irq(&phba->hbalock);
  269. /* toggle between multiple hbqs, if any */
  270. i = lpfc_sli_hbq_count();
  271. if (i > 1) {
  272. lpfc_debugfs_last_hbq++;
  273. if (lpfc_debugfs_last_hbq >= i)
  274. lpfc_debugfs_last_hbq = 0;
  275. }
  276. else
  277. lpfc_debugfs_last_hbq = 0;
  278. i = lpfc_debugfs_last_hbq;
  279. len += scnprintf(buf+len, size-len, "HBQ %d Info\n", i);
  280. hbqs = &phba->hbqs[i];
  281. posted = 0;
  282. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
  283. posted++;
  284. hip = lpfc_hbq_defs[i];
  285. len += scnprintf(buf+len, size-len,
  286. "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
  287. hip->hbq_index, hip->profile, hip->rn,
  288. hip->buffer_count, hip->init_count, hip->add_count, posted);
  289. raw_index = phba->hbq_get[i];
  290. getidx = le32_to_cpu(raw_index);
  291. len += scnprintf(buf+len, size-len,
  292. "entries:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
  293. hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
  294. hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
  295. hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
  296. for (j=0; j<hbqs->entry_count; j++) {
  297. len += scnprintf(buf+len, size-len,
  298. "%03d: %08x %04x %05x ", j,
  299. le32_to_cpu(hbqe->bde.addrLow),
  300. le32_to_cpu(hbqe->bde.tus.w),
  301. le32_to_cpu(hbqe->buffer_tag));
  302. i = 0;
  303. found = 0;
  304. /* First calculate if slot has an associated posted buffer */
  305. low = hbqs->hbqPutIdx - posted;
  306. if (low >= 0) {
  307. if ((j >= hbqs->hbqPutIdx) || (j < low)) {
  308. len += scnprintf(buf + len, size - len,
  309. "Unused\n");
  310. goto skipit;
  311. }
  312. }
  313. else {
  314. if ((j >= hbqs->hbqPutIdx) &&
  315. (j < (hbqs->entry_count+low))) {
  316. len += scnprintf(buf + len, size - len,
  317. "Unused\n");
  318. goto skipit;
  319. }
  320. }
  321. /* Get the Buffer info for the posted buffer */
  322. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
  323. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  324. phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
  325. if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
  326. len += scnprintf(buf+len, size-len,
  327. "Buf%d: %p %06x\n", i,
  328. hbq_buf->dbuf.virt, hbq_buf->tag);
  329. found = 1;
  330. break;
  331. }
  332. i++;
  333. }
  334. if (!found) {
  335. len += scnprintf(buf+len, size-len, "No DMAinfo?\n");
  336. }
  337. skipit:
  338. hbqe++;
  339. if (len > LPFC_HBQINFO_SIZE - 54)
  340. break;
  341. }
  342. spin_unlock_irq(&phba->hbalock);
  343. return len;
  344. }
  345. static int lpfc_debugfs_last_hba_slim_off;
  346. /**
  347. * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
  348. * @phba: The HBA to gather SLIM info from.
  349. * @buf: The buffer to dump log into.
  350. * @size: The maximum amount of data to process.
  351. *
  352. * Description:
  353. * This routine dumps the current contents of HBA SLIM for the HBA associated
  354. * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
  355. *
  356. * Notes:
  357. * This routine will only dump up to 1024 bytes of data each time called and
  358. * should be called multiple times to dump the entire HBA SLIM.
  359. *
  360. * Return Value:
  361. * This routine returns the amount of bytes that were dumped into @buf and will
  362. * not exceed @size.
  363. **/
  364. static int
  365. lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
  366. {
  367. int len = 0;
  368. int i, off;
  369. uint32_t *ptr;
  370. char *buffer;
  371. buffer = kmalloc(1024, GFP_KERNEL);
  372. if (!buffer)
  373. return 0;
  374. off = 0;
  375. spin_lock_irq(&phba->hbalock);
  376. len += scnprintf(buf+len, size-len, "HBA SLIM\n");
  377. lpfc_memcpy_from_slim(buffer,
  378. phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
  379. ptr = (uint32_t *)&buffer[0];
  380. off = lpfc_debugfs_last_hba_slim_off;
  381. /* Set it up for the next time */
  382. lpfc_debugfs_last_hba_slim_off += 1024;
  383. if (lpfc_debugfs_last_hba_slim_off >= 4096)
  384. lpfc_debugfs_last_hba_slim_off = 0;
  385. i = 1024;
  386. while (i > 0) {
  387. len += scnprintf(buf+len, size-len,
  388. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  389. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  390. *(ptr+5), *(ptr+6), *(ptr+7));
  391. ptr += 8;
  392. i -= (8 * sizeof(uint32_t));
  393. off += (8 * sizeof(uint32_t));
  394. }
  395. spin_unlock_irq(&phba->hbalock);
  396. kfree(buffer);
  397. return len;
  398. }
  399. /**
  400. * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
  401. * @phba: The HBA to gather Host SLIM info from.
  402. * @buf: The buffer to dump log into.
  403. * @size: The maximum amount of data to process.
  404. *
  405. * Description:
  406. * This routine dumps the current contents of host SLIM for the host associated
  407. * with @phba to @buf up to @size bytes of data. The dump will contain the
  408. * Mailbox, PCB, Rings, and Registers that are located in host memory.
  409. *
  410. * Return Value:
  411. * This routine returns the amount of bytes that were dumped into @buf and will
  412. * not exceed @size.
  413. **/
  414. static int
  415. lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
  416. {
  417. int len = 0;
  418. int i, off;
  419. uint32_t word0, word1, word2, word3;
  420. uint32_t *ptr;
  421. struct lpfc_pgp *pgpp;
  422. struct lpfc_sli *psli = &phba->sli;
  423. struct lpfc_sli_ring *pring;
  424. off = 0;
  425. spin_lock_irq(&phba->hbalock);
  426. len += scnprintf(buf+len, size-len, "SLIM Mailbox\n");
  427. ptr = (uint32_t *)phba->slim2p.virt;
  428. i = sizeof(MAILBOX_t);
  429. while (i > 0) {
  430. len += scnprintf(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. len += scnprintf(buf+len, size-len, "SLIM PCB\n");
  439. ptr = (uint32_t *)phba->pcb;
  440. i = sizeof(PCB_t);
  441. while (i > 0) {
  442. len += scnprintf(buf+len, size-len,
  443. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  444. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  445. *(ptr+5), *(ptr+6), *(ptr+7));
  446. ptr += 8;
  447. i -= (8 * sizeof(uint32_t));
  448. off += (8 * sizeof(uint32_t));
  449. }
  450. if (phba->sli_rev <= LPFC_SLI_REV3) {
  451. for (i = 0; i < 4; i++) {
  452. pgpp = &phba->port_gp[i];
  453. pring = &psli->sli3_ring[i];
  454. len += scnprintf(buf+len, size-len,
  455. "Ring %d: CMD GetInx:%d "
  456. "(Max:%d Next:%d "
  457. "Local:%d flg:x%x) "
  458. "RSP PutInx:%d Max:%d\n",
  459. i, pgpp->cmdGetInx,
  460. pring->sli.sli3.numCiocb,
  461. pring->sli.sli3.next_cmdidx,
  462. pring->sli.sli3.local_getidx,
  463. pring->flag, pgpp->rspPutInx,
  464. pring->sli.sli3.numRiocb);
  465. }
  466. word0 = readl(phba->HAregaddr);
  467. word1 = readl(phba->CAregaddr);
  468. word2 = readl(phba->HSregaddr);
  469. word3 = readl(phba->HCregaddr);
  470. len += scnprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
  471. "HC:%08x\n", word0, word1, word2, word3);
  472. }
  473. spin_unlock_irq(&phba->hbalock);
  474. return len;
  475. }
  476. /**
  477. * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
  478. * @vport: The vport to gather target node info from.
  479. * @buf: The buffer to dump log into.
  480. * @size: The maximum amount of data to process.
  481. *
  482. * Description:
  483. * This routine dumps the current target node list associated with @vport to
  484. * @buf up to @size bytes of data. Each node entry in the dump will contain a
  485. * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
  486. *
  487. * Return Value:
  488. * This routine returns the amount of bytes that were dumped into @buf and will
  489. * not exceed @size.
  490. **/
  491. static int
  492. lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
  493. {
  494. int len = 0;
  495. int i, iocnt, outio, cnt;
  496. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  497. struct lpfc_hba *phba = vport->phba;
  498. struct lpfc_nodelist *ndlp;
  499. unsigned char *statep;
  500. struct nvme_fc_local_port *localport;
  501. struct lpfc_nvmet_tgtport *tgtp;
  502. struct nvme_fc_remote_port *nrport = NULL;
  503. struct lpfc_nvme_rport *rport;
  504. cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
  505. outio = 0;
  506. len += scnprintf(buf+len, size-len, "\nFCP Nodelist Entries ...\n");
  507. spin_lock_irq(shost->host_lock);
  508. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  509. iocnt = 0;
  510. if (!cnt) {
  511. len += scnprintf(buf+len, size-len,
  512. "Missing Nodelist Entries\n");
  513. break;
  514. }
  515. cnt--;
  516. switch (ndlp->nlp_state) {
  517. case NLP_STE_UNUSED_NODE:
  518. statep = "UNUSED";
  519. break;
  520. case NLP_STE_PLOGI_ISSUE:
  521. statep = "PLOGI ";
  522. break;
  523. case NLP_STE_ADISC_ISSUE:
  524. statep = "ADISC ";
  525. break;
  526. case NLP_STE_REG_LOGIN_ISSUE:
  527. statep = "REGLOG";
  528. break;
  529. case NLP_STE_PRLI_ISSUE:
  530. statep = "PRLI ";
  531. break;
  532. case NLP_STE_LOGO_ISSUE:
  533. statep = "LOGO ";
  534. break;
  535. case NLP_STE_UNMAPPED_NODE:
  536. statep = "UNMAP ";
  537. iocnt = 1;
  538. break;
  539. case NLP_STE_MAPPED_NODE:
  540. statep = "MAPPED";
  541. iocnt = 1;
  542. break;
  543. case NLP_STE_NPR_NODE:
  544. statep = "NPR ";
  545. break;
  546. default:
  547. statep = "UNKNOWN";
  548. }
  549. len += scnprintf(buf+len, size-len, "%s DID:x%06x ",
  550. statep, ndlp->nlp_DID);
  551. len += scnprintf(buf+len, size-len,
  552. "WWPN x%llx ",
  553. wwn_to_u64(ndlp->nlp_portname.u.wwn));
  554. len += scnprintf(buf+len, size-len,
  555. "WWNN x%llx ",
  556. wwn_to_u64(ndlp->nlp_nodename.u.wwn));
  557. if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
  558. len += scnprintf(buf+len, size-len, "RPI:%03d ",
  559. ndlp->nlp_rpi);
  560. else
  561. len += scnprintf(buf+len, size-len, "RPI:none ");
  562. len += scnprintf(buf+len, size-len, "flag:x%08x ",
  563. ndlp->nlp_flag);
  564. if (!ndlp->nlp_type)
  565. len += scnprintf(buf+len, size-len, "UNKNOWN_TYPE ");
  566. if (ndlp->nlp_type & NLP_FC_NODE)
  567. len += scnprintf(buf+len, size-len, "FC_NODE ");
  568. if (ndlp->nlp_type & NLP_FABRIC) {
  569. len += scnprintf(buf+len, size-len, "FABRIC ");
  570. iocnt = 0;
  571. }
  572. if (ndlp->nlp_type & NLP_FCP_TARGET)
  573. len += scnprintf(buf+len, size-len, "FCP_TGT sid:%d ",
  574. ndlp->nlp_sid);
  575. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  576. len += scnprintf(buf+len, size-len, "FCP_INITIATOR ");
  577. if (ndlp->nlp_type & NLP_NVME_TARGET)
  578. len += scnprintf(buf + len,
  579. size - len, "NVME_TGT sid:%d ",
  580. NLP_NO_SID);
  581. if (ndlp->nlp_type & NLP_NVME_INITIATOR)
  582. len += scnprintf(buf + len,
  583. size - len, "NVME_INITIATOR ");
  584. len += scnprintf(buf+len, size-len, "usgmap:%x ",
  585. ndlp->nlp_usg_map);
  586. len += scnprintf(buf+len, size-len, "refcnt:%x",
  587. kref_read(&ndlp->kref));
  588. if (iocnt) {
  589. i = atomic_read(&ndlp->cmd_pending);
  590. len += scnprintf(buf + len, size - len,
  591. " OutIO:x%x Qdepth x%x",
  592. i, ndlp->cmd_qdepth);
  593. outio += i;
  594. }
  595. len += scnprintf(buf+len, size-len, "\n");
  596. }
  597. spin_unlock_irq(shost->host_lock);
  598. len += scnprintf(buf + len, size - len,
  599. "\nOutstanding IO x%x\n", outio);
  600. if (phba->nvmet_support && phba->targetport && (vport == phba->pport)) {
  601. tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
  602. len += scnprintf(buf + len, size - len,
  603. "\nNVME Targetport Entry ...\n");
  604. /* Port state is only one of two values for now. */
  605. if (phba->targetport->port_id)
  606. statep = "REGISTERED";
  607. else
  608. statep = "INIT";
  609. len += scnprintf(buf + len, size - len,
  610. "TGT WWNN x%llx WWPN x%llx State %s\n",
  611. wwn_to_u64(vport->fc_nodename.u.wwn),
  612. wwn_to_u64(vport->fc_portname.u.wwn),
  613. statep);
  614. len += scnprintf(buf + len, size - len,
  615. " Targetport DID x%06x\n",
  616. phba->targetport->port_id);
  617. goto out_exit;
  618. }
  619. len += scnprintf(buf + len, size - len,
  620. "\nNVME Lport/Rport Entries ...\n");
  621. localport = vport->localport;
  622. if (!localport)
  623. goto out_exit;
  624. spin_lock_irq(shost->host_lock);
  625. /* Port state is only one of two values for now. */
  626. if (localport->port_id)
  627. statep = "ONLINE";
  628. else
  629. statep = "UNKNOWN ";
  630. len += scnprintf(buf + len, size - len,
  631. "Lport DID x%06x PortState %s\n",
  632. localport->port_id, statep);
  633. len += scnprintf(buf + len, size - len, "\tRport List:\n");
  634. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  635. /* local short-hand pointer. */
  636. spin_lock(&phba->hbalock);
  637. rport = lpfc_ndlp_get_nrport(ndlp);
  638. if (rport)
  639. nrport = rport->remoteport;
  640. else
  641. nrport = NULL;
  642. spin_unlock(&phba->hbalock);
  643. if (!nrport)
  644. continue;
  645. /* Port state is only one of two values for now. */
  646. switch (nrport->port_state) {
  647. case FC_OBJSTATE_ONLINE:
  648. statep = "ONLINE";
  649. break;
  650. case FC_OBJSTATE_UNKNOWN:
  651. statep = "UNKNOWN ";
  652. break;
  653. default:
  654. statep = "UNSUPPORTED";
  655. break;
  656. }
  657. /* Tab in to show lport ownership. */
  658. len += scnprintf(buf + len, size - len,
  659. "\t%s Port ID:x%06x ",
  660. statep, nrport->port_id);
  661. len += scnprintf(buf + len, size - len, "WWPN x%llx ",
  662. nrport->port_name);
  663. len += scnprintf(buf + len, size - len, "WWNN x%llx ",
  664. nrport->node_name);
  665. /* An NVME rport can have multiple roles. */
  666. if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
  667. len += scnprintf(buf + len, size - len,
  668. "INITIATOR ");
  669. if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
  670. len += scnprintf(buf + len, size - len,
  671. "TARGET ");
  672. if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
  673. len += scnprintf(buf + len, size - len,
  674. "DISCSRVC ");
  675. if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
  676. FC_PORT_ROLE_NVME_TARGET |
  677. FC_PORT_ROLE_NVME_DISCOVERY))
  678. len += scnprintf(buf + len, size - len,
  679. "UNKNOWN ROLE x%x",
  680. nrport->port_role);
  681. /* Terminate the string. */
  682. len += scnprintf(buf + len, size - len, "\n");
  683. }
  684. spin_unlock_irq(shost->host_lock);
  685. out_exit:
  686. return len;
  687. }
  688. /**
  689. * lpfc_debugfs_nvmestat_data - Dump target node list to a buffer
  690. * @vport: The vport to gather target node info from.
  691. * @buf: The buffer to dump log into.
  692. * @size: The maximum amount of data to process.
  693. *
  694. * Description:
  695. * This routine dumps the NVME statistics associated with @vport
  696. *
  697. * Return Value:
  698. * This routine returns the amount of bytes that were dumped into @buf and will
  699. * not exceed @size.
  700. **/
  701. static int
  702. lpfc_debugfs_nvmestat_data(struct lpfc_vport *vport, char *buf, int size)
  703. {
  704. struct lpfc_hba *phba = vport->phba;
  705. struct lpfc_nvmet_tgtport *tgtp;
  706. struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp;
  707. struct nvme_fc_local_port *localport;
  708. struct lpfc_nvme_ctrl_stat *cstat;
  709. struct lpfc_nvme_lport *lport;
  710. uint64_t data1, data2, data3;
  711. uint64_t tot, totin, totout;
  712. int cnt, i, maxch;
  713. int len = 0;
  714. if (phba->nvmet_support) {
  715. if (!phba->targetport)
  716. return len;
  717. tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
  718. len += scnprintf(buf + len, size - len,
  719. "\nNVME Targetport Statistics\n");
  720. len += scnprintf(buf + len, size - len,
  721. "LS: Rcv %08x Drop %08x Abort %08x\n",
  722. atomic_read(&tgtp->rcv_ls_req_in),
  723. atomic_read(&tgtp->rcv_ls_req_drop),
  724. atomic_read(&tgtp->xmt_ls_abort));
  725. if (atomic_read(&tgtp->rcv_ls_req_in) !=
  726. atomic_read(&tgtp->rcv_ls_req_out)) {
  727. len += scnprintf(buf + len, size - len,
  728. "Rcv LS: in %08x != out %08x\n",
  729. atomic_read(&tgtp->rcv_ls_req_in),
  730. atomic_read(&tgtp->rcv_ls_req_out));
  731. }
  732. len += scnprintf(buf + len, size - len,
  733. "LS: Xmt %08x Drop %08x Cmpl %08x\n",
  734. atomic_read(&tgtp->xmt_ls_rsp),
  735. atomic_read(&tgtp->xmt_ls_drop),
  736. atomic_read(&tgtp->xmt_ls_rsp_cmpl));
  737. len += scnprintf(buf + len, size - len,
  738. "LS: RSP Abort %08x xb %08x Err %08x\n",
  739. atomic_read(&tgtp->xmt_ls_rsp_aborted),
  740. atomic_read(&tgtp->xmt_ls_rsp_xb_set),
  741. atomic_read(&tgtp->xmt_ls_rsp_error));
  742. len += scnprintf(buf + len, size - len,
  743. "FCP: Rcv %08x Defer %08x Release %08x "
  744. "Drop %08x\n",
  745. atomic_read(&tgtp->rcv_fcp_cmd_in),
  746. atomic_read(&tgtp->rcv_fcp_cmd_defer),
  747. atomic_read(&tgtp->xmt_fcp_release),
  748. atomic_read(&tgtp->rcv_fcp_cmd_drop));
  749. if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
  750. atomic_read(&tgtp->rcv_fcp_cmd_out)) {
  751. len += scnprintf(buf + len, size - len,
  752. "Rcv FCP: in %08x != out %08x\n",
  753. atomic_read(&tgtp->rcv_fcp_cmd_in),
  754. atomic_read(&tgtp->rcv_fcp_cmd_out));
  755. }
  756. len += scnprintf(buf + len, size - len,
  757. "FCP Rsp: read %08x readrsp %08x "
  758. "write %08x rsp %08x\n",
  759. atomic_read(&tgtp->xmt_fcp_read),
  760. atomic_read(&tgtp->xmt_fcp_read_rsp),
  761. atomic_read(&tgtp->xmt_fcp_write),
  762. atomic_read(&tgtp->xmt_fcp_rsp));
  763. len += scnprintf(buf + len, size - len,
  764. "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
  765. atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
  766. atomic_read(&tgtp->xmt_fcp_rsp_error),
  767. atomic_read(&tgtp->xmt_fcp_rsp_drop));
  768. len += scnprintf(buf + len, size - len,
  769. "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
  770. atomic_read(&tgtp->xmt_fcp_rsp_aborted),
  771. atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
  772. atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
  773. len += scnprintf(buf + len, size - len,
  774. "ABORT: Xmt %08x Cmpl %08x\n",
  775. atomic_read(&tgtp->xmt_fcp_abort),
  776. atomic_read(&tgtp->xmt_fcp_abort_cmpl));
  777. len += scnprintf(buf + len, size - len,
  778. "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
  779. atomic_read(&tgtp->xmt_abort_sol),
  780. atomic_read(&tgtp->xmt_abort_unsol),
  781. atomic_read(&tgtp->xmt_abort_rsp),
  782. atomic_read(&tgtp->xmt_abort_rsp_error));
  783. len += scnprintf(buf + len, size - len, "\n");
  784. cnt = 0;
  785. spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
  786. list_for_each_entry_safe(ctxp, next_ctxp,
  787. &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
  788. list) {
  789. cnt++;
  790. }
  791. spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
  792. if (cnt) {
  793. len += scnprintf(buf + len, size - len,
  794. "ABORT: %d ctx entries\n", cnt);
  795. spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
  796. list_for_each_entry_safe(ctxp, next_ctxp,
  797. &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
  798. list) {
  799. if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ))
  800. break;
  801. len += scnprintf(buf + len, size - len,
  802. "Entry: oxid %x state %x "
  803. "flag %x\n",
  804. ctxp->oxid, ctxp->state,
  805. ctxp->flag);
  806. }
  807. spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
  808. }
  809. /* Calculate outstanding IOs */
  810. tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
  811. tot += atomic_read(&tgtp->xmt_fcp_release);
  812. tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
  813. len += scnprintf(buf + len, size - len,
  814. "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
  815. "CTX Outstanding %08llx\n",
  816. phba->sli4_hba.nvmet_xri_cnt,
  817. phba->sli4_hba.nvmet_io_wait_cnt,
  818. phba->sli4_hba.nvmet_io_wait_total,
  819. tot);
  820. } else {
  821. if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
  822. return len;
  823. localport = vport->localport;
  824. if (!localport)
  825. return len;
  826. lport = (struct lpfc_nvme_lport *)localport->private;
  827. if (!lport)
  828. return len;
  829. len += scnprintf(buf + len, size - len,
  830. "\nNVME Lport Statistics\n");
  831. len += scnprintf(buf + len, size - len,
  832. "LS: Xmt %016x Cmpl %016x\n",
  833. atomic_read(&lport->fc4NvmeLsRequests),
  834. atomic_read(&lport->fc4NvmeLsCmpls));
  835. if (phba->cfg_nvme_io_channel < 32)
  836. maxch = phba->cfg_nvme_io_channel;
  837. else
  838. maxch = 32;
  839. totin = 0;
  840. totout = 0;
  841. for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
  842. cstat = &lport->cstat[i];
  843. tot = atomic_read(&cstat->fc4NvmeIoCmpls);
  844. totin += tot;
  845. data1 = atomic_read(&cstat->fc4NvmeInputRequests);
  846. data2 = atomic_read(&cstat->fc4NvmeOutputRequests);
  847. data3 = atomic_read(&cstat->fc4NvmeControlRequests);
  848. totout += (data1 + data2 + data3);
  849. /* Limit to 32, debugfs display buffer limitation */
  850. if (i >= 32)
  851. continue;
  852. len += scnprintf(buf + len, PAGE_SIZE - len,
  853. "FCP (%d): Rd %016llx Wr %016llx "
  854. "IO %016llx ",
  855. i, data1, data2, data3);
  856. len += scnprintf(buf + len, PAGE_SIZE - len,
  857. "Cmpl %016llx OutIO %016llx\n",
  858. tot, ((data1 + data2 + data3) - tot));
  859. }
  860. len += scnprintf(buf + len, PAGE_SIZE - len,
  861. "Total FCP Cmpl %016llx Issue %016llx "
  862. "OutIO %016llx\n",
  863. totin, totout, totout - totin);
  864. len += scnprintf(buf + len, size - len,
  865. "LS Xmt Err: Abrt %08x Err %08x "
  866. "Cmpl Err: xb %08x Err %08x\n",
  867. atomic_read(&lport->xmt_ls_abort),
  868. atomic_read(&lport->xmt_ls_err),
  869. atomic_read(&lport->cmpl_ls_xb),
  870. atomic_read(&lport->cmpl_ls_err));
  871. len += scnprintf(buf + len, size - len,
  872. "FCP Xmt Err: noxri %06x nondlp %06x "
  873. "qdepth %06x wqerr %06x err %06x Abrt %06x\n",
  874. atomic_read(&lport->xmt_fcp_noxri),
  875. atomic_read(&lport->xmt_fcp_bad_ndlp),
  876. atomic_read(&lport->xmt_fcp_qdepth),
  877. atomic_read(&lport->xmt_fcp_wqerr),
  878. atomic_read(&lport->xmt_fcp_err),
  879. atomic_read(&lport->xmt_fcp_abort));
  880. len += scnprintf(buf + len, size - len,
  881. "FCP Cmpl Err: xb %08x Err %08x\n",
  882. atomic_read(&lport->cmpl_fcp_xb),
  883. atomic_read(&lport->cmpl_fcp_err));
  884. }
  885. return len;
  886. }
  887. /**
  888. * lpfc_debugfs_nvmektime_data - Dump target node list to a buffer
  889. * @vport: The vport to gather target node info from.
  890. * @buf: The buffer to dump log into.
  891. * @size: The maximum amount of data to process.
  892. *
  893. * Description:
  894. * This routine dumps the NVME statistics associated with @vport
  895. *
  896. * Return Value:
  897. * This routine returns the amount of bytes that were dumped into @buf and will
  898. * not exceed @size.
  899. **/
  900. static int
  901. lpfc_debugfs_nvmektime_data(struct lpfc_vport *vport, char *buf, int size)
  902. {
  903. struct lpfc_hba *phba = vport->phba;
  904. int len = 0;
  905. if (phba->nvmet_support == 0) {
  906. /* NVME Initiator */
  907. len += scnprintf(buf + len, PAGE_SIZE - len,
  908. "ktime %s: Total Samples: %lld\n",
  909. (phba->ktime_on ? "Enabled" : "Disabled"),
  910. phba->ktime_data_samples);
  911. if (phba->ktime_data_samples == 0)
  912. return len;
  913. len += scnprintf(
  914. buf + len, PAGE_SIZE - len,
  915. "Segment 1: Last NVME Cmd cmpl "
  916. "done -to- Start of next NVME cnd (in driver)\n");
  917. len += scnprintf(
  918. buf + len, PAGE_SIZE - len,
  919. "avg:%08lld min:%08lld max %08lld\n",
  920. div_u64(phba->ktime_seg1_total,
  921. phba->ktime_data_samples),
  922. phba->ktime_seg1_min,
  923. phba->ktime_seg1_max);
  924. len += scnprintf(
  925. buf + len, PAGE_SIZE - len,
  926. "Segment 2: Driver start of NVME cmd "
  927. "-to- Firmware WQ doorbell\n");
  928. len += scnprintf(
  929. buf + len, PAGE_SIZE - len,
  930. "avg:%08lld min:%08lld max %08lld\n",
  931. div_u64(phba->ktime_seg2_total,
  932. phba->ktime_data_samples),
  933. phba->ktime_seg2_min,
  934. phba->ktime_seg2_max);
  935. len += scnprintf(
  936. buf + len, PAGE_SIZE - len,
  937. "Segment 3: Firmware WQ doorbell -to- "
  938. "MSI-X ISR cmpl\n");
  939. len += scnprintf(
  940. buf + len, PAGE_SIZE - len,
  941. "avg:%08lld min:%08lld max %08lld\n",
  942. div_u64(phba->ktime_seg3_total,
  943. phba->ktime_data_samples),
  944. phba->ktime_seg3_min,
  945. phba->ktime_seg3_max);
  946. len += scnprintf(
  947. buf + len, PAGE_SIZE - len,
  948. "Segment 4: MSI-X ISR cmpl -to- "
  949. "NVME cmpl done\n");
  950. len += scnprintf(
  951. buf + len, PAGE_SIZE - len,
  952. "avg:%08lld min:%08lld max %08lld\n",
  953. div_u64(phba->ktime_seg4_total,
  954. phba->ktime_data_samples),
  955. phba->ktime_seg4_min,
  956. phba->ktime_seg4_max);
  957. len += scnprintf(
  958. buf + len, PAGE_SIZE - len,
  959. "Total IO avg time: %08lld\n",
  960. div_u64(phba->ktime_seg1_total +
  961. phba->ktime_seg2_total +
  962. phba->ktime_seg3_total +
  963. phba->ktime_seg4_total,
  964. phba->ktime_data_samples));
  965. return len;
  966. }
  967. /* NVME Target */
  968. len += scnprintf(buf + len, PAGE_SIZE-len,
  969. "ktime %s: Total Samples: %lld %lld\n",
  970. (phba->ktime_on ? "Enabled" : "Disabled"),
  971. phba->ktime_data_samples,
  972. phba->ktime_status_samples);
  973. if (phba->ktime_data_samples == 0)
  974. return len;
  975. len += scnprintf(buf + len, PAGE_SIZE-len,
  976. "Segment 1: MSI-X ISR Rcv cmd -to- "
  977. "cmd pass to NVME Layer\n");
  978. len += scnprintf(buf + len, PAGE_SIZE-len,
  979. "avg:%08lld min:%08lld max %08lld\n",
  980. div_u64(phba->ktime_seg1_total,
  981. phba->ktime_data_samples),
  982. phba->ktime_seg1_min,
  983. phba->ktime_seg1_max);
  984. len += scnprintf(buf + len, PAGE_SIZE-len,
  985. "Segment 2: cmd pass to NVME Layer- "
  986. "-to- Driver rcv cmd OP (action)\n");
  987. len += scnprintf(buf + len, PAGE_SIZE-len,
  988. "avg:%08lld min:%08lld max %08lld\n",
  989. div_u64(phba->ktime_seg2_total,
  990. phba->ktime_data_samples),
  991. phba->ktime_seg2_min,
  992. phba->ktime_seg2_max);
  993. len += scnprintf(buf + len, PAGE_SIZE-len,
  994. "Segment 3: Driver rcv cmd OP -to- "
  995. "Firmware WQ doorbell: cmd\n");
  996. len += scnprintf(buf + len, PAGE_SIZE-len,
  997. "avg:%08lld min:%08lld max %08lld\n",
  998. div_u64(phba->ktime_seg3_total,
  999. phba->ktime_data_samples),
  1000. phba->ktime_seg3_min,
  1001. phba->ktime_seg3_max);
  1002. len += scnprintf(buf + len, PAGE_SIZE-len,
  1003. "Segment 4: Firmware WQ doorbell: cmd "
  1004. "-to- MSI-X ISR for cmd cmpl\n");
  1005. len += scnprintf(buf + len, PAGE_SIZE-len,
  1006. "avg:%08lld min:%08lld max %08lld\n",
  1007. div_u64(phba->ktime_seg4_total,
  1008. phba->ktime_data_samples),
  1009. phba->ktime_seg4_min,
  1010. phba->ktime_seg4_max);
  1011. len += scnprintf(buf + len, PAGE_SIZE-len,
  1012. "Segment 5: MSI-X ISR for cmd cmpl "
  1013. "-to- NVME layer passed cmd done\n");
  1014. len += scnprintf(buf + len, PAGE_SIZE-len,
  1015. "avg:%08lld min:%08lld max %08lld\n",
  1016. div_u64(phba->ktime_seg5_total,
  1017. phba->ktime_data_samples),
  1018. phba->ktime_seg5_min,
  1019. phba->ktime_seg5_max);
  1020. if (phba->ktime_status_samples == 0) {
  1021. len += scnprintf(buf + len, PAGE_SIZE-len,
  1022. "Total: cmd received by MSI-X ISR "
  1023. "-to- cmd completed on wire\n");
  1024. len += scnprintf(buf + len, PAGE_SIZE-len,
  1025. "avg:%08lld min:%08lld "
  1026. "max %08lld\n",
  1027. div_u64(phba->ktime_seg10_total,
  1028. phba->ktime_data_samples),
  1029. phba->ktime_seg10_min,
  1030. phba->ktime_seg10_max);
  1031. return len;
  1032. }
  1033. len += scnprintf(buf + len, PAGE_SIZE-len,
  1034. "Segment 6: NVME layer passed cmd done "
  1035. "-to- Driver rcv rsp status OP\n");
  1036. len += scnprintf(buf + len, PAGE_SIZE-len,
  1037. "avg:%08lld min:%08lld max %08lld\n",
  1038. div_u64(phba->ktime_seg6_total,
  1039. phba->ktime_status_samples),
  1040. phba->ktime_seg6_min,
  1041. phba->ktime_seg6_max);
  1042. len += scnprintf(buf + len, PAGE_SIZE-len,
  1043. "Segment 7: Driver rcv rsp status OP "
  1044. "-to- Firmware WQ doorbell: status\n");
  1045. len += scnprintf(buf + len, PAGE_SIZE-len,
  1046. "avg:%08lld min:%08lld max %08lld\n",
  1047. div_u64(phba->ktime_seg7_total,
  1048. phba->ktime_status_samples),
  1049. phba->ktime_seg7_min,
  1050. phba->ktime_seg7_max);
  1051. len += scnprintf(buf + len, PAGE_SIZE-len,
  1052. "Segment 8: Firmware WQ doorbell: status"
  1053. " -to- MSI-X ISR for status cmpl\n");
  1054. len += scnprintf(buf + len, PAGE_SIZE-len,
  1055. "avg:%08lld min:%08lld max %08lld\n",
  1056. div_u64(phba->ktime_seg8_total,
  1057. phba->ktime_status_samples),
  1058. phba->ktime_seg8_min,
  1059. phba->ktime_seg8_max);
  1060. len += scnprintf(buf + len, PAGE_SIZE-len,
  1061. "Segment 9: MSI-X ISR for status cmpl "
  1062. "-to- NVME layer passed status done\n");
  1063. len += scnprintf(buf + len, PAGE_SIZE-len,
  1064. "avg:%08lld min:%08lld max %08lld\n",
  1065. div_u64(phba->ktime_seg9_total,
  1066. phba->ktime_status_samples),
  1067. phba->ktime_seg9_min,
  1068. phba->ktime_seg9_max);
  1069. len += scnprintf(buf + len, PAGE_SIZE-len,
  1070. "Total: cmd received by MSI-X ISR -to- "
  1071. "cmd completed on wire\n");
  1072. len += scnprintf(buf + len, PAGE_SIZE-len,
  1073. "avg:%08lld min:%08lld max %08lld\n",
  1074. div_u64(phba->ktime_seg10_total,
  1075. phba->ktime_status_samples),
  1076. phba->ktime_seg10_min,
  1077. phba->ktime_seg10_max);
  1078. return len;
  1079. }
  1080. /**
  1081. * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
  1082. * @phba: The phba to gather target node info from.
  1083. * @buf: The buffer to dump log into.
  1084. * @size: The maximum amount of data to process.
  1085. *
  1086. * Description:
  1087. * This routine dumps the NVME IO trace associated with @phba
  1088. *
  1089. * Return Value:
  1090. * This routine returns the amount of bytes that were dumped into @buf and will
  1091. * not exceed @size.
  1092. **/
  1093. static int
  1094. lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
  1095. {
  1096. struct lpfc_debugfs_nvmeio_trc *dtp;
  1097. int i, state, index, skip;
  1098. int len = 0;
  1099. state = phba->nvmeio_trc_on;
  1100. index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
  1101. (phba->nvmeio_trc_size - 1);
  1102. skip = phba->nvmeio_trc_output_idx;
  1103. len += scnprintf(buf + len, size - len,
  1104. "%s IO Trace %s: next_idx %d skip %d size %d\n",
  1105. (phba->nvmet_support ? "NVME" : "NVMET"),
  1106. (state ? "Enabled" : "Disabled"),
  1107. index, skip, phba->nvmeio_trc_size);
  1108. if (!phba->nvmeio_trc || state)
  1109. return len;
  1110. /* trace MUST bhe off to continue */
  1111. for (i = index; i < phba->nvmeio_trc_size; i++) {
  1112. if (skip) {
  1113. skip--;
  1114. continue;
  1115. }
  1116. dtp = phba->nvmeio_trc + i;
  1117. phba->nvmeio_trc_output_idx++;
  1118. if (!dtp->fmt)
  1119. continue;
  1120. len += scnprintf(buf + len, size - len, dtp->fmt,
  1121. dtp->data1, dtp->data2, dtp->data3);
  1122. if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
  1123. phba->nvmeio_trc_output_idx = 0;
  1124. len += scnprintf(buf + len, size - len,
  1125. "Trace Complete\n");
  1126. goto out;
  1127. }
  1128. if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
  1129. len += scnprintf(buf + len, size - len,
  1130. "Trace Continue (%d of %d)\n",
  1131. phba->nvmeio_trc_output_idx,
  1132. phba->nvmeio_trc_size);
  1133. goto out;
  1134. }
  1135. }
  1136. for (i = 0; i < index; i++) {
  1137. if (skip) {
  1138. skip--;
  1139. continue;
  1140. }
  1141. dtp = phba->nvmeio_trc + i;
  1142. phba->nvmeio_trc_output_idx++;
  1143. if (!dtp->fmt)
  1144. continue;
  1145. len += scnprintf(buf + len, size - len, dtp->fmt,
  1146. dtp->data1, dtp->data2, dtp->data3);
  1147. if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
  1148. phba->nvmeio_trc_output_idx = 0;
  1149. len += scnprintf(buf + len, size - len,
  1150. "Trace Complete\n");
  1151. goto out;
  1152. }
  1153. if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
  1154. len += scnprintf(buf + len, size - len,
  1155. "Trace Continue (%d of %d)\n",
  1156. phba->nvmeio_trc_output_idx,
  1157. phba->nvmeio_trc_size);
  1158. goto out;
  1159. }
  1160. }
  1161. len += scnprintf(buf + len, size - len,
  1162. "Trace Done\n");
  1163. out:
  1164. return len;
  1165. }
  1166. /**
  1167. * lpfc_debugfs_cpucheck_data - Dump target node list to a buffer
  1168. * @vport: The vport to gather target node info from.
  1169. * @buf: The buffer to dump log into.
  1170. * @size: The maximum amount of data to process.
  1171. *
  1172. * Description:
  1173. * This routine dumps the NVME statistics associated with @vport
  1174. *
  1175. * Return Value:
  1176. * This routine returns the amount of bytes that were dumped into @buf and will
  1177. * not exceed @size.
  1178. **/
  1179. static int
  1180. lpfc_debugfs_cpucheck_data(struct lpfc_vport *vport, char *buf, int size)
  1181. {
  1182. struct lpfc_hba *phba = vport->phba;
  1183. int i;
  1184. int len = 0;
  1185. uint32_t tot_xmt = 0;
  1186. uint32_t tot_rcv = 0;
  1187. uint32_t tot_cmpl = 0;
  1188. uint32_t tot_ccmpl = 0;
  1189. if (phba->nvmet_support == 0) {
  1190. /* NVME Initiator */
  1191. len += scnprintf(buf + len, PAGE_SIZE - len,
  1192. "CPUcheck %s\n",
  1193. (phba->cpucheck_on & LPFC_CHECK_NVME_IO ?
  1194. "Enabled" : "Disabled"));
  1195. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  1196. if (i >= LPFC_CHECK_CPU_CNT)
  1197. break;
  1198. len += scnprintf(buf + len, PAGE_SIZE - len,
  1199. "%02d: xmit x%08x cmpl x%08x\n",
  1200. i, phba->cpucheck_xmt_io[i],
  1201. phba->cpucheck_cmpl_io[i]);
  1202. tot_xmt += phba->cpucheck_xmt_io[i];
  1203. tot_cmpl += phba->cpucheck_cmpl_io[i];
  1204. }
  1205. len += scnprintf(buf + len, PAGE_SIZE - len,
  1206. "tot:xmit x%08x cmpl x%08x\n",
  1207. tot_xmt, tot_cmpl);
  1208. return len;
  1209. }
  1210. /* NVME Target */
  1211. len += scnprintf(buf + len, PAGE_SIZE - len,
  1212. "CPUcheck %s ",
  1213. (phba->cpucheck_on & LPFC_CHECK_NVMET_IO ?
  1214. "IO Enabled - " : "IO Disabled - "));
  1215. len += scnprintf(buf + len, PAGE_SIZE - len,
  1216. "%s\n",
  1217. (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV ?
  1218. "Rcv Enabled\n" : "Rcv Disabled\n"));
  1219. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  1220. if (i >= LPFC_CHECK_CPU_CNT)
  1221. break;
  1222. len += scnprintf(buf + len, PAGE_SIZE - len,
  1223. "%02d: xmit x%08x ccmpl x%08x "
  1224. "cmpl x%08x rcv x%08x\n",
  1225. i, phba->cpucheck_xmt_io[i],
  1226. phba->cpucheck_ccmpl_io[i],
  1227. phba->cpucheck_cmpl_io[i],
  1228. phba->cpucheck_rcv_io[i]);
  1229. tot_xmt += phba->cpucheck_xmt_io[i];
  1230. tot_rcv += phba->cpucheck_rcv_io[i];
  1231. tot_cmpl += phba->cpucheck_cmpl_io[i];
  1232. tot_ccmpl += phba->cpucheck_ccmpl_io[i];
  1233. }
  1234. len += scnprintf(buf + len, PAGE_SIZE - len,
  1235. "tot:xmit x%08x ccmpl x%08x cmpl x%08x rcv x%08x\n",
  1236. tot_xmt, tot_ccmpl, tot_cmpl, tot_rcv);
  1237. return len;
  1238. }
  1239. #endif
  1240. /**
  1241. * lpfc_debugfs_disc_trc - Store discovery trace log
  1242. * @vport: The vport to associate this trace string with for retrieval.
  1243. * @mask: Log entry classification.
  1244. * @fmt: Format string to be displayed when dumping the log.
  1245. * @data1: 1st data parameter to be applied to @fmt.
  1246. * @data2: 2nd data parameter to be applied to @fmt.
  1247. * @data3: 3rd data parameter to be applied to @fmt.
  1248. *
  1249. * Description:
  1250. * This routine is used by the driver code to add a debugfs log entry to the
  1251. * discovery trace buffer associated with @vport. Only entries with a @mask that
  1252. * match the current debugfs discovery mask will be saved. Entries that do not
  1253. * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
  1254. * printf when displaying the log.
  1255. **/
  1256. inline void
  1257. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  1258. uint32_t data1, uint32_t data2, uint32_t data3)
  1259. {
  1260. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1261. struct lpfc_debugfs_trc *dtp;
  1262. int index;
  1263. if (!(lpfc_debugfs_mask_disc_trc & mask))
  1264. return;
  1265. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  1266. !vport || !vport->disc_trc)
  1267. return;
  1268. index = atomic_inc_return(&vport->disc_trc_cnt) &
  1269. (lpfc_debugfs_max_disc_trc - 1);
  1270. dtp = vport->disc_trc + index;
  1271. dtp->fmt = fmt;
  1272. dtp->data1 = data1;
  1273. dtp->data2 = data2;
  1274. dtp->data3 = data3;
  1275. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  1276. dtp->jif = jiffies;
  1277. #endif
  1278. return;
  1279. }
  1280. /**
  1281. * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
  1282. * @phba: The phba to associate this trace string with for retrieval.
  1283. * @fmt: Format string to be displayed when dumping the log.
  1284. * @data1: 1st data parameter to be applied to @fmt.
  1285. * @data2: 2nd data parameter to be applied to @fmt.
  1286. * @data3: 3rd data parameter to be applied to @fmt.
  1287. *
  1288. * Description:
  1289. * This routine is used by the driver code to add a debugfs log entry to the
  1290. * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
  1291. * @data3 are used like printf when displaying the log.
  1292. **/
  1293. inline void
  1294. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  1295. uint32_t data1, uint32_t data2, uint32_t data3)
  1296. {
  1297. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1298. struct lpfc_debugfs_trc *dtp;
  1299. int index;
  1300. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  1301. !phba || !phba->slow_ring_trc)
  1302. return;
  1303. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  1304. (lpfc_debugfs_max_slow_ring_trc - 1);
  1305. dtp = phba->slow_ring_trc + index;
  1306. dtp->fmt = fmt;
  1307. dtp->data1 = data1;
  1308. dtp->data2 = data2;
  1309. dtp->data3 = data3;
  1310. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  1311. dtp->jif = jiffies;
  1312. #endif
  1313. return;
  1314. }
  1315. /**
  1316. * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
  1317. * @phba: The phba to associate this trace string with for retrieval.
  1318. * @fmt: Format string to be displayed when dumping the log.
  1319. * @data1: 1st data parameter to be applied to @fmt.
  1320. * @data2: 2nd data parameter to be applied to @fmt.
  1321. * @data3: 3rd data parameter to be applied to @fmt.
  1322. *
  1323. * Description:
  1324. * This routine is used by the driver code to add a debugfs log entry to the
  1325. * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
  1326. * @data3 are used like printf when displaying the log.
  1327. **/
  1328. inline void
  1329. lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
  1330. uint16_t data1, uint16_t data2, uint32_t data3)
  1331. {
  1332. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1333. struct lpfc_debugfs_nvmeio_trc *dtp;
  1334. int index;
  1335. if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
  1336. return;
  1337. index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
  1338. (phba->nvmeio_trc_size - 1);
  1339. dtp = phba->nvmeio_trc + index;
  1340. dtp->fmt = fmt;
  1341. dtp->data1 = data1;
  1342. dtp->data2 = data2;
  1343. dtp->data3 = data3;
  1344. #endif
  1345. }
  1346. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1347. /**
  1348. * lpfc_debugfs_disc_trc_open - Open the discovery trace log
  1349. * @inode: The inode pointer that contains a vport pointer.
  1350. * @file: The file pointer to attach the log output.
  1351. *
  1352. * Description:
  1353. * This routine is the entry point for the debugfs open file operation. It gets
  1354. * the vport from the i_private field in @inode, allocates the necessary buffer
  1355. * for the log, fills the buffer from the in-memory log for this vport, and then
  1356. * returns a pointer to that log in the private_data field in @file.
  1357. *
  1358. * Returns:
  1359. * This function returns zero if successful. On error it will return a negative
  1360. * error value.
  1361. **/
  1362. static int
  1363. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  1364. {
  1365. struct lpfc_vport *vport = inode->i_private;
  1366. struct lpfc_debug *debug;
  1367. int size;
  1368. int rc = -ENOMEM;
  1369. if (!lpfc_debugfs_max_disc_trc) {
  1370. rc = -ENOSPC;
  1371. goto out;
  1372. }
  1373. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1374. if (!debug)
  1375. goto out;
  1376. /* Round to page boundary */
  1377. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  1378. size = PAGE_ALIGN(size);
  1379. debug->buffer = kmalloc(size, GFP_KERNEL);
  1380. if (!debug->buffer) {
  1381. kfree(debug);
  1382. goto out;
  1383. }
  1384. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  1385. file->private_data = debug;
  1386. rc = 0;
  1387. out:
  1388. return rc;
  1389. }
  1390. /**
  1391. * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
  1392. * @inode: The inode pointer that contains a vport pointer.
  1393. * @file: The file pointer to attach the log output.
  1394. *
  1395. * Description:
  1396. * This routine is the entry point for the debugfs open file operation. It gets
  1397. * the vport from the i_private field in @inode, allocates the necessary buffer
  1398. * for the log, fills the buffer from the in-memory log for this vport, and then
  1399. * returns a pointer to that log in the private_data field in @file.
  1400. *
  1401. * Returns:
  1402. * This function returns zero if successful. On error it will return a negative
  1403. * error value.
  1404. **/
  1405. static int
  1406. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  1407. {
  1408. struct lpfc_hba *phba = inode->i_private;
  1409. struct lpfc_debug *debug;
  1410. int size;
  1411. int rc = -ENOMEM;
  1412. if (!lpfc_debugfs_max_slow_ring_trc) {
  1413. rc = -ENOSPC;
  1414. goto out;
  1415. }
  1416. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1417. if (!debug)
  1418. goto out;
  1419. /* Round to page boundary */
  1420. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  1421. size = PAGE_ALIGN(size);
  1422. debug->buffer = kmalloc(size, GFP_KERNEL);
  1423. if (!debug->buffer) {
  1424. kfree(debug);
  1425. goto out;
  1426. }
  1427. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  1428. file->private_data = debug;
  1429. rc = 0;
  1430. out:
  1431. return rc;
  1432. }
  1433. /**
  1434. * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
  1435. * @inode: The inode pointer that contains a vport pointer.
  1436. * @file: The file pointer to attach the log output.
  1437. *
  1438. * Description:
  1439. * This routine is the entry point for the debugfs open file operation. It gets
  1440. * the vport from the i_private field in @inode, allocates the necessary buffer
  1441. * for the log, fills the buffer from the in-memory log for this vport, and then
  1442. * returns a pointer to that log in the private_data field in @file.
  1443. *
  1444. * Returns:
  1445. * This function returns zero if successful. On error it will return a negative
  1446. * error value.
  1447. **/
  1448. static int
  1449. lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
  1450. {
  1451. struct lpfc_hba *phba = inode->i_private;
  1452. struct lpfc_debug *debug;
  1453. int rc = -ENOMEM;
  1454. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1455. if (!debug)
  1456. goto out;
  1457. /* Round to page boundary */
  1458. debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
  1459. if (!debug->buffer) {
  1460. kfree(debug);
  1461. goto out;
  1462. }
  1463. debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
  1464. LPFC_HBQINFO_SIZE);
  1465. file->private_data = debug;
  1466. rc = 0;
  1467. out:
  1468. return rc;
  1469. }
  1470. /**
  1471. * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
  1472. * @inode: The inode pointer that contains a vport pointer.
  1473. * @file: The file pointer to attach the log output.
  1474. *
  1475. * Description:
  1476. * This routine is the entry point for the debugfs open file operation. It gets
  1477. * the vport from the i_private field in @inode, allocates the necessary buffer
  1478. * for the log, fills the buffer from the in-memory log for this vport, and then
  1479. * returns a pointer to that log in the private_data field in @file.
  1480. *
  1481. * Returns:
  1482. * This function returns zero if successful. On error it will return a negative
  1483. * error value.
  1484. **/
  1485. static int
  1486. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  1487. {
  1488. struct lpfc_hba *phba = inode->i_private;
  1489. struct lpfc_debug *debug;
  1490. int rc = -ENOMEM;
  1491. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1492. if (!debug)
  1493. goto out;
  1494. /* Round to page boundary */
  1495. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  1496. if (!debug->buffer) {
  1497. kfree(debug);
  1498. goto out;
  1499. }
  1500. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  1501. LPFC_DUMPHBASLIM_SIZE);
  1502. file->private_data = debug;
  1503. rc = 0;
  1504. out:
  1505. return rc;
  1506. }
  1507. /**
  1508. * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
  1509. * @inode: The inode pointer that contains a vport pointer.
  1510. * @file: The file pointer to attach the log output.
  1511. *
  1512. * Description:
  1513. * This routine is the entry point for the debugfs open file operation. It gets
  1514. * the vport from the i_private field in @inode, allocates the necessary buffer
  1515. * for the log, fills the buffer from the in-memory log for this vport, and then
  1516. * returns a pointer to that log in the private_data field in @file.
  1517. *
  1518. * Returns:
  1519. * This function returns zero if successful. On error it will return a negative
  1520. * error value.
  1521. **/
  1522. static int
  1523. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  1524. {
  1525. struct lpfc_hba *phba = inode->i_private;
  1526. struct lpfc_debug *debug;
  1527. int rc = -ENOMEM;
  1528. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1529. if (!debug)
  1530. goto out;
  1531. /* Round to page boundary */
  1532. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  1533. if (!debug->buffer) {
  1534. kfree(debug);
  1535. goto out;
  1536. }
  1537. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  1538. LPFC_DUMPHOSTSLIM_SIZE);
  1539. file->private_data = debug;
  1540. rc = 0;
  1541. out:
  1542. return rc;
  1543. }
  1544. static int
  1545. lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
  1546. {
  1547. struct lpfc_debug *debug;
  1548. int rc = -ENOMEM;
  1549. if (!_dump_buf_data)
  1550. return -EBUSY;
  1551. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1552. if (!debug)
  1553. goto out;
  1554. /* Round to page boundary */
  1555. pr_err("9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
  1556. __func__, _dump_buf_data);
  1557. debug->buffer = _dump_buf_data;
  1558. if (!debug->buffer) {
  1559. kfree(debug);
  1560. goto out;
  1561. }
  1562. debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
  1563. file->private_data = debug;
  1564. rc = 0;
  1565. out:
  1566. return rc;
  1567. }
  1568. static int
  1569. lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
  1570. {
  1571. struct lpfc_debug *debug;
  1572. int rc = -ENOMEM;
  1573. if (!_dump_buf_dif)
  1574. return -EBUSY;
  1575. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1576. if (!debug)
  1577. goto out;
  1578. /* Round to page boundary */
  1579. pr_err("9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%pD\n",
  1580. __func__, _dump_buf_dif, file);
  1581. debug->buffer = _dump_buf_dif;
  1582. if (!debug->buffer) {
  1583. kfree(debug);
  1584. goto out;
  1585. }
  1586. debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
  1587. file->private_data = debug;
  1588. rc = 0;
  1589. out:
  1590. return rc;
  1591. }
  1592. static ssize_t
  1593. lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
  1594. size_t nbytes, loff_t *ppos)
  1595. {
  1596. /*
  1597. * The Data/DIF buffers only save one failing IO
  1598. * The write op is used as a reset mechanism after an IO has
  1599. * already been saved to the next one can be saved
  1600. */
  1601. spin_lock(&_dump_buf_lock);
  1602. memset((void *)_dump_buf_data, 0,
  1603. ((1 << PAGE_SHIFT) << _dump_buf_data_order));
  1604. memset((void *)_dump_buf_dif, 0,
  1605. ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
  1606. _dump_buf_done = 0;
  1607. spin_unlock(&_dump_buf_lock);
  1608. return nbytes;
  1609. }
  1610. static ssize_t
  1611. lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
  1612. size_t nbytes, loff_t *ppos)
  1613. {
  1614. struct dentry *dent = file->f_path.dentry;
  1615. struct lpfc_hba *phba = file->private_data;
  1616. char cbuf[32];
  1617. uint64_t tmp = 0;
  1618. int cnt = 0;
  1619. if (dent == phba->debug_writeGuard)
  1620. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
  1621. else if (dent == phba->debug_writeApp)
  1622. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
  1623. else if (dent == phba->debug_writeRef)
  1624. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
  1625. else if (dent == phba->debug_readGuard)
  1626. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
  1627. else if (dent == phba->debug_readApp)
  1628. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
  1629. else if (dent == phba->debug_readRef)
  1630. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
  1631. else if (dent == phba->debug_InjErrNPortID)
  1632. cnt = scnprintf(cbuf, 32, "0x%06x\n",
  1633. phba->lpfc_injerr_nportid);
  1634. else if (dent == phba->debug_InjErrWWPN) {
  1635. memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
  1636. tmp = cpu_to_be64(tmp);
  1637. cnt = scnprintf(cbuf, 32, "0x%016llx\n", tmp);
  1638. } else if (dent == phba->debug_InjErrLBA) {
  1639. if (phba->lpfc_injerr_lba == (sector_t)(-1))
  1640. cnt = scnprintf(cbuf, 32, "off\n");
  1641. else
  1642. cnt = scnprintf(cbuf, 32, "0x%llx\n",
  1643. (uint64_t) phba->lpfc_injerr_lba);
  1644. } else
  1645. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1646. "0547 Unknown debugfs error injection entry\n");
  1647. return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
  1648. }
  1649. static ssize_t
  1650. lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
  1651. size_t nbytes, loff_t *ppos)
  1652. {
  1653. struct dentry *dent = file->f_path.dentry;
  1654. struct lpfc_hba *phba = file->private_data;
  1655. char dstbuf[33];
  1656. uint64_t tmp = 0;
  1657. int size;
  1658. memset(dstbuf, 0, 33);
  1659. size = (nbytes < 32) ? nbytes : 32;
  1660. if (copy_from_user(dstbuf, buf, size))
  1661. return 0;
  1662. if (dent == phba->debug_InjErrLBA) {
  1663. if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
  1664. tmp = (uint64_t)(-1);
  1665. }
  1666. if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
  1667. return 0;
  1668. if (dent == phba->debug_writeGuard)
  1669. phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
  1670. else if (dent == phba->debug_writeApp)
  1671. phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
  1672. else if (dent == phba->debug_writeRef)
  1673. phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
  1674. else if (dent == phba->debug_readGuard)
  1675. phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
  1676. else if (dent == phba->debug_readApp)
  1677. phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
  1678. else if (dent == phba->debug_readRef)
  1679. phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
  1680. else if (dent == phba->debug_InjErrLBA)
  1681. phba->lpfc_injerr_lba = (sector_t)tmp;
  1682. else if (dent == phba->debug_InjErrNPortID)
  1683. phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
  1684. else if (dent == phba->debug_InjErrWWPN) {
  1685. tmp = cpu_to_be64(tmp);
  1686. memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
  1687. } else
  1688. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1689. "0548 Unknown debugfs error injection entry\n");
  1690. return nbytes;
  1691. }
  1692. static int
  1693. lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
  1694. {
  1695. return 0;
  1696. }
  1697. /**
  1698. * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
  1699. * @inode: The inode pointer that contains a vport pointer.
  1700. * @file: The file pointer to attach the log output.
  1701. *
  1702. * Description:
  1703. * This routine is the entry point for the debugfs open file operation. It gets
  1704. * the vport from the i_private field in @inode, allocates the necessary buffer
  1705. * for the log, fills the buffer from the in-memory log for this vport, and then
  1706. * returns a pointer to that log in the private_data field in @file.
  1707. *
  1708. * Returns:
  1709. * This function returns zero if successful. On error it will return a negative
  1710. * error value.
  1711. **/
  1712. static int
  1713. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  1714. {
  1715. struct lpfc_vport *vport = inode->i_private;
  1716. struct lpfc_debug *debug;
  1717. int rc = -ENOMEM;
  1718. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1719. if (!debug)
  1720. goto out;
  1721. /* Round to page boundary */
  1722. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  1723. if (!debug->buffer) {
  1724. kfree(debug);
  1725. goto out;
  1726. }
  1727. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  1728. LPFC_NODELIST_SIZE);
  1729. file->private_data = debug;
  1730. rc = 0;
  1731. out:
  1732. return rc;
  1733. }
  1734. /**
  1735. * lpfc_debugfs_lseek - Seek through a debugfs file
  1736. * @file: The file pointer to seek through.
  1737. * @off: The offset to seek to or the amount to seek by.
  1738. * @whence: Indicates how to seek.
  1739. *
  1740. * Description:
  1741. * This routine is the entry point for the debugfs lseek file operation. The
  1742. * @whence parameter indicates whether @off is the offset to directly seek to,
  1743. * or if it is a value to seek forward or reverse by. This function figures out
  1744. * what the new offset of the debugfs file will be and assigns that value to the
  1745. * f_pos field of @file.
  1746. *
  1747. * Returns:
  1748. * This function returns the new offset if successful and returns a negative
  1749. * error if unable to process the seek.
  1750. **/
  1751. static loff_t
  1752. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  1753. {
  1754. struct lpfc_debug *debug = file->private_data;
  1755. return fixed_size_llseek(file, off, whence, debug->len);
  1756. }
  1757. /**
  1758. * lpfc_debugfs_read - Read a debugfs file
  1759. * @file: The file pointer to read from.
  1760. * @buf: The buffer to copy the data to.
  1761. * @nbytes: The number of bytes to read.
  1762. * @ppos: The position in the file to start reading from.
  1763. *
  1764. * Description:
  1765. * This routine reads data from from the buffer indicated in the private_data
  1766. * field of @file. It will start reading at @ppos and copy up to @nbytes of
  1767. * data to @buf.
  1768. *
  1769. * Returns:
  1770. * This function returns the amount of data that was read (this could be less
  1771. * than @nbytes if the end of the file was reached) or a negative error value.
  1772. **/
  1773. static ssize_t
  1774. lpfc_debugfs_read(struct file *file, char __user *buf,
  1775. size_t nbytes, loff_t *ppos)
  1776. {
  1777. struct lpfc_debug *debug = file->private_data;
  1778. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  1779. debug->len);
  1780. }
  1781. /**
  1782. * lpfc_debugfs_release - Release the buffer used to store debugfs file data
  1783. * @inode: The inode pointer that contains a vport pointer. (unused)
  1784. * @file: The file pointer that contains the buffer to release.
  1785. *
  1786. * Description:
  1787. * This routine frees the buffer that was allocated when the debugfs file was
  1788. * opened.
  1789. *
  1790. * Returns:
  1791. * This function returns zero.
  1792. **/
  1793. static int
  1794. lpfc_debugfs_release(struct inode *inode, struct file *file)
  1795. {
  1796. struct lpfc_debug *debug = file->private_data;
  1797. kfree(debug->buffer);
  1798. kfree(debug);
  1799. return 0;
  1800. }
  1801. static int
  1802. lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
  1803. {
  1804. struct lpfc_debug *debug = file->private_data;
  1805. debug->buffer = NULL;
  1806. kfree(debug);
  1807. return 0;
  1808. }
  1809. static int
  1810. lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
  1811. {
  1812. struct lpfc_vport *vport = inode->i_private;
  1813. struct lpfc_debug *debug;
  1814. int rc = -ENOMEM;
  1815. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1816. if (!debug)
  1817. goto out;
  1818. /* Round to page boundary */
  1819. debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
  1820. if (!debug->buffer) {
  1821. kfree(debug);
  1822. goto out;
  1823. }
  1824. debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
  1825. LPFC_NVMESTAT_SIZE);
  1826. debug->i_private = inode->i_private;
  1827. file->private_data = debug;
  1828. rc = 0;
  1829. out:
  1830. return rc;
  1831. }
  1832. static ssize_t
  1833. lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
  1834. size_t nbytes, loff_t *ppos)
  1835. {
  1836. struct lpfc_debug *debug = file->private_data;
  1837. struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
  1838. struct lpfc_hba *phba = vport->phba;
  1839. struct lpfc_nvmet_tgtport *tgtp;
  1840. char mybuf[64];
  1841. char *pbuf;
  1842. if (!phba->targetport)
  1843. return -ENXIO;
  1844. if (nbytes > 64)
  1845. nbytes = 64;
  1846. memset(mybuf, 0, sizeof(mybuf));
  1847. if (copy_from_user(mybuf, buf, nbytes))
  1848. return -EFAULT;
  1849. pbuf = &mybuf[0];
  1850. tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
  1851. if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
  1852. (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
  1853. atomic_set(&tgtp->rcv_ls_req_in, 0);
  1854. atomic_set(&tgtp->rcv_ls_req_out, 0);
  1855. atomic_set(&tgtp->rcv_ls_req_drop, 0);
  1856. atomic_set(&tgtp->xmt_ls_abort, 0);
  1857. atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
  1858. atomic_set(&tgtp->xmt_ls_rsp, 0);
  1859. atomic_set(&tgtp->xmt_ls_drop, 0);
  1860. atomic_set(&tgtp->xmt_ls_rsp_error, 0);
  1861. atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
  1862. atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
  1863. atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
  1864. atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
  1865. atomic_set(&tgtp->xmt_fcp_drop, 0);
  1866. atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
  1867. atomic_set(&tgtp->xmt_fcp_read, 0);
  1868. atomic_set(&tgtp->xmt_fcp_write, 0);
  1869. atomic_set(&tgtp->xmt_fcp_rsp, 0);
  1870. atomic_set(&tgtp->xmt_fcp_release, 0);
  1871. atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
  1872. atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
  1873. atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
  1874. atomic_set(&tgtp->xmt_fcp_abort, 0);
  1875. atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
  1876. atomic_set(&tgtp->xmt_abort_sol, 0);
  1877. atomic_set(&tgtp->xmt_abort_unsol, 0);
  1878. atomic_set(&tgtp->xmt_abort_rsp, 0);
  1879. atomic_set(&tgtp->xmt_abort_rsp_error, 0);
  1880. }
  1881. return nbytes;
  1882. }
  1883. static int
  1884. lpfc_debugfs_nvmektime_open(struct inode *inode, struct file *file)
  1885. {
  1886. struct lpfc_vport *vport = inode->i_private;
  1887. struct lpfc_debug *debug;
  1888. int rc = -ENOMEM;
  1889. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1890. if (!debug)
  1891. goto out;
  1892. /* Round to page boundary */
  1893. debug->buffer = kmalloc(LPFC_NVMEKTIME_SIZE, GFP_KERNEL);
  1894. if (!debug->buffer) {
  1895. kfree(debug);
  1896. goto out;
  1897. }
  1898. debug->len = lpfc_debugfs_nvmektime_data(vport, debug->buffer,
  1899. LPFC_NVMEKTIME_SIZE);
  1900. debug->i_private = inode->i_private;
  1901. file->private_data = debug;
  1902. rc = 0;
  1903. out:
  1904. return rc;
  1905. }
  1906. static ssize_t
  1907. lpfc_debugfs_nvmektime_write(struct file *file, const char __user *buf,
  1908. size_t nbytes, loff_t *ppos)
  1909. {
  1910. struct lpfc_debug *debug = file->private_data;
  1911. struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
  1912. struct lpfc_hba *phba = vport->phba;
  1913. char mybuf[64];
  1914. char *pbuf;
  1915. if (nbytes > 64)
  1916. nbytes = 64;
  1917. memset(mybuf, 0, sizeof(mybuf));
  1918. if (copy_from_user(mybuf, buf, nbytes))
  1919. return -EFAULT;
  1920. pbuf = &mybuf[0];
  1921. if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
  1922. phba->ktime_data_samples = 0;
  1923. phba->ktime_status_samples = 0;
  1924. phba->ktime_seg1_total = 0;
  1925. phba->ktime_seg1_max = 0;
  1926. phba->ktime_seg1_min = 0xffffffff;
  1927. phba->ktime_seg2_total = 0;
  1928. phba->ktime_seg2_max = 0;
  1929. phba->ktime_seg2_min = 0xffffffff;
  1930. phba->ktime_seg3_total = 0;
  1931. phba->ktime_seg3_max = 0;
  1932. phba->ktime_seg3_min = 0xffffffff;
  1933. phba->ktime_seg4_total = 0;
  1934. phba->ktime_seg4_max = 0;
  1935. phba->ktime_seg4_min = 0xffffffff;
  1936. phba->ktime_seg5_total = 0;
  1937. phba->ktime_seg5_max = 0;
  1938. phba->ktime_seg5_min = 0xffffffff;
  1939. phba->ktime_seg6_total = 0;
  1940. phba->ktime_seg6_max = 0;
  1941. phba->ktime_seg6_min = 0xffffffff;
  1942. phba->ktime_seg7_total = 0;
  1943. phba->ktime_seg7_max = 0;
  1944. phba->ktime_seg7_min = 0xffffffff;
  1945. phba->ktime_seg8_total = 0;
  1946. phba->ktime_seg8_max = 0;
  1947. phba->ktime_seg8_min = 0xffffffff;
  1948. phba->ktime_seg9_total = 0;
  1949. phba->ktime_seg9_max = 0;
  1950. phba->ktime_seg9_min = 0xffffffff;
  1951. phba->ktime_seg10_total = 0;
  1952. phba->ktime_seg10_max = 0;
  1953. phba->ktime_seg10_min = 0xffffffff;
  1954. phba->ktime_on = 1;
  1955. return strlen(pbuf);
  1956. } else if ((strncmp(pbuf, "off",
  1957. sizeof("off") - 1) == 0)) {
  1958. phba->ktime_on = 0;
  1959. return strlen(pbuf);
  1960. } else if ((strncmp(pbuf, "zero",
  1961. sizeof("zero") - 1) == 0)) {
  1962. phba->ktime_data_samples = 0;
  1963. phba->ktime_status_samples = 0;
  1964. phba->ktime_seg1_total = 0;
  1965. phba->ktime_seg1_max = 0;
  1966. phba->ktime_seg1_min = 0xffffffff;
  1967. phba->ktime_seg2_total = 0;
  1968. phba->ktime_seg2_max = 0;
  1969. phba->ktime_seg2_min = 0xffffffff;
  1970. phba->ktime_seg3_total = 0;
  1971. phba->ktime_seg3_max = 0;
  1972. phba->ktime_seg3_min = 0xffffffff;
  1973. phba->ktime_seg4_total = 0;
  1974. phba->ktime_seg4_max = 0;
  1975. phba->ktime_seg4_min = 0xffffffff;
  1976. phba->ktime_seg5_total = 0;
  1977. phba->ktime_seg5_max = 0;
  1978. phba->ktime_seg5_min = 0xffffffff;
  1979. phba->ktime_seg6_total = 0;
  1980. phba->ktime_seg6_max = 0;
  1981. phba->ktime_seg6_min = 0xffffffff;
  1982. phba->ktime_seg7_total = 0;
  1983. phba->ktime_seg7_max = 0;
  1984. phba->ktime_seg7_min = 0xffffffff;
  1985. phba->ktime_seg8_total = 0;
  1986. phba->ktime_seg8_max = 0;
  1987. phba->ktime_seg8_min = 0xffffffff;
  1988. phba->ktime_seg9_total = 0;
  1989. phba->ktime_seg9_max = 0;
  1990. phba->ktime_seg9_min = 0xffffffff;
  1991. phba->ktime_seg10_total = 0;
  1992. phba->ktime_seg10_max = 0;
  1993. phba->ktime_seg10_min = 0xffffffff;
  1994. return strlen(pbuf);
  1995. }
  1996. return -EINVAL;
  1997. }
  1998. static int
  1999. lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
  2000. {
  2001. struct lpfc_hba *phba = inode->i_private;
  2002. struct lpfc_debug *debug;
  2003. int rc = -ENOMEM;
  2004. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2005. if (!debug)
  2006. goto out;
  2007. /* Round to page boundary */
  2008. debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
  2009. if (!debug->buffer) {
  2010. kfree(debug);
  2011. goto out;
  2012. }
  2013. debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
  2014. LPFC_NVMEIO_TRC_SIZE);
  2015. debug->i_private = inode->i_private;
  2016. file->private_data = debug;
  2017. rc = 0;
  2018. out:
  2019. return rc;
  2020. }
  2021. static ssize_t
  2022. lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
  2023. size_t nbytes, loff_t *ppos)
  2024. {
  2025. struct lpfc_debug *debug = file->private_data;
  2026. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2027. int i;
  2028. unsigned long sz;
  2029. char mybuf[64];
  2030. char *pbuf;
  2031. if (nbytes > 64)
  2032. nbytes = 64;
  2033. memset(mybuf, 0, sizeof(mybuf));
  2034. if (copy_from_user(mybuf, buf, nbytes))
  2035. return -EFAULT;
  2036. pbuf = &mybuf[0];
  2037. if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
  2038. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2039. "0570 nvmeio_trc_off\n");
  2040. phba->nvmeio_trc_output_idx = 0;
  2041. phba->nvmeio_trc_on = 0;
  2042. return strlen(pbuf);
  2043. } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
  2044. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2045. "0571 nvmeio_trc_on\n");
  2046. phba->nvmeio_trc_output_idx = 0;
  2047. phba->nvmeio_trc_on = 1;
  2048. return strlen(pbuf);
  2049. }
  2050. /* We must be off to allocate the trace buffer */
  2051. if (phba->nvmeio_trc_on != 0)
  2052. return -EINVAL;
  2053. /* If not on or off, the parameter is the trace buffer size */
  2054. i = kstrtoul(pbuf, 0, &sz);
  2055. if (i)
  2056. return -EINVAL;
  2057. phba->nvmeio_trc_size = (uint32_t)sz;
  2058. /* It must be a power of 2 - round down */
  2059. i = 0;
  2060. while (sz > 1) {
  2061. sz = sz >> 1;
  2062. i++;
  2063. }
  2064. sz = (1 << i);
  2065. if (phba->nvmeio_trc_size != sz)
  2066. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2067. "0572 nvmeio_trc_size changed to %ld\n",
  2068. sz);
  2069. phba->nvmeio_trc_size = (uint32_t)sz;
  2070. /* If one previously exists, free it */
  2071. kfree(phba->nvmeio_trc);
  2072. /* Allocate new trace buffer and initialize */
  2073. phba->nvmeio_trc = kzalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
  2074. sz), GFP_KERNEL);
  2075. if (!phba->nvmeio_trc) {
  2076. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2077. "0573 Cannot create debugfs "
  2078. "nvmeio_trc buffer\n");
  2079. return -ENOMEM;
  2080. }
  2081. atomic_set(&phba->nvmeio_trc_cnt, 0);
  2082. phba->nvmeio_trc_on = 0;
  2083. phba->nvmeio_trc_output_idx = 0;
  2084. return strlen(pbuf);
  2085. }
  2086. static int
  2087. lpfc_debugfs_cpucheck_open(struct inode *inode, struct file *file)
  2088. {
  2089. struct lpfc_vport *vport = inode->i_private;
  2090. struct lpfc_debug *debug;
  2091. int rc = -ENOMEM;
  2092. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2093. if (!debug)
  2094. goto out;
  2095. /* Round to page boundary */
  2096. debug->buffer = kmalloc(LPFC_CPUCHECK_SIZE, GFP_KERNEL);
  2097. if (!debug->buffer) {
  2098. kfree(debug);
  2099. goto out;
  2100. }
  2101. debug->len = lpfc_debugfs_cpucheck_data(vport, debug->buffer,
  2102. LPFC_NVMEKTIME_SIZE);
  2103. debug->i_private = inode->i_private;
  2104. file->private_data = debug;
  2105. rc = 0;
  2106. out:
  2107. return rc;
  2108. }
  2109. static ssize_t
  2110. lpfc_debugfs_cpucheck_write(struct file *file, const char __user *buf,
  2111. size_t nbytes, loff_t *ppos)
  2112. {
  2113. struct lpfc_debug *debug = file->private_data;
  2114. struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
  2115. struct lpfc_hba *phba = vport->phba;
  2116. char mybuf[64];
  2117. char *pbuf;
  2118. int i;
  2119. if (nbytes > 64)
  2120. nbytes = 64;
  2121. memset(mybuf, 0, sizeof(mybuf));
  2122. if (copy_from_user(mybuf, buf, nbytes))
  2123. return -EFAULT;
  2124. pbuf = &mybuf[0];
  2125. if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
  2126. if (phba->nvmet_support)
  2127. phba->cpucheck_on |= LPFC_CHECK_NVMET_IO;
  2128. else
  2129. phba->cpucheck_on |= LPFC_CHECK_NVME_IO;
  2130. return strlen(pbuf);
  2131. } else if ((strncmp(pbuf, "rcv",
  2132. sizeof("rcv") - 1) == 0)) {
  2133. if (phba->nvmet_support)
  2134. phba->cpucheck_on |= LPFC_CHECK_NVMET_RCV;
  2135. else
  2136. return -EINVAL;
  2137. return strlen(pbuf);
  2138. } else if ((strncmp(pbuf, "off",
  2139. sizeof("off") - 1) == 0)) {
  2140. phba->cpucheck_on = LPFC_CHECK_OFF;
  2141. return strlen(pbuf);
  2142. } else if ((strncmp(pbuf, "zero",
  2143. sizeof("zero") - 1) == 0)) {
  2144. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  2145. if (i >= LPFC_CHECK_CPU_CNT)
  2146. break;
  2147. phba->cpucheck_rcv_io[i] = 0;
  2148. phba->cpucheck_xmt_io[i] = 0;
  2149. phba->cpucheck_cmpl_io[i] = 0;
  2150. phba->cpucheck_ccmpl_io[i] = 0;
  2151. }
  2152. return strlen(pbuf);
  2153. }
  2154. return -EINVAL;
  2155. }
  2156. /*
  2157. * ---------------------------------
  2158. * iDiag debugfs file access methods
  2159. * ---------------------------------
  2160. *
  2161. * All access methods are through the proper SLI4 PCI function's debugfs
  2162. * iDiag directory:
  2163. *
  2164. * /sys/kernel/debug/lpfc/fn<#>/iDiag
  2165. */
  2166. /**
  2167. * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
  2168. * @buf: The pointer to the user space buffer.
  2169. * @nbytes: The number of bytes in the user space buffer.
  2170. * @idiag_cmd: pointer to the idiag command struct.
  2171. *
  2172. * This routine reads data from debugfs user space buffer and parses the
  2173. * buffer for getting the idiag command and arguments. The while space in
  2174. * between the set of data is used as the parsing separator.
  2175. *
  2176. * This routine returns 0 when successful, it returns proper error code
  2177. * back to the user space in error conditions.
  2178. */
  2179. static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
  2180. struct lpfc_idiag_cmd *idiag_cmd)
  2181. {
  2182. char mybuf[64];
  2183. char *pbuf, *step_str;
  2184. int i;
  2185. size_t bsize;
  2186. memset(mybuf, 0, sizeof(mybuf));
  2187. memset(idiag_cmd, 0, sizeof(*idiag_cmd));
  2188. bsize = min(nbytes, (sizeof(mybuf)-1));
  2189. if (copy_from_user(mybuf, buf, bsize))
  2190. return -EFAULT;
  2191. pbuf = &mybuf[0];
  2192. step_str = strsep(&pbuf, "\t ");
  2193. /* The opcode must present */
  2194. if (!step_str)
  2195. return -EINVAL;
  2196. idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
  2197. if (idiag_cmd->opcode == 0)
  2198. return -EINVAL;
  2199. for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
  2200. step_str = strsep(&pbuf, "\t ");
  2201. if (!step_str)
  2202. return i;
  2203. idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
  2204. }
  2205. return i;
  2206. }
  2207. /**
  2208. * lpfc_idiag_open - idiag open debugfs
  2209. * @inode: The inode pointer that contains a pointer to phba.
  2210. * @file: The file pointer to attach the file operation.
  2211. *
  2212. * Description:
  2213. * This routine is the entry point for the debugfs open file operation. It
  2214. * gets the reference to phba from the i_private field in @inode, it then
  2215. * allocates buffer for the file operation, performs the necessary PCI config
  2216. * space read into the allocated buffer according to the idiag user command
  2217. * setup, and then returns a pointer to buffer in the private_data field in
  2218. * @file.
  2219. *
  2220. * Returns:
  2221. * This function returns zero if successful. On error it will return an
  2222. * negative error value.
  2223. **/
  2224. static int
  2225. lpfc_idiag_open(struct inode *inode, struct file *file)
  2226. {
  2227. struct lpfc_debug *debug;
  2228. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2229. if (!debug)
  2230. return -ENOMEM;
  2231. debug->i_private = inode->i_private;
  2232. debug->buffer = NULL;
  2233. file->private_data = debug;
  2234. return 0;
  2235. }
  2236. /**
  2237. * lpfc_idiag_release - Release idiag access file operation
  2238. * @inode: The inode pointer that contains a vport pointer. (unused)
  2239. * @file: The file pointer that contains the buffer to release.
  2240. *
  2241. * Description:
  2242. * This routine is the generic release routine for the idiag access file
  2243. * operation, it frees the buffer that was allocated when the debugfs file
  2244. * was opened.
  2245. *
  2246. * Returns:
  2247. * This function returns zero.
  2248. **/
  2249. static int
  2250. lpfc_idiag_release(struct inode *inode, struct file *file)
  2251. {
  2252. struct lpfc_debug *debug = file->private_data;
  2253. /* Free the buffers to the file operation */
  2254. kfree(debug->buffer);
  2255. kfree(debug);
  2256. return 0;
  2257. }
  2258. /**
  2259. * lpfc_idiag_cmd_release - Release idiag cmd access file operation
  2260. * @inode: The inode pointer that contains a vport pointer. (unused)
  2261. * @file: The file pointer that contains the buffer to release.
  2262. *
  2263. * Description:
  2264. * This routine frees the buffer that was allocated when the debugfs file
  2265. * was opened. It also reset the fields in the idiag command struct in the
  2266. * case of command for write operation.
  2267. *
  2268. * Returns:
  2269. * This function returns zero.
  2270. **/
  2271. static int
  2272. lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
  2273. {
  2274. struct lpfc_debug *debug = file->private_data;
  2275. if (debug->op == LPFC_IDIAG_OP_WR) {
  2276. switch (idiag.cmd.opcode) {
  2277. case LPFC_IDIAG_CMD_PCICFG_WR:
  2278. case LPFC_IDIAG_CMD_PCICFG_ST:
  2279. case LPFC_IDIAG_CMD_PCICFG_CL:
  2280. case LPFC_IDIAG_CMD_QUEACC_WR:
  2281. case LPFC_IDIAG_CMD_QUEACC_ST:
  2282. case LPFC_IDIAG_CMD_QUEACC_CL:
  2283. memset(&idiag, 0, sizeof(idiag));
  2284. break;
  2285. default:
  2286. break;
  2287. }
  2288. }
  2289. /* Free the buffers to the file operation */
  2290. kfree(debug->buffer);
  2291. kfree(debug);
  2292. return 0;
  2293. }
  2294. /**
  2295. * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
  2296. * @file: The file pointer to read from.
  2297. * @buf: The buffer to copy the data to.
  2298. * @nbytes: The number of bytes to read.
  2299. * @ppos: The position in the file to start reading from.
  2300. *
  2301. * Description:
  2302. * This routine reads data from the @phba pci config space according to the
  2303. * idiag command, and copies to user @buf. Depending on the PCI config space
  2304. * read command setup, it does either a single register read of a byte
  2305. * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
  2306. * registers from the 4K extended PCI config space.
  2307. *
  2308. * Returns:
  2309. * This function returns the amount of data that was read (this could be less
  2310. * than @nbytes if the end of the file was reached) or a negative error value.
  2311. **/
  2312. static ssize_t
  2313. lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
  2314. loff_t *ppos)
  2315. {
  2316. struct lpfc_debug *debug = file->private_data;
  2317. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2318. int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
  2319. int where, count;
  2320. char *pbuffer;
  2321. struct pci_dev *pdev;
  2322. uint32_t u32val;
  2323. uint16_t u16val;
  2324. uint8_t u8val;
  2325. pdev = phba->pcidev;
  2326. if (!pdev)
  2327. return 0;
  2328. /* This is a user read operation */
  2329. debug->op = LPFC_IDIAG_OP_RD;
  2330. if (!debug->buffer)
  2331. debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
  2332. if (!debug->buffer)
  2333. return 0;
  2334. pbuffer = debug->buffer;
  2335. if (*ppos)
  2336. return 0;
  2337. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  2338. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  2339. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  2340. } else
  2341. return 0;
  2342. /* Read single PCI config space register */
  2343. switch (count) {
  2344. case SIZE_U8: /* byte (8 bits) */
  2345. pci_read_config_byte(pdev, where, &u8val);
  2346. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2347. "%03x: %02x\n", where, u8val);
  2348. break;
  2349. case SIZE_U16: /* word (16 bits) */
  2350. pci_read_config_word(pdev, where, &u16val);
  2351. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2352. "%03x: %04x\n", where, u16val);
  2353. break;
  2354. case SIZE_U32: /* double word (32 bits) */
  2355. pci_read_config_dword(pdev, where, &u32val);
  2356. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2357. "%03x: %08x\n", where, u32val);
  2358. break;
  2359. case LPFC_PCI_CFG_BROWSE: /* browse all */
  2360. goto pcicfg_browse;
  2361. break;
  2362. default:
  2363. /* illegal count */
  2364. len = 0;
  2365. break;
  2366. }
  2367. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2368. pcicfg_browse:
  2369. /* Browse all PCI config space registers */
  2370. offset_label = idiag.offset.last_rd;
  2371. offset = offset_label;
  2372. /* Read PCI config space */
  2373. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2374. "%03x: ", offset_label);
  2375. while (index > 0) {
  2376. pci_read_config_dword(pdev, offset, &u32val);
  2377. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2378. "%08x ", u32val);
  2379. offset += sizeof(uint32_t);
  2380. if (offset >= LPFC_PCI_CFG_SIZE) {
  2381. len += scnprintf(pbuffer+len,
  2382. LPFC_PCI_CFG_SIZE-len, "\n");
  2383. break;
  2384. }
  2385. index -= sizeof(uint32_t);
  2386. if (!index)
  2387. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2388. "\n");
  2389. else if (!(index % (8 * sizeof(uint32_t)))) {
  2390. offset_label += (8 * sizeof(uint32_t));
  2391. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2392. "\n%03x: ", offset_label);
  2393. }
  2394. }
  2395. /* Set up the offset for next portion of pci cfg read */
  2396. if (index == 0) {
  2397. idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
  2398. if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
  2399. idiag.offset.last_rd = 0;
  2400. } else
  2401. idiag.offset.last_rd = 0;
  2402. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2403. }
  2404. /**
  2405. * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
  2406. * @file: The file pointer to read from.
  2407. * @buf: The buffer to copy the user data from.
  2408. * @nbytes: The number of bytes to get.
  2409. * @ppos: The position in the file to start reading from.
  2410. *
  2411. * This routine get the debugfs idiag command struct from user space and
  2412. * then perform the syntax check for PCI config space read or write command
  2413. * accordingly. In the case of PCI config space read command, it sets up
  2414. * the command in the idiag command struct for the debugfs read operation.
  2415. * In the case of PCI config space write operation, it executes the write
  2416. * operation into the PCI config space accordingly.
  2417. *
  2418. * It returns the @nbytges passing in from debugfs user space when successful.
  2419. * In case of error conditions, it returns proper error code back to the user
  2420. * space.
  2421. */
  2422. static ssize_t
  2423. lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
  2424. size_t nbytes, loff_t *ppos)
  2425. {
  2426. struct lpfc_debug *debug = file->private_data;
  2427. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2428. uint32_t where, value, count;
  2429. uint32_t u32val;
  2430. uint16_t u16val;
  2431. uint8_t u8val;
  2432. struct pci_dev *pdev;
  2433. int rc;
  2434. pdev = phba->pcidev;
  2435. if (!pdev)
  2436. return -EFAULT;
  2437. /* This is a user write operation */
  2438. debug->op = LPFC_IDIAG_OP_WR;
  2439. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2440. if (rc < 0)
  2441. return rc;
  2442. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  2443. /* Sanity check on PCI config read command line arguments */
  2444. if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
  2445. goto error_out;
  2446. /* Read command from PCI config space, set up command fields */
  2447. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  2448. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  2449. if (count == LPFC_PCI_CFG_BROWSE) {
  2450. if (where % sizeof(uint32_t))
  2451. goto error_out;
  2452. /* Starting offset to browse */
  2453. idiag.offset.last_rd = where;
  2454. } else if ((count != sizeof(uint8_t)) &&
  2455. (count != sizeof(uint16_t)) &&
  2456. (count != sizeof(uint32_t)))
  2457. goto error_out;
  2458. if (count == sizeof(uint8_t)) {
  2459. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  2460. goto error_out;
  2461. if (where % sizeof(uint8_t))
  2462. goto error_out;
  2463. }
  2464. if (count == sizeof(uint16_t)) {
  2465. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  2466. goto error_out;
  2467. if (where % sizeof(uint16_t))
  2468. goto error_out;
  2469. }
  2470. if (count == sizeof(uint32_t)) {
  2471. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  2472. goto error_out;
  2473. if (where % sizeof(uint32_t))
  2474. goto error_out;
  2475. }
  2476. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
  2477. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
  2478. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  2479. /* Sanity check on PCI config write command line arguments */
  2480. if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
  2481. goto error_out;
  2482. /* Write command to PCI config space, read-modify-write */
  2483. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  2484. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  2485. value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
  2486. /* Sanity checks */
  2487. if ((count != sizeof(uint8_t)) &&
  2488. (count != sizeof(uint16_t)) &&
  2489. (count != sizeof(uint32_t)))
  2490. goto error_out;
  2491. if (count == sizeof(uint8_t)) {
  2492. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  2493. goto error_out;
  2494. if (where % sizeof(uint8_t))
  2495. goto error_out;
  2496. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  2497. pci_write_config_byte(pdev, where,
  2498. (uint8_t)value);
  2499. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  2500. rc = pci_read_config_byte(pdev, where, &u8val);
  2501. if (!rc) {
  2502. u8val |= (uint8_t)value;
  2503. pci_write_config_byte(pdev, where,
  2504. u8val);
  2505. }
  2506. }
  2507. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  2508. rc = pci_read_config_byte(pdev, where, &u8val);
  2509. if (!rc) {
  2510. u8val &= (uint8_t)(~value);
  2511. pci_write_config_byte(pdev, where,
  2512. u8val);
  2513. }
  2514. }
  2515. }
  2516. if (count == sizeof(uint16_t)) {
  2517. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  2518. goto error_out;
  2519. if (where % sizeof(uint16_t))
  2520. goto error_out;
  2521. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  2522. pci_write_config_word(pdev, where,
  2523. (uint16_t)value);
  2524. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  2525. rc = pci_read_config_word(pdev, where, &u16val);
  2526. if (!rc) {
  2527. u16val |= (uint16_t)value;
  2528. pci_write_config_word(pdev, where,
  2529. u16val);
  2530. }
  2531. }
  2532. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  2533. rc = pci_read_config_word(pdev, where, &u16val);
  2534. if (!rc) {
  2535. u16val &= (uint16_t)(~value);
  2536. pci_write_config_word(pdev, where,
  2537. u16val);
  2538. }
  2539. }
  2540. }
  2541. if (count == sizeof(uint32_t)) {
  2542. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  2543. goto error_out;
  2544. if (where % sizeof(uint32_t))
  2545. goto error_out;
  2546. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  2547. pci_write_config_dword(pdev, where, value);
  2548. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  2549. rc = pci_read_config_dword(pdev, where,
  2550. &u32val);
  2551. if (!rc) {
  2552. u32val |= value;
  2553. pci_write_config_dword(pdev, where,
  2554. u32val);
  2555. }
  2556. }
  2557. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  2558. rc = pci_read_config_dword(pdev, where,
  2559. &u32val);
  2560. if (!rc) {
  2561. u32val &= ~value;
  2562. pci_write_config_dword(pdev, where,
  2563. u32val);
  2564. }
  2565. }
  2566. }
  2567. } else
  2568. /* All other opecodes are illegal for now */
  2569. goto error_out;
  2570. return nbytes;
  2571. error_out:
  2572. memset(&idiag, 0, sizeof(idiag));
  2573. return -EINVAL;
  2574. }
  2575. /**
  2576. * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
  2577. * @file: The file pointer to read from.
  2578. * @buf: The buffer to copy the data to.
  2579. * @nbytes: The number of bytes to read.
  2580. * @ppos: The position in the file to start reading from.
  2581. *
  2582. * Description:
  2583. * This routine reads data from the @phba pci bar memory mapped space
  2584. * according to the idiag command, and copies to user @buf.
  2585. *
  2586. * Returns:
  2587. * This function returns the amount of data that was read (this could be less
  2588. * than @nbytes if the end of the file was reached) or a negative error value.
  2589. **/
  2590. static ssize_t
  2591. lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
  2592. loff_t *ppos)
  2593. {
  2594. struct lpfc_debug *debug = file->private_data;
  2595. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2596. int offset_label, offset, offset_run, len = 0, index;
  2597. int bar_num, acc_range, bar_size;
  2598. char *pbuffer;
  2599. void __iomem *mem_mapped_bar;
  2600. uint32_t if_type;
  2601. struct pci_dev *pdev;
  2602. uint32_t u32val;
  2603. pdev = phba->pcidev;
  2604. if (!pdev)
  2605. return 0;
  2606. /* This is a user read operation */
  2607. debug->op = LPFC_IDIAG_OP_RD;
  2608. if (!debug->buffer)
  2609. debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
  2610. if (!debug->buffer)
  2611. return 0;
  2612. pbuffer = debug->buffer;
  2613. if (*ppos)
  2614. return 0;
  2615. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  2616. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  2617. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  2618. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  2619. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  2620. } else
  2621. return 0;
  2622. if (acc_range == 0)
  2623. return 0;
  2624. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  2625. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  2626. if (bar_num == IDIAG_BARACC_BAR_0)
  2627. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  2628. else if (bar_num == IDIAG_BARACC_BAR_1)
  2629. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  2630. else if (bar_num == IDIAG_BARACC_BAR_2)
  2631. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  2632. else
  2633. return 0;
  2634. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  2635. if (bar_num == IDIAG_BARACC_BAR_0)
  2636. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  2637. else
  2638. return 0;
  2639. } else
  2640. return 0;
  2641. /* Read single PCI bar space register */
  2642. if (acc_range == SINGLE_WORD) {
  2643. offset_run = offset;
  2644. u32val = readl(mem_mapped_bar + offset_run);
  2645. len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  2646. "%05x: %08x\n", offset_run, u32val);
  2647. } else
  2648. goto baracc_browse;
  2649. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2650. baracc_browse:
  2651. /* Browse all PCI bar space registers */
  2652. offset_label = idiag.offset.last_rd;
  2653. offset_run = offset_label;
  2654. /* Read PCI bar memory mapped space */
  2655. len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  2656. "%05x: ", offset_label);
  2657. index = LPFC_PCI_BAR_RD_SIZE;
  2658. while (index > 0) {
  2659. u32val = readl(mem_mapped_bar + offset_run);
  2660. len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  2661. "%08x ", u32val);
  2662. offset_run += sizeof(uint32_t);
  2663. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  2664. if (offset_run >= bar_size) {
  2665. len += scnprintf(pbuffer+len,
  2666. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  2667. break;
  2668. }
  2669. } else {
  2670. if (offset_run >= offset +
  2671. (acc_range * sizeof(uint32_t))) {
  2672. len += scnprintf(pbuffer+len,
  2673. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  2674. break;
  2675. }
  2676. }
  2677. index -= sizeof(uint32_t);
  2678. if (!index)
  2679. len += scnprintf(pbuffer+len,
  2680. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  2681. else if (!(index % (8 * sizeof(uint32_t)))) {
  2682. offset_label += (8 * sizeof(uint32_t));
  2683. len += scnprintf(pbuffer+len,
  2684. LPFC_PCI_BAR_RD_BUF_SIZE-len,
  2685. "\n%05x: ", offset_label);
  2686. }
  2687. }
  2688. /* Set up the offset for next portion of pci bar read */
  2689. if (index == 0) {
  2690. idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
  2691. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  2692. if (idiag.offset.last_rd >= bar_size)
  2693. idiag.offset.last_rd = 0;
  2694. } else {
  2695. if (offset_run >= offset +
  2696. (acc_range * sizeof(uint32_t)))
  2697. idiag.offset.last_rd = offset;
  2698. }
  2699. } else {
  2700. if (acc_range == LPFC_PCI_BAR_BROWSE)
  2701. idiag.offset.last_rd = 0;
  2702. else
  2703. idiag.offset.last_rd = offset;
  2704. }
  2705. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2706. }
  2707. /**
  2708. * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
  2709. * @file: The file pointer to read from.
  2710. * @buf: The buffer to copy the user data from.
  2711. * @nbytes: The number of bytes to get.
  2712. * @ppos: The position in the file to start reading from.
  2713. *
  2714. * This routine get the debugfs idiag command struct from user space and
  2715. * then perform the syntax check for PCI bar memory mapped space read or
  2716. * write command accordingly. In the case of PCI bar memory mapped space
  2717. * read command, it sets up the command in the idiag command struct for
  2718. * the debugfs read operation. In the case of PCI bar memorpy mapped space
  2719. * write operation, it executes the write operation into the PCI bar memory
  2720. * mapped space accordingly.
  2721. *
  2722. * It returns the @nbytges passing in from debugfs user space when successful.
  2723. * In case of error conditions, it returns proper error code back to the user
  2724. * space.
  2725. */
  2726. static ssize_t
  2727. lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
  2728. size_t nbytes, loff_t *ppos)
  2729. {
  2730. struct lpfc_debug *debug = file->private_data;
  2731. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2732. uint32_t bar_num, bar_size, offset, value, acc_range;
  2733. struct pci_dev *pdev;
  2734. void __iomem *mem_mapped_bar;
  2735. uint32_t if_type;
  2736. uint32_t u32val;
  2737. int rc;
  2738. pdev = phba->pcidev;
  2739. if (!pdev)
  2740. return -EFAULT;
  2741. /* This is a user write operation */
  2742. debug->op = LPFC_IDIAG_OP_WR;
  2743. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2744. if (rc < 0)
  2745. return rc;
  2746. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  2747. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  2748. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  2749. if ((bar_num != IDIAG_BARACC_BAR_0) &&
  2750. (bar_num != IDIAG_BARACC_BAR_1) &&
  2751. (bar_num != IDIAG_BARACC_BAR_2))
  2752. goto error_out;
  2753. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  2754. if (bar_num != IDIAG_BARACC_BAR_0)
  2755. goto error_out;
  2756. } else
  2757. goto error_out;
  2758. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  2759. if (bar_num == IDIAG_BARACC_BAR_0) {
  2760. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  2761. LPFC_PCI_IF0_BAR0_SIZE;
  2762. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  2763. } else if (bar_num == IDIAG_BARACC_BAR_1) {
  2764. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  2765. LPFC_PCI_IF0_BAR1_SIZE;
  2766. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  2767. } else if (bar_num == IDIAG_BARACC_BAR_2) {
  2768. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  2769. LPFC_PCI_IF0_BAR2_SIZE;
  2770. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  2771. } else
  2772. goto error_out;
  2773. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  2774. if (bar_num == IDIAG_BARACC_BAR_0) {
  2775. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  2776. LPFC_PCI_IF2_BAR0_SIZE;
  2777. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  2778. } else
  2779. goto error_out;
  2780. } else
  2781. goto error_out;
  2782. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  2783. if (offset % sizeof(uint32_t))
  2784. goto error_out;
  2785. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  2786. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  2787. /* Sanity check on PCI config read command line arguments */
  2788. if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
  2789. goto error_out;
  2790. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  2791. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  2792. if (offset > bar_size - sizeof(uint32_t))
  2793. goto error_out;
  2794. /* Starting offset to browse */
  2795. idiag.offset.last_rd = offset;
  2796. } else if (acc_range > SINGLE_WORD) {
  2797. if (offset + acc_range * sizeof(uint32_t) > bar_size)
  2798. goto error_out;
  2799. /* Starting offset to browse */
  2800. idiag.offset.last_rd = offset;
  2801. } else if (acc_range != SINGLE_WORD)
  2802. goto error_out;
  2803. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
  2804. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
  2805. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  2806. /* Sanity check on PCI bar write command line arguments */
  2807. if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
  2808. goto error_out;
  2809. /* Write command to PCI bar space, read-modify-write */
  2810. acc_range = SINGLE_WORD;
  2811. value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
  2812. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
  2813. writel(value, mem_mapped_bar + offset);
  2814. readl(mem_mapped_bar + offset);
  2815. }
  2816. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
  2817. u32val = readl(mem_mapped_bar + offset);
  2818. u32val |= value;
  2819. writel(u32val, mem_mapped_bar + offset);
  2820. readl(mem_mapped_bar + offset);
  2821. }
  2822. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  2823. u32val = readl(mem_mapped_bar + offset);
  2824. u32val &= ~value;
  2825. writel(u32val, mem_mapped_bar + offset);
  2826. readl(mem_mapped_bar + offset);
  2827. }
  2828. } else
  2829. /* All other opecodes are illegal for now */
  2830. goto error_out;
  2831. return nbytes;
  2832. error_out:
  2833. memset(&idiag, 0, sizeof(idiag));
  2834. return -EINVAL;
  2835. }
  2836. static int
  2837. __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
  2838. char *pbuffer, int len)
  2839. {
  2840. if (!qp)
  2841. return len;
  2842. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2843. "\t\t%s WQ info: ", wqtype);
  2844. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2845. "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
  2846. qp->assoc_qid, qp->q_cnt_1,
  2847. (unsigned long long)qp->q_cnt_4);
  2848. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2849. "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  2850. "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
  2851. qp->queue_id, qp->entry_count,
  2852. qp->entry_size, qp->host_index,
  2853. qp->hba_index, qp->entry_repost);
  2854. len += scnprintf(pbuffer + len,
  2855. LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
  2856. return len;
  2857. }
  2858. static int
  2859. lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
  2860. int *len, int max_cnt, int cq_id)
  2861. {
  2862. struct lpfc_queue *qp;
  2863. int qidx;
  2864. for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
  2865. qp = phba->sli4_hba.fcp_wq[qidx];
  2866. if (qp->assoc_qid != cq_id)
  2867. continue;
  2868. *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
  2869. if (*len >= max_cnt)
  2870. return 1;
  2871. }
  2872. for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
  2873. qp = phba->sli4_hba.nvme_wq[qidx];
  2874. if (qp->assoc_qid != cq_id)
  2875. continue;
  2876. *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
  2877. if (*len >= max_cnt)
  2878. return 1;
  2879. }
  2880. return 0;
  2881. }
  2882. static int
  2883. __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
  2884. char *pbuffer, int len)
  2885. {
  2886. if (!qp)
  2887. return len;
  2888. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2889. "\t%s CQ info: ", cqtype);
  2890. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2891. "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
  2892. "xabt:x%x wq:x%llx]\n",
  2893. qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
  2894. qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
  2895. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2896. "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  2897. "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
  2898. qp->queue_id, qp->entry_count,
  2899. qp->entry_size, qp->host_index,
  2900. qp->hba_index, qp->entry_repost);
  2901. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
  2902. return len;
  2903. }
  2904. static int
  2905. __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
  2906. char *rqtype, char *pbuffer, int len)
  2907. {
  2908. if (!qp || !datqp)
  2909. return len;
  2910. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2911. "\t\t%s RQ info: ", rqtype);
  2912. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2913. "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
  2914. "posted:x%x rcv:x%llx]\n",
  2915. qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
  2916. qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
  2917. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2918. "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  2919. "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
  2920. qp->queue_id, qp->entry_count, qp->entry_size,
  2921. qp->host_index, qp->hba_index, qp->entry_repost);
  2922. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2923. "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  2924. "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
  2925. datqp->queue_id, datqp->entry_count,
  2926. datqp->entry_size, datqp->host_index,
  2927. datqp->hba_index, datqp->entry_repost);
  2928. return len;
  2929. }
  2930. static int
  2931. lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
  2932. int *len, int max_cnt, int eqidx, int eq_id)
  2933. {
  2934. struct lpfc_queue *qp;
  2935. int qidx, rc;
  2936. for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
  2937. qp = phba->sli4_hba.fcp_cq[qidx];
  2938. if (qp->assoc_qid != eq_id)
  2939. continue;
  2940. *len = __lpfc_idiag_print_cq(qp, "FCP", pbuffer, *len);
  2941. /* Reset max counter */
  2942. qp->CQ_max_cqe = 0;
  2943. if (*len >= max_cnt)
  2944. return 1;
  2945. rc = lpfc_idiag_wqs_for_cq(phba, "FCP", pbuffer, len,
  2946. max_cnt, qp->queue_id);
  2947. if (rc)
  2948. return 1;
  2949. }
  2950. for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
  2951. qp = phba->sli4_hba.nvme_cq[qidx];
  2952. if (qp->assoc_qid != eq_id)
  2953. continue;
  2954. *len = __lpfc_idiag_print_cq(qp, "NVME", pbuffer, *len);
  2955. /* Reset max counter */
  2956. qp->CQ_max_cqe = 0;
  2957. if (*len >= max_cnt)
  2958. return 1;
  2959. rc = lpfc_idiag_wqs_for_cq(phba, "NVME", pbuffer, len,
  2960. max_cnt, qp->queue_id);
  2961. if (rc)
  2962. return 1;
  2963. }
  2964. if ((eqidx < phba->cfg_nvmet_mrq) && phba->nvmet_support) {
  2965. /* NVMET CQset */
  2966. qp = phba->sli4_hba.nvmet_cqset[eqidx];
  2967. *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
  2968. /* Reset max counter */
  2969. qp->CQ_max_cqe = 0;
  2970. if (*len >= max_cnt)
  2971. return 1;
  2972. /* RQ header */
  2973. qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
  2974. *len = __lpfc_idiag_print_rqpair(qp,
  2975. phba->sli4_hba.nvmet_mrq_data[eqidx],
  2976. "NVMET MRQ", pbuffer, *len);
  2977. if (*len >= max_cnt)
  2978. return 1;
  2979. }
  2980. return 0;
  2981. }
  2982. static int
  2983. __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
  2984. char *pbuffer, int len)
  2985. {
  2986. if (!qp)
  2987. return len;
  2988. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2989. "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
  2990. "cqe_proc:x%x eqe_proc:x%llx eqd %d]\n",
  2991. eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
  2992. (unsigned long long)qp->q_cnt_4, qp->q_mode);
  2993. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  2994. "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  2995. "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
  2996. qp->queue_id, qp->entry_count, qp->entry_size,
  2997. qp->host_index, qp->hba_index, qp->entry_repost);
  2998. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
  2999. return len;
  3000. }
  3001. /**
  3002. * lpfc_idiag_queinfo_read - idiag debugfs read queue information
  3003. * @file: The file pointer to read from.
  3004. * @buf: The buffer to copy the data to.
  3005. * @nbytes: The number of bytes to read.
  3006. * @ppos: The position in the file to start reading from.
  3007. *
  3008. * Description:
  3009. * This routine reads data from the @phba SLI4 PCI function queue information,
  3010. * and copies to user @buf.
  3011. * This routine only returns 1 EQs worth of information. It remembers the last
  3012. * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
  3013. * retrieve all EQs allocated for the phba.
  3014. *
  3015. * Returns:
  3016. * This function returns the amount of data that was read (this could be less
  3017. * than @nbytes if the end of the file was reached) or a negative error value.
  3018. **/
  3019. static ssize_t
  3020. lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
  3021. loff_t *ppos)
  3022. {
  3023. struct lpfc_debug *debug = file->private_data;
  3024. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3025. char *pbuffer;
  3026. int max_cnt, rc, x, len = 0;
  3027. struct lpfc_queue *qp = NULL;
  3028. if (!debug->buffer)
  3029. debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
  3030. if (!debug->buffer)
  3031. return 0;
  3032. pbuffer = debug->buffer;
  3033. max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
  3034. if (*ppos)
  3035. return 0;
  3036. spin_lock_irq(&phba->hbalock);
  3037. /* Fast-path event queue */
  3038. if (phba->sli4_hba.hba_eq && phba->io_channel_irqs) {
  3039. x = phba->lpfc_idiag_last_eq;
  3040. if (phba->cfg_fof && (x >= phba->io_channel_irqs)) {
  3041. phba->lpfc_idiag_last_eq = 0;
  3042. goto fof;
  3043. }
  3044. phba->lpfc_idiag_last_eq++;
  3045. if (phba->lpfc_idiag_last_eq >= phba->io_channel_irqs)
  3046. if (phba->cfg_fof == 0)
  3047. phba->lpfc_idiag_last_eq = 0;
  3048. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3049. "EQ %d out of %d HBA EQs\n",
  3050. x, phba->io_channel_irqs);
  3051. /* Fast-path EQ */
  3052. qp = phba->sli4_hba.hba_eq[x];
  3053. if (!qp)
  3054. goto out;
  3055. len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
  3056. /* Reset max counter */
  3057. qp->EQ_max_eqe = 0;
  3058. if (len >= max_cnt)
  3059. goto too_big;
  3060. /* will dump both fcp and nvme cqs/wqs for the eq */
  3061. rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
  3062. max_cnt, x, qp->queue_id);
  3063. if (rc)
  3064. goto too_big;
  3065. /* Only EQ 0 has slow path CQs configured */
  3066. if (x)
  3067. goto out;
  3068. /* Slow-path mailbox CQ */
  3069. qp = phba->sli4_hba.mbx_cq;
  3070. len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
  3071. if (len >= max_cnt)
  3072. goto too_big;
  3073. /* Slow-path MBOX MQ */
  3074. qp = phba->sli4_hba.mbx_wq;
  3075. len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
  3076. if (len >= max_cnt)
  3077. goto too_big;
  3078. /* Slow-path ELS response CQ */
  3079. qp = phba->sli4_hba.els_cq;
  3080. len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
  3081. /* Reset max counter */
  3082. if (qp)
  3083. qp->CQ_max_cqe = 0;
  3084. if (len >= max_cnt)
  3085. goto too_big;
  3086. /* Slow-path ELS WQ */
  3087. qp = phba->sli4_hba.els_wq;
  3088. len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
  3089. if (len >= max_cnt)
  3090. goto too_big;
  3091. qp = phba->sli4_hba.hdr_rq;
  3092. len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
  3093. "ELS RQpair", pbuffer, len);
  3094. if (len >= max_cnt)
  3095. goto too_big;
  3096. /* Slow-path NVME LS response CQ */
  3097. qp = phba->sli4_hba.nvmels_cq;
  3098. len = __lpfc_idiag_print_cq(qp, "NVME LS",
  3099. pbuffer, len);
  3100. /* Reset max counter */
  3101. if (qp)
  3102. qp->CQ_max_cqe = 0;
  3103. if (len >= max_cnt)
  3104. goto too_big;
  3105. /* Slow-path NVME LS WQ */
  3106. qp = phba->sli4_hba.nvmels_wq;
  3107. len = __lpfc_idiag_print_wq(qp, "NVME LS",
  3108. pbuffer, len);
  3109. if (len >= max_cnt)
  3110. goto too_big;
  3111. goto out;
  3112. }
  3113. fof:
  3114. if (phba->cfg_fof) {
  3115. /* FOF EQ */
  3116. qp = phba->sli4_hba.fof_eq;
  3117. len = __lpfc_idiag_print_eq(qp, "FOF", pbuffer, len);
  3118. /* Reset max counter */
  3119. if (qp)
  3120. qp->EQ_max_eqe = 0;
  3121. if (len >= max_cnt)
  3122. goto too_big;
  3123. /* OAS CQ */
  3124. qp = phba->sli4_hba.oas_cq;
  3125. len = __lpfc_idiag_print_cq(qp, "OAS", pbuffer, len);
  3126. /* Reset max counter */
  3127. if (qp)
  3128. qp->CQ_max_cqe = 0;
  3129. if (len >= max_cnt)
  3130. goto too_big;
  3131. /* OAS WQ */
  3132. qp = phba->sli4_hba.oas_wq;
  3133. len = __lpfc_idiag_print_wq(qp, "OAS", pbuffer, len);
  3134. if (len >= max_cnt)
  3135. goto too_big;
  3136. }
  3137. spin_unlock_irq(&phba->hbalock);
  3138. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3139. too_big:
  3140. len += scnprintf(pbuffer + len,
  3141. LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
  3142. out:
  3143. spin_unlock_irq(&phba->hbalock);
  3144. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3145. }
  3146. /**
  3147. * lpfc_idiag_que_param_check - queue access command parameter sanity check
  3148. * @q: The pointer to queue structure.
  3149. * @index: The index into a queue entry.
  3150. * @count: The number of queue entries to access.
  3151. *
  3152. * Description:
  3153. * The routine performs sanity check on device queue access method commands.
  3154. *
  3155. * Returns:
  3156. * This function returns -EINVAL when fails the sanity check, otherwise, it
  3157. * returns 0.
  3158. **/
  3159. static int
  3160. lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
  3161. {
  3162. /* Only support single entry read or browsing */
  3163. if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
  3164. return -EINVAL;
  3165. if (index > q->entry_count - 1)
  3166. return -EINVAL;
  3167. return 0;
  3168. }
  3169. /**
  3170. * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
  3171. * @pbuffer: The pointer to buffer to copy the read data into.
  3172. * @pque: The pointer to the queue to be read.
  3173. * @index: The index into the queue entry.
  3174. *
  3175. * Description:
  3176. * This routine reads out a single entry from the given queue's index location
  3177. * and copies it into the buffer provided.
  3178. *
  3179. * Returns:
  3180. * This function returns 0 when it fails, otherwise, it returns the length of
  3181. * the data read into the buffer provided.
  3182. **/
  3183. static int
  3184. lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
  3185. uint32_t index)
  3186. {
  3187. int offset, esize;
  3188. uint32_t *pentry;
  3189. if (!pbuffer || !pque)
  3190. return 0;
  3191. esize = pque->entry_size;
  3192. len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  3193. "QE-INDEX[%04d]:\n", index);
  3194. offset = 0;
  3195. pentry = pque->qe[index].address;
  3196. while (esize > 0) {
  3197. len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  3198. "%08x ", *pentry);
  3199. pentry++;
  3200. offset += sizeof(uint32_t);
  3201. esize -= sizeof(uint32_t);
  3202. if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
  3203. len += scnprintf(pbuffer+len,
  3204. LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  3205. }
  3206. len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  3207. return len;
  3208. }
  3209. /**
  3210. * lpfc_idiag_queacc_read - idiag debugfs read port queue
  3211. * @file: The file pointer to read from.
  3212. * @buf: The buffer to copy the data to.
  3213. * @nbytes: The number of bytes to read.
  3214. * @ppos: The position in the file to start reading from.
  3215. *
  3216. * Description:
  3217. * This routine reads data from the @phba device queue memory according to the
  3218. * idiag command, and copies to user @buf. Depending on the queue dump read
  3219. * command setup, it does either a single queue entry read or browing through
  3220. * all entries of the queue.
  3221. *
  3222. * Returns:
  3223. * This function returns the amount of data that was read (this could be less
  3224. * than @nbytes if the end of the file was reached) or a negative error value.
  3225. **/
  3226. static ssize_t
  3227. lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
  3228. loff_t *ppos)
  3229. {
  3230. struct lpfc_debug *debug = file->private_data;
  3231. uint32_t last_index, index, count;
  3232. struct lpfc_queue *pque = NULL;
  3233. char *pbuffer;
  3234. int len = 0;
  3235. /* This is a user read operation */
  3236. debug->op = LPFC_IDIAG_OP_RD;
  3237. if (!debug->buffer)
  3238. debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
  3239. if (!debug->buffer)
  3240. return 0;
  3241. pbuffer = debug->buffer;
  3242. if (*ppos)
  3243. return 0;
  3244. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  3245. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  3246. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  3247. pque = (struct lpfc_queue *)idiag.ptr_private;
  3248. } else
  3249. return 0;
  3250. /* Browse the queue starting from index */
  3251. if (count == LPFC_QUE_ACC_BROWSE)
  3252. goto que_browse;
  3253. /* Read a single entry from the queue */
  3254. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  3255. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3256. que_browse:
  3257. /* Browse all entries from the queue */
  3258. last_index = idiag.offset.last_rd;
  3259. index = last_index;
  3260. while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
  3261. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  3262. index++;
  3263. if (index > pque->entry_count - 1)
  3264. break;
  3265. }
  3266. /* Set up the offset for next portion of pci cfg read */
  3267. if (index > pque->entry_count - 1)
  3268. index = 0;
  3269. idiag.offset.last_rd = index;
  3270. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3271. }
  3272. /**
  3273. * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
  3274. * @file: The file pointer to read from.
  3275. * @buf: The buffer to copy the user data from.
  3276. * @nbytes: The number of bytes to get.
  3277. * @ppos: The position in the file to start reading from.
  3278. *
  3279. * This routine get the debugfs idiag command struct from user space and then
  3280. * perform the syntax check for port queue read (dump) or write (set) command
  3281. * accordingly. In the case of port queue read command, it sets up the command
  3282. * in the idiag command struct for the following debugfs read operation. In
  3283. * the case of port queue write operation, it executes the write operation
  3284. * into the port queue entry accordingly.
  3285. *
  3286. * It returns the @nbytges passing in from debugfs user space when successful.
  3287. * In case of error conditions, it returns proper error code back to the user
  3288. * space.
  3289. **/
  3290. static ssize_t
  3291. lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
  3292. size_t nbytes, loff_t *ppos)
  3293. {
  3294. struct lpfc_debug *debug = file->private_data;
  3295. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3296. uint32_t qidx, quetp, queid, index, count, offset, value;
  3297. uint32_t *pentry;
  3298. struct lpfc_queue *pque, *qp;
  3299. int rc;
  3300. /* This is a user write operation */
  3301. debug->op = LPFC_IDIAG_OP_WR;
  3302. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  3303. if (rc < 0)
  3304. return rc;
  3305. /* Get and sanity check on command feilds */
  3306. quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
  3307. queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
  3308. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  3309. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  3310. offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
  3311. value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
  3312. /* Sanity check on command line arguments */
  3313. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  3314. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  3315. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  3316. if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
  3317. goto error_out;
  3318. if (count != 1)
  3319. goto error_out;
  3320. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  3321. if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
  3322. goto error_out;
  3323. } else
  3324. goto error_out;
  3325. switch (quetp) {
  3326. case LPFC_IDIAG_EQ:
  3327. /* HBA event queue */
  3328. if (phba->sli4_hba.hba_eq) {
  3329. for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) {
  3330. qp = phba->sli4_hba.hba_eq[qidx];
  3331. if (qp && qp->queue_id == queid) {
  3332. /* Sanity check */
  3333. rc = lpfc_idiag_que_param_check(qp,
  3334. index, count);
  3335. if (rc)
  3336. goto error_out;
  3337. idiag.ptr_private = qp;
  3338. goto pass_check;
  3339. }
  3340. }
  3341. }
  3342. goto error_out;
  3343. break;
  3344. case LPFC_IDIAG_CQ:
  3345. /* MBX complete queue */
  3346. if (phba->sli4_hba.mbx_cq &&
  3347. phba->sli4_hba.mbx_cq->queue_id == queid) {
  3348. /* Sanity check */
  3349. rc = lpfc_idiag_que_param_check(
  3350. phba->sli4_hba.mbx_cq, index, count);
  3351. if (rc)
  3352. goto error_out;
  3353. idiag.ptr_private = phba->sli4_hba.mbx_cq;
  3354. goto pass_check;
  3355. }
  3356. /* ELS complete queue */
  3357. if (phba->sli4_hba.els_cq &&
  3358. phba->sli4_hba.els_cq->queue_id == queid) {
  3359. /* Sanity check */
  3360. rc = lpfc_idiag_que_param_check(
  3361. phba->sli4_hba.els_cq, index, count);
  3362. if (rc)
  3363. goto error_out;
  3364. idiag.ptr_private = phba->sli4_hba.els_cq;
  3365. goto pass_check;
  3366. }
  3367. /* NVME LS complete queue */
  3368. if (phba->sli4_hba.nvmels_cq &&
  3369. phba->sli4_hba.nvmels_cq->queue_id == queid) {
  3370. /* Sanity check */
  3371. rc = lpfc_idiag_que_param_check(
  3372. phba->sli4_hba.nvmels_cq, index, count);
  3373. if (rc)
  3374. goto error_out;
  3375. idiag.ptr_private = phba->sli4_hba.nvmels_cq;
  3376. goto pass_check;
  3377. }
  3378. /* FCP complete queue */
  3379. if (phba->sli4_hba.fcp_cq) {
  3380. for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
  3381. qidx++) {
  3382. qp = phba->sli4_hba.fcp_cq[qidx];
  3383. if (qp && qp->queue_id == queid) {
  3384. /* Sanity check */
  3385. rc = lpfc_idiag_que_param_check(
  3386. qp, index, count);
  3387. if (rc)
  3388. goto error_out;
  3389. idiag.ptr_private = qp;
  3390. goto pass_check;
  3391. }
  3392. }
  3393. }
  3394. /* NVME complete queue */
  3395. if (phba->sli4_hba.nvme_cq) {
  3396. qidx = 0;
  3397. do {
  3398. if (phba->sli4_hba.nvme_cq[qidx] &&
  3399. phba->sli4_hba.nvme_cq[qidx]->queue_id ==
  3400. queid) {
  3401. /* Sanity check */
  3402. rc = lpfc_idiag_que_param_check(
  3403. phba->sli4_hba.nvme_cq[qidx],
  3404. index, count);
  3405. if (rc)
  3406. goto error_out;
  3407. idiag.ptr_private =
  3408. phba->sli4_hba.nvme_cq[qidx];
  3409. goto pass_check;
  3410. }
  3411. } while (++qidx < phba->cfg_nvme_io_channel);
  3412. }
  3413. goto error_out;
  3414. break;
  3415. case LPFC_IDIAG_MQ:
  3416. /* MBX work queue */
  3417. if (phba->sli4_hba.mbx_wq &&
  3418. phba->sli4_hba.mbx_wq->queue_id == queid) {
  3419. /* Sanity check */
  3420. rc = lpfc_idiag_que_param_check(
  3421. phba->sli4_hba.mbx_wq, index, count);
  3422. if (rc)
  3423. goto error_out;
  3424. idiag.ptr_private = phba->sli4_hba.mbx_wq;
  3425. goto pass_check;
  3426. }
  3427. goto error_out;
  3428. break;
  3429. case LPFC_IDIAG_WQ:
  3430. /* ELS work queue */
  3431. if (phba->sli4_hba.els_wq &&
  3432. phba->sli4_hba.els_wq->queue_id == queid) {
  3433. /* Sanity check */
  3434. rc = lpfc_idiag_que_param_check(
  3435. phba->sli4_hba.els_wq, index, count);
  3436. if (rc)
  3437. goto error_out;
  3438. idiag.ptr_private = phba->sli4_hba.els_wq;
  3439. goto pass_check;
  3440. }
  3441. /* NVME LS work queue */
  3442. if (phba->sli4_hba.nvmels_wq &&
  3443. phba->sli4_hba.nvmels_wq->queue_id == queid) {
  3444. /* Sanity check */
  3445. rc = lpfc_idiag_que_param_check(
  3446. phba->sli4_hba.nvmels_wq, index, count);
  3447. if (rc)
  3448. goto error_out;
  3449. idiag.ptr_private = phba->sli4_hba.nvmels_wq;
  3450. goto pass_check;
  3451. }
  3452. /* FCP work queue */
  3453. if (phba->sli4_hba.fcp_wq) {
  3454. for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
  3455. qidx++) {
  3456. qp = phba->sli4_hba.fcp_wq[qidx];
  3457. if (qp && qp->queue_id == queid) {
  3458. /* Sanity check */
  3459. rc = lpfc_idiag_que_param_check(
  3460. qp, index, count);
  3461. if (rc)
  3462. goto error_out;
  3463. idiag.ptr_private = qp;
  3464. goto pass_check;
  3465. }
  3466. }
  3467. }
  3468. /* NVME work queue */
  3469. if (phba->sli4_hba.nvme_wq) {
  3470. for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
  3471. qidx++) {
  3472. qp = phba->sli4_hba.nvme_wq[qidx];
  3473. if (qp && qp->queue_id == queid) {
  3474. /* Sanity check */
  3475. rc = lpfc_idiag_que_param_check(
  3476. qp, index, count);
  3477. if (rc)
  3478. goto error_out;
  3479. idiag.ptr_private = qp;
  3480. goto pass_check;
  3481. }
  3482. }
  3483. }
  3484. /* NVME work queues */
  3485. if (phba->sli4_hba.nvme_wq) {
  3486. for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
  3487. qidx++) {
  3488. if (!phba->sli4_hba.nvme_wq[qidx])
  3489. continue;
  3490. if (phba->sli4_hba.nvme_wq[qidx]->queue_id ==
  3491. queid) {
  3492. /* Sanity check */
  3493. rc = lpfc_idiag_que_param_check(
  3494. phba->sli4_hba.nvme_wq[qidx],
  3495. index, count);
  3496. if (rc)
  3497. goto error_out;
  3498. idiag.ptr_private =
  3499. phba->sli4_hba.nvme_wq[qidx];
  3500. goto pass_check;
  3501. }
  3502. }
  3503. }
  3504. goto error_out;
  3505. break;
  3506. case LPFC_IDIAG_RQ:
  3507. /* HDR queue */
  3508. if (phba->sli4_hba.hdr_rq &&
  3509. phba->sli4_hba.hdr_rq->queue_id == queid) {
  3510. /* Sanity check */
  3511. rc = lpfc_idiag_que_param_check(
  3512. phba->sli4_hba.hdr_rq, index, count);
  3513. if (rc)
  3514. goto error_out;
  3515. idiag.ptr_private = phba->sli4_hba.hdr_rq;
  3516. goto pass_check;
  3517. }
  3518. /* DAT queue */
  3519. if (phba->sli4_hba.dat_rq &&
  3520. phba->sli4_hba.dat_rq->queue_id == queid) {
  3521. /* Sanity check */
  3522. rc = lpfc_idiag_que_param_check(
  3523. phba->sli4_hba.dat_rq, index, count);
  3524. if (rc)
  3525. goto error_out;
  3526. idiag.ptr_private = phba->sli4_hba.dat_rq;
  3527. goto pass_check;
  3528. }
  3529. goto error_out;
  3530. break;
  3531. default:
  3532. goto error_out;
  3533. break;
  3534. }
  3535. pass_check:
  3536. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  3537. if (count == LPFC_QUE_ACC_BROWSE)
  3538. idiag.offset.last_rd = index;
  3539. }
  3540. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  3541. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  3542. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  3543. /* Additional sanity checks on write operation */
  3544. pque = (struct lpfc_queue *)idiag.ptr_private;
  3545. if (offset > pque->entry_size/sizeof(uint32_t) - 1)
  3546. goto error_out;
  3547. pentry = pque->qe[index].address;
  3548. pentry += offset;
  3549. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
  3550. *pentry = value;
  3551. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
  3552. *pentry |= value;
  3553. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
  3554. *pentry &= ~value;
  3555. }
  3556. return nbytes;
  3557. error_out:
  3558. /* Clean out command structure on command error out */
  3559. memset(&idiag, 0, sizeof(idiag));
  3560. return -EINVAL;
  3561. }
  3562. /**
  3563. * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
  3564. * @phba: The pointer to hba structure.
  3565. * @pbuffer: The pointer to the buffer to copy the data to.
  3566. * @len: The lenght of bytes to copied.
  3567. * @drbregid: The id to doorbell registers.
  3568. *
  3569. * Description:
  3570. * This routine reads a doorbell register and copies its content to the
  3571. * user buffer pointed to by @pbuffer.
  3572. *
  3573. * Returns:
  3574. * This function returns the amount of data that was copied into @pbuffer.
  3575. **/
  3576. static int
  3577. lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  3578. int len, uint32_t drbregid)
  3579. {
  3580. if (!pbuffer)
  3581. return 0;
  3582. switch (drbregid) {
  3583. case LPFC_DRB_EQ:
  3584. len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE-len,
  3585. "EQ-DRB-REG: 0x%08x\n",
  3586. readl(phba->sli4_hba.EQDBregaddr));
  3587. break;
  3588. case LPFC_DRB_CQ:
  3589. len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE - len,
  3590. "CQ-DRB-REG: 0x%08x\n",
  3591. readl(phba->sli4_hba.CQDBregaddr));
  3592. break;
  3593. case LPFC_DRB_MQ:
  3594. len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  3595. "MQ-DRB-REG: 0x%08x\n",
  3596. readl(phba->sli4_hba.MQDBregaddr));
  3597. break;
  3598. case LPFC_DRB_WQ:
  3599. len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  3600. "WQ-DRB-REG: 0x%08x\n",
  3601. readl(phba->sli4_hba.WQDBregaddr));
  3602. break;
  3603. case LPFC_DRB_RQ:
  3604. len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  3605. "RQ-DRB-REG: 0x%08x\n",
  3606. readl(phba->sli4_hba.RQDBregaddr));
  3607. break;
  3608. default:
  3609. break;
  3610. }
  3611. return len;
  3612. }
  3613. /**
  3614. * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
  3615. * @file: The file pointer to read from.
  3616. * @buf: The buffer to copy the data to.
  3617. * @nbytes: The number of bytes to read.
  3618. * @ppos: The position in the file to start reading from.
  3619. *
  3620. * Description:
  3621. * This routine reads data from the @phba device doorbell register according
  3622. * to the idiag command, and copies to user @buf. Depending on the doorbell
  3623. * register read command setup, it does either a single doorbell register
  3624. * read or dump all doorbell registers.
  3625. *
  3626. * Returns:
  3627. * This function returns the amount of data that was read (this could be less
  3628. * than @nbytes if the end of the file was reached) or a negative error value.
  3629. **/
  3630. static ssize_t
  3631. lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
  3632. loff_t *ppos)
  3633. {
  3634. struct lpfc_debug *debug = file->private_data;
  3635. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3636. uint32_t drb_reg_id, i;
  3637. char *pbuffer;
  3638. int len = 0;
  3639. /* This is a user read operation */
  3640. debug->op = LPFC_IDIAG_OP_RD;
  3641. if (!debug->buffer)
  3642. debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
  3643. if (!debug->buffer)
  3644. return 0;
  3645. pbuffer = debug->buffer;
  3646. if (*ppos)
  3647. return 0;
  3648. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
  3649. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  3650. else
  3651. return 0;
  3652. if (drb_reg_id == LPFC_DRB_ACC_ALL)
  3653. for (i = 1; i <= LPFC_DRB_MAX; i++)
  3654. len = lpfc_idiag_drbacc_read_reg(phba,
  3655. pbuffer, len, i);
  3656. else
  3657. len = lpfc_idiag_drbacc_read_reg(phba,
  3658. pbuffer, len, drb_reg_id);
  3659. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3660. }
  3661. /**
  3662. * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
  3663. * @file: The file pointer to read from.
  3664. * @buf: The buffer to copy the user data from.
  3665. * @nbytes: The number of bytes to get.
  3666. * @ppos: The position in the file to start reading from.
  3667. *
  3668. * This routine get the debugfs idiag command struct from user space and then
  3669. * perform the syntax check for port doorbell register read (dump) or write
  3670. * (set) command accordingly. In the case of port queue read command, it sets
  3671. * up the command in the idiag command struct for the following debugfs read
  3672. * operation. In the case of port doorbell register write operation, it
  3673. * executes the write operation into the port doorbell register accordingly.
  3674. *
  3675. * It returns the @nbytges passing in from debugfs user space when successful.
  3676. * In case of error conditions, it returns proper error code back to the user
  3677. * space.
  3678. **/
  3679. static ssize_t
  3680. lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
  3681. size_t nbytes, loff_t *ppos)
  3682. {
  3683. struct lpfc_debug *debug = file->private_data;
  3684. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3685. uint32_t drb_reg_id, value, reg_val = 0;
  3686. void __iomem *drb_reg;
  3687. int rc;
  3688. /* This is a user write operation */
  3689. debug->op = LPFC_IDIAG_OP_WR;
  3690. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  3691. if (rc < 0)
  3692. return rc;
  3693. /* Sanity check on command line arguments */
  3694. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  3695. value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
  3696. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  3697. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  3698. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  3699. if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
  3700. goto error_out;
  3701. if (drb_reg_id > LPFC_DRB_MAX)
  3702. goto error_out;
  3703. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
  3704. if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
  3705. goto error_out;
  3706. if ((drb_reg_id > LPFC_DRB_MAX) &&
  3707. (drb_reg_id != LPFC_DRB_ACC_ALL))
  3708. goto error_out;
  3709. } else
  3710. goto error_out;
  3711. /* Perform the write access operation */
  3712. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  3713. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  3714. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  3715. switch (drb_reg_id) {
  3716. case LPFC_DRB_EQ:
  3717. drb_reg = phba->sli4_hba.EQDBregaddr;
  3718. break;
  3719. case LPFC_DRB_CQ:
  3720. drb_reg = phba->sli4_hba.CQDBregaddr;
  3721. break;
  3722. case LPFC_DRB_MQ:
  3723. drb_reg = phba->sli4_hba.MQDBregaddr;
  3724. break;
  3725. case LPFC_DRB_WQ:
  3726. drb_reg = phba->sli4_hba.WQDBregaddr;
  3727. break;
  3728. case LPFC_DRB_RQ:
  3729. drb_reg = phba->sli4_hba.RQDBregaddr;
  3730. break;
  3731. default:
  3732. goto error_out;
  3733. }
  3734. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
  3735. reg_val = value;
  3736. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
  3737. reg_val = readl(drb_reg);
  3738. reg_val |= value;
  3739. }
  3740. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  3741. reg_val = readl(drb_reg);
  3742. reg_val &= ~value;
  3743. }
  3744. writel(reg_val, drb_reg);
  3745. readl(drb_reg); /* flush */
  3746. }
  3747. return nbytes;
  3748. error_out:
  3749. /* Clean out command structure on command error out */
  3750. memset(&idiag, 0, sizeof(idiag));
  3751. return -EINVAL;
  3752. }
  3753. /**
  3754. * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
  3755. * @phba: The pointer to hba structure.
  3756. * @pbuffer: The pointer to the buffer to copy the data to.
  3757. * @len: The lenght of bytes to copied.
  3758. * @drbregid: The id to doorbell registers.
  3759. *
  3760. * Description:
  3761. * This routine reads a control register and copies its content to the
  3762. * user buffer pointed to by @pbuffer.
  3763. *
  3764. * Returns:
  3765. * This function returns the amount of data that was copied into @pbuffer.
  3766. **/
  3767. static int
  3768. lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  3769. int len, uint32_t ctlregid)
  3770. {
  3771. if (!pbuffer)
  3772. return 0;
  3773. switch (ctlregid) {
  3774. case LPFC_CTL_PORT_SEM:
  3775. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  3776. "Port SemReg: 0x%08x\n",
  3777. readl(phba->sli4_hba.conf_regs_memmap_p +
  3778. LPFC_CTL_PORT_SEM_OFFSET));
  3779. break;
  3780. case LPFC_CTL_PORT_STA:
  3781. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  3782. "Port StaReg: 0x%08x\n",
  3783. readl(phba->sli4_hba.conf_regs_memmap_p +
  3784. LPFC_CTL_PORT_STA_OFFSET));
  3785. break;
  3786. case LPFC_CTL_PORT_CTL:
  3787. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  3788. "Port CtlReg: 0x%08x\n",
  3789. readl(phba->sli4_hba.conf_regs_memmap_p +
  3790. LPFC_CTL_PORT_CTL_OFFSET));
  3791. break;
  3792. case LPFC_CTL_PORT_ER1:
  3793. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  3794. "Port Er1Reg: 0x%08x\n",
  3795. readl(phba->sli4_hba.conf_regs_memmap_p +
  3796. LPFC_CTL_PORT_ER1_OFFSET));
  3797. break;
  3798. case LPFC_CTL_PORT_ER2:
  3799. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  3800. "Port Er2Reg: 0x%08x\n",
  3801. readl(phba->sli4_hba.conf_regs_memmap_p +
  3802. LPFC_CTL_PORT_ER2_OFFSET));
  3803. break;
  3804. case LPFC_CTL_PDEV_CTL:
  3805. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  3806. "PDev CtlReg: 0x%08x\n",
  3807. readl(phba->sli4_hba.conf_regs_memmap_p +
  3808. LPFC_CTL_PDEV_CTL_OFFSET));
  3809. break;
  3810. default:
  3811. break;
  3812. }
  3813. return len;
  3814. }
  3815. /**
  3816. * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
  3817. * @file: The file pointer to read from.
  3818. * @buf: The buffer to copy the data to.
  3819. * @nbytes: The number of bytes to read.
  3820. * @ppos: The position in the file to start reading from.
  3821. *
  3822. * Description:
  3823. * This routine reads data from the @phba port and device registers according
  3824. * to the idiag command, and copies to user @buf.
  3825. *
  3826. * Returns:
  3827. * This function returns the amount of data that was read (this could be less
  3828. * than @nbytes if the end of the file was reached) or a negative error value.
  3829. **/
  3830. static ssize_t
  3831. lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
  3832. loff_t *ppos)
  3833. {
  3834. struct lpfc_debug *debug = file->private_data;
  3835. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3836. uint32_t ctl_reg_id, i;
  3837. char *pbuffer;
  3838. int len = 0;
  3839. /* This is a user read operation */
  3840. debug->op = LPFC_IDIAG_OP_RD;
  3841. if (!debug->buffer)
  3842. debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
  3843. if (!debug->buffer)
  3844. return 0;
  3845. pbuffer = debug->buffer;
  3846. if (*ppos)
  3847. return 0;
  3848. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
  3849. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  3850. else
  3851. return 0;
  3852. if (ctl_reg_id == LPFC_CTL_ACC_ALL)
  3853. for (i = 1; i <= LPFC_CTL_MAX; i++)
  3854. len = lpfc_idiag_ctlacc_read_reg(phba,
  3855. pbuffer, len, i);
  3856. else
  3857. len = lpfc_idiag_ctlacc_read_reg(phba,
  3858. pbuffer, len, ctl_reg_id);
  3859. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3860. }
  3861. /**
  3862. * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
  3863. * @file: The file pointer to read from.
  3864. * @buf: The buffer to copy the user data from.
  3865. * @nbytes: The number of bytes to get.
  3866. * @ppos: The position in the file to start reading from.
  3867. *
  3868. * This routine get the debugfs idiag command struct from user space and then
  3869. * perform the syntax check for port and device control register read (dump)
  3870. * or write (set) command accordingly.
  3871. *
  3872. * It returns the @nbytges passing in from debugfs user space when successful.
  3873. * In case of error conditions, it returns proper error code back to the user
  3874. * space.
  3875. **/
  3876. static ssize_t
  3877. lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
  3878. size_t nbytes, loff_t *ppos)
  3879. {
  3880. struct lpfc_debug *debug = file->private_data;
  3881. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3882. uint32_t ctl_reg_id, value, reg_val = 0;
  3883. void __iomem *ctl_reg;
  3884. int rc;
  3885. /* This is a user write operation */
  3886. debug->op = LPFC_IDIAG_OP_WR;
  3887. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  3888. if (rc < 0)
  3889. return rc;
  3890. /* Sanity check on command line arguments */
  3891. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  3892. value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
  3893. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  3894. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  3895. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  3896. if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
  3897. goto error_out;
  3898. if (ctl_reg_id > LPFC_CTL_MAX)
  3899. goto error_out;
  3900. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
  3901. if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
  3902. goto error_out;
  3903. if ((ctl_reg_id > LPFC_CTL_MAX) &&
  3904. (ctl_reg_id != LPFC_CTL_ACC_ALL))
  3905. goto error_out;
  3906. } else
  3907. goto error_out;
  3908. /* Perform the write access operation */
  3909. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  3910. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  3911. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  3912. switch (ctl_reg_id) {
  3913. case LPFC_CTL_PORT_SEM:
  3914. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  3915. LPFC_CTL_PORT_SEM_OFFSET;
  3916. break;
  3917. case LPFC_CTL_PORT_STA:
  3918. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  3919. LPFC_CTL_PORT_STA_OFFSET;
  3920. break;
  3921. case LPFC_CTL_PORT_CTL:
  3922. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  3923. LPFC_CTL_PORT_CTL_OFFSET;
  3924. break;
  3925. case LPFC_CTL_PORT_ER1:
  3926. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  3927. LPFC_CTL_PORT_ER1_OFFSET;
  3928. break;
  3929. case LPFC_CTL_PORT_ER2:
  3930. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  3931. LPFC_CTL_PORT_ER2_OFFSET;
  3932. break;
  3933. case LPFC_CTL_PDEV_CTL:
  3934. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  3935. LPFC_CTL_PDEV_CTL_OFFSET;
  3936. break;
  3937. default:
  3938. goto error_out;
  3939. }
  3940. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
  3941. reg_val = value;
  3942. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
  3943. reg_val = readl(ctl_reg);
  3944. reg_val |= value;
  3945. }
  3946. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  3947. reg_val = readl(ctl_reg);
  3948. reg_val &= ~value;
  3949. }
  3950. writel(reg_val, ctl_reg);
  3951. readl(ctl_reg); /* flush */
  3952. }
  3953. return nbytes;
  3954. error_out:
  3955. /* Clean out command structure on command error out */
  3956. memset(&idiag, 0, sizeof(idiag));
  3957. return -EINVAL;
  3958. }
  3959. /**
  3960. * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
  3961. * @phba: Pointer to HBA context object.
  3962. * @pbuffer: Pointer to data buffer.
  3963. *
  3964. * Description:
  3965. * This routine gets the driver mailbox access debugfs setup information.
  3966. *
  3967. * Returns:
  3968. * This function returns the amount of data that was read (this could be less
  3969. * than @nbytes if the end of the file was reached) or a negative error value.
  3970. **/
  3971. static int
  3972. lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
  3973. {
  3974. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  3975. int len = 0;
  3976. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  3977. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  3978. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  3979. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  3980. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  3981. "mbx_dump_map: 0x%08x\n", mbx_dump_map);
  3982. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  3983. "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
  3984. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  3985. "mbx_word_cnt: %04d\n", mbx_word_cnt);
  3986. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  3987. "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
  3988. return len;
  3989. }
  3990. /**
  3991. * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
  3992. * @file: The file pointer to read from.
  3993. * @buf: The buffer to copy the data to.
  3994. * @nbytes: The number of bytes to read.
  3995. * @ppos: The position in the file to start reading from.
  3996. *
  3997. * Description:
  3998. * This routine reads data from the @phba driver mailbox access debugfs setup
  3999. * information.
  4000. *
  4001. * Returns:
  4002. * This function returns the amount of data that was read (this could be less
  4003. * than @nbytes if the end of the file was reached) or a negative error value.
  4004. **/
  4005. static ssize_t
  4006. lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
  4007. loff_t *ppos)
  4008. {
  4009. struct lpfc_debug *debug = file->private_data;
  4010. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4011. char *pbuffer;
  4012. int len = 0;
  4013. /* This is a user read operation */
  4014. debug->op = LPFC_IDIAG_OP_RD;
  4015. if (!debug->buffer)
  4016. debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
  4017. if (!debug->buffer)
  4018. return 0;
  4019. pbuffer = debug->buffer;
  4020. if (*ppos)
  4021. return 0;
  4022. if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
  4023. (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
  4024. return 0;
  4025. len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
  4026. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  4027. }
  4028. /**
  4029. * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
  4030. * @file: The file pointer to read from.
  4031. * @buf: The buffer to copy the user data from.
  4032. * @nbytes: The number of bytes to get.
  4033. * @ppos: The position in the file to start reading from.
  4034. *
  4035. * This routine get the debugfs idiag command struct from user space and then
  4036. * perform the syntax check for driver mailbox command (dump) and sets up the
  4037. * necessary states in the idiag command struct accordingly.
  4038. *
  4039. * It returns the @nbytges passing in from debugfs user space when successful.
  4040. * In case of error conditions, it returns proper error code back to the user
  4041. * space.
  4042. **/
  4043. static ssize_t
  4044. lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
  4045. size_t nbytes, loff_t *ppos)
  4046. {
  4047. struct lpfc_debug *debug = file->private_data;
  4048. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  4049. int rc;
  4050. /* This is a user write operation */
  4051. debug->op = LPFC_IDIAG_OP_WR;
  4052. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  4053. if (rc < 0)
  4054. return rc;
  4055. /* Sanity check on command line arguments */
  4056. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  4057. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  4058. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  4059. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  4060. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
  4061. if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
  4062. goto error_out;
  4063. if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
  4064. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  4065. goto error_out;
  4066. if (mbx_word_cnt > sizeof(MAILBOX_t))
  4067. goto error_out;
  4068. } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
  4069. if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
  4070. goto error_out;
  4071. if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
  4072. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  4073. goto error_out;
  4074. if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
  4075. goto error_out;
  4076. if (mbx_mbox_cmd != 0x9b)
  4077. goto error_out;
  4078. } else
  4079. goto error_out;
  4080. if (mbx_word_cnt == 0)
  4081. goto error_out;
  4082. if (rc != LPFC_MBX_DMP_ARG)
  4083. goto error_out;
  4084. if (mbx_mbox_cmd & ~0xff)
  4085. goto error_out;
  4086. /* condition for stop mailbox dump */
  4087. if (mbx_dump_cnt == 0)
  4088. goto reset_out;
  4089. return nbytes;
  4090. reset_out:
  4091. /* Clean out command structure on command error out */
  4092. memset(&idiag, 0, sizeof(idiag));
  4093. return nbytes;
  4094. error_out:
  4095. /* Clean out command structure on command error out */
  4096. memset(&idiag, 0, sizeof(idiag));
  4097. return -EINVAL;
  4098. }
  4099. /**
  4100. * lpfc_idiag_extacc_avail_get - get the available extents information
  4101. * @phba: pointer to lpfc hba data structure.
  4102. * @pbuffer: pointer to internal buffer.
  4103. * @len: length into the internal buffer data has been copied.
  4104. *
  4105. * Description:
  4106. * This routine is to get the available extent information.
  4107. *
  4108. * Returns:
  4109. * overall lenth of the data read into the internal buffer.
  4110. **/
  4111. static int
  4112. lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
  4113. {
  4114. uint16_t ext_cnt, ext_size;
  4115. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4116. "\nAvailable Extents Information:\n");
  4117. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4118. "\tPort Available VPI extents: ");
  4119. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
  4120. &ext_cnt, &ext_size);
  4121. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4122. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4123. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4124. "\tPort Available VFI extents: ");
  4125. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
  4126. &ext_cnt, &ext_size);
  4127. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4128. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4129. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4130. "\tPort Available RPI extents: ");
  4131. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
  4132. &ext_cnt, &ext_size);
  4133. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4134. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4135. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4136. "\tPort Available XRI extents: ");
  4137. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
  4138. &ext_cnt, &ext_size);
  4139. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4140. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4141. return len;
  4142. }
  4143. /**
  4144. * lpfc_idiag_extacc_alloc_get - get the allocated extents information
  4145. * @phba: pointer to lpfc hba data structure.
  4146. * @pbuffer: pointer to internal buffer.
  4147. * @len: length into the internal buffer data has been copied.
  4148. *
  4149. * Description:
  4150. * This routine is to get the allocated extent information.
  4151. *
  4152. * Returns:
  4153. * overall lenth of the data read into the internal buffer.
  4154. **/
  4155. static int
  4156. lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
  4157. {
  4158. uint16_t ext_cnt, ext_size;
  4159. int rc;
  4160. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4161. "\nAllocated Extents Information:\n");
  4162. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4163. "\tHost Allocated VPI extents: ");
  4164. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
  4165. &ext_cnt, &ext_size);
  4166. if (!rc)
  4167. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4168. "Port %d Extent %3d, Size %3d\n",
  4169. phba->brd_no, ext_cnt, ext_size);
  4170. else
  4171. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4172. "N/A\n");
  4173. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4174. "\tHost Allocated VFI extents: ");
  4175. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
  4176. &ext_cnt, &ext_size);
  4177. if (!rc)
  4178. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4179. "Port %d Extent %3d, Size %3d\n",
  4180. phba->brd_no, ext_cnt, ext_size);
  4181. else
  4182. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4183. "N/A\n");
  4184. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4185. "\tHost Allocated RPI extents: ");
  4186. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
  4187. &ext_cnt, &ext_size);
  4188. if (!rc)
  4189. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4190. "Port %d Extent %3d, Size %3d\n",
  4191. phba->brd_no, ext_cnt, ext_size);
  4192. else
  4193. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4194. "N/A\n");
  4195. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4196. "\tHost Allocated XRI extents: ");
  4197. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
  4198. &ext_cnt, &ext_size);
  4199. if (!rc)
  4200. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4201. "Port %d Extent %3d, Size %3d\n",
  4202. phba->brd_no, ext_cnt, ext_size);
  4203. else
  4204. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4205. "N/A\n");
  4206. return len;
  4207. }
  4208. /**
  4209. * lpfc_idiag_extacc_drivr_get - get driver extent information
  4210. * @phba: pointer to lpfc hba data structure.
  4211. * @pbuffer: pointer to internal buffer.
  4212. * @len: length into the internal buffer data has been copied.
  4213. *
  4214. * Description:
  4215. * This routine is to get the driver extent information.
  4216. *
  4217. * Returns:
  4218. * overall lenth of the data read into the internal buffer.
  4219. **/
  4220. static int
  4221. lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
  4222. {
  4223. struct lpfc_rsrc_blks *rsrc_blks;
  4224. int index;
  4225. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4226. "\nDriver Extents Information:\n");
  4227. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4228. "\tVPI extents:\n");
  4229. index = 0;
  4230. list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
  4231. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4232. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4233. index, rsrc_blks->rsrc_start,
  4234. rsrc_blks->rsrc_size);
  4235. index++;
  4236. }
  4237. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4238. "\tVFI extents:\n");
  4239. index = 0;
  4240. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
  4241. list) {
  4242. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4243. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4244. index, rsrc_blks->rsrc_start,
  4245. rsrc_blks->rsrc_size);
  4246. index++;
  4247. }
  4248. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4249. "\tRPI extents:\n");
  4250. index = 0;
  4251. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
  4252. list) {
  4253. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4254. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4255. index, rsrc_blks->rsrc_start,
  4256. rsrc_blks->rsrc_size);
  4257. index++;
  4258. }
  4259. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4260. "\tXRI extents:\n");
  4261. index = 0;
  4262. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
  4263. list) {
  4264. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4265. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4266. index, rsrc_blks->rsrc_start,
  4267. rsrc_blks->rsrc_size);
  4268. index++;
  4269. }
  4270. return len;
  4271. }
  4272. /**
  4273. * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
  4274. * @file: The file pointer to read from.
  4275. * @buf: The buffer to copy the user data from.
  4276. * @nbytes: The number of bytes to get.
  4277. * @ppos: The position in the file to start reading from.
  4278. *
  4279. * This routine get the debugfs idiag command struct from user space and then
  4280. * perform the syntax check for extent information access commands and sets
  4281. * up the necessary states in the idiag command struct accordingly.
  4282. *
  4283. * It returns the @nbytges passing in from debugfs user space when successful.
  4284. * In case of error conditions, it returns proper error code back to the user
  4285. * space.
  4286. **/
  4287. static ssize_t
  4288. lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
  4289. size_t nbytes, loff_t *ppos)
  4290. {
  4291. struct lpfc_debug *debug = file->private_data;
  4292. uint32_t ext_map;
  4293. int rc;
  4294. /* This is a user write operation */
  4295. debug->op = LPFC_IDIAG_OP_WR;
  4296. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  4297. if (rc < 0)
  4298. return rc;
  4299. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  4300. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  4301. goto error_out;
  4302. if (rc != LPFC_EXT_ACC_CMD_ARG)
  4303. goto error_out;
  4304. if (!(ext_map & LPFC_EXT_ACC_ALL))
  4305. goto error_out;
  4306. return nbytes;
  4307. error_out:
  4308. /* Clean out command structure on command error out */
  4309. memset(&idiag, 0, sizeof(idiag));
  4310. return -EINVAL;
  4311. }
  4312. /**
  4313. * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
  4314. * @file: The file pointer to read from.
  4315. * @buf: The buffer to copy the data to.
  4316. * @nbytes: The number of bytes to read.
  4317. * @ppos: The position in the file to start reading from.
  4318. *
  4319. * Description:
  4320. * This routine reads data from the proper extent information according to
  4321. * the idiag command, and copies to user @buf.
  4322. *
  4323. * Returns:
  4324. * This function returns the amount of data that was read (this could be less
  4325. * than @nbytes if the end of the file was reached) or a negative error value.
  4326. **/
  4327. static ssize_t
  4328. lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
  4329. loff_t *ppos)
  4330. {
  4331. struct lpfc_debug *debug = file->private_data;
  4332. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4333. char *pbuffer;
  4334. uint32_t ext_map;
  4335. int len = 0;
  4336. /* This is a user read operation */
  4337. debug->op = LPFC_IDIAG_OP_RD;
  4338. if (!debug->buffer)
  4339. debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
  4340. if (!debug->buffer)
  4341. return 0;
  4342. pbuffer = debug->buffer;
  4343. if (*ppos)
  4344. return 0;
  4345. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  4346. return 0;
  4347. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  4348. if (ext_map & LPFC_EXT_ACC_AVAIL)
  4349. len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
  4350. if (ext_map & LPFC_EXT_ACC_ALLOC)
  4351. len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
  4352. if (ext_map & LPFC_EXT_ACC_DRIVR)
  4353. len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
  4354. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  4355. }
  4356. #undef lpfc_debugfs_op_disc_trc
  4357. static const struct file_operations lpfc_debugfs_op_disc_trc = {
  4358. .owner = THIS_MODULE,
  4359. .open = lpfc_debugfs_disc_trc_open,
  4360. .llseek = lpfc_debugfs_lseek,
  4361. .read = lpfc_debugfs_read,
  4362. .release = lpfc_debugfs_release,
  4363. };
  4364. #undef lpfc_debugfs_op_nodelist
  4365. static const struct file_operations lpfc_debugfs_op_nodelist = {
  4366. .owner = THIS_MODULE,
  4367. .open = lpfc_debugfs_nodelist_open,
  4368. .llseek = lpfc_debugfs_lseek,
  4369. .read = lpfc_debugfs_read,
  4370. .release = lpfc_debugfs_release,
  4371. };
  4372. #undef lpfc_debugfs_op_hbqinfo
  4373. static const struct file_operations lpfc_debugfs_op_hbqinfo = {
  4374. .owner = THIS_MODULE,
  4375. .open = lpfc_debugfs_hbqinfo_open,
  4376. .llseek = lpfc_debugfs_lseek,
  4377. .read = lpfc_debugfs_read,
  4378. .release = lpfc_debugfs_release,
  4379. };
  4380. #undef lpfc_debugfs_op_dumpHBASlim
  4381. static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  4382. .owner = THIS_MODULE,
  4383. .open = lpfc_debugfs_dumpHBASlim_open,
  4384. .llseek = lpfc_debugfs_lseek,
  4385. .read = lpfc_debugfs_read,
  4386. .release = lpfc_debugfs_release,
  4387. };
  4388. #undef lpfc_debugfs_op_dumpHostSlim
  4389. static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  4390. .owner = THIS_MODULE,
  4391. .open = lpfc_debugfs_dumpHostSlim_open,
  4392. .llseek = lpfc_debugfs_lseek,
  4393. .read = lpfc_debugfs_read,
  4394. .release = lpfc_debugfs_release,
  4395. };
  4396. #undef lpfc_debugfs_op_nvmestat
  4397. static const struct file_operations lpfc_debugfs_op_nvmestat = {
  4398. .owner = THIS_MODULE,
  4399. .open = lpfc_debugfs_nvmestat_open,
  4400. .llseek = lpfc_debugfs_lseek,
  4401. .read = lpfc_debugfs_read,
  4402. .write = lpfc_debugfs_nvmestat_write,
  4403. .release = lpfc_debugfs_release,
  4404. };
  4405. #undef lpfc_debugfs_op_nvmektime
  4406. static const struct file_operations lpfc_debugfs_op_nvmektime = {
  4407. .owner = THIS_MODULE,
  4408. .open = lpfc_debugfs_nvmektime_open,
  4409. .llseek = lpfc_debugfs_lseek,
  4410. .read = lpfc_debugfs_read,
  4411. .write = lpfc_debugfs_nvmektime_write,
  4412. .release = lpfc_debugfs_release,
  4413. };
  4414. #undef lpfc_debugfs_op_nvmeio_trc
  4415. static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
  4416. .owner = THIS_MODULE,
  4417. .open = lpfc_debugfs_nvmeio_trc_open,
  4418. .llseek = lpfc_debugfs_lseek,
  4419. .read = lpfc_debugfs_read,
  4420. .write = lpfc_debugfs_nvmeio_trc_write,
  4421. .release = lpfc_debugfs_release,
  4422. };
  4423. #undef lpfc_debugfs_op_cpucheck
  4424. static const struct file_operations lpfc_debugfs_op_cpucheck = {
  4425. .owner = THIS_MODULE,
  4426. .open = lpfc_debugfs_cpucheck_open,
  4427. .llseek = lpfc_debugfs_lseek,
  4428. .read = lpfc_debugfs_read,
  4429. .write = lpfc_debugfs_cpucheck_write,
  4430. .release = lpfc_debugfs_release,
  4431. };
  4432. #undef lpfc_debugfs_op_dumpData
  4433. static const struct file_operations lpfc_debugfs_op_dumpData = {
  4434. .owner = THIS_MODULE,
  4435. .open = lpfc_debugfs_dumpData_open,
  4436. .llseek = lpfc_debugfs_lseek,
  4437. .read = lpfc_debugfs_read,
  4438. .write = lpfc_debugfs_dumpDataDif_write,
  4439. .release = lpfc_debugfs_dumpDataDif_release,
  4440. };
  4441. #undef lpfc_debugfs_op_dumpDif
  4442. static const struct file_operations lpfc_debugfs_op_dumpDif = {
  4443. .owner = THIS_MODULE,
  4444. .open = lpfc_debugfs_dumpDif_open,
  4445. .llseek = lpfc_debugfs_lseek,
  4446. .read = lpfc_debugfs_read,
  4447. .write = lpfc_debugfs_dumpDataDif_write,
  4448. .release = lpfc_debugfs_dumpDataDif_release,
  4449. };
  4450. #undef lpfc_debugfs_op_dif_err
  4451. static const struct file_operations lpfc_debugfs_op_dif_err = {
  4452. .owner = THIS_MODULE,
  4453. .open = simple_open,
  4454. .llseek = lpfc_debugfs_lseek,
  4455. .read = lpfc_debugfs_dif_err_read,
  4456. .write = lpfc_debugfs_dif_err_write,
  4457. .release = lpfc_debugfs_dif_err_release,
  4458. };
  4459. #undef lpfc_debugfs_op_slow_ring_trc
  4460. static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  4461. .owner = THIS_MODULE,
  4462. .open = lpfc_debugfs_slow_ring_trc_open,
  4463. .llseek = lpfc_debugfs_lseek,
  4464. .read = lpfc_debugfs_read,
  4465. .release = lpfc_debugfs_release,
  4466. };
  4467. static struct dentry *lpfc_debugfs_root = NULL;
  4468. static atomic_t lpfc_debugfs_hba_count;
  4469. /*
  4470. * File operations for the iDiag debugfs
  4471. */
  4472. #undef lpfc_idiag_op_pciCfg
  4473. static const struct file_operations lpfc_idiag_op_pciCfg = {
  4474. .owner = THIS_MODULE,
  4475. .open = lpfc_idiag_open,
  4476. .llseek = lpfc_debugfs_lseek,
  4477. .read = lpfc_idiag_pcicfg_read,
  4478. .write = lpfc_idiag_pcicfg_write,
  4479. .release = lpfc_idiag_cmd_release,
  4480. };
  4481. #undef lpfc_idiag_op_barAcc
  4482. static const struct file_operations lpfc_idiag_op_barAcc = {
  4483. .owner = THIS_MODULE,
  4484. .open = lpfc_idiag_open,
  4485. .llseek = lpfc_debugfs_lseek,
  4486. .read = lpfc_idiag_baracc_read,
  4487. .write = lpfc_idiag_baracc_write,
  4488. .release = lpfc_idiag_cmd_release,
  4489. };
  4490. #undef lpfc_idiag_op_queInfo
  4491. static const struct file_operations lpfc_idiag_op_queInfo = {
  4492. .owner = THIS_MODULE,
  4493. .open = lpfc_idiag_open,
  4494. .read = lpfc_idiag_queinfo_read,
  4495. .release = lpfc_idiag_release,
  4496. };
  4497. #undef lpfc_idiag_op_queAcc
  4498. static const struct file_operations lpfc_idiag_op_queAcc = {
  4499. .owner = THIS_MODULE,
  4500. .open = lpfc_idiag_open,
  4501. .llseek = lpfc_debugfs_lseek,
  4502. .read = lpfc_idiag_queacc_read,
  4503. .write = lpfc_idiag_queacc_write,
  4504. .release = lpfc_idiag_cmd_release,
  4505. };
  4506. #undef lpfc_idiag_op_drbAcc
  4507. static const struct file_operations lpfc_idiag_op_drbAcc = {
  4508. .owner = THIS_MODULE,
  4509. .open = lpfc_idiag_open,
  4510. .llseek = lpfc_debugfs_lseek,
  4511. .read = lpfc_idiag_drbacc_read,
  4512. .write = lpfc_idiag_drbacc_write,
  4513. .release = lpfc_idiag_cmd_release,
  4514. };
  4515. #undef lpfc_idiag_op_ctlAcc
  4516. static const struct file_operations lpfc_idiag_op_ctlAcc = {
  4517. .owner = THIS_MODULE,
  4518. .open = lpfc_idiag_open,
  4519. .llseek = lpfc_debugfs_lseek,
  4520. .read = lpfc_idiag_ctlacc_read,
  4521. .write = lpfc_idiag_ctlacc_write,
  4522. .release = lpfc_idiag_cmd_release,
  4523. };
  4524. #undef lpfc_idiag_op_mbxAcc
  4525. static const struct file_operations lpfc_idiag_op_mbxAcc = {
  4526. .owner = THIS_MODULE,
  4527. .open = lpfc_idiag_open,
  4528. .llseek = lpfc_debugfs_lseek,
  4529. .read = lpfc_idiag_mbxacc_read,
  4530. .write = lpfc_idiag_mbxacc_write,
  4531. .release = lpfc_idiag_cmd_release,
  4532. };
  4533. #undef lpfc_idiag_op_extAcc
  4534. static const struct file_operations lpfc_idiag_op_extAcc = {
  4535. .owner = THIS_MODULE,
  4536. .open = lpfc_idiag_open,
  4537. .llseek = lpfc_debugfs_lseek,
  4538. .read = lpfc_idiag_extacc_read,
  4539. .write = lpfc_idiag_extacc_write,
  4540. .release = lpfc_idiag_cmd_release,
  4541. };
  4542. #endif
  4543. /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
  4544. * @phba: Pointer to HBA context object.
  4545. * @dmabuf: Pointer to a DMA buffer descriptor.
  4546. *
  4547. * Description:
  4548. * This routine dump a bsg pass-through non-embedded mailbox command with
  4549. * external buffer.
  4550. **/
  4551. void
  4552. lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
  4553. enum mbox_type mbox_tp, enum dma_type dma_tp,
  4554. enum sta_type sta_tp,
  4555. struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
  4556. {
  4557. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  4558. uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
  4559. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  4560. int len = 0;
  4561. uint32_t do_dump = 0;
  4562. uint32_t *pword;
  4563. uint32_t i;
  4564. if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
  4565. return;
  4566. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  4567. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  4568. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  4569. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  4570. if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
  4571. (*mbx_dump_cnt == 0) ||
  4572. (*mbx_word_cnt == 0))
  4573. return;
  4574. if (*mbx_mbox_cmd != 0x9B)
  4575. return;
  4576. if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
  4577. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
  4578. do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
  4579. pr_err("\nRead mbox command (x%x), "
  4580. "nemb:0x%x, extbuf_cnt:%d:\n",
  4581. sta_tp, nemb_tp, ext_buf);
  4582. }
  4583. }
  4584. if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
  4585. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
  4586. do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
  4587. pr_err("\nRead mbox buffer (x%x), "
  4588. "nemb:0x%x, extbuf_seq:%d:\n",
  4589. sta_tp, nemb_tp, ext_buf);
  4590. }
  4591. }
  4592. if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
  4593. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
  4594. do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
  4595. pr_err("\nWrite mbox command (x%x), "
  4596. "nemb:0x%x, extbuf_cnt:%d:\n",
  4597. sta_tp, nemb_tp, ext_buf);
  4598. }
  4599. }
  4600. if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
  4601. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
  4602. do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
  4603. pr_err("\nWrite mbox buffer (x%x), "
  4604. "nemb:0x%x, extbuf_seq:%d:\n",
  4605. sta_tp, nemb_tp, ext_buf);
  4606. }
  4607. }
  4608. /* dump buffer content */
  4609. if (do_dump) {
  4610. pword = (uint32_t *)dmabuf->virt;
  4611. for (i = 0; i < *mbx_word_cnt; i++) {
  4612. if (!(i % 8)) {
  4613. if (i != 0)
  4614. pr_err("%s\n", line_buf);
  4615. len = 0;
  4616. len += scnprintf(line_buf+len,
  4617. LPFC_MBX_ACC_LBUF_SZ-len,
  4618. "%03d: ", i);
  4619. }
  4620. len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  4621. "%08x ", (uint32_t)*pword);
  4622. pword++;
  4623. }
  4624. if ((i - 1) % 8)
  4625. pr_err("%s\n", line_buf);
  4626. (*mbx_dump_cnt)--;
  4627. }
  4628. /* Clean out command structure on reaching dump count */
  4629. if (*mbx_dump_cnt == 0)
  4630. memset(&idiag, 0, sizeof(idiag));
  4631. return;
  4632. #endif
  4633. }
  4634. /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
  4635. * @phba: Pointer to HBA context object.
  4636. * @dmabuf: Pointer to a DMA buffer descriptor.
  4637. *
  4638. * Description:
  4639. * This routine dump a pass-through non-embedded mailbox command from issue
  4640. * mailbox command.
  4641. **/
  4642. void
  4643. lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
  4644. {
  4645. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  4646. uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
  4647. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  4648. int len = 0;
  4649. uint32_t *pword;
  4650. uint8_t *pbyte;
  4651. uint32_t i, j;
  4652. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
  4653. return;
  4654. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  4655. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  4656. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  4657. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  4658. if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
  4659. (*mbx_dump_cnt == 0) ||
  4660. (*mbx_word_cnt == 0))
  4661. return;
  4662. if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
  4663. (*mbx_mbox_cmd != pmbox->mbxCommand))
  4664. return;
  4665. /* dump buffer content */
  4666. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
  4667. pr_err("Mailbox command:0x%x dump by word:\n",
  4668. pmbox->mbxCommand);
  4669. pword = (uint32_t *)pmbox;
  4670. for (i = 0; i < *mbx_word_cnt; i++) {
  4671. if (!(i % 8)) {
  4672. if (i != 0)
  4673. pr_err("%s\n", line_buf);
  4674. len = 0;
  4675. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  4676. len += scnprintf(line_buf+len,
  4677. LPFC_MBX_ACC_LBUF_SZ-len,
  4678. "%03d: ", i);
  4679. }
  4680. len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  4681. "%08x ",
  4682. ((uint32_t)*pword) & 0xffffffff);
  4683. pword++;
  4684. }
  4685. if ((i - 1) % 8)
  4686. pr_err("%s\n", line_buf);
  4687. pr_err("\n");
  4688. }
  4689. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
  4690. pr_err("Mailbox command:0x%x dump by byte:\n",
  4691. pmbox->mbxCommand);
  4692. pbyte = (uint8_t *)pmbox;
  4693. for (i = 0; i < *mbx_word_cnt; i++) {
  4694. if (!(i % 8)) {
  4695. if (i != 0)
  4696. pr_err("%s\n", line_buf);
  4697. len = 0;
  4698. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  4699. len += scnprintf(line_buf+len,
  4700. LPFC_MBX_ACC_LBUF_SZ-len,
  4701. "%03d: ", i);
  4702. }
  4703. for (j = 0; j < 4; j++) {
  4704. len += scnprintf(line_buf+len,
  4705. LPFC_MBX_ACC_LBUF_SZ-len,
  4706. "%02x",
  4707. ((uint8_t)*pbyte) & 0xff);
  4708. pbyte++;
  4709. }
  4710. len += scnprintf(line_buf+len,
  4711. LPFC_MBX_ACC_LBUF_SZ-len, " ");
  4712. }
  4713. if ((i - 1) % 8)
  4714. pr_err("%s\n", line_buf);
  4715. pr_err("\n");
  4716. }
  4717. (*mbx_dump_cnt)--;
  4718. /* Clean out command structure on reaching dump count */
  4719. if (*mbx_dump_cnt == 0)
  4720. memset(&idiag, 0, sizeof(idiag));
  4721. return;
  4722. #endif
  4723. }
  4724. /**
  4725. * lpfc_debugfs_initialize - Initialize debugfs for a vport
  4726. * @vport: The vport pointer to initialize.
  4727. *
  4728. * Description:
  4729. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  4730. * If not already created, this routine will create the lpfc directory, and
  4731. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  4732. * also create each file used to access lpfc specific debugfs information.
  4733. **/
  4734. inline void
  4735. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  4736. {
  4737. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  4738. struct lpfc_hba *phba = vport->phba;
  4739. char name[64];
  4740. uint32_t num, i;
  4741. bool pport_setup = false;
  4742. if (!lpfc_debugfs_enable)
  4743. return;
  4744. /* Setup lpfc root directory */
  4745. if (!lpfc_debugfs_root) {
  4746. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  4747. atomic_set(&lpfc_debugfs_hba_count, 0);
  4748. if (!lpfc_debugfs_root) {
  4749. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4750. "0408 Cannot create debugfs root\n");
  4751. goto debug_failed;
  4752. }
  4753. }
  4754. if (!lpfc_debugfs_start_time)
  4755. lpfc_debugfs_start_time = jiffies;
  4756. /* Setup funcX directory for specific HBA PCI function */
  4757. snprintf(name, sizeof(name), "fn%d", phba->brd_no);
  4758. if (!phba->hba_debugfs_root) {
  4759. pport_setup = true;
  4760. phba->hba_debugfs_root =
  4761. debugfs_create_dir(name, lpfc_debugfs_root);
  4762. if (!phba->hba_debugfs_root) {
  4763. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4764. "0412 Cannot create debugfs hba\n");
  4765. goto debug_failed;
  4766. }
  4767. atomic_inc(&lpfc_debugfs_hba_count);
  4768. atomic_set(&phba->debugfs_vport_count, 0);
  4769. /* Setup hbqinfo */
  4770. snprintf(name, sizeof(name), "hbqinfo");
  4771. phba->debug_hbqinfo =
  4772. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4773. phba->hba_debugfs_root,
  4774. phba, &lpfc_debugfs_op_hbqinfo);
  4775. if (!phba->debug_hbqinfo) {
  4776. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4777. "0411 Cannot create debugfs hbqinfo\n");
  4778. goto debug_failed;
  4779. }
  4780. /* Setup dumpHBASlim */
  4781. if (phba->sli_rev < LPFC_SLI_REV4) {
  4782. snprintf(name, sizeof(name), "dumpHBASlim");
  4783. phba->debug_dumpHBASlim =
  4784. debugfs_create_file(name,
  4785. S_IFREG|S_IRUGO|S_IWUSR,
  4786. phba->hba_debugfs_root,
  4787. phba, &lpfc_debugfs_op_dumpHBASlim);
  4788. if (!phba->debug_dumpHBASlim) {
  4789. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4790. "0413 Cannot create debugfs "
  4791. "dumpHBASlim\n");
  4792. goto debug_failed;
  4793. }
  4794. } else
  4795. phba->debug_dumpHBASlim = NULL;
  4796. /* Setup dumpHostSlim */
  4797. if (phba->sli_rev < LPFC_SLI_REV4) {
  4798. snprintf(name, sizeof(name), "dumpHostSlim");
  4799. phba->debug_dumpHostSlim =
  4800. debugfs_create_file(name,
  4801. S_IFREG|S_IRUGO|S_IWUSR,
  4802. phba->hba_debugfs_root,
  4803. phba, &lpfc_debugfs_op_dumpHostSlim);
  4804. if (!phba->debug_dumpHostSlim) {
  4805. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4806. "0414 Cannot create debugfs "
  4807. "dumpHostSlim\n");
  4808. goto debug_failed;
  4809. }
  4810. } else
  4811. phba->debug_dumpHostSlim = NULL;
  4812. /* Setup dumpData */
  4813. snprintf(name, sizeof(name), "dumpData");
  4814. phba->debug_dumpData =
  4815. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4816. phba->hba_debugfs_root,
  4817. phba, &lpfc_debugfs_op_dumpData);
  4818. if (!phba->debug_dumpData) {
  4819. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4820. "0800 Cannot create debugfs dumpData\n");
  4821. goto debug_failed;
  4822. }
  4823. /* Setup dumpDif */
  4824. snprintf(name, sizeof(name), "dumpDif");
  4825. phba->debug_dumpDif =
  4826. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4827. phba->hba_debugfs_root,
  4828. phba, &lpfc_debugfs_op_dumpDif);
  4829. if (!phba->debug_dumpDif) {
  4830. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4831. "0801 Cannot create debugfs dumpDif\n");
  4832. goto debug_failed;
  4833. }
  4834. /* Setup DIF Error Injections */
  4835. snprintf(name, sizeof(name), "InjErrLBA");
  4836. phba->debug_InjErrLBA =
  4837. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4838. phba->hba_debugfs_root,
  4839. phba, &lpfc_debugfs_op_dif_err);
  4840. if (!phba->debug_InjErrLBA) {
  4841. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4842. "0807 Cannot create debugfs InjErrLBA\n");
  4843. goto debug_failed;
  4844. }
  4845. phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
  4846. snprintf(name, sizeof(name), "InjErrNPortID");
  4847. phba->debug_InjErrNPortID =
  4848. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4849. phba->hba_debugfs_root,
  4850. phba, &lpfc_debugfs_op_dif_err);
  4851. if (!phba->debug_InjErrNPortID) {
  4852. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4853. "0809 Cannot create debugfs InjErrNPortID\n");
  4854. goto debug_failed;
  4855. }
  4856. snprintf(name, sizeof(name), "InjErrWWPN");
  4857. phba->debug_InjErrWWPN =
  4858. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4859. phba->hba_debugfs_root,
  4860. phba, &lpfc_debugfs_op_dif_err);
  4861. if (!phba->debug_InjErrWWPN) {
  4862. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4863. "0810 Cannot create debugfs InjErrWWPN\n");
  4864. goto debug_failed;
  4865. }
  4866. snprintf(name, sizeof(name), "writeGuardInjErr");
  4867. phba->debug_writeGuard =
  4868. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4869. phba->hba_debugfs_root,
  4870. phba, &lpfc_debugfs_op_dif_err);
  4871. if (!phba->debug_writeGuard) {
  4872. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4873. "0802 Cannot create debugfs writeGuard\n");
  4874. goto debug_failed;
  4875. }
  4876. snprintf(name, sizeof(name), "writeAppInjErr");
  4877. phba->debug_writeApp =
  4878. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4879. phba->hba_debugfs_root,
  4880. phba, &lpfc_debugfs_op_dif_err);
  4881. if (!phba->debug_writeApp) {
  4882. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4883. "0803 Cannot create debugfs writeApp\n");
  4884. goto debug_failed;
  4885. }
  4886. snprintf(name, sizeof(name), "writeRefInjErr");
  4887. phba->debug_writeRef =
  4888. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4889. phba->hba_debugfs_root,
  4890. phba, &lpfc_debugfs_op_dif_err);
  4891. if (!phba->debug_writeRef) {
  4892. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4893. "0804 Cannot create debugfs writeRef\n");
  4894. goto debug_failed;
  4895. }
  4896. snprintf(name, sizeof(name), "readGuardInjErr");
  4897. phba->debug_readGuard =
  4898. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4899. phba->hba_debugfs_root,
  4900. phba, &lpfc_debugfs_op_dif_err);
  4901. if (!phba->debug_readGuard) {
  4902. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4903. "0808 Cannot create debugfs readGuard\n");
  4904. goto debug_failed;
  4905. }
  4906. snprintf(name, sizeof(name), "readAppInjErr");
  4907. phba->debug_readApp =
  4908. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4909. phba->hba_debugfs_root,
  4910. phba, &lpfc_debugfs_op_dif_err);
  4911. if (!phba->debug_readApp) {
  4912. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4913. "0805 Cannot create debugfs readApp\n");
  4914. goto debug_failed;
  4915. }
  4916. snprintf(name, sizeof(name), "readRefInjErr");
  4917. phba->debug_readRef =
  4918. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4919. phba->hba_debugfs_root,
  4920. phba, &lpfc_debugfs_op_dif_err);
  4921. if (!phba->debug_readRef) {
  4922. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4923. "0806 Cannot create debugfs readApp\n");
  4924. goto debug_failed;
  4925. }
  4926. /* Setup slow ring trace */
  4927. if (lpfc_debugfs_max_slow_ring_trc) {
  4928. num = lpfc_debugfs_max_slow_ring_trc - 1;
  4929. if (num & lpfc_debugfs_max_slow_ring_trc) {
  4930. /* Change to be a power of 2 */
  4931. num = lpfc_debugfs_max_slow_ring_trc;
  4932. i = 0;
  4933. while (num > 1) {
  4934. num = num >> 1;
  4935. i++;
  4936. }
  4937. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  4938. pr_err("lpfc_debugfs_max_disc_trc changed to "
  4939. "%d\n", lpfc_debugfs_max_disc_trc);
  4940. }
  4941. }
  4942. snprintf(name, sizeof(name), "slow_ring_trace");
  4943. phba->debug_slow_ring_trc =
  4944. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  4945. phba->hba_debugfs_root,
  4946. phba, &lpfc_debugfs_op_slow_ring_trc);
  4947. if (!phba->debug_slow_ring_trc) {
  4948. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4949. "0415 Cannot create debugfs "
  4950. "slow_ring_trace\n");
  4951. goto debug_failed;
  4952. }
  4953. if (!phba->slow_ring_trc) {
  4954. phba->slow_ring_trc = kmalloc(
  4955. (sizeof(struct lpfc_debugfs_trc) *
  4956. lpfc_debugfs_max_slow_ring_trc),
  4957. GFP_KERNEL);
  4958. if (!phba->slow_ring_trc) {
  4959. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4960. "0416 Cannot create debugfs "
  4961. "slow_ring buffer\n");
  4962. goto debug_failed;
  4963. }
  4964. atomic_set(&phba->slow_ring_trc_cnt, 0);
  4965. memset(phba->slow_ring_trc, 0,
  4966. (sizeof(struct lpfc_debugfs_trc) *
  4967. lpfc_debugfs_max_slow_ring_trc));
  4968. }
  4969. snprintf(name, sizeof(name), "nvmeio_trc");
  4970. phba->debug_nvmeio_trc =
  4971. debugfs_create_file(name, 0644,
  4972. phba->hba_debugfs_root,
  4973. phba, &lpfc_debugfs_op_nvmeio_trc);
  4974. if (!phba->debug_nvmeio_trc) {
  4975. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  4976. "0574 No create debugfs nvmeio_trc\n");
  4977. goto debug_failed;
  4978. }
  4979. atomic_set(&phba->nvmeio_trc_cnt, 0);
  4980. if (lpfc_debugfs_max_nvmeio_trc) {
  4981. num = lpfc_debugfs_max_nvmeio_trc - 1;
  4982. if (num & lpfc_debugfs_max_disc_trc) {
  4983. /* Change to be a power of 2 */
  4984. num = lpfc_debugfs_max_nvmeio_trc;
  4985. i = 0;
  4986. while (num > 1) {
  4987. num = num >> 1;
  4988. i++;
  4989. }
  4990. lpfc_debugfs_max_nvmeio_trc = (1 << i);
  4991. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4992. "0575 lpfc_debugfs_max_nvmeio_trc "
  4993. "changed to %d\n",
  4994. lpfc_debugfs_max_nvmeio_trc);
  4995. }
  4996. phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
  4997. /* Allocate trace buffer and initialize */
  4998. phba->nvmeio_trc = kzalloc(
  4999. (sizeof(struct lpfc_debugfs_nvmeio_trc) *
  5000. phba->nvmeio_trc_size), GFP_KERNEL);
  5001. if (!phba->nvmeio_trc) {
  5002. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5003. "0576 Cannot create debugfs "
  5004. "nvmeio_trc buffer\n");
  5005. goto nvmeio_off;
  5006. }
  5007. phba->nvmeio_trc_on = 1;
  5008. phba->nvmeio_trc_output_idx = 0;
  5009. phba->nvmeio_trc = NULL;
  5010. } else {
  5011. nvmeio_off:
  5012. phba->nvmeio_trc_size = 0;
  5013. phba->nvmeio_trc_on = 0;
  5014. phba->nvmeio_trc_output_idx = 0;
  5015. phba->nvmeio_trc = NULL;
  5016. }
  5017. }
  5018. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  5019. if (!vport->vport_debugfs_root) {
  5020. vport->vport_debugfs_root =
  5021. debugfs_create_dir(name, phba->hba_debugfs_root);
  5022. if (!vport->vport_debugfs_root) {
  5023. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5024. "0417 Can't create debugfs\n");
  5025. goto debug_failed;
  5026. }
  5027. atomic_inc(&phba->debugfs_vport_count);
  5028. }
  5029. if (lpfc_debugfs_max_disc_trc) {
  5030. num = lpfc_debugfs_max_disc_trc - 1;
  5031. if (num & lpfc_debugfs_max_disc_trc) {
  5032. /* Change to be a power of 2 */
  5033. num = lpfc_debugfs_max_disc_trc;
  5034. i = 0;
  5035. while (num > 1) {
  5036. num = num >> 1;
  5037. i++;
  5038. }
  5039. lpfc_debugfs_max_disc_trc = (1 << i);
  5040. pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
  5041. lpfc_debugfs_max_disc_trc);
  5042. }
  5043. }
  5044. vport->disc_trc = kzalloc(
  5045. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  5046. GFP_KERNEL);
  5047. if (!vport->disc_trc) {
  5048. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5049. "0418 Cannot create debugfs disc trace "
  5050. "buffer\n");
  5051. goto debug_failed;
  5052. }
  5053. atomic_set(&vport->disc_trc_cnt, 0);
  5054. snprintf(name, sizeof(name), "discovery_trace");
  5055. vport->debug_disc_trc =
  5056. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5057. vport->vport_debugfs_root,
  5058. vport, &lpfc_debugfs_op_disc_trc);
  5059. if (!vport->debug_disc_trc) {
  5060. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5061. "0419 Cannot create debugfs "
  5062. "discovery_trace\n");
  5063. goto debug_failed;
  5064. }
  5065. snprintf(name, sizeof(name), "nodelist");
  5066. vport->debug_nodelist =
  5067. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5068. vport->vport_debugfs_root,
  5069. vport, &lpfc_debugfs_op_nodelist);
  5070. if (!vport->debug_nodelist) {
  5071. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5072. "2985 Can't create debugfs nodelist\n");
  5073. goto debug_failed;
  5074. }
  5075. snprintf(name, sizeof(name), "nvmestat");
  5076. vport->debug_nvmestat =
  5077. debugfs_create_file(name, 0644,
  5078. vport->vport_debugfs_root,
  5079. vport, &lpfc_debugfs_op_nvmestat);
  5080. if (!vport->debug_nvmestat) {
  5081. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5082. "0811 Cannot create debugfs nvmestat\n");
  5083. goto debug_failed;
  5084. }
  5085. snprintf(name, sizeof(name), "nvmektime");
  5086. vport->debug_nvmektime =
  5087. debugfs_create_file(name, 0644,
  5088. vport->vport_debugfs_root,
  5089. vport, &lpfc_debugfs_op_nvmektime);
  5090. if (!vport->debug_nvmektime) {
  5091. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5092. "0815 Cannot create debugfs nvmektime\n");
  5093. goto debug_failed;
  5094. }
  5095. snprintf(name, sizeof(name), "cpucheck");
  5096. vport->debug_cpucheck =
  5097. debugfs_create_file(name, 0644,
  5098. vport->vport_debugfs_root,
  5099. vport, &lpfc_debugfs_op_cpucheck);
  5100. if (!vport->debug_cpucheck) {
  5101. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5102. "0819 Cannot create debugfs cpucheck\n");
  5103. goto debug_failed;
  5104. }
  5105. /*
  5106. * The following section is for additional directories/files for the
  5107. * physical port.
  5108. */
  5109. if (!pport_setup)
  5110. goto debug_failed;
  5111. /*
  5112. * iDiag debugfs root entry points for SLI4 device only
  5113. */
  5114. if (phba->sli_rev < LPFC_SLI_REV4)
  5115. goto debug_failed;
  5116. snprintf(name, sizeof(name), "iDiag");
  5117. if (!phba->idiag_root) {
  5118. phba->idiag_root =
  5119. debugfs_create_dir(name, phba->hba_debugfs_root);
  5120. if (!phba->idiag_root) {
  5121. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5122. "2922 Can't create idiag debugfs\n");
  5123. goto debug_failed;
  5124. }
  5125. /* Initialize iDiag data structure */
  5126. memset(&idiag, 0, sizeof(idiag));
  5127. }
  5128. /* iDiag read PCI config space */
  5129. snprintf(name, sizeof(name), "pciCfg");
  5130. if (!phba->idiag_pci_cfg) {
  5131. phba->idiag_pci_cfg =
  5132. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5133. phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
  5134. if (!phba->idiag_pci_cfg) {
  5135. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5136. "2923 Can't create idiag debugfs\n");
  5137. goto debug_failed;
  5138. }
  5139. idiag.offset.last_rd = 0;
  5140. }
  5141. /* iDiag PCI BAR access */
  5142. snprintf(name, sizeof(name), "barAcc");
  5143. if (!phba->idiag_bar_acc) {
  5144. phba->idiag_bar_acc =
  5145. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5146. phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
  5147. if (!phba->idiag_bar_acc) {
  5148. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5149. "3056 Can't create idiag debugfs\n");
  5150. goto debug_failed;
  5151. }
  5152. idiag.offset.last_rd = 0;
  5153. }
  5154. /* iDiag get PCI function queue information */
  5155. snprintf(name, sizeof(name), "queInfo");
  5156. if (!phba->idiag_que_info) {
  5157. phba->idiag_que_info =
  5158. debugfs_create_file(name, S_IFREG|S_IRUGO,
  5159. phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
  5160. if (!phba->idiag_que_info) {
  5161. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5162. "2924 Can't create idiag debugfs\n");
  5163. goto debug_failed;
  5164. }
  5165. }
  5166. /* iDiag access PCI function queue */
  5167. snprintf(name, sizeof(name), "queAcc");
  5168. if (!phba->idiag_que_acc) {
  5169. phba->idiag_que_acc =
  5170. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5171. phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
  5172. if (!phba->idiag_que_acc) {
  5173. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5174. "2926 Can't create idiag debugfs\n");
  5175. goto debug_failed;
  5176. }
  5177. }
  5178. /* iDiag access PCI function doorbell registers */
  5179. snprintf(name, sizeof(name), "drbAcc");
  5180. if (!phba->idiag_drb_acc) {
  5181. phba->idiag_drb_acc =
  5182. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5183. phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
  5184. if (!phba->idiag_drb_acc) {
  5185. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5186. "2927 Can't create idiag debugfs\n");
  5187. goto debug_failed;
  5188. }
  5189. }
  5190. /* iDiag access PCI function control registers */
  5191. snprintf(name, sizeof(name), "ctlAcc");
  5192. if (!phba->idiag_ctl_acc) {
  5193. phba->idiag_ctl_acc =
  5194. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5195. phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
  5196. if (!phba->idiag_ctl_acc) {
  5197. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5198. "2981 Can't create idiag debugfs\n");
  5199. goto debug_failed;
  5200. }
  5201. }
  5202. /* iDiag access mbox commands */
  5203. snprintf(name, sizeof(name), "mbxAcc");
  5204. if (!phba->idiag_mbx_acc) {
  5205. phba->idiag_mbx_acc =
  5206. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5207. phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
  5208. if (!phba->idiag_mbx_acc) {
  5209. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5210. "2980 Can't create idiag debugfs\n");
  5211. goto debug_failed;
  5212. }
  5213. }
  5214. /* iDiag extents access commands */
  5215. if (phba->sli4_hba.extents_in_use) {
  5216. snprintf(name, sizeof(name), "extAcc");
  5217. if (!phba->idiag_ext_acc) {
  5218. phba->idiag_ext_acc =
  5219. debugfs_create_file(name,
  5220. S_IFREG|S_IRUGO|S_IWUSR,
  5221. phba->idiag_root, phba,
  5222. &lpfc_idiag_op_extAcc);
  5223. if (!phba->idiag_ext_acc) {
  5224. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5225. "2986 Cant create "
  5226. "idiag debugfs\n");
  5227. goto debug_failed;
  5228. }
  5229. }
  5230. }
  5231. debug_failed:
  5232. return;
  5233. #endif
  5234. }
  5235. /**
  5236. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
  5237. * @vport: The vport pointer to remove from debugfs.
  5238. *
  5239. * Description:
  5240. * When Debugfs is configured this routine removes debugfs file system elements
  5241. * that are specific to this vport. It also checks to see if there are any
  5242. * users left for the debugfs directories associated with the HBA and driver. If
  5243. * this is the last user of the HBA directory or driver directory then it will
  5244. * remove those from the debugfs infrastructure as well.
  5245. **/
  5246. inline void
  5247. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  5248. {
  5249. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  5250. struct lpfc_hba *phba = vport->phba;
  5251. kfree(vport->disc_trc);
  5252. vport->disc_trc = NULL;
  5253. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  5254. vport->debug_disc_trc = NULL;
  5255. debugfs_remove(vport->debug_nodelist); /* nodelist */
  5256. vport->debug_nodelist = NULL;
  5257. debugfs_remove(vport->debug_nvmestat); /* nvmestat */
  5258. vport->debug_nvmestat = NULL;
  5259. debugfs_remove(vport->debug_nvmektime); /* nvmektime */
  5260. vport->debug_nvmektime = NULL;
  5261. debugfs_remove(vport->debug_cpucheck); /* cpucheck */
  5262. vport->debug_cpucheck = NULL;
  5263. if (vport->vport_debugfs_root) {
  5264. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  5265. vport->vport_debugfs_root = NULL;
  5266. atomic_dec(&phba->debugfs_vport_count);
  5267. }
  5268. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  5269. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  5270. phba->debug_hbqinfo = NULL;
  5271. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  5272. phba->debug_dumpHBASlim = NULL;
  5273. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  5274. phba->debug_dumpHostSlim = NULL;
  5275. debugfs_remove(phba->debug_dumpData); /* dumpData */
  5276. phba->debug_dumpData = NULL;
  5277. debugfs_remove(phba->debug_dumpDif); /* dumpDif */
  5278. phba->debug_dumpDif = NULL;
  5279. debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
  5280. phba->debug_InjErrLBA = NULL;
  5281. debugfs_remove(phba->debug_InjErrNPortID);
  5282. phba->debug_InjErrNPortID = NULL;
  5283. debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
  5284. phba->debug_InjErrWWPN = NULL;
  5285. debugfs_remove(phba->debug_writeGuard); /* writeGuard */
  5286. phba->debug_writeGuard = NULL;
  5287. debugfs_remove(phba->debug_writeApp); /* writeApp */
  5288. phba->debug_writeApp = NULL;
  5289. debugfs_remove(phba->debug_writeRef); /* writeRef */
  5290. phba->debug_writeRef = NULL;
  5291. debugfs_remove(phba->debug_readGuard); /* readGuard */
  5292. phba->debug_readGuard = NULL;
  5293. debugfs_remove(phba->debug_readApp); /* readApp */
  5294. phba->debug_readApp = NULL;
  5295. debugfs_remove(phba->debug_readRef); /* readRef */
  5296. phba->debug_readRef = NULL;
  5297. kfree(phba->slow_ring_trc);
  5298. phba->slow_ring_trc = NULL;
  5299. /* slow_ring_trace */
  5300. debugfs_remove(phba->debug_slow_ring_trc);
  5301. phba->debug_slow_ring_trc = NULL;
  5302. debugfs_remove(phba->debug_nvmeio_trc);
  5303. phba->debug_nvmeio_trc = NULL;
  5304. kfree(phba->nvmeio_trc);
  5305. phba->nvmeio_trc = NULL;
  5306. /*
  5307. * iDiag release
  5308. */
  5309. if (phba->sli_rev == LPFC_SLI_REV4) {
  5310. /* iDiag extAcc */
  5311. debugfs_remove(phba->idiag_ext_acc);
  5312. phba->idiag_ext_acc = NULL;
  5313. /* iDiag mbxAcc */
  5314. debugfs_remove(phba->idiag_mbx_acc);
  5315. phba->idiag_mbx_acc = NULL;
  5316. /* iDiag ctlAcc */
  5317. debugfs_remove(phba->idiag_ctl_acc);
  5318. phba->idiag_ctl_acc = NULL;
  5319. /* iDiag drbAcc */
  5320. debugfs_remove(phba->idiag_drb_acc);
  5321. phba->idiag_drb_acc = NULL;
  5322. /* iDiag queAcc */
  5323. debugfs_remove(phba->idiag_que_acc);
  5324. phba->idiag_que_acc = NULL;
  5325. /* iDiag queInfo */
  5326. debugfs_remove(phba->idiag_que_info);
  5327. phba->idiag_que_info = NULL;
  5328. /* iDiag barAcc */
  5329. debugfs_remove(phba->idiag_bar_acc);
  5330. phba->idiag_bar_acc = NULL;
  5331. /* iDiag pciCfg */
  5332. debugfs_remove(phba->idiag_pci_cfg);
  5333. phba->idiag_pci_cfg = NULL;
  5334. /* Finally remove the iDiag debugfs root */
  5335. debugfs_remove(phba->idiag_root);
  5336. phba->idiag_root = NULL;
  5337. }
  5338. if (phba->hba_debugfs_root) {
  5339. debugfs_remove(phba->hba_debugfs_root); /* fnX */
  5340. phba->hba_debugfs_root = NULL;
  5341. atomic_dec(&lpfc_debugfs_hba_count);
  5342. }
  5343. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  5344. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  5345. lpfc_debugfs_root = NULL;
  5346. }
  5347. }
  5348. #endif
  5349. return;
  5350. }
  5351. /*
  5352. * Driver debug utility routines outside of debugfs. The debug utility
  5353. * routines implemented here is intended to be used in the instrumented
  5354. * debug driver for debugging host or port issues.
  5355. */
  5356. /**
  5357. * lpfc_debug_dump_all_queues - dump all the queues with a hba
  5358. * @phba: Pointer to HBA context object.
  5359. *
  5360. * This function dumps entries of all the queues asociated with the @phba.
  5361. **/
  5362. void
  5363. lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
  5364. {
  5365. int idx;
  5366. /*
  5367. * Dump Work Queues (WQs)
  5368. */
  5369. lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
  5370. lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
  5371. lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
  5372. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
  5373. lpfc_debug_dump_wq(phba, DUMP_FCP, idx);
  5374. for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
  5375. lpfc_debug_dump_wq(phba, DUMP_NVME, idx);
  5376. lpfc_debug_dump_hdr_rq(phba);
  5377. lpfc_debug_dump_dat_rq(phba);
  5378. /*
  5379. * Dump Complete Queues (CQs)
  5380. */
  5381. lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
  5382. lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
  5383. lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
  5384. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
  5385. lpfc_debug_dump_cq(phba, DUMP_FCP, idx);
  5386. for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
  5387. lpfc_debug_dump_cq(phba, DUMP_NVME, idx);
  5388. /*
  5389. * Dump Event Queues (EQs)
  5390. */
  5391. for (idx = 0; idx < phba->io_channel_irqs; idx++)
  5392. lpfc_debug_dump_hba_eq(phba, idx);
  5393. }