lpfc_debugfs.c 190 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2022 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 Scsi_Host *shost = lpfc_shost_from_vport(vport);
  729. struct lpfc_hba *phba = vport->phba;
  730. struct lpfc_nodelist *ndlp;
  731. unsigned char *statep;
  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_irq(shost->host_lock);
  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_irq(shost->host_lock);
  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. spin_lock_irq(shost->host_lock);
  855. /* Port state is only one of two values for now. */
  856. if (localport->port_id)
  857. statep = "ONLINE";
  858. else
  859. statep = "UNKNOWN ";
  860. len += scnprintf(buf + len, size - len,
  861. "Lport DID x%06x PortState %s\n",
  862. localport->port_id, statep);
  863. len += scnprintf(buf + len, size - len, "\tRport List:\n");
  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_irq(shost->host_lock);
  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->hbalock);
  1973. if (phba->ras_fwlog.state != ACTIVE) {
  1974. spin_unlock_irq(&phba->hbalock);
  1975. return -EINVAL;
  1976. }
  1977. spin_unlock_irq(&phba->hbalock);
  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->hbalock);
  2023. if (phba->ras_fwlog.state != ACTIVE) {
  2024. spin_unlock_irq(&phba->hbalock);
  2025. rc = -EINVAL;
  2026. goto out;
  2027. }
  2028. spin_unlock_irq(&phba->hbalock);
  2029. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2030. if (!debug)
  2031. goto out;
  2032. size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize;
  2033. debug->buffer = vmalloc(size);
  2034. if (!debug->buffer)
  2035. goto free_debug;
  2036. debug->len = lpfc_debugfs_ras_log_data(phba, debug->buffer, size);
  2037. if (debug->len < 0) {
  2038. rc = -EINVAL;
  2039. goto free_buffer;
  2040. }
  2041. file->private_data = debug;
  2042. return 0;
  2043. free_buffer:
  2044. vfree(debug->buffer);
  2045. free_debug:
  2046. kfree(debug);
  2047. out:
  2048. return rc;
  2049. }
  2050. /**
  2051. * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
  2052. * @inode: The inode pointer that contains a vport pointer.
  2053. * @file: The file pointer to attach the log output.
  2054. *
  2055. * Description:
  2056. * This routine is the entry point for the debugfs open file operation. It gets
  2057. * the vport from the i_private field in @inode, allocates the necessary buffer
  2058. * for the log, fills the buffer from the in-memory log for this vport, and then
  2059. * returns a pointer to that log in the private_data field in @file.
  2060. *
  2061. * Returns:
  2062. * This function returns zero if successful. On error it will return a negative
  2063. * error value.
  2064. **/
  2065. static int
  2066. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  2067. {
  2068. struct lpfc_hba *phba = inode->i_private;
  2069. struct lpfc_debug *debug;
  2070. int rc = -ENOMEM;
  2071. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2072. if (!debug)
  2073. goto out;
  2074. /* Round to page boundary */
  2075. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  2076. if (!debug->buffer) {
  2077. kfree(debug);
  2078. goto out;
  2079. }
  2080. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  2081. LPFC_DUMPHBASLIM_SIZE);
  2082. file->private_data = debug;
  2083. rc = 0;
  2084. out:
  2085. return rc;
  2086. }
  2087. /**
  2088. * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
  2089. * @inode: The inode pointer that contains a vport pointer.
  2090. * @file: The file pointer to attach the log output.
  2091. *
  2092. * Description:
  2093. * This routine is the entry point for the debugfs open file operation. It gets
  2094. * the vport from the i_private field in @inode, allocates the necessary buffer
  2095. * for the log, fills the buffer from the in-memory log for this vport, and then
  2096. * returns a pointer to that log in the private_data field in @file.
  2097. *
  2098. * Returns:
  2099. * This function returns zero if successful. On error it will return a negative
  2100. * error value.
  2101. **/
  2102. static int
  2103. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  2104. {
  2105. struct lpfc_hba *phba = inode->i_private;
  2106. struct lpfc_debug *debug;
  2107. int rc = -ENOMEM;
  2108. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2109. if (!debug)
  2110. goto out;
  2111. /* Round to page boundary */
  2112. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  2113. if (!debug->buffer) {
  2114. kfree(debug);
  2115. goto out;
  2116. }
  2117. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  2118. LPFC_DUMPHOSTSLIM_SIZE);
  2119. file->private_data = debug;
  2120. rc = 0;
  2121. out:
  2122. return rc;
  2123. }
  2124. static ssize_t
  2125. lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
  2126. size_t nbytes, loff_t *ppos)
  2127. {
  2128. struct dentry *dent = file->f_path.dentry;
  2129. struct lpfc_hba *phba = file->private_data;
  2130. char cbuf[32];
  2131. uint64_t tmp = 0;
  2132. int cnt = 0;
  2133. if (dent == phba->debug_writeGuard)
  2134. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
  2135. else if (dent == phba->debug_writeApp)
  2136. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
  2137. else if (dent == phba->debug_writeRef)
  2138. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
  2139. else if (dent == phba->debug_readGuard)
  2140. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
  2141. else if (dent == phba->debug_readApp)
  2142. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
  2143. else if (dent == phba->debug_readRef)
  2144. cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
  2145. else if (dent == phba->debug_InjErrNPortID)
  2146. cnt = scnprintf(cbuf, 32, "0x%06x\n",
  2147. phba->lpfc_injerr_nportid);
  2148. else if (dent == phba->debug_InjErrWWPN) {
  2149. memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
  2150. tmp = cpu_to_be64(tmp);
  2151. cnt = scnprintf(cbuf, 32, "0x%016llx\n", tmp);
  2152. } else if (dent == phba->debug_InjErrLBA) {
  2153. if (phba->lpfc_injerr_lba == (sector_t)(-1))
  2154. cnt = scnprintf(cbuf, 32, "off\n");
  2155. else
  2156. cnt = scnprintf(cbuf, 32, "0x%llx\n",
  2157. (uint64_t) phba->lpfc_injerr_lba);
  2158. } else
  2159. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2160. "0547 Unknown debugfs error injection entry\n");
  2161. return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
  2162. }
  2163. static ssize_t
  2164. lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
  2165. size_t nbytes, loff_t *ppos)
  2166. {
  2167. struct dentry *dent = file->f_path.dentry;
  2168. struct lpfc_hba *phba = file->private_data;
  2169. char dstbuf[33];
  2170. uint64_t tmp = 0;
  2171. int size;
  2172. memset(dstbuf, 0, 33);
  2173. size = (nbytes < 32) ? nbytes : 32;
  2174. if (copy_from_user(dstbuf, buf, size))
  2175. return -EFAULT;
  2176. if (dent == phba->debug_InjErrLBA) {
  2177. if ((dstbuf[0] == 'o') && (dstbuf[1] == 'f') &&
  2178. (dstbuf[2] == 'f'))
  2179. tmp = (uint64_t)(-1);
  2180. }
  2181. if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
  2182. return -EINVAL;
  2183. if (dent == phba->debug_writeGuard)
  2184. phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
  2185. else if (dent == phba->debug_writeApp)
  2186. phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
  2187. else if (dent == phba->debug_writeRef)
  2188. phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
  2189. else if (dent == phba->debug_readGuard)
  2190. phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
  2191. else if (dent == phba->debug_readApp)
  2192. phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
  2193. else if (dent == phba->debug_readRef)
  2194. phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
  2195. else if (dent == phba->debug_InjErrLBA)
  2196. phba->lpfc_injerr_lba = (sector_t)tmp;
  2197. else if (dent == phba->debug_InjErrNPortID)
  2198. phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
  2199. else if (dent == phba->debug_InjErrWWPN) {
  2200. tmp = cpu_to_be64(tmp);
  2201. memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
  2202. } else
  2203. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2204. "0548 Unknown debugfs error injection entry\n");
  2205. return nbytes;
  2206. }
  2207. static int
  2208. lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
  2209. {
  2210. return 0;
  2211. }
  2212. /**
  2213. * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
  2214. * @inode: The inode pointer that contains a vport pointer.
  2215. * @file: The file pointer to attach the log output.
  2216. *
  2217. * Description:
  2218. * This routine is the entry point for the debugfs open file operation. It gets
  2219. * the vport from the i_private field in @inode, allocates the necessary buffer
  2220. * for the log, fills the buffer from the in-memory log for this vport, and then
  2221. * returns a pointer to that log in the private_data field in @file.
  2222. *
  2223. * Returns:
  2224. * This function returns zero if successful. On error it will return a negative
  2225. * error value.
  2226. **/
  2227. static int
  2228. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  2229. {
  2230. struct lpfc_vport *vport = inode->i_private;
  2231. struct lpfc_debug *debug;
  2232. int rc = -ENOMEM;
  2233. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2234. if (!debug)
  2235. goto out;
  2236. /* Round to page boundary */
  2237. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  2238. if (!debug->buffer) {
  2239. kfree(debug);
  2240. goto out;
  2241. }
  2242. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  2243. LPFC_NODELIST_SIZE);
  2244. file->private_data = debug;
  2245. rc = 0;
  2246. out:
  2247. return rc;
  2248. }
  2249. /**
  2250. * lpfc_debugfs_lseek - Seek through a debugfs file
  2251. * @file: The file pointer to seek through.
  2252. * @off: The offset to seek to or the amount to seek by.
  2253. * @whence: Indicates how to seek.
  2254. *
  2255. * Description:
  2256. * This routine is the entry point for the debugfs lseek file operation. The
  2257. * @whence parameter indicates whether @off is the offset to directly seek to,
  2258. * or if it is a value to seek forward or reverse by. This function figures out
  2259. * what the new offset of the debugfs file will be and assigns that value to the
  2260. * f_pos field of @file.
  2261. *
  2262. * Returns:
  2263. * This function returns the new offset if successful and returns a negative
  2264. * error if unable to process the seek.
  2265. **/
  2266. static loff_t
  2267. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  2268. {
  2269. struct lpfc_debug *debug = file->private_data;
  2270. return fixed_size_llseek(file, off, whence, debug->len);
  2271. }
  2272. /**
  2273. * lpfc_debugfs_read - Read a debugfs file
  2274. * @file: The file pointer to read from.
  2275. * @buf: The buffer to copy the data to.
  2276. * @nbytes: The number of bytes to read.
  2277. * @ppos: The position in the file to start reading from.
  2278. *
  2279. * Description:
  2280. * This routine reads data from from the buffer indicated in the private_data
  2281. * field of @file. It will start reading at @ppos and copy up to @nbytes of
  2282. * data to @buf.
  2283. *
  2284. * Returns:
  2285. * This function returns the amount of data that was read (this could be less
  2286. * than @nbytes if the end of the file was reached) or a negative error value.
  2287. **/
  2288. static ssize_t
  2289. lpfc_debugfs_read(struct file *file, char __user *buf,
  2290. size_t nbytes, loff_t *ppos)
  2291. {
  2292. struct lpfc_debug *debug = file->private_data;
  2293. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  2294. debug->len);
  2295. }
  2296. /**
  2297. * lpfc_debugfs_release - Release the buffer used to store debugfs file data
  2298. * @inode: The inode pointer that contains a vport pointer. (unused)
  2299. * @file: The file pointer that contains the buffer to release.
  2300. *
  2301. * Description:
  2302. * This routine frees the buffer that was allocated when the debugfs file was
  2303. * opened.
  2304. *
  2305. * Returns:
  2306. * This function returns zero.
  2307. **/
  2308. static int
  2309. lpfc_debugfs_release(struct inode *inode, struct file *file)
  2310. {
  2311. struct lpfc_debug *debug = file->private_data;
  2312. kfree(debug->buffer);
  2313. kfree(debug);
  2314. return 0;
  2315. }
  2316. /**
  2317. * lpfc_debugfs_multixripools_write - Clear multi-XRI pools statistics
  2318. * @file: The file pointer to read from.
  2319. * @buf: The buffer to copy the user data from.
  2320. * @nbytes: The number of bytes to get.
  2321. * @ppos: The position in the file to start reading from.
  2322. *
  2323. * Description:
  2324. * This routine clears multi-XRI pools statistics when buf contains "clear".
  2325. *
  2326. * Return Value:
  2327. * It returns the @nbytges passing in from debugfs user space when successful.
  2328. * In case of error conditions, it returns proper error code back to the user
  2329. * space.
  2330. **/
  2331. static ssize_t
  2332. lpfc_debugfs_multixripools_write(struct file *file, const char __user *buf,
  2333. size_t nbytes, loff_t *ppos)
  2334. {
  2335. struct lpfc_debug *debug = file->private_data;
  2336. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2337. char mybuf[64];
  2338. char *pbuf;
  2339. u32 i;
  2340. u32 hwq_count;
  2341. struct lpfc_sli4_hdw_queue *qp;
  2342. struct lpfc_multixri_pool *multixri_pool;
  2343. if (nbytes > sizeof(mybuf) - 1)
  2344. nbytes = sizeof(mybuf) - 1;
  2345. memset(mybuf, 0, sizeof(mybuf));
  2346. if (copy_from_user(mybuf, buf, nbytes))
  2347. return -EFAULT;
  2348. pbuf = &mybuf[0];
  2349. if ((strncmp(pbuf, "clear", strlen("clear"))) == 0) {
  2350. hwq_count = phba->cfg_hdw_queue;
  2351. for (i = 0; i < hwq_count; i++) {
  2352. qp = &phba->sli4_hba.hdwq[i];
  2353. multixri_pool = qp->p_multixri_pool;
  2354. if (!multixri_pool)
  2355. continue;
  2356. qp->empty_io_bufs = 0;
  2357. multixri_pool->pbl_empty_count = 0;
  2358. #ifdef LPFC_MXP_STAT
  2359. multixri_pool->above_limit_count = 0;
  2360. multixri_pool->below_limit_count = 0;
  2361. multixri_pool->stat_max_hwm = 0;
  2362. multixri_pool->local_pbl_hit_count = 0;
  2363. multixri_pool->other_pbl_hit_count = 0;
  2364. multixri_pool->stat_pbl_count = 0;
  2365. multixri_pool->stat_pvt_count = 0;
  2366. multixri_pool->stat_busy_count = 0;
  2367. multixri_pool->stat_snapshot_taken = 0;
  2368. #endif
  2369. }
  2370. return strlen(pbuf);
  2371. }
  2372. return -EINVAL;
  2373. }
  2374. static int
  2375. lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
  2376. {
  2377. struct lpfc_vport *vport = inode->i_private;
  2378. struct lpfc_debug *debug;
  2379. int rc = -ENOMEM;
  2380. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2381. if (!debug)
  2382. goto out;
  2383. /* Round to page boundary */
  2384. debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
  2385. if (!debug->buffer) {
  2386. kfree(debug);
  2387. goto out;
  2388. }
  2389. debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
  2390. LPFC_NVMESTAT_SIZE);
  2391. debug->i_private = inode->i_private;
  2392. file->private_data = debug;
  2393. rc = 0;
  2394. out:
  2395. return rc;
  2396. }
  2397. static ssize_t
  2398. lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
  2399. size_t nbytes, loff_t *ppos)
  2400. {
  2401. struct lpfc_debug *debug = file->private_data;
  2402. struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
  2403. struct lpfc_hba *phba = vport->phba;
  2404. struct lpfc_nvmet_tgtport *tgtp;
  2405. char mybuf[64];
  2406. char *pbuf;
  2407. if (!phba->targetport)
  2408. return -ENXIO;
  2409. if (nbytes > sizeof(mybuf) - 1)
  2410. nbytes = sizeof(mybuf) - 1;
  2411. memset(mybuf, 0, sizeof(mybuf));
  2412. if (copy_from_user(mybuf, buf, nbytes))
  2413. return -EFAULT;
  2414. pbuf = &mybuf[0];
  2415. tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
  2416. if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
  2417. (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
  2418. atomic_set(&tgtp->rcv_ls_req_in, 0);
  2419. atomic_set(&tgtp->rcv_ls_req_out, 0);
  2420. atomic_set(&tgtp->rcv_ls_req_drop, 0);
  2421. atomic_set(&tgtp->xmt_ls_abort, 0);
  2422. atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
  2423. atomic_set(&tgtp->xmt_ls_rsp, 0);
  2424. atomic_set(&tgtp->xmt_ls_drop, 0);
  2425. atomic_set(&tgtp->xmt_ls_rsp_error, 0);
  2426. atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
  2427. atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
  2428. atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
  2429. atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
  2430. atomic_set(&tgtp->xmt_fcp_drop, 0);
  2431. atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
  2432. atomic_set(&tgtp->xmt_fcp_read, 0);
  2433. atomic_set(&tgtp->xmt_fcp_write, 0);
  2434. atomic_set(&tgtp->xmt_fcp_rsp, 0);
  2435. atomic_set(&tgtp->xmt_fcp_release, 0);
  2436. atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
  2437. atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
  2438. atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
  2439. atomic_set(&tgtp->xmt_fcp_abort, 0);
  2440. atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
  2441. atomic_set(&tgtp->xmt_abort_sol, 0);
  2442. atomic_set(&tgtp->xmt_abort_unsol, 0);
  2443. atomic_set(&tgtp->xmt_abort_rsp, 0);
  2444. atomic_set(&tgtp->xmt_abort_rsp_error, 0);
  2445. }
  2446. return nbytes;
  2447. }
  2448. static int
  2449. lpfc_debugfs_scsistat_open(struct inode *inode, struct file *file)
  2450. {
  2451. struct lpfc_vport *vport = inode->i_private;
  2452. struct lpfc_debug *debug;
  2453. int rc = -ENOMEM;
  2454. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2455. if (!debug)
  2456. goto out;
  2457. /* Round to page boundary */
  2458. debug->buffer = kzalloc(LPFC_SCSISTAT_SIZE, GFP_KERNEL);
  2459. if (!debug->buffer) {
  2460. kfree(debug);
  2461. goto out;
  2462. }
  2463. debug->len = lpfc_debugfs_scsistat_data(vport, debug->buffer,
  2464. LPFC_SCSISTAT_SIZE);
  2465. debug->i_private = inode->i_private;
  2466. file->private_data = debug;
  2467. rc = 0;
  2468. out:
  2469. return rc;
  2470. }
  2471. static ssize_t
  2472. lpfc_debugfs_scsistat_write(struct file *file, const char __user *buf,
  2473. size_t nbytes, loff_t *ppos)
  2474. {
  2475. struct lpfc_debug *debug = file->private_data;
  2476. struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
  2477. struct lpfc_hba *phba = vport->phba;
  2478. char mybuf[6] = {0};
  2479. int i;
  2480. if (copy_from_user(mybuf, buf, (nbytes >= sizeof(mybuf)) ?
  2481. (sizeof(mybuf) - 1) : nbytes))
  2482. return -EFAULT;
  2483. if ((strncmp(&mybuf[0], "reset", strlen("reset")) == 0) ||
  2484. (strncmp(&mybuf[0], "zero", strlen("zero")) == 0)) {
  2485. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  2486. memset(&phba->sli4_hba.hdwq[i].scsi_cstat, 0,
  2487. sizeof(phba->sli4_hba.hdwq[i].scsi_cstat));
  2488. }
  2489. }
  2490. return nbytes;
  2491. }
  2492. static int
  2493. lpfc_debugfs_ioktime_open(struct inode *inode, struct file *file)
  2494. {
  2495. struct lpfc_vport *vport = inode->i_private;
  2496. struct lpfc_debug *debug;
  2497. int rc = -ENOMEM;
  2498. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2499. if (!debug)
  2500. goto out;
  2501. /* Round to page boundary */
  2502. debug->buffer = kmalloc(LPFC_IOKTIME_SIZE, GFP_KERNEL);
  2503. if (!debug->buffer) {
  2504. kfree(debug);
  2505. goto out;
  2506. }
  2507. debug->len = lpfc_debugfs_ioktime_data(vport, debug->buffer,
  2508. LPFC_IOKTIME_SIZE);
  2509. debug->i_private = inode->i_private;
  2510. file->private_data = debug;
  2511. rc = 0;
  2512. out:
  2513. return rc;
  2514. }
  2515. static ssize_t
  2516. lpfc_debugfs_ioktime_write(struct file *file, const char __user *buf,
  2517. size_t nbytes, loff_t *ppos)
  2518. {
  2519. struct lpfc_debug *debug = file->private_data;
  2520. struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
  2521. struct lpfc_hba *phba = vport->phba;
  2522. char mybuf[64];
  2523. char *pbuf;
  2524. if (nbytes > sizeof(mybuf) - 1)
  2525. nbytes = sizeof(mybuf) - 1;
  2526. memset(mybuf, 0, sizeof(mybuf));
  2527. if (copy_from_user(mybuf, buf, nbytes))
  2528. return -EFAULT;
  2529. pbuf = &mybuf[0];
  2530. if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
  2531. phba->ktime_data_samples = 0;
  2532. phba->ktime_status_samples = 0;
  2533. phba->ktime_seg1_total = 0;
  2534. phba->ktime_seg1_max = 0;
  2535. phba->ktime_seg1_min = 0xffffffff;
  2536. phba->ktime_seg2_total = 0;
  2537. phba->ktime_seg2_max = 0;
  2538. phba->ktime_seg2_min = 0xffffffff;
  2539. phba->ktime_seg3_total = 0;
  2540. phba->ktime_seg3_max = 0;
  2541. phba->ktime_seg3_min = 0xffffffff;
  2542. phba->ktime_seg4_total = 0;
  2543. phba->ktime_seg4_max = 0;
  2544. phba->ktime_seg4_min = 0xffffffff;
  2545. phba->ktime_seg5_total = 0;
  2546. phba->ktime_seg5_max = 0;
  2547. phba->ktime_seg5_min = 0xffffffff;
  2548. phba->ktime_seg6_total = 0;
  2549. phba->ktime_seg6_max = 0;
  2550. phba->ktime_seg6_min = 0xffffffff;
  2551. phba->ktime_seg7_total = 0;
  2552. phba->ktime_seg7_max = 0;
  2553. phba->ktime_seg7_min = 0xffffffff;
  2554. phba->ktime_seg8_total = 0;
  2555. phba->ktime_seg8_max = 0;
  2556. phba->ktime_seg8_min = 0xffffffff;
  2557. phba->ktime_seg9_total = 0;
  2558. phba->ktime_seg9_max = 0;
  2559. phba->ktime_seg9_min = 0xffffffff;
  2560. phba->ktime_seg10_total = 0;
  2561. phba->ktime_seg10_max = 0;
  2562. phba->ktime_seg10_min = 0xffffffff;
  2563. phba->ktime_on = 1;
  2564. return strlen(pbuf);
  2565. } else if ((strncmp(pbuf, "off",
  2566. sizeof("off") - 1) == 0)) {
  2567. phba->ktime_on = 0;
  2568. return strlen(pbuf);
  2569. } else if ((strncmp(pbuf, "zero",
  2570. sizeof("zero") - 1) == 0)) {
  2571. phba->ktime_data_samples = 0;
  2572. phba->ktime_status_samples = 0;
  2573. phba->ktime_seg1_total = 0;
  2574. phba->ktime_seg1_max = 0;
  2575. phba->ktime_seg1_min = 0xffffffff;
  2576. phba->ktime_seg2_total = 0;
  2577. phba->ktime_seg2_max = 0;
  2578. phba->ktime_seg2_min = 0xffffffff;
  2579. phba->ktime_seg3_total = 0;
  2580. phba->ktime_seg3_max = 0;
  2581. phba->ktime_seg3_min = 0xffffffff;
  2582. phba->ktime_seg4_total = 0;
  2583. phba->ktime_seg4_max = 0;
  2584. phba->ktime_seg4_min = 0xffffffff;
  2585. phba->ktime_seg5_total = 0;
  2586. phba->ktime_seg5_max = 0;
  2587. phba->ktime_seg5_min = 0xffffffff;
  2588. phba->ktime_seg6_total = 0;
  2589. phba->ktime_seg6_max = 0;
  2590. phba->ktime_seg6_min = 0xffffffff;
  2591. phba->ktime_seg7_total = 0;
  2592. phba->ktime_seg7_max = 0;
  2593. phba->ktime_seg7_min = 0xffffffff;
  2594. phba->ktime_seg8_total = 0;
  2595. phba->ktime_seg8_max = 0;
  2596. phba->ktime_seg8_min = 0xffffffff;
  2597. phba->ktime_seg9_total = 0;
  2598. phba->ktime_seg9_max = 0;
  2599. phba->ktime_seg9_min = 0xffffffff;
  2600. phba->ktime_seg10_total = 0;
  2601. phba->ktime_seg10_max = 0;
  2602. phba->ktime_seg10_min = 0xffffffff;
  2603. return strlen(pbuf);
  2604. }
  2605. return -EINVAL;
  2606. }
  2607. static int
  2608. lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
  2609. {
  2610. struct lpfc_hba *phba = inode->i_private;
  2611. struct lpfc_debug *debug;
  2612. int rc = -ENOMEM;
  2613. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2614. if (!debug)
  2615. goto out;
  2616. /* Round to page boundary */
  2617. debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
  2618. if (!debug->buffer) {
  2619. kfree(debug);
  2620. goto out;
  2621. }
  2622. debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
  2623. LPFC_NVMEIO_TRC_SIZE);
  2624. debug->i_private = inode->i_private;
  2625. file->private_data = debug;
  2626. rc = 0;
  2627. out:
  2628. return rc;
  2629. }
  2630. static ssize_t
  2631. lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
  2632. size_t nbytes, loff_t *ppos)
  2633. {
  2634. struct lpfc_debug *debug = file->private_data;
  2635. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2636. int i;
  2637. unsigned long sz;
  2638. char mybuf[64];
  2639. char *pbuf;
  2640. if (nbytes > sizeof(mybuf) - 1)
  2641. nbytes = sizeof(mybuf) - 1;
  2642. memset(mybuf, 0, sizeof(mybuf));
  2643. if (copy_from_user(mybuf, buf, nbytes))
  2644. return -EFAULT;
  2645. pbuf = &mybuf[0];
  2646. if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
  2647. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2648. "0570 nvmeio_trc_off\n");
  2649. phba->nvmeio_trc_output_idx = 0;
  2650. phba->nvmeio_trc_on = 0;
  2651. return strlen(pbuf);
  2652. } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
  2653. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2654. "0571 nvmeio_trc_on\n");
  2655. phba->nvmeio_trc_output_idx = 0;
  2656. phba->nvmeio_trc_on = 1;
  2657. return strlen(pbuf);
  2658. }
  2659. /* We must be off to allocate the trace buffer */
  2660. if (phba->nvmeio_trc_on != 0)
  2661. return -EINVAL;
  2662. /* If not on or off, the parameter is the trace buffer size */
  2663. i = kstrtoul(pbuf, 0, &sz);
  2664. if (i)
  2665. return -EINVAL;
  2666. phba->nvmeio_trc_size = (uint32_t)sz;
  2667. /* It must be a power of 2 - round down */
  2668. i = 0;
  2669. while (sz > 1) {
  2670. sz = sz >> 1;
  2671. i++;
  2672. }
  2673. sz = (1 << i);
  2674. if (phba->nvmeio_trc_size != sz)
  2675. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2676. "0572 nvmeio_trc_size changed to %ld\n",
  2677. sz);
  2678. phba->nvmeio_trc_size = (uint32_t)sz;
  2679. /* If one previously exists, free it */
  2680. kfree(phba->nvmeio_trc);
  2681. /* Allocate new trace buffer and initialize */
  2682. phba->nvmeio_trc = kzalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
  2683. sz), GFP_KERNEL);
  2684. if (!phba->nvmeio_trc) {
  2685. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2686. "0573 Cannot create debugfs "
  2687. "nvmeio_trc buffer\n");
  2688. return -ENOMEM;
  2689. }
  2690. atomic_set(&phba->nvmeio_trc_cnt, 0);
  2691. phba->nvmeio_trc_on = 0;
  2692. phba->nvmeio_trc_output_idx = 0;
  2693. return strlen(pbuf);
  2694. }
  2695. static int
  2696. lpfc_debugfs_hdwqstat_open(struct inode *inode, struct file *file)
  2697. {
  2698. struct lpfc_vport *vport = inode->i_private;
  2699. struct lpfc_debug *debug;
  2700. int rc = -ENOMEM;
  2701. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2702. if (!debug)
  2703. goto out;
  2704. /* Round to page boundary */
  2705. debug->buffer = kcalloc(1, LPFC_SCSISTAT_SIZE, GFP_KERNEL);
  2706. if (!debug->buffer) {
  2707. kfree(debug);
  2708. goto out;
  2709. }
  2710. debug->len = lpfc_debugfs_hdwqstat_data(vport, debug->buffer,
  2711. LPFC_SCSISTAT_SIZE);
  2712. debug->i_private = inode->i_private;
  2713. file->private_data = debug;
  2714. rc = 0;
  2715. out:
  2716. return rc;
  2717. }
  2718. static ssize_t
  2719. lpfc_debugfs_hdwqstat_write(struct file *file, const char __user *buf,
  2720. size_t nbytes, loff_t *ppos)
  2721. {
  2722. struct lpfc_debug *debug = file->private_data;
  2723. struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
  2724. struct lpfc_hba *phba = vport->phba;
  2725. struct lpfc_hdwq_stat *c_stat;
  2726. char mybuf[64];
  2727. char *pbuf;
  2728. int i;
  2729. if (nbytes > sizeof(mybuf) - 1)
  2730. nbytes = sizeof(mybuf) - 1;
  2731. memset(mybuf, 0, sizeof(mybuf));
  2732. if (copy_from_user(mybuf, buf, nbytes))
  2733. return -EFAULT;
  2734. pbuf = &mybuf[0];
  2735. if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
  2736. if (phba->nvmet_support)
  2737. phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
  2738. else
  2739. phba->hdwqstat_on |= (LPFC_CHECK_NVME_IO |
  2740. LPFC_CHECK_SCSI_IO);
  2741. return strlen(pbuf);
  2742. } else if ((strncmp(pbuf, "nvme_on", sizeof("nvme_on") - 1) == 0)) {
  2743. if (phba->nvmet_support)
  2744. phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
  2745. else
  2746. phba->hdwqstat_on |= LPFC_CHECK_NVME_IO;
  2747. return strlen(pbuf);
  2748. } else if ((strncmp(pbuf, "scsi_on", sizeof("scsi_on") - 1) == 0)) {
  2749. if (!phba->nvmet_support)
  2750. phba->hdwqstat_on |= LPFC_CHECK_SCSI_IO;
  2751. return strlen(pbuf);
  2752. } else if ((strncmp(pbuf, "nvme_off", sizeof("nvme_off") - 1) == 0)) {
  2753. phba->hdwqstat_on &= ~(LPFC_CHECK_NVME_IO |
  2754. LPFC_CHECK_NVMET_IO);
  2755. return strlen(pbuf);
  2756. } else if ((strncmp(pbuf, "scsi_off", sizeof("scsi_off") - 1) == 0)) {
  2757. phba->hdwqstat_on &= ~LPFC_CHECK_SCSI_IO;
  2758. return strlen(pbuf);
  2759. } else if ((strncmp(pbuf, "off",
  2760. sizeof("off") - 1) == 0)) {
  2761. phba->hdwqstat_on = LPFC_CHECK_OFF;
  2762. return strlen(pbuf);
  2763. } else if ((strncmp(pbuf, "zero",
  2764. sizeof("zero") - 1) == 0)) {
  2765. for_each_present_cpu(i) {
  2766. c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, i);
  2767. c_stat->xmt_io = 0;
  2768. c_stat->cmpl_io = 0;
  2769. c_stat->rcv_io = 0;
  2770. }
  2771. return strlen(pbuf);
  2772. }
  2773. return -EINVAL;
  2774. }
  2775. /*
  2776. * ---------------------------------
  2777. * iDiag debugfs file access methods
  2778. * ---------------------------------
  2779. *
  2780. * All access methods are through the proper SLI4 PCI function's debugfs
  2781. * iDiag directory:
  2782. *
  2783. * /sys/kernel/debug/lpfc/fn<#>/iDiag
  2784. */
  2785. /**
  2786. * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
  2787. * @buf: The pointer to the user space buffer.
  2788. * @nbytes: The number of bytes in the user space buffer.
  2789. * @idiag_cmd: pointer to the idiag command struct.
  2790. *
  2791. * This routine reads data from debugfs user space buffer and parses the
  2792. * buffer for getting the idiag command and arguments. The while space in
  2793. * between the set of data is used as the parsing separator.
  2794. *
  2795. * This routine returns 0 when successful, it returns proper error code
  2796. * back to the user space in error conditions.
  2797. */
  2798. static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
  2799. struct lpfc_idiag_cmd *idiag_cmd)
  2800. {
  2801. char mybuf[64];
  2802. char *pbuf, *step_str;
  2803. int i;
  2804. size_t bsize;
  2805. memset(mybuf, 0, sizeof(mybuf));
  2806. memset(idiag_cmd, 0, sizeof(*idiag_cmd));
  2807. bsize = min(nbytes, (sizeof(mybuf)-1));
  2808. if (copy_from_user(mybuf, buf, bsize))
  2809. return -EFAULT;
  2810. pbuf = &mybuf[0];
  2811. step_str = strsep(&pbuf, "\t ");
  2812. /* The opcode must present */
  2813. if (!step_str)
  2814. return -EINVAL;
  2815. idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
  2816. if (idiag_cmd->opcode == 0)
  2817. return -EINVAL;
  2818. for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
  2819. step_str = strsep(&pbuf, "\t ");
  2820. if (!step_str)
  2821. return i;
  2822. idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
  2823. }
  2824. return i;
  2825. }
  2826. /**
  2827. * lpfc_idiag_open - idiag open debugfs
  2828. * @inode: The inode pointer that contains a pointer to phba.
  2829. * @file: The file pointer to attach the file operation.
  2830. *
  2831. * Description:
  2832. * This routine is the entry point for the debugfs open file operation. It
  2833. * gets the reference to phba from the i_private field in @inode, it then
  2834. * allocates buffer for the file operation, performs the necessary PCI config
  2835. * space read into the allocated buffer according to the idiag user command
  2836. * setup, and then returns a pointer to buffer in the private_data field in
  2837. * @file.
  2838. *
  2839. * Returns:
  2840. * This function returns zero if successful. On error it will return an
  2841. * negative error value.
  2842. **/
  2843. static int
  2844. lpfc_idiag_open(struct inode *inode, struct file *file)
  2845. {
  2846. struct lpfc_debug *debug;
  2847. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  2848. if (!debug)
  2849. return -ENOMEM;
  2850. debug->i_private = inode->i_private;
  2851. debug->buffer = NULL;
  2852. file->private_data = debug;
  2853. return 0;
  2854. }
  2855. /**
  2856. * lpfc_idiag_release - Release idiag access file operation
  2857. * @inode: The inode pointer that contains a vport pointer. (unused)
  2858. * @file: The file pointer that contains the buffer to release.
  2859. *
  2860. * Description:
  2861. * This routine is the generic release routine for the idiag access file
  2862. * operation, it frees the buffer that was allocated when the debugfs file
  2863. * was opened.
  2864. *
  2865. * Returns:
  2866. * This function returns zero.
  2867. **/
  2868. static int
  2869. lpfc_idiag_release(struct inode *inode, struct file *file)
  2870. {
  2871. struct lpfc_debug *debug = file->private_data;
  2872. /* Free the buffers to the file operation */
  2873. kfree(debug->buffer);
  2874. kfree(debug);
  2875. return 0;
  2876. }
  2877. /**
  2878. * lpfc_idiag_cmd_release - Release idiag cmd access file operation
  2879. * @inode: The inode pointer that contains a vport pointer. (unused)
  2880. * @file: The file pointer that contains the buffer to release.
  2881. *
  2882. * Description:
  2883. * This routine frees the buffer that was allocated when the debugfs file
  2884. * was opened. It also reset the fields in the idiag command struct in the
  2885. * case of command for write operation.
  2886. *
  2887. * Returns:
  2888. * This function returns zero.
  2889. **/
  2890. static int
  2891. lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
  2892. {
  2893. struct lpfc_debug *debug = file->private_data;
  2894. if (debug->op == LPFC_IDIAG_OP_WR) {
  2895. switch (idiag.cmd.opcode) {
  2896. case LPFC_IDIAG_CMD_PCICFG_WR:
  2897. case LPFC_IDIAG_CMD_PCICFG_ST:
  2898. case LPFC_IDIAG_CMD_PCICFG_CL:
  2899. case LPFC_IDIAG_CMD_QUEACC_WR:
  2900. case LPFC_IDIAG_CMD_QUEACC_ST:
  2901. case LPFC_IDIAG_CMD_QUEACC_CL:
  2902. memset(&idiag, 0, sizeof(idiag));
  2903. break;
  2904. default:
  2905. break;
  2906. }
  2907. }
  2908. /* Free the buffers to the file operation */
  2909. kfree(debug->buffer);
  2910. kfree(debug);
  2911. return 0;
  2912. }
  2913. /**
  2914. * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
  2915. * @file: The file pointer to read from.
  2916. * @buf: The buffer to copy the data to.
  2917. * @nbytes: The number of bytes to read.
  2918. * @ppos: The position in the file to start reading from.
  2919. *
  2920. * Description:
  2921. * This routine reads data from the @phba pci config space according to the
  2922. * idiag command, and copies to user @buf. Depending on the PCI config space
  2923. * read command setup, it does either a single register read of a byte
  2924. * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
  2925. * registers from the 4K extended PCI config space.
  2926. *
  2927. * Returns:
  2928. * This function returns the amount of data that was read (this could be less
  2929. * than @nbytes if the end of the file was reached) or a negative error value.
  2930. **/
  2931. static ssize_t
  2932. lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
  2933. loff_t *ppos)
  2934. {
  2935. struct lpfc_debug *debug = file->private_data;
  2936. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2937. int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
  2938. int where, count;
  2939. char *pbuffer;
  2940. struct pci_dev *pdev;
  2941. uint32_t u32val;
  2942. uint16_t u16val;
  2943. uint8_t u8val;
  2944. pdev = phba->pcidev;
  2945. if (!pdev)
  2946. return 0;
  2947. /* This is a user read operation */
  2948. debug->op = LPFC_IDIAG_OP_RD;
  2949. if (!debug->buffer)
  2950. debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
  2951. if (!debug->buffer)
  2952. return 0;
  2953. pbuffer = debug->buffer;
  2954. if (*ppos)
  2955. return 0;
  2956. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  2957. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  2958. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  2959. } else
  2960. return 0;
  2961. /* Read single PCI config space register */
  2962. switch (count) {
  2963. case SIZE_U8: /* byte (8 bits) */
  2964. pci_read_config_byte(pdev, where, &u8val);
  2965. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2966. "%03x: %02x\n", where, u8val);
  2967. break;
  2968. case SIZE_U16: /* word (16 bits) */
  2969. pci_read_config_word(pdev, where, &u16val);
  2970. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2971. "%03x: %04x\n", where, u16val);
  2972. break;
  2973. case SIZE_U32: /* double word (32 bits) */
  2974. pci_read_config_dword(pdev, where, &u32val);
  2975. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2976. "%03x: %08x\n", where, u32val);
  2977. break;
  2978. case LPFC_PCI_CFG_BROWSE: /* browse all */
  2979. goto pcicfg_browse;
  2980. default:
  2981. /* illegal count */
  2982. len = 0;
  2983. break;
  2984. }
  2985. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2986. pcicfg_browse:
  2987. /* Browse all PCI config space registers */
  2988. offset_label = idiag.offset.last_rd;
  2989. offset = offset_label;
  2990. /* Read PCI config space */
  2991. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2992. "%03x: ", offset_label);
  2993. while (index > 0) {
  2994. pci_read_config_dword(pdev, offset, &u32val);
  2995. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  2996. "%08x ", u32val);
  2997. offset += sizeof(uint32_t);
  2998. if (offset >= LPFC_PCI_CFG_SIZE) {
  2999. len += scnprintf(pbuffer+len,
  3000. LPFC_PCI_CFG_SIZE-len, "\n");
  3001. break;
  3002. }
  3003. index -= sizeof(uint32_t);
  3004. if (!index)
  3005. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  3006. "\n");
  3007. else if (!(index % (8 * sizeof(uint32_t)))) {
  3008. offset_label += (8 * sizeof(uint32_t));
  3009. len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  3010. "\n%03x: ", offset_label);
  3011. }
  3012. }
  3013. /* Set up the offset for next portion of pci cfg read */
  3014. if (index == 0) {
  3015. idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
  3016. if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
  3017. idiag.offset.last_rd = 0;
  3018. } else
  3019. idiag.offset.last_rd = 0;
  3020. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3021. }
  3022. /**
  3023. * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
  3024. * @file: The file pointer to read from.
  3025. * @buf: The buffer to copy the user data from.
  3026. * @nbytes: The number of bytes to get.
  3027. * @ppos: The position in the file to start reading from.
  3028. *
  3029. * This routine get the debugfs idiag command struct from user space and
  3030. * then perform the syntax check for PCI config space read or write command
  3031. * accordingly. In the case of PCI config space read command, it sets up
  3032. * the command in the idiag command struct for the debugfs read operation.
  3033. * In the case of PCI config space write operation, it executes the write
  3034. * operation into the PCI config space accordingly.
  3035. *
  3036. * It returns the @nbytges passing in from debugfs user space when successful.
  3037. * In case of error conditions, it returns proper error code back to the user
  3038. * space.
  3039. */
  3040. static ssize_t
  3041. lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
  3042. size_t nbytes, loff_t *ppos)
  3043. {
  3044. struct lpfc_debug *debug = file->private_data;
  3045. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3046. uint32_t where, value, count;
  3047. uint32_t u32val;
  3048. uint16_t u16val;
  3049. uint8_t u8val;
  3050. struct pci_dev *pdev;
  3051. int rc;
  3052. pdev = phba->pcidev;
  3053. if (!pdev)
  3054. return -EFAULT;
  3055. /* This is a user write operation */
  3056. debug->op = LPFC_IDIAG_OP_WR;
  3057. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  3058. if (rc < 0)
  3059. return rc;
  3060. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  3061. /* Sanity check on PCI config read command line arguments */
  3062. if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
  3063. goto error_out;
  3064. /* Read command from PCI config space, set up command fields */
  3065. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  3066. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  3067. if (count == LPFC_PCI_CFG_BROWSE) {
  3068. if (where % sizeof(uint32_t))
  3069. goto error_out;
  3070. /* Starting offset to browse */
  3071. idiag.offset.last_rd = where;
  3072. } else if ((count != sizeof(uint8_t)) &&
  3073. (count != sizeof(uint16_t)) &&
  3074. (count != sizeof(uint32_t)))
  3075. goto error_out;
  3076. if (count == sizeof(uint8_t)) {
  3077. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  3078. goto error_out;
  3079. if (where % sizeof(uint8_t))
  3080. goto error_out;
  3081. }
  3082. if (count == sizeof(uint16_t)) {
  3083. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  3084. goto error_out;
  3085. if (where % sizeof(uint16_t))
  3086. goto error_out;
  3087. }
  3088. if (count == sizeof(uint32_t)) {
  3089. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  3090. goto error_out;
  3091. if (where % sizeof(uint32_t))
  3092. goto error_out;
  3093. }
  3094. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
  3095. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
  3096. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  3097. /* Sanity check on PCI config write command line arguments */
  3098. if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
  3099. goto error_out;
  3100. /* Write command to PCI config space, read-modify-write */
  3101. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  3102. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  3103. value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
  3104. /* Sanity checks */
  3105. if ((count != sizeof(uint8_t)) &&
  3106. (count != sizeof(uint16_t)) &&
  3107. (count != sizeof(uint32_t)))
  3108. goto error_out;
  3109. if (count == sizeof(uint8_t)) {
  3110. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  3111. goto error_out;
  3112. if (where % sizeof(uint8_t))
  3113. goto error_out;
  3114. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  3115. pci_write_config_byte(pdev, where,
  3116. (uint8_t)value);
  3117. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  3118. rc = pci_read_config_byte(pdev, where, &u8val);
  3119. if (!rc) {
  3120. u8val |= (uint8_t)value;
  3121. pci_write_config_byte(pdev, where,
  3122. u8val);
  3123. }
  3124. }
  3125. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  3126. rc = pci_read_config_byte(pdev, where, &u8val);
  3127. if (!rc) {
  3128. u8val &= (uint8_t)(~value);
  3129. pci_write_config_byte(pdev, where,
  3130. u8val);
  3131. }
  3132. }
  3133. }
  3134. if (count == sizeof(uint16_t)) {
  3135. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  3136. goto error_out;
  3137. if (where % sizeof(uint16_t))
  3138. goto error_out;
  3139. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  3140. pci_write_config_word(pdev, where,
  3141. (uint16_t)value);
  3142. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  3143. rc = pci_read_config_word(pdev, where, &u16val);
  3144. if (!rc) {
  3145. u16val |= (uint16_t)value;
  3146. pci_write_config_word(pdev, where,
  3147. u16val);
  3148. }
  3149. }
  3150. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  3151. rc = pci_read_config_word(pdev, where, &u16val);
  3152. if (!rc) {
  3153. u16val &= (uint16_t)(~value);
  3154. pci_write_config_word(pdev, where,
  3155. u16val);
  3156. }
  3157. }
  3158. }
  3159. if (count == sizeof(uint32_t)) {
  3160. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  3161. goto error_out;
  3162. if (where % sizeof(uint32_t))
  3163. goto error_out;
  3164. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  3165. pci_write_config_dword(pdev, where, value);
  3166. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  3167. rc = pci_read_config_dword(pdev, where,
  3168. &u32val);
  3169. if (!rc) {
  3170. u32val |= value;
  3171. pci_write_config_dword(pdev, where,
  3172. u32val);
  3173. }
  3174. }
  3175. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  3176. rc = pci_read_config_dword(pdev, where,
  3177. &u32val);
  3178. if (!rc) {
  3179. u32val &= ~value;
  3180. pci_write_config_dword(pdev, where,
  3181. u32val);
  3182. }
  3183. }
  3184. }
  3185. } else
  3186. /* All other opecodes are illegal for now */
  3187. goto error_out;
  3188. return nbytes;
  3189. error_out:
  3190. memset(&idiag, 0, sizeof(idiag));
  3191. return -EINVAL;
  3192. }
  3193. /**
  3194. * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
  3195. * @file: The file pointer to read from.
  3196. * @buf: The buffer to copy the data to.
  3197. * @nbytes: The number of bytes to read.
  3198. * @ppos: The position in the file to start reading from.
  3199. *
  3200. * Description:
  3201. * This routine reads data from the @phba pci bar memory mapped space
  3202. * according to the idiag command, and copies to user @buf.
  3203. *
  3204. * Returns:
  3205. * This function returns the amount of data that was read (this could be less
  3206. * than @nbytes if the end of the file was reached) or a negative error value.
  3207. **/
  3208. static ssize_t
  3209. lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
  3210. loff_t *ppos)
  3211. {
  3212. struct lpfc_debug *debug = file->private_data;
  3213. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3214. int offset_label, offset, offset_run, len = 0, index;
  3215. int bar_num, acc_range, bar_size;
  3216. char *pbuffer;
  3217. void __iomem *mem_mapped_bar;
  3218. uint32_t if_type;
  3219. struct pci_dev *pdev;
  3220. uint32_t u32val;
  3221. pdev = phba->pcidev;
  3222. if (!pdev)
  3223. return 0;
  3224. /* This is a user read operation */
  3225. debug->op = LPFC_IDIAG_OP_RD;
  3226. if (!debug->buffer)
  3227. debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
  3228. if (!debug->buffer)
  3229. return 0;
  3230. pbuffer = debug->buffer;
  3231. if (*ppos)
  3232. return 0;
  3233. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  3234. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  3235. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  3236. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  3237. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  3238. } else
  3239. return 0;
  3240. if (acc_range == 0)
  3241. return 0;
  3242. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  3243. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  3244. if (bar_num == IDIAG_BARACC_BAR_0)
  3245. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  3246. else if (bar_num == IDIAG_BARACC_BAR_1)
  3247. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  3248. else if (bar_num == IDIAG_BARACC_BAR_2)
  3249. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  3250. else
  3251. return 0;
  3252. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  3253. if (bar_num == IDIAG_BARACC_BAR_0)
  3254. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  3255. else
  3256. return 0;
  3257. } else
  3258. return 0;
  3259. /* Read single PCI bar space register */
  3260. if (acc_range == SINGLE_WORD) {
  3261. offset_run = offset;
  3262. u32val = readl(mem_mapped_bar + offset_run);
  3263. len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  3264. "%05x: %08x\n", offset_run, u32val);
  3265. } else
  3266. goto baracc_browse;
  3267. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3268. baracc_browse:
  3269. /* Browse all PCI bar space registers */
  3270. offset_label = idiag.offset.last_rd;
  3271. offset_run = offset_label;
  3272. /* Read PCI bar memory mapped space */
  3273. len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  3274. "%05x: ", offset_label);
  3275. index = LPFC_PCI_BAR_RD_SIZE;
  3276. while (index > 0) {
  3277. u32val = readl(mem_mapped_bar + offset_run);
  3278. len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  3279. "%08x ", u32val);
  3280. offset_run += sizeof(uint32_t);
  3281. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  3282. if (offset_run >= bar_size) {
  3283. len += scnprintf(pbuffer+len,
  3284. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  3285. break;
  3286. }
  3287. } else {
  3288. if (offset_run >= offset +
  3289. (acc_range * sizeof(uint32_t))) {
  3290. len += scnprintf(pbuffer+len,
  3291. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  3292. break;
  3293. }
  3294. }
  3295. index -= sizeof(uint32_t);
  3296. if (!index)
  3297. len += scnprintf(pbuffer+len,
  3298. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  3299. else if (!(index % (8 * sizeof(uint32_t)))) {
  3300. offset_label += (8 * sizeof(uint32_t));
  3301. len += scnprintf(pbuffer+len,
  3302. LPFC_PCI_BAR_RD_BUF_SIZE-len,
  3303. "\n%05x: ", offset_label);
  3304. }
  3305. }
  3306. /* Set up the offset for next portion of pci bar read */
  3307. if (index == 0) {
  3308. idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
  3309. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  3310. if (idiag.offset.last_rd >= bar_size)
  3311. idiag.offset.last_rd = 0;
  3312. } else {
  3313. if (offset_run >= offset +
  3314. (acc_range * sizeof(uint32_t)))
  3315. idiag.offset.last_rd = offset;
  3316. }
  3317. } else {
  3318. if (acc_range == LPFC_PCI_BAR_BROWSE)
  3319. idiag.offset.last_rd = 0;
  3320. else
  3321. idiag.offset.last_rd = offset;
  3322. }
  3323. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3324. }
  3325. /**
  3326. * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
  3327. * @file: The file pointer to read from.
  3328. * @buf: The buffer to copy the user data from.
  3329. * @nbytes: The number of bytes to get.
  3330. * @ppos: The position in the file to start reading from.
  3331. *
  3332. * This routine get the debugfs idiag command struct from user space and
  3333. * then perform the syntax check for PCI bar memory mapped space read or
  3334. * write command accordingly. In the case of PCI bar memory mapped space
  3335. * read command, it sets up the command in the idiag command struct for
  3336. * the debugfs read operation. In the case of PCI bar memorpy mapped space
  3337. * write operation, it executes the write operation into the PCI bar memory
  3338. * mapped space accordingly.
  3339. *
  3340. * It returns the @nbytges passing in from debugfs user space when successful.
  3341. * In case of error conditions, it returns proper error code back to the user
  3342. * space.
  3343. */
  3344. static ssize_t
  3345. lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
  3346. size_t nbytes, loff_t *ppos)
  3347. {
  3348. struct lpfc_debug *debug = file->private_data;
  3349. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3350. uint32_t bar_num, bar_size, offset, value, acc_range;
  3351. struct pci_dev *pdev;
  3352. void __iomem *mem_mapped_bar;
  3353. uint32_t if_type;
  3354. uint32_t u32val;
  3355. int rc;
  3356. pdev = phba->pcidev;
  3357. if (!pdev)
  3358. return -EFAULT;
  3359. /* This is a user write operation */
  3360. debug->op = LPFC_IDIAG_OP_WR;
  3361. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  3362. if (rc < 0)
  3363. return rc;
  3364. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  3365. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  3366. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  3367. if ((bar_num != IDIAG_BARACC_BAR_0) &&
  3368. (bar_num != IDIAG_BARACC_BAR_1) &&
  3369. (bar_num != IDIAG_BARACC_BAR_2))
  3370. goto error_out;
  3371. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  3372. if (bar_num != IDIAG_BARACC_BAR_0)
  3373. goto error_out;
  3374. } else
  3375. goto error_out;
  3376. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  3377. if (bar_num == IDIAG_BARACC_BAR_0) {
  3378. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  3379. LPFC_PCI_IF0_BAR0_SIZE;
  3380. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  3381. } else if (bar_num == IDIAG_BARACC_BAR_1) {
  3382. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  3383. LPFC_PCI_IF0_BAR1_SIZE;
  3384. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  3385. } else if (bar_num == IDIAG_BARACC_BAR_2) {
  3386. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  3387. LPFC_PCI_IF0_BAR2_SIZE;
  3388. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  3389. } else
  3390. goto error_out;
  3391. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  3392. if (bar_num == IDIAG_BARACC_BAR_0) {
  3393. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  3394. LPFC_PCI_IF2_BAR0_SIZE;
  3395. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  3396. } else
  3397. goto error_out;
  3398. } else
  3399. goto error_out;
  3400. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  3401. if (offset % sizeof(uint32_t))
  3402. goto error_out;
  3403. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  3404. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  3405. /* Sanity check on PCI config read command line arguments */
  3406. if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
  3407. goto error_out;
  3408. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  3409. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  3410. if (offset > bar_size - sizeof(uint32_t))
  3411. goto error_out;
  3412. /* Starting offset to browse */
  3413. idiag.offset.last_rd = offset;
  3414. } else if (acc_range > SINGLE_WORD) {
  3415. if (offset + acc_range * sizeof(uint32_t) > bar_size)
  3416. goto error_out;
  3417. /* Starting offset to browse */
  3418. idiag.offset.last_rd = offset;
  3419. } else if (acc_range != SINGLE_WORD)
  3420. goto error_out;
  3421. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
  3422. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
  3423. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  3424. /* Sanity check on PCI bar write command line arguments */
  3425. if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
  3426. goto error_out;
  3427. /* Write command to PCI bar space, read-modify-write */
  3428. acc_range = SINGLE_WORD;
  3429. value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
  3430. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
  3431. writel(value, mem_mapped_bar + offset);
  3432. readl(mem_mapped_bar + offset);
  3433. }
  3434. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
  3435. u32val = readl(mem_mapped_bar + offset);
  3436. u32val |= value;
  3437. writel(u32val, mem_mapped_bar + offset);
  3438. readl(mem_mapped_bar + offset);
  3439. }
  3440. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  3441. u32val = readl(mem_mapped_bar + offset);
  3442. u32val &= ~value;
  3443. writel(u32val, mem_mapped_bar + offset);
  3444. readl(mem_mapped_bar + offset);
  3445. }
  3446. } else
  3447. /* All other opecodes are illegal for now */
  3448. goto error_out;
  3449. return nbytes;
  3450. error_out:
  3451. memset(&idiag, 0, sizeof(idiag));
  3452. return -EINVAL;
  3453. }
  3454. static int
  3455. __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
  3456. char *pbuffer, int len)
  3457. {
  3458. if (!qp)
  3459. return len;
  3460. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3461. "\t\t%s WQ info: ", wqtype);
  3462. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3463. "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
  3464. qp->assoc_qid, qp->q_cnt_1,
  3465. (unsigned long long)qp->q_cnt_4);
  3466. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3467. "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  3468. "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]",
  3469. qp->queue_id, qp->entry_count,
  3470. qp->entry_size, qp->host_index,
  3471. qp->hba_index, qp->notify_interval);
  3472. len += scnprintf(pbuffer + len,
  3473. LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
  3474. return len;
  3475. }
  3476. static int
  3477. lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
  3478. int *len, int max_cnt, int cq_id)
  3479. {
  3480. struct lpfc_queue *qp;
  3481. int qidx;
  3482. for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
  3483. qp = phba->sli4_hba.hdwq[qidx].io_wq;
  3484. if (qp->assoc_qid != cq_id)
  3485. continue;
  3486. *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
  3487. if (*len >= max_cnt)
  3488. return 1;
  3489. }
  3490. return 0;
  3491. }
  3492. static int
  3493. __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
  3494. char *pbuffer, int len)
  3495. {
  3496. if (!qp)
  3497. return len;
  3498. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3499. "\t%s CQ info: ", cqtype);
  3500. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3501. "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
  3502. "xabt:x%x wq:x%llx]\n",
  3503. qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
  3504. qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
  3505. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3506. "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  3507. "HST-IDX[%04d], NTFI[%03d], PLMT[%03d]",
  3508. qp->queue_id, qp->entry_count,
  3509. qp->entry_size, qp->host_index,
  3510. qp->notify_interval, qp->max_proc_limit);
  3511. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3512. "\n");
  3513. return len;
  3514. }
  3515. static int
  3516. __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
  3517. char *rqtype, char *pbuffer, int len)
  3518. {
  3519. if (!qp || !datqp)
  3520. return len;
  3521. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3522. "\t\t%s RQ info: ", rqtype);
  3523. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3524. "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
  3525. "posted:x%x rcv:x%llx]\n",
  3526. qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
  3527. qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
  3528. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3529. "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  3530. "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
  3531. qp->queue_id, qp->entry_count, qp->entry_size,
  3532. qp->host_index, qp->hba_index, qp->notify_interval);
  3533. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3534. "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  3535. "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
  3536. datqp->queue_id, datqp->entry_count,
  3537. datqp->entry_size, datqp->host_index,
  3538. datqp->hba_index, datqp->notify_interval);
  3539. return len;
  3540. }
  3541. static int
  3542. lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
  3543. int *len, int max_cnt, int eqidx, int eq_id)
  3544. {
  3545. struct lpfc_queue *qp;
  3546. int rc;
  3547. qp = phba->sli4_hba.hdwq[eqidx].io_cq;
  3548. *len = __lpfc_idiag_print_cq(qp, "IO", pbuffer, *len);
  3549. /* Reset max counter */
  3550. qp->CQ_max_cqe = 0;
  3551. if (*len >= max_cnt)
  3552. return 1;
  3553. rc = lpfc_idiag_wqs_for_cq(phba, "IO", pbuffer, len,
  3554. max_cnt, qp->queue_id);
  3555. if (rc)
  3556. return 1;
  3557. if ((eqidx < phba->cfg_nvmet_mrq) && phba->nvmet_support) {
  3558. /* NVMET CQset */
  3559. qp = phba->sli4_hba.nvmet_cqset[eqidx];
  3560. *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
  3561. /* Reset max counter */
  3562. qp->CQ_max_cqe = 0;
  3563. if (*len >= max_cnt)
  3564. return 1;
  3565. /* RQ header */
  3566. qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
  3567. *len = __lpfc_idiag_print_rqpair(qp,
  3568. phba->sli4_hba.nvmet_mrq_data[eqidx],
  3569. "NVMET MRQ", pbuffer, *len);
  3570. if (*len >= max_cnt)
  3571. return 1;
  3572. }
  3573. return 0;
  3574. }
  3575. static int
  3576. __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
  3577. char *pbuffer, int len)
  3578. {
  3579. if (!qp)
  3580. return len;
  3581. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3582. "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
  3583. "cqe_proc:x%x eqe_proc:x%llx eqd %d]\n",
  3584. eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
  3585. (unsigned long long)qp->q_cnt_4, qp->q_mode);
  3586. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3587. "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
  3588. "HST-IDX[%04d], NTFI[%03d], PLMT[%03d], AFFIN[%03d]",
  3589. qp->queue_id, qp->entry_count, qp->entry_size,
  3590. qp->host_index, qp->notify_interval,
  3591. qp->max_proc_limit, qp->chann);
  3592. len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3593. "\n");
  3594. return len;
  3595. }
  3596. /**
  3597. * lpfc_idiag_queinfo_read - idiag debugfs read queue information
  3598. * @file: The file pointer to read from.
  3599. * @buf: The buffer to copy the data to.
  3600. * @nbytes: The number of bytes to read.
  3601. * @ppos: The position in the file to start reading from.
  3602. *
  3603. * Description:
  3604. * This routine reads data from the @phba SLI4 PCI function queue information,
  3605. * and copies to user @buf.
  3606. * This routine only returns 1 EQs worth of information. It remembers the last
  3607. * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
  3608. * retrieve all EQs allocated for the phba.
  3609. *
  3610. * Returns:
  3611. * This function returns the amount of data that was read (this could be less
  3612. * than @nbytes if the end of the file was reached) or a negative error value.
  3613. **/
  3614. static ssize_t
  3615. lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
  3616. loff_t *ppos)
  3617. {
  3618. struct lpfc_debug *debug = file->private_data;
  3619. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3620. char *pbuffer;
  3621. int max_cnt, rc, x, len = 0;
  3622. struct lpfc_queue *qp = NULL;
  3623. if (!debug->buffer)
  3624. debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
  3625. if (!debug->buffer)
  3626. return 0;
  3627. pbuffer = debug->buffer;
  3628. max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
  3629. if (*ppos)
  3630. return 0;
  3631. spin_lock_irq(&phba->hbalock);
  3632. /* Fast-path event queue */
  3633. if (phba->sli4_hba.hdwq && phba->cfg_hdw_queue) {
  3634. x = phba->lpfc_idiag_last_eq;
  3635. phba->lpfc_idiag_last_eq++;
  3636. if (phba->lpfc_idiag_last_eq >= phba->cfg_hdw_queue)
  3637. phba->lpfc_idiag_last_eq = 0;
  3638. len += scnprintf(pbuffer + len,
  3639. LPFC_QUE_INFO_GET_BUF_SIZE - len,
  3640. "HDWQ %d out of %d HBA HDWQs\n",
  3641. x, phba->cfg_hdw_queue);
  3642. /* Fast-path EQ */
  3643. qp = phba->sli4_hba.hdwq[x].hba_eq;
  3644. if (!qp)
  3645. goto out;
  3646. len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
  3647. /* Reset max counter */
  3648. qp->EQ_max_eqe = 0;
  3649. if (len >= max_cnt)
  3650. goto too_big;
  3651. /* will dump both fcp and nvme cqs/wqs for the eq */
  3652. rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
  3653. max_cnt, x, qp->queue_id);
  3654. if (rc)
  3655. goto too_big;
  3656. /* Only EQ 0 has slow path CQs configured */
  3657. if (x)
  3658. goto out;
  3659. /* Slow-path mailbox CQ */
  3660. qp = phba->sli4_hba.mbx_cq;
  3661. len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
  3662. if (len >= max_cnt)
  3663. goto too_big;
  3664. /* Slow-path MBOX MQ */
  3665. qp = phba->sli4_hba.mbx_wq;
  3666. len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
  3667. if (len >= max_cnt)
  3668. goto too_big;
  3669. /* Slow-path ELS response CQ */
  3670. qp = phba->sli4_hba.els_cq;
  3671. len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
  3672. /* Reset max counter */
  3673. if (qp)
  3674. qp->CQ_max_cqe = 0;
  3675. if (len >= max_cnt)
  3676. goto too_big;
  3677. /* Slow-path ELS WQ */
  3678. qp = phba->sli4_hba.els_wq;
  3679. len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
  3680. if (len >= max_cnt)
  3681. goto too_big;
  3682. qp = phba->sli4_hba.hdr_rq;
  3683. len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
  3684. "ELS RQpair", pbuffer, len);
  3685. if (len >= max_cnt)
  3686. goto too_big;
  3687. /* Slow-path NVME LS response CQ */
  3688. qp = phba->sli4_hba.nvmels_cq;
  3689. len = __lpfc_idiag_print_cq(qp, "NVME LS",
  3690. pbuffer, len);
  3691. /* Reset max counter */
  3692. if (qp)
  3693. qp->CQ_max_cqe = 0;
  3694. if (len >= max_cnt)
  3695. goto too_big;
  3696. /* Slow-path NVME LS WQ */
  3697. qp = phba->sli4_hba.nvmels_wq;
  3698. len = __lpfc_idiag_print_wq(qp, "NVME LS",
  3699. pbuffer, len);
  3700. if (len >= max_cnt)
  3701. goto too_big;
  3702. goto out;
  3703. }
  3704. spin_unlock_irq(&phba->hbalock);
  3705. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3706. too_big:
  3707. len += scnprintf(pbuffer + len,
  3708. LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
  3709. out:
  3710. spin_unlock_irq(&phba->hbalock);
  3711. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3712. }
  3713. /**
  3714. * lpfc_idiag_que_param_check - queue access command parameter sanity check
  3715. * @q: The pointer to queue structure.
  3716. * @index: The index into a queue entry.
  3717. * @count: The number of queue entries to access.
  3718. *
  3719. * Description:
  3720. * The routine performs sanity check on device queue access method commands.
  3721. *
  3722. * Returns:
  3723. * This function returns -EINVAL when fails the sanity check, otherwise, it
  3724. * returns 0.
  3725. **/
  3726. static int
  3727. lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
  3728. {
  3729. /* Only support single entry read or browsing */
  3730. if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
  3731. return -EINVAL;
  3732. if (index > q->entry_count - 1)
  3733. return -EINVAL;
  3734. return 0;
  3735. }
  3736. /**
  3737. * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
  3738. * @pbuffer: The pointer to buffer to copy the read data into.
  3739. * @len: Length of the buffer.
  3740. * @pque: The pointer to the queue to be read.
  3741. * @index: The index into the queue entry.
  3742. *
  3743. * Description:
  3744. * This routine reads out a single entry from the given queue's index location
  3745. * and copies it into the buffer provided.
  3746. *
  3747. * Returns:
  3748. * This function returns 0 when it fails, otherwise, it returns the length of
  3749. * the data read into the buffer provided.
  3750. **/
  3751. static int
  3752. lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
  3753. uint32_t index)
  3754. {
  3755. int offset, esize;
  3756. uint32_t *pentry;
  3757. if (!pbuffer || !pque)
  3758. return 0;
  3759. esize = pque->entry_size;
  3760. len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  3761. "QE-INDEX[%04d]:\n", index);
  3762. offset = 0;
  3763. pentry = lpfc_sli4_qe(pque, index);
  3764. while (esize > 0) {
  3765. len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  3766. "%08x ", *pentry);
  3767. pentry++;
  3768. offset += sizeof(uint32_t);
  3769. esize -= sizeof(uint32_t);
  3770. if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
  3771. len += scnprintf(pbuffer+len,
  3772. LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  3773. }
  3774. len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  3775. return len;
  3776. }
  3777. /**
  3778. * lpfc_idiag_queacc_read - idiag debugfs read port queue
  3779. * @file: The file pointer to read from.
  3780. * @buf: The buffer to copy the data to.
  3781. * @nbytes: The number of bytes to read.
  3782. * @ppos: The position in the file to start reading from.
  3783. *
  3784. * Description:
  3785. * This routine reads data from the @phba device queue memory according to the
  3786. * idiag command, and copies to user @buf. Depending on the queue dump read
  3787. * command setup, it does either a single queue entry read or browing through
  3788. * all entries of the queue.
  3789. *
  3790. * Returns:
  3791. * This function returns the amount of data that was read (this could be less
  3792. * than @nbytes if the end of the file was reached) or a negative error value.
  3793. **/
  3794. static ssize_t
  3795. lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
  3796. loff_t *ppos)
  3797. {
  3798. struct lpfc_debug *debug = file->private_data;
  3799. uint32_t last_index, index, count;
  3800. struct lpfc_queue *pque = NULL;
  3801. char *pbuffer;
  3802. int len = 0;
  3803. /* This is a user read operation */
  3804. debug->op = LPFC_IDIAG_OP_RD;
  3805. if (!debug->buffer)
  3806. debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
  3807. if (!debug->buffer)
  3808. return 0;
  3809. pbuffer = debug->buffer;
  3810. if (*ppos)
  3811. return 0;
  3812. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  3813. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  3814. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  3815. pque = (struct lpfc_queue *)idiag.ptr_private;
  3816. } else
  3817. return 0;
  3818. /* Browse the queue starting from index */
  3819. if (count == LPFC_QUE_ACC_BROWSE)
  3820. goto que_browse;
  3821. /* Read a single entry from the queue */
  3822. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  3823. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3824. que_browse:
  3825. /* Browse all entries from the queue */
  3826. last_index = idiag.offset.last_rd;
  3827. index = last_index;
  3828. while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
  3829. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  3830. index++;
  3831. if (index > pque->entry_count - 1)
  3832. break;
  3833. }
  3834. /* Set up the offset for next portion of pci cfg read */
  3835. if (index > pque->entry_count - 1)
  3836. index = 0;
  3837. idiag.offset.last_rd = index;
  3838. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3839. }
  3840. /**
  3841. * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
  3842. * @file: The file pointer to read from.
  3843. * @buf: The buffer to copy the user data from.
  3844. * @nbytes: The number of bytes to get.
  3845. * @ppos: The position in the file to start reading from.
  3846. *
  3847. * This routine get the debugfs idiag command struct from user space and then
  3848. * perform the syntax check for port queue read (dump) or write (set) command
  3849. * accordingly. In the case of port queue read command, it sets up the command
  3850. * in the idiag command struct for the following debugfs read operation. In
  3851. * the case of port queue write operation, it executes the write operation
  3852. * into the port queue entry accordingly.
  3853. *
  3854. * It returns the @nbytges passing in from debugfs user space when successful.
  3855. * In case of error conditions, it returns proper error code back to the user
  3856. * space.
  3857. **/
  3858. static ssize_t
  3859. lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
  3860. size_t nbytes, loff_t *ppos)
  3861. {
  3862. struct lpfc_debug *debug = file->private_data;
  3863. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3864. uint32_t qidx, quetp, queid, index, count, offset, value;
  3865. uint32_t *pentry;
  3866. struct lpfc_queue *pque, *qp;
  3867. int rc;
  3868. /* This is a user write operation */
  3869. debug->op = LPFC_IDIAG_OP_WR;
  3870. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  3871. if (rc < 0)
  3872. return rc;
  3873. /* Get and sanity check on command feilds */
  3874. quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
  3875. queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
  3876. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  3877. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  3878. offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
  3879. value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
  3880. /* Sanity check on command line arguments */
  3881. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  3882. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  3883. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  3884. if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
  3885. goto error_out;
  3886. if (count != 1)
  3887. goto error_out;
  3888. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  3889. if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
  3890. goto error_out;
  3891. } else
  3892. goto error_out;
  3893. switch (quetp) {
  3894. case LPFC_IDIAG_EQ:
  3895. /* HBA event queue */
  3896. if (phba->sli4_hba.hdwq) {
  3897. for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
  3898. qp = phba->sli4_hba.hdwq[qidx].hba_eq;
  3899. if (qp && qp->queue_id == queid) {
  3900. /* Sanity check */
  3901. rc = lpfc_idiag_que_param_check(qp,
  3902. index, count);
  3903. if (rc)
  3904. goto error_out;
  3905. idiag.ptr_private = qp;
  3906. goto pass_check;
  3907. }
  3908. }
  3909. }
  3910. goto error_out;
  3911. case LPFC_IDIAG_CQ:
  3912. /* MBX complete queue */
  3913. if (phba->sli4_hba.mbx_cq &&
  3914. phba->sli4_hba.mbx_cq->queue_id == queid) {
  3915. /* Sanity check */
  3916. rc = lpfc_idiag_que_param_check(
  3917. phba->sli4_hba.mbx_cq, index, count);
  3918. if (rc)
  3919. goto error_out;
  3920. idiag.ptr_private = phba->sli4_hba.mbx_cq;
  3921. goto pass_check;
  3922. }
  3923. /* ELS complete queue */
  3924. if (phba->sli4_hba.els_cq &&
  3925. phba->sli4_hba.els_cq->queue_id == queid) {
  3926. /* Sanity check */
  3927. rc = lpfc_idiag_que_param_check(
  3928. phba->sli4_hba.els_cq, index, count);
  3929. if (rc)
  3930. goto error_out;
  3931. idiag.ptr_private = phba->sli4_hba.els_cq;
  3932. goto pass_check;
  3933. }
  3934. /* NVME LS complete queue */
  3935. if (phba->sli4_hba.nvmels_cq &&
  3936. phba->sli4_hba.nvmels_cq->queue_id == queid) {
  3937. /* Sanity check */
  3938. rc = lpfc_idiag_que_param_check(
  3939. phba->sli4_hba.nvmels_cq, index, count);
  3940. if (rc)
  3941. goto error_out;
  3942. idiag.ptr_private = phba->sli4_hba.nvmels_cq;
  3943. goto pass_check;
  3944. }
  3945. /* FCP complete queue */
  3946. if (phba->sli4_hba.hdwq) {
  3947. for (qidx = 0; qidx < phba->cfg_hdw_queue;
  3948. qidx++) {
  3949. qp = phba->sli4_hba.hdwq[qidx].io_cq;
  3950. if (qp && qp->queue_id == queid) {
  3951. /* Sanity check */
  3952. rc = lpfc_idiag_que_param_check(
  3953. qp, index, count);
  3954. if (rc)
  3955. goto error_out;
  3956. idiag.ptr_private = qp;
  3957. goto pass_check;
  3958. }
  3959. }
  3960. }
  3961. goto error_out;
  3962. case LPFC_IDIAG_MQ:
  3963. /* MBX work queue */
  3964. if (phba->sli4_hba.mbx_wq &&
  3965. phba->sli4_hba.mbx_wq->queue_id == queid) {
  3966. /* Sanity check */
  3967. rc = lpfc_idiag_que_param_check(
  3968. phba->sli4_hba.mbx_wq, index, count);
  3969. if (rc)
  3970. goto error_out;
  3971. idiag.ptr_private = phba->sli4_hba.mbx_wq;
  3972. goto pass_check;
  3973. }
  3974. goto error_out;
  3975. case LPFC_IDIAG_WQ:
  3976. /* ELS work queue */
  3977. if (phba->sli4_hba.els_wq &&
  3978. phba->sli4_hba.els_wq->queue_id == queid) {
  3979. /* Sanity check */
  3980. rc = lpfc_idiag_que_param_check(
  3981. phba->sli4_hba.els_wq, index, count);
  3982. if (rc)
  3983. goto error_out;
  3984. idiag.ptr_private = phba->sli4_hba.els_wq;
  3985. goto pass_check;
  3986. }
  3987. /* NVME LS work queue */
  3988. if (phba->sli4_hba.nvmels_wq &&
  3989. phba->sli4_hba.nvmels_wq->queue_id == queid) {
  3990. /* Sanity check */
  3991. rc = lpfc_idiag_que_param_check(
  3992. phba->sli4_hba.nvmels_wq, index, count);
  3993. if (rc)
  3994. goto error_out;
  3995. idiag.ptr_private = phba->sli4_hba.nvmels_wq;
  3996. goto pass_check;
  3997. }
  3998. if (phba->sli4_hba.hdwq) {
  3999. /* FCP/SCSI work queue */
  4000. for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
  4001. qp = phba->sli4_hba.hdwq[qidx].io_wq;
  4002. if (qp && qp->queue_id == queid) {
  4003. /* Sanity check */
  4004. rc = lpfc_idiag_que_param_check(
  4005. qp, index, count);
  4006. if (rc)
  4007. goto error_out;
  4008. idiag.ptr_private = qp;
  4009. goto pass_check;
  4010. }
  4011. }
  4012. }
  4013. goto error_out;
  4014. case LPFC_IDIAG_RQ:
  4015. /* HDR queue */
  4016. if (phba->sli4_hba.hdr_rq &&
  4017. phba->sli4_hba.hdr_rq->queue_id == queid) {
  4018. /* Sanity check */
  4019. rc = lpfc_idiag_que_param_check(
  4020. phba->sli4_hba.hdr_rq, index, count);
  4021. if (rc)
  4022. goto error_out;
  4023. idiag.ptr_private = phba->sli4_hba.hdr_rq;
  4024. goto pass_check;
  4025. }
  4026. /* DAT queue */
  4027. if (phba->sli4_hba.dat_rq &&
  4028. phba->sli4_hba.dat_rq->queue_id == queid) {
  4029. /* Sanity check */
  4030. rc = lpfc_idiag_que_param_check(
  4031. phba->sli4_hba.dat_rq, index, count);
  4032. if (rc)
  4033. goto error_out;
  4034. idiag.ptr_private = phba->sli4_hba.dat_rq;
  4035. goto pass_check;
  4036. }
  4037. goto error_out;
  4038. default:
  4039. goto error_out;
  4040. }
  4041. pass_check:
  4042. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  4043. if (count == LPFC_QUE_ACC_BROWSE)
  4044. idiag.offset.last_rd = index;
  4045. }
  4046. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  4047. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  4048. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  4049. /* Additional sanity checks on write operation */
  4050. pque = (struct lpfc_queue *)idiag.ptr_private;
  4051. if (offset > pque->entry_size/sizeof(uint32_t) - 1)
  4052. goto error_out;
  4053. pentry = lpfc_sli4_qe(pque, index);
  4054. pentry += offset;
  4055. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
  4056. *pentry = value;
  4057. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
  4058. *pentry |= value;
  4059. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
  4060. *pentry &= ~value;
  4061. }
  4062. return nbytes;
  4063. error_out:
  4064. /* Clean out command structure on command error out */
  4065. memset(&idiag, 0, sizeof(idiag));
  4066. return -EINVAL;
  4067. }
  4068. /**
  4069. * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
  4070. * @phba: The pointer to hba structure.
  4071. * @pbuffer: The pointer to the buffer to copy the data to.
  4072. * @len: The length of bytes to copied.
  4073. * @drbregid: The id to doorbell registers.
  4074. *
  4075. * Description:
  4076. * This routine reads a doorbell register and copies its content to the
  4077. * user buffer pointed to by @pbuffer.
  4078. *
  4079. * Returns:
  4080. * This function returns the amount of data that was copied into @pbuffer.
  4081. **/
  4082. static int
  4083. lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  4084. int len, uint32_t drbregid)
  4085. {
  4086. if (!pbuffer)
  4087. return 0;
  4088. switch (drbregid) {
  4089. case LPFC_DRB_EQ:
  4090. len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE-len,
  4091. "EQ-DRB-REG: 0x%08x\n",
  4092. readl(phba->sli4_hba.EQDBregaddr));
  4093. break;
  4094. case LPFC_DRB_CQ:
  4095. len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE - len,
  4096. "CQ-DRB-REG: 0x%08x\n",
  4097. readl(phba->sli4_hba.CQDBregaddr));
  4098. break;
  4099. case LPFC_DRB_MQ:
  4100. len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  4101. "MQ-DRB-REG: 0x%08x\n",
  4102. readl(phba->sli4_hba.MQDBregaddr));
  4103. break;
  4104. case LPFC_DRB_WQ:
  4105. len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  4106. "WQ-DRB-REG: 0x%08x\n",
  4107. readl(phba->sli4_hba.WQDBregaddr));
  4108. break;
  4109. case LPFC_DRB_RQ:
  4110. len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  4111. "RQ-DRB-REG: 0x%08x\n",
  4112. readl(phba->sli4_hba.RQDBregaddr));
  4113. break;
  4114. default:
  4115. break;
  4116. }
  4117. return len;
  4118. }
  4119. /**
  4120. * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
  4121. * @file: The file pointer to read from.
  4122. * @buf: The buffer to copy the data to.
  4123. * @nbytes: The number of bytes to read.
  4124. * @ppos: The position in the file to start reading from.
  4125. *
  4126. * Description:
  4127. * This routine reads data from the @phba device doorbell register according
  4128. * to the idiag command, and copies to user @buf. Depending on the doorbell
  4129. * register read command setup, it does either a single doorbell register
  4130. * read or dump all doorbell registers.
  4131. *
  4132. * Returns:
  4133. * This function returns the amount of data that was read (this could be less
  4134. * than @nbytes if the end of the file was reached) or a negative error value.
  4135. **/
  4136. static ssize_t
  4137. lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
  4138. loff_t *ppos)
  4139. {
  4140. struct lpfc_debug *debug = file->private_data;
  4141. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4142. uint32_t drb_reg_id, i;
  4143. char *pbuffer;
  4144. int len = 0;
  4145. /* This is a user read operation */
  4146. debug->op = LPFC_IDIAG_OP_RD;
  4147. if (!debug->buffer)
  4148. debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
  4149. if (!debug->buffer)
  4150. return 0;
  4151. pbuffer = debug->buffer;
  4152. if (*ppos)
  4153. return 0;
  4154. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
  4155. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  4156. else
  4157. return 0;
  4158. if (drb_reg_id == LPFC_DRB_ACC_ALL)
  4159. for (i = 1; i <= LPFC_DRB_MAX; i++)
  4160. len = lpfc_idiag_drbacc_read_reg(phba,
  4161. pbuffer, len, i);
  4162. else
  4163. len = lpfc_idiag_drbacc_read_reg(phba,
  4164. pbuffer, len, drb_reg_id);
  4165. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  4166. }
  4167. /**
  4168. * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
  4169. * @file: The file pointer to read from.
  4170. * @buf: The buffer to copy the user data from.
  4171. * @nbytes: The number of bytes to get.
  4172. * @ppos: The position in the file to start reading from.
  4173. *
  4174. * This routine get the debugfs idiag command struct from user space and then
  4175. * perform the syntax check for port doorbell register read (dump) or write
  4176. * (set) command accordingly. In the case of port queue read command, it sets
  4177. * up the command in the idiag command struct for the following debugfs read
  4178. * operation. In the case of port doorbell register write operation, it
  4179. * executes the write operation into the port doorbell register accordingly.
  4180. *
  4181. * It returns the @nbytges passing in from debugfs user space when successful.
  4182. * In case of error conditions, it returns proper error code back to the user
  4183. * space.
  4184. **/
  4185. static ssize_t
  4186. lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
  4187. size_t nbytes, loff_t *ppos)
  4188. {
  4189. struct lpfc_debug *debug = file->private_data;
  4190. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4191. uint32_t drb_reg_id, value, reg_val = 0;
  4192. void __iomem *drb_reg;
  4193. int rc;
  4194. /* This is a user write operation */
  4195. debug->op = LPFC_IDIAG_OP_WR;
  4196. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  4197. if (rc < 0)
  4198. return rc;
  4199. /* Sanity check on command line arguments */
  4200. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  4201. value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
  4202. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  4203. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  4204. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  4205. if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
  4206. goto error_out;
  4207. if (drb_reg_id > LPFC_DRB_MAX)
  4208. goto error_out;
  4209. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
  4210. if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
  4211. goto error_out;
  4212. if ((drb_reg_id > LPFC_DRB_MAX) &&
  4213. (drb_reg_id != LPFC_DRB_ACC_ALL))
  4214. goto error_out;
  4215. } else
  4216. goto error_out;
  4217. /* Perform the write access operation */
  4218. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  4219. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  4220. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  4221. switch (drb_reg_id) {
  4222. case LPFC_DRB_EQ:
  4223. drb_reg = phba->sli4_hba.EQDBregaddr;
  4224. break;
  4225. case LPFC_DRB_CQ:
  4226. drb_reg = phba->sli4_hba.CQDBregaddr;
  4227. break;
  4228. case LPFC_DRB_MQ:
  4229. drb_reg = phba->sli4_hba.MQDBregaddr;
  4230. break;
  4231. case LPFC_DRB_WQ:
  4232. drb_reg = phba->sli4_hba.WQDBregaddr;
  4233. break;
  4234. case LPFC_DRB_RQ:
  4235. drb_reg = phba->sli4_hba.RQDBregaddr;
  4236. break;
  4237. default:
  4238. goto error_out;
  4239. }
  4240. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
  4241. reg_val = value;
  4242. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
  4243. reg_val = readl(drb_reg);
  4244. reg_val |= value;
  4245. }
  4246. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  4247. reg_val = readl(drb_reg);
  4248. reg_val &= ~value;
  4249. }
  4250. writel(reg_val, drb_reg);
  4251. readl(drb_reg); /* flush */
  4252. }
  4253. return nbytes;
  4254. error_out:
  4255. /* Clean out command structure on command error out */
  4256. memset(&idiag, 0, sizeof(idiag));
  4257. return -EINVAL;
  4258. }
  4259. /**
  4260. * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
  4261. * @phba: The pointer to hba structure.
  4262. * @pbuffer: The pointer to the buffer to copy the data to.
  4263. * @len: The length of bytes to copied.
  4264. * @ctlregid: The id to doorbell registers.
  4265. *
  4266. * Description:
  4267. * This routine reads a control register and copies its content to the
  4268. * user buffer pointed to by @pbuffer.
  4269. *
  4270. * Returns:
  4271. * This function returns the amount of data that was copied into @pbuffer.
  4272. **/
  4273. static int
  4274. lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  4275. int len, uint32_t ctlregid)
  4276. {
  4277. if (!pbuffer)
  4278. return 0;
  4279. switch (ctlregid) {
  4280. case LPFC_CTL_PORT_SEM:
  4281. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4282. "Port SemReg: 0x%08x\n",
  4283. readl(phba->sli4_hba.conf_regs_memmap_p +
  4284. LPFC_CTL_PORT_SEM_OFFSET));
  4285. break;
  4286. case LPFC_CTL_PORT_STA:
  4287. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4288. "Port StaReg: 0x%08x\n",
  4289. readl(phba->sli4_hba.conf_regs_memmap_p +
  4290. LPFC_CTL_PORT_STA_OFFSET));
  4291. break;
  4292. case LPFC_CTL_PORT_CTL:
  4293. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4294. "Port CtlReg: 0x%08x\n",
  4295. readl(phba->sli4_hba.conf_regs_memmap_p +
  4296. LPFC_CTL_PORT_CTL_OFFSET));
  4297. break;
  4298. case LPFC_CTL_PORT_ER1:
  4299. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4300. "Port Er1Reg: 0x%08x\n",
  4301. readl(phba->sli4_hba.conf_regs_memmap_p +
  4302. LPFC_CTL_PORT_ER1_OFFSET));
  4303. break;
  4304. case LPFC_CTL_PORT_ER2:
  4305. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4306. "Port Er2Reg: 0x%08x\n",
  4307. readl(phba->sli4_hba.conf_regs_memmap_p +
  4308. LPFC_CTL_PORT_ER2_OFFSET));
  4309. break;
  4310. case LPFC_CTL_PDEV_CTL:
  4311. len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  4312. "PDev CtlReg: 0x%08x\n",
  4313. readl(phba->sli4_hba.conf_regs_memmap_p +
  4314. LPFC_CTL_PDEV_CTL_OFFSET));
  4315. break;
  4316. default:
  4317. break;
  4318. }
  4319. return len;
  4320. }
  4321. /**
  4322. * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
  4323. * @file: The file pointer to read from.
  4324. * @buf: The buffer to copy the data to.
  4325. * @nbytes: The number of bytes to read.
  4326. * @ppos: The position in the file to start reading from.
  4327. *
  4328. * Description:
  4329. * This routine reads data from the @phba port and device registers according
  4330. * to the idiag command, and copies to user @buf.
  4331. *
  4332. * Returns:
  4333. * This function returns the amount of data that was read (this could be less
  4334. * than @nbytes if the end of the file was reached) or a negative error value.
  4335. **/
  4336. static ssize_t
  4337. lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
  4338. loff_t *ppos)
  4339. {
  4340. struct lpfc_debug *debug = file->private_data;
  4341. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4342. uint32_t ctl_reg_id, i;
  4343. char *pbuffer;
  4344. int len = 0;
  4345. /* This is a user read operation */
  4346. debug->op = LPFC_IDIAG_OP_RD;
  4347. if (!debug->buffer)
  4348. debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
  4349. if (!debug->buffer)
  4350. return 0;
  4351. pbuffer = debug->buffer;
  4352. if (*ppos)
  4353. return 0;
  4354. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
  4355. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  4356. else
  4357. return 0;
  4358. if (ctl_reg_id == LPFC_CTL_ACC_ALL)
  4359. for (i = 1; i <= LPFC_CTL_MAX; i++)
  4360. len = lpfc_idiag_ctlacc_read_reg(phba,
  4361. pbuffer, len, i);
  4362. else
  4363. len = lpfc_idiag_ctlacc_read_reg(phba,
  4364. pbuffer, len, ctl_reg_id);
  4365. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  4366. }
  4367. /**
  4368. * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
  4369. * @file: The file pointer to read from.
  4370. * @buf: The buffer to copy the user data from.
  4371. * @nbytes: The number of bytes to get.
  4372. * @ppos: The position in the file to start reading from.
  4373. *
  4374. * This routine get the debugfs idiag command struct from user space and then
  4375. * perform the syntax check for port and device control register read (dump)
  4376. * or write (set) command accordingly.
  4377. *
  4378. * It returns the @nbytges passing in from debugfs user space when successful.
  4379. * In case of error conditions, it returns proper error code back to the user
  4380. * space.
  4381. **/
  4382. static ssize_t
  4383. lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
  4384. size_t nbytes, loff_t *ppos)
  4385. {
  4386. struct lpfc_debug *debug = file->private_data;
  4387. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4388. uint32_t ctl_reg_id, value, reg_val = 0;
  4389. void __iomem *ctl_reg;
  4390. int rc;
  4391. /* This is a user write operation */
  4392. debug->op = LPFC_IDIAG_OP_WR;
  4393. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  4394. if (rc < 0)
  4395. return rc;
  4396. /* Sanity check on command line arguments */
  4397. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  4398. value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
  4399. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  4400. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  4401. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  4402. if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
  4403. goto error_out;
  4404. if (ctl_reg_id > LPFC_CTL_MAX)
  4405. goto error_out;
  4406. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
  4407. if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
  4408. goto error_out;
  4409. if ((ctl_reg_id > LPFC_CTL_MAX) &&
  4410. (ctl_reg_id != LPFC_CTL_ACC_ALL))
  4411. goto error_out;
  4412. } else
  4413. goto error_out;
  4414. /* Perform the write access operation */
  4415. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  4416. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  4417. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  4418. switch (ctl_reg_id) {
  4419. case LPFC_CTL_PORT_SEM:
  4420. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4421. LPFC_CTL_PORT_SEM_OFFSET;
  4422. break;
  4423. case LPFC_CTL_PORT_STA:
  4424. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4425. LPFC_CTL_PORT_STA_OFFSET;
  4426. break;
  4427. case LPFC_CTL_PORT_CTL:
  4428. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4429. LPFC_CTL_PORT_CTL_OFFSET;
  4430. break;
  4431. case LPFC_CTL_PORT_ER1:
  4432. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4433. LPFC_CTL_PORT_ER1_OFFSET;
  4434. break;
  4435. case LPFC_CTL_PORT_ER2:
  4436. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4437. LPFC_CTL_PORT_ER2_OFFSET;
  4438. break;
  4439. case LPFC_CTL_PDEV_CTL:
  4440. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  4441. LPFC_CTL_PDEV_CTL_OFFSET;
  4442. break;
  4443. default:
  4444. goto error_out;
  4445. }
  4446. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
  4447. reg_val = value;
  4448. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
  4449. reg_val = readl(ctl_reg);
  4450. reg_val |= value;
  4451. }
  4452. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  4453. reg_val = readl(ctl_reg);
  4454. reg_val &= ~value;
  4455. }
  4456. writel(reg_val, ctl_reg);
  4457. readl(ctl_reg); /* flush */
  4458. }
  4459. return nbytes;
  4460. error_out:
  4461. /* Clean out command structure on command error out */
  4462. memset(&idiag, 0, sizeof(idiag));
  4463. return -EINVAL;
  4464. }
  4465. /**
  4466. * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
  4467. * @phba: Pointer to HBA context object.
  4468. * @pbuffer: Pointer to data buffer.
  4469. *
  4470. * Description:
  4471. * This routine gets the driver mailbox access debugfs setup information.
  4472. *
  4473. * Returns:
  4474. * This function returns the amount of data that was read (this could be less
  4475. * than @nbytes if the end of the file was reached) or a negative error value.
  4476. **/
  4477. static int
  4478. lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
  4479. {
  4480. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  4481. int len = 0;
  4482. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  4483. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  4484. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  4485. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  4486. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  4487. "mbx_dump_map: 0x%08x\n", mbx_dump_map);
  4488. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  4489. "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
  4490. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  4491. "mbx_word_cnt: %04d\n", mbx_word_cnt);
  4492. len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  4493. "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
  4494. return len;
  4495. }
  4496. /**
  4497. * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
  4498. * @file: The file pointer to read from.
  4499. * @buf: The buffer to copy the data to.
  4500. * @nbytes: The number of bytes to read.
  4501. * @ppos: The position in the file to start reading from.
  4502. *
  4503. * Description:
  4504. * This routine reads data from the @phba driver mailbox access debugfs setup
  4505. * information.
  4506. *
  4507. * Returns:
  4508. * This function returns the amount of data that was read (this could be less
  4509. * than @nbytes if the end of the file was reached) or a negative error value.
  4510. **/
  4511. static ssize_t
  4512. lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
  4513. loff_t *ppos)
  4514. {
  4515. struct lpfc_debug *debug = file->private_data;
  4516. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4517. char *pbuffer;
  4518. int len = 0;
  4519. /* This is a user read operation */
  4520. debug->op = LPFC_IDIAG_OP_RD;
  4521. if (!debug->buffer)
  4522. debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
  4523. if (!debug->buffer)
  4524. return 0;
  4525. pbuffer = debug->buffer;
  4526. if (*ppos)
  4527. return 0;
  4528. if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
  4529. (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
  4530. return 0;
  4531. len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
  4532. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  4533. }
  4534. /**
  4535. * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
  4536. * @file: The file pointer to read from.
  4537. * @buf: The buffer to copy the user data from.
  4538. * @nbytes: The number of bytes to get.
  4539. * @ppos: The position in the file to start reading from.
  4540. *
  4541. * This routine get the debugfs idiag command struct from user space and then
  4542. * perform the syntax check for driver mailbox command (dump) and sets up the
  4543. * necessary states in the idiag command struct accordingly.
  4544. *
  4545. * It returns the @nbytges passing in from debugfs user space when successful.
  4546. * In case of error conditions, it returns proper error code back to the user
  4547. * space.
  4548. **/
  4549. static ssize_t
  4550. lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
  4551. size_t nbytes, loff_t *ppos)
  4552. {
  4553. struct lpfc_debug *debug = file->private_data;
  4554. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  4555. int rc;
  4556. /* This is a user write operation */
  4557. debug->op = LPFC_IDIAG_OP_WR;
  4558. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  4559. if (rc < 0)
  4560. return rc;
  4561. /* Sanity check on command line arguments */
  4562. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  4563. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  4564. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  4565. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  4566. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
  4567. if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
  4568. goto error_out;
  4569. if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
  4570. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  4571. goto error_out;
  4572. if (mbx_word_cnt > sizeof(MAILBOX_t))
  4573. goto error_out;
  4574. } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
  4575. if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
  4576. goto error_out;
  4577. if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
  4578. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  4579. goto error_out;
  4580. if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
  4581. goto error_out;
  4582. if (mbx_mbox_cmd != 0x9b)
  4583. goto error_out;
  4584. } else
  4585. goto error_out;
  4586. if (mbx_word_cnt == 0)
  4587. goto error_out;
  4588. if (rc != LPFC_MBX_DMP_ARG)
  4589. goto error_out;
  4590. if (mbx_mbox_cmd & ~0xff)
  4591. goto error_out;
  4592. /* condition for stop mailbox dump */
  4593. if (mbx_dump_cnt == 0)
  4594. goto reset_out;
  4595. return nbytes;
  4596. reset_out:
  4597. /* Clean out command structure on command error out */
  4598. memset(&idiag, 0, sizeof(idiag));
  4599. return nbytes;
  4600. error_out:
  4601. /* Clean out command structure on command error out */
  4602. memset(&idiag, 0, sizeof(idiag));
  4603. return -EINVAL;
  4604. }
  4605. /**
  4606. * lpfc_idiag_extacc_avail_get - get the available extents information
  4607. * @phba: pointer to lpfc hba data structure.
  4608. * @pbuffer: pointer to internal buffer.
  4609. * @len: length into the internal buffer data has been copied.
  4610. *
  4611. * Description:
  4612. * This routine is to get the available extent information.
  4613. *
  4614. * Returns:
  4615. * overall length of the data read into the internal buffer.
  4616. **/
  4617. static int
  4618. lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
  4619. {
  4620. uint16_t ext_cnt = 0, ext_size = 0;
  4621. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4622. "\nAvailable Extents Information:\n");
  4623. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4624. "\tPort Available VPI extents: ");
  4625. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
  4626. &ext_cnt, &ext_size);
  4627. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4628. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4629. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4630. "\tPort Available VFI extents: ");
  4631. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
  4632. &ext_cnt, &ext_size);
  4633. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4634. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4635. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4636. "\tPort Available RPI extents: ");
  4637. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
  4638. &ext_cnt, &ext_size);
  4639. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4640. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4641. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4642. "\tPort Available XRI extents: ");
  4643. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
  4644. &ext_cnt, &ext_size);
  4645. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4646. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  4647. return len;
  4648. }
  4649. /**
  4650. * lpfc_idiag_extacc_alloc_get - get the allocated extents information
  4651. * @phba: pointer to lpfc hba data structure.
  4652. * @pbuffer: pointer to internal buffer.
  4653. * @len: length into the internal buffer data has been copied.
  4654. *
  4655. * Description:
  4656. * This routine is to get the allocated extent information.
  4657. *
  4658. * Returns:
  4659. * overall length of the data read into the internal buffer.
  4660. **/
  4661. static int
  4662. lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
  4663. {
  4664. uint16_t ext_cnt, ext_size;
  4665. int rc;
  4666. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4667. "\nAllocated Extents Information:\n");
  4668. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4669. "\tHost Allocated VPI extents: ");
  4670. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
  4671. &ext_cnt, &ext_size);
  4672. if (!rc)
  4673. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4674. "Port %d Extent %3d, Size %3d\n",
  4675. phba->brd_no, ext_cnt, ext_size);
  4676. else
  4677. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4678. "N/A\n");
  4679. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4680. "\tHost Allocated VFI extents: ");
  4681. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
  4682. &ext_cnt, &ext_size);
  4683. if (!rc)
  4684. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4685. "Port %d Extent %3d, Size %3d\n",
  4686. phba->brd_no, ext_cnt, ext_size);
  4687. else
  4688. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4689. "N/A\n");
  4690. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4691. "\tHost Allocated RPI extents: ");
  4692. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
  4693. &ext_cnt, &ext_size);
  4694. if (!rc)
  4695. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4696. "Port %d Extent %3d, Size %3d\n",
  4697. phba->brd_no, ext_cnt, ext_size);
  4698. else
  4699. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4700. "N/A\n");
  4701. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4702. "\tHost Allocated XRI extents: ");
  4703. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
  4704. &ext_cnt, &ext_size);
  4705. if (!rc)
  4706. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4707. "Port %d Extent %3d, Size %3d\n",
  4708. phba->brd_no, ext_cnt, ext_size);
  4709. else
  4710. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4711. "N/A\n");
  4712. return len;
  4713. }
  4714. /**
  4715. * lpfc_idiag_extacc_drivr_get - get driver extent information
  4716. * @phba: pointer to lpfc hba data structure.
  4717. * @pbuffer: pointer to internal buffer.
  4718. * @len: length into the internal buffer data has been copied.
  4719. *
  4720. * Description:
  4721. * This routine is to get the driver extent information.
  4722. *
  4723. * Returns:
  4724. * overall length of the data read into the internal buffer.
  4725. **/
  4726. static int
  4727. lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
  4728. {
  4729. struct lpfc_rsrc_blks *rsrc_blks;
  4730. int index;
  4731. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4732. "\nDriver Extents Information:\n");
  4733. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4734. "\tVPI extents:\n");
  4735. index = 0;
  4736. list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
  4737. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4738. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4739. index, rsrc_blks->rsrc_start,
  4740. rsrc_blks->rsrc_size);
  4741. index++;
  4742. }
  4743. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4744. "\tVFI extents:\n");
  4745. index = 0;
  4746. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
  4747. list) {
  4748. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4749. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4750. index, rsrc_blks->rsrc_start,
  4751. rsrc_blks->rsrc_size);
  4752. index++;
  4753. }
  4754. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4755. "\tRPI extents:\n");
  4756. index = 0;
  4757. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
  4758. list) {
  4759. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4760. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4761. index, rsrc_blks->rsrc_start,
  4762. rsrc_blks->rsrc_size);
  4763. index++;
  4764. }
  4765. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4766. "\tXRI extents:\n");
  4767. index = 0;
  4768. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
  4769. list) {
  4770. len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  4771. "\t\tBlock %3d: Start %4d, Count %4d\n",
  4772. index, rsrc_blks->rsrc_start,
  4773. rsrc_blks->rsrc_size);
  4774. index++;
  4775. }
  4776. return len;
  4777. }
  4778. /**
  4779. * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
  4780. * @file: The file pointer to read from.
  4781. * @buf: The buffer to copy the user data from.
  4782. * @nbytes: The number of bytes to get.
  4783. * @ppos: The position in the file to start reading from.
  4784. *
  4785. * This routine get the debugfs idiag command struct from user space and then
  4786. * perform the syntax check for extent information access commands and sets
  4787. * up the necessary states in the idiag command struct accordingly.
  4788. *
  4789. * It returns the @nbytges passing in from debugfs user space when successful.
  4790. * In case of error conditions, it returns proper error code back to the user
  4791. * space.
  4792. **/
  4793. static ssize_t
  4794. lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
  4795. size_t nbytes, loff_t *ppos)
  4796. {
  4797. struct lpfc_debug *debug = file->private_data;
  4798. uint32_t ext_map;
  4799. int rc;
  4800. /* This is a user write operation */
  4801. debug->op = LPFC_IDIAG_OP_WR;
  4802. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  4803. if (rc < 0)
  4804. return rc;
  4805. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  4806. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  4807. goto error_out;
  4808. if (rc != LPFC_EXT_ACC_CMD_ARG)
  4809. goto error_out;
  4810. if (!(ext_map & LPFC_EXT_ACC_ALL))
  4811. goto error_out;
  4812. return nbytes;
  4813. error_out:
  4814. /* Clean out command structure on command error out */
  4815. memset(&idiag, 0, sizeof(idiag));
  4816. return -EINVAL;
  4817. }
  4818. /**
  4819. * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
  4820. * @file: The file pointer to read from.
  4821. * @buf: The buffer to copy the data to.
  4822. * @nbytes: The number of bytes to read.
  4823. * @ppos: The position in the file to start reading from.
  4824. *
  4825. * Description:
  4826. * This routine reads data from the proper extent information according to
  4827. * the idiag command, and copies to user @buf.
  4828. *
  4829. * Returns:
  4830. * This function returns the amount of data that was read (this could be less
  4831. * than @nbytes if the end of the file was reached) or a negative error value.
  4832. **/
  4833. static ssize_t
  4834. lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
  4835. loff_t *ppos)
  4836. {
  4837. struct lpfc_debug *debug = file->private_data;
  4838. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4839. char *pbuffer;
  4840. uint32_t ext_map;
  4841. int len = 0;
  4842. /* This is a user read operation */
  4843. debug->op = LPFC_IDIAG_OP_RD;
  4844. if (!debug->buffer)
  4845. debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
  4846. if (!debug->buffer)
  4847. return 0;
  4848. pbuffer = debug->buffer;
  4849. if (*ppos)
  4850. return 0;
  4851. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  4852. return 0;
  4853. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  4854. if (ext_map & LPFC_EXT_ACC_AVAIL)
  4855. len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
  4856. if (ext_map & LPFC_EXT_ACC_ALLOC)
  4857. len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
  4858. if (ext_map & LPFC_EXT_ACC_DRIVR)
  4859. len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
  4860. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  4861. }
  4862. static int
  4863. lpfc_cgn_buffer_open(struct inode *inode, struct file *file)
  4864. {
  4865. struct lpfc_debug *debug;
  4866. int rc = -ENOMEM;
  4867. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  4868. if (!debug)
  4869. goto out;
  4870. debug->buffer = vmalloc(LPFC_CGN_BUF_SIZE);
  4871. if (!debug->buffer) {
  4872. kfree(debug);
  4873. goto out;
  4874. }
  4875. debug->i_private = inode->i_private;
  4876. file->private_data = debug;
  4877. rc = 0;
  4878. out:
  4879. return rc;
  4880. }
  4881. static ssize_t
  4882. lpfc_cgn_buffer_read(struct file *file, char __user *buf, size_t nbytes,
  4883. loff_t *ppos)
  4884. {
  4885. struct lpfc_debug *debug = file->private_data;
  4886. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4887. char *buffer = debug->buffer;
  4888. uint32_t *ptr;
  4889. int cnt, len = 0;
  4890. if (!phba->sli4_hba.pc_sli4_params.mi_ver || !phba->cgn_i) {
  4891. len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
  4892. "Congestion Mgmt is not supported\n");
  4893. goto out;
  4894. }
  4895. ptr = (uint32_t *)phba->cgn_i->virt;
  4896. len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
  4897. "Congestion Buffer Header\n");
  4898. /* Dump the first 32 bytes */
  4899. cnt = 32;
  4900. len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
  4901. "000: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  4902. *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
  4903. *(ptr + 4), *(ptr + 5), *(ptr + 6), *(ptr + 7));
  4904. ptr += 8;
  4905. len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
  4906. "Congestion Buffer Data\n");
  4907. while (cnt < sizeof(struct lpfc_cgn_info)) {
  4908. if (len > (LPFC_CGN_BUF_SIZE - LPFC_DEBUG_OUT_LINE_SZ)) {
  4909. len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
  4910. "Truncated . . .\n");
  4911. goto out;
  4912. }
  4913. len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
  4914. "%03x: %08x %08x %08x %08x "
  4915. "%08x %08x %08x %08x\n",
  4916. cnt, *ptr, *(ptr + 1), *(ptr + 2),
  4917. *(ptr + 3), *(ptr + 4), *(ptr + 5),
  4918. *(ptr + 6), *(ptr + 7));
  4919. cnt += 32;
  4920. ptr += 8;
  4921. }
  4922. if (len > (LPFC_CGN_BUF_SIZE - LPFC_DEBUG_OUT_LINE_SZ)) {
  4923. len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
  4924. "Truncated . . .\n");
  4925. goto out;
  4926. }
  4927. len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
  4928. "Parameter Data\n");
  4929. ptr = (uint32_t *)&phba->cgn_p;
  4930. len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
  4931. "%08x %08x %08x %08x\n",
  4932. *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3));
  4933. out:
  4934. return simple_read_from_buffer(buf, nbytes, ppos, buffer, len);
  4935. }
  4936. static int
  4937. lpfc_cgn_buffer_release(struct inode *inode, struct file *file)
  4938. {
  4939. struct lpfc_debug *debug = file->private_data;
  4940. vfree(debug->buffer);
  4941. kfree(debug);
  4942. return 0;
  4943. }
  4944. static int
  4945. lpfc_rx_monitor_open(struct inode *inode, struct file *file)
  4946. {
  4947. struct lpfc_rx_monitor_debug *debug;
  4948. int rc = -ENOMEM;
  4949. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  4950. if (!debug)
  4951. goto out;
  4952. debug->buffer = vmalloc(MAX_DEBUGFS_RX_INFO_SIZE);
  4953. if (!debug->buffer) {
  4954. kfree(debug);
  4955. goto out;
  4956. }
  4957. debug->i_private = inode->i_private;
  4958. file->private_data = debug;
  4959. rc = 0;
  4960. out:
  4961. return rc;
  4962. }
  4963. static ssize_t
  4964. lpfc_rx_monitor_read(struct file *file, char __user *buf, size_t nbytes,
  4965. loff_t *ppos)
  4966. {
  4967. struct lpfc_rx_monitor_debug *debug = file->private_data;
  4968. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  4969. char *buffer = debug->buffer;
  4970. if (!phba->rx_monitor) {
  4971. scnprintf(buffer, MAX_DEBUGFS_RX_INFO_SIZE,
  4972. "Rx Monitor Info is empty.\n");
  4973. } else {
  4974. lpfc_rx_monitor_report(phba, phba->rx_monitor, buffer,
  4975. MAX_DEBUGFS_RX_INFO_SIZE,
  4976. LPFC_MAX_RXMONITOR_ENTRY);
  4977. }
  4978. return simple_read_from_buffer(buf, nbytes, ppos, buffer,
  4979. strlen(buffer));
  4980. }
  4981. static int
  4982. lpfc_rx_monitor_release(struct inode *inode, struct file *file)
  4983. {
  4984. struct lpfc_rx_monitor_debug *debug = file->private_data;
  4985. vfree(debug->buffer);
  4986. kfree(debug);
  4987. return 0;
  4988. }
  4989. #undef lpfc_debugfs_op_disc_trc
  4990. static const struct file_operations lpfc_debugfs_op_disc_trc = {
  4991. .owner = THIS_MODULE,
  4992. .open = lpfc_debugfs_disc_trc_open,
  4993. .llseek = lpfc_debugfs_lseek,
  4994. .read = lpfc_debugfs_read,
  4995. .release = lpfc_debugfs_release,
  4996. };
  4997. #undef lpfc_debugfs_op_nodelist
  4998. static const struct file_operations lpfc_debugfs_op_nodelist = {
  4999. .owner = THIS_MODULE,
  5000. .open = lpfc_debugfs_nodelist_open,
  5001. .llseek = lpfc_debugfs_lseek,
  5002. .read = lpfc_debugfs_read,
  5003. .release = lpfc_debugfs_release,
  5004. };
  5005. #undef lpfc_debugfs_op_multixripools
  5006. static const struct file_operations lpfc_debugfs_op_multixripools = {
  5007. .owner = THIS_MODULE,
  5008. .open = lpfc_debugfs_multixripools_open,
  5009. .llseek = lpfc_debugfs_lseek,
  5010. .read = lpfc_debugfs_read,
  5011. .write = lpfc_debugfs_multixripools_write,
  5012. .release = lpfc_debugfs_release,
  5013. };
  5014. #undef lpfc_debugfs_op_hbqinfo
  5015. static const struct file_operations lpfc_debugfs_op_hbqinfo = {
  5016. .owner = THIS_MODULE,
  5017. .open = lpfc_debugfs_hbqinfo_open,
  5018. .llseek = lpfc_debugfs_lseek,
  5019. .read = lpfc_debugfs_read,
  5020. .release = lpfc_debugfs_release,
  5021. };
  5022. #ifdef LPFC_HDWQ_LOCK_STAT
  5023. #undef lpfc_debugfs_op_lockstat
  5024. static const struct file_operations lpfc_debugfs_op_lockstat = {
  5025. .owner = THIS_MODULE,
  5026. .open = lpfc_debugfs_lockstat_open,
  5027. .llseek = lpfc_debugfs_lseek,
  5028. .read = lpfc_debugfs_read,
  5029. .write = lpfc_debugfs_lockstat_write,
  5030. .release = lpfc_debugfs_release,
  5031. };
  5032. #endif
  5033. #undef lpfc_debugfs_ras_log
  5034. static const struct file_operations lpfc_debugfs_ras_log = {
  5035. .owner = THIS_MODULE,
  5036. .open = lpfc_debugfs_ras_log_open,
  5037. .llseek = lpfc_debugfs_lseek,
  5038. .read = lpfc_debugfs_read,
  5039. .release = lpfc_debugfs_ras_log_release,
  5040. };
  5041. #undef lpfc_debugfs_op_dumpHBASlim
  5042. static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  5043. .owner = THIS_MODULE,
  5044. .open = lpfc_debugfs_dumpHBASlim_open,
  5045. .llseek = lpfc_debugfs_lseek,
  5046. .read = lpfc_debugfs_read,
  5047. .release = lpfc_debugfs_release,
  5048. };
  5049. #undef lpfc_debugfs_op_dumpHostSlim
  5050. static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  5051. .owner = THIS_MODULE,
  5052. .open = lpfc_debugfs_dumpHostSlim_open,
  5053. .llseek = lpfc_debugfs_lseek,
  5054. .read = lpfc_debugfs_read,
  5055. .release = lpfc_debugfs_release,
  5056. };
  5057. #undef lpfc_debugfs_op_nvmestat
  5058. static const struct file_operations lpfc_debugfs_op_nvmestat = {
  5059. .owner = THIS_MODULE,
  5060. .open = lpfc_debugfs_nvmestat_open,
  5061. .llseek = lpfc_debugfs_lseek,
  5062. .read = lpfc_debugfs_read,
  5063. .write = lpfc_debugfs_nvmestat_write,
  5064. .release = lpfc_debugfs_release,
  5065. };
  5066. #undef lpfc_debugfs_op_scsistat
  5067. static const struct file_operations lpfc_debugfs_op_scsistat = {
  5068. .owner = THIS_MODULE,
  5069. .open = lpfc_debugfs_scsistat_open,
  5070. .llseek = lpfc_debugfs_lseek,
  5071. .read = lpfc_debugfs_read,
  5072. .write = lpfc_debugfs_scsistat_write,
  5073. .release = lpfc_debugfs_release,
  5074. };
  5075. #undef lpfc_debugfs_op_ioktime
  5076. static const struct file_operations lpfc_debugfs_op_ioktime = {
  5077. .owner = THIS_MODULE,
  5078. .open = lpfc_debugfs_ioktime_open,
  5079. .llseek = lpfc_debugfs_lseek,
  5080. .read = lpfc_debugfs_read,
  5081. .write = lpfc_debugfs_ioktime_write,
  5082. .release = lpfc_debugfs_release,
  5083. };
  5084. #undef lpfc_debugfs_op_nvmeio_trc
  5085. static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
  5086. .owner = THIS_MODULE,
  5087. .open = lpfc_debugfs_nvmeio_trc_open,
  5088. .llseek = lpfc_debugfs_lseek,
  5089. .read = lpfc_debugfs_read,
  5090. .write = lpfc_debugfs_nvmeio_trc_write,
  5091. .release = lpfc_debugfs_release,
  5092. };
  5093. #undef lpfc_debugfs_op_hdwqstat
  5094. static const struct file_operations lpfc_debugfs_op_hdwqstat = {
  5095. .owner = THIS_MODULE,
  5096. .open = lpfc_debugfs_hdwqstat_open,
  5097. .llseek = lpfc_debugfs_lseek,
  5098. .read = lpfc_debugfs_read,
  5099. .write = lpfc_debugfs_hdwqstat_write,
  5100. .release = lpfc_debugfs_release,
  5101. };
  5102. #undef lpfc_debugfs_op_dif_err
  5103. static const struct file_operations lpfc_debugfs_op_dif_err = {
  5104. .owner = THIS_MODULE,
  5105. .open = simple_open,
  5106. .llseek = lpfc_debugfs_lseek,
  5107. .read = lpfc_debugfs_dif_err_read,
  5108. .write = lpfc_debugfs_dif_err_write,
  5109. .release = lpfc_debugfs_dif_err_release,
  5110. };
  5111. #undef lpfc_debugfs_op_slow_ring_trc
  5112. static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  5113. .owner = THIS_MODULE,
  5114. .open = lpfc_debugfs_slow_ring_trc_open,
  5115. .llseek = lpfc_debugfs_lseek,
  5116. .read = lpfc_debugfs_read,
  5117. .release = lpfc_debugfs_release,
  5118. };
  5119. static struct dentry *lpfc_debugfs_root = NULL;
  5120. static atomic_t lpfc_debugfs_hba_count;
  5121. /*
  5122. * File operations for the iDiag debugfs
  5123. */
  5124. #undef lpfc_idiag_op_pciCfg
  5125. static const struct file_operations lpfc_idiag_op_pciCfg = {
  5126. .owner = THIS_MODULE,
  5127. .open = lpfc_idiag_open,
  5128. .llseek = lpfc_debugfs_lseek,
  5129. .read = lpfc_idiag_pcicfg_read,
  5130. .write = lpfc_idiag_pcicfg_write,
  5131. .release = lpfc_idiag_cmd_release,
  5132. };
  5133. #undef lpfc_idiag_op_barAcc
  5134. static const struct file_operations lpfc_idiag_op_barAcc = {
  5135. .owner = THIS_MODULE,
  5136. .open = lpfc_idiag_open,
  5137. .llseek = lpfc_debugfs_lseek,
  5138. .read = lpfc_idiag_baracc_read,
  5139. .write = lpfc_idiag_baracc_write,
  5140. .release = lpfc_idiag_cmd_release,
  5141. };
  5142. #undef lpfc_idiag_op_queInfo
  5143. static const struct file_operations lpfc_idiag_op_queInfo = {
  5144. .owner = THIS_MODULE,
  5145. .open = lpfc_idiag_open,
  5146. .read = lpfc_idiag_queinfo_read,
  5147. .release = lpfc_idiag_release,
  5148. };
  5149. #undef lpfc_idiag_op_queAcc
  5150. static const struct file_operations lpfc_idiag_op_queAcc = {
  5151. .owner = THIS_MODULE,
  5152. .open = lpfc_idiag_open,
  5153. .llseek = lpfc_debugfs_lseek,
  5154. .read = lpfc_idiag_queacc_read,
  5155. .write = lpfc_idiag_queacc_write,
  5156. .release = lpfc_idiag_cmd_release,
  5157. };
  5158. #undef lpfc_idiag_op_drbAcc
  5159. static const struct file_operations lpfc_idiag_op_drbAcc = {
  5160. .owner = THIS_MODULE,
  5161. .open = lpfc_idiag_open,
  5162. .llseek = lpfc_debugfs_lseek,
  5163. .read = lpfc_idiag_drbacc_read,
  5164. .write = lpfc_idiag_drbacc_write,
  5165. .release = lpfc_idiag_cmd_release,
  5166. };
  5167. #undef lpfc_idiag_op_ctlAcc
  5168. static const struct file_operations lpfc_idiag_op_ctlAcc = {
  5169. .owner = THIS_MODULE,
  5170. .open = lpfc_idiag_open,
  5171. .llseek = lpfc_debugfs_lseek,
  5172. .read = lpfc_idiag_ctlacc_read,
  5173. .write = lpfc_idiag_ctlacc_write,
  5174. .release = lpfc_idiag_cmd_release,
  5175. };
  5176. #undef lpfc_idiag_op_mbxAcc
  5177. static const struct file_operations lpfc_idiag_op_mbxAcc = {
  5178. .owner = THIS_MODULE,
  5179. .open = lpfc_idiag_open,
  5180. .llseek = lpfc_debugfs_lseek,
  5181. .read = lpfc_idiag_mbxacc_read,
  5182. .write = lpfc_idiag_mbxacc_write,
  5183. .release = lpfc_idiag_cmd_release,
  5184. };
  5185. #undef lpfc_idiag_op_extAcc
  5186. static const struct file_operations lpfc_idiag_op_extAcc = {
  5187. .owner = THIS_MODULE,
  5188. .open = lpfc_idiag_open,
  5189. .llseek = lpfc_debugfs_lseek,
  5190. .read = lpfc_idiag_extacc_read,
  5191. .write = lpfc_idiag_extacc_write,
  5192. .release = lpfc_idiag_cmd_release,
  5193. };
  5194. #undef lpfc_cgn_buffer_op
  5195. static const struct file_operations lpfc_cgn_buffer_op = {
  5196. .owner = THIS_MODULE,
  5197. .open = lpfc_cgn_buffer_open,
  5198. .llseek = lpfc_debugfs_lseek,
  5199. .read = lpfc_cgn_buffer_read,
  5200. .release = lpfc_cgn_buffer_release,
  5201. };
  5202. #undef lpfc_rx_monitor_op
  5203. static const struct file_operations lpfc_rx_monitor_op = {
  5204. .owner = THIS_MODULE,
  5205. .open = lpfc_rx_monitor_open,
  5206. .llseek = lpfc_debugfs_lseek,
  5207. .read = lpfc_rx_monitor_read,
  5208. .release = lpfc_rx_monitor_release,
  5209. };
  5210. #endif
  5211. /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
  5212. * @phba: Pointer to HBA context object.
  5213. * @dmabuf: Pointer to a DMA buffer descriptor.
  5214. *
  5215. * Description:
  5216. * This routine dump a bsg pass-through non-embedded mailbox command with
  5217. * external buffer.
  5218. **/
  5219. void
  5220. lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
  5221. enum mbox_type mbox_tp, enum dma_type dma_tp,
  5222. enum sta_type sta_tp,
  5223. struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
  5224. {
  5225. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  5226. uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
  5227. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  5228. int len = 0;
  5229. uint32_t do_dump = 0;
  5230. uint32_t *pword;
  5231. uint32_t i;
  5232. if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
  5233. return;
  5234. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  5235. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  5236. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  5237. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  5238. if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
  5239. (*mbx_dump_cnt == 0) ||
  5240. (*mbx_word_cnt == 0))
  5241. return;
  5242. if (*mbx_mbox_cmd != 0x9B)
  5243. return;
  5244. if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
  5245. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
  5246. do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
  5247. pr_err("\nRead mbox command (x%x), "
  5248. "nemb:0x%x, extbuf_cnt:%d:\n",
  5249. sta_tp, nemb_tp, ext_buf);
  5250. }
  5251. }
  5252. if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
  5253. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
  5254. do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
  5255. pr_err("\nRead mbox buffer (x%x), "
  5256. "nemb:0x%x, extbuf_seq:%d:\n",
  5257. sta_tp, nemb_tp, ext_buf);
  5258. }
  5259. }
  5260. if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
  5261. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
  5262. do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
  5263. pr_err("\nWrite mbox command (x%x), "
  5264. "nemb:0x%x, extbuf_cnt:%d:\n",
  5265. sta_tp, nemb_tp, ext_buf);
  5266. }
  5267. }
  5268. if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
  5269. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
  5270. do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
  5271. pr_err("\nWrite mbox buffer (x%x), "
  5272. "nemb:0x%x, extbuf_seq:%d:\n",
  5273. sta_tp, nemb_tp, ext_buf);
  5274. }
  5275. }
  5276. /* dump buffer content */
  5277. if (do_dump) {
  5278. pword = (uint32_t *)dmabuf->virt;
  5279. for (i = 0; i < *mbx_word_cnt; i++) {
  5280. if (!(i % 8)) {
  5281. if (i != 0)
  5282. pr_err("%s\n", line_buf);
  5283. len = 0;
  5284. len += scnprintf(line_buf+len,
  5285. LPFC_MBX_ACC_LBUF_SZ-len,
  5286. "%03d: ", i);
  5287. }
  5288. len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  5289. "%08x ", (uint32_t)*pword);
  5290. pword++;
  5291. }
  5292. if ((i - 1) % 8)
  5293. pr_err("%s\n", line_buf);
  5294. (*mbx_dump_cnt)--;
  5295. }
  5296. /* Clean out command structure on reaching dump count */
  5297. if (*mbx_dump_cnt == 0)
  5298. memset(&idiag, 0, sizeof(idiag));
  5299. return;
  5300. #endif
  5301. }
  5302. /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
  5303. * @phba: Pointer to HBA context object.
  5304. * @dmabuf: Pointer to a DMA buffer descriptor.
  5305. *
  5306. * Description:
  5307. * This routine dump a pass-through non-embedded mailbox command from issue
  5308. * mailbox command.
  5309. **/
  5310. void
  5311. lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
  5312. {
  5313. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  5314. uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
  5315. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  5316. int len = 0;
  5317. uint32_t *pword;
  5318. uint8_t *pbyte;
  5319. uint32_t i, j;
  5320. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
  5321. return;
  5322. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  5323. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  5324. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  5325. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  5326. if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
  5327. (*mbx_dump_cnt == 0) ||
  5328. (*mbx_word_cnt == 0))
  5329. return;
  5330. if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
  5331. (*mbx_mbox_cmd != pmbox->mbxCommand))
  5332. return;
  5333. /* dump buffer content */
  5334. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
  5335. pr_err("Mailbox command:0x%x dump by word:\n",
  5336. pmbox->mbxCommand);
  5337. pword = (uint32_t *)pmbox;
  5338. for (i = 0; i < *mbx_word_cnt; i++) {
  5339. if (!(i % 8)) {
  5340. if (i != 0)
  5341. pr_err("%s\n", line_buf);
  5342. len = 0;
  5343. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  5344. len += scnprintf(line_buf+len,
  5345. LPFC_MBX_ACC_LBUF_SZ-len,
  5346. "%03d: ", i);
  5347. }
  5348. len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  5349. "%08x ",
  5350. ((uint32_t)*pword) & 0xffffffff);
  5351. pword++;
  5352. }
  5353. if ((i - 1) % 8)
  5354. pr_err("%s\n", line_buf);
  5355. pr_err("\n");
  5356. }
  5357. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
  5358. pr_err("Mailbox command:0x%x dump by byte:\n",
  5359. pmbox->mbxCommand);
  5360. pbyte = (uint8_t *)pmbox;
  5361. for (i = 0; i < *mbx_word_cnt; i++) {
  5362. if (!(i % 8)) {
  5363. if (i != 0)
  5364. pr_err("%s\n", line_buf);
  5365. len = 0;
  5366. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  5367. len += scnprintf(line_buf+len,
  5368. LPFC_MBX_ACC_LBUF_SZ-len,
  5369. "%03d: ", i);
  5370. }
  5371. for (j = 0; j < 4; j++) {
  5372. len += scnprintf(line_buf+len,
  5373. LPFC_MBX_ACC_LBUF_SZ-len,
  5374. "%02x",
  5375. ((uint8_t)*pbyte) & 0xff);
  5376. pbyte++;
  5377. }
  5378. len += scnprintf(line_buf+len,
  5379. LPFC_MBX_ACC_LBUF_SZ-len, " ");
  5380. }
  5381. if ((i - 1) % 8)
  5382. pr_err("%s\n", line_buf);
  5383. pr_err("\n");
  5384. }
  5385. (*mbx_dump_cnt)--;
  5386. /* Clean out command structure on reaching dump count */
  5387. if (*mbx_dump_cnt == 0)
  5388. memset(&idiag, 0, sizeof(idiag));
  5389. return;
  5390. #endif
  5391. }
  5392. /**
  5393. * lpfc_debugfs_initialize - Initialize debugfs for a vport
  5394. * @vport: The vport pointer to initialize.
  5395. *
  5396. * Description:
  5397. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  5398. * If not already created, this routine will create the lpfc directory, and
  5399. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  5400. * also create each file used to access lpfc specific debugfs information.
  5401. **/
  5402. inline void
  5403. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  5404. {
  5405. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  5406. struct lpfc_hba *phba = vport->phba;
  5407. char name[64];
  5408. uint32_t num, i;
  5409. bool pport_setup = false;
  5410. if (!lpfc_debugfs_enable)
  5411. return;
  5412. /* Setup lpfc root directory */
  5413. if (!lpfc_debugfs_root) {
  5414. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  5415. atomic_set(&lpfc_debugfs_hba_count, 0);
  5416. }
  5417. if (!lpfc_debugfs_start_time)
  5418. lpfc_debugfs_start_time = jiffies;
  5419. /* Setup funcX directory for specific HBA PCI function */
  5420. snprintf(name, sizeof(name), "fn%d", phba->brd_no);
  5421. if (!phba->hba_debugfs_root) {
  5422. pport_setup = true;
  5423. phba->hba_debugfs_root =
  5424. debugfs_create_dir(name, lpfc_debugfs_root);
  5425. atomic_inc(&lpfc_debugfs_hba_count);
  5426. atomic_set(&phba->debugfs_vport_count, 0);
  5427. /* Multi-XRI pools */
  5428. snprintf(name, sizeof(name), "multixripools");
  5429. phba->debug_multixri_pools =
  5430. debugfs_create_file(name, S_IFREG | 0644,
  5431. phba->hba_debugfs_root,
  5432. phba,
  5433. &lpfc_debugfs_op_multixripools);
  5434. if (IS_ERR(phba->debug_multixri_pools)) {
  5435. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5436. "0527 Cannot create debugfs multixripools\n");
  5437. goto debug_failed;
  5438. }
  5439. /* Congestion Info Buffer */
  5440. scnprintf(name, sizeof(name), "cgn_buffer");
  5441. phba->debug_cgn_buffer =
  5442. debugfs_create_file(name, S_IFREG | 0644,
  5443. phba->hba_debugfs_root,
  5444. phba, &lpfc_cgn_buffer_op);
  5445. if (IS_ERR(phba->debug_cgn_buffer)) {
  5446. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5447. "6527 Cannot create debugfs "
  5448. "cgn_buffer\n");
  5449. goto debug_failed;
  5450. }
  5451. /* RX Monitor */
  5452. scnprintf(name, sizeof(name), "rx_monitor");
  5453. phba->debug_rx_monitor =
  5454. debugfs_create_file(name, S_IFREG | 0644,
  5455. phba->hba_debugfs_root,
  5456. phba, &lpfc_rx_monitor_op);
  5457. if (IS_ERR(phba->debug_rx_monitor)) {
  5458. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5459. "6528 Cannot create debugfs "
  5460. "rx_monitor\n");
  5461. goto debug_failed;
  5462. }
  5463. /* RAS log */
  5464. snprintf(name, sizeof(name), "ras_log");
  5465. phba->debug_ras_log =
  5466. debugfs_create_file(name, 0644,
  5467. phba->hba_debugfs_root,
  5468. phba, &lpfc_debugfs_ras_log);
  5469. if (IS_ERR(phba->debug_ras_log)) {
  5470. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5471. "6148 Cannot create debugfs"
  5472. " ras_log\n");
  5473. goto debug_failed;
  5474. }
  5475. /* Setup hbqinfo */
  5476. snprintf(name, sizeof(name), "hbqinfo");
  5477. phba->debug_hbqinfo =
  5478. debugfs_create_file(name, S_IFREG | 0644,
  5479. phba->hba_debugfs_root,
  5480. phba, &lpfc_debugfs_op_hbqinfo);
  5481. #ifdef LPFC_HDWQ_LOCK_STAT
  5482. /* Setup lockstat */
  5483. snprintf(name, sizeof(name), "lockstat");
  5484. phba->debug_lockstat =
  5485. debugfs_create_file(name, S_IFREG | 0644,
  5486. phba->hba_debugfs_root,
  5487. phba, &lpfc_debugfs_op_lockstat);
  5488. if (IS_ERR(phba->debug_lockstat)) {
  5489. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5490. "4610 Can't create debugfs lockstat\n");
  5491. goto debug_failed;
  5492. }
  5493. #endif
  5494. /* Setup dumpHBASlim */
  5495. if (phba->sli_rev < LPFC_SLI_REV4) {
  5496. snprintf(name, sizeof(name), "dumpHBASlim");
  5497. phba->debug_dumpHBASlim =
  5498. debugfs_create_file(name,
  5499. S_IFREG|S_IRUGO|S_IWUSR,
  5500. phba->hba_debugfs_root,
  5501. phba, &lpfc_debugfs_op_dumpHBASlim);
  5502. } else
  5503. phba->debug_dumpHBASlim = NULL;
  5504. /* Setup dumpHostSlim */
  5505. if (phba->sli_rev < LPFC_SLI_REV4) {
  5506. snprintf(name, sizeof(name), "dumpHostSlim");
  5507. phba->debug_dumpHostSlim =
  5508. debugfs_create_file(name,
  5509. S_IFREG|S_IRUGO|S_IWUSR,
  5510. phba->hba_debugfs_root,
  5511. phba, &lpfc_debugfs_op_dumpHostSlim);
  5512. } else
  5513. phba->debug_dumpHostSlim = NULL;
  5514. /* Setup DIF Error Injections */
  5515. snprintf(name, sizeof(name), "InjErrLBA");
  5516. phba->debug_InjErrLBA =
  5517. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5518. phba->hba_debugfs_root,
  5519. phba, &lpfc_debugfs_op_dif_err);
  5520. phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
  5521. snprintf(name, sizeof(name), "InjErrNPortID");
  5522. phba->debug_InjErrNPortID =
  5523. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5524. phba->hba_debugfs_root,
  5525. phba, &lpfc_debugfs_op_dif_err);
  5526. snprintf(name, sizeof(name), "InjErrWWPN");
  5527. phba->debug_InjErrWWPN =
  5528. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5529. phba->hba_debugfs_root,
  5530. phba, &lpfc_debugfs_op_dif_err);
  5531. snprintf(name, sizeof(name), "writeGuardInjErr");
  5532. phba->debug_writeGuard =
  5533. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5534. phba->hba_debugfs_root,
  5535. phba, &lpfc_debugfs_op_dif_err);
  5536. snprintf(name, sizeof(name), "writeAppInjErr");
  5537. phba->debug_writeApp =
  5538. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5539. phba->hba_debugfs_root,
  5540. phba, &lpfc_debugfs_op_dif_err);
  5541. snprintf(name, sizeof(name), "writeRefInjErr");
  5542. phba->debug_writeRef =
  5543. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5544. phba->hba_debugfs_root,
  5545. phba, &lpfc_debugfs_op_dif_err);
  5546. snprintf(name, sizeof(name), "readGuardInjErr");
  5547. phba->debug_readGuard =
  5548. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5549. phba->hba_debugfs_root,
  5550. phba, &lpfc_debugfs_op_dif_err);
  5551. snprintf(name, sizeof(name), "readAppInjErr");
  5552. phba->debug_readApp =
  5553. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5554. phba->hba_debugfs_root,
  5555. phba, &lpfc_debugfs_op_dif_err);
  5556. snprintf(name, sizeof(name), "readRefInjErr");
  5557. phba->debug_readRef =
  5558. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5559. phba->hba_debugfs_root,
  5560. phba, &lpfc_debugfs_op_dif_err);
  5561. /* Setup slow ring trace */
  5562. if (lpfc_debugfs_max_slow_ring_trc) {
  5563. num = lpfc_debugfs_max_slow_ring_trc - 1;
  5564. if (num & lpfc_debugfs_max_slow_ring_trc) {
  5565. /* Change to be a power of 2 */
  5566. num = lpfc_debugfs_max_slow_ring_trc;
  5567. i = 0;
  5568. while (num > 1) {
  5569. num = num >> 1;
  5570. i++;
  5571. }
  5572. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  5573. pr_err("lpfc_debugfs_max_disc_trc changed to "
  5574. "%d\n", lpfc_debugfs_max_disc_trc);
  5575. }
  5576. }
  5577. snprintf(name, sizeof(name), "slow_ring_trace");
  5578. phba->debug_slow_ring_trc =
  5579. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5580. phba->hba_debugfs_root,
  5581. phba, &lpfc_debugfs_op_slow_ring_trc);
  5582. if (!phba->slow_ring_trc) {
  5583. phba->slow_ring_trc = kcalloc(
  5584. lpfc_debugfs_max_slow_ring_trc,
  5585. sizeof(struct lpfc_debugfs_trc),
  5586. GFP_KERNEL);
  5587. if (!phba->slow_ring_trc) {
  5588. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5589. "0416 Cannot create debugfs "
  5590. "slow_ring buffer\n");
  5591. goto debug_failed;
  5592. }
  5593. atomic_set(&phba->slow_ring_trc_cnt, 0);
  5594. }
  5595. snprintf(name, sizeof(name), "nvmeio_trc");
  5596. phba->debug_nvmeio_trc =
  5597. debugfs_create_file(name, 0644,
  5598. phba->hba_debugfs_root,
  5599. phba, &lpfc_debugfs_op_nvmeio_trc);
  5600. atomic_set(&phba->nvmeio_trc_cnt, 0);
  5601. if (lpfc_debugfs_max_nvmeio_trc) {
  5602. num = lpfc_debugfs_max_nvmeio_trc - 1;
  5603. if (num & lpfc_debugfs_max_disc_trc) {
  5604. /* Change to be a power of 2 */
  5605. num = lpfc_debugfs_max_nvmeio_trc;
  5606. i = 0;
  5607. while (num > 1) {
  5608. num = num >> 1;
  5609. i++;
  5610. }
  5611. lpfc_debugfs_max_nvmeio_trc = (1 << i);
  5612. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5613. "0575 lpfc_debugfs_max_nvmeio_trc "
  5614. "changed to %d\n",
  5615. lpfc_debugfs_max_nvmeio_trc);
  5616. }
  5617. phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
  5618. /* Allocate trace buffer and initialize */
  5619. phba->nvmeio_trc = kzalloc(
  5620. (sizeof(struct lpfc_debugfs_nvmeio_trc) *
  5621. phba->nvmeio_trc_size), GFP_KERNEL);
  5622. if (!phba->nvmeio_trc) {
  5623. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5624. "0576 Cannot create debugfs "
  5625. "nvmeio_trc buffer\n");
  5626. goto nvmeio_off;
  5627. }
  5628. phba->nvmeio_trc_on = 1;
  5629. phba->nvmeio_trc_output_idx = 0;
  5630. phba->nvmeio_trc = NULL;
  5631. } else {
  5632. nvmeio_off:
  5633. phba->nvmeio_trc_size = 0;
  5634. phba->nvmeio_trc_on = 0;
  5635. phba->nvmeio_trc_output_idx = 0;
  5636. phba->nvmeio_trc = NULL;
  5637. }
  5638. }
  5639. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  5640. if (!vport->vport_debugfs_root) {
  5641. vport->vport_debugfs_root =
  5642. debugfs_create_dir(name, phba->hba_debugfs_root);
  5643. atomic_inc(&phba->debugfs_vport_count);
  5644. }
  5645. if (lpfc_debugfs_max_disc_trc) {
  5646. num = lpfc_debugfs_max_disc_trc - 1;
  5647. if (num & lpfc_debugfs_max_disc_trc) {
  5648. /* Change to be a power of 2 */
  5649. num = lpfc_debugfs_max_disc_trc;
  5650. i = 0;
  5651. while (num > 1) {
  5652. num = num >> 1;
  5653. i++;
  5654. }
  5655. lpfc_debugfs_max_disc_trc = (1 << i);
  5656. pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
  5657. lpfc_debugfs_max_disc_trc);
  5658. }
  5659. }
  5660. vport->disc_trc = kzalloc(
  5661. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  5662. GFP_KERNEL);
  5663. if (!vport->disc_trc) {
  5664. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5665. "0418 Cannot create debugfs disc trace "
  5666. "buffer\n");
  5667. goto debug_failed;
  5668. }
  5669. atomic_set(&vport->disc_trc_cnt, 0);
  5670. snprintf(name, sizeof(name), "discovery_trace");
  5671. vport->debug_disc_trc =
  5672. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5673. vport->vport_debugfs_root,
  5674. vport, &lpfc_debugfs_op_disc_trc);
  5675. snprintf(name, sizeof(name), "nodelist");
  5676. vport->debug_nodelist =
  5677. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5678. vport->vport_debugfs_root,
  5679. vport, &lpfc_debugfs_op_nodelist);
  5680. snprintf(name, sizeof(name), "nvmestat");
  5681. vport->debug_nvmestat =
  5682. debugfs_create_file(name, 0644,
  5683. vport->vport_debugfs_root,
  5684. vport, &lpfc_debugfs_op_nvmestat);
  5685. snprintf(name, sizeof(name), "scsistat");
  5686. vport->debug_scsistat =
  5687. debugfs_create_file(name, 0644,
  5688. vport->vport_debugfs_root,
  5689. vport, &lpfc_debugfs_op_scsistat);
  5690. if (IS_ERR(vport->debug_scsistat)) {
  5691. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5692. "4611 Cannot create debugfs scsistat\n");
  5693. goto debug_failed;
  5694. }
  5695. snprintf(name, sizeof(name), "ioktime");
  5696. vport->debug_ioktime =
  5697. debugfs_create_file(name, 0644,
  5698. vport->vport_debugfs_root,
  5699. vport, &lpfc_debugfs_op_ioktime);
  5700. if (IS_ERR(vport->debug_ioktime)) {
  5701. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  5702. "0815 Cannot create debugfs ioktime\n");
  5703. goto debug_failed;
  5704. }
  5705. snprintf(name, sizeof(name), "hdwqstat");
  5706. vport->debug_hdwqstat =
  5707. debugfs_create_file(name, 0644,
  5708. vport->vport_debugfs_root,
  5709. vport, &lpfc_debugfs_op_hdwqstat);
  5710. /*
  5711. * The following section is for additional directories/files for the
  5712. * physical port.
  5713. */
  5714. if (!pport_setup)
  5715. goto debug_failed;
  5716. /*
  5717. * iDiag debugfs root entry points for SLI4 device only
  5718. */
  5719. if (phba->sli_rev < LPFC_SLI_REV4)
  5720. goto debug_failed;
  5721. snprintf(name, sizeof(name), "iDiag");
  5722. if (!phba->idiag_root) {
  5723. phba->idiag_root =
  5724. debugfs_create_dir(name, phba->hba_debugfs_root);
  5725. /* Initialize iDiag data structure */
  5726. memset(&idiag, 0, sizeof(idiag));
  5727. }
  5728. /* iDiag read PCI config space */
  5729. snprintf(name, sizeof(name), "pciCfg");
  5730. if (!phba->idiag_pci_cfg) {
  5731. phba->idiag_pci_cfg =
  5732. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5733. phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
  5734. idiag.offset.last_rd = 0;
  5735. }
  5736. /* iDiag PCI BAR access */
  5737. snprintf(name, sizeof(name), "barAcc");
  5738. if (!phba->idiag_bar_acc) {
  5739. phba->idiag_bar_acc =
  5740. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5741. phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
  5742. idiag.offset.last_rd = 0;
  5743. }
  5744. /* iDiag get PCI function queue information */
  5745. snprintf(name, sizeof(name), "queInfo");
  5746. if (!phba->idiag_que_info) {
  5747. phba->idiag_que_info =
  5748. debugfs_create_file(name, S_IFREG|S_IRUGO,
  5749. phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
  5750. }
  5751. /* iDiag access PCI function queue */
  5752. snprintf(name, sizeof(name), "queAcc");
  5753. if (!phba->idiag_que_acc) {
  5754. phba->idiag_que_acc =
  5755. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5756. phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
  5757. }
  5758. /* iDiag access PCI function doorbell registers */
  5759. snprintf(name, sizeof(name), "drbAcc");
  5760. if (!phba->idiag_drb_acc) {
  5761. phba->idiag_drb_acc =
  5762. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5763. phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
  5764. }
  5765. /* iDiag access PCI function control registers */
  5766. snprintf(name, sizeof(name), "ctlAcc");
  5767. if (!phba->idiag_ctl_acc) {
  5768. phba->idiag_ctl_acc =
  5769. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5770. phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
  5771. }
  5772. /* iDiag access mbox commands */
  5773. snprintf(name, sizeof(name), "mbxAcc");
  5774. if (!phba->idiag_mbx_acc) {
  5775. phba->idiag_mbx_acc =
  5776. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  5777. phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
  5778. }
  5779. /* iDiag extents access commands */
  5780. if (phba->sli4_hba.extents_in_use) {
  5781. snprintf(name, sizeof(name), "extAcc");
  5782. if (!phba->idiag_ext_acc) {
  5783. phba->idiag_ext_acc =
  5784. debugfs_create_file(name,
  5785. S_IFREG|S_IRUGO|S_IWUSR,
  5786. phba->idiag_root, phba,
  5787. &lpfc_idiag_op_extAcc);
  5788. }
  5789. }
  5790. debug_failed:
  5791. return;
  5792. #endif
  5793. }
  5794. /**
  5795. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
  5796. * @vport: The vport pointer to remove from debugfs.
  5797. *
  5798. * Description:
  5799. * When Debugfs is configured this routine removes debugfs file system elements
  5800. * that are specific to this vport. It also checks to see if there are any
  5801. * users left for the debugfs directories associated with the HBA and driver. If
  5802. * this is the last user of the HBA directory or driver directory then it will
  5803. * remove those from the debugfs infrastructure as well.
  5804. **/
  5805. inline void
  5806. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  5807. {
  5808. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  5809. struct lpfc_hba *phba = vport->phba;
  5810. kfree(vport->disc_trc);
  5811. vport->disc_trc = NULL;
  5812. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  5813. vport->debug_disc_trc = NULL;
  5814. debugfs_remove(vport->debug_nodelist); /* nodelist */
  5815. vport->debug_nodelist = NULL;
  5816. debugfs_remove(vport->debug_nvmestat); /* nvmestat */
  5817. vport->debug_nvmestat = NULL;
  5818. debugfs_remove(vport->debug_scsistat); /* scsistat */
  5819. vport->debug_scsistat = NULL;
  5820. debugfs_remove(vport->debug_ioktime); /* ioktime */
  5821. vport->debug_ioktime = NULL;
  5822. debugfs_remove(vport->debug_hdwqstat); /* hdwqstat */
  5823. vport->debug_hdwqstat = NULL;
  5824. if (vport->vport_debugfs_root) {
  5825. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  5826. vport->vport_debugfs_root = NULL;
  5827. atomic_dec(&phba->debugfs_vport_count);
  5828. }
  5829. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  5830. debugfs_remove(phba->debug_multixri_pools); /* multixripools*/
  5831. phba->debug_multixri_pools = NULL;
  5832. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  5833. phba->debug_hbqinfo = NULL;
  5834. debugfs_remove(phba->debug_cgn_buffer);
  5835. phba->debug_cgn_buffer = NULL;
  5836. debugfs_remove(phba->debug_rx_monitor);
  5837. phba->debug_rx_monitor = NULL;
  5838. debugfs_remove(phba->debug_ras_log);
  5839. phba->debug_ras_log = NULL;
  5840. #ifdef LPFC_HDWQ_LOCK_STAT
  5841. debugfs_remove(phba->debug_lockstat); /* lockstat */
  5842. phba->debug_lockstat = NULL;
  5843. #endif
  5844. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  5845. phba->debug_dumpHBASlim = NULL;
  5846. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  5847. phba->debug_dumpHostSlim = NULL;
  5848. debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
  5849. phba->debug_InjErrLBA = NULL;
  5850. debugfs_remove(phba->debug_InjErrNPortID);
  5851. phba->debug_InjErrNPortID = NULL;
  5852. debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
  5853. phba->debug_InjErrWWPN = NULL;
  5854. debugfs_remove(phba->debug_writeGuard); /* writeGuard */
  5855. phba->debug_writeGuard = NULL;
  5856. debugfs_remove(phba->debug_writeApp); /* writeApp */
  5857. phba->debug_writeApp = NULL;
  5858. debugfs_remove(phba->debug_writeRef); /* writeRef */
  5859. phba->debug_writeRef = NULL;
  5860. debugfs_remove(phba->debug_readGuard); /* readGuard */
  5861. phba->debug_readGuard = NULL;
  5862. debugfs_remove(phba->debug_readApp); /* readApp */
  5863. phba->debug_readApp = NULL;
  5864. debugfs_remove(phba->debug_readRef); /* readRef */
  5865. phba->debug_readRef = NULL;
  5866. kfree(phba->slow_ring_trc);
  5867. phba->slow_ring_trc = NULL;
  5868. /* slow_ring_trace */
  5869. debugfs_remove(phba->debug_slow_ring_trc);
  5870. phba->debug_slow_ring_trc = NULL;
  5871. debugfs_remove(phba->debug_nvmeio_trc);
  5872. phba->debug_nvmeio_trc = NULL;
  5873. kfree(phba->nvmeio_trc);
  5874. phba->nvmeio_trc = NULL;
  5875. /*
  5876. * iDiag release
  5877. */
  5878. if (phba->sli_rev == LPFC_SLI_REV4) {
  5879. /* iDiag extAcc */
  5880. debugfs_remove(phba->idiag_ext_acc);
  5881. phba->idiag_ext_acc = NULL;
  5882. /* iDiag mbxAcc */
  5883. debugfs_remove(phba->idiag_mbx_acc);
  5884. phba->idiag_mbx_acc = NULL;
  5885. /* iDiag ctlAcc */
  5886. debugfs_remove(phba->idiag_ctl_acc);
  5887. phba->idiag_ctl_acc = NULL;
  5888. /* iDiag drbAcc */
  5889. debugfs_remove(phba->idiag_drb_acc);
  5890. phba->idiag_drb_acc = NULL;
  5891. /* iDiag queAcc */
  5892. debugfs_remove(phba->idiag_que_acc);
  5893. phba->idiag_que_acc = NULL;
  5894. /* iDiag queInfo */
  5895. debugfs_remove(phba->idiag_que_info);
  5896. phba->idiag_que_info = NULL;
  5897. /* iDiag barAcc */
  5898. debugfs_remove(phba->idiag_bar_acc);
  5899. phba->idiag_bar_acc = NULL;
  5900. /* iDiag pciCfg */
  5901. debugfs_remove(phba->idiag_pci_cfg);
  5902. phba->idiag_pci_cfg = NULL;
  5903. /* Finally remove the iDiag debugfs root */
  5904. debugfs_remove(phba->idiag_root);
  5905. phba->idiag_root = NULL;
  5906. }
  5907. if (phba->hba_debugfs_root) {
  5908. debugfs_remove(phba->hba_debugfs_root); /* fnX */
  5909. phba->hba_debugfs_root = NULL;
  5910. atomic_dec(&lpfc_debugfs_hba_count);
  5911. }
  5912. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  5913. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  5914. lpfc_debugfs_root = NULL;
  5915. }
  5916. }
  5917. #endif
  5918. return;
  5919. }
  5920. /*
  5921. * Driver debug utility routines outside of debugfs. The debug utility
  5922. * routines implemented here is intended to be used in the instrumented
  5923. * debug driver for debugging host or port issues.
  5924. */
  5925. /**
  5926. * lpfc_debug_dump_all_queues - dump all the queues with a hba
  5927. * @phba: Pointer to HBA context object.
  5928. *
  5929. * This function dumps entries of all the queues asociated with the @phba.
  5930. **/
  5931. void
  5932. lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
  5933. {
  5934. int idx;
  5935. /*
  5936. * Dump Work Queues (WQs)
  5937. */
  5938. lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
  5939. lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
  5940. lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
  5941. for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
  5942. lpfc_debug_dump_wq(phba, DUMP_IO, idx);
  5943. lpfc_debug_dump_hdr_rq(phba);
  5944. lpfc_debug_dump_dat_rq(phba);
  5945. /*
  5946. * Dump Complete Queues (CQs)
  5947. */
  5948. lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
  5949. lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
  5950. lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
  5951. for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
  5952. lpfc_debug_dump_cq(phba, DUMP_IO, idx);
  5953. /*
  5954. * Dump Event Queues (EQs)
  5955. */
  5956. for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
  5957. lpfc_debug_dump_hba_eq(phba, idx);
  5958. }