lpfc_attr.c 176 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2015 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/ctype.h>
  22. #include <linux/delay.h>
  23. #include <linux/pci.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/module.h>
  26. #include <linux/aer.h>
  27. #include <linux/gfp.h>
  28. #include <linux/kernel.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/scsi_device.h>
  31. #include <scsi/scsi_host.h>
  32. #include <scsi/scsi_tcq.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include <scsi/fc/fc_fs.h>
  35. #include "lpfc_hw4.h"
  36. #include "lpfc_hw.h"
  37. #include "lpfc_sli.h"
  38. #include "lpfc_sli4.h"
  39. #include "lpfc_nl.h"
  40. #include "lpfc_disc.h"
  41. #include "lpfc_scsi.h"
  42. #include "lpfc.h"
  43. #include "lpfc_logmsg.h"
  44. #include "lpfc_version.h"
  45. #include "lpfc_compat.h"
  46. #include "lpfc_crtn.h"
  47. #include "lpfc_vport.h"
  48. #define LPFC_DEF_DEVLOSS_TMO 30
  49. #define LPFC_MIN_DEVLOSS_TMO 1
  50. #define LPFC_MAX_DEVLOSS_TMO 255
  51. /*
  52. * Write key size should be multiple of 4. If write key is changed
  53. * make sure that library write key is also changed.
  54. */
  55. #define LPFC_REG_WRITE_KEY_SIZE 4
  56. #define LPFC_REG_WRITE_KEY "EMLX"
  57. /**
  58. * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
  59. * @incr: integer to convert.
  60. * @hdw: ascii string holding converted integer plus a string terminator.
  61. *
  62. * Description:
  63. * JEDEC Joint Electron Device Engineering Council.
  64. * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
  65. * character string. The string is then terminated with a NULL in byte 9.
  66. * Hex 0-9 becomes ascii '0' to '9'.
  67. * Hex a-f becomes ascii '=' to 'B' capital B.
  68. *
  69. * Notes:
  70. * Coded for 32 bit integers only.
  71. **/
  72. static void
  73. lpfc_jedec_to_ascii(int incr, char hdw[])
  74. {
  75. int i, j;
  76. for (i = 0; i < 8; i++) {
  77. j = (incr & 0xf);
  78. if (j <= 9)
  79. hdw[7 - i] = 0x30 + j;
  80. else
  81. hdw[7 - i] = 0x61 + j - 10;
  82. incr = (incr >> 4);
  83. }
  84. hdw[8] = 0;
  85. return;
  86. }
  87. /**
  88. * lpfc_drvr_version_show - Return the Emulex driver string with version number
  89. * @dev: class unused variable.
  90. * @attr: device attribute, not used.
  91. * @buf: on return contains the module description text.
  92. *
  93. * Returns: size of formatted string.
  94. **/
  95. static ssize_t
  96. lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
  97. char *buf)
  98. {
  99. return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
  100. }
  101. /**
  102. * lpfc_enable_fip_show - Return the fip mode of the HBA
  103. * @dev: class unused variable.
  104. * @attr: device attribute, not used.
  105. * @buf: on return contains the module description text.
  106. *
  107. * Returns: size of formatted string.
  108. **/
  109. static ssize_t
  110. lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
  111. char *buf)
  112. {
  113. struct Scsi_Host *shost = class_to_shost(dev);
  114. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  115. struct lpfc_hba *phba = vport->phba;
  116. if (phba->hba_flag & HBA_FIP_SUPPORT)
  117. return snprintf(buf, PAGE_SIZE, "1\n");
  118. else
  119. return snprintf(buf, PAGE_SIZE, "0\n");
  120. }
  121. static ssize_t
  122. lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
  123. char *buf)
  124. {
  125. struct Scsi_Host *shost = class_to_shost(dev);
  126. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  127. struct lpfc_hba *phba = vport->phba;
  128. if (phba->cfg_enable_bg)
  129. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  130. return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
  131. else
  132. return snprintf(buf, PAGE_SIZE,
  133. "BlockGuard Not Supported\n");
  134. else
  135. return snprintf(buf, PAGE_SIZE,
  136. "BlockGuard Disabled\n");
  137. }
  138. static ssize_t
  139. lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
  140. char *buf)
  141. {
  142. struct Scsi_Host *shost = class_to_shost(dev);
  143. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  144. struct lpfc_hba *phba = vport->phba;
  145. return snprintf(buf, PAGE_SIZE, "%llu\n",
  146. (unsigned long long)phba->bg_guard_err_cnt);
  147. }
  148. static ssize_t
  149. lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
  150. char *buf)
  151. {
  152. struct Scsi_Host *shost = class_to_shost(dev);
  153. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  154. struct lpfc_hba *phba = vport->phba;
  155. return snprintf(buf, PAGE_SIZE, "%llu\n",
  156. (unsigned long long)phba->bg_apptag_err_cnt);
  157. }
  158. static ssize_t
  159. lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
  160. char *buf)
  161. {
  162. struct Scsi_Host *shost = class_to_shost(dev);
  163. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  164. struct lpfc_hba *phba = vport->phba;
  165. return snprintf(buf, PAGE_SIZE, "%llu\n",
  166. (unsigned long long)phba->bg_reftag_err_cnt);
  167. }
  168. /**
  169. * lpfc_info_show - Return some pci info about the host in ascii
  170. * @dev: class converted to a Scsi_host structure.
  171. * @attr: device attribute, not used.
  172. * @buf: on return contains the formatted text from lpfc_info().
  173. *
  174. * Returns: size of formatted string.
  175. **/
  176. static ssize_t
  177. lpfc_info_show(struct device *dev, struct device_attribute *attr,
  178. char *buf)
  179. {
  180. struct Scsi_Host *host = class_to_shost(dev);
  181. return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
  182. }
  183. /**
  184. * lpfc_serialnum_show - Return the hba serial number in ascii
  185. * @dev: class converted to a Scsi_host structure.
  186. * @attr: device attribute, not used.
  187. * @buf: on return contains the formatted text serial number.
  188. *
  189. * Returns: size of formatted string.
  190. **/
  191. static ssize_t
  192. lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
  193. char *buf)
  194. {
  195. struct Scsi_Host *shost = class_to_shost(dev);
  196. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  197. struct lpfc_hba *phba = vport->phba;
  198. return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
  199. }
  200. /**
  201. * lpfc_temp_sensor_show - Return the temperature sensor level
  202. * @dev: class converted to a Scsi_host structure.
  203. * @attr: device attribute, not used.
  204. * @buf: on return contains the formatted support level.
  205. *
  206. * Description:
  207. * Returns a number indicating the temperature sensor level currently
  208. * supported, zero or one in ascii.
  209. *
  210. * Returns: size of formatted string.
  211. **/
  212. static ssize_t
  213. lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
  214. char *buf)
  215. {
  216. struct Scsi_Host *shost = class_to_shost(dev);
  217. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  218. struct lpfc_hba *phba = vport->phba;
  219. return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
  220. }
  221. /**
  222. * lpfc_modeldesc_show - Return the model description of the hba
  223. * @dev: class converted to a Scsi_host structure.
  224. * @attr: device attribute, not used.
  225. * @buf: on return contains the scsi vpd model description.
  226. *
  227. * Returns: size of formatted string.
  228. **/
  229. static ssize_t
  230. lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
  231. char *buf)
  232. {
  233. struct Scsi_Host *shost = class_to_shost(dev);
  234. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  235. struct lpfc_hba *phba = vport->phba;
  236. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
  237. }
  238. /**
  239. * lpfc_modelname_show - Return the model name of the hba
  240. * @dev: class converted to a Scsi_host structure.
  241. * @attr: device attribute, not used.
  242. * @buf: on return contains the scsi vpd model name.
  243. *
  244. * Returns: size of formatted string.
  245. **/
  246. static ssize_t
  247. lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
  248. char *buf)
  249. {
  250. struct Scsi_Host *shost = class_to_shost(dev);
  251. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  252. struct lpfc_hba *phba = vport->phba;
  253. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
  254. }
  255. /**
  256. * lpfc_programtype_show - Return the program type of the hba
  257. * @dev: class converted to a Scsi_host structure.
  258. * @attr: device attribute, not used.
  259. * @buf: on return contains the scsi vpd program type.
  260. *
  261. * Returns: size of formatted string.
  262. **/
  263. static ssize_t
  264. lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
  265. char *buf)
  266. {
  267. struct Scsi_Host *shost = class_to_shost(dev);
  268. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  269. struct lpfc_hba *phba = vport->phba;
  270. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
  271. }
  272. /**
  273. * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
  274. * @dev: class converted to a Scsi_host structure.
  275. * @attr: device attribute, not used.
  276. * @buf: on return contains the Menlo Maintenance sli flag.
  277. *
  278. * Returns: size of formatted string.
  279. **/
  280. static ssize_t
  281. lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
  282. {
  283. struct Scsi_Host *shost = class_to_shost(dev);
  284. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  285. struct lpfc_hba *phba = vport->phba;
  286. return snprintf(buf, PAGE_SIZE, "%d\n",
  287. (phba->sli.sli_flag & LPFC_MENLO_MAINT));
  288. }
  289. /**
  290. * lpfc_vportnum_show - Return the port number in ascii of the hba
  291. * @dev: class converted to a Scsi_host structure.
  292. * @attr: device attribute, not used.
  293. * @buf: on return contains scsi vpd program type.
  294. *
  295. * Returns: size of formatted string.
  296. **/
  297. static ssize_t
  298. lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
  299. char *buf)
  300. {
  301. struct Scsi_Host *shost = class_to_shost(dev);
  302. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  303. struct lpfc_hba *phba = vport->phba;
  304. return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
  305. }
  306. /**
  307. * lpfc_fwrev_show - Return the firmware rev running in the hba
  308. * @dev: class converted to a Scsi_host structure.
  309. * @attr: device attribute, not used.
  310. * @buf: on return contains the scsi vpd program type.
  311. *
  312. * Returns: size of formatted string.
  313. **/
  314. static ssize_t
  315. lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
  316. char *buf)
  317. {
  318. struct Scsi_Host *shost = class_to_shost(dev);
  319. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  320. struct lpfc_hba *phba = vport->phba;
  321. uint32_t if_type;
  322. uint8_t sli_family;
  323. char fwrev[FW_REV_STR_SIZE];
  324. int len;
  325. lpfc_decode_firmware_rev(phba, fwrev, 1);
  326. if_type = phba->sli4_hba.pc_sli4_params.if_type;
  327. sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
  328. if (phba->sli_rev < LPFC_SLI_REV4)
  329. len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
  330. fwrev, phba->sli_rev);
  331. else
  332. len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
  333. fwrev, phba->sli_rev, if_type, sli_family);
  334. return len;
  335. }
  336. /**
  337. * lpfc_hdw_show - Return the jedec information about the hba
  338. * @dev: class converted to a Scsi_host structure.
  339. * @attr: device attribute, not used.
  340. * @buf: on return contains the scsi vpd program type.
  341. *
  342. * Returns: size of formatted string.
  343. **/
  344. static ssize_t
  345. lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
  346. {
  347. char hdw[9];
  348. struct Scsi_Host *shost = class_to_shost(dev);
  349. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  350. struct lpfc_hba *phba = vport->phba;
  351. lpfc_vpd_t *vp = &phba->vpd;
  352. lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
  353. return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
  354. }
  355. /**
  356. * lpfc_option_rom_version_show - Return the adapter ROM FCode version
  357. * @dev: class converted to a Scsi_host structure.
  358. * @attr: device attribute, not used.
  359. * @buf: on return contains the ROM and FCode ascii strings.
  360. *
  361. * Returns: size of formatted string.
  362. **/
  363. static ssize_t
  364. lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
  365. char *buf)
  366. {
  367. struct Scsi_Host *shost = class_to_shost(dev);
  368. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  369. struct lpfc_hba *phba = vport->phba;
  370. char fwrev[FW_REV_STR_SIZE];
  371. if (phba->sli_rev < LPFC_SLI_REV4)
  372. return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
  373. lpfc_decode_firmware_rev(phba, fwrev, 1);
  374. return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
  375. }
  376. /**
  377. * lpfc_state_show - Return the link state of the port
  378. * @dev: class converted to a Scsi_host structure.
  379. * @attr: device attribute, not used.
  380. * @buf: on return contains text describing the state of the link.
  381. *
  382. * Notes:
  383. * The switch statement has no default so zero will be returned.
  384. *
  385. * Returns: size of formatted string.
  386. **/
  387. static ssize_t
  388. lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
  389. char *buf)
  390. {
  391. struct Scsi_Host *shost = class_to_shost(dev);
  392. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  393. struct lpfc_hba *phba = vport->phba;
  394. int len = 0;
  395. switch (phba->link_state) {
  396. case LPFC_LINK_UNKNOWN:
  397. case LPFC_WARM_START:
  398. case LPFC_INIT_START:
  399. case LPFC_INIT_MBX_CMDS:
  400. case LPFC_LINK_DOWN:
  401. case LPFC_HBA_ERROR:
  402. if (phba->hba_flag & LINK_DISABLED)
  403. len += snprintf(buf + len, PAGE_SIZE-len,
  404. "Link Down - User disabled\n");
  405. else
  406. len += snprintf(buf + len, PAGE_SIZE-len,
  407. "Link Down\n");
  408. break;
  409. case LPFC_LINK_UP:
  410. case LPFC_CLEAR_LA:
  411. case LPFC_HBA_READY:
  412. len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
  413. switch (vport->port_state) {
  414. case LPFC_LOCAL_CFG_LINK:
  415. len += snprintf(buf + len, PAGE_SIZE-len,
  416. "Configuring Link\n");
  417. break;
  418. case LPFC_FDISC:
  419. case LPFC_FLOGI:
  420. case LPFC_FABRIC_CFG_LINK:
  421. case LPFC_NS_REG:
  422. case LPFC_NS_QRY:
  423. case LPFC_BUILD_DISC_LIST:
  424. case LPFC_DISC_AUTH:
  425. len += snprintf(buf + len, PAGE_SIZE - len,
  426. "Discovery\n");
  427. break;
  428. case LPFC_VPORT_READY:
  429. len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
  430. break;
  431. case LPFC_VPORT_FAILED:
  432. len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
  433. break;
  434. case LPFC_VPORT_UNKNOWN:
  435. len += snprintf(buf + len, PAGE_SIZE - len,
  436. "Unknown\n");
  437. break;
  438. }
  439. if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
  440. len += snprintf(buf + len, PAGE_SIZE-len,
  441. " Menlo Maint Mode\n");
  442. else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  443. if (vport->fc_flag & FC_PUBLIC_LOOP)
  444. len += snprintf(buf + len, PAGE_SIZE-len,
  445. " Public Loop\n");
  446. else
  447. len += snprintf(buf + len, PAGE_SIZE-len,
  448. " Private Loop\n");
  449. } else {
  450. if (vport->fc_flag & FC_FABRIC)
  451. len += snprintf(buf + len, PAGE_SIZE-len,
  452. " Fabric\n");
  453. else
  454. len += snprintf(buf + len, PAGE_SIZE-len,
  455. " Point-2-Point\n");
  456. }
  457. }
  458. return len;
  459. }
  460. /**
  461. * lpfc_sli4_protocol_show - Return the fip mode of the HBA
  462. * @dev: class unused variable.
  463. * @attr: device attribute, not used.
  464. * @buf: on return contains the module description text.
  465. *
  466. * Returns: size of formatted string.
  467. **/
  468. static ssize_t
  469. lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
  470. char *buf)
  471. {
  472. struct Scsi_Host *shost = class_to_shost(dev);
  473. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  474. struct lpfc_hba *phba = vport->phba;
  475. if (phba->sli_rev < LPFC_SLI_REV4)
  476. return snprintf(buf, PAGE_SIZE, "fc\n");
  477. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
  478. if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
  479. return snprintf(buf, PAGE_SIZE, "fcoe\n");
  480. if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
  481. return snprintf(buf, PAGE_SIZE, "fc\n");
  482. }
  483. return snprintf(buf, PAGE_SIZE, "unknown\n");
  484. }
  485. /**
  486. * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
  487. * (OAS) is supported.
  488. * @dev: class unused variable.
  489. * @attr: device attribute, not used.
  490. * @buf: on return contains the module description text.
  491. *
  492. * Returns: size of formatted string.
  493. **/
  494. static ssize_t
  495. lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
  496. char *buf)
  497. {
  498. struct Scsi_Host *shost = class_to_shost(dev);
  499. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  500. struct lpfc_hba *phba = vport->phba;
  501. return snprintf(buf, PAGE_SIZE, "%d\n",
  502. phba->sli4_hba.pc_sli4_params.oas_supported);
  503. }
  504. /**
  505. * lpfc_link_state_store - Transition the link_state on an HBA port
  506. * @dev: class device that is converted into a Scsi_host.
  507. * @attr: device attribute, not used.
  508. * @buf: one or more lpfc_polling_flags values.
  509. * @count: not used.
  510. *
  511. * Returns:
  512. * -EINVAL if the buffer is not "up" or "down"
  513. * return from link state change function if non-zero
  514. * length of the buf on success
  515. **/
  516. static ssize_t
  517. lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
  518. const char *buf, size_t count)
  519. {
  520. struct Scsi_Host *shost = class_to_shost(dev);
  521. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  522. struct lpfc_hba *phba = vport->phba;
  523. int status = -EINVAL;
  524. if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
  525. (phba->link_state == LPFC_LINK_DOWN))
  526. status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  527. else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
  528. (phba->link_state >= LPFC_LINK_UP))
  529. status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
  530. if (status == 0)
  531. return strlen(buf);
  532. else
  533. return status;
  534. }
  535. /**
  536. * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
  537. * @dev: class device that is converted into a Scsi_host.
  538. * @attr: device attribute, not used.
  539. * @buf: on return contains the sum of fc mapped and unmapped.
  540. *
  541. * Description:
  542. * Returns the ascii text number of the sum of the fc mapped and unmapped
  543. * vport counts.
  544. *
  545. * Returns: size of formatted string.
  546. **/
  547. static ssize_t
  548. lpfc_num_discovered_ports_show(struct device *dev,
  549. struct device_attribute *attr, char *buf)
  550. {
  551. struct Scsi_Host *shost = class_to_shost(dev);
  552. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  553. return snprintf(buf, PAGE_SIZE, "%d\n",
  554. vport->fc_map_cnt + vport->fc_unmap_cnt);
  555. }
  556. /**
  557. * lpfc_issue_lip - Misnomer, name carried over from long ago
  558. * @shost: Scsi_Host pointer.
  559. *
  560. * Description:
  561. * Bring the link down gracefully then re-init the link. The firmware will
  562. * re-init the fiber channel interface as required. Does not issue a LIP.
  563. *
  564. * Returns:
  565. * -EPERM port offline or management commands are being blocked
  566. * -ENOMEM cannot allocate memory for the mailbox command
  567. * -EIO error sending the mailbox command
  568. * zero for success
  569. **/
  570. static int
  571. lpfc_issue_lip(struct Scsi_Host *shost)
  572. {
  573. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  574. struct lpfc_hba *phba = vport->phba;
  575. LPFC_MBOXQ_t *pmboxq;
  576. int mbxstatus = MBXERR_ERROR;
  577. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  578. (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
  579. return -EPERM;
  580. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  581. if (!pmboxq)
  582. return -ENOMEM;
  583. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  584. pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
  585. pmboxq->u.mb.mbxOwner = OWN_HOST;
  586. mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
  587. if ((mbxstatus == MBX_SUCCESS) &&
  588. (pmboxq->u.mb.mbxStatus == 0 ||
  589. pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
  590. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  591. lpfc_init_link(phba, pmboxq, phba->cfg_topology,
  592. phba->cfg_link_speed);
  593. mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
  594. phba->fc_ratov * 2);
  595. if ((mbxstatus == MBX_SUCCESS) &&
  596. (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  597. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  598. "2859 SLI authentication is required "
  599. "for INIT_LINK but has not done yet\n");
  600. }
  601. lpfc_set_loopback_flag(phba);
  602. if (mbxstatus != MBX_TIMEOUT)
  603. mempool_free(pmboxq, phba->mbox_mem_pool);
  604. if (mbxstatus == MBXERR_ERROR)
  605. return -EIO;
  606. return 0;
  607. }
  608. /**
  609. * lpfc_do_offline - Issues a mailbox command to bring the link down
  610. * @phba: lpfc_hba pointer.
  611. * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
  612. *
  613. * Notes:
  614. * Assumes any error from lpfc_do_offline() will be negative.
  615. * Can wait up to 5 seconds for the port ring buffers count
  616. * to reach zero, prints a warning if it is not zero and continues.
  617. * lpfc_workq_post_event() returns a non-zero return code if call fails.
  618. *
  619. * Returns:
  620. * -EIO error posting the event
  621. * zero for success
  622. **/
  623. static int
  624. lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
  625. {
  626. struct completion online_compl;
  627. struct lpfc_sli_ring *pring;
  628. struct lpfc_sli *psli;
  629. int status = 0;
  630. int cnt = 0;
  631. int i;
  632. int rc;
  633. init_completion(&online_compl);
  634. rc = lpfc_workq_post_event(phba, &status, &online_compl,
  635. LPFC_EVT_OFFLINE_PREP);
  636. if (rc == 0)
  637. return -ENOMEM;
  638. wait_for_completion(&online_compl);
  639. if (status != 0)
  640. return -EIO;
  641. psli = &phba->sli;
  642. /* Wait a little for things to settle down, but not
  643. * long enough for dev loss timeout to expire.
  644. */
  645. for (i = 0; i < psli->num_rings; i++) {
  646. pring = &psli->ring[i];
  647. while (!list_empty(&pring->txcmplq)) {
  648. msleep(10);
  649. if (cnt++ > 500) { /* 5 secs */
  650. lpfc_printf_log(phba,
  651. KERN_WARNING, LOG_INIT,
  652. "0466 Outstanding IO when "
  653. "bringing Adapter offline\n");
  654. break;
  655. }
  656. }
  657. }
  658. init_completion(&online_compl);
  659. rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
  660. if (rc == 0)
  661. return -ENOMEM;
  662. wait_for_completion(&online_compl);
  663. if (status != 0)
  664. return -EIO;
  665. return 0;
  666. }
  667. /**
  668. * lpfc_selective_reset - Offline then onlines the port
  669. * @phba: lpfc_hba pointer.
  670. *
  671. * Description:
  672. * If the port is configured to allow a reset then the hba is brought
  673. * offline then online.
  674. *
  675. * Notes:
  676. * Assumes any error from lpfc_do_offline() will be negative.
  677. * Do not make this function static.
  678. *
  679. * Returns:
  680. * lpfc_do_offline() return code if not zero
  681. * -EIO reset not configured or error posting the event
  682. * zero for success
  683. **/
  684. int
  685. lpfc_selective_reset(struct lpfc_hba *phba)
  686. {
  687. struct completion online_compl;
  688. int status = 0;
  689. int rc;
  690. if (!phba->cfg_enable_hba_reset)
  691. return -EACCES;
  692. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
  693. status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  694. if (status != 0)
  695. return status;
  696. }
  697. init_completion(&online_compl);
  698. rc = lpfc_workq_post_event(phba, &status, &online_compl,
  699. LPFC_EVT_ONLINE);
  700. if (rc == 0)
  701. return -ENOMEM;
  702. wait_for_completion(&online_compl);
  703. if (status != 0)
  704. return -EIO;
  705. return 0;
  706. }
  707. /**
  708. * lpfc_issue_reset - Selectively resets an adapter
  709. * @dev: class device that is converted into a Scsi_host.
  710. * @attr: device attribute, not used.
  711. * @buf: containing the string "selective".
  712. * @count: unused variable.
  713. *
  714. * Description:
  715. * If the buf contains the string "selective" then lpfc_selective_reset()
  716. * is called to perform the reset.
  717. *
  718. * Notes:
  719. * Assumes any error from lpfc_selective_reset() will be negative.
  720. * If lpfc_selective_reset() returns zero then the length of the buffer
  721. * is returned which indicates success
  722. *
  723. * Returns:
  724. * -EINVAL if the buffer does not contain the string "selective"
  725. * length of buf if lpfc-selective_reset() if the call succeeds
  726. * return value of lpfc_selective_reset() if the call fails
  727. **/
  728. static ssize_t
  729. lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
  730. const char *buf, size_t count)
  731. {
  732. struct Scsi_Host *shost = class_to_shost(dev);
  733. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  734. struct lpfc_hba *phba = vport->phba;
  735. int status = -EINVAL;
  736. if (!phba->cfg_enable_hba_reset)
  737. return -EACCES;
  738. if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
  739. status = phba->lpfc_selective_reset(phba);
  740. if (status == 0)
  741. return strlen(buf);
  742. else
  743. return status;
  744. }
  745. /**
  746. * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
  747. * @phba: lpfc_hba pointer.
  748. *
  749. * Description:
  750. * SLI4 interface type-2 device to wait on the sliport status register for
  751. * the readyness after performing a firmware reset.
  752. *
  753. * Returns:
  754. * zero for success, -EPERM when port does not have privilege to perform the
  755. * reset, -EIO when port timeout from recovering from the reset.
  756. *
  757. * Note:
  758. * As the caller will interpret the return code by value, be careful in making
  759. * change or addition to return codes.
  760. **/
  761. int
  762. lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
  763. {
  764. struct lpfc_register portstat_reg = {0};
  765. int i;
  766. msleep(100);
  767. lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  768. &portstat_reg.word0);
  769. /* verify if privileged for the request operation */
  770. if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
  771. !bf_get(lpfc_sliport_status_err, &portstat_reg))
  772. return -EPERM;
  773. /* wait for the SLI port firmware ready after firmware reset */
  774. for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
  775. msleep(10);
  776. lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  777. &portstat_reg.word0);
  778. if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
  779. continue;
  780. if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
  781. continue;
  782. if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
  783. continue;
  784. break;
  785. }
  786. if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
  787. return 0;
  788. else
  789. return -EIO;
  790. }
  791. /**
  792. * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
  793. * @phba: lpfc_hba pointer.
  794. *
  795. * Description:
  796. * Request SLI4 interface type-2 device to perform a physical register set
  797. * access.
  798. *
  799. * Returns:
  800. * zero for success
  801. **/
  802. static ssize_t
  803. lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
  804. {
  805. struct completion online_compl;
  806. struct pci_dev *pdev = phba->pcidev;
  807. uint32_t before_fc_flag;
  808. uint32_t sriov_nr_virtfn;
  809. uint32_t reg_val;
  810. int status = 0, rc = 0;
  811. int job_posted = 1, sriov_err;
  812. if (!phba->cfg_enable_hba_reset)
  813. return -EACCES;
  814. if ((phba->sli_rev < LPFC_SLI_REV4) ||
  815. (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  816. LPFC_SLI_INTF_IF_TYPE_2))
  817. return -EPERM;
  818. /* Keep state if we need to restore back */
  819. before_fc_flag = phba->pport->fc_flag;
  820. sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
  821. /* Disable SR-IOV virtual functions if enabled */
  822. if (phba->cfg_sriov_nr_virtfn) {
  823. pci_disable_sriov(pdev);
  824. phba->cfg_sriov_nr_virtfn = 0;
  825. }
  826. if (opcode == LPFC_FW_DUMP)
  827. phba->hba_flag |= HBA_FW_DUMP_OP;
  828. status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  829. if (status != 0) {
  830. phba->hba_flag &= ~HBA_FW_DUMP_OP;
  831. return status;
  832. }
  833. /* wait for the device to be quiesced before firmware reset */
  834. msleep(100);
  835. reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
  836. LPFC_CTL_PDEV_CTL_OFFSET);
  837. if (opcode == LPFC_FW_DUMP)
  838. reg_val |= LPFC_FW_DUMP_REQUEST;
  839. else if (opcode == LPFC_FW_RESET)
  840. reg_val |= LPFC_CTL_PDEV_CTL_FRST;
  841. else if (opcode == LPFC_DV_RESET)
  842. reg_val |= LPFC_CTL_PDEV_CTL_DRST;
  843. writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
  844. LPFC_CTL_PDEV_CTL_OFFSET);
  845. /* flush */
  846. readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
  847. /* delay driver action following IF_TYPE_2 reset */
  848. rc = lpfc_sli4_pdev_status_reg_wait(phba);
  849. if (rc == -EPERM) {
  850. /* no privilege for reset */
  851. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  852. "3150 No privilege to perform the requested "
  853. "access: x%x\n", reg_val);
  854. } else if (rc == -EIO) {
  855. /* reset failed, there is nothing more we can do */
  856. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  857. "3153 Fail to perform the requested "
  858. "access: x%x\n", reg_val);
  859. return rc;
  860. }
  861. /* keep the original port state */
  862. if (before_fc_flag & FC_OFFLINE_MODE)
  863. goto out;
  864. init_completion(&online_compl);
  865. job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
  866. LPFC_EVT_ONLINE);
  867. if (!job_posted)
  868. goto out;
  869. wait_for_completion(&online_compl);
  870. out:
  871. /* in any case, restore the virtual functions enabled as before */
  872. if (sriov_nr_virtfn) {
  873. sriov_err =
  874. lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
  875. if (!sriov_err)
  876. phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
  877. }
  878. /* return proper error code */
  879. if (!rc) {
  880. if (!job_posted)
  881. rc = -ENOMEM;
  882. else if (status)
  883. rc = -EIO;
  884. }
  885. return rc;
  886. }
  887. /**
  888. * lpfc_nport_evt_cnt_show - Return the number of nport events
  889. * @dev: class device that is converted into a Scsi_host.
  890. * @attr: device attribute, not used.
  891. * @buf: on return contains the ascii number of nport events.
  892. *
  893. * Returns: size of formatted string.
  894. **/
  895. static ssize_t
  896. lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
  897. char *buf)
  898. {
  899. struct Scsi_Host *shost = class_to_shost(dev);
  900. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  901. struct lpfc_hba *phba = vport->phba;
  902. return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
  903. }
  904. /**
  905. * lpfc_board_mode_show - Return the state of the board
  906. * @dev: class device that is converted into a Scsi_host.
  907. * @attr: device attribute, not used.
  908. * @buf: on return contains the state of the adapter.
  909. *
  910. * Returns: size of formatted string.
  911. **/
  912. static ssize_t
  913. lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
  914. char *buf)
  915. {
  916. struct Scsi_Host *shost = class_to_shost(dev);
  917. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  918. struct lpfc_hba *phba = vport->phba;
  919. char * state;
  920. if (phba->link_state == LPFC_HBA_ERROR)
  921. state = "error";
  922. else if (phba->link_state == LPFC_WARM_START)
  923. state = "warm start";
  924. else if (phba->link_state == LPFC_INIT_START)
  925. state = "offline";
  926. else
  927. state = "online";
  928. return snprintf(buf, PAGE_SIZE, "%s\n", state);
  929. }
  930. /**
  931. * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
  932. * @dev: class device that is converted into a Scsi_host.
  933. * @attr: device attribute, not used.
  934. * @buf: containing one of the strings "online", "offline", "warm" or "error".
  935. * @count: unused variable.
  936. *
  937. * Returns:
  938. * -EACCES if enable hba reset not enabled
  939. * -EINVAL if the buffer does not contain a valid string (see above)
  940. * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
  941. * buf length greater than zero indicates success
  942. **/
  943. static ssize_t
  944. lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
  945. const char *buf, size_t count)
  946. {
  947. struct Scsi_Host *shost = class_to_shost(dev);
  948. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  949. struct lpfc_hba *phba = vport->phba;
  950. struct completion online_compl;
  951. char *board_mode_str = NULL;
  952. int status = 0;
  953. int rc;
  954. if (!phba->cfg_enable_hba_reset) {
  955. status = -EACCES;
  956. goto board_mode_out;
  957. }
  958. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  959. "3050 lpfc_board_mode set to %s\n", buf);
  960. init_completion(&online_compl);
  961. if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
  962. rc = lpfc_workq_post_event(phba, &status, &online_compl,
  963. LPFC_EVT_ONLINE);
  964. if (rc == 0) {
  965. status = -ENOMEM;
  966. goto board_mode_out;
  967. }
  968. wait_for_completion(&online_compl);
  969. } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
  970. status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  971. else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
  972. if (phba->sli_rev == LPFC_SLI_REV4)
  973. status = -EINVAL;
  974. else
  975. status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
  976. else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
  977. if (phba->sli_rev == LPFC_SLI_REV4)
  978. status = -EINVAL;
  979. else
  980. status = lpfc_do_offline(phba, LPFC_EVT_KILL);
  981. else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
  982. status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
  983. else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
  984. status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
  985. else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
  986. status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
  987. else
  988. status = -EINVAL;
  989. board_mode_out:
  990. if (!status)
  991. return strlen(buf);
  992. else {
  993. board_mode_str = strchr(buf, '\n');
  994. if (board_mode_str)
  995. *board_mode_str = '\0';
  996. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  997. "3097 Failed \"%s\", status(%d), "
  998. "fc_flag(x%x)\n",
  999. buf, status, phba->pport->fc_flag);
  1000. return status;
  1001. }
  1002. }
  1003. /**
  1004. * lpfc_get_hba_info - Return various bits of informaton about the adapter
  1005. * @phba: pointer to the adapter structure.
  1006. * @mxri: max xri count.
  1007. * @axri: available xri count.
  1008. * @mrpi: max rpi count.
  1009. * @arpi: available rpi count.
  1010. * @mvpi: max vpi count.
  1011. * @avpi: available vpi count.
  1012. *
  1013. * Description:
  1014. * If an integer pointer for an count is not null then the value for the
  1015. * count is returned.
  1016. *
  1017. * Returns:
  1018. * zero on error
  1019. * one for success
  1020. **/
  1021. static int
  1022. lpfc_get_hba_info(struct lpfc_hba *phba,
  1023. uint32_t *mxri, uint32_t *axri,
  1024. uint32_t *mrpi, uint32_t *arpi,
  1025. uint32_t *mvpi, uint32_t *avpi)
  1026. {
  1027. struct lpfc_mbx_read_config *rd_config;
  1028. LPFC_MBOXQ_t *pmboxq;
  1029. MAILBOX_t *pmb;
  1030. int rc = 0;
  1031. uint32_t max_vpi;
  1032. /*
  1033. * prevent udev from issuing mailbox commands until the port is
  1034. * configured.
  1035. */
  1036. if (phba->link_state < LPFC_LINK_DOWN ||
  1037. !phba->mbox_mem_pool ||
  1038. (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
  1039. return 0;
  1040. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  1041. return 0;
  1042. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1043. if (!pmboxq)
  1044. return 0;
  1045. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1046. pmb = &pmboxq->u.mb;
  1047. pmb->mbxCommand = MBX_READ_CONFIG;
  1048. pmb->mbxOwner = OWN_HOST;
  1049. pmboxq->context1 = NULL;
  1050. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  1051. rc = MBX_NOT_FINISHED;
  1052. else
  1053. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1054. if (rc != MBX_SUCCESS) {
  1055. if (rc != MBX_TIMEOUT)
  1056. mempool_free(pmboxq, phba->mbox_mem_pool);
  1057. return 0;
  1058. }
  1059. if (phba->sli_rev == LPFC_SLI_REV4) {
  1060. rd_config = &pmboxq->u.mqe.un.rd_config;
  1061. if (mrpi)
  1062. *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  1063. if (arpi)
  1064. *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
  1065. phba->sli4_hba.max_cfg_param.rpi_used;
  1066. if (mxri)
  1067. *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  1068. if (axri)
  1069. *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
  1070. phba->sli4_hba.max_cfg_param.xri_used;
  1071. /* Account for differences with SLI-3. Get vpi count from
  1072. * mailbox data and subtract one for max vpi value.
  1073. */
  1074. max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
  1075. (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
  1076. if (mvpi)
  1077. *mvpi = max_vpi;
  1078. if (avpi)
  1079. *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
  1080. } else {
  1081. if (mrpi)
  1082. *mrpi = pmb->un.varRdConfig.max_rpi;
  1083. if (arpi)
  1084. *arpi = pmb->un.varRdConfig.avail_rpi;
  1085. if (mxri)
  1086. *mxri = pmb->un.varRdConfig.max_xri;
  1087. if (axri)
  1088. *axri = pmb->un.varRdConfig.avail_xri;
  1089. if (mvpi)
  1090. *mvpi = pmb->un.varRdConfig.max_vpi;
  1091. if (avpi)
  1092. *avpi = pmb->un.varRdConfig.avail_vpi;
  1093. }
  1094. mempool_free(pmboxq, phba->mbox_mem_pool);
  1095. return 1;
  1096. }
  1097. /**
  1098. * lpfc_max_rpi_show - Return maximum rpi
  1099. * @dev: class device that is converted into a Scsi_host.
  1100. * @attr: device attribute, not used.
  1101. * @buf: on return contains the maximum rpi count in decimal or "Unknown".
  1102. *
  1103. * Description:
  1104. * Calls lpfc_get_hba_info() asking for just the mrpi count.
  1105. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  1106. * to "Unknown" and the buffer length is returned, therefore the caller
  1107. * must check for "Unknown" in the buffer to detect a failure.
  1108. *
  1109. * Returns: size of formatted string.
  1110. **/
  1111. static ssize_t
  1112. lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
  1113. char *buf)
  1114. {
  1115. struct Scsi_Host *shost = class_to_shost(dev);
  1116. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1117. struct lpfc_hba *phba = vport->phba;
  1118. uint32_t cnt;
  1119. if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
  1120. return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
  1121. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  1122. }
  1123. /**
  1124. * lpfc_used_rpi_show - Return maximum rpi minus available rpi
  1125. * @dev: class device that is converted into a Scsi_host.
  1126. * @attr: device attribute, not used.
  1127. * @buf: containing the used rpi count in decimal or "Unknown".
  1128. *
  1129. * Description:
  1130. * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
  1131. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  1132. * to "Unknown" and the buffer length is returned, therefore the caller
  1133. * must check for "Unknown" in the buffer to detect a failure.
  1134. *
  1135. * Returns: size of formatted string.
  1136. **/
  1137. static ssize_t
  1138. lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
  1139. char *buf)
  1140. {
  1141. struct Scsi_Host *shost = class_to_shost(dev);
  1142. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1143. struct lpfc_hba *phba = vport->phba;
  1144. uint32_t cnt, acnt;
  1145. if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
  1146. return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  1147. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  1148. }
  1149. /**
  1150. * lpfc_max_xri_show - Return maximum xri
  1151. * @dev: class device that is converted into a Scsi_host.
  1152. * @attr: device attribute, not used.
  1153. * @buf: on return contains the maximum xri count in decimal or "Unknown".
  1154. *
  1155. * Description:
  1156. * Calls lpfc_get_hba_info() asking for just the mrpi count.
  1157. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  1158. * to "Unknown" and the buffer length is returned, therefore the caller
  1159. * must check for "Unknown" in the buffer to detect a failure.
  1160. *
  1161. * Returns: size of formatted string.
  1162. **/
  1163. static ssize_t
  1164. lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
  1165. char *buf)
  1166. {
  1167. struct Scsi_Host *shost = class_to_shost(dev);
  1168. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1169. struct lpfc_hba *phba = vport->phba;
  1170. uint32_t cnt;
  1171. if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
  1172. return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
  1173. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  1174. }
  1175. /**
  1176. * lpfc_used_xri_show - Return maximum xpi minus the available xpi
  1177. * @dev: class device that is converted into a Scsi_host.
  1178. * @attr: device attribute, not used.
  1179. * @buf: on return contains the used xri count in decimal or "Unknown".
  1180. *
  1181. * Description:
  1182. * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
  1183. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  1184. * to "Unknown" and the buffer length is returned, therefore the caller
  1185. * must check for "Unknown" in the buffer to detect a failure.
  1186. *
  1187. * Returns: size of formatted string.
  1188. **/
  1189. static ssize_t
  1190. lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
  1191. char *buf)
  1192. {
  1193. struct Scsi_Host *shost = class_to_shost(dev);
  1194. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1195. struct lpfc_hba *phba = vport->phba;
  1196. uint32_t cnt, acnt;
  1197. if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
  1198. return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  1199. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  1200. }
  1201. /**
  1202. * lpfc_max_vpi_show - Return maximum vpi
  1203. * @dev: class device that is converted into a Scsi_host.
  1204. * @attr: device attribute, not used.
  1205. * @buf: on return contains the maximum vpi count in decimal or "Unknown".
  1206. *
  1207. * Description:
  1208. * Calls lpfc_get_hba_info() asking for just the mvpi count.
  1209. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  1210. * to "Unknown" and the buffer length is returned, therefore the caller
  1211. * must check for "Unknown" in the buffer to detect a failure.
  1212. *
  1213. * Returns: size of formatted string.
  1214. **/
  1215. static ssize_t
  1216. lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
  1217. char *buf)
  1218. {
  1219. struct Scsi_Host *shost = class_to_shost(dev);
  1220. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1221. struct lpfc_hba *phba = vport->phba;
  1222. uint32_t cnt;
  1223. if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
  1224. return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
  1225. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  1226. }
  1227. /**
  1228. * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
  1229. * @dev: class device that is converted into a Scsi_host.
  1230. * @attr: device attribute, not used.
  1231. * @buf: on return contains the used vpi count in decimal or "Unknown".
  1232. *
  1233. * Description:
  1234. * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
  1235. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  1236. * to "Unknown" and the buffer length is returned, therefore the caller
  1237. * must check for "Unknown" in the buffer to detect a failure.
  1238. *
  1239. * Returns: size of formatted string.
  1240. **/
  1241. static ssize_t
  1242. lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
  1243. char *buf)
  1244. {
  1245. struct Scsi_Host *shost = class_to_shost(dev);
  1246. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1247. struct lpfc_hba *phba = vport->phba;
  1248. uint32_t cnt, acnt;
  1249. if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
  1250. return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  1251. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  1252. }
  1253. /**
  1254. * lpfc_npiv_info_show - Return text about NPIV support for the adapter
  1255. * @dev: class device that is converted into a Scsi_host.
  1256. * @attr: device attribute, not used.
  1257. * @buf: text that must be interpreted to determine if npiv is supported.
  1258. *
  1259. * Description:
  1260. * Buffer will contain text indicating npiv is not suppoerted on the port,
  1261. * the port is an NPIV physical port, or it is an npiv virtual port with
  1262. * the id of the vport.
  1263. *
  1264. * Returns: size of formatted string.
  1265. **/
  1266. static ssize_t
  1267. lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
  1268. char *buf)
  1269. {
  1270. struct Scsi_Host *shost = class_to_shost(dev);
  1271. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1272. struct lpfc_hba *phba = vport->phba;
  1273. if (!(phba->max_vpi))
  1274. return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
  1275. if (vport->port_type == LPFC_PHYSICAL_PORT)
  1276. return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
  1277. return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
  1278. }
  1279. /**
  1280. * lpfc_poll_show - Return text about poll support for the adapter
  1281. * @dev: class device that is converted into a Scsi_host.
  1282. * @attr: device attribute, not used.
  1283. * @buf: on return contains the cfg_poll in hex.
  1284. *
  1285. * Notes:
  1286. * cfg_poll should be a lpfc_polling_flags type.
  1287. *
  1288. * Returns: size of formatted string.
  1289. **/
  1290. static ssize_t
  1291. lpfc_poll_show(struct device *dev, struct device_attribute *attr,
  1292. char *buf)
  1293. {
  1294. struct Scsi_Host *shost = class_to_shost(dev);
  1295. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1296. struct lpfc_hba *phba = vport->phba;
  1297. return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
  1298. }
  1299. /**
  1300. * lpfc_poll_store - Set the value of cfg_poll for the adapter
  1301. * @dev: class device that is converted into a Scsi_host.
  1302. * @attr: device attribute, not used.
  1303. * @buf: one or more lpfc_polling_flags values.
  1304. * @count: not used.
  1305. *
  1306. * Notes:
  1307. * buf contents converted to integer and checked for a valid value.
  1308. *
  1309. * Returns:
  1310. * -EINVAL if the buffer connot be converted or is out of range
  1311. * length of the buf on success
  1312. **/
  1313. static ssize_t
  1314. lpfc_poll_store(struct device *dev, struct device_attribute *attr,
  1315. const char *buf, size_t count)
  1316. {
  1317. struct Scsi_Host *shost = class_to_shost(dev);
  1318. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1319. struct lpfc_hba *phba = vport->phba;
  1320. uint32_t creg_val;
  1321. uint32_t old_val;
  1322. int val=0;
  1323. if (!isdigit(buf[0]))
  1324. return -EINVAL;
  1325. if (sscanf(buf, "%i", &val) != 1)
  1326. return -EINVAL;
  1327. if ((val & 0x3) != val)
  1328. return -EINVAL;
  1329. if (phba->sli_rev == LPFC_SLI_REV4)
  1330. val = 0;
  1331. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1332. "3051 lpfc_poll changed from %d to %d\n",
  1333. phba->cfg_poll, val);
  1334. spin_lock_irq(&phba->hbalock);
  1335. old_val = phba->cfg_poll;
  1336. if (val & ENABLE_FCP_RING_POLLING) {
  1337. if ((val & DISABLE_FCP_RING_INT) &&
  1338. !(old_val & DISABLE_FCP_RING_INT)) {
  1339. if (lpfc_readl(phba->HCregaddr, &creg_val)) {
  1340. spin_unlock_irq(&phba->hbalock);
  1341. return -EINVAL;
  1342. }
  1343. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  1344. writel(creg_val, phba->HCregaddr);
  1345. readl(phba->HCregaddr); /* flush */
  1346. lpfc_poll_start_timer(phba);
  1347. }
  1348. } else if (val != 0x0) {
  1349. spin_unlock_irq(&phba->hbalock);
  1350. return -EINVAL;
  1351. }
  1352. if (!(val & DISABLE_FCP_RING_INT) &&
  1353. (old_val & DISABLE_FCP_RING_INT))
  1354. {
  1355. spin_unlock_irq(&phba->hbalock);
  1356. del_timer(&phba->fcp_poll_timer);
  1357. spin_lock_irq(&phba->hbalock);
  1358. if (lpfc_readl(phba->HCregaddr, &creg_val)) {
  1359. spin_unlock_irq(&phba->hbalock);
  1360. return -EINVAL;
  1361. }
  1362. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  1363. writel(creg_val, phba->HCregaddr);
  1364. readl(phba->HCregaddr); /* flush */
  1365. }
  1366. phba->cfg_poll = val;
  1367. spin_unlock_irq(&phba->hbalock);
  1368. return strlen(buf);
  1369. }
  1370. /**
  1371. * lpfc_fips_level_show - Return the current FIPS level for the HBA
  1372. * @dev: class unused variable.
  1373. * @attr: device attribute, not used.
  1374. * @buf: on return contains the module description text.
  1375. *
  1376. * Returns: size of formatted string.
  1377. **/
  1378. static ssize_t
  1379. lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
  1380. char *buf)
  1381. {
  1382. struct Scsi_Host *shost = class_to_shost(dev);
  1383. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1384. struct lpfc_hba *phba = vport->phba;
  1385. return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
  1386. }
  1387. /**
  1388. * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
  1389. * @dev: class unused variable.
  1390. * @attr: device attribute, not used.
  1391. * @buf: on return contains the module description text.
  1392. *
  1393. * Returns: size of formatted string.
  1394. **/
  1395. static ssize_t
  1396. lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
  1397. char *buf)
  1398. {
  1399. struct Scsi_Host *shost = class_to_shost(dev);
  1400. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1401. struct lpfc_hba *phba = vport->phba;
  1402. return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
  1403. }
  1404. /**
  1405. * lpfc_dss_show - Return the current state of dss and the configured state
  1406. * @dev: class converted to a Scsi_host structure.
  1407. * @attr: device attribute, not used.
  1408. * @buf: on return contains the formatted text.
  1409. *
  1410. * Returns: size of formatted string.
  1411. **/
  1412. static ssize_t
  1413. lpfc_dss_show(struct device *dev, struct device_attribute *attr,
  1414. char *buf)
  1415. {
  1416. struct Scsi_Host *shost = class_to_shost(dev);
  1417. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1418. struct lpfc_hba *phba = vport->phba;
  1419. return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
  1420. (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
  1421. (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
  1422. "" : "Not ");
  1423. }
  1424. /**
  1425. * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
  1426. * @dev: class converted to a Scsi_host structure.
  1427. * @attr: device attribute, not used.
  1428. * @buf: on return contains the formatted support level.
  1429. *
  1430. * Description:
  1431. * Returns the maximum number of virtual functions a physical function can
  1432. * support, 0 will be returned if called on virtual function.
  1433. *
  1434. * Returns: size of formatted string.
  1435. **/
  1436. static ssize_t
  1437. lpfc_sriov_hw_max_virtfn_show(struct device *dev,
  1438. struct device_attribute *attr,
  1439. char *buf)
  1440. {
  1441. struct Scsi_Host *shost = class_to_shost(dev);
  1442. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1443. struct lpfc_hba *phba = vport->phba;
  1444. uint16_t max_nr_virtfn;
  1445. max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
  1446. return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
  1447. }
  1448. /**
  1449. * lpfc_param_show - Return a cfg attribute value in decimal
  1450. *
  1451. * Description:
  1452. * Macro that given an attr e.g. hba_queue_depth expands
  1453. * into a function with the name lpfc_hba_queue_depth_show.
  1454. *
  1455. * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
  1456. * @dev: class device that is converted into a Scsi_host.
  1457. * @attr: device attribute, not used.
  1458. * @buf: on return contains the attribute value in decimal.
  1459. *
  1460. * Returns: size of formatted string.
  1461. **/
  1462. #define lpfc_param_show(attr) \
  1463. static ssize_t \
  1464. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  1465. char *buf) \
  1466. { \
  1467. struct Scsi_Host *shost = class_to_shost(dev);\
  1468. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1469. struct lpfc_hba *phba = vport->phba;\
  1470. uint val = 0;\
  1471. val = phba->cfg_##attr;\
  1472. return snprintf(buf, PAGE_SIZE, "%d\n",\
  1473. phba->cfg_##attr);\
  1474. }
  1475. /**
  1476. * lpfc_param_hex_show - Return a cfg attribute value in hex
  1477. *
  1478. * Description:
  1479. * Macro that given an attr e.g. hba_queue_depth expands
  1480. * into a function with the name lpfc_hba_queue_depth_show
  1481. *
  1482. * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
  1483. * @dev: class device that is converted into a Scsi_host.
  1484. * @attr: device attribute, not used.
  1485. * @buf: on return contains the attribute value in hexadecimal.
  1486. *
  1487. * Returns: size of formatted string.
  1488. **/
  1489. #define lpfc_param_hex_show(attr) \
  1490. static ssize_t \
  1491. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  1492. char *buf) \
  1493. { \
  1494. struct Scsi_Host *shost = class_to_shost(dev);\
  1495. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1496. struct lpfc_hba *phba = vport->phba;\
  1497. uint val = 0;\
  1498. val = phba->cfg_##attr;\
  1499. return snprintf(buf, PAGE_SIZE, "%#x\n",\
  1500. phba->cfg_##attr);\
  1501. }
  1502. /**
  1503. * lpfc_param_init - Initializes a cfg attribute
  1504. *
  1505. * Description:
  1506. * Macro that given an attr e.g. hba_queue_depth expands
  1507. * into a function with the name lpfc_hba_queue_depth_init. The macro also
  1508. * takes a default argument, a minimum and maximum argument.
  1509. *
  1510. * lpfc_##attr##_init: Initializes an attribute.
  1511. * @phba: pointer the the adapter structure.
  1512. * @val: integer attribute value.
  1513. *
  1514. * Validates the min and max values then sets the adapter config field
  1515. * accordingly, or uses the default if out of range and prints an error message.
  1516. *
  1517. * Returns:
  1518. * zero on success
  1519. * -EINVAL if default used
  1520. **/
  1521. #define lpfc_param_init(attr, default, minval, maxval) \
  1522. static int \
  1523. lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
  1524. { \
  1525. if (val >= minval && val <= maxval) {\
  1526. phba->cfg_##attr = val;\
  1527. return 0;\
  1528. }\
  1529. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  1530. "0449 lpfc_"#attr" attribute cannot be set to %d, "\
  1531. "allowed range is ["#minval", "#maxval"]\n", val); \
  1532. phba->cfg_##attr = default;\
  1533. return -EINVAL;\
  1534. }
  1535. /**
  1536. * lpfc_param_set - Set a cfg attribute value
  1537. *
  1538. * Description:
  1539. * Macro that given an attr e.g. hba_queue_depth expands
  1540. * into a function with the name lpfc_hba_queue_depth_set
  1541. *
  1542. * lpfc_##attr##_set: Sets an attribute value.
  1543. * @phba: pointer the the adapter structure.
  1544. * @val: integer attribute value.
  1545. *
  1546. * Description:
  1547. * Validates the min and max values then sets the
  1548. * adapter config field if in the valid range. prints error message
  1549. * and does not set the parameter if invalid.
  1550. *
  1551. * Returns:
  1552. * zero on success
  1553. * -EINVAL if val is invalid
  1554. **/
  1555. #define lpfc_param_set(attr, default, minval, maxval) \
  1556. static int \
  1557. lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
  1558. { \
  1559. if (val >= minval && val <= maxval) {\
  1560. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  1561. "3052 lpfc_" #attr " changed from %d to %d\n", \
  1562. phba->cfg_##attr, val); \
  1563. phba->cfg_##attr = val;\
  1564. return 0;\
  1565. }\
  1566. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  1567. "0450 lpfc_"#attr" attribute cannot be set to %d, "\
  1568. "allowed range is ["#minval", "#maxval"]\n", val); \
  1569. return -EINVAL;\
  1570. }
  1571. /**
  1572. * lpfc_param_store - Set a vport attribute value
  1573. *
  1574. * Description:
  1575. * Macro that given an attr e.g. hba_queue_depth expands
  1576. * into a function with the name lpfc_hba_queue_depth_store.
  1577. *
  1578. * lpfc_##attr##_store: Set an sttribute value.
  1579. * @dev: class device that is converted into a Scsi_host.
  1580. * @attr: device attribute, not used.
  1581. * @buf: contains the attribute value in ascii.
  1582. * @count: not used.
  1583. *
  1584. * Description:
  1585. * Convert the ascii text number to an integer, then
  1586. * use the lpfc_##attr##_set function to set the value.
  1587. *
  1588. * Returns:
  1589. * -EINVAL if val is invalid or lpfc_##attr##_set() fails
  1590. * length of buffer upon success.
  1591. **/
  1592. #define lpfc_param_store(attr) \
  1593. static ssize_t \
  1594. lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
  1595. const char *buf, size_t count) \
  1596. { \
  1597. struct Scsi_Host *shost = class_to_shost(dev);\
  1598. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1599. struct lpfc_hba *phba = vport->phba;\
  1600. uint val = 0;\
  1601. if (!isdigit(buf[0]))\
  1602. return -EINVAL;\
  1603. if (sscanf(buf, "%i", &val) != 1)\
  1604. return -EINVAL;\
  1605. if (lpfc_##attr##_set(phba, val) == 0) \
  1606. return strlen(buf);\
  1607. else \
  1608. return -EINVAL;\
  1609. }
  1610. /**
  1611. * lpfc_vport_param_show - Return decimal formatted cfg attribute value
  1612. *
  1613. * Description:
  1614. * Macro that given an attr e.g. hba_queue_depth expands
  1615. * into a function with the name lpfc_hba_queue_depth_show
  1616. *
  1617. * lpfc_##attr##_show: prints the attribute value in decimal.
  1618. * @dev: class device that is converted into a Scsi_host.
  1619. * @attr: device attribute, not used.
  1620. * @buf: on return contains the attribute value in decimal.
  1621. *
  1622. * Returns: length of formatted string.
  1623. **/
  1624. #define lpfc_vport_param_show(attr) \
  1625. static ssize_t \
  1626. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  1627. char *buf) \
  1628. { \
  1629. struct Scsi_Host *shost = class_to_shost(dev);\
  1630. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1631. uint val = 0;\
  1632. val = vport->cfg_##attr;\
  1633. return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
  1634. }
  1635. /**
  1636. * lpfc_vport_param_hex_show - Return hex formatted attribute value
  1637. *
  1638. * Description:
  1639. * Macro that given an attr e.g.
  1640. * hba_queue_depth expands into a function with the name
  1641. * lpfc_hba_queue_depth_show
  1642. *
  1643. * lpfc_##attr##_show: prints the attribute value in hexadecimal.
  1644. * @dev: class device that is converted into a Scsi_host.
  1645. * @attr: device attribute, not used.
  1646. * @buf: on return contains the attribute value in hexadecimal.
  1647. *
  1648. * Returns: length of formatted string.
  1649. **/
  1650. #define lpfc_vport_param_hex_show(attr) \
  1651. static ssize_t \
  1652. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  1653. char *buf) \
  1654. { \
  1655. struct Scsi_Host *shost = class_to_shost(dev);\
  1656. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1657. uint val = 0;\
  1658. val = vport->cfg_##attr;\
  1659. return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
  1660. }
  1661. /**
  1662. * lpfc_vport_param_init - Initialize a vport cfg attribute
  1663. *
  1664. * Description:
  1665. * Macro that given an attr e.g. hba_queue_depth expands
  1666. * into a function with the name lpfc_hba_queue_depth_init. The macro also
  1667. * takes a default argument, a minimum and maximum argument.
  1668. *
  1669. * lpfc_##attr##_init: validates the min and max values then sets the
  1670. * adapter config field accordingly, or uses the default if out of range
  1671. * and prints an error message.
  1672. * @phba: pointer the the adapter structure.
  1673. * @val: integer attribute value.
  1674. *
  1675. * Returns:
  1676. * zero on success
  1677. * -EINVAL if default used
  1678. **/
  1679. #define lpfc_vport_param_init(attr, default, minval, maxval) \
  1680. static int \
  1681. lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
  1682. { \
  1683. if (val >= minval && val <= maxval) {\
  1684. vport->cfg_##attr = val;\
  1685. return 0;\
  1686. }\
  1687. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
  1688. "0423 lpfc_"#attr" attribute cannot be set to %d, "\
  1689. "allowed range is ["#minval", "#maxval"]\n", val); \
  1690. vport->cfg_##attr = default;\
  1691. return -EINVAL;\
  1692. }
  1693. /**
  1694. * lpfc_vport_param_set - Set a vport cfg attribute
  1695. *
  1696. * Description:
  1697. * Macro that given an attr e.g. hba_queue_depth expands
  1698. * into a function with the name lpfc_hba_queue_depth_set
  1699. *
  1700. * lpfc_##attr##_set: validates the min and max values then sets the
  1701. * adapter config field if in the valid range. prints error message
  1702. * and does not set the parameter if invalid.
  1703. * @phba: pointer the the adapter structure.
  1704. * @val: integer attribute value.
  1705. *
  1706. * Returns:
  1707. * zero on success
  1708. * -EINVAL if val is invalid
  1709. **/
  1710. #define lpfc_vport_param_set(attr, default, minval, maxval) \
  1711. static int \
  1712. lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
  1713. { \
  1714. if (val >= minval && val <= maxval) {\
  1715. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
  1716. "3053 lpfc_" #attr \
  1717. " changed from %d (x%x) to %d (x%x)\n", \
  1718. vport->cfg_##attr, vport->cfg_##attr, \
  1719. val, val); \
  1720. vport->cfg_##attr = val;\
  1721. return 0;\
  1722. }\
  1723. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
  1724. "0424 lpfc_"#attr" attribute cannot be set to %d, "\
  1725. "allowed range is ["#minval", "#maxval"]\n", val); \
  1726. return -EINVAL;\
  1727. }
  1728. /**
  1729. * lpfc_vport_param_store - Set a vport attribute
  1730. *
  1731. * Description:
  1732. * Macro that given an attr e.g. hba_queue_depth
  1733. * expands into a function with the name lpfc_hba_queue_depth_store
  1734. *
  1735. * lpfc_##attr##_store: convert the ascii text number to an integer, then
  1736. * use the lpfc_##attr##_set function to set the value.
  1737. * @cdev: class device that is converted into a Scsi_host.
  1738. * @buf: contains the attribute value in decimal.
  1739. * @count: not used.
  1740. *
  1741. * Returns:
  1742. * -EINVAL if val is invalid or lpfc_##attr##_set() fails
  1743. * length of buffer upon success.
  1744. **/
  1745. #define lpfc_vport_param_store(attr) \
  1746. static ssize_t \
  1747. lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
  1748. const char *buf, size_t count) \
  1749. { \
  1750. struct Scsi_Host *shost = class_to_shost(dev);\
  1751. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1752. uint val = 0;\
  1753. if (!isdigit(buf[0]))\
  1754. return -EINVAL;\
  1755. if (sscanf(buf, "%i", &val) != 1)\
  1756. return -EINVAL;\
  1757. if (lpfc_##attr##_set(vport, val) == 0) \
  1758. return strlen(buf);\
  1759. else \
  1760. return -EINVAL;\
  1761. }
  1762. #define LPFC_ATTR(name, defval, minval, maxval, desc) \
  1763. static uint lpfc_##name = defval;\
  1764. module_param(lpfc_##name, uint, S_IRUGO);\
  1765. MODULE_PARM_DESC(lpfc_##name, desc);\
  1766. lpfc_param_init(name, defval, minval, maxval)
  1767. #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
  1768. static uint lpfc_##name = defval;\
  1769. module_param(lpfc_##name, uint, S_IRUGO);\
  1770. MODULE_PARM_DESC(lpfc_##name, desc);\
  1771. lpfc_param_show(name)\
  1772. lpfc_param_init(name, defval, minval, maxval)\
  1773. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  1774. #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
  1775. static uint lpfc_##name = defval;\
  1776. module_param(lpfc_##name, uint, S_IRUGO);\
  1777. MODULE_PARM_DESC(lpfc_##name, desc);\
  1778. lpfc_param_show(name)\
  1779. lpfc_param_init(name, defval, minval, maxval)\
  1780. lpfc_param_set(name, defval, minval, maxval)\
  1781. lpfc_param_store(name)\
  1782. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  1783. lpfc_##name##_show, lpfc_##name##_store)
  1784. #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
  1785. static uint lpfc_##name = defval;\
  1786. module_param(lpfc_##name, uint, S_IRUGO);\
  1787. MODULE_PARM_DESC(lpfc_##name, desc);\
  1788. lpfc_param_hex_show(name)\
  1789. lpfc_param_init(name, defval, minval, maxval)\
  1790. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  1791. #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
  1792. static uint lpfc_##name = defval;\
  1793. module_param(lpfc_##name, uint, S_IRUGO);\
  1794. MODULE_PARM_DESC(lpfc_##name, desc);\
  1795. lpfc_param_hex_show(name)\
  1796. lpfc_param_init(name, defval, minval, maxval)\
  1797. lpfc_param_set(name, defval, minval, maxval)\
  1798. lpfc_param_store(name)\
  1799. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  1800. lpfc_##name##_show, lpfc_##name##_store)
  1801. #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
  1802. static uint lpfc_##name = defval;\
  1803. module_param(lpfc_##name, uint, S_IRUGO);\
  1804. MODULE_PARM_DESC(lpfc_##name, desc);\
  1805. lpfc_vport_param_init(name, defval, minval, maxval)
  1806. #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
  1807. static uint lpfc_##name = defval;\
  1808. module_param(lpfc_##name, uint, S_IRUGO);\
  1809. MODULE_PARM_DESC(lpfc_##name, desc);\
  1810. lpfc_vport_param_show(name)\
  1811. lpfc_vport_param_init(name, defval, minval, maxval)\
  1812. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  1813. #define LPFC_VPORT_ULL_ATTR_R(name, defval, minval, maxval, desc) \
  1814. static uint64_t lpfc_##name = defval;\
  1815. module_param(lpfc_##name, ullong, S_IRUGO);\
  1816. MODULE_PARM_DESC(lpfc_##name, desc);\
  1817. lpfc_vport_param_show(name)\
  1818. lpfc_vport_param_init(name, defval, minval, maxval)\
  1819. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  1820. #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
  1821. static uint lpfc_##name = defval;\
  1822. module_param(lpfc_##name, uint, S_IRUGO);\
  1823. MODULE_PARM_DESC(lpfc_##name, desc);\
  1824. lpfc_vport_param_show(name)\
  1825. lpfc_vport_param_init(name, defval, minval, maxval)\
  1826. lpfc_vport_param_set(name, defval, minval, maxval)\
  1827. lpfc_vport_param_store(name)\
  1828. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  1829. lpfc_##name##_show, lpfc_##name##_store)
  1830. #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
  1831. static uint lpfc_##name = defval;\
  1832. module_param(lpfc_##name, uint, S_IRUGO);\
  1833. MODULE_PARM_DESC(lpfc_##name, desc);\
  1834. lpfc_vport_param_hex_show(name)\
  1835. lpfc_vport_param_init(name, defval, minval, maxval)\
  1836. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  1837. #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
  1838. static uint lpfc_##name = defval;\
  1839. module_param(lpfc_##name, uint, S_IRUGO);\
  1840. MODULE_PARM_DESC(lpfc_##name, desc);\
  1841. lpfc_vport_param_hex_show(name)\
  1842. lpfc_vport_param_init(name, defval, minval, maxval)\
  1843. lpfc_vport_param_set(name, defval, minval, maxval)\
  1844. lpfc_vport_param_store(name)\
  1845. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  1846. lpfc_##name##_show, lpfc_##name##_store)
  1847. static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
  1848. static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
  1849. static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
  1850. static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
  1851. static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
  1852. static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
  1853. static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
  1854. static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
  1855. static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
  1856. static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
  1857. static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
  1858. static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
  1859. static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
  1860. lpfc_link_state_store);
  1861. static DEVICE_ATTR(option_rom_version, S_IRUGO,
  1862. lpfc_option_rom_version_show, NULL);
  1863. static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
  1864. lpfc_num_discovered_ports_show, NULL);
  1865. static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
  1866. static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
  1867. static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
  1868. static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
  1869. static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
  1870. lpfc_board_mode_show, lpfc_board_mode_store);
  1871. static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
  1872. static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
  1873. static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
  1874. static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
  1875. static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
  1876. static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
  1877. static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
  1878. static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
  1879. static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
  1880. static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
  1881. static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
  1882. static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
  1883. static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
  1884. lpfc_sriov_hw_max_virtfn_show, NULL);
  1885. static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
  1886. static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
  1887. NULL);
  1888. static char *lpfc_soft_wwn_key = "C99G71SL8032A";
  1889. #define WWN_SZ 8
  1890. /**
  1891. * lpfc_wwn_set - Convert string to the 8 byte WWN value.
  1892. * @buf: WWN string.
  1893. * @cnt: Length of string.
  1894. * @wwn: Array to receive converted wwn value.
  1895. *
  1896. * Returns:
  1897. * -EINVAL if the buffer does not contain a valid wwn
  1898. * 0 success
  1899. **/
  1900. static size_t
  1901. lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
  1902. {
  1903. unsigned int i, j;
  1904. /* Count may include a LF at end of string */
  1905. if (buf[cnt-1] == '\n')
  1906. cnt--;
  1907. if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
  1908. ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
  1909. return -EINVAL;
  1910. memset(wwn, 0, WWN_SZ);
  1911. /* Validate and store the new name */
  1912. for (i = 0, j = 0; i < 16; i++) {
  1913. if ((*buf >= 'a') && (*buf <= 'f'))
  1914. j = ((j << 4) | ((*buf++ - 'a') + 10));
  1915. else if ((*buf >= 'A') && (*buf <= 'F'))
  1916. j = ((j << 4) | ((*buf++ - 'A') + 10));
  1917. else if ((*buf >= '0') && (*buf <= '9'))
  1918. j = ((j << 4) | (*buf++ - '0'));
  1919. else
  1920. return -EINVAL;
  1921. if (i % 2) {
  1922. wwn[i/2] = j & 0xff;
  1923. j = 0;
  1924. }
  1925. }
  1926. return 0;
  1927. }
  1928. /**
  1929. * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
  1930. * @dev: class device that is converted into a Scsi_host.
  1931. * @attr: device attribute, not used.
  1932. * @buf: containing the string lpfc_soft_wwn_key.
  1933. * @count: must be size of lpfc_soft_wwn_key.
  1934. *
  1935. * Returns:
  1936. * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
  1937. * length of buf indicates success
  1938. **/
  1939. static ssize_t
  1940. lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
  1941. const char *buf, size_t count)
  1942. {
  1943. struct Scsi_Host *shost = class_to_shost(dev);
  1944. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1945. struct lpfc_hba *phba = vport->phba;
  1946. unsigned int cnt = count;
  1947. /*
  1948. * We're doing a simple sanity check for soft_wwpn setting.
  1949. * We require that the user write a specific key to enable
  1950. * the soft_wwpn attribute to be settable. Once the attribute
  1951. * is written, the enable key resets. If further updates are
  1952. * desired, the key must be written again to re-enable the
  1953. * attribute.
  1954. *
  1955. * The "key" is not secret - it is a hardcoded string shown
  1956. * here. The intent is to protect against the random user or
  1957. * application that is just writing attributes.
  1958. */
  1959. /* count may include a LF at end of string */
  1960. if (buf[cnt-1] == '\n')
  1961. cnt--;
  1962. if ((cnt != strlen(lpfc_soft_wwn_key)) ||
  1963. (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
  1964. return -EINVAL;
  1965. phba->soft_wwn_enable = 1;
  1966. return count;
  1967. }
  1968. static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
  1969. lpfc_soft_wwn_enable_store);
  1970. /**
  1971. * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
  1972. * @dev: class device that is converted into a Scsi_host.
  1973. * @attr: device attribute, not used.
  1974. * @buf: on return contains the wwpn in hexadecimal.
  1975. *
  1976. * Returns: size of formatted string.
  1977. **/
  1978. static ssize_t
  1979. lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
  1980. char *buf)
  1981. {
  1982. struct Scsi_Host *shost = class_to_shost(dev);
  1983. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1984. struct lpfc_hba *phba = vport->phba;
  1985. return snprintf(buf, PAGE_SIZE, "0x%llx\n",
  1986. (unsigned long long)phba->cfg_soft_wwpn);
  1987. }
  1988. /**
  1989. * lpfc_soft_wwpn_store - Set the ww port name of the adapter
  1990. * @dev class device that is converted into a Scsi_host.
  1991. * @attr: device attribute, not used.
  1992. * @buf: contains the wwpn in hexadecimal.
  1993. * @count: number of wwpn bytes in buf
  1994. *
  1995. * Returns:
  1996. * -EACCES hba reset not enabled, adapter over temp
  1997. * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
  1998. * -EIO error taking adapter offline or online
  1999. * value of count on success
  2000. **/
  2001. static ssize_t
  2002. lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
  2003. const char *buf, size_t count)
  2004. {
  2005. struct Scsi_Host *shost = class_to_shost(dev);
  2006. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2007. struct lpfc_hba *phba = vport->phba;
  2008. struct completion online_compl;
  2009. int stat1 = 0, stat2 = 0;
  2010. unsigned int cnt = count;
  2011. u8 wwpn[WWN_SZ];
  2012. int rc;
  2013. if (!phba->cfg_enable_hba_reset)
  2014. return -EACCES;
  2015. spin_lock_irq(&phba->hbalock);
  2016. if (phba->over_temp_state == HBA_OVER_TEMP) {
  2017. spin_unlock_irq(&phba->hbalock);
  2018. return -EACCES;
  2019. }
  2020. spin_unlock_irq(&phba->hbalock);
  2021. /* count may include a LF at end of string */
  2022. if (buf[cnt-1] == '\n')
  2023. cnt--;
  2024. if (!phba->soft_wwn_enable)
  2025. return -EINVAL;
  2026. /* lock setting wwpn, wwnn down */
  2027. phba->soft_wwn_enable = 0;
  2028. rc = lpfc_wwn_set(buf, cnt, wwpn);
  2029. if (!rc) {
  2030. /* not able to set wwpn, unlock it */
  2031. phba->soft_wwn_enable = 1;
  2032. return rc;
  2033. }
  2034. phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
  2035. fc_host_port_name(shost) = phba->cfg_soft_wwpn;
  2036. if (phba->cfg_soft_wwnn)
  2037. fc_host_node_name(shost) = phba->cfg_soft_wwnn;
  2038. dev_printk(KERN_NOTICE, &phba->pcidev->dev,
  2039. "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
  2040. stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  2041. if (stat1)
  2042. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2043. "0463 lpfc_soft_wwpn attribute set failed to "
  2044. "reinit adapter - %d\n", stat1);
  2045. init_completion(&online_compl);
  2046. rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
  2047. LPFC_EVT_ONLINE);
  2048. if (rc == 0)
  2049. return -ENOMEM;
  2050. wait_for_completion(&online_compl);
  2051. if (stat2)
  2052. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2053. "0464 lpfc_soft_wwpn attribute set failed to "
  2054. "reinit adapter - %d\n", stat2);
  2055. return (stat1 || stat2) ? -EIO : count;
  2056. }
  2057. static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
  2058. lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
  2059. /**
  2060. * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
  2061. * @dev: class device that is converted into a Scsi_host.
  2062. * @attr: device attribute, not used.
  2063. * @buf: on return contains the wwnn in hexadecimal.
  2064. *
  2065. * Returns: size of formatted string.
  2066. **/
  2067. static ssize_t
  2068. lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
  2069. char *buf)
  2070. {
  2071. struct Scsi_Host *shost = class_to_shost(dev);
  2072. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2073. return snprintf(buf, PAGE_SIZE, "0x%llx\n",
  2074. (unsigned long long)phba->cfg_soft_wwnn);
  2075. }
  2076. /**
  2077. * lpfc_soft_wwnn_store - sets the ww node name of the adapter
  2078. * @cdev: class device that is converted into a Scsi_host.
  2079. * @buf: contains the ww node name in hexadecimal.
  2080. * @count: number of wwnn bytes in buf.
  2081. *
  2082. * Returns:
  2083. * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
  2084. * value of count on success
  2085. **/
  2086. static ssize_t
  2087. lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
  2088. const char *buf, size_t count)
  2089. {
  2090. struct Scsi_Host *shost = class_to_shost(dev);
  2091. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2092. unsigned int cnt = count;
  2093. u8 wwnn[WWN_SZ];
  2094. int rc;
  2095. /* count may include a LF at end of string */
  2096. if (buf[cnt-1] == '\n')
  2097. cnt--;
  2098. if (!phba->soft_wwn_enable)
  2099. return -EINVAL;
  2100. rc = lpfc_wwn_set(buf, cnt, wwnn);
  2101. if (!rc) {
  2102. /* Allow wwnn to be set many times, as long as the enable
  2103. * is set. However, once the wwpn is set, everything locks.
  2104. */
  2105. return rc;
  2106. }
  2107. phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
  2108. dev_printk(KERN_NOTICE, &phba->pcidev->dev,
  2109. "lpfc%d: soft_wwnn set. Value will take effect upon "
  2110. "setting of the soft_wwpn\n", phba->brd_no);
  2111. return count;
  2112. }
  2113. static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
  2114. lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
  2115. /**
  2116. * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
  2117. * Optimized Access Storage (OAS) operations.
  2118. * @dev: class device that is converted into a Scsi_host.
  2119. * @attr: device attribute, not used.
  2120. * @buf: buffer for passing information.
  2121. *
  2122. * Returns:
  2123. * value of count
  2124. **/
  2125. static ssize_t
  2126. lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
  2127. char *buf)
  2128. {
  2129. struct Scsi_Host *shost = class_to_shost(dev);
  2130. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2131. return snprintf(buf, PAGE_SIZE, "0x%llx\n",
  2132. wwn_to_u64(phba->cfg_oas_tgt_wwpn));
  2133. }
  2134. /**
  2135. * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
  2136. * Optimized Access Storage (OAS) operations.
  2137. * @dev: class device that is converted into a Scsi_host.
  2138. * @attr: device attribute, not used.
  2139. * @buf: buffer for passing information.
  2140. * @count: Size of the data buffer.
  2141. *
  2142. * Returns:
  2143. * -EINVAL count is invalid, invalid wwpn byte invalid
  2144. * -EPERM oas is not supported by hba
  2145. * value of count on success
  2146. **/
  2147. static ssize_t
  2148. lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
  2149. const char *buf, size_t count)
  2150. {
  2151. struct Scsi_Host *shost = class_to_shost(dev);
  2152. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2153. unsigned int cnt = count;
  2154. uint8_t wwpn[WWN_SZ];
  2155. int rc;
  2156. if (!phba->cfg_fof)
  2157. return -EPERM;
  2158. /* count may include a LF at end of string */
  2159. if (buf[cnt-1] == '\n')
  2160. cnt--;
  2161. rc = lpfc_wwn_set(buf, cnt, wwpn);
  2162. if (rc)
  2163. return rc;
  2164. memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
  2165. memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
  2166. if (wwn_to_u64(wwpn) == 0)
  2167. phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
  2168. else
  2169. phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
  2170. phba->cfg_oas_flags &= ~OAS_LUN_VALID;
  2171. phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
  2172. return count;
  2173. }
  2174. static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
  2175. lpfc_oas_tgt_show, lpfc_oas_tgt_store);
  2176. /**
  2177. * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
  2178. * for Optimized Access Storage (OAS) operations.
  2179. * @dev: class device that is converted into a Scsi_host.
  2180. * @attr: device attribute, not used.
  2181. * @buf: buffer for passing information.
  2182. *
  2183. * Returns:
  2184. * value of count on success
  2185. **/
  2186. static ssize_t
  2187. lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
  2188. char *buf)
  2189. {
  2190. struct Scsi_Host *shost = class_to_shost(dev);
  2191. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2192. return snprintf(buf, PAGE_SIZE, "0x%llx\n",
  2193. wwn_to_u64(phba->cfg_oas_vpt_wwpn));
  2194. }
  2195. /**
  2196. * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
  2197. * for Optimized Access Storage (OAS) operations.
  2198. * @dev: class device that is converted into a Scsi_host.
  2199. * @attr: device attribute, not used.
  2200. * @buf: buffer for passing information.
  2201. * @count: Size of the data buffer.
  2202. *
  2203. * Returns:
  2204. * -EINVAL count is invalid, invalid wwpn byte invalid
  2205. * -EPERM oas is not supported by hba
  2206. * value of count on success
  2207. **/
  2208. static ssize_t
  2209. lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
  2210. const char *buf, size_t count)
  2211. {
  2212. struct Scsi_Host *shost = class_to_shost(dev);
  2213. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2214. unsigned int cnt = count;
  2215. uint8_t wwpn[WWN_SZ];
  2216. int rc;
  2217. if (!phba->cfg_fof)
  2218. return -EPERM;
  2219. /* count may include a LF at end of string */
  2220. if (buf[cnt-1] == '\n')
  2221. cnt--;
  2222. rc = lpfc_wwn_set(buf, cnt, wwpn);
  2223. if (rc)
  2224. return rc;
  2225. memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
  2226. memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
  2227. if (wwn_to_u64(wwpn) == 0)
  2228. phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
  2229. else
  2230. phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
  2231. phba->cfg_oas_flags &= ~OAS_LUN_VALID;
  2232. phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
  2233. return count;
  2234. }
  2235. static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
  2236. lpfc_oas_vpt_show, lpfc_oas_vpt_store);
  2237. /**
  2238. * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
  2239. * of whether luns will be enabled or disabled
  2240. * for Optimized Access Storage (OAS) operations.
  2241. * @dev: class device that is converted into a Scsi_host.
  2242. * @attr: device attribute, not used.
  2243. * @buf: buffer for passing information.
  2244. *
  2245. * Returns:
  2246. * size of formatted string.
  2247. **/
  2248. static ssize_t
  2249. lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
  2250. char *buf)
  2251. {
  2252. struct Scsi_Host *shost = class_to_shost(dev);
  2253. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2254. return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
  2255. }
  2256. /**
  2257. * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
  2258. * of whether luns will be enabled or disabled
  2259. * for Optimized Access Storage (OAS) operations.
  2260. * @dev: class device that is converted into a Scsi_host.
  2261. * @attr: device attribute, not used.
  2262. * @buf: buffer for passing information.
  2263. * @count: Size of the data buffer.
  2264. *
  2265. * Returns:
  2266. * -EINVAL count is invalid, invalid wwpn byte invalid
  2267. * -EPERM oas is not supported by hba
  2268. * value of count on success
  2269. **/
  2270. static ssize_t
  2271. lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
  2272. const char *buf, size_t count)
  2273. {
  2274. struct Scsi_Host *shost = class_to_shost(dev);
  2275. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2276. int val = 0;
  2277. if (!phba->cfg_fof)
  2278. return -EPERM;
  2279. if (!isdigit(buf[0]))
  2280. return -EINVAL;
  2281. if (sscanf(buf, "%i", &val) != 1)
  2282. return -EINVAL;
  2283. if ((val != 0) && (val != 1))
  2284. return -EINVAL;
  2285. phba->cfg_oas_lun_state = val;
  2286. return strlen(buf);
  2287. }
  2288. static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
  2289. lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
  2290. /**
  2291. * lpfc_oas_lun_status_show - Return the status of the Optimized Access
  2292. * Storage (OAS) lun returned by the
  2293. * lpfc_oas_lun_show function.
  2294. * @dev: class device that is converted into a Scsi_host.
  2295. * @attr: device attribute, not used.
  2296. * @buf: buffer for passing information.
  2297. *
  2298. * Returns:
  2299. * size of formatted string.
  2300. **/
  2301. static ssize_t
  2302. lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
  2303. char *buf)
  2304. {
  2305. struct Scsi_Host *shost = class_to_shost(dev);
  2306. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2307. if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
  2308. return -EFAULT;
  2309. return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
  2310. }
  2311. static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
  2312. lpfc_oas_lun_status_show, NULL);
  2313. /**
  2314. * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
  2315. * (OAS) operations.
  2316. * @phba: lpfc_hba pointer.
  2317. * @ndlp: pointer to fcp target node.
  2318. * @lun: the fc lun for setting oas state.
  2319. * @oas_state: the oas state to be set to the lun.
  2320. *
  2321. * Returns:
  2322. * SUCCESS : 0
  2323. * -EPERM OAS is not enabled or not supported by this port.
  2324. *
  2325. */
  2326. static size_t
  2327. lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
  2328. uint8_t tgt_wwpn[], uint64_t lun, uint32_t oas_state)
  2329. {
  2330. int rc = 0;
  2331. if (!phba->cfg_fof)
  2332. return -EPERM;
  2333. if (oas_state) {
  2334. if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
  2335. (struct lpfc_name *)tgt_wwpn, lun))
  2336. rc = -ENOMEM;
  2337. } else {
  2338. lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
  2339. (struct lpfc_name *)tgt_wwpn, lun);
  2340. }
  2341. return rc;
  2342. }
  2343. /**
  2344. * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
  2345. * Access Storage (OAS) operations.
  2346. * @phba: lpfc_hba pointer.
  2347. * @vpt_wwpn: wwpn of the vport associated with the returned lun
  2348. * @tgt_wwpn: wwpn of the target associated with the returned lun
  2349. * @lun_status: status of the lun returned lun
  2350. *
  2351. * Returns the first or next lun enabled for OAS operations for the vport/target
  2352. * specified. If a lun is found, its vport wwpn, target wwpn and status is
  2353. * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
  2354. *
  2355. * Return:
  2356. * lun that is OAS enabled for the vport/target
  2357. * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
  2358. */
  2359. static uint64_t
  2360. lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
  2361. uint8_t tgt_wwpn[], uint32_t *lun_status)
  2362. {
  2363. uint64_t found_lun;
  2364. if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
  2365. return NOT_OAS_ENABLED_LUN;
  2366. if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
  2367. phba->sli4_hba.oas_next_vpt_wwpn,
  2368. (struct lpfc_name *)
  2369. phba->sli4_hba.oas_next_tgt_wwpn,
  2370. &phba->sli4_hba.oas_next_lun,
  2371. (struct lpfc_name *)vpt_wwpn,
  2372. (struct lpfc_name *)tgt_wwpn,
  2373. &found_lun, lun_status))
  2374. return found_lun;
  2375. else
  2376. return NOT_OAS_ENABLED_LUN;
  2377. }
  2378. /**
  2379. * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
  2380. * @phba: lpfc_hba pointer.
  2381. * @vpt_wwpn: vport wwpn by reference.
  2382. * @tgt_wwpn: target wwpn by reference.
  2383. * @lun: the fc lun for setting oas state.
  2384. * @oas_state: the oas state to be set to the oas_lun.
  2385. *
  2386. * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
  2387. * a lun for OAS operations.
  2388. *
  2389. * Return:
  2390. * SUCCESS: 0
  2391. * -ENOMEM: failed to enable an lun for OAS operations
  2392. * -EPERM: OAS is not enabled
  2393. */
  2394. static ssize_t
  2395. lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
  2396. uint8_t tgt_wwpn[], uint64_t lun,
  2397. uint32_t oas_state)
  2398. {
  2399. int rc;
  2400. rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
  2401. oas_state);
  2402. return rc;
  2403. }
  2404. /**
  2405. * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
  2406. * @dev: class device that is converted into a Scsi_host.
  2407. * @attr: device attribute, not used.
  2408. * @buf: buffer for passing information.
  2409. *
  2410. * This routine returns a lun enabled for OAS each time the function
  2411. * is called.
  2412. *
  2413. * Returns:
  2414. * SUCCESS: size of formatted string.
  2415. * -EFAULT: target or vport wwpn was not set properly.
  2416. * -EPERM: oas is not enabled.
  2417. **/
  2418. static ssize_t
  2419. lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
  2420. char *buf)
  2421. {
  2422. struct Scsi_Host *shost = class_to_shost(dev);
  2423. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2424. uint64_t oas_lun;
  2425. int len = 0;
  2426. if (!phba->cfg_fof)
  2427. return -EPERM;
  2428. if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
  2429. if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
  2430. return -EFAULT;
  2431. if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
  2432. if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
  2433. return -EFAULT;
  2434. oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
  2435. phba->cfg_oas_tgt_wwpn,
  2436. &phba->cfg_oas_lun_status);
  2437. if (oas_lun != NOT_OAS_ENABLED_LUN)
  2438. phba->cfg_oas_flags |= OAS_LUN_VALID;
  2439. len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
  2440. return len;
  2441. }
  2442. /**
  2443. * lpfc_oas_lun_store - Sets the OAS state for lun
  2444. * @dev: class device that is converted into a Scsi_host.
  2445. * @attr: device attribute, not used.
  2446. * @buf: buffer for passing information.
  2447. *
  2448. * This function sets the OAS state for lun. Before this function is called,
  2449. * the vport wwpn, target wwpn, and oas state need to be set.
  2450. *
  2451. * Returns:
  2452. * SUCCESS: size of formatted string.
  2453. * -EFAULT: target or vport wwpn was not set properly.
  2454. * -EPERM: oas is not enabled.
  2455. * size of formatted string.
  2456. **/
  2457. static ssize_t
  2458. lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
  2459. const char *buf, size_t count)
  2460. {
  2461. struct Scsi_Host *shost = class_to_shost(dev);
  2462. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2463. uint64_t scsi_lun;
  2464. ssize_t rc;
  2465. if (!phba->cfg_fof)
  2466. return -EPERM;
  2467. if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
  2468. return -EFAULT;
  2469. if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
  2470. return -EFAULT;
  2471. if (!isdigit(buf[0]))
  2472. return -EINVAL;
  2473. if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
  2474. return -EINVAL;
  2475. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2476. "3372 Try to set vport 0x%llx target 0x%llx lun:%lld "
  2477. "with oas set to %d\n",
  2478. wwn_to_u64(phba->cfg_oas_vpt_wwpn),
  2479. wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
  2480. phba->cfg_oas_lun_state);
  2481. rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
  2482. phba->cfg_oas_tgt_wwpn, scsi_lun,
  2483. phba->cfg_oas_lun_state);
  2484. if (rc)
  2485. return rc;
  2486. return count;
  2487. }
  2488. static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
  2489. lpfc_oas_lun_show, lpfc_oas_lun_store);
  2490. static int lpfc_poll = 0;
  2491. module_param(lpfc_poll, int, S_IRUGO);
  2492. MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
  2493. " 0 - none,"
  2494. " 1 - poll with interrupts enabled"
  2495. " 3 - poll and disable FCP ring interrupts");
  2496. static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
  2497. lpfc_poll_show, lpfc_poll_store);
  2498. int lpfc_sli_mode = 0;
  2499. module_param(lpfc_sli_mode, int, S_IRUGO);
  2500. MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
  2501. " 0 - auto (SLI-3 if supported),"
  2502. " 2 - select SLI-2 even on SLI-3 capable HBAs,"
  2503. " 3 - select SLI-3");
  2504. int lpfc_enable_npiv = 1;
  2505. module_param(lpfc_enable_npiv, int, S_IRUGO);
  2506. MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
  2507. lpfc_param_show(enable_npiv);
  2508. lpfc_param_init(enable_npiv, 1, 0, 1);
  2509. static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
  2510. LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
  2511. "FCF Fast failover=1 Priority failover=2");
  2512. int lpfc_enable_rrq = 2;
  2513. module_param(lpfc_enable_rrq, int, S_IRUGO);
  2514. MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
  2515. lpfc_param_show(enable_rrq);
  2516. /*
  2517. # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
  2518. # 0x0 = disabled, XRI/OXID use not tracked.
  2519. # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
  2520. # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
  2521. */
  2522. lpfc_param_init(enable_rrq, 2, 0, 2);
  2523. static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
  2524. /*
  2525. # lpfc_suppress_link_up: Bring link up at initialization
  2526. # 0x0 = bring link up (issue MBX_INIT_LINK)
  2527. # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
  2528. # 0x2 = never bring up link
  2529. # Default value is 0.
  2530. */
  2531. LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
  2532. LPFC_DELAY_INIT_LINK_INDEFINITELY,
  2533. "Suppress Link Up at initialization");
  2534. /*
  2535. # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
  2536. # 1 - (1024)
  2537. # 2 - (2048)
  2538. # 3 - (3072)
  2539. # 4 - (4096)
  2540. # 5 - (5120)
  2541. */
  2542. static ssize_t
  2543. lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
  2544. {
  2545. struct Scsi_Host *shost = class_to_shost(dev);
  2546. struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
  2547. return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
  2548. }
  2549. static DEVICE_ATTR(iocb_hw, S_IRUGO,
  2550. lpfc_iocb_hw_show, NULL);
  2551. static ssize_t
  2552. lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
  2553. {
  2554. struct Scsi_Host *shost = class_to_shost(dev);
  2555. struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
  2556. return snprintf(buf, PAGE_SIZE, "%d\n",
  2557. phba->sli.ring[LPFC_ELS_RING].txq_max);
  2558. }
  2559. static DEVICE_ATTR(txq_hw, S_IRUGO,
  2560. lpfc_txq_hw_show, NULL);
  2561. static ssize_t
  2562. lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
  2563. char *buf)
  2564. {
  2565. struct Scsi_Host *shost = class_to_shost(dev);
  2566. struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
  2567. return snprintf(buf, PAGE_SIZE, "%d\n",
  2568. phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
  2569. }
  2570. static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
  2571. lpfc_txcmplq_hw_show, NULL);
  2572. int lpfc_iocb_cnt = 2;
  2573. module_param(lpfc_iocb_cnt, int, S_IRUGO);
  2574. MODULE_PARM_DESC(lpfc_iocb_cnt,
  2575. "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
  2576. lpfc_param_show(iocb_cnt);
  2577. lpfc_param_init(iocb_cnt, 2, 1, 5);
  2578. static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
  2579. lpfc_iocb_cnt_show, NULL);
  2580. /*
  2581. # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
  2582. # until the timer expires. Value range is [0,255]. Default value is 30.
  2583. */
  2584. static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
  2585. static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
  2586. module_param(lpfc_nodev_tmo, int, 0);
  2587. MODULE_PARM_DESC(lpfc_nodev_tmo,
  2588. "Seconds driver will hold I/O waiting "
  2589. "for a device to come back");
  2590. /**
  2591. * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
  2592. * @dev: class converted to a Scsi_host structure.
  2593. * @attr: device attribute, not used.
  2594. * @buf: on return contains the dev loss timeout in decimal.
  2595. *
  2596. * Returns: size of formatted string.
  2597. **/
  2598. static ssize_t
  2599. lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
  2600. char *buf)
  2601. {
  2602. struct Scsi_Host *shost = class_to_shost(dev);
  2603. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2604. return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
  2605. }
  2606. /**
  2607. * lpfc_nodev_tmo_init - Set the hba nodev timeout value
  2608. * @vport: lpfc vport structure pointer.
  2609. * @val: contains the nodev timeout value.
  2610. *
  2611. * Description:
  2612. * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
  2613. * a kernel error message is printed and zero is returned.
  2614. * Else if val is in range then nodev tmo and devloss tmo are set to val.
  2615. * Otherwise nodev tmo is set to the default value.
  2616. *
  2617. * Returns:
  2618. * zero if already set or if val is in range
  2619. * -EINVAL val out of range
  2620. **/
  2621. static int
  2622. lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
  2623. {
  2624. if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
  2625. vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
  2626. if (val != LPFC_DEF_DEVLOSS_TMO)
  2627. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2628. "0407 Ignoring nodev_tmo module "
  2629. "parameter because devloss_tmo is "
  2630. "set.\n");
  2631. return 0;
  2632. }
  2633. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  2634. vport->cfg_nodev_tmo = val;
  2635. vport->cfg_devloss_tmo = val;
  2636. return 0;
  2637. }
  2638. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2639. "0400 lpfc_nodev_tmo attribute cannot be set to"
  2640. " %d, allowed range is [%d, %d]\n",
  2641. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  2642. vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
  2643. return -EINVAL;
  2644. }
  2645. /**
  2646. * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
  2647. * @vport: lpfc vport structure pointer.
  2648. *
  2649. * Description:
  2650. * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
  2651. **/
  2652. static void
  2653. lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
  2654. {
  2655. struct Scsi_Host *shost;
  2656. struct lpfc_nodelist *ndlp;
  2657. shost = lpfc_shost_from_vport(vport);
  2658. spin_lock_irq(shost->host_lock);
  2659. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
  2660. if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
  2661. ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
  2662. spin_unlock_irq(shost->host_lock);
  2663. }
  2664. /**
  2665. * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
  2666. * @vport: lpfc vport structure pointer.
  2667. * @val: contains the tmo value.
  2668. *
  2669. * Description:
  2670. * If the devloss tmo is already set or the vport dev loss tmo has changed
  2671. * then a kernel error message is printed and zero is returned.
  2672. * Else if val is in range then nodev tmo and devloss tmo are set to val.
  2673. * Otherwise nodev tmo is set to the default value.
  2674. *
  2675. * Returns:
  2676. * zero if already set or if val is in range
  2677. * -EINVAL val out of range
  2678. **/
  2679. static int
  2680. lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
  2681. {
  2682. if (vport->dev_loss_tmo_changed ||
  2683. (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
  2684. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2685. "0401 Ignoring change to nodev_tmo "
  2686. "because devloss_tmo is set.\n");
  2687. return 0;
  2688. }
  2689. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  2690. vport->cfg_nodev_tmo = val;
  2691. vport->cfg_devloss_tmo = val;
  2692. /*
  2693. * For compat: set the fc_host dev loss so new rports
  2694. * will get the value.
  2695. */
  2696. fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
  2697. lpfc_update_rport_devloss_tmo(vport);
  2698. return 0;
  2699. }
  2700. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2701. "0403 lpfc_nodev_tmo attribute cannot be set to"
  2702. "%d, allowed range is [%d, %d]\n",
  2703. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  2704. return -EINVAL;
  2705. }
  2706. lpfc_vport_param_store(nodev_tmo)
  2707. static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
  2708. lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
  2709. /*
  2710. # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
  2711. # disappear until the timer expires. Value range is [0,255]. Default
  2712. # value is 30.
  2713. */
  2714. module_param(lpfc_devloss_tmo, int, S_IRUGO);
  2715. MODULE_PARM_DESC(lpfc_devloss_tmo,
  2716. "Seconds driver will hold I/O waiting "
  2717. "for a device to come back");
  2718. lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
  2719. LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
  2720. lpfc_vport_param_show(devloss_tmo)
  2721. /**
  2722. * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
  2723. * @vport: lpfc vport structure pointer.
  2724. * @val: contains the tmo value.
  2725. *
  2726. * Description:
  2727. * If val is in a valid range then set the vport nodev tmo,
  2728. * devloss tmo, also set the vport dev loss tmo changed flag.
  2729. * Else a kernel error message is printed.
  2730. *
  2731. * Returns:
  2732. * zero if val is in range
  2733. * -EINVAL val out of range
  2734. **/
  2735. static int
  2736. lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
  2737. {
  2738. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  2739. vport->cfg_nodev_tmo = val;
  2740. vport->cfg_devloss_tmo = val;
  2741. vport->dev_loss_tmo_changed = 1;
  2742. fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
  2743. lpfc_update_rport_devloss_tmo(vport);
  2744. return 0;
  2745. }
  2746. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2747. "0404 lpfc_devloss_tmo attribute cannot be set to"
  2748. " %d, allowed range is [%d, %d]\n",
  2749. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  2750. return -EINVAL;
  2751. }
  2752. lpfc_vport_param_store(devloss_tmo)
  2753. static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
  2754. lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
  2755. /*
  2756. # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
  2757. # deluged with LOTS of information.
  2758. # You can set a bit mask to record specific types of verbose messages:
  2759. # See lpfc_logmsh.h for definitions.
  2760. */
  2761. LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
  2762. "Verbose logging bit-mask");
  2763. /*
  2764. # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
  2765. # objects that have been registered with the nameserver after login.
  2766. */
  2767. LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
  2768. "Deregister nameserver objects before LOGO");
  2769. /*
  2770. # lun_queue_depth: This parameter is used to limit the number of outstanding
  2771. # commands per FCP LUN. Value range is [1,512]. Default value is 30.
  2772. # If this parameter value is greater than 1/8th the maximum number of exchanges
  2773. # supported by the HBA port, then the lun queue depth will be reduced to
  2774. # 1/8th the maximum number of exchanges.
  2775. */
  2776. LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
  2777. "Max number of FCP commands we can queue to a specific LUN");
  2778. /*
  2779. # tgt_queue_depth: This parameter is used to limit the number of outstanding
  2780. # commands per target port. Value range is [10,65535]. Default value is 65535.
  2781. */
  2782. LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
  2783. "Max number of FCP commands we can queue to a specific target port");
  2784. /*
  2785. # hba_queue_depth: This parameter is used to limit the number of outstanding
  2786. # commands per lpfc HBA. Value range is [32,8192]. If this parameter
  2787. # value is greater than the maximum number of exchanges supported by the HBA,
  2788. # then maximum number of exchanges supported by the HBA is used to determine
  2789. # the hba_queue_depth.
  2790. */
  2791. LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
  2792. "Max number of FCP commands we can queue to a lpfc HBA");
  2793. /*
  2794. # peer_port_login: This parameter allows/prevents logins
  2795. # between peer ports hosted on the same physical port.
  2796. # When this parameter is set 0 peer ports of same physical port
  2797. # are not allowed to login to each other.
  2798. # When this parameter is set 1 peer ports of same physical port
  2799. # are allowed to login to each other.
  2800. # Default value of this parameter is 0.
  2801. */
  2802. LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
  2803. "Allow peer ports on the same physical port to login to each "
  2804. "other.");
  2805. /*
  2806. # restrict_login: This parameter allows/prevents logins
  2807. # between Virtual Ports and remote initiators.
  2808. # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
  2809. # other initiators and will attempt to PLOGI all remote ports.
  2810. # When this parameter is set (1) Virtual Ports will reject PLOGIs from
  2811. # remote ports and will not attempt to PLOGI to other initiators.
  2812. # This parameter does not restrict to the physical port.
  2813. # This parameter does not restrict logins to Fabric resident remote ports.
  2814. # Default value of this parameter is 1.
  2815. */
  2816. static int lpfc_restrict_login = 1;
  2817. module_param(lpfc_restrict_login, int, S_IRUGO);
  2818. MODULE_PARM_DESC(lpfc_restrict_login,
  2819. "Restrict virtual ports login to remote initiators.");
  2820. lpfc_vport_param_show(restrict_login);
  2821. /**
  2822. * lpfc_restrict_login_init - Set the vport restrict login flag
  2823. * @vport: lpfc vport structure pointer.
  2824. * @val: contains the restrict login value.
  2825. *
  2826. * Description:
  2827. * If val is not in a valid range then log a kernel error message and set
  2828. * the vport restrict login to one.
  2829. * If the port type is physical clear the restrict login flag and return.
  2830. * Else set the restrict login flag to val.
  2831. *
  2832. * Returns:
  2833. * zero if val is in range
  2834. * -EINVAL val out of range
  2835. **/
  2836. static int
  2837. lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
  2838. {
  2839. if (val < 0 || val > 1) {
  2840. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2841. "0422 lpfc_restrict_login attribute cannot "
  2842. "be set to %d, allowed range is [0, 1]\n",
  2843. val);
  2844. vport->cfg_restrict_login = 1;
  2845. return -EINVAL;
  2846. }
  2847. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  2848. vport->cfg_restrict_login = 0;
  2849. return 0;
  2850. }
  2851. vport->cfg_restrict_login = val;
  2852. return 0;
  2853. }
  2854. /**
  2855. * lpfc_restrict_login_set - Set the vport restrict login flag
  2856. * @vport: lpfc vport structure pointer.
  2857. * @val: contains the restrict login value.
  2858. *
  2859. * Description:
  2860. * If val is not in a valid range then log a kernel error message and set
  2861. * the vport restrict login to one.
  2862. * If the port type is physical and the val is not zero log a kernel
  2863. * error message, clear the restrict login flag and return zero.
  2864. * Else set the restrict login flag to val.
  2865. *
  2866. * Returns:
  2867. * zero if val is in range
  2868. * -EINVAL val out of range
  2869. **/
  2870. static int
  2871. lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
  2872. {
  2873. if (val < 0 || val > 1) {
  2874. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2875. "0425 lpfc_restrict_login attribute cannot "
  2876. "be set to %d, allowed range is [0, 1]\n",
  2877. val);
  2878. vport->cfg_restrict_login = 1;
  2879. return -EINVAL;
  2880. }
  2881. if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
  2882. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2883. "0468 lpfc_restrict_login must be 0 for "
  2884. "Physical ports.\n");
  2885. vport->cfg_restrict_login = 0;
  2886. return 0;
  2887. }
  2888. vport->cfg_restrict_login = val;
  2889. return 0;
  2890. }
  2891. lpfc_vport_param_store(restrict_login);
  2892. static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
  2893. lpfc_restrict_login_show, lpfc_restrict_login_store);
  2894. /*
  2895. # Some disk devices have a "select ID" or "select Target" capability.
  2896. # From a protocol standpoint "select ID" usually means select the
  2897. # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
  2898. # annex" which contains a table that maps a "select ID" (a number
  2899. # between 0 and 7F) to an ALPA. By default, for compatibility with
  2900. # older drivers, the lpfc driver scans this table from low ALPA to high
  2901. # ALPA.
  2902. #
  2903. # Turning on the scan-down variable (on = 1, off = 0) will
  2904. # cause the lpfc driver to use an inverted table, effectively
  2905. # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
  2906. #
  2907. # (Note: This "select ID" functionality is a LOOP ONLY characteristic
  2908. # and will not work across a fabric. Also this parameter will take
  2909. # effect only in the case when ALPA map is not available.)
  2910. */
  2911. LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
  2912. "Start scanning for devices from highest ALPA to lowest");
  2913. /*
  2914. # lpfc_topology: link topology for init link
  2915. # 0x0 = attempt loop mode then point-to-point
  2916. # 0x01 = internal loopback mode
  2917. # 0x02 = attempt point-to-point mode only
  2918. # 0x04 = attempt loop mode only
  2919. # 0x06 = attempt point-to-point mode then loop
  2920. # Set point-to-point mode if you want to run as an N_Port.
  2921. # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
  2922. # Default value is 0.
  2923. */
  2924. /**
  2925. * lpfc_topology_set - Set the adapters topology field
  2926. * @phba: lpfc_hba pointer.
  2927. * @val: topology value.
  2928. *
  2929. * Description:
  2930. * If val is in a valid range then set the adapter's topology field and
  2931. * issue a lip; if the lip fails reset the topology to the old value.
  2932. *
  2933. * If the value is not in range log a kernel error message and return an error.
  2934. *
  2935. * Returns:
  2936. * zero if val is in range and lip okay
  2937. * non-zero return value from lpfc_issue_lip()
  2938. * -EINVAL val out of range
  2939. **/
  2940. static ssize_t
  2941. lpfc_topology_store(struct device *dev, struct device_attribute *attr,
  2942. const char *buf, size_t count)
  2943. {
  2944. struct Scsi_Host *shost = class_to_shost(dev);
  2945. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2946. struct lpfc_hba *phba = vport->phba;
  2947. int val = 0;
  2948. int nolip = 0;
  2949. const char *val_buf = buf;
  2950. int err;
  2951. uint32_t prev_val;
  2952. if (!strncmp(buf, "nolip ", strlen("nolip "))) {
  2953. nolip = 1;
  2954. val_buf = &buf[strlen("nolip ")];
  2955. }
  2956. if (!isdigit(val_buf[0]))
  2957. return -EINVAL;
  2958. if (sscanf(val_buf, "%i", &val) != 1)
  2959. return -EINVAL;
  2960. if (val >= 0 && val <= 6) {
  2961. prev_val = phba->cfg_topology;
  2962. phba->cfg_topology = val;
  2963. if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
  2964. val == 4) {
  2965. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2966. "3113 Loop mode not supported at speed %d\n",
  2967. phba->cfg_link_speed);
  2968. phba->cfg_topology = prev_val;
  2969. return -EINVAL;
  2970. }
  2971. if (nolip)
  2972. return strlen(buf);
  2973. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2974. "3054 lpfc_topology changed from %d to %d\n",
  2975. prev_val, val);
  2976. if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
  2977. phba->fc_topology_changed = 1;
  2978. err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
  2979. if (err) {
  2980. phba->cfg_topology = prev_val;
  2981. return -EINVAL;
  2982. } else
  2983. return strlen(buf);
  2984. }
  2985. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2986. "%d:0467 lpfc_topology attribute cannot be set to %d, "
  2987. "allowed range is [0, 6]\n",
  2988. phba->brd_no, val);
  2989. return -EINVAL;
  2990. }
  2991. static int lpfc_topology = 0;
  2992. module_param(lpfc_topology, int, S_IRUGO);
  2993. MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
  2994. lpfc_param_show(topology)
  2995. lpfc_param_init(topology, 0, 0, 6)
  2996. static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
  2997. lpfc_topology_show, lpfc_topology_store);
  2998. /**
  2999. * lpfc_static_vport_show: Read callback function for
  3000. * lpfc_static_vport sysfs file.
  3001. * @dev: Pointer to class device object.
  3002. * @attr: device attribute structure.
  3003. * @buf: Data buffer.
  3004. *
  3005. * This function is the read call back function for
  3006. * lpfc_static_vport sysfs file. The lpfc_static_vport
  3007. * sysfs file report the mageability of the vport.
  3008. **/
  3009. static ssize_t
  3010. lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
  3011. char *buf)
  3012. {
  3013. struct Scsi_Host *shost = class_to_shost(dev);
  3014. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3015. if (vport->vport_flag & STATIC_VPORT)
  3016. sprintf(buf, "1\n");
  3017. else
  3018. sprintf(buf, "0\n");
  3019. return strlen(buf);
  3020. }
  3021. /*
  3022. * Sysfs attribute to control the statistical data collection.
  3023. */
  3024. static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
  3025. lpfc_static_vport_show, NULL);
  3026. /**
  3027. * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
  3028. * @dev: Pointer to class device.
  3029. * @buf: Data buffer.
  3030. * @count: Size of the data buffer.
  3031. *
  3032. * This function get called when an user write to the lpfc_stat_data_ctrl
  3033. * sysfs file. This function parse the command written to the sysfs file
  3034. * and take appropriate action. These commands are used for controlling
  3035. * driver statistical data collection.
  3036. * Following are the command this function handles.
  3037. *
  3038. * setbucket <bucket_type> <base> <step>
  3039. * = Set the latency buckets.
  3040. * destroybucket = destroy all the buckets.
  3041. * start = start data collection
  3042. * stop = stop data collection
  3043. * reset = reset the collected data
  3044. **/
  3045. static ssize_t
  3046. lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
  3047. const char *buf, size_t count)
  3048. {
  3049. struct Scsi_Host *shost = class_to_shost(dev);
  3050. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3051. struct lpfc_hba *phba = vport->phba;
  3052. #define LPFC_MAX_DATA_CTRL_LEN 1024
  3053. static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
  3054. unsigned long i;
  3055. char *str_ptr, *token;
  3056. struct lpfc_vport **vports;
  3057. struct Scsi_Host *v_shost;
  3058. char *bucket_type_str, *base_str, *step_str;
  3059. unsigned long base, step, bucket_type;
  3060. if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
  3061. if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
  3062. return -EINVAL;
  3063. strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
  3064. str_ptr = &bucket_data[0];
  3065. /* Ignore this token - this is command token */
  3066. token = strsep(&str_ptr, "\t ");
  3067. if (!token)
  3068. return -EINVAL;
  3069. bucket_type_str = strsep(&str_ptr, "\t ");
  3070. if (!bucket_type_str)
  3071. return -EINVAL;
  3072. if (!strncmp(bucket_type_str, "linear", strlen("linear")))
  3073. bucket_type = LPFC_LINEAR_BUCKET;
  3074. else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
  3075. bucket_type = LPFC_POWER2_BUCKET;
  3076. else
  3077. return -EINVAL;
  3078. base_str = strsep(&str_ptr, "\t ");
  3079. if (!base_str)
  3080. return -EINVAL;
  3081. base = simple_strtoul(base_str, NULL, 0);
  3082. step_str = strsep(&str_ptr, "\t ");
  3083. if (!step_str)
  3084. return -EINVAL;
  3085. step = simple_strtoul(step_str, NULL, 0);
  3086. if (!step)
  3087. return -EINVAL;
  3088. /* Block the data collection for every vport */
  3089. vports = lpfc_create_vport_work_array(phba);
  3090. if (vports == NULL)
  3091. return -ENOMEM;
  3092. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3093. v_shost = lpfc_shost_from_vport(vports[i]);
  3094. spin_lock_irq(v_shost->host_lock);
  3095. /* Block and reset data collection */
  3096. vports[i]->stat_data_blocked = 1;
  3097. if (vports[i]->stat_data_enabled)
  3098. lpfc_vport_reset_stat_data(vports[i]);
  3099. spin_unlock_irq(v_shost->host_lock);
  3100. }
  3101. /* Set the bucket attributes */
  3102. phba->bucket_type = bucket_type;
  3103. phba->bucket_base = base;
  3104. phba->bucket_step = step;
  3105. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3106. v_shost = lpfc_shost_from_vport(vports[i]);
  3107. /* Unblock data collection */
  3108. spin_lock_irq(v_shost->host_lock);
  3109. vports[i]->stat_data_blocked = 0;
  3110. spin_unlock_irq(v_shost->host_lock);
  3111. }
  3112. lpfc_destroy_vport_work_array(phba, vports);
  3113. return strlen(buf);
  3114. }
  3115. if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
  3116. vports = lpfc_create_vport_work_array(phba);
  3117. if (vports == NULL)
  3118. return -ENOMEM;
  3119. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3120. v_shost = lpfc_shost_from_vport(vports[i]);
  3121. spin_lock_irq(shost->host_lock);
  3122. vports[i]->stat_data_blocked = 1;
  3123. lpfc_free_bucket(vport);
  3124. vport->stat_data_enabled = 0;
  3125. vports[i]->stat_data_blocked = 0;
  3126. spin_unlock_irq(shost->host_lock);
  3127. }
  3128. lpfc_destroy_vport_work_array(phba, vports);
  3129. phba->bucket_type = LPFC_NO_BUCKET;
  3130. phba->bucket_base = 0;
  3131. phba->bucket_step = 0;
  3132. return strlen(buf);
  3133. }
  3134. if (!strncmp(buf, "start", strlen("start"))) {
  3135. /* If no buckets configured return error */
  3136. if (phba->bucket_type == LPFC_NO_BUCKET)
  3137. return -EINVAL;
  3138. spin_lock_irq(shost->host_lock);
  3139. if (vport->stat_data_enabled) {
  3140. spin_unlock_irq(shost->host_lock);
  3141. return strlen(buf);
  3142. }
  3143. lpfc_alloc_bucket(vport);
  3144. vport->stat_data_enabled = 1;
  3145. spin_unlock_irq(shost->host_lock);
  3146. return strlen(buf);
  3147. }
  3148. if (!strncmp(buf, "stop", strlen("stop"))) {
  3149. spin_lock_irq(shost->host_lock);
  3150. if (vport->stat_data_enabled == 0) {
  3151. spin_unlock_irq(shost->host_lock);
  3152. return strlen(buf);
  3153. }
  3154. lpfc_free_bucket(vport);
  3155. vport->stat_data_enabled = 0;
  3156. spin_unlock_irq(shost->host_lock);
  3157. return strlen(buf);
  3158. }
  3159. if (!strncmp(buf, "reset", strlen("reset"))) {
  3160. if ((phba->bucket_type == LPFC_NO_BUCKET)
  3161. || !vport->stat_data_enabled)
  3162. return strlen(buf);
  3163. spin_lock_irq(shost->host_lock);
  3164. vport->stat_data_blocked = 1;
  3165. lpfc_vport_reset_stat_data(vport);
  3166. vport->stat_data_blocked = 0;
  3167. spin_unlock_irq(shost->host_lock);
  3168. return strlen(buf);
  3169. }
  3170. return -EINVAL;
  3171. }
  3172. /**
  3173. * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
  3174. * @dev: Pointer to class device object.
  3175. * @buf: Data buffer.
  3176. *
  3177. * This function is the read call back function for
  3178. * lpfc_stat_data_ctrl sysfs file. This function report the
  3179. * current statistical data collection state.
  3180. **/
  3181. static ssize_t
  3182. lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
  3183. char *buf)
  3184. {
  3185. struct Scsi_Host *shost = class_to_shost(dev);
  3186. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3187. struct lpfc_hba *phba = vport->phba;
  3188. int index = 0;
  3189. int i;
  3190. char *bucket_type;
  3191. unsigned long bucket_value;
  3192. switch (phba->bucket_type) {
  3193. case LPFC_LINEAR_BUCKET:
  3194. bucket_type = "linear";
  3195. break;
  3196. case LPFC_POWER2_BUCKET:
  3197. bucket_type = "power2";
  3198. break;
  3199. default:
  3200. bucket_type = "No Bucket";
  3201. break;
  3202. }
  3203. sprintf(&buf[index], "Statistical Data enabled :%d, "
  3204. "blocked :%d, Bucket type :%s, Bucket base :%d,"
  3205. " Bucket step :%d\nLatency Ranges :",
  3206. vport->stat_data_enabled, vport->stat_data_blocked,
  3207. bucket_type, phba->bucket_base, phba->bucket_step);
  3208. index = strlen(buf);
  3209. if (phba->bucket_type != LPFC_NO_BUCKET) {
  3210. for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
  3211. if (phba->bucket_type == LPFC_LINEAR_BUCKET)
  3212. bucket_value = phba->bucket_base +
  3213. phba->bucket_step * i;
  3214. else
  3215. bucket_value = phba->bucket_base +
  3216. (1 << i) * phba->bucket_step;
  3217. if (index + 10 > PAGE_SIZE)
  3218. break;
  3219. sprintf(&buf[index], "%08ld ", bucket_value);
  3220. index = strlen(buf);
  3221. }
  3222. }
  3223. sprintf(&buf[index], "\n");
  3224. return strlen(buf);
  3225. }
  3226. /*
  3227. * Sysfs attribute to control the statistical data collection.
  3228. */
  3229. static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
  3230. lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
  3231. /*
  3232. * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
  3233. */
  3234. /*
  3235. * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
  3236. * for each target.
  3237. */
  3238. #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
  3239. #define MAX_STAT_DATA_SIZE_PER_TARGET \
  3240. STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
  3241. /**
  3242. * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
  3243. * @filp: sysfs file
  3244. * @kobj: Pointer to the kernel object
  3245. * @bin_attr: Attribute object
  3246. * @buff: Buffer pointer
  3247. * @off: File offset
  3248. * @count: Buffer size
  3249. *
  3250. * This function is the read call back function for lpfc_drvr_stat_data
  3251. * sysfs file. This function export the statistical data to user
  3252. * applications.
  3253. **/
  3254. static ssize_t
  3255. sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
  3256. struct bin_attribute *bin_attr,
  3257. char *buf, loff_t off, size_t count)
  3258. {
  3259. struct device *dev = container_of(kobj, struct device,
  3260. kobj);
  3261. struct Scsi_Host *shost = class_to_shost(dev);
  3262. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3263. struct lpfc_hba *phba = vport->phba;
  3264. int i = 0, index = 0;
  3265. unsigned long nport_index;
  3266. struct lpfc_nodelist *ndlp = NULL;
  3267. nport_index = (unsigned long)off /
  3268. MAX_STAT_DATA_SIZE_PER_TARGET;
  3269. if (!vport->stat_data_enabled || vport->stat_data_blocked
  3270. || (phba->bucket_type == LPFC_NO_BUCKET))
  3271. return 0;
  3272. spin_lock_irq(shost->host_lock);
  3273. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3274. if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
  3275. continue;
  3276. if (nport_index > 0) {
  3277. nport_index--;
  3278. continue;
  3279. }
  3280. if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
  3281. > count)
  3282. break;
  3283. if (!ndlp->lat_data)
  3284. continue;
  3285. /* Print the WWN */
  3286. sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
  3287. ndlp->nlp_portname.u.wwn[0],
  3288. ndlp->nlp_portname.u.wwn[1],
  3289. ndlp->nlp_portname.u.wwn[2],
  3290. ndlp->nlp_portname.u.wwn[3],
  3291. ndlp->nlp_portname.u.wwn[4],
  3292. ndlp->nlp_portname.u.wwn[5],
  3293. ndlp->nlp_portname.u.wwn[6],
  3294. ndlp->nlp_portname.u.wwn[7]);
  3295. index = strlen(buf);
  3296. for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
  3297. sprintf(&buf[index], "%010u,",
  3298. ndlp->lat_data[i].cmd_count);
  3299. index = strlen(buf);
  3300. }
  3301. sprintf(&buf[index], "\n");
  3302. index = strlen(buf);
  3303. }
  3304. spin_unlock_irq(shost->host_lock);
  3305. return index;
  3306. }
  3307. static struct bin_attribute sysfs_drvr_stat_data_attr = {
  3308. .attr = {
  3309. .name = "lpfc_drvr_stat_data",
  3310. .mode = S_IRUSR,
  3311. },
  3312. .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
  3313. .read = sysfs_drvr_stat_data_read,
  3314. .write = NULL,
  3315. };
  3316. /*
  3317. # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
  3318. # connection.
  3319. # Value range is [0,16]. Default value is 0.
  3320. */
  3321. /**
  3322. * lpfc_link_speed_set - Set the adapters link speed
  3323. * @phba: lpfc_hba pointer.
  3324. * @val: link speed value.
  3325. *
  3326. * Description:
  3327. * If val is in a valid range then set the adapter's link speed field and
  3328. * issue a lip; if the lip fails reset the link speed to the old value.
  3329. *
  3330. * Notes:
  3331. * If the value is not in range log a kernel error message and return an error.
  3332. *
  3333. * Returns:
  3334. * zero if val is in range and lip okay.
  3335. * non-zero return value from lpfc_issue_lip()
  3336. * -EINVAL val out of range
  3337. **/
  3338. static ssize_t
  3339. lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
  3340. const char *buf, size_t count)
  3341. {
  3342. struct Scsi_Host *shost = class_to_shost(dev);
  3343. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3344. struct lpfc_hba *phba = vport->phba;
  3345. int val = LPFC_USER_LINK_SPEED_AUTO;
  3346. int nolip = 0;
  3347. const char *val_buf = buf;
  3348. int err;
  3349. uint32_t prev_val;
  3350. if (!strncmp(buf, "nolip ", strlen("nolip "))) {
  3351. nolip = 1;
  3352. val_buf = &buf[strlen("nolip ")];
  3353. }
  3354. if (!isdigit(val_buf[0]))
  3355. return -EINVAL;
  3356. if (sscanf(val_buf, "%i", &val) != 1)
  3357. return -EINVAL;
  3358. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3359. "3055 lpfc_link_speed changed from %d to %d %s\n",
  3360. phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
  3361. if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
  3362. ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
  3363. ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
  3364. ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
  3365. ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
  3366. ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
  3367. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3368. "2879 lpfc_link_speed attribute cannot be set "
  3369. "to %d. Speed is not supported by this port.\n",
  3370. val);
  3371. return -EINVAL;
  3372. }
  3373. if (val == LPFC_USER_LINK_SPEED_16G &&
  3374. phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  3375. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3376. "3112 lpfc_link_speed attribute cannot be set "
  3377. "to %d. Speed is not supported in loop mode.\n",
  3378. val);
  3379. return -EINVAL;
  3380. }
  3381. if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
  3382. (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
  3383. prev_val = phba->cfg_link_speed;
  3384. phba->cfg_link_speed = val;
  3385. if (nolip)
  3386. return strlen(buf);
  3387. err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
  3388. if (err) {
  3389. phba->cfg_link_speed = prev_val;
  3390. return -EINVAL;
  3391. } else
  3392. return strlen(buf);
  3393. }
  3394. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3395. "0469 lpfc_link_speed attribute cannot be set to %d, "
  3396. "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
  3397. return -EINVAL;
  3398. }
  3399. static int lpfc_link_speed = 0;
  3400. module_param(lpfc_link_speed, int, S_IRUGO);
  3401. MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
  3402. lpfc_param_show(link_speed)
  3403. /**
  3404. * lpfc_link_speed_init - Set the adapters link speed
  3405. * @phba: lpfc_hba pointer.
  3406. * @val: link speed value.
  3407. *
  3408. * Description:
  3409. * If val is in a valid range then set the adapter's link speed field.
  3410. *
  3411. * Notes:
  3412. * If the value is not in range log a kernel error message, clear the link
  3413. * speed and return an error.
  3414. *
  3415. * Returns:
  3416. * zero if val saved.
  3417. * -EINVAL val out of range
  3418. **/
  3419. static int
  3420. lpfc_link_speed_init(struct lpfc_hba *phba, int val)
  3421. {
  3422. if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
  3423. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3424. "3111 lpfc_link_speed of %d cannot "
  3425. "support loop mode, setting topology to default.\n",
  3426. val);
  3427. phba->cfg_topology = 0;
  3428. }
  3429. if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
  3430. (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
  3431. phba->cfg_link_speed = val;
  3432. return 0;
  3433. }
  3434. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3435. "0405 lpfc_link_speed attribute cannot "
  3436. "be set to %d, allowed values are "
  3437. "["LPFC_LINK_SPEED_STRING"]\n", val);
  3438. phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
  3439. return -EINVAL;
  3440. }
  3441. static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
  3442. lpfc_link_speed_show, lpfc_link_speed_store);
  3443. /*
  3444. # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
  3445. # 0 = aer disabled or not supported
  3446. # 1 = aer supported and enabled (default)
  3447. # Value range is [0,1]. Default value is 1.
  3448. */
  3449. /**
  3450. * lpfc_aer_support_store - Set the adapter for aer support
  3451. *
  3452. * @dev: class device that is converted into a Scsi_host.
  3453. * @attr: device attribute, not used.
  3454. * @buf: containing enable or disable aer flag.
  3455. * @count: unused variable.
  3456. *
  3457. * Description:
  3458. * If the val is 1 and currently the device's AER capability was not
  3459. * enabled, invoke the kernel's enable AER helper routine, trying to
  3460. * enable the device's AER capability. If the helper routine enabling
  3461. * AER returns success, update the device's cfg_aer_support flag to
  3462. * indicate AER is supported by the device; otherwise, if the device
  3463. * AER capability is already enabled to support AER, then do nothing.
  3464. *
  3465. * If the val is 0 and currently the device's AER support was enabled,
  3466. * invoke the kernel's disable AER helper routine. After that, update
  3467. * the device's cfg_aer_support flag to indicate AER is not supported
  3468. * by the device; otherwise, if the device AER capability is already
  3469. * disabled from supporting AER, then do nothing.
  3470. *
  3471. * Returns:
  3472. * length of the buf on success if val is in range the intended mode
  3473. * is supported.
  3474. * -EINVAL if val out of range or intended mode is not supported.
  3475. **/
  3476. static ssize_t
  3477. lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
  3478. const char *buf, size_t count)
  3479. {
  3480. struct Scsi_Host *shost = class_to_shost(dev);
  3481. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  3482. struct lpfc_hba *phba = vport->phba;
  3483. int val = 0, rc = -EINVAL;
  3484. if (!isdigit(buf[0]))
  3485. return -EINVAL;
  3486. if (sscanf(buf, "%i", &val) != 1)
  3487. return -EINVAL;
  3488. switch (val) {
  3489. case 0:
  3490. if (phba->hba_flag & HBA_AER_ENABLED) {
  3491. rc = pci_disable_pcie_error_reporting(phba->pcidev);
  3492. if (!rc) {
  3493. spin_lock_irq(&phba->hbalock);
  3494. phba->hba_flag &= ~HBA_AER_ENABLED;
  3495. spin_unlock_irq(&phba->hbalock);
  3496. phba->cfg_aer_support = 0;
  3497. rc = strlen(buf);
  3498. } else
  3499. rc = -EPERM;
  3500. } else {
  3501. phba->cfg_aer_support = 0;
  3502. rc = strlen(buf);
  3503. }
  3504. break;
  3505. case 1:
  3506. if (!(phba->hba_flag & HBA_AER_ENABLED)) {
  3507. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3508. if (!rc) {
  3509. spin_lock_irq(&phba->hbalock);
  3510. phba->hba_flag |= HBA_AER_ENABLED;
  3511. spin_unlock_irq(&phba->hbalock);
  3512. phba->cfg_aer_support = 1;
  3513. rc = strlen(buf);
  3514. } else
  3515. rc = -EPERM;
  3516. } else {
  3517. phba->cfg_aer_support = 1;
  3518. rc = strlen(buf);
  3519. }
  3520. break;
  3521. default:
  3522. rc = -EINVAL;
  3523. break;
  3524. }
  3525. return rc;
  3526. }
  3527. static int lpfc_aer_support = 1;
  3528. module_param(lpfc_aer_support, int, S_IRUGO);
  3529. MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
  3530. lpfc_param_show(aer_support)
  3531. /**
  3532. * lpfc_aer_support_init - Set the initial adapters aer support flag
  3533. * @phba: lpfc_hba pointer.
  3534. * @val: enable aer or disable aer flag.
  3535. *
  3536. * Description:
  3537. * If val is in a valid range [0,1], then set the adapter's initial
  3538. * cfg_aer_support field. It will be up to the driver's probe_one
  3539. * routine to determine whether the device's AER support can be set
  3540. * or not.
  3541. *
  3542. * Notes:
  3543. * If the value is not in range log a kernel error message, and
  3544. * choose the default value of setting AER support and return.
  3545. *
  3546. * Returns:
  3547. * zero if val saved.
  3548. * -EINVAL val out of range
  3549. **/
  3550. static int
  3551. lpfc_aer_support_init(struct lpfc_hba *phba, int val)
  3552. {
  3553. if (val == 0 || val == 1) {
  3554. phba->cfg_aer_support = val;
  3555. return 0;
  3556. }
  3557. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3558. "2712 lpfc_aer_support attribute value %d out "
  3559. "of range, allowed values are 0|1, setting it "
  3560. "to default value of 1\n", val);
  3561. /* By default, try to enable AER on a device */
  3562. phba->cfg_aer_support = 1;
  3563. return -EINVAL;
  3564. }
  3565. static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
  3566. lpfc_aer_support_show, lpfc_aer_support_store);
  3567. /**
  3568. * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
  3569. * @dev: class device that is converted into a Scsi_host.
  3570. * @attr: device attribute, not used.
  3571. * @buf: containing flag 1 for aer cleanup state.
  3572. * @count: unused variable.
  3573. *
  3574. * Description:
  3575. * If the @buf contains 1 and the device currently has the AER support
  3576. * enabled, then invokes the kernel AER helper routine
  3577. * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
  3578. * error status register.
  3579. *
  3580. * Notes:
  3581. *
  3582. * Returns:
  3583. * -EINVAL if the buf does not contain the 1 or the device is not currently
  3584. * enabled with the AER support.
  3585. **/
  3586. static ssize_t
  3587. lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
  3588. const char *buf, size_t count)
  3589. {
  3590. struct Scsi_Host *shost = class_to_shost(dev);
  3591. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3592. struct lpfc_hba *phba = vport->phba;
  3593. int val, rc = -1;
  3594. if (!isdigit(buf[0]))
  3595. return -EINVAL;
  3596. if (sscanf(buf, "%i", &val) != 1)
  3597. return -EINVAL;
  3598. if (val != 1)
  3599. return -EINVAL;
  3600. if (phba->hba_flag & HBA_AER_ENABLED)
  3601. rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
  3602. if (rc == 0)
  3603. return strlen(buf);
  3604. else
  3605. return -EPERM;
  3606. }
  3607. static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
  3608. lpfc_aer_cleanup_state);
  3609. /**
  3610. * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
  3611. *
  3612. * @dev: class device that is converted into a Scsi_host.
  3613. * @attr: device attribute, not used.
  3614. * @buf: containing the string the number of vfs to be enabled.
  3615. * @count: unused variable.
  3616. *
  3617. * Description:
  3618. * When this api is called either through user sysfs, the driver shall
  3619. * try to enable or disable SR-IOV virtual functions according to the
  3620. * following:
  3621. *
  3622. * If zero virtual function has been enabled to the physical function,
  3623. * the driver shall invoke the pci enable virtual function api trying
  3624. * to enable the virtual functions. If the nr_vfn provided is greater
  3625. * than the maximum supported, the maximum virtual function number will
  3626. * be used for invoking the api; otherwise, the nr_vfn provided shall
  3627. * be used for invoking the api. If the api call returned success, the
  3628. * actual number of virtual functions enabled will be set to the driver
  3629. * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
  3630. * cfg_sriov_nr_virtfn remains zero.
  3631. *
  3632. * If none-zero virtual functions have already been enabled to the
  3633. * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
  3634. * -EINVAL will be returned and the driver does nothing;
  3635. *
  3636. * If the nr_vfn provided is zero and none-zero virtual functions have
  3637. * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
  3638. * disabling virtual function api shall be invoded to disable all the
  3639. * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
  3640. * zero. Otherwise, if zero virtual function has been enabled, do
  3641. * nothing.
  3642. *
  3643. * Returns:
  3644. * length of the buf on success if val is in range the intended mode
  3645. * is supported.
  3646. * -EINVAL if val out of range or intended mode is not supported.
  3647. **/
  3648. static ssize_t
  3649. lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
  3650. const char *buf, size_t count)
  3651. {
  3652. struct Scsi_Host *shost = class_to_shost(dev);
  3653. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  3654. struct lpfc_hba *phba = vport->phba;
  3655. struct pci_dev *pdev = phba->pcidev;
  3656. int val = 0, rc = -EINVAL;
  3657. /* Sanity check on user data */
  3658. if (!isdigit(buf[0]))
  3659. return -EINVAL;
  3660. if (sscanf(buf, "%i", &val) != 1)
  3661. return -EINVAL;
  3662. if (val < 0)
  3663. return -EINVAL;
  3664. /* Request disabling virtual functions */
  3665. if (val == 0) {
  3666. if (phba->cfg_sriov_nr_virtfn > 0) {
  3667. pci_disable_sriov(pdev);
  3668. phba->cfg_sriov_nr_virtfn = 0;
  3669. }
  3670. return strlen(buf);
  3671. }
  3672. /* Request enabling virtual functions */
  3673. if (phba->cfg_sriov_nr_virtfn > 0) {
  3674. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3675. "3018 There are %d virtual functions "
  3676. "enabled on physical function.\n",
  3677. phba->cfg_sriov_nr_virtfn);
  3678. return -EEXIST;
  3679. }
  3680. if (val <= LPFC_MAX_VFN_PER_PFN)
  3681. phba->cfg_sriov_nr_virtfn = val;
  3682. else {
  3683. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3684. "3019 Enabling %d virtual functions is not "
  3685. "allowed.\n", val);
  3686. return -EINVAL;
  3687. }
  3688. rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
  3689. if (rc) {
  3690. phba->cfg_sriov_nr_virtfn = 0;
  3691. rc = -EPERM;
  3692. } else
  3693. rc = strlen(buf);
  3694. return rc;
  3695. }
  3696. static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
  3697. module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
  3698. MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
  3699. lpfc_param_show(sriov_nr_virtfn)
  3700. /**
  3701. * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
  3702. * @phba: lpfc_hba pointer.
  3703. * @val: link speed value.
  3704. *
  3705. * Description:
  3706. * If val is in a valid range [0,255], then set the adapter's initial
  3707. * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
  3708. * number shall be used instead. It will be up to the driver's probe_one
  3709. * routine to determine whether the device's SR-IOV is supported or not.
  3710. *
  3711. * Returns:
  3712. * zero if val saved.
  3713. * -EINVAL val out of range
  3714. **/
  3715. static int
  3716. lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
  3717. {
  3718. if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
  3719. phba->cfg_sriov_nr_virtfn = val;
  3720. return 0;
  3721. }
  3722. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3723. "3017 Enabling %d virtual functions is not "
  3724. "allowed.\n", val);
  3725. return -EINVAL;
  3726. }
  3727. static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
  3728. lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
  3729. /**
  3730. * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
  3731. *
  3732. * @dev: class device that is converted into a Scsi_host.
  3733. * @attr: device attribute, not used.
  3734. * @buf: containing the string the number of vfs to be enabled.
  3735. * @count: unused variable.
  3736. *
  3737. * Description:
  3738. *
  3739. * Returns:
  3740. * length of the buf on success if val is in range the intended mode
  3741. * is supported.
  3742. * -EINVAL if val out of range or intended mode is not supported.
  3743. **/
  3744. static ssize_t
  3745. lpfc_request_firmware_upgrade_store(struct device *dev,
  3746. struct device_attribute *attr,
  3747. const char *buf, size_t count)
  3748. {
  3749. struct Scsi_Host *shost = class_to_shost(dev);
  3750. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  3751. struct lpfc_hba *phba = vport->phba;
  3752. int val = 0, rc = -EINVAL;
  3753. /* Sanity check on user data */
  3754. if (!isdigit(buf[0]))
  3755. return -EINVAL;
  3756. if (sscanf(buf, "%i", &val) != 1)
  3757. return -EINVAL;
  3758. if (val != 1)
  3759. return -EINVAL;
  3760. rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
  3761. if (rc)
  3762. rc = -EPERM;
  3763. else
  3764. rc = strlen(buf);
  3765. return rc;
  3766. }
  3767. static int lpfc_req_fw_upgrade;
  3768. module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
  3769. MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
  3770. lpfc_param_show(request_firmware_upgrade)
  3771. /**
  3772. * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
  3773. * @phba: lpfc_hba pointer.
  3774. * @val: 0 or 1.
  3775. *
  3776. * Description:
  3777. * Set the initial Linux generic firmware upgrade enable or disable flag.
  3778. *
  3779. * Returns:
  3780. * zero if val saved.
  3781. * -EINVAL val out of range
  3782. **/
  3783. static int
  3784. lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
  3785. {
  3786. if (val >= 0 && val <= 1) {
  3787. phba->cfg_request_firmware_upgrade = val;
  3788. return 0;
  3789. }
  3790. return -EINVAL;
  3791. }
  3792. static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
  3793. lpfc_request_firmware_upgrade_show,
  3794. lpfc_request_firmware_upgrade_store);
  3795. /**
  3796. * lpfc_fcp_imax_store
  3797. *
  3798. * @dev: class device that is converted into a Scsi_host.
  3799. * @attr: device attribute, not used.
  3800. * @buf: string with the number of fast-path FCP interrupts per second.
  3801. * @count: unused variable.
  3802. *
  3803. * Description:
  3804. * If val is in a valid range [636,651042], then set the adapter's
  3805. * maximum number of fast-path FCP interrupts per second.
  3806. *
  3807. * Returns:
  3808. * length of the buf on success if val is in range the intended mode
  3809. * is supported.
  3810. * -EINVAL if val out of range or intended mode is not supported.
  3811. **/
  3812. static ssize_t
  3813. lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
  3814. const char *buf, size_t count)
  3815. {
  3816. struct Scsi_Host *shost = class_to_shost(dev);
  3817. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  3818. struct lpfc_hba *phba = vport->phba;
  3819. int val = 0, i;
  3820. /* fcp_imax is only valid for SLI4 */
  3821. if (phba->sli_rev != LPFC_SLI_REV4)
  3822. return -EINVAL;
  3823. /* Sanity check on user data */
  3824. if (!isdigit(buf[0]))
  3825. return -EINVAL;
  3826. if (sscanf(buf, "%i", &val) != 1)
  3827. return -EINVAL;
  3828. /*
  3829. * Value range for the HBA is [5000,5000000]
  3830. * The value for each EQ depends on how many EQs are configured.
  3831. */
  3832. if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
  3833. return -EINVAL;
  3834. phba->cfg_fcp_imax = (uint32_t)val;
  3835. for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
  3836. lpfc_modify_fcp_eq_delay(phba, i);
  3837. return strlen(buf);
  3838. }
  3839. /*
  3840. # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
  3841. # for the HBA.
  3842. #
  3843. # Value range is [5,000 to 5,000,000]. Default value is 50,000.
  3844. */
  3845. static int lpfc_fcp_imax = LPFC_DEF_IMAX;
  3846. module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
  3847. MODULE_PARM_DESC(lpfc_fcp_imax,
  3848. "Set the maximum number of FCP interrupts per second per HBA");
  3849. lpfc_param_show(fcp_imax)
  3850. /**
  3851. * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
  3852. * @phba: lpfc_hba pointer.
  3853. * @val: link speed value.
  3854. *
  3855. * Description:
  3856. * If val is in a valid range [636,651042], then initialize the adapter's
  3857. * maximum number of fast-path FCP interrupts per second.
  3858. *
  3859. * Returns:
  3860. * zero if val saved.
  3861. * -EINVAL val out of range
  3862. **/
  3863. static int
  3864. lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
  3865. {
  3866. if (phba->sli_rev != LPFC_SLI_REV4) {
  3867. phba->cfg_fcp_imax = 0;
  3868. return 0;
  3869. }
  3870. if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
  3871. phba->cfg_fcp_imax = val;
  3872. return 0;
  3873. }
  3874. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3875. "3016 fcp_imax: %d out of range, using default\n", val);
  3876. phba->cfg_fcp_imax = LPFC_DEF_IMAX;
  3877. return 0;
  3878. }
  3879. static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
  3880. lpfc_fcp_imax_show, lpfc_fcp_imax_store);
  3881. /**
  3882. * lpfc_state_show - Display current driver CPU affinity
  3883. * @dev: class converted to a Scsi_host structure.
  3884. * @attr: device attribute, not used.
  3885. * @buf: on return contains text describing the state of the link.
  3886. *
  3887. * Returns: size of formatted string.
  3888. **/
  3889. static ssize_t
  3890. lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
  3891. char *buf)
  3892. {
  3893. struct Scsi_Host *shost = class_to_shost(dev);
  3894. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  3895. struct lpfc_hba *phba = vport->phba;
  3896. struct lpfc_vector_map_info *cpup;
  3897. int len = 0;
  3898. if ((phba->sli_rev != LPFC_SLI_REV4) ||
  3899. (phba->intr_type != MSIX))
  3900. return len;
  3901. switch (phba->cfg_fcp_cpu_map) {
  3902. case 0:
  3903. len += snprintf(buf + len, PAGE_SIZE-len,
  3904. "fcp_cpu_map: No mapping (%d)\n",
  3905. phba->cfg_fcp_cpu_map);
  3906. return len;
  3907. case 1:
  3908. len += snprintf(buf + len, PAGE_SIZE-len,
  3909. "fcp_cpu_map: HBA centric mapping (%d): "
  3910. "%d online CPUs\n",
  3911. phba->cfg_fcp_cpu_map,
  3912. phba->sli4_hba.num_online_cpu);
  3913. break;
  3914. case 2:
  3915. len += snprintf(buf + len, PAGE_SIZE-len,
  3916. "fcp_cpu_map: Driver centric mapping (%d): "
  3917. "%d online CPUs\n",
  3918. phba->cfg_fcp_cpu_map,
  3919. phba->sli4_hba.num_online_cpu);
  3920. break;
  3921. }
  3922. while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
  3923. cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
  3924. /* margin should fit in this and the truncated message */
  3925. if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
  3926. len += snprintf(buf + len, PAGE_SIZE-len,
  3927. "CPU %02d io_chan %02d "
  3928. "physid %d coreid %d\n",
  3929. phba->sli4_hba.curr_disp_cpu,
  3930. cpup->channel_id, cpup->phys_id,
  3931. cpup->core_id);
  3932. else
  3933. len += snprintf(buf + len, PAGE_SIZE-len,
  3934. "CPU %02d io_chan %02d "
  3935. "physid %d coreid %d IRQ %d\n",
  3936. phba->sli4_hba.curr_disp_cpu,
  3937. cpup->channel_id, cpup->phys_id,
  3938. cpup->core_id, cpup->irq);
  3939. phba->sli4_hba.curr_disp_cpu++;
  3940. /* display max number of CPUs keeping some margin */
  3941. if (phba->sli4_hba.curr_disp_cpu <
  3942. phba->sli4_hba.num_present_cpu &&
  3943. (len >= (PAGE_SIZE - 64))) {
  3944. len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
  3945. break;
  3946. }
  3947. }
  3948. if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
  3949. phba->sli4_hba.curr_disp_cpu = 0;
  3950. return len;
  3951. }
  3952. /**
  3953. * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
  3954. * @dev: class device that is converted into a Scsi_host.
  3955. * @attr: device attribute, not used.
  3956. * @buf: one or more lpfc_polling_flags values.
  3957. * @count: not used.
  3958. *
  3959. * Returns:
  3960. * -EINVAL - Not implemented yet.
  3961. **/
  3962. static ssize_t
  3963. lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
  3964. const char *buf, size_t count)
  3965. {
  3966. int status = -EINVAL;
  3967. return status;
  3968. }
  3969. /*
  3970. # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
  3971. # for the HBA.
  3972. #
  3973. # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
  3974. # 0 - Do not affinitze IRQ vectors
  3975. # 1 - Affintize HBA vectors with respect to each HBA
  3976. # (start with CPU0 for each HBA)
  3977. # 2 - Affintize HBA vectors with respect to the entire driver
  3978. # (round robin thru all CPUs across all HBAs)
  3979. */
  3980. static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
  3981. module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
  3982. MODULE_PARM_DESC(lpfc_fcp_cpu_map,
  3983. "Defines how to map CPUs to IRQ vectors per HBA");
  3984. /**
  3985. * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
  3986. * @phba: lpfc_hba pointer.
  3987. * @val: link speed value.
  3988. *
  3989. * Description:
  3990. * If val is in a valid range [0-2], then affinitze the adapter's
  3991. * MSIX vectors.
  3992. *
  3993. * Returns:
  3994. * zero if val saved.
  3995. * -EINVAL val out of range
  3996. **/
  3997. static int
  3998. lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
  3999. {
  4000. if (phba->sli_rev != LPFC_SLI_REV4) {
  4001. phba->cfg_fcp_cpu_map = 0;
  4002. return 0;
  4003. }
  4004. if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
  4005. phba->cfg_fcp_cpu_map = val;
  4006. return 0;
  4007. }
  4008. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4009. "3326 fcp_cpu_map: %d out of range, using default\n",
  4010. val);
  4011. phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
  4012. return 0;
  4013. }
  4014. static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
  4015. lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
  4016. /*
  4017. # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
  4018. # Value range is [2,3]. Default value is 3.
  4019. */
  4020. LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
  4021. "Select Fibre Channel class of service for FCP sequences");
  4022. /*
  4023. # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
  4024. # is [0,1]. Default value is 0.
  4025. */
  4026. LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
  4027. "Use ADISC on rediscovery to authenticate FCP devices");
  4028. /*
  4029. # lpfc_first_burst_size: First burst size to use on the NPorts
  4030. # that support first burst.
  4031. # Value range is [0,65536]. Default value is 0.
  4032. */
  4033. LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
  4034. "First burst size for Targets that support first burst");
  4035. /*
  4036. # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
  4037. # depth. Default value is 0. When the value of this parameter is zero the
  4038. # SCSI command completion time is not used for controlling I/O queue depth. When
  4039. # the parameter is set to a non-zero value, the I/O queue depth is controlled
  4040. # to limit the I/O completion time to the parameter value.
  4041. # The value is set in milliseconds.
  4042. */
  4043. static int lpfc_max_scsicmpl_time;
  4044. module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
  4045. MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
  4046. "Use command completion time to control queue depth");
  4047. lpfc_vport_param_show(max_scsicmpl_time);
  4048. lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
  4049. static int
  4050. lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
  4051. {
  4052. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4053. struct lpfc_nodelist *ndlp, *next_ndlp;
  4054. if (val == vport->cfg_max_scsicmpl_time)
  4055. return 0;
  4056. if ((val < 0) || (val > 60000))
  4057. return -EINVAL;
  4058. vport->cfg_max_scsicmpl_time = val;
  4059. spin_lock_irq(shost->host_lock);
  4060. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  4061. if (!NLP_CHK_NODE_ACT(ndlp))
  4062. continue;
  4063. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  4064. continue;
  4065. ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
  4066. }
  4067. spin_unlock_irq(shost->host_lock);
  4068. return 0;
  4069. }
  4070. lpfc_vport_param_store(max_scsicmpl_time);
  4071. static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
  4072. lpfc_max_scsicmpl_time_show,
  4073. lpfc_max_scsicmpl_time_store);
  4074. /*
  4075. # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
  4076. # range is [0,1]. Default value is 0.
  4077. */
  4078. LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
  4079. /*
  4080. # lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
  4081. # range is [0,1]. Default value is 0.
  4082. # For [0], FCP commands are issued to Work Queues ina round robin fashion.
  4083. # For [1], FCP commands are issued to a Work Queue associated with the
  4084. # current CPU.
  4085. # It would be set to 1 by the driver if it's able to set up cpu affinity
  4086. # for FCP I/Os through Work Queue associated with the current CPU. Otherwise,
  4087. # roundrobin scheduling of FCP I/Os through WQs will be used.
  4088. */
  4089. LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algorithm for "
  4090. "issuing commands [0] - Round Robin, [1] - Current CPU");
  4091. /*
  4092. # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
  4093. # range is [0,1]. Default value is 0.
  4094. # For [0], bus reset issues target reset to ALL devices
  4095. # For [1], bus reset issues target reset to non-FCP2 devices
  4096. */
  4097. LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
  4098. "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
  4099. /*
  4100. # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
  4101. # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
  4102. # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
  4103. # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
  4104. # cr_delay is set to 0.
  4105. */
  4106. LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
  4107. "interrupt response is generated");
  4108. LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
  4109. "interrupt response is generated");
  4110. /*
  4111. # lpfc_multi_ring_support: Determines how many rings to spread available
  4112. # cmd/rsp IOCB entries across.
  4113. # Value range is [1,2]. Default value is 1.
  4114. */
  4115. LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
  4116. "SLI rings to spread IOCB entries across");
  4117. /*
  4118. # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
  4119. # identifies what rctl value to configure the additional ring for.
  4120. # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
  4121. */
  4122. LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
  4123. 255, "Identifies RCTL for additional ring configuration");
  4124. /*
  4125. # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
  4126. # identifies what type value to configure the additional ring for.
  4127. # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
  4128. */
  4129. LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
  4130. 255, "Identifies TYPE for additional ring configuration");
  4131. /*
  4132. # lpfc_fdmi_on: controls FDMI support.
  4133. # Set NOT Set
  4134. # bit 0 = FDMI support no FDMI support
  4135. # LPFC_FDMI_SUPPORT just turns basic support on/off
  4136. # bit 1 = Register delay no register delay (60 seconds)
  4137. # LPFC_FDMI_REG_DELAY 60 sec registration delay after FDMI login
  4138. # bit 2 = All attributes Use a attribute subset
  4139. # LPFC_FDMI_ALL_ATTRIB applies to both port and HBA attributes
  4140. # Port attrutes subset: 1 thru 6 OR all: 1 thru 0xd 0x101 0x102 0x103
  4141. # HBA attributes subset: 1 thru 0xb OR all: 1 thru 0xc
  4142. # Value range [0,7]. Default value is 0.
  4143. */
  4144. LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 7, "Enable FDMI support");
  4145. /*
  4146. # Specifies the maximum number of ELS cmds we can have outstanding (for
  4147. # discovery). Value range is [1,64]. Default value = 32.
  4148. */
  4149. LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
  4150. "during discovery");
  4151. /*
  4152. # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
  4153. # will be scanned by the SCSI midlayer when sequential scanning is
  4154. # used; and is also the highest LUN ID allowed when the SCSI midlayer
  4155. # parses REPORT_LUN responses. The lpfc driver has no LUN count or
  4156. # LUN ID limit, but the SCSI midlayer requires this field for the uses
  4157. # above. The lpfc driver limits the default value to 255 for two reasons.
  4158. # As it bounds the sequential scan loop, scanning for thousands of luns
  4159. # on a target can take minutes of wall clock time. Additionally,
  4160. # there are FC targets, such as JBODs, that only recognize 8-bits of
  4161. # LUN ID. When they receive a value greater than 8 bits, they chop off
  4162. # the high order bits. In other words, they see LUN IDs 0, 256, 512,
  4163. # and so on all as LUN ID 0. This causes the linux kernel, which sees
  4164. # valid responses at each of the LUN IDs, to believe there are multiple
  4165. # devices present, when in fact, there is only 1.
  4166. # A customer that is aware of their target behaviors, and the results as
  4167. # indicated above, is welcome to increase the lpfc_max_luns value.
  4168. # As mentioned, this value is not used by the lpfc driver, only the
  4169. # SCSI midlayer.
  4170. # Value range is [0,65535]. Default value is 255.
  4171. # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
  4172. */
  4173. LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
  4174. /*
  4175. # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
  4176. # Value range is [1,255], default value is 10.
  4177. */
  4178. LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
  4179. "Milliseconds driver will wait between polling FCP ring");
  4180. /*
  4181. # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
  4182. # to complete in seconds. Value range is [5,180], default value is 60.
  4183. */
  4184. LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
  4185. "Maximum time to wait for task management commands to complete");
  4186. /*
  4187. # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
  4188. # support this feature
  4189. # 0 = MSI disabled
  4190. # 1 = MSI enabled
  4191. # 2 = MSI-X enabled (default)
  4192. # Value range is [0,2]. Default value is 2.
  4193. */
  4194. LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
  4195. "MSI-X (2), if possible");
  4196. /*
  4197. # lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
  4198. #
  4199. # Value range is [1,7]. Default value is 4.
  4200. */
  4201. LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
  4202. LPFC_FCP_IO_CHAN_MAX,
  4203. "Set the number of FCP I/O channels");
  4204. /*
  4205. # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
  4206. # 0 = HBA resets disabled
  4207. # 1 = HBA resets enabled (default)
  4208. # Value range is [0,1]. Default value is 1.
  4209. */
  4210. LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
  4211. /*
  4212. # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
  4213. # 0 = HBA Heartbeat disabled
  4214. # 1 = HBA Heartbeat enabled (default)
  4215. # Value range is [0,1]. Default value is 1.
  4216. */
  4217. LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
  4218. /*
  4219. # lpfc_EnableXLane: Enable Express Lane Feature
  4220. # 0x0 Express Lane Feature disabled
  4221. # 0x1 Express Lane Feature enabled
  4222. # Value range is [0,1]. Default value is 0.
  4223. */
  4224. LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
  4225. /*
  4226. # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
  4227. # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
  4228. # Value range is [0x0,0x7f]. Default value is 0
  4229. */
  4230. LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
  4231. /*
  4232. # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
  4233. # 0 = BlockGuard disabled (default)
  4234. # 1 = BlockGuard enabled
  4235. # Value range is [0,1]. Default value is 0.
  4236. */
  4237. LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
  4238. /*
  4239. # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
  4240. # 0 = disabled (default)
  4241. # 1 = enabled
  4242. # Value range is [0,1]. Default value is 0.
  4243. #
  4244. # This feature in under investigation and may be supported in the future.
  4245. */
  4246. unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
  4247. /*
  4248. # lpfc_prot_mask: i
  4249. # - Bit mask of host protection capabilities used to register with the
  4250. # SCSI mid-layer
  4251. # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
  4252. # - Allows you to ultimately specify which profiles to use
  4253. # - Default will result in registering capabilities for all profiles.
  4254. # - SHOST_DIF_TYPE1_PROTECTION 1
  4255. # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
  4256. # - SHOST_DIX_TYPE0_PROTECTION 8
  4257. # HBA supports DIX Type 0: Host to HBA protection only
  4258. # - SHOST_DIX_TYPE1_PROTECTION 16
  4259. # HBA supports DIX Type 1: Host to HBA Type 1 protection
  4260. #
  4261. */
  4262. unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
  4263. SHOST_DIX_TYPE0_PROTECTION |
  4264. SHOST_DIX_TYPE1_PROTECTION;
  4265. module_param(lpfc_prot_mask, uint, S_IRUGO);
  4266. MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
  4267. /*
  4268. # lpfc_prot_guard: i
  4269. # - Bit mask of protection guard types to register with the SCSI mid-layer
  4270. # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
  4271. # - Allows you to ultimately specify which profiles to use
  4272. # - Default will result in registering capabilities for all guard types
  4273. #
  4274. */
  4275. unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
  4276. module_param(lpfc_prot_guard, byte, S_IRUGO);
  4277. MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
  4278. /*
  4279. * Delay initial NPort discovery when Clean Address bit is cleared in
  4280. * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
  4281. * This parameter can have value 0 or 1.
  4282. * When this parameter is set to 0, no delay is added to the initial
  4283. * discovery.
  4284. * When this parameter is set to non-zero value, initial Nport discovery is
  4285. * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
  4286. * accept and FCID/Fabric name/Fabric portname is changed.
  4287. * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
  4288. * when Clean Address bit is cleared in FLOGI/FDISC
  4289. * accept and FCID/Fabric name/Fabric portname is changed.
  4290. * Default value is 0.
  4291. */
  4292. int lpfc_delay_discovery;
  4293. module_param(lpfc_delay_discovery, int, S_IRUGO);
  4294. MODULE_PARM_DESC(lpfc_delay_discovery,
  4295. "Delay NPort discovery when Clean Address bit is cleared. "
  4296. "Allowed values: 0,1.");
  4297. /*
  4298. * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
  4299. * This value can be set to values between 64 and 4096. The default value is
  4300. * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
  4301. * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
  4302. * Because of the additional overhead involved in setting up T10-DIF,
  4303. * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
  4304. * and will be limited to 512 if BlockGuard is enabled under SLI3.
  4305. */
  4306. LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
  4307. LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
  4308. /*
  4309. * This parameter will be depricated, the driver cannot limit the
  4310. * protection data s/g list.
  4311. */
  4312. LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
  4313. LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
  4314. "Max Protection Scatter Gather Segment Count");
  4315. struct device_attribute *lpfc_hba_attrs[] = {
  4316. &dev_attr_bg_info,
  4317. &dev_attr_bg_guard_err,
  4318. &dev_attr_bg_apptag_err,
  4319. &dev_attr_bg_reftag_err,
  4320. &dev_attr_info,
  4321. &dev_attr_serialnum,
  4322. &dev_attr_modeldesc,
  4323. &dev_attr_modelname,
  4324. &dev_attr_programtype,
  4325. &dev_attr_portnum,
  4326. &dev_attr_fwrev,
  4327. &dev_attr_hdw,
  4328. &dev_attr_option_rom_version,
  4329. &dev_attr_link_state,
  4330. &dev_attr_num_discovered_ports,
  4331. &dev_attr_menlo_mgmt_mode,
  4332. &dev_attr_lpfc_drvr_version,
  4333. &dev_attr_lpfc_enable_fip,
  4334. &dev_attr_lpfc_temp_sensor,
  4335. &dev_attr_lpfc_log_verbose,
  4336. &dev_attr_lpfc_lun_queue_depth,
  4337. &dev_attr_lpfc_tgt_queue_depth,
  4338. &dev_attr_lpfc_hba_queue_depth,
  4339. &dev_attr_lpfc_peer_port_login,
  4340. &dev_attr_lpfc_nodev_tmo,
  4341. &dev_attr_lpfc_devloss_tmo,
  4342. &dev_attr_lpfc_fcp_class,
  4343. &dev_attr_lpfc_use_adisc,
  4344. &dev_attr_lpfc_first_burst_size,
  4345. &dev_attr_lpfc_ack0,
  4346. &dev_attr_lpfc_topology,
  4347. &dev_attr_lpfc_scan_down,
  4348. &dev_attr_lpfc_link_speed,
  4349. &dev_attr_lpfc_fcp_io_sched,
  4350. &dev_attr_lpfc_fcp2_no_tgt_reset,
  4351. &dev_attr_lpfc_cr_delay,
  4352. &dev_attr_lpfc_cr_count,
  4353. &dev_attr_lpfc_multi_ring_support,
  4354. &dev_attr_lpfc_multi_ring_rctl,
  4355. &dev_attr_lpfc_multi_ring_type,
  4356. &dev_attr_lpfc_fdmi_on,
  4357. &dev_attr_lpfc_max_luns,
  4358. &dev_attr_lpfc_enable_npiv,
  4359. &dev_attr_lpfc_fcf_failover_policy,
  4360. &dev_attr_lpfc_enable_rrq,
  4361. &dev_attr_nport_evt_cnt,
  4362. &dev_attr_board_mode,
  4363. &dev_attr_max_vpi,
  4364. &dev_attr_used_vpi,
  4365. &dev_attr_max_rpi,
  4366. &dev_attr_used_rpi,
  4367. &dev_attr_max_xri,
  4368. &dev_attr_used_xri,
  4369. &dev_attr_npiv_info,
  4370. &dev_attr_issue_reset,
  4371. &dev_attr_lpfc_poll,
  4372. &dev_attr_lpfc_poll_tmo,
  4373. &dev_attr_lpfc_task_mgmt_tmo,
  4374. &dev_attr_lpfc_use_msi,
  4375. &dev_attr_lpfc_fcp_imax,
  4376. &dev_attr_lpfc_fcp_cpu_map,
  4377. &dev_attr_lpfc_fcp_io_channel,
  4378. &dev_attr_lpfc_enable_bg,
  4379. &dev_attr_lpfc_soft_wwnn,
  4380. &dev_attr_lpfc_soft_wwpn,
  4381. &dev_attr_lpfc_soft_wwn_enable,
  4382. &dev_attr_lpfc_enable_hba_reset,
  4383. &dev_attr_lpfc_enable_hba_heartbeat,
  4384. &dev_attr_lpfc_EnableXLane,
  4385. &dev_attr_lpfc_XLanePriority,
  4386. &dev_attr_lpfc_xlane_lun,
  4387. &dev_attr_lpfc_xlane_tgt,
  4388. &dev_attr_lpfc_xlane_vpt,
  4389. &dev_attr_lpfc_xlane_lun_state,
  4390. &dev_attr_lpfc_xlane_lun_status,
  4391. &dev_attr_lpfc_sg_seg_cnt,
  4392. &dev_attr_lpfc_max_scsicmpl_time,
  4393. &dev_attr_lpfc_stat_data_ctrl,
  4394. &dev_attr_lpfc_prot_sg_seg_cnt,
  4395. &dev_attr_lpfc_aer_support,
  4396. &dev_attr_lpfc_aer_state_cleanup,
  4397. &dev_attr_lpfc_sriov_nr_virtfn,
  4398. &dev_attr_lpfc_req_fw_upgrade,
  4399. &dev_attr_lpfc_suppress_link_up,
  4400. &dev_attr_lpfc_iocb_cnt,
  4401. &dev_attr_iocb_hw,
  4402. &dev_attr_txq_hw,
  4403. &dev_attr_txcmplq_hw,
  4404. &dev_attr_lpfc_fips_level,
  4405. &dev_attr_lpfc_fips_rev,
  4406. &dev_attr_lpfc_dss,
  4407. &dev_attr_lpfc_sriov_hw_max_virtfn,
  4408. &dev_attr_protocol,
  4409. &dev_attr_lpfc_xlane_supported,
  4410. NULL,
  4411. };
  4412. struct device_attribute *lpfc_vport_attrs[] = {
  4413. &dev_attr_info,
  4414. &dev_attr_link_state,
  4415. &dev_attr_num_discovered_ports,
  4416. &dev_attr_lpfc_drvr_version,
  4417. &dev_attr_lpfc_log_verbose,
  4418. &dev_attr_lpfc_lun_queue_depth,
  4419. &dev_attr_lpfc_tgt_queue_depth,
  4420. &dev_attr_lpfc_nodev_tmo,
  4421. &dev_attr_lpfc_devloss_tmo,
  4422. &dev_attr_lpfc_hba_queue_depth,
  4423. &dev_attr_lpfc_peer_port_login,
  4424. &dev_attr_lpfc_restrict_login,
  4425. &dev_attr_lpfc_fcp_class,
  4426. &dev_attr_lpfc_use_adisc,
  4427. &dev_attr_lpfc_first_burst_size,
  4428. &dev_attr_lpfc_fdmi_on,
  4429. &dev_attr_lpfc_max_luns,
  4430. &dev_attr_nport_evt_cnt,
  4431. &dev_attr_npiv_info,
  4432. &dev_attr_lpfc_enable_da_id,
  4433. &dev_attr_lpfc_max_scsicmpl_time,
  4434. &dev_attr_lpfc_stat_data_ctrl,
  4435. &dev_attr_lpfc_static_vport,
  4436. &dev_attr_lpfc_fips_level,
  4437. &dev_attr_lpfc_fips_rev,
  4438. NULL,
  4439. };
  4440. /**
  4441. * sysfs_ctlreg_write - Write method for writing to ctlreg
  4442. * @filp: open sysfs file
  4443. * @kobj: kernel kobject that contains the kernel class device.
  4444. * @bin_attr: kernel attributes passed to us.
  4445. * @buf: contains the data to be written to the adapter IOREG space.
  4446. * @off: offset into buffer to beginning of data.
  4447. * @count: bytes to transfer.
  4448. *
  4449. * Description:
  4450. * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
  4451. * Uses the adapter io control registers to send buf contents to the adapter.
  4452. *
  4453. * Returns:
  4454. * -ERANGE off and count combo out of range
  4455. * -EINVAL off, count or buff address invalid
  4456. * -EPERM adapter is offline
  4457. * value of count, buf contents written
  4458. **/
  4459. static ssize_t
  4460. sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
  4461. struct bin_attribute *bin_attr,
  4462. char *buf, loff_t off, size_t count)
  4463. {
  4464. size_t buf_off;
  4465. struct device *dev = container_of(kobj, struct device, kobj);
  4466. struct Scsi_Host *shost = class_to_shost(dev);
  4467. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4468. struct lpfc_hba *phba = vport->phba;
  4469. if (phba->sli_rev >= LPFC_SLI_REV4)
  4470. return -EPERM;
  4471. if ((off + count) > FF_REG_AREA_SIZE)
  4472. return -ERANGE;
  4473. if (count <= LPFC_REG_WRITE_KEY_SIZE)
  4474. return 0;
  4475. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  4476. return -EINVAL;
  4477. /* This is to protect HBA registers from accidental writes. */
  4478. if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
  4479. return -EINVAL;
  4480. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  4481. return -EPERM;
  4482. spin_lock_irq(&phba->hbalock);
  4483. for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
  4484. buf_off += sizeof(uint32_t))
  4485. writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
  4486. phba->ctrl_regs_memmap_p + off + buf_off);
  4487. spin_unlock_irq(&phba->hbalock);
  4488. return count;
  4489. }
  4490. /**
  4491. * sysfs_ctlreg_read - Read method for reading from ctlreg
  4492. * @filp: open sysfs file
  4493. * @kobj: kernel kobject that contains the kernel class device.
  4494. * @bin_attr: kernel attributes passed to us.
  4495. * @buf: if successful contains the data from the adapter IOREG space.
  4496. * @off: offset into buffer to beginning of data.
  4497. * @count: bytes to transfer.
  4498. *
  4499. * Description:
  4500. * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
  4501. * Uses the adapter io control registers to read data into buf.
  4502. *
  4503. * Returns:
  4504. * -ERANGE off and count combo out of range
  4505. * -EINVAL off, count or buff address invalid
  4506. * value of count, buf contents read
  4507. **/
  4508. static ssize_t
  4509. sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
  4510. struct bin_attribute *bin_attr,
  4511. char *buf, loff_t off, size_t count)
  4512. {
  4513. size_t buf_off;
  4514. uint32_t * tmp_ptr;
  4515. struct device *dev = container_of(kobj, struct device, kobj);
  4516. struct Scsi_Host *shost = class_to_shost(dev);
  4517. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4518. struct lpfc_hba *phba = vport->phba;
  4519. if (phba->sli_rev >= LPFC_SLI_REV4)
  4520. return -EPERM;
  4521. if (off > FF_REG_AREA_SIZE)
  4522. return -ERANGE;
  4523. if ((off + count) > FF_REG_AREA_SIZE)
  4524. count = FF_REG_AREA_SIZE - off;
  4525. if (count == 0) return 0;
  4526. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  4527. return -EINVAL;
  4528. spin_lock_irq(&phba->hbalock);
  4529. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
  4530. tmp_ptr = (uint32_t *)(buf + buf_off);
  4531. *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
  4532. }
  4533. spin_unlock_irq(&phba->hbalock);
  4534. return count;
  4535. }
  4536. static struct bin_attribute sysfs_ctlreg_attr = {
  4537. .attr = {
  4538. .name = "ctlreg",
  4539. .mode = S_IRUSR | S_IWUSR,
  4540. },
  4541. .size = 256,
  4542. .read = sysfs_ctlreg_read,
  4543. .write = sysfs_ctlreg_write,
  4544. };
  4545. /**
  4546. * sysfs_mbox_write - Write method for writing information via mbox
  4547. * @filp: open sysfs file
  4548. * @kobj: kernel kobject that contains the kernel class device.
  4549. * @bin_attr: kernel attributes passed to us.
  4550. * @buf: contains the data to be written to sysfs mbox.
  4551. * @off: offset into buffer to beginning of data.
  4552. * @count: bytes to transfer.
  4553. *
  4554. * Description:
  4555. * Deprecated function. All mailbox access from user space is performed via the
  4556. * bsg interface.
  4557. *
  4558. * Returns:
  4559. * -EPERM operation not permitted
  4560. **/
  4561. static ssize_t
  4562. sysfs_mbox_write(struct file *filp, struct kobject *kobj,
  4563. struct bin_attribute *bin_attr,
  4564. char *buf, loff_t off, size_t count)
  4565. {
  4566. return -EPERM;
  4567. }
  4568. /**
  4569. * sysfs_mbox_read - Read method for reading information via mbox
  4570. * @filp: open sysfs file
  4571. * @kobj: kernel kobject that contains the kernel class device.
  4572. * @bin_attr: kernel attributes passed to us.
  4573. * @buf: contains the data to be read from sysfs mbox.
  4574. * @off: offset into buffer to beginning of data.
  4575. * @count: bytes to transfer.
  4576. *
  4577. * Description:
  4578. * Deprecated function. All mailbox access from user space is performed via the
  4579. * bsg interface.
  4580. *
  4581. * Returns:
  4582. * -EPERM operation not permitted
  4583. **/
  4584. static ssize_t
  4585. sysfs_mbox_read(struct file *filp, struct kobject *kobj,
  4586. struct bin_attribute *bin_attr,
  4587. char *buf, loff_t off, size_t count)
  4588. {
  4589. return -EPERM;
  4590. }
  4591. static struct bin_attribute sysfs_mbox_attr = {
  4592. .attr = {
  4593. .name = "mbox",
  4594. .mode = S_IRUSR | S_IWUSR,
  4595. },
  4596. .size = MAILBOX_SYSFS_MAX,
  4597. .read = sysfs_mbox_read,
  4598. .write = sysfs_mbox_write,
  4599. };
  4600. /**
  4601. * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
  4602. * @vport: address of lpfc vport structure.
  4603. *
  4604. * Return codes:
  4605. * zero on success
  4606. * error return code from sysfs_create_bin_file()
  4607. **/
  4608. int
  4609. lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
  4610. {
  4611. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4612. int error;
  4613. error = sysfs_create_bin_file(&shost->shost_dev.kobj,
  4614. &sysfs_drvr_stat_data_attr);
  4615. /* Virtual ports do not need ctrl_reg and mbox */
  4616. if (error || vport->port_type == LPFC_NPIV_PORT)
  4617. goto out;
  4618. error = sysfs_create_bin_file(&shost->shost_dev.kobj,
  4619. &sysfs_ctlreg_attr);
  4620. if (error)
  4621. goto out_remove_stat_attr;
  4622. error = sysfs_create_bin_file(&shost->shost_dev.kobj,
  4623. &sysfs_mbox_attr);
  4624. if (error)
  4625. goto out_remove_ctlreg_attr;
  4626. return 0;
  4627. out_remove_ctlreg_attr:
  4628. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
  4629. out_remove_stat_attr:
  4630. sysfs_remove_bin_file(&shost->shost_dev.kobj,
  4631. &sysfs_drvr_stat_data_attr);
  4632. out:
  4633. return error;
  4634. }
  4635. /**
  4636. * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
  4637. * @vport: address of lpfc vport structure.
  4638. **/
  4639. void
  4640. lpfc_free_sysfs_attr(struct lpfc_vport *vport)
  4641. {
  4642. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4643. sysfs_remove_bin_file(&shost->shost_dev.kobj,
  4644. &sysfs_drvr_stat_data_attr);
  4645. /* Virtual ports do not need ctrl_reg and mbox */
  4646. if (vport->port_type == LPFC_NPIV_PORT)
  4647. return;
  4648. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
  4649. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
  4650. }
  4651. /*
  4652. * Dynamic FC Host Attributes Support
  4653. */
  4654. /**
  4655. * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
  4656. * @shost: kernel scsi host pointer.
  4657. **/
  4658. static void
  4659. lpfc_get_host_port_id(struct Scsi_Host *shost)
  4660. {
  4661. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4662. /* note: fc_myDID already in cpu endianness */
  4663. fc_host_port_id(shost) = vport->fc_myDID;
  4664. }
  4665. /**
  4666. * lpfc_get_host_port_type - Set the value of the scsi host port type
  4667. * @shost: kernel scsi host pointer.
  4668. **/
  4669. static void
  4670. lpfc_get_host_port_type(struct Scsi_Host *shost)
  4671. {
  4672. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4673. struct lpfc_hba *phba = vport->phba;
  4674. spin_lock_irq(shost->host_lock);
  4675. if (vport->port_type == LPFC_NPIV_PORT) {
  4676. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  4677. } else if (lpfc_is_link_up(phba)) {
  4678. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  4679. if (vport->fc_flag & FC_PUBLIC_LOOP)
  4680. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  4681. else
  4682. fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
  4683. } else {
  4684. if (vport->fc_flag & FC_FABRIC)
  4685. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  4686. else
  4687. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  4688. }
  4689. } else
  4690. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  4691. spin_unlock_irq(shost->host_lock);
  4692. }
  4693. /**
  4694. * lpfc_get_host_port_state - Set the value of the scsi host port state
  4695. * @shost: kernel scsi host pointer.
  4696. **/
  4697. static void
  4698. lpfc_get_host_port_state(struct Scsi_Host *shost)
  4699. {
  4700. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4701. struct lpfc_hba *phba = vport->phba;
  4702. spin_lock_irq(shost->host_lock);
  4703. if (vport->fc_flag & FC_OFFLINE_MODE)
  4704. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  4705. else {
  4706. switch (phba->link_state) {
  4707. case LPFC_LINK_UNKNOWN:
  4708. case LPFC_LINK_DOWN:
  4709. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  4710. break;
  4711. case LPFC_LINK_UP:
  4712. case LPFC_CLEAR_LA:
  4713. case LPFC_HBA_READY:
  4714. /* Links up, reports port state accordingly */
  4715. if (vport->port_state < LPFC_VPORT_READY)
  4716. fc_host_port_state(shost) =
  4717. FC_PORTSTATE_BYPASSED;
  4718. else
  4719. fc_host_port_state(shost) =
  4720. FC_PORTSTATE_ONLINE;
  4721. break;
  4722. case LPFC_HBA_ERROR:
  4723. fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
  4724. break;
  4725. default:
  4726. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  4727. break;
  4728. }
  4729. }
  4730. spin_unlock_irq(shost->host_lock);
  4731. }
  4732. /**
  4733. * lpfc_get_host_speed - Set the value of the scsi host speed
  4734. * @shost: kernel scsi host pointer.
  4735. **/
  4736. static void
  4737. lpfc_get_host_speed(struct Scsi_Host *shost)
  4738. {
  4739. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4740. struct lpfc_hba *phba = vport->phba;
  4741. spin_lock_irq(shost->host_lock);
  4742. if (lpfc_is_link_up(phba)) {
  4743. switch(phba->fc_linkspeed) {
  4744. case LPFC_LINK_SPEED_1GHZ:
  4745. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  4746. break;
  4747. case LPFC_LINK_SPEED_2GHZ:
  4748. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  4749. break;
  4750. case LPFC_LINK_SPEED_4GHZ:
  4751. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  4752. break;
  4753. case LPFC_LINK_SPEED_8GHZ:
  4754. fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
  4755. break;
  4756. case LPFC_LINK_SPEED_10GHZ:
  4757. fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
  4758. break;
  4759. case LPFC_LINK_SPEED_16GHZ:
  4760. fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
  4761. break;
  4762. default:
  4763. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  4764. break;
  4765. }
  4766. } else
  4767. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  4768. spin_unlock_irq(shost->host_lock);
  4769. }
  4770. /**
  4771. * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
  4772. * @shost: kernel scsi host pointer.
  4773. **/
  4774. static void
  4775. lpfc_get_host_fabric_name (struct Scsi_Host *shost)
  4776. {
  4777. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4778. struct lpfc_hba *phba = vport->phba;
  4779. u64 node_name;
  4780. spin_lock_irq(shost->host_lock);
  4781. if ((vport->port_state > LPFC_FLOGI) &&
  4782. ((vport->fc_flag & FC_FABRIC) ||
  4783. ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
  4784. (vport->fc_flag & FC_PUBLIC_LOOP))))
  4785. node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
  4786. else
  4787. /* fabric is local port if there is no F/FL_Port */
  4788. node_name = 0;
  4789. spin_unlock_irq(shost->host_lock);
  4790. fc_host_fabric_name(shost) = node_name;
  4791. }
  4792. /**
  4793. * lpfc_get_stats - Return statistical information about the adapter
  4794. * @shost: kernel scsi host pointer.
  4795. *
  4796. * Notes:
  4797. * NULL on error for link down, no mbox pool, sli2 active,
  4798. * management not allowed, memory allocation error, or mbox error.
  4799. *
  4800. * Returns:
  4801. * NULL for error
  4802. * address of the adapter host statistics
  4803. **/
  4804. static struct fc_host_statistics *
  4805. lpfc_get_stats(struct Scsi_Host *shost)
  4806. {
  4807. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4808. struct lpfc_hba *phba = vport->phba;
  4809. struct lpfc_sli *psli = &phba->sli;
  4810. struct fc_host_statistics *hs = &phba->link_stats;
  4811. struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
  4812. LPFC_MBOXQ_t *pmboxq;
  4813. MAILBOX_t *pmb;
  4814. unsigned long seconds;
  4815. int rc = 0;
  4816. /*
  4817. * prevent udev from issuing mailbox commands until the port is
  4818. * configured.
  4819. */
  4820. if (phba->link_state < LPFC_LINK_DOWN ||
  4821. !phba->mbox_mem_pool ||
  4822. (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
  4823. return NULL;
  4824. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  4825. return NULL;
  4826. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4827. if (!pmboxq)
  4828. return NULL;
  4829. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  4830. pmb = &pmboxq->u.mb;
  4831. pmb->mbxCommand = MBX_READ_STATUS;
  4832. pmb->mbxOwner = OWN_HOST;
  4833. pmboxq->context1 = NULL;
  4834. pmboxq->vport = vport;
  4835. if (vport->fc_flag & FC_OFFLINE_MODE)
  4836. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  4837. else
  4838. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  4839. if (rc != MBX_SUCCESS) {
  4840. if (rc != MBX_TIMEOUT)
  4841. mempool_free(pmboxq, phba->mbox_mem_pool);
  4842. return NULL;
  4843. }
  4844. memset(hs, 0, sizeof (struct fc_host_statistics));
  4845. hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
  4846. /*
  4847. * The MBX_READ_STATUS returns tx_k_bytes which has to
  4848. * converted to words
  4849. */
  4850. hs->tx_words = (uint64_t)
  4851. ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
  4852. * (uint64_t)256);
  4853. hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
  4854. hs->rx_words = (uint64_t)
  4855. ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
  4856. * (uint64_t)256);
  4857. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  4858. pmb->mbxCommand = MBX_READ_LNK_STAT;
  4859. pmb->mbxOwner = OWN_HOST;
  4860. pmboxq->context1 = NULL;
  4861. pmboxq->vport = vport;
  4862. if (vport->fc_flag & FC_OFFLINE_MODE)
  4863. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  4864. else
  4865. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  4866. if (rc != MBX_SUCCESS) {
  4867. if (rc != MBX_TIMEOUT)
  4868. mempool_free(pmboxq, phba->mbox_mem_pool);
  4869. return NULL;
  4870. }
  4871. hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  4872. hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  4873. hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  4874. hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  4875. hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  4876. hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  4877. hs->error_frames = pmb->un.varRdLnk.crcCnt;
  4878. hs->link_failure_count -= lso->link_failure_count;
  4879. hs->loss_of_sync_count -= lso->loss_of_sync_count;
  4880. hs->loss_of_signal_count -= lso->loss_of_signal_count;
  4881. hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
  4882. hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
  4883. hs->invalid_crc_count -= lso->invalid_crc_count;
  4884. hs->error_frames -= lso->error_frames;
  4885. if (phba->hba_flag & HBA_FCOE_MODE) {
  4886. hs->lip_count = -1;
  4887. hs->nos_count = (phba->link_events >> 1);
  4888. hs->nos_count -= lso->link_events;
  4889. } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  4890. hs->lip_count = (phba->fc_eventTag >> 1);
  4891. hs->lip_count -= lso->link_events;
  4892. hs->nos_count = -1;
  4893. } else {
  4894. hs->lip_count = -1;
  4895. hs->nos_count = (phba->fc_eventTag >> 1);
  4896. hs->nos_count -= lso->link_events;
  4897. }
  4898. hs->dumped_frames = -1;
  4899. seconds = get_seconds();
  4900. if (seconds < psli->stats_start)
  4901. hs->seconds_since_last_reset = seconds +
  4902. ((unsigned long)-1 - psli->stats_start);
  4903. else
  4904. hs->seconds_since_last_reset = seconds - psli->stats_start;
  4905. mempool_free(pmboxq, phba->mbox_mem_pool);
  4906. return hs;
  4907. }
  4908. /**
  4909. * lpfc_reset_stats - Copy the adapter link stats information
  4910. * @shost: kernel scsi host pointer.
  4911. **/
  4912. static void
  4913. lpfc_reset_stats(struct Scsi_Host *shost)
  4914. {
  4915. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4916. struct lpfc_hba *phba = vport->phba;
  4917. struct lpfc_sli *psli = &phba->sli;
  4918. struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
  4919. LPFC_MBOXQ_t *pmboxq;
  4920. MAILBOX_t *pmb;
  4921. int rc = 0;
  4922. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  4923. return;
  4924. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4925. if (!pmboxq)
  4926. return;
  4927. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  4928. pmb = &pmboxq->u.mb;
  4929. pmb->mbxCommand = MBX_READ_STATUS;
  4930. pmb->mbxOwner = OWN_HOST;
  4931. pmb->un.varWords[0] = 0x1; /* reset request */
  4932. pmboxq->context1 = NULL;
  4933. pmboxq->vport = vport;
  4934. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  4935. (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
  4936. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  4937. else
  4938. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  4939. if (rc != MBX_SUCCESS) {
  4940. if (rc != MBX_TIMEOUT)
  4941. mempool_free(pmboxq, phba->mbox_mem_pool);
  4942. return;
  4943. }
  4944. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  4945. pmb->mbxCommand = MBX_READ_LNK_STAT;
  4946. pmb->mbxOwner = OWN_HOST;
  4947. pmboxq->context1 = NULL;
  4948. pmboxq->vport = vport;
  4949. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  4950. (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
  4951. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  4952. else
  4953. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  4954. if (rc != MBX_SUCCESS) {
  4955. if (rc != MBX_TIMEOUT)
  4956. mempool_free( pmboxq, phba->mbox_mem_pool);
  4957. return;
  4958. }
  4959. lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  4960. lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  4961. lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  4962. lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  4963. lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  4964. lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  4965. lso->error_frames = pmb->un.varRdLnk.crcCnt;
  4966. if (phba->hba_flag & HBA_FCOE_MODE)
  4967. lso->link_events = (phba->link_events >> 1);
  4968. else
  4969. lso->link_events = (phba->fc_eventTag >> 1);
  4970. psli->stats_start = get_seconds();
  4971. mempool_free(pmboxq, phba->mbox_mem_pool);
  4972. return;
  4973. }
  4974. /*
  4975. * The LPFC driver treats linkdown handling as target loss events so there
  4976. * are no sysfs handlers for link_down_tmo.
  4977. */
  4978. /**
  4979. * lpfc_get_node_by_target - Return the nodelist for a target
  4980. * @starget: kernel scsi target pointer.
  4981. *
  4982. * Returns:
  4983. * address of the node list if found
  4984. * NULL target not found
  4985. **/
  4986. static struct lpfc_nodelist *
  4987. lpfc_get_node_by_target(struct scsi_target *starget)
  4988. {
  4989. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  4990. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4991. struct lpfc_nodelist *ndlp;
  4992. spin_lock_irq(shost->host_lock);
  4993. /* Search for this, mapped, target ID */
  4994. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  4995. if (NLP_CHK_NODE_ACT(ndlp) &&
  4996. ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
  4997. starget->id == ndlp->nlp_sid) {
  4998. spin_unlock_irq(shost->host_lock);
  4999. return ndlp;
  5000. }
  5001. }
  5002. spin_unlock_irq(shost->host_lock);
  5003. return NULL;
  5004. }
  5005. /**
  5006. * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
  5007. * @starget: kernel scsi target pointer.
  5008. **/
  5009. static void
  5010. lpfc_get_starget_port_id(struct scsi_target *starget)
  5011. {
  5012. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  5013. fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
  5014. }
  5015. /**
  5016. * lpfc_get_starget_node_name - Set the target node name
  5017. * @starget: kernel scsi target pointer.
  5018. *
  5019. * Description: Set the target node name to the ndlp node name wwn or zero.
  5020. **/
  5021. static void
  5022. lpfc_get_starget_node_name(struct scsi_target *starget)
  5023. {
  5024. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  5025. fc_starget_node_name(starget) =
  5026. ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
  5027. }
  5028. /**
  5029. * lpfc_get_starget_port_name - Set the target port name
  5030. * @starget: kernel scsi target pointer.
  5031. *
  5032. * Description: set the target port name to the ndlp port name wwn or zero.
  5033. **/
  5034. static void
  5035. lpfc_get_starget_port_name(struct scsi_target *starget)
  5036. {
  5037. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  5038. fc_starget_port_name(starget) =
  5039. ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
  5040. }
  5041. /**
  5042. * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
  5043. * @rport: fc rport address.
  5044. * @timeout: new value for dev loss tmo.
  5045. *
  5046. * Description:
  5047. * If timeout is non zero set the dev_loss_tmo to timeout, else set
  5048. * dev_loss_tmo to one.
  5049. **/
  5050. static void
  5051. lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  5052. {
  5053. if (timeout)
  5054. rport->dev_loss_tmo = timeout;
  5055. else
  5056. rport->dev_loss_tmo = 1;
  5057. }
  5058. /**
  5059. * lpfc_rport_show_function - Return rport target information
  5060. *
  5061. * Description:
  5062. * Macro that uses field to generate a function with the name lpfc_show_rport_
  5063. *
  5064. * lpfc_show_rport_##field: returns the bytes formatted in buf
  5065. * @cdev: class converted to an fc_rport.
  5066. * @buf: on return contains the target_field or zero.
  5067. *
  5068. * Returns: size of formatted string.
  5069. **/
  5070. #define lpfc_rport_show_function(field, format_string, sz, cast) \
  5071. static ssize_t \
  5072. lpfc_show_rport_##field (struct device *dev, \
  5073. struct device_attribute *attr, \
  5074. char *buf) \
  5075. { \
  5076. struct fc_rport *rport = transport_class_to_rport(dev); \
  5077. struct lpfc_rport_data *rdata = rport->hostdata; \
  5078. return snprintf(buf, sz, format_string, \
  5079. (rdata->target) ? cast rdata->target->field : 0); \
  5080. }
  5081. #define lpfc_rport_rd_attr(field, format_string, sz) \
  5082. lpfc_rport_show_function(field, format_string, sz, ) \
  5083. static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
  5084. /**
  5085. * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
  5086. * @fc_vport: The fc_vport who's symbolic name has been changed.
  5087. *
  5088. * Description:
  5089. * This function is called by the transport after the @fc_vport's symbolic name
  5090. * has been changed. This function re-registers the symbolic name with the
  5091. * switch to propagate the change into the fabric if the vport is active.
  5092. **/
  5093. static void
  5094. lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
  5095. {
  5096. struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
  5097. if (vport->port_state == LPFC_VPORT_READY)
  5098. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  5099. }
  5100. /**
  5101. * lpfc_hba_log_verbose_init - Set hba's log verbose level
  5102. * @phba: Pointer to lpfc_hba struct.
  5103. *
  5104. * This function is called by the lpfc_get_cfgparam() routine to set the
  5105. * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
  5106. * log message according to the module's lpfc_log_verbose parameter setting
  5107. * before hba port or vport created.
  5108. **/
  5109. static void
  5110. lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
  5111. {
  5112. phba->cfg_log_verbose = verbose;
  5113. }
  5114. struct fc_function_template lpfc_transport_functions = {
  5115. /* fixed attributes the driver supports */
  5116. .show_host_node_name = 1,
  5117. .show_host_port_name = 1,
  5118. .show_host_supported_classes = 1,
  5119. .show_host_supported_fc4s = 1,
  5120. .show_host_supported_speeds = 1,
  5121. .show_host_maxframe_size = 1,
  5122. .show_host_symbolic_name = 1,
  5123. /* dynamic attributes the driver supports */
  5124. .get_host_port_id = lpfc_get_host_port_id,
  5125. .show_host_port_id = 1,
  5126. .get_host_port_type = lpfc_get_host_port_type,
  5127. .show_host_port_type = 1,
  5128. .get_host_port_state = lpfc_get_host_port_state,
  5129. .show_host_port_state = 1,
  5130. /* active_fc4s is shown but doesn't change (thus no get function) */
  5131. .show_host_active_fc4s = 1,
  5132. .get_host_speed = lpfc_get_host_speed,
  5133. .show_host_speed = 1,
  5134. .get_host_fabric_name = lpfc_get_host_fabric_name,
  5135. .show_host_fabric_name = 1,
  5136. /*
  5137. * The LPFC driver treats linkdown handling as target loss events
  5138. * so there are no sysfs handlers for link_down_tmo.
  5139. */
  5140. .get_fc_host_stats = lpfc_get_stats,
  5141. .reset_fc_host_stats = lpfc_reset_stats,
  5142. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  5143. .show_rport_maxframe_size = 1,
  5144. .show_rport_supported_classes = 1,
  5145. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  5146. .show_rport_dev_loss_tmo = 1,
  5147. .get_starget_port_id = lpfc_get_starget_port_id,
  5148. .show_starget_port_id = 1,
  5149. .get_starget_node_name = lpfc_get_starget_node_name,
  5150. .show_starget_node_name = 1,
  5151. .get_starget_port_name = lpfc_get_starget_port_name,
  5152. .show_starget_port_name = 1,
  5153. .issue_fc_host_lip = lpfc_issue_lip,
  5154. .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
  5155. .terminate_rport_io = lpfc_terminate_rport_io,
  5156. .dd_fcvport_size = sizeof(struct lpfc_vport *),
  5157. .vport_disable = lpfc_vport_disable,
  5158. .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
  5159. .bsg_request = lpfc_bsg_request,
  5160. .bsg_timeout = lpfc_bsg_timeout,
  5161. };
  5162. struct fc_function_template lpfc_vport_transport_functions = {
  5163. /* fixed attributes the driver supports */
  5164. .show_host_node_name = 1,
  5165. .show_host_port_name = 1,
  5166. .show_host_supported_classes = 1,
  5167. .show_host_supported_fc4s = 1,
  5168. .show_host_supported_speeds = 1,
  5169. .show_host_maxframe_size = 1,
  5170. .show_host_symbolic_name = 1,
  5171. /* dynamic attributes the driver supports */
  5172. .get_host_port_id = lpfc_get_host_port_id,
  5173. .show_host_port_id = 1,
  5174. .get_host_port_type = lpfc_get_host_port_type,
  5175. .show_host_port_type = 1,
  5176. .get_host_port_state = lpfc_get_host_port_state,
  5177. .show_host_port_state = 1,
  5178. /* active_fc4s is shown but doesn't change (thus no get function) */
  5179. .show_host_active_fc4s = 1,
  5180. .get_host_speed = lpfc_get_host_speed,
  5181. .show_host_speed = 1,
  5182. .get_host_fabric_name = lpfc_get_host_fabric_name,
  5183. .show_host_fabric_name = 1,
  5184. /*
  5185. * The LPFC driver treats linkdown handling as target loss events
  5186. * so there are no sysfs handlers for link_down_tmo.
  5187. */
  5188. .get_fc_host_stats = lpfc_get_stats,
  5189. .reset_fc_host_stats = lpfc_reset_stats,
  5190. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  5191. .show_rport_maxframe_size = 1,
  5192. .show_rport_supported_classes = 1,
  5193. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  5194. .show_rport_dev_loss_tmo = 1,
  5195. .get_starget_port_id = lpfc_get_starget_port_id,
  5196. .show_starget_port_id = 1,
  5197. .get_starget_node_name = lpfc_get_starget_node_name,
  5198. .show_starget_node_name = 1,
  5199. .get_starget_port_name = lpfc_get_starget_port_name,
  5200. .show_starget_port_name = 1,
  5201. .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
  5202. .terminate_rport_io = lpfc_terminate_rport_io,
  5203. .vport_disable = lpfc_vport_disable,
  5204. .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
  5205. };
  5206. /**
  5207. * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
  5208. * @phba: lpfc_hba pointer.
  5209. **/
  5210. void
  5211. lpfc_get_cfgparam(struct lpfc_hba *phba)
  5212. {
  5213. lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
  5214. lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
  5215. lpfc_cr_delay_init(phba, lpfc_cr_delay);
  5216. lpfc_cr_count_init(phba, lpfc_cr_count);
  5217. lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
  5218. lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
  5219. lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
  5220. lpfc_ack0_init(phba, lpfc_ack0);
  5221. lpfc_topology_init(phba, lpfc_topology);
  5222. lpfc_link_speed_init(phba, lpfc_link_speed);
  5223. lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
  5224. lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
  5225. lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
  5226. lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
  5227. lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
  5228. lpfc_use_msi_init(phba, lpfc_use_msi);
  5229. lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
  5230. lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
  5231. lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
  5232. lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
  5233. lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
  5234. lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
  5235. if (phba->sli_rev != LPFC_SLI_REV4)
  5236. phba->cfg_EnableXLane = 0;
  5237. lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
  5238. memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
  5239. memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
  5240. phba->cfg_oas_lun_state = 0;
  5241. phba->cfg_oas_lun_status = 0;
  5242. phba->cfg_oas_flags = 0;
  5243. lpfc_enable_bg_init(phba, lpfc_enable_bg);
  5244. if (phba->sli_rev == LPFC_SLI_REV4)
  5245. phba->cfg_poll = 0;
  5246. else
  5247. phba->cfg_poll = lpfc_poll;
  5248. phba->cfg_soft_wwnn = 0L;
  5249. phba->cfg_soft_wwpn = 0L;
  5250. lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
  5251. lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
  5252. lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
  5253. lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
  5254. lpfc_aer_support_init(phba, lpfc_aer_support);
  5255. lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
  5256. lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
  5257. lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
  5258. lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
  5259. phba->cfg_enable_dss = 1;
  5260. return;
  5261. }
  5262. /**
  5263. * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
  5264. * @vport: lpfc_vport pointer.
  5265. **/
  5266. void
  5267. lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
  5268. {
  5269. lpfc_log_verbose_init(vport, lpfc_log_verbose);
  5270. lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
  5271. lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
  5272. lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
  5273. lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
  5274. lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
  5275. lpfc_restrict_login_init(vport, lpfc_restrict_login);
  5276. lpfc_fcp_class_init(vport, lpfc_fcp_class);
  5277. lpfc_use_adisc_init(vport, lpfc_use_adisc);
  5278. lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
  5279. lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
  5280. lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
  5281. lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
  5282. lpfc_max_luns_init(vport, lpfc_max_luns);
  5283. lpfc_scan_down_init(vport, lpfc_scan_down);
  5284. lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
  5285. return;
  5286. }