lpfc_debugfs.c 190 KB

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