lpfc_attr.c 219 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  10. * *
  11. * This program is free software; you can redistribute it and/or *
  12. * modify it under the terms of version 2 of the GNU General *
  13. * Public License as published by the Free Software Foundation. *
  14. * This program is distributed in the hope that it will be useful. *
  15. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  16. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  17. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  18. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  19. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  20. * more details, a copy of which can be found in the file COPYING *
  21. * included with this package. *
  22. *******************************************************************/
  23. #include <linux/ctype.h>
  24. #include <linux/delay.h>
  25. #include <linux/pci.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/module.h>
  28. #include <linux/aer.h>
  29. #include <linux/gfp.h>
  30. #include <linux/kernel.h>
  31. #include <scsi/scsi.h>
  32. #include <scsi/scsi_device.h>
  33. #include <scsi/scsi_host.h>
  34. #include <scsi/scsi_tcq.h>
  35. #include <scsi/scsi_transport_fc.h>
  36. #include <scsi/fc/fc_fs.h>
  37. #include "lpfc_hw4.h"
  38. #include "lpfc_hw.h"
  39. #include "lpfc_sli.h"
  40. #include "lpfc_sli4.h"
  41. #include "lpfc_nl.h"
  42. #include "lpfc_disc.h"
  43. #include "lpfc.h"
  44. #include "lpfc_scsi.h"
  45. #include "lpfc_nvme.h"
  46. #include "lpfc_logmsg.h"
  47. #include "lpfc_version.h"
  48. #include "lpfc_compat.h"
  49. #include "lpfc_crtn.h"
  50. #include "lpfc_vport.h"
  51. #include "lpfc_attr.h"
  52. #define LPFC_DEF_DEVLOSS_TMO 30
  53. #define LPFC_MIN_DEVLOSS_TMO 1
  54. #define LPFC_MAX_DEVLOSS_TMO 255
  55. #define LPFC_MAX_INFO_TMP_LEN 100
  56. #define LPFC_INFO_MORE_STR "\nCould be more info...\n"
  57. /*
  58. * Write key size should be multiple of 4. If write key is changed
  59. * make sure that library write key is also changed.
  60. */
  61. #define LPFC_REG_WRITE_KEY_SIZE 4
  62. #define LPFC_REG_WRITE_KEY "EMLX"
  63. const char *const trunk_errmsg[] = { /* map errcode */
  64. "", /* There is no such error code at index 0*/
  65. "link negotiated speed does not match existing"
  66. " trunk - link was \"low\" speed",
  67. "link negotiated speed does not match"
  68. " existing trunk - link was \"middle\" speed",
  69. "link negotiated speed does not match existing"
  70. " trunk - link was \"high\" speed",
  71. "Attached to non-trunking port - F_Port",
  72. "Attached to non-trunking port - N_Port",
  73. "FLOGI response timeout",
  74. "non-FLOGI frame received",
  75. "Invalid FLOGI response",
  76. "Trunking initialization protocol",
  77. "Trunk peer device mismatch",
  78. };
  79. /**
  80. * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
  81. * @incr: integer to convert.
  82. * @hdw: ascii string holding converted integer plus a string terminator.
  83. *
  84. * Description:
  85. * JEDEC Joint Electron Device Engineering Council.
  86. * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
  87. * character string. The string is then terminated with a NULL in byte 9.
  88. * Hex 0-9 becomes ascii '0' to '9'.
  89. * Hex a-f becomes ascii '=' to 'B' capital B.
  90. *
  91. * Notes:
  92. * Coded for 32 bit integers only.
  93. **/
  94. static void
  95. lpfc_jedec_to_ascii(int incr, char hdw[])
  96. {
  97. int i, j;
  98. for (i = 0; i < 8; i++) {
  99. j = (incr & 0xf);
  100. if (j <= 9)
  101. hdw[7 - i] = 0x30 + j;
  102. else
  103. hdw[7 - i] = 0x61 + j - 10;
  104. incr = (incr >> 4);
  105. }
  106. hdw[8] = 0;
  107. return;
  108. }
  109. static ssize_t
  110. lpfc_cmf_info_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. struct lpfc_cgn_info *cp = NULL;
  117. struct lpfc_cgn_stat *cgs;
  118. int len = 0;
  119. int cpu;
  120. u64 rcv, total;
  121. char tmp[LPFC_MAX_INFO_TMP_LEN] = {0};
  122. if (phba->cgn_i)
  123. cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
  124. scnprintf(tmp, sizeof(tmp),
  125. "Congestion Mgmt Info: E2Eattr %d Ver %d "
  126. "CMF %d cnt %d\n",
  127. phba->sli4_hba.pc_sli4_params.mi_cap,
  128. cp ? cp->cgn_info_version : 0,
  129. phba->sli4_hba.pc_sli4_params.cmf, phba->cmf_timer_cnt);
  130. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  131. goto buffer_done;
  132. if (!phba->sli4_hba.pc_sli4_params.cmf)
  133. goto buffer_done;
  134. switch (phba->cgn_init_reg_signal) {
  135. case EDC_CG_SIG_WARN_ONLY:
  136. scnprintf(tmp, sizeof(tmp),
  137. "Register: Init: Signal:WARN ");
  138. break;
  139. case EDC_CG_SIG_WARN_ALARM:
  140. scnprintf(tmp, sizeof(tmp),
  141. "Register: Init: Signal:WARN|ALARM ");
  142. break;
  143. default:
  144. scnprintf(tmp, sizeof(tmp),
  145. "Register: Init: Signal:NONE ");
  146. break;
  147. }
  148. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  149. goto buffer_done;
  150. switch (phba->cgn_init_reg_fpin) {
  151. case LPFC_CGN_FPIN_WARN:
  152. scnprintf(tmp, sizeof(tmp),
  153. "FPIN:WARN\n");
  154. break;
  155. case LPFC_CGN_FPIN_ALARM:
  156. scnprintf(tmp, sizeof(tmp),
  157. "FPIN:ALARM\n");
  158. break;
  159. case LPFC_CGN_FPIN_BOTH:
  160. scnprintf(tmp, sizeof(tmp),
  161. "FPIN:WARN|ALARM\n");
  162. break;
  163. default:
  164. scnprintf(tmp, sizeof(tmp),
  165. "FPIN:NONE\n");
  166. break;
  167. }
  168. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  169. goto buffer_done;
  170. switch (phba->cgn_reg_signal) {
  171. case EDC_CG_SIG_WARN_ONLY:
  172. scnprintf(tmp, sizeof(tmp),
  173. " Current: Signal:WARN ");
  174. break;
  175. case EDC_CG_SIG_WARN_ALARM:
  176. scnprintf(tmp, sizeof(tmp),
  177. " Current: Signal:WARN|ALARM ");
  178. break;
  179. default:
  180. scnprintf(tmp, sizeof(tmp),
  181. " Current: Signal:NONE ");
  182. break;
  183. }
  184. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  185. goto buffer_done;
  186. switch (phba->cgn_reg_fpin) {
  187. case LPFC_CGN_FPIN_WARN:
  188. scnprintf(tmp, sizeof(tmp),
  189. "FPIN:WARN ACQEcnt:%d\n", phba->cgn_acqe_cnt);
  190. break;
  191. case LPFC_CGN_FPIN_ALARM:
  192. scnprintf(tmp, sizeof(tmp),
  193. "FPIN:ALARM ACQEcnt:%d\n", phba->cgn_acqe_cnt);
  194. break;
  195. case LPFC_CGN_FPIN_BOTH:
  196. scnprintf(tmp, sizeof(tmp),
  197. "FPIN:WARN|ALARM ACQEcnt:%d\n", phba->cgn_acqe_cnt);
  198. break;
  199. default:
  200. scnprintf(tmp, sizeof(tmp),
  201. "FPIN:NONE ACQEcnt:%d\n", phba->cgn_acqe_cnt);
  202. break;
  203. }
  204. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  205. goto buffer_done;
  206. if (phba->cmf_active_mode != phba->cgn_p.cgn_param_mode) {
  207. switch (phba->cmf_active_mode) {
  208. case LPFC_CFG_OFF:
  209. scnprintf(tmp, sizeof(tmp), "Active: Mode:Off\n");
  210. break;
  211. case LPFC_CFG_MANAGED:
  212. scnprintf(tmp, sizeof(tmp), "Active: Mode:Managed\n");
  213. break;
  214. case LPFC_CFG_MONITOR:
  215. scnprintf(tmp, sizeof(tmp), "Active: Mode:Monitor\n");
  216. break;
  217. default:
  218. scnprintf(tmp, sizeof(tmp), "Active: Mode:Unknown\n");
  219. }
  220. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  221. goto buffer_done;
  222. }
  223. switch (phba->cgn_p.cgn_param_mode) {
  224. case LPFC_CFG_OFF:
  225. scnprintf(tmp, sizeof(tmp), "Config: Mode:Off ");
  226. break;
  227. case LPFC_CFG_MANAGED:
  228. scnprintf(tmp, sizeof(tmp), "Config: Mode:Managed ");
  229. break;
  230. case LPFC_CFG_MONITOR:
  231. scnprintf(tmp, sizeof(tmp), "Config: Mode:Monitor ");
  232. break;
  233. default:
  234. scnprintf(tmp, sizeof(tmp), "Config: Mode:Unknown ");
  235. }
  236. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  237. goto buffer_done;
  238. total = 0;
  239. rcv = 0;
  240. for_each_present_cpu(cpu) {
  241. cgs = per_cpu_ptr(phba->cmf_stat, cpu);
  242. total += atomic64_read(&cgs->total_bytes);
  243. rcv += atomic64_read(&cgs->rcv_bytes);
  244. }
  245. scnprintf(tmp, sizeof(tmp),
  246. "IObusy:%d Info:%d Bytes: Rcv:x%llx Total:x%llx\n",
  247. atomic_read(&phba->cmf_busy),
  248. phba->cmf_active_info, rcv, total);
  249. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  250. goto buffer_done;
  251. scnprintf(tmp, sizeof(tmp),
  252. "Port_speed:%d Link_byte_cnt:%ld "
  253. "Max_byte_per_interval:%ld\n",
  254. lpfc_sli_port_speed_get(phba),
  255. (unsigned long)phba->cmf_link_byte_count,
  256. (unsigned long)phba->cmf_max_bytes_per_interval);
  257. strlcat(buf, tmp, PAGE_SIZE);
  258. buffer_done:
  259. len = strnlen(buf, PAGE_SIZE);
  260. if (unlikely(len >= (PAGE_SIZE - 1))) {
  261. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  262. "6312 Catching potential buffer "
  263. "overflow > PAGE_SIZE = %lu bytes\n",
  264. PAGE_SIZE);
  265. strscpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_INFO_MORE_STR),
  266. LPFC_INFO_MORE_STR, sizeof(LPFC_INFO_MORE_STR) + 1);
  267. }
  268. return len;
  269. }
  270. /**
  271. * lpfc_drvr_version_show - Return the Emulex driver string with version number
  272. * @dev: class unused variable.
  273. * @attr: device attribute, not used.
  274. * @buf: on return contains the module description text.
  275. *
  276. * Returns: size of formatted string.
  277. **/
  278. static ssize_t
  279. lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
  280. char *buf)
  281. {
  282. return scnprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
  283. }
  284. /**
  285. * lpfc_enable_fip_show - Return the fip mode of the HBA
  286. * @dev: class unused variable.
  287. * @attr: device attribute, not used.
  288. * @buf: on return contains the module description text.
  289. *
  290. * Returns: size of formatted string.
  291. **/
  292. static ssize_t
  293. lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
  294. char *buf)
  295. {
  296. struct Scsi_Host *shost = class_to_shost(dev);
  297. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  298. struct lpfc_hba *phba = vport->phba;
  299. if (test_bit(HBA_FIP_SUPPORT, &phba->hba_flag))
  300. return scnprintf(buf, PAGE_SIZE, "1\n");
  301. else
  302. return scnprintf(buf, PAGE_SIZE, "0\n");
  303. }
  304. static ssize_t
  305. lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
  306. char *buf)
  307. {
  308. struct Scsi_Host *shost = class_to_shost(dev);
  309. struct lpfc_vport *vport = shost_priv(shost);
  310. struct lpfc_hba *phba = vport->phba;
  311. struct lpfc_nvmet_tgtport *tgtp;
  312. struct nvme_fc_local_port *localport;
  313. struct lpfc_nvme_lport *lport;
  314. struct lpfc_nvme_rport *rport;
  315. struct lpfc_nodelist *ndlp;
  316. struct nvme_fc_remote_port *nrport;
  317. struct lpfc_fc4_ctrl_stat *cstat;
  318. uint64_t data1, data2, data3;
  319. uint64_t totin, totout, tot;
  320. unsigned long iflags;
  321. char *statep;
  322. int i;
  323. int len = 0;
  324. char tmp[LPFC_MAX_INFO_TMP_LEN] = {0};
  325. if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
  326. len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
  327. return len;
  328. }
  329. if (phba->nvmet_support) {
  330. if (!phba->targetport) {
  331. len = scnprintf(buf, PAGE_SIZE,
  332. "NVME Target: x%llx is not allocated\n",
  333. wwn_to_u64(vport->fc_portname.u.wwn));
  334. return len;
  335. }
  336. /* Port state is only one of two values for now. */
  337. if (phba->targetport->port_id)
  338. statep = "REGISTERED";
  339. else
  340. statep = "INIT";
  341. scnprintf(tmp, sizeof(tmp),
  342. "NVME Target Enabled State %s\n",
  343. statep);
  344. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  345. goto buffer_done;
  346. scnprintf(tmp, sizeof(tmp),
  347. "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
  348. "NVME Target: lpfc",
  349. phba->brd_no,
  350. wwn_to_u64(vport->fc_portname.u.wwn),
  351. wwn_to_u64(vport->fc_nodename.u.wwn),
  352. phba->targetport->port_id);
  353. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  354. goto buffer_done;
  355. if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
  356. >= PAGE_SIZE)
  357. goto buffer_done;
  358. tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
  359. scnprintf(tmp, sizeof(tmp),
  360. "LS: Rcv %08x Drop %08x Abort %08x\n",
  361. atomic_read(&tgtp->rcv_ls_req_in),
  362. atomic_read(&tgtp->rcv_ls_req_drop),
  363. atomic_read(&tgtp->xmt_ls_abort));
  364. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  365. goto buffer_done;
  366. if (atomic_read(&tgtp->rcv_ls_req_in) !=
  367. atomic_read(&tgtp->rcv_ls_req_out)) {
  368. scnprintf(tmp, sizeof(tmp),
  369. "Rcv LS: in %08x != out %08x\n",
  370. atomic_read(&tgtp->rcv_ls_req_in),
  371. atomic_read(&tgtp->rcv_ls_req_out));
  372. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  373. goto buffer_done;
  374. }
  375. scnprintf(tmp, sizeof(tmp),
  376. "LS: Xmt %08x Drop %08x Cmpl %08x\n",
  377. atomic_read(&tgtp->xmt_ls_rsp),
  378. atomic_read(&tgtp->xmt_ls_drop),
  379. atomic_read(&tgtp->xmt_ls_rsp_cmpl));
  380. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  381. goto buffer_done;
  382. scnprintf(tmp, sizeof(tmp),
  383. "LS: RSP Abort %08x xb %08x Err %08x\n",
  384. atomic_read(&tgtp->xmt_ls_rsp_aborted),
  385. atomic_read(&tgtp->xmt_ls_rsp_xb_set),
  386. atomic_read(&tgtp->xmt_ls_rsp_error));
  387. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  388. goto buffer_done;
  389. scnprintf(tmp, sizeof(tmp),
  390. "FCP: Rcv %08x Defer %08x Release %08x "
  391. "Drop %08x\n",
  392. atomic_read(&tgtp->rcv_fcp_cmd_in),
  393. atomic_read(&tgtp->rcv_fcp_cmd_defer),
  394. atomic_read(&tgtp->xmt_fcp_release),
  395. atomic_read(&tgtp->rcv_fcp_cmd_drop));
  396. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  397. goto buffer_done;
  398. if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
  399. atomic_read(&tgtp->rcv_fcp_cmd_out)) {
  400. scnprintf(tmp, sizeof(tmp),
  401. "Rcv FCP: in %08x != out %08x\n",
  402. atomic_read(&tgtp->rcv_fcp_cmd_in),
  403. atomic_read(&tgtp->rcv_fcp_cmd_out));
  404. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  405. goto buffer_done;
  406. }
  407. scnprintf(tmp, sizeof(tmp),
  408. "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
  409. "drop %08x\n",
  410. atomic_read(&tgtp->xmt_fcp_read),
  411. atomic_read(&tgtp->xmt_fcp_read_rsp),
  412. atomic_read(&tgtp->xmt_fcp_write),
  413. atomic_read(&tgtp->xmt_fcp_rsp),
  414. atomic_read(&tgtp->xmt_fcp_drop));
  415. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  416. goto buffer_done;
  417. scnprintf(tmp, sizeof(tmp),
  418. "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
  419. atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
  420. atomic_read(&tgtp->xmt_fcp_rsp_error),
  421. atomic_read(&tgtp->xmt_fcp_rsp_drop));
  422. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  423. goto buffer_done;
  424. scnprintf(tmp, sizeof(tmp),
  425. "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
  426. atomic_read(&tgtp->xmt_fcp_rsp_aborted),
  427. atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
  428. atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
  429. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  430. goto buffer_done;
  431. scnprintf(tmp, sizeof(tmp),
  432. "ABORT: Xmt %08x Cmpl %08x\n",
  433. atomic_read(&tgtp->xmt_fcp_abort),
  434. atomic_read(&tgtp->xmt_fcp_abort_cmpl));
  435. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  436. goto buffer_done;
  437. scnprintf(tmp, sizeof(tmp),
  438. "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
  439. atomic_read(&tgtp->xmt_abort_sol),
  440. atomic_read(&tgtp->xmt_abort_unsol),
  441. atomic_read(&tgtp->xmt_abort_rsp),
  442. atomic_read(&tgtp->xmt_abort_rsp_error));
  443. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  444. goto buffer_done;
  445. scnprintf(tmp, sizeof(tmp),
  446. "DELAY: ctx %08x fod %08x wqfull %08x\n",
  447. atomic_read(&tgtp->defer_ctx),
  448. atomic_read(&tgtp->defer_fod),
  449. atomic_read(&tgtp->defer_wqfull));
  450. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  451. goto buffer_done;
  452. /* Calculate outstanding IOs */
  453. tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
  454. tot += atomic_read(&tgtp->xmt_fcp_release);
  455. tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
  456. scnprintf(tmp, sizeof(tmp),
  457. "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
  458. "CTX Outstanding %08llx\n\n",
  459. phba->sli4_hba.nvmet_xri_cnt,
  460. phba->sli4_hba.nvmet_io_wait_cnt,
  461. phba->sli4_hba.nvmet_io_wait_total,
  462. tot);
  463. strlcat(buf, tmp, PAGE_SIZE);
  464. goto buffer_done;
  465. }
  466. localport = vport->localport;
  467. if (!localport) {
  468. len = scnprintf(buf, PAGE_SIZE,
  469. "NVME Initiator x%llx is not allocated\n",
  470. wwn_to_u64(vport->fc_portname.u.wwn));
  471. return len;
  472. }
  473. lport = (struct lpfc_nvme_lport *)localport->private;
  474. if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
  475. goto buffer_done;
  476. scnprintf(tmp, sizeof(tmp),
  477. "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
  478. phba->brd_no,
  479. phba->sli4_hba.max_cfg_param.max_xri,
  480. phba->sli4_hba.io_xri_max,
  481. lpfc_sli4_get_els_iocb_cnt(phba));
  482. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  483. goto buffer_done;
  484. /* Port state is only one of two values for now. */
  485. if (localport->port_id)
  486. statep = "ONLINE";
  487. else
  488. statep = "UNKNOWN ";
  489. scnprintf(tmp, sizeof(tmp),
  490. "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
  491. "NVME LPORT lpfc",
  492. phba->brd_no,
  493. wwn_to_u64(vport->fc_portname.u.wwn),
  494. wwn_to_u64(vport->fc_nodename.u.wwn),
  495. localport->port_id, statep);
  496. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  497. goto buffer_done;
  498. spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
  499. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  500. nrport = NULL;
  501. spin_lock(&ndlp->lock);
  502. rport = lpfc_ndlp_get_nrport(ndlp);
  503. if (rport)
  504. nrport = rport->remoteport;
  505. spin_unlock(&ndlp->lock);
  506. if (!nrport)
  507. continue;
  508. /* Port state is only one of two values for now. */
  509. switch (nrport->port_state) {
  510. case FC_OBJSTATE_ONLINE:
  511. statep = "ONLINE";
  512. break;
  513. case FC_OBJSTATE_UNKNOWN:
  514. statep = "UNKNOWN ";
  515. break;
  516. default:
  517. statep = "UNSUPPORTED";
  518. break;
  519. }
  520. /* Tab in to show lport ownership. */
  521. if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
  522. goto unlock_buf_done;
  523. if (phba->brd_no >= 10) {
  524. if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
  525. goto unlock_buf_done;
  526. }
  527. scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
  528. nrport->port_name);
  529. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  530. goto unlock_buf_done;
  531. scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
  532. nrport->node_name);
  533. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  534. goto unlock_buf_done;
  535. scnprintf(tmp, sizeof(tmp), "DID x%06x ",
  536. nrport->port_id);
  537. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  538. goto unlock_buf_done;
  539. /* An NVME rport can have multiple roles. */
  540. if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
  541. if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
  542. goto unlock_buf_done;
  543. }
  544. if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
  545. if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
  546. goto unlock_buf_done;
  547. }
  548. if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
  549. if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
  550. goto unlock_buf_done;
  551. }
  552. if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
  553. FC_PORT_ROLE_NVME_TARGET |
  554. FC_PORT_ROLE_NVME_DISCOVERY)) {
  555. scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
  556. nrport->port_role);
  557. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  558. goto unlock_buf_done;
  559. }
  560. scnprintf(tmp, sizeof(tmp), "%s\n", statep);
  561. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  562. goto unlock_buf_done;
  563. }
  564. spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
  565. if (!lport)
  566. goto buffer_done;
  567. if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
  568. goto buffer_done;
  569. scnprintf(tmp, sizeof(tmp),
  570. "LS: Xmt %010x Cmpl %010x Abort %08x\n",
  571. atomic_read(&lport->fc4NvmeLsRequests),
  572. atomic_read(&lport->fc4NvmeLsCmpls),
  573. atomic_read(&lport->xmt_ls_abort));
  574. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  575. goto buffer_done;
  576. scnprintf(tmp, sizeof(tmp),
  577. "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
  578. atomic_read(&lport->xmt_ls_err),
  579. atomic_read(&lport->cmpl_ls_xb),
  580. atomic_read(&lport->cmpl_ls_err));
  581. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  582. goto buffer_done;
  583. totin = 0;
  584. totout = 0;
  585. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  586. cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
  587. tot = cstat->io_cmpls;
  588. totin += tot;
  589. data1 = cstat->input_requests;
  590. data2 = cstat->output_requests;
  591. data3 = cstat->control_requests;
  592. totout += (data1 + data2 + data3);
  593. }
  594. scnprintf(tmp, sizeof(tmp),
  595. "Total FCP Cmpl %016llx Issue %016llx "
  596. "OutIO %016llx\n",
  597. totin, totout, totout - totin);
  598. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  599. goto buffer_done;
  600. scnprintf(tmp, sizeof(tmp),
  601. "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
  602. "wqerr %08x err %08x\n",
  603. atomic_read(&lport->xmt_fcp_abort),
  604. atomic_read(&lport->xmt_fcp_noxri),
  605. atomic_read(&lport->xmt_fcp_bad_ndlp),
  606. atomic_read(&lport->xmt_fcp_qdepth),
  607. atomic_read(&lport->xmt_fcp_wqerr),
  608. atomic_read(&lport->xmt_fcp_err));
  609. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  610. goto buffer_done;
  611. scnprintf(tmp, sizeof(tmp),
  612. "FCP CMPL: xb %08x Err %08x\n",
  613. atomic_read(&lport->cmpl_fcp_xb),
  614. atomic_read(&lport->cmpl_fcp_err));
  615. strlcat(buf, tmp, PAGE_SIZE);
  616. /* host_lock is already unlocked. */
  617. goto buffer_done;
  618. unlock_buf_done:
  619. spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
  620. buffer_done:
  621. len = strnlen(buf, PAGE_SIZE);
  622. if (unlikely(len >= (PAGE_SIZE - 1))) {
  623. lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
  624. "6314 Catching potential buffer "
  625. "overflow > PAGE_SIZE = %lu bytes\n",
  626. PAGE_SIZE);
  627. strscpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_INFO_MORE_STR),
  628. LPFC_INFO_MORE_STR,
  629. sizeof(LPFC_INFO_MORE_STR) + 1);
  630. }
  631. return len;
  632. }
  633. static ssize_t
  634. lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
  635. char *buf)
  636. {
  637. struct Scsi_Host *shost = class_to_shost(dev);
  638. struct lpfc_vport *vport = shost_priv(shost);
  639. struct lpfc_hba *phba = vport->phba;
  640. int len;
  641. struct lpfc_fc4_ctrl_stat *cstat;
  642. u64 data1, data2, data3;
  643. u64 tot, totin, totout;
  644. int i;
  645. char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
  646. if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
  647. (phba->sli_rev != LPFC_SLI_REV4))
  648. return 0;
  649. scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
  650. totin = 0;
  651. totout = 0;
  652. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  653. cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
  654. tot = cstat->io_cmpls;
  655. totin += tot;
  656. data1 = cstat->input_requests;
  657. data2 = cstat->output_requests;
  658. data3 = cstat->control_requests;
  659. totout += (data1 + data2 + data3);
  660. scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
  661. "IO %016llx ", i, data1, data2, data3);
  662. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  663. goto buffer_done;
  664. scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
  665. tot, ((data1 + data2 + data3) - tot));
  666. if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
  667. goto buffer_done;
  668. }
  669. scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
  670. "OutIO %016llx\n", totin, totout, totout - totin);
  671. strlcat(buf, tmp, PAGE_SIZE);
  672. buffer_done:
  673. len = strnlen(buf, PAGE_SIZE);
  674. return len;
  675. }
  676. static ssize_t
  677. lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
  678. char *buf)
  679. {
  680. struct Scsi_Host *shost = class_to_shost(dev);
  681. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  682. struct lpfc_hba *phba = vport->phba;
  683. if (phba->cfg_enable_bg) {
  684. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  685. return scnprintf(buf, PAGE_SIZE,
  686. "BlockGuard Enabled\n");
  687. else
  688. return scnprintf(buf, PAGE_SIZE,
  689. "BlockGuard Not Supported\n");
  690. } else
  691. return scnprintf(buf, PAGE_SIZE,
  692. "BlockGuard Disabled\n");
  693. }
  694. static ssize_t
  695. lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
  696. char *buf)
  697. {
  698. struct Scsi_Host *shost = class_to_shost(dev);
  699. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  700. struct lpfc_hba *phba = vport->phba;
  701. return scnprintf(buf, PAGE_SIZE, "%llu\n",
  702. (unsigned long long)phba->bg_guard_err_cnt);
  703. }
  704. static ssize_t
  705. lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
  706. char *buf)
  707. {
  708. struct Scsi_Host *shost = class_to_shost(dev);
  709. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  710. struct lpfc_hba *phba = vport->phba;
  711. return scnprintf(buf, PAGE_SIZE, "%llu\n",
  712. (unsigned long long)phba->bg_apptag_err_cnt);
  713. }
  714. static ssize_t
  715. lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
  716. char *buf)
  717. {
  718. struct Scsi_Host *shost = class_to_shost(dev);
  719. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  720. struct lpfc_hba *phba = vport->phba;
  721. return scnprintf(buf, PAGE_SIZE, "%llu\n",
  722. (unsigned long long)phba->bg_reftag_err_cnt);
  723. }
  724. /**
  725. * lpfc_info_show - Return some pci info about the host in ascii
  726. * @dev: class converted to a Scsi_host structure.
  727. * @attr: device attribute, not used.
  728. * @buf: on return contains the formatted text from lpfc_info().
  729. *
  730. * Returns: size of formatted string.
  731. **/
  732. static ssize_t
  733. lpfc_info_show(struct device *dev, struct device_attribute *attr,
  734. char *buf)
  735. {
  736. struct Scsi_Host *host = class_to_shost(dev);
  737. return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));
  738. }
  739. /**
  740. * lpfc_serialnum_show - Return the hba serial number in ascii
  741. * @dev: class converted to a Scsi_host structure.
  742. * @attr: device attribute, not used.
  743. * @buf: on return contains the formatted text serial number.
  744. *
  745. * Returns: size of formatted string.
  746. **/
  747. static ssize_t
  748. lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
  749. char *buf)
  750. {
  751. struct Scsi_Host *shost = class_to_shost(dev);
  752. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  753. struct lpfc_hba *phba = vport->phba;
  754. return scnprintf(buf, PAGE_SIZE, "%s\n", phba->SerialNumber);
  755. }
  756. /**
  757. * lpfc_temp_sensor_show - Return the temperature sensor level
  758. * @dev: class converted to a Scsi_host structure.
  759. * @attr: device attribute, not used.
  760. * @buf: on return contains the formatted support level.
  761. *
  762. * Description:
  763. * Returns a number indicating the temperature sensor level currently
  764. * supported, zero or one in ascii.
  765. *
  766. * Returns: size of formatted string.
  767. **/
  768. static ssize_t
  769. lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
  770. char *buf)
  771. {
  772. struct Scsi_Host *shost = class_to_shost(dev);
  773. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  774. struct lpfc_hba *phba = vport->phba;
  775. return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);
  776. }
  777. /**
  778. * lpfc_modeldesc_show - Return the model description of the hba
  779. * @dev: class converted to a Scsi_host structure.
  780. * @attr: device attribute, not used.
  781. * @buf: on return contains the scsi vpd model description.
  782. *
  783. * Returns: size of formatted string.
  784. **/
  785. static ssize_t
  786. lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
  787. char *buf)
  788. {
  789. struct Scsi_Host *shost = class_to_shost(dev);
  790. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  791. struct lpfc_hba *phba = vport->phba;
  792. return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);
  793. }
  794. /**
  795. * lpfc_modelname_show - Return the model name of the hba
  796. * @dev: class converted to a Scsi_host structure.
  797. * @attr: device attribute, not used.
  798. * @buf: on return contains the scsi vpd model name.
  799. *
  800. * Returns: size of formatted string.
  801. **/
  802. static ssize_t
  803. lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
  804. char *buf)
  805. {
  806. struct Scsi_Host *shost = class_to_shost(dev);
  807. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  808. struct lpfc_hba *phba = vport->phba;
  809. return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);
  810. }
  811. /**
  812. * lpfc_programtype_show - Return the program type of the hba
  813. * @dev: class converted to a Scsi_host structure.
  814. * @attr: device attribute, not used.
  815. * @buf: on return contains the scsi vpd program type.
  816. *
  817. * Returns: size of formatted string.
  818. **/
  819. static ssize_t
  820. lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
  821. char *buf)
  822. {
  823. struct Scsi_Host *shost = class_to_shost(dev);
  824. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  825. struct lpfc_hba *phba = vport->phba;
  826. return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);
  827. }
  828. /**
  829. * lpfc_vportnum_show - Return the port number in ascii of the hba
  830. * @dev: class converted to a Scsi_host structure.
  831. * @attr: device attribute, not used.
  832. * @buf: on return contains scsi vpd program type.
  833. *
  834. * Returns: size of formatted string.
  835. **/
  836. static ssize_t
  837. lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
  838. char *buf)
  839. {
  840. struct Scsi_Host *shost = class_to_shost(dev);
  841. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  842. struct lpfc_hba *phba = vport->phba;
  843. return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);
  844. }
  845. /**
  846. * lpfc_fwrev_show - Return the firmware rev running in the hba
  847. * @dev: class converted to a Scsi_host structure.
  848. * @attr: device attribute, not used.
  849. * @buf: on return contains the scsi vpd program type.
  850. *
  851. * Returns: size of formatted string.
  852. **/
  853. static ssize_t
  854. lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
  855. char *buf)
  856. {
  857. struct Scsi_Host *shost = class_to_shost(dev);
  858. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  859. struct lpfc_hba *phba = vport->phba;
  860. uint32_t if_type;
  861. uint8_t sli_family;
  862. char fwrev[FW_REV_STR_SIZE];
  863. int len;
  864. lpfc_decode_firmware_rev(phba, fwrev, 1);
  865. if_type = phba->sli4_hba.pc_sli4_params.if_type;
  866. sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
  867. if (phba->sli_rev < LPFC_SLI_REV4)
  868. len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
  869. fwrev, phba->sli_rev);
  870. else
  871. len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
  872. fwrev, phba->sli_rev, if_type, sli_family);
  873. return len;
  874. }
  875. /**
  876. * lpfc_hdw_show - Return the jedec information about the hba
  877. * @dev: class converted to a Scsi_host structure.
  878. * @attr: device attribute, not used.
  879. * @buf: on return contains the scsi vpd program type.
  880. *
  881. * Returns: size of formatted string.
  882. **/
  883. static ssize_t
  884. lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
  885. {
  886. char hdw[9];
  887. struct Scsi_Host *shost = class_to_shost(dev);
  888. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  889. struct lpfc_hba *phba = vport->phba;
  890. lpfc_vpd_t *vp = &phba->vpd;
  891. lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
  892. return scnprintf(buf, PAGE_SIZE, "%s %08x %08x\n", hdw,
  893. vp->rev.smRev, vp->rev.smFwRev);
  894. }
  895. /**
  896. * lpfc_option_rom_version_show - Return the adapter ROM FCode version
  897. * @dev: class converted to a Scsi_host structure.
  898. * @attr: device attribute, not used.
  899. * @buf: on return contains the ROM and FCode ascii strings.
  900. *
  901. * Returns: size of formatted string.
  902. **/
  903. static ssize_t
  904. lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
  905. char *buf)
  906. {
  907. struct Scsi_Host *shost = class_to_shost(dev);
  908. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  909. struct lpfc_hba *phba = vport->phba;
  910. char fwrev[FW_REV_STR_SIZE];
  911. if (phba->sli_rev < LPFC_SLI_REV4)
  912. return scnprintf(buf, PAGE_SIZE, "%s\n",
  913. phba->OptionROMVersion);
  914. lpfc_decode_firmware_rev(phba, fwrev, 1);
  915. return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);
  916. }
  917. /**
  918. * lpfc_link_state_show - Return the link state of the port
  919. * @dev: class converted to a Scsi_host structure.
  920. * @attr: device attribute, not used.
  921. * @buf: on return contains text describing the state of the link.
  922. *
  923. * Notes:
  924. * The switch statement has no default so zero will be returned.
  925. *
  926. * Returns: size of formatted string.
  927. **/
  928. static ssize_t
  929. lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
  930. char *buf)
  931. {
  932. struct Scsi_Host *shost = class_to_shost(dev);
  933. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  934. struct lpfc_hba *phba = vport->phba;
  935. int len = 0;
  936. switch (phba->link_state) {
  937. case LPFC_LINK_UNKNOWN:
  938. case LPFC_WARM_START:
  939. case LPFC_INIT_START:
  940. case LPFC_INIT_MBX_CMDS:
  941. case LPFC_LINK_DOWN:
  942. case LPFC_HBA_ERROR:
  943. if (test_bit(LINK_DISABLED, &phba->hba_flag))
  944. len += scnprintf(buf + len, PAGE_SIZE-len,
  945. "Link Down - User disabled\n");
  946. else
  947. len += scnprintf(buf + len, PAGE_SIZE-len,
  948. "Link Down\n");
  949. break;
  950. case LPFC_LINK_UP:
  951. case LPFC_CLEAR_LA:
  952. case LPFC_HBA_READY:
  953. len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
  954. switch (vport->port_state) {
  955. case LPFC_LOCAL_CFG_LINK:
  956. len += scnprintf(buf + len, PAGE_SIZE-len,
  957. "Configuring Link\n");
  958. break;
  959. case LPFC_FDISC:
  960. case LPFC_FLOGI:
  961. case LPFC_FABRIC_CFG_LINK:
  962. case LPFC_NS_REG:
  963. case LPFC_NS_QRY:
  964. case LPFC_BUILD_DISC_LIST:
  965. case LPFC_DISC_AUTH:
  966. len += scnprintf(buf + len, PAGE_SIZE - len,
  967. "Discovery\n");
  968. break;
  969. case LPFC_VPORT_READY:
  970. len += scnprintf(buf + len, PAGE_SIZE - len,
  971. "Ready\n");
  972. break;
  973. case LPFC_VPORT_FAILED:
  974. len += scnprintf(buf + len, PAGE_SIZE - len,
  975. "Failed\n");
  976. break;
  977. case LPFC_VPORT_UNKNOWN:
  978. len += scnprintf(buf + len, PAGE_SIZE - len,
  979. "Unknown\n");
  980. break;
  981. }
  982. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  983. if (test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))
  984. len += scnprintf(buf + len, PAGE_SIZE-len,
  985. " Public Loop\n");
  986. else
  987. len += scnprintf(buf + len, PAGE_SIZE-len,
  988. " Private Loop\n");
  989. } else {
  990. if (test_bit(FC_FABRIC, &vport->fc_flag)) {
  991. if (phba->sli_rev == LPFC_SLI_REV4 &&
  992. vport->port_type == LPFC_PHYSICAL_PORT &&
  993. phba->sli4_hba.fawwpn_flag &
  994. LPFC_FAWWPN_FABRIC)
  995. len += scnprintf(buf + len,
  996. PAGE_SIZE - len,
  997. " Fabric FA-PWWN\n");
  998. else
  999. len += scnprintf(buf + len,
  1000. PAGE_SIZE - len,
  1001. " Fabric\n");
  1002. } else {
  1003. len += scnprintf(buf + len, PAGE_SIZE-len,
  1004. " Point-2-Point\n");
  1005. }
  1006. }
  1007. }
  1008. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  1009. ((bf_get(lpfc_sli_intf_if_type,
  1010. &phba->sli4_hba.sli_intf) ==
  1011. LPFC_SLI_INTF_IF_TYPE_6))) {
  1012. struct lpfc_trunk_link link = phba->trunk_link;
  1013. if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
  1014. len += scnprintf(buf + len, PAGE_SIZE - len,
  1015. "Trunk port 0: Link %s %s\n",
  1016. (link.link0.state == LPFC_LINK_UP) ?
  1017. "Up" : "Down. ",
  1018. trunk_errmsg[link.link0.fault]);
  1019. if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
  1020. len += scnprintf(buf + len, PAGE_SIZE - len,
  1021. "Trunk port 1: Link %s %s\n",
  1022. (link.link1.state == LPFC_LINK_UP) ?
  1023. "Up" : "Down. ",
  1024. trunk_errmsg[link.link1.fault]);
  1025. if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
  1026. len += scnprintf(buf + len, PAGE_SIZE - len,
  1027. "Trunk port 2: Link %s %s\n",
  1028. (link.link2.state == LPFC_LINK_UP) ?
  1029. "Up" : "Down. ",
  1030. trunk_errmsg[link.link2.fault]);
  1031. if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
  1032. len += scnprintf(buf + len, PAGE_SIZE - len,
  1033. "Trunk port 3: Link %s %s\n",
  1034. (link.link3.state == LPFC_LINK_UP) ?
  1035. "Up" : "Down. ",
  1036. trunk_errmsg[link.link3.fault]);
  1037. }
  1038. return len;
  1039. }
  1040. /**
  1041. * lpfc_sli4_protocol_show - Return the fip mode of the HBA
  1042. * @dev: class unused variable.
  1043. * @attr: device attribute, not used.
  1044. * @buf: on return contains the module description text.
  1045. *
  1046. * Returns: size of formatted string.
  1047. **/
  1048. static ssize_t
  1049. lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
  1050. char *buf)
  1051. {
  1052. struct Scsi_Host *shost = class_to_shost(dev);
  1053. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1054. struct lpfc_hba *phba = vport->phba;
  1055. if (phba->sli_rev < LPFC_SLI_REV4)
  1056. return scnprintf(buf, PAGE_SIZE, "fc\n");
  1057. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
  1058. if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
  1059. return scnprintf(buf, PAGE_SIZE, "fcoe\n");
  1060. if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
  1061. return scnprintf(buf, PAGE_SIZE, "fc\n");
  1062. }
  1063. return scnprintf(buf, PAGE_SIZE, "unknown\n");
  1064. }
  1065. /**
  1066. * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
  1067. * (OAS) is supported.
  1068. * @dev: class unused variable.
  1069. * @attr: device attribute, not used.
  1070. * @buf: on return contains the module description text.
  1071. *
  1072. * Returns: size of formatted string.
  1073. **/
  1074. static ssize_t
  1075. lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
  1076. char *buf)
  1077. {
  1078. struct Scsi_Host *shost = class_to_shost(dev);
  1079. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  1080. struct lpfc_hba *phba = vport->phba;
  1081. return scnprintf(buf, PAGE_SIZE, "%d\n",
  1082. phba->sli4_hba.pc_sli4_params.oas_supported);
  1083. }
  1084. /**
  1085. * lpfc_link_state_store - Transition the link_state on an HBA port
  1086. * @dev: class device that is converted into a Scsi_host.
  1087. * @attr: device attribute, not used.
  1088. * @buf: one or more lpfc_polling_flags values.
  1089. * @count: not used.
  1090. *
  1091. * Returns:
  1092. * -EINVAL if the buffer is not "up" or "down"
  1093. * return from link state change function if non-zero
  1094. * length of the buf on success
  1095. **/
  1096. static ssize_t
  1097. lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
  1098. const char *buf, size_t count)
  1099. {
  1100. struct Scsi_Host *shost = class_to_shost(dev);
  1101. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1102. struct lpfc_hba *phba = vport->phba;
  1103. int status = -EINVAL;
  1104. if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
  1105. (phba->link_state == LPFC_LINK_DOWN))
  1106. status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  1107. else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
  1108. (phba->link_state >= LPFC_LINK_UP))
  1109. status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
  1110. if (status == 0)
  1111. return strlen(buf);
  1112. else
  1113. return status;
  1114. }
  1115. /**
  1116. * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
  1117. * @dev: class device that is converted into a Scsi_host.
  1118. * @attr: device attribute, not used.
  1119. * @buf: on return contains the sum of fc mapped and unmapped.
  1120. *
  1121. * Description:
  1122. * Returns the ascii text number of the sum of the fc mapped and unmapped
  1123. * vport counts.
  1124. *
  1125. * Returns: size of formatted string.
  1126. **/
  1127. static ssize_t
  1128. lpfc_num_discovered_ports_show(struct device *dev,
  1129. struct device_attribute *attr, char *buf)
  1130. {
  1131. struct Scsi_Host *shost = class_to_shost(dev);
  1132. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1133. return scnprintf(buf, PAGE_SIZE, "%d\n",
  1134. atomic_read(&vport->fc_map_cnt) +
  1135. atomic_read(&vport->fc_unmap_cnt));
  1136. }
  1137. /**
  1138. * lpfc_issue_lip - Misnomer, name carried over from long ago
  1139. * @shost: Scsi_Host pointer.
  1140. *
  1141. * Description:
  1142. * Bring the link down gracefully then re-init the link. The firmware will
  1143. * re-init the fiber channel interface as required. Does not issue a LIP.
  1144. *
  1145. * Returns:
  1146. * -EPERM port offline or management commands are being blocked
  1147. * -ENOMEM cannot allocate memory for the mailbox command
  1148. * -EIO error sending the mailbox command
  1149. * zero for success
  1150. **/
  1151. static int
  1152. lpfc_issue_lip(struct Scsi_Host *shost)
  1153. {
  1154. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1155. struct lpfc_hba *phba = vport->phba;
  1156. LPFC_MBOXQ_t *pmboxq;
  1157. int mbxstatus = MBXERR_ERROR;
  1158. /*
  1159. * If the link is offline, disabled or BLOCK_MGMT_IO
  1160. * it doesn't make any sense to allow issue_lip
  1161. */
  1162. if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
  1163. test_bit(LINK_DISABLED, &phba->hba_flag) ||
  1164. (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
  1165. return -EPERM;
  1166. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  1167. if (!pmboxq)
  1168. return -ENOMEM;
  1169. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1170. pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
  1171. pmboxq->u.mb.mbxOwner = OWN_HOST;
  1172. if (test_bit(FC_PT2PT, &vport->fc_flag))
  1173. clear_bit(FC_PT2PT_NO_NVME, &vport->fc_flag);
  1174. mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
  1175. if ((mbxstatus == MBX_SUCCESS) &&
  1176. (pmboxq->u.mb.mbxStatus == 0 ||
  1177. pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
  1178. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1179. lpfc_init_link(phba, pmboxq, phba->cfg_topology,
  1180. phba->cfg_link_speed);
  1181. mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
  1182. phba->fc_ratov * 2);
  1183. if ((mbxstatus == MBX_SUCCESS) &&
  1184. (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1185. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1186. "2859 SLI authentication is required "
  1187. "for INIT_LINK but has not done yet\n");
  1188. }
  1189. lpfc_set_loopback_flag(phba);
  1190. if (mbxstatus != MBX_TIMEOUT)
  1191. mempool_free(pmboxq, phba->mbox_mem_pool);
  1192. if (mbxstatus == MBXERR_ERROR)
  1193. return -EIO;
  1194. return 0;
  1195. }
  1196. int
  1197. lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
  1198. {
  1199. int cnt = 0;
  1200. spin_lock_irq(lock);
  1201. while (!list_empty(q)) {
  1202. spin_unlock_irq(lock);
  1203. msleep(20);
  1204. if (cnt++ > 250) { /* 5 secs */
  1205. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1206. "0466 Outstanding IO when "
  1207. "bringing Adapter offline\n");
  1208. return 0;
  1209. }
  1210. spin_lock_irq(lock);
  1211. }
  1212. spin_unlock_irq(lock);
  1213. return 1;
  1214. }
  1215. /**
  1216. * lpfc_do_offline - Issues a mailbox command to bring the link down
  1217. * @phba: lpfc_hba pointer.
  1218. * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
  1219. *
  1220. * Notes:
  1221. * Assumes any error from lpfc_do_offline() will be negative.
  1222. * Can wait up to 5 seconds for the port ring buffers count
  1223. * to reach zero, prints a warning if it is not zero and continues.
  1224. * lpfc_workq_post_event() returns a non-zero return code if call fails.
  1225. *
  1226. * Returns:
  1227. * -EIO error posting the event
  1228. * zero for success
  1229. **/
  1230. static int
  1231. lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
  1232. {
  1233. struct completion online_compl;
  1234. struct lpfc_queue *qp = NULL;
  1235. struct lpfc_sli_ring *pring;
  1236. struct lpfc_sli *psli;
  1237. int status = 0;
  1238. int i;
  1239. int rc;
  1240. init_completion(&online_compl);
  1241. rc = lpfc_workq_post_event(phba, &status, &online_compl,
  1242. LPFC_EVT_OFFLINE_PREP);
  1243. if (rc == 0)
  1244. return -ENOMEM;
  1245. wait_for_completion(&online_compl);
  1246. if (status != 0)
  1247. return -EIO;
  1248. psli = &phba->sli;
  1249. /*
  1250. * If freeing the queues have already started, don't access them.
  1251. * Otherwise set FREE_WAIT to indicate that queues are being used
  1252. * to hold the freeing process until we finish.
  1253. */
  1254. spin_lock_irq(&phba->hbalock);
  1255. if (!(psli->sli_flag & LPFC_QUEUE_FREE_INIT)) {
  1256. psli->sli_flag |= LPFC_QUEUE_FREE_WAIT;
  1257. } else {
  1258. spin_unlock_irq(&phba->hbalock);
  1259. goto skip_wait;
  1260. }
  1261. spin_unlock_irq(&phba->hbalock);
  1262. /* Wait a little for things to settle down, but not
  1263. * long enough for dev loss timeout to expire.
  1264. */
  1265. if (phba->sli_rev != LPFC_SLI_REV4) {
  1266. for (i = 0; i < psli->num_rings; i++) {
  1267. pring = &psli->sli3_ring[i];
  1268. if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
  1269. &phba->hbalock))
  1270. goto out;
  1271. }
  1272. } else {
  1273. list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
  1274. pring = qp->pring;
  1275. if (!pring)
  1276. continue;
  1277. if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
  1278. &pring->ring_lock))
  1279. goto out;
  1280. }
  1281. }
  1282. out:
  1283. spin_lock_irq(&phba->hbalock);
  1284. psli->sli_flag &= ~LPFC_QUEUE_FREE_WAIT;
  1285. spin_unlock_irq(&phba->hbalock);
  1286. skip_wait:
  1287. init_completion(&online_compl);
  1288. rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
  1289. if (rc == 0)
  1290. return -ENOMEM;
  1291. wait_for_completion(&online_compl);
  1292. if (status != 0)
  1293. return -EIO;
  1294. return 0;
  1295. }
  1296. /**
  1297. * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
  1298. * @phba: lpfc_hba pointer.
  1299. *
  1300. * Description:
  1301. * Issues a PCI secondary bus reset for the phba->pcidev.
  1302. *
  1303. * Notes:
  1304. * First walks the bus_list to ensure only PCI devices with Emulex
  1305. * vendor id, device ids that support hot reset, only one occurrence
  1306. * of function 0, and all ports on the bus are in offline mode to ensure the
  1307. * hot reset only affects one valid HBA.
  1308. *
  1309. * Returns:
  1310. * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
  1311. * -ENODEV, NULL ptr to pcidev
  1312. * -EBADSLT, detected invalid device
  1313. * -EBUSY, port is not in offline state
  1314. * 0, successful
  1315. */
  1316. static int
  1317. lpfc_reset_pci_bus(struct lpfc_hba *phba)
  1318. {
  1319. struct pci_dev *pdev = phba->pcidev;
  1320. struct Scsi_Host *shost = NULL;
  1321. struct lpfc_hba *phba_other = NULL;
  1322. struct pci_dev *ptr = NULL;
  1323. int res;
  1324. if (phba->cfg_enable_hba_reset != 2)
  1325. return -ENOTSUPP;
  1326. if (!pdev) {
  1327. lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
  1328. return -ENODEV;
  1329. }
  1330. res = lpfc_check_pci_resettable(phba);
  1331. if (res)
  1332. return res;
  1333. /* Walk the list of devices on the pci_dev's bus */
  1334. list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
  1335. /* Check port is offline */
  1336. shost = pci_get_drvdata(ptr);
  1337. if (shost) {
  1338. phba_other =
  1339. ((struct lpfc_vport *)shost->hostdata)->phba;
  1340. if (!test_bit(FC_OFFLINE_MODE,
  1341. &phba_other->pport->fc_flag)) {
  1342. lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
  1343. "8349 WWPN = 0x%02x%02x%02x%02x"
  1344. "%02x%02x%02x%02x is not "
  1345. "offline!\n",
  1346. phba_other->wwpn[0],
  1347. phba_other->wwpn[1],
  1348. phba_other->wwpn[2],
  1349. phba_other->wwpn[3],
  1350. phba_other->wwpn[4],
  1351. phba_other->wwpn[5],
  1352. phba_other->wwpn[6],
  1353. phba_other->wwpn[7]);
  1354. return -EBUSY;
  1355. }
  1356. }
  1357. }
  1358. /* Issue PCI bus reset */
  1359. res = pci_reset_bus(pdev);
  1360. if (res) {
  1361. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1362. "8350 PCI reset bus failed: %d\n", res);
  1363. }
  1364. return res;
  1365. }
  1366. /**
  1367. * lpfc_selective_reset - Offline then onlines the port
  1368. * @phba: lpfc_hba pointer.
  1369. *
  1370. * Description:
  1371. * If the port is configured to allow a reset then the hba is brought
  1372. * offline then online.
  1373. *
  1374. * Notes:
  1375. * Assumes any error from lpfc_do_offline() will be negative.
  1376. * Do not make this function static.
  1377. *
  1378. * Returns:
  1379. * lpfc_do_offline() return code if not zero
  1380. * -EIO reset not configured or error posting the event
  1381. * zero for success
  1382. **/
  1383. int
  1384. lpfc_selective_reset(struct lpfc_hba *phba)
  1385. {
  1386. struct completion online_compl;
  1387. int status = 0;
  1388. int rc;
  1389. if (!phba->cfg_enable_hba_reset)
  1390. return -EACCES;
  1391. if (!test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag)) {
  1392. status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  1393. if (status != 0)
  1394. return status;
  1395. }
  1396. init_completion(&online_compl);
  1397. rc = lpfc_workq_post_event(phba, &status, &online_compl,
  1398. LPFC_EVT_ONLINE);
  1399. if (rc == 0)
  1400. return -ENOMEM;
  1401. wait_for_completion(&online_compl);
  1402. if (status != 0)
  1403. return -EIO;
  1404. return 0;
  1405. }
  1406. /**
  1407. * lpfc_issue_reset - Selectively resets an adapter
  1408. * @dev: class device that is converted into a Scsi_host.
  1409. * @attr: device attribute, not used.
  1410. * @buf: containing the string "selective".
  1411. * @count: unused variable.
  1412. *
  1413. * Description:
  1414. * If the buf contains the string "selective" then lpfc_selective_reset()
  1415. * is called to perform the reset.
  1416. *
  1417. * Notes:
  1418. * Assumes any error from lpfc_selective_reset() will be negative.
  1419. * If lpfc_selective_reset() returns zero then the length of the buffer
  1420. * is returned which indicates success
  1421. *
  1422. * Returns:
  1423. * -EINVAL if the buffer does not contain the string "selective"
  1424. * length of buf if lpfc-selective_reset() if the call succeeds
  1425. * return value of lpfc_selective_reset() if the call fails
  1426. **/
  1427. static ssize_t
  1428. lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
  1429. const char *buf, size_t count)
  1430. {
  1431. struct Scsi_Host *shost = class_to_shost(dev);
  1432. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1433. struct lpfc_hba *phba = vport->phba;
  1434. int status = -EINVAL;
  1435. if (!phba->cfg_enable_hba_reset)
  1436. return -EACCES;
  1437. if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
  1438. status = phba->lpfc_selective_reset(phba);
  1439. if (status == 0)
  1440. return strlen(buf);
  1441. else
  1442. return status;
  1443. }
  1444. /**
  1445. * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
  1446. * @phba: lpfc_hba pointer.
  1447. *
  1448. * Description:
  1449. * SLI4 interface type-2 device to wait on the sliport status register for
  1450. * the readyness after performing a firmware reset.
  1451. *
  1452. * Returns:
  1453. * zero for success, -EPERM when port does not have privilege to perform the
  1454. * reset, -EIO when port timeout from recovering from the reset.
  1455. *
  1456. * Note:
  1457. * As the caller will interpret the return code by value, be careful in making
  1458. * change or addition to return codes.
  1459. **/
  1460. int
  1461. lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
  1462. {
  1463. struct lpfc_register portstat_reg = {0};
  1464. int i;
  1465. msleep(100);
  1466. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  1467. &portstat_reg.word0))
  1468. return -EIO;
  1469. /* verify if privileged for the request operation */
  1470. if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
  1471. !bf_get(lpfc_sliport_status_err, &portstat_reg))
  1472. return -EPERM;
  1473. /* There is no point to wait if the port is in an unrecoverable
  1474. * state.
  1475. */
  1476. if (lpfc_sli4_unrecoverable_port(&portstat_reg))
  1477. return -EIO;
  1478. /* wait for the SLI port firmware ready after firmware reset */
  1479. for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
  1480. msleep(10);
  1481. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  1482. &portstat_reg.word0))
  1483. continue;
  1484. if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
  1485. continue;
  1486. if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
  1487. continue;
  1488. if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
  1489. continue;
  1490. break;
  1491. }
  1492. if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
  1493. return 0;
  1494. else
  1495. return -EIO;
  1496. }
  1497. /**
  1498. * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
  1499. * @phba: lpfc_hba pointer.
  1500. * @opcode: The sli4 config command opcode.
  1501. *
  1502. * Description:
  1503. * Request SLI4 interface type-2 device to perform a physical register set
  1504. * access.
  1505. *
  1506. * Returns:
  1507. * zero for success
  1508. **/
  1509. static ssize_t
  1510. lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
  1511. {
  1512. struct completion online_compl;
  1513. struct pci_dev *pdev = phba->pcidev;
  1514. unsigned long before_fc_flag;
  1515. uint32_t sriov_nr_virtfn;
  1516. uint32_t reg_val;
  1517. int status = 0, rc = 0;
  1518. int job_posted = 1, sriov_err;
  1519. if (!phba->cfg_enable_hba_reset)
  1520. return -EACCES;
  1521. if ((phba->sli_rev < LPFC_SLI_REV4) ||
  1522. (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
  1523. LPFC_SLI_INTF_IF_TYPE_2))
  1524. return -EPERM;
  1525. /* Keep state if we need to restore back */
  1526. before_fc_flag = phba->pport->fc_flag;
  1527. sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
  1528. if (opcode == LPFC_FW_DUMP) {
  1529. init_completion(&online_compl);
  1530. phba->fw_dump_cmpl = &online_compl;
  1531. } else {
  1532. /* Disable SR-IOV virtual functions if enabled */
  1533. if (phba->cfg_sriov_nr_virtfn) {
  1534. pci_disable_sriov(pdev);
  1535. phba->cfg_sriov_nr_virtfn = 0;
  1536. }
  1537. status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  1538. if (status != 0)
  1539. return status;
  1540. /* wait for the device to be quiesced before firmware reset */
  1541. msleep(100);
  1542. }
  1543. reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
  1544. LPFC_CTL_PDEV_CTL_OFFSET);
  1545. if (opcode == LPFC_FW_DUMP)
  1546. reg_val |= LPFC_FW_DUMP_REQUEST;
  1547. else if (opcode == LPFC_FW_RESET)
  1548. reg_val |= LPFC_CTL_PDEV_CTL_FRST;
  1549. else if (opcode == LPFC_DV_RESET)
  1550. reg_val |= LPFC_CTL_PDEV_CTL_DRST;
  1551. writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
  1552. LPFC_CTL_PDEV_CTL_OFFSET);
  1553. /* flush */
  1554. readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
  1555. /* delay driver action following IF_TYPE_2 reset */
  1556. rc = lpfc_sli4_pdev_status_reg_wait(phba);
  1557. if (rc == -EPERM) {
  1558. /* no privilege for reset */
  1559. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1560. "3150 No privilege to perform the requested "
  1561. "access: x%x\n", reg_val);
  1562. } else if (rc == -EIO) {
  1563. /* reset failed, there is nothing more we can do */
  1564. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1565. "3153 Fail to perform the requested "
  1566. "access: x%x\n", reg_val);
  1567. if (phba->fw_dump_cmpl)
  1568. phba->fw_dump_cmpl = NULL;
  1569. return rc;
  1570. }
  1571. /* keep the original port state */
  1572. if (test_bit(FC_OFFLINE_MODE, &before_fc_flag)) {
  1573. if (phba->fw_dump_cmpl)
  1574. phba->fw_dump_cmpl = NULL;
  1575. goto out;
  1576. }
  1577. /* Firmware dump will trigger an HA_ERATT event, and
  1578. * lpfc_handle_eratt_s4 routine already handles bringing the port back
  1579. * online.
  1580. */
  1581. if (opcode == LPFC_FW_DUMP) {
  1582. wait_for_completion(phba->fw_dump_cmpl);
  1583. } else {
  1584. init_completion(&online_compl);
  1585. job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
  1586. LPFC_EVT_ONLINE);
  1587. if (!job_posted)
  1588. goto out;
  1589. wait_for_completion(&online_compl);
  1590. }
  1591. out:
  1592. /* in any case, restore the virtual functions enabled as before */
  1593. if (sriov_nr_virtfn) {
  1594. /* If fw_dump was performed, first disable to clean up */
  1595. if (opcode == LPFC_FW_DUMP) {
  1596. pci_disable_sriov(pdev);
  1597. phba->cfg_sriov_nr_virtfn = 0;
  1598. }
  1599. sriov_err =
  1600. lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
  1601. if (!sriov_err)
  1602. phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
  1603. }
  1604. /* return proper error code */
  1605. if (!rc) {
  1606. if (!job_posted)
  1607. rc = -ENOMEM;
  1608. else if (status)
  1609. rc = -EIO;
  1610. }
  1611. return rc;
  1612. }
  1613. /**
  1614. * lpfc_nport_evt_cnt_show - Return the number of nport events
  1615. * @dev: class device that is converted into a Scsi_host.
  1616. * @attr: device attribute, not used.
  1617. * @buf: on return contains the ascii number of nport events.
  1618. *
  1619. * Returns: size of formatted string.
  1620. **/
  1621. static ssize_t
  1622. lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
  1623. char *buf)
  1624. {
  1625. struct Scsi_Host *shost = class_to_shost(dev);
  1626. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1627. struct lpfc_hba *phba = vport->phba;
  1628. return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
  1629. }
  1630. static int
  1631. lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
  1632. {
  1633. LPFC_MBOXQ_t *mbox = NULL;
  1634. u32 payload_len;
  1635. unsigned long val = 0;
  1636. char *pval = NULL;
  1637. int rc = 0;
  1638. if (!strncmp("enable", buff_out,
  1639. strlen("enable"))) {
  1640. pval = buff_out + strlen("enable") + 1;
  1641. rc = kstrtoul(pval, 0, &val);
  1642. if (rc)
  1643. return rc; /* Invalid number */
  1644. } else if (!strncmp("disable", buff_out,
  1645. strlen("disable"))) {
  1646. val = 0;
  1647. } else {
  1648. return -EINVAL; /* Invalid command */
  1649. }
  1650. switch (val) {
  1651. case 0:
  1652. val = 0x0; /* Disable */
  1653. break;
  1654. case 2:
  1655. val = 0x1; /* Enable two port trunk */
  1656. break;
  1657. case 4:
  1658. val = 0x2; /* Enable four port trunk */
  1659. break;
  1660. default:
  1661. return -EINVAL;
  1662. }
  1663. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1664. "0070 Set trunk mode with val %ld ", val);
  1665. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1666. if (!mbox)
  1667. return -ENOMEM;
  1668. payload_len = sizeof(struct lpfc_mbx_set_trunk_mode) -
  1669. sizeof(struct lpfc_sli4_cfg_mhdr);
  1670. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  1671. LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
  1672. payload_len, LPFC_SLI4_MBX_EMBED);
  1673. bf_set(lpfc_mbx_set_trunk_mode,
  1674. &mbox->u.mqe.un.set_trunk_mode,
  1675. val);
  1676. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  1677. if (rc)
  1678. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1679. "0071 Set trunk mode failed with status: %d",
  1680. rc);
  1681. mempool_free(mbox, phba->mbox_mem_pool);
  1682. return 0;
  1683. }
  1684. static ssize_t
  1685. lpfc_xcvr_data_show(struct device *dev, struct device_attribute *attr,
  1686. char *buf)
  1687. {
  1688. struct Scsi_Host *shost = class_to_shost(dev);
  1689. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  1690. struct lpfc_hba *phba = vport->phba;
  1691. int rc;
  1692. int len = 0;
  1693. struct lpfc_rdp_context *rdp_context;
  1694. u16 temperature;
  1695. u16 rx_power;
  1696. u16 tx_bias;
  1697. u16 tx_power;
  1698. u16 vcc;
  1699. char chbuf[128];
  1700. u16 wavelength = 0;
  1701. struct sff_trasnceiver_codes_byte7 *trasn_code_byte7;
  1702. /* Get transceiver information */
  1703. rdp_context = kmalloc(sizeof(*rdp_context), GFP_KERNEL);
  1704. if (!rdp_context) {
  1705. len = scnprintf(buf, PAGE_SIZE - len,
  1706. "SPF info NA: alloc failure\n");
  1707. return len;
  1708. }
  1709. rc = lpfc_get_sfp_info_wait(phba, rdp_context);
  1710. if (rc) {
  1711. len = scnprintf(buf, PAGE_SIZE - len, "SFP info NA:\n");
  1712. goto out_free_rdp;
  1713. }
  1714. strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_NAME], 16);
  1715. len = scnprintf(buf, PAGE_SIZE - len, "VendorName:\t%s\n", chbuf);
  1716. len += scnprintf(buf + len, PAGE_SIZE - len,
  1717. "VendorOUI:\t%02x-%02x-%02x\n",
  1718. (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI],
  1719. (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 1],
  1720. (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 2]);
  1721. strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_PN], 16);
  1722. len += scnprintf(buf + len, PAGE_SIZE - len, "VendorPN:\t%s\n", chbuf);
  1723. strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_SN], 16);
  1724. len += scnprintf(buf + len, PAGE_SIZE - len, "VendorSN:\t%s\n", chbuf);
  1725. strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_REV], 4);
  1726. len += scnprintf(buf + len, PAGE_SIZE - len, "VendorRev:\t%s\n", chbuf);
  1727. strscpy(chbuf, &rdp_context->page_a0[SSF_DATE_CODE], 8);
  1728. len += scnprintf(buf + len, PAGE_SIZE - len, "DateCode:\t%s\n", chbuf);
  1729. len += scnprintf(buf + len, PAGE_SIZE - len, "Identifier:\t%xh\n",
  1730. (uint8_t)rdp_context->page_a0[SSF_IDENTIFIER]);
  1731. len += scnprintf(buf + len, PAGE_SIZE - len, "ExtIdentifier:\t%xh\n",
  1732. (uint8_t)rdp_context->page_a0[SSF_EXT_IDENTIFIER]);
  1733. len += scnprintf(buf + len, PAGE_SIZE - len, "Connector:\t%xh\n",
  1734. (uint8_t)rdp_context->page_a0[SSF_CONNECTOR]);
  1735. wavelength = (rdp_context->page_a0[SSF_WAVELENGTH_B1] << 8) |
  1736. rdp_context->page_a0[SSF_WAVELENGTH_B0];
  1737. len += scnprintf(buf + len, PAGE_SIZE - len, "Wavelength:\t%d nm\n",
  1738. wavelength);
  1739. trasn_code_byte7 = (struct sff_trasnceiver_codes_byte7 *)
  1740. &rdp_context->page_a0[SSF_TRANSCEIVER_CODE_B7];
  1741. len += scnprintf(buf + len, PAGE_SIZE - len, "Speeds: \t");
  1742. if (*(uint8_t *)trasn_code_byte7 == 0) {
  1743. len += scnprintf(buf + len, PAGE_SIZE - len, "Unknown\n");
  1744. } else {
  1745. if (trasn_code_byte7->fc_sp_100MB)
  1746. len += scnprintf(buf + len, PAGE_SIZE - len, "1 ");
  1747. if (trasn_code_byte7->fc_sp_200mb)
  1748. len += scnprintf(buf + len, PAGE_SIZE - len, "2 ");
  1749. if (trasn_code_byte7->fc_sp_400MB)
  1750. len += scnprintf(buf + len, PAGE_SIZE - len, "4 ");
  1751. if (trasn_code_byte7->fc_sp_800MB)
  1752. len += scnprintf(buf + len, PAGE_SIZE - len, "8 ");
  1753. if (trasn_code_byte7->fc_sp_1600MB)
  1754. len += scnprintf(buf + len, PAGE_SIZE - len, "16 ");
  1755. if (trasn_code_byte7->fc_sp_3200MB)
  1756. len += scnprintf(buf + len, PAGE_SIZE - len, "32 ");
  1757. if (trasn_code_byte7->speed_chk_ecc)
  1758. len += scnprintf(buf + len, PAGE_SIZE - len, "64 ");
  1759. len += scnprintf(buf + len, PAGE_SIZE - len, "GB\n");
  1760. }
  1761. temperature = (rdp_context->page_a2[SFF_TEMPERATURE_B1] << 8 |
  1762. rdp_context->page_a2[SFF_TEMPERATURE_B0]);
  1763. vcc = (rdp_context->page_a2[SFF_VCC_B1] << 8 |
  1764. rdp_context->page_a2[SFF_VCC_B0]);
  1765. tx_power = (rdp_context->page_a2[SFF_TXPOWER_B1] << 8 |
  1766. rdp_context->page_a2[SFF_TXPOWER_B0]);
  1767. tx_bias = (rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
  1768. rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B0]);
  1769. rx_power = (rdp_context->page_a2[SFF_RXPOWER_B1] << 8 |
  1770. rdp_context->page_a2[SFF_RXPOWER_B0]);
  1771. len += scnprintf(buf + len, PAGE_SIZE - len,
  1772. "Temperature:\tx%04x C\n", temperature);
  1773. len += scnprintf(buf + len, PAGE_SIZE - len, "Vcc:\t\tx%04x V\n", vcc);
  1774. len += scnprintf(buf + len, PAGE_SIZE - len,
  1775. "TxBiasCurrent:\tx%04x mA\n", tx_bias);
  1776. len += scnprintf(buf + len, PAGE_SIZE - len, "TxPower:\tx%04x mW\n",
  1777. tx_power);
  1778. len += scnprintf(buf + len, PAGE_SIZE - len, "RxPower:\tx%04x mW\n",
  1779. rx_power);
  1780. out_free_rdp:
  1781. kfree(rdp_context);
  1782. return len;
  1783. }
  1784. /**
  1785. * lpfc_board_mode_show - Return the state of the board
  1786. * @dev: class device that is converted into a Scsi_host.
  1787. * @attr: device attribute, not used.
  1788. * @buf: on return contains the state of the adapter.
  1789. *
  1790. * Returns: size of formatted string.
  1791. **/
  1792. static ssize_t
  1793. lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
  1794. char *buf)
  1795. {
  1796. struct Scsi_Host *shost = class_to_shost(dev);
  1797. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1798. struct lpfc_hba *phba = vport->phba;
  1799. char * state;
  1800. if (phba->link_state == LPFC_HBA_ERROR)
  1801. state = "error";
  1802. else if (phba->link_state == LPFC_WARM_START)
  1803. state = "warm start";
  1804. else if (phba->link_state == LPFC_INIT_START)
  1805. state = "offline";
  1806. else
  1807. state = "online";
  1808. return scnprintf(buf, PAGE_SIZE, "%s\n", state);
  1809. }
  1810. /**
  1811. * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
  1812. * @dev: class device that is converted into a Scsi_host.
  1813. * @attr: device attribute, not used.
  1814. * @buf: containing one of the strings "online", "offline", "warm" or "error".
  1815. * @count: unused variable.
  1816. *
  1817. * Returns:
  1818. * -EACCES if enable hba reset not enabled
  1819. * -EINVAL if the buffer does not contain a valid string (see above)
  1820. * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
  1821. * buf length greater than zero indicates success
  1822. **/
  1823. static ssize_t
  1824. lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
  1825. const char *buf, size_t count)
  1826. {
  1827. struct Scsi_Host *shost = class_to_shost(dev);
  1828. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1829. struct lpfc_hba *phba = vport->phba;
  1830. struct completion online_compl;
  1831. char *board_mode_str = NULL;
  1832. int status = 0;
  1833. int rc;
  1834. if (!phba->cfg_enable_hba_reset) {
  1835. status = -EACCES;
  1836. goto board_mode_out;
  1837. }
  1838. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1839. "3050 lpfc_board_mode set to %s\n", buf);
  1840. init_completion(&online_compl);
  1841. if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
  1842. rc = lpfc_workq_post_event(phba, &status, &online_compl,
  1843. LPFC_EVT_ONLINE);
  1844. if (rc == 0) {
  1845. status = -ENOMEM;
  1846. goto board_mode_out;
  1847. }
  1848. wait_for_completion(&online_compl);
  1849. if (status)
  1850. status = -EIO;
  1851. } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
  1852. status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  1853. else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
  1854. if (phba->sli_rev == LPFC_SLI_REV4)
  1855. status = -EINVAL;
  1856. else
  1857. status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
  1858. else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
  1859. if (phba->sli_rev == LPFC_SLI_REV4)
  1860. status = -EINVAL;
  1861. else
  1862. status = lpfc_do_offline(phba, LPFC_EVT_KILL);
  1863. else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
  1864. status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
  1865. else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
  1866. status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
  1867. else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
  1868. status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
  1869. else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
  1870. == 0)
  1871. status = lpfc_reset_pci_bus(phba);
  1872. else if (strncmp(buf, "heartbeat", sizeof("heartbeat") - 1) == 0)
  1873. lpfc_issue_hb_tmo(phba);
  1874. else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
  1875. status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
  1876. else
  1877. status = -EINVAL;
  1878. board_mode_out:
  1879. if (!status)
  1880. return strlen(buf);
  1881. else {
  1882. board_mode_str = strchr(buf, '\n');
  1883. if (board_mode_str)
  1884. *board_mode_str = '\0';
  1885. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1886. "3097 Failed \"%s\", status(%d), "
  1887. "fc_flag(x%lx)\n",
  1888. buf, status, phba->pport->fc_flag);
  1889. return status;
  1890. }
  1891. }
  1892. /**
  1893. * lpfc_get_hba_info - Return various bits of informaton about the adapter
  1894. * @phba: pointer to the adapter structure.
  1895. * @mxri: max xri count.
  1896. * @axri: available xri count.
  1897. * @mrpi: max rpi count.
  1898. * @arpi: available rpi count.
  1899. * @mvpi: max vpi count.
  1900. * @avpi: available vpi count.
  1901. *
  1902. * Description:
  1903. * If an integer pointer for an count is not null then the value for the
  1904. * count is returned.
  1905. *
  1906. * Returns:
  1907. * zero on error
  1908. * one for success
  1909. **/
  1910. static int
  1911. lpfc_get_hba_info(struct lpfc_hba *phba,
  1912. uint32_t *mxri, uint32_t *axri,
  1913. uint32_t *mrpi, uint32_t *arpi,
  1914. uint32_t *mvpi, uint32_t *avpi)
  1915. {
  1916. LPFC_MBOXQ_t *pmboxq;
  1917. MAILBOX_t *pmb;
  1918. int rc = 0;
  1919. struct lpfc_sli4_hba *sli4_hba;
  1920. struct lpfc_max_cfg_param *max_cfg_param;
  1921. u16 rsrc_ext_cnt, rsrc_ext_size, max_vpi;
  1922. /*
  1923. * prevent udev from issuing mailbox commands until the port is
  1924. * configured.
  1925. */
  1926. if (phba->link_state < LPFC_LINK_DOWN ||
  1927. !phba->mbox_mem_pool ||
  1928. (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
  1929. return 0;
  1930. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  1931. return 0;
  1932. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1933. if (!pmboxq)
  1934. return 0;
  1935. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1936. pmb = &pmboxq->u.mb;
  1937. pmb->mbxCommand = MBX_READ_CONFIG;
  1938. pmb->mbxOwner = OWN_HOST;
  1939. pmboxq->ctx_buf = NULL;
  1940. if (test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag))
  1941. rc = MBX_NOT_FINISHED;
  1942. else
  1943. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1944. if (rc != MBX_SUCCESS) {
  1945. if (rc != MBX_TIMEOUT)
  1946. mempool_free(pmboxq, phba->mbox_mem_pool);
  1947. return 0;
  1948. }
  1949. if (phba->sli_rev == LPFC_SLI_REV4) {
  1950. sli4_hba = &phba->sli4_hba;
  1951. max_cfg_param = &sli4_hba->max_cfg_param;
  1952. /* Normally, extents are not used */
  1953. if (!phba->sli4_hba.extents_in_use) {
  1954. if (mrpi)
  1955. *mrpi = max_cfg_param->max_rpi;
  1956. if (mxri)
  1957. *mxri = max_cfg_param->max_xri;
  1958. if (mvpi) {
  1959. max_vpi = max_cfg_param->max_vpi;
  1960. /* Limit the max we support */
  1961. if (max_vpi > LPFC_MAX_VPI)
  1962. max_vpi = LPFC_MAX_VPI;
  1963. *mvpi = max_vpi;
  1964. }
  1965. } else { /* Extents in use */
  1966. if (mrpi) {
  1967. if (lpfc_sli4_get_avail_extnt_rsrc(phba,
  1968. LPFC_RSC_TYPE_FCOE_RPI,
  1969. &rsrc_ext_cnt,
  1970. &rsrc_ext_size)) {
  1971. rc = 0;
  1972. goto free_pmboxq;
  1973. }
  1974. *mrpi = rsrc_ext_cnt * rsrc_ext_size;
  1975. }
  1976. if (mxri) {
  1977. if (lpfc_sli4_get_avail_extnt_rsrc(phba,
  1978. LPFC_RSC_TYPE_FCOE_XRI,
  1979. &rsrc_ext_cnt,
  1980. &rsrc_ext_size)) {
  1981. rc = 0;
  1982. goto free_pmboxq;
  1983. }
  1984. *mxri = rsrc_ext_cnt * rsrc_ext_size;
  1985. }
  1986. if (mvpi) {
  1987. if (lpfc_sli4_get_avail_extnt_rsrc(phba,
  1988. LPFC_RSC_TYPE_FCOE_VPI,
  1989. &rsrc_ext_cnt,
  1990. &rsrc_ext_size)) {
  1991. rc = 0;
  1992. goto free_pmboxq;
  1993. }
  1994. max_vpi = rsrc_ext_cnt * rsrc_ext_size;
  1995. /* Limit the max we support */
  1996. if (max_vpi > LPFC_MAX_VPI)
  1997. max_vpi = LPFC_MAX_VPI;
  1998. *mvpi = max_vpi;
  1999. }
  2000. }
  2001. } else {
  2002. if (mrpi)
  2003. *mrpi = pmb->un.varRdConfig.max_rpi;
  2004. if (arpi)
  2005. *arpi = pmb->un.varRdConfig.avail_rpi;
  2006. if (mxri)
  2007. *mxri = pmb->un.varRdConfig.max_xri;
  2008. if (axri)
  2009. *axri = pmb->un.varRdConfig.avail_xri;
  2010. if (mvpi)
  2011. *mvpi = pmb->un.varRdConfig.max_vpi;
  2012. if (avpi) {
  2013. /* avail_vpi is only valid if link is up and ready */
  2014. if (phba->link_state == LPFC_HBA_READY)
  2015. *avpi = pmb->un.varRdConfig.avail_vpi;
  2016. else
  2017. *avpi = pmb->un.varRdConfig.max_vpi;
  2018. }
  2019. }
  2020. /* Success */
  2021. rc = 1;
  2022. free_pmboxq:
  2023. mempool_free(pmboxq, phba->mbox_mem_pool);
  2024. return rc;
  2025. }
  2026. /**
  2027. * lpfc_max_rpi_show - Return maximum rpi
  2028. * @dev: class device that is converted into a Scsi_host.
  2029. * @attr: device attribute, not used.
  2030. * @buf: on return contains the maximum rpi count in decimal or "Unknown".
  2031. *
  2032. * Description:
  2033. * Calls lpfc_get_hba_info() asking for just the mrpi count.
  2034. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  2035. * to "Unknown" and the buffer length is returned, therefore the caller
  2036. * must check for "Unknown" in the buffer to detect a failure.
  2037. *
  2038. * Returns: size of formatted string.
  2039. **/
  2040. static ssize_t
  2041. lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
  2042. char *buf)
  2043. {
  2044. struct Scsi_Host *shost = class_to_shost(dev);
  2045. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2046. struct lpfc_hba *phba = vport->phba;
  2047. uint32_t cnt;
  2048. if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
  2049. return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
  2050. return scnprintf(buf, PAGE_SIZE, "Unknown\n");
  2051. }
  2052. /**
  2053. * lpfc_used_rpi_show - Return maximum rpi minus available rpi
  2054. * @dev: class device that is converted into a Scsi_host.
  2055. * @attr: device attribute, not used.
  2056. * @buf: containing the used rpi count in decimal or "Unknown".
  2057. *
  2058. * Description:
  2059. * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
  2060. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  2061. * to "Unknown" and the buffer length is returned, therefore the caller
  2062. * must check for "Unknown" in the buffer to detect a failure.
  2063. *
  2064. * Returns: size of formatted string.
  2065. **/
  2066. static ssize_t
  2067. lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
  2068. char *buf)
  2069. {
  2070. struct Scsi_Host *shost = class_to_shost(dev);
  2071. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2072. struct lpfc_hba *phba = vport->phba;
  2073. struct lpfc_sli4_hba *sli4_hba;
  2074. struct lpfc_max_cfg_param *max_cfg_param;
  2075. u32 cnt = 0, acnt = 0;
  2076. if (phba->sli_rev == LPFC_SLI_REV4) {
  2077. sli4_hba = &phba->sli4_hba;
  2078. max_cfg_param = &sli4_hba->max_cfg_param;
  2079. return scnprintf(buf, PAGE_SIZE, "%d\n",
  2080. max_cfg_param->rpi_used);
  2081. } else {
  2082. if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
  2083. return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  2084. }
  2085. return scnprintf(buf, PAGE_SIZE, "Unknown\n");
  2086. }
  2087. /**
  2088. * lpfc_max_xri_show - Return maximum xri
  2089. * @dev: class device that is converted into a Scsi_host.
  2090. * @attr: device attribute, not used.
  2091. * @buf: on return contains the maximum xri count in decimal or "Unknown".
  2092. *
  2093. * Description:
  2094. * Calls lpfc_get_hba_info() asking for just the mrpi count.
  2095. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  2096. * to "Unknown" and the buffer length is returned, therefore the caller
  2097. * must check for "Unknown" in the buffer to detect a failure.
  2098. *
  2099. * Returns: size of formatted string.
  2100. **/
  2101. static ssize_t
  2102. lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
  2103. char *buf)
  2104. {
  2105. struct Scsi_Host *shost = class_to_shost(dev);
  2106. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2107. struct lpfc_hba *phba = vport->phba;
  2108. uint32_t cnt;
  2109. if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
  2110. return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
  2111. return scnprintf(buf, PAGE_SIZE, "Unknown\n");
  2112. }
  2113. /**
  2114. * lpfc_used_xri_show - Return maximum xpi minus the available xpi
  2115. * @dev: class device that is converted into a Scsi_host.
  2116. * @attr: device attribute, not used.
  2117. * @buf: on return contains the used xri count in decimal or "Unknown".
  2118. *
  2119. * Description:
  2120. * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
  2121. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  2122. * to "Unknown" and the buffer length is returned, therefore the caller
  2123. * must check for "Unknown" in the buffer to detect a failure.
  2124. *
  2125. * Returns: size of formatted string.
  2126. **/
  2127. static ssize_t
  2128. lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
  2129. char *buf)
  2130. {
  2131. struct Scsi_Host *shost = class_to_shost(dev);
  2132. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2133. struct lpfc_hba *phba = vport->phba;
  2134. struct lpfc_sli4_hba *sli4_hba;
  2135. struct lpfc_max_cfg_param *max_cfg_param;
  2136. u32 cnt = 0, acnt = 0;
  2137. if (phba->sli_rev == LPFC_SLI_REV4) {
  2138. sli4_hba = &phba->sli4_hba;
  2139. max_cfg_param = &sli4_hba->max_cfg_param;
  2140. return scnprintf(buf, PAGE_SIZE, "%d\n",
  2141. max_cfg_param->xri_used);
  2142. } else {
  2143. if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
  2144. return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  2145. }
  2146. return scnprintf(buf, PAGE_SIZE, "Unknown\n");
  2147. }
  2148. /**
  2149. * lpfc_max_vpi_show - Return maximum vpi
  2150. * @dev: class device that is converted into a Scsi_host.
  2151. * @attr: device attribute, not used.
  2152. * @buf: on return contains the maximum vpi count in decimal or "Unknown".
  2153. *
  2154. * Description:
  2155. * Calls lpfc_get_hba_info() asking for just the mvpi count.
  2156. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  2157. * to "Unknown" and the buffer length is returned, therefore the caller
  2158. * must check for "Unknown" in the buffer to detect a failure.
  2159. *
  2160. * Returns: size of formatted string.
  2161. **/
  2162. static ssize_t
  2163. lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
  2164. char *buf)
  2165. {
  2166. struct Scsi_Host *shost = class_to_shost(dev);
  2167. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2168. struct lpfc_hba *phba = vport->phba;
  2169. uint32_t cnt;
  2170. if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
  2171. return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
  2172. return scnprintf(buf, PAGE_SIZE, "Unknown\n");
  2173. }
  2174. /**
  2175. * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
  2176. * @dev: class device that is converted into a Scsi_host.
  2177. * @attr: device attribute, not used.
  2178. * @buf: on return contains the used vpi count in decimal or "Unknown".
  2179. *
  2180. * Description:
  2181. * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
  2182. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  2183. * to "Unknown" and the buffer length is returned, therefore the caller
  2184. * must check for "Unknown" in the buffer to detect a failure.
  2185. *
  2186. * Returns: size of formatted string.
  2187. **/
  2188. static ssize_t
  2189. lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
  2190. char *buf)
  2191. {
  2192. struct Scsi_Host *shost = class_to_shost(dev);
  2193. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2194. struct lpfc_hba *phba = vport->phba;
  2195. struct lpfc_sli4_hba *sli4_hba;
  2196. struct lpfc_max_cfg_param *max_cfg_param;
  2197. u32 cnt = 0, acnt = 0;
  2198. if (phba->sli_rev == LPFC_SLI_REV4) {
  2199. sli4_hba = &phba->sli4_hba;
  2200. max_cfg_param = &sli4_hba->max_cfg_param;
  2201. return scnprintf(buf, PAGE_SIZE, "%d\n",
  2202. max_cfg_param->vpi_used);
  2203. } else {
  2204. if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
  2205. return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  2206. }
  2207. return scnprintf(buf, PAGE_SIZE, "Unknown\n");
  2208. }
  2209. /**
  2210. * lpfc_npiv_info_show - Return text about NPIV support for the adapter
  2211. * @dev: class device that is converted into a Scsi_host.
  2212. * @attr: device attribute, not used.
  2213. * @buf: text that must be interpreted to determine if npiv is supported.
  2214. *
  2215. * Description:
  2216. * Buffer will contain text indicating npiv is not suppoerted on the port,
  2217. * the port is an NPIV physical port, or it is an npiv virtual port with
  2218. * the id of the vport.
  2219. *
  2220. * Returns: size of formatted string.
  2221. **/
  2222. static ssize_t
  2223. lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
  2224. char *buf)
  2225. {
  2226. struct Scsi_Host *shost = class_to_shost(dev);
  2227. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2228. struct lpfc_hba *phba = vport->phba;
  2229. if (!(phba->max_vpi))
  2230. return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
  2231. if (vport->port_type == LPFC_PHYSICAL_PORT)
  2232. return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
  2233. return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
  2234. }
  2235. /**
  2236. * lpfc_poll_show - Return text about poll support for the adapter
  2237. * @dev: class device that is converted into a Scsi_host.
  2238. * @attr: device attribute, not used.
  2239. * @buf: on return contains the cfg_poll in hex.
  2240. *
  2241. * Notes:
  2242. * cfg_poll should be a lpfc_polling_flags type.
  2243. *
  2244. * Returns: size of formatted string.
  2245. **/
  2246. static ssize_t
  2247. lpfc_poll_show(struct device *dev, struct device_attribute *attr,
  2248. char *buf)
  2249. {
  2250. struct Scsi_Host *shost = class_to_shost(dev);
  2251. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2252. struct lpfc_hba *phba = vport->phba;
  2253. return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
  2254. }
  2255. /**
  2256. * lpfc_poll_store - Set the value of cfg_poll for the adapter
  2257. * @dev: class device that is converted into a Scsi_host.
  2258. * @attr: device attribute, not used.
  2259. * @buf: one or more lpfc_polling_flags values.
  2260. * @count: not used.
  2261. *
  2262. * Notes:
  2263. * buf contents converted to integer and checked for a valid value.
  2264. *
  2265. * Returns:
  2266. * -EINVAL if the buffer connot be converted or is out of range
  2267. * length of the buf on success
  2268. **/
  2269. static ssize_t
  2270. lpfc_poll_store(struct device *dev, struct device_attribute *attr,
  2271. const char *buf, size_t count)
  2272. {
  2273. struct Scsi_Host *shost = class_to_shost(dev);
  2274. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2275. struct lpfc_hba *phba = vport->phba;
  2276. uint32_t creg_val;
  2277. uint32_t old_val;
  2278. int val=0;
  2279. if (!isdigit(buf[0]))
  2280. return -EINVAL;
  2281. if (sscanf(buf, "%i", &val) != 1)
  2282. return -EINVAL;
  2283. if ((val & 0x3) != val)
  2284. return -EINVAL;
  2285. if (phba->sli_rev == LPFC_SLI_REV4)
  2286. val = 0;
  2287. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2288. "3051 lpfc_poll changed from %d to %d\n",
  2289. phba->cfg_poll, val);
  2290. spin_lock_irq(&phba->hbalock);
  2291. old_val = phba->cfg_poll;
  2292. if (val & ENABLE_FCP_RING_POLLING) {
  2293. if ((val & DISABLE_FCP_RING_INT) &&
  2294. !(old_val & DISABLE_FCP_RING_INT)) {
  2295. if (lpfc_readl(phba->HCregaddr, &creg_val)) {
  2296. spin_unlock_irq(&phba->hbalock);
  2297. return -EINVAL;
  2298. }
  2299. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  2300. writel(creg_val, phba->HCregaddr);
  2301. readl(phba->HCregaddr); /* flush */
  2302. lpfc_poll_start_timer(phba);
  2303. }
  2304. } else if (val != 0x0) {
  2305. spin_unlock_irq(&phba->hbalock);
  2306. return -EINVAL;
  2307. }
  2308. if (!(val & DISABLE_FCP_RING_INT) &&
  2309. (old_val & DISABLE_FCP_RING_INT))
  2310. {
  2311. spin_unlock_irq(&phba->hbalock);
  2312. del_timer(&phba->fcp_poll_timer);
  2313. spin_lock_irq(&phba->hbalock);
  2314. if (lpfc_readl(phba->HCregaddr, &creg_val)) {
  2315. spin_unlock_irq(&phba->hbalock);
  2316. return -EINVAL;
  2317. }
  2318. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  2319. writel(creg_val, phba->HCregaddr);
  2320. readl(phba->HCregaddr); /* flush */
  2321. }
  2322. phba->cfg_poll = val;
  2323. spin_unlock_irq(&phba->hbalock);
  2324. return strlen(buf);
  2325. }
  2326. /**
  2327. * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
  2328. * @dev: class converted to a Scsi_host structure.
  2329. * @attr: device attribute, not used.
  2330. * @buf: on return contains the formatted support level.
  2331. *
  2332. * Description:
  2333. * Returns the maximum number of virtual functions a physical function can
  2334. * support, 0 will be returned if called on virtual function.
  2335. *
  2336. * Returns: size of formatted string.
  2337. **/
  2338. static ssize_t
  2339. lpfc_sriov_hw_max_virtfn_show(struct device *dev,
  2340. struct device_attribute *attr,
  2341. char *buf)
  2342. {
  2343. struct Scsi_Host *shost = class_to_shost(dev);
  2344. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2345. struct lpfc_hba *phba = vport->phba;
  2346. uint16_t max_nr_virtfn;
  2347. max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
  2348. return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
  2349. }
  2350. /**
  2351. * lpfc_enable_bbcr_set: Sets an attribute value.
  2352. * @phba: pointer to the adapter structure.
  2353. * @val: integer attribute value.
  2354. *
  2355. * Description:
  2356. * Validates the min and max values then sets the
  2357. * adapter config field if in the valid range. prints error message
  2358. * and does not set the parameter if invalid.
  2359. *
  2360. * Returns:
  2361. * zero on success
  2362. * -EINVAL if val is invalid
  2363. */
  2364. static ssize_t
  2365. lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
  2366. {
  2367. if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
  2368. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2369. "3068 lpfc_enable_bbcr changed from %d to "
  2370. "%d\n", phba->cfg_enable_bbcr, val);
  2371. phba->cfg_enable_bbcr = val;
  2372. return 0;
  2373. }
  2374. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2375. "0451 lpfc_enable_bbcr cannot set to %d, range is 0, "
  2376. "1\n", val);
  2377. return -EINVAL;
  2378. }
  2379. /*
  2380. * lpfc_param_show - Return a cfg attribute value in decimal
  2381. *
  2382. * Description:
  2383. * Macro that given an attr e.g. hba_queue_depth expands
  2384. * into a function with the name lpfc_hba_queue_depth_show.
  2385. *
  2386. * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
  2387. * @dev: class device that is converted into a Scsi_host.
  2388. * @attr: device attribute, not used.
  2389. * @buf: on return contains the attribute value in decimal.
  2390. *
  2391. * Returns: size of formatted string.
  2392. **/
  2393. #define lpfc_param_show(attr) \
  2394. static ssize_t \
  2395. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  2396. char *buf) \
  2397. { \
  2398. struct Scsi_Host *shost = class_to_shost(dev);\
  2399. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  2400. struct lpfc_hba *phba = vport->phba;\
  2401. return scnprintf(buf, PAGE_SIZE, "%d\n",\
  2402. phba->cfg_##attr);\
  2403. }
  2404. /*
  2405. * lpfc_param_hex_show - Return a cfg attribute value in hex
  2406. *
  2407. * Description:
  2408. * Macro that given an attr e.g. hba_queue_depth expands
  2409. * into a function with the name lpfc_hba_queue_depth_show
  2410. *
  2411. * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
  2412. * @dev: class device that is converted into a Scsi_host.
  2413. * @attr: device attribute, not used.
  2414. * @buf: on return contains the attribute value in hexadecimal.
  2415. *
  2416. * Returns: size of formatted string.
  2417. **/
  2418. #define lpfc_param_hex_show(attr) \
  2419. static ssize_t \
  2420. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  2421. char *buf) \
  2422. { \
  2423. struct Scsi_Host *shost = class_to_shost(dev);\
  2424. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  2425. struct lpfc_hba *phba = vport->phba;\
  2426. uint val = 0;\
  2427. val = phba->cfg_##attr;\
  2428. return scnprintf(buf, PAGE_SIZE, "%#x\n",\
  2429. phba->cfg_##attr);\
  2430. }
  2431. /*
  2432. * lpfc_param_init - Initializes a cfg attribute
  2433. *
  2434. * Description:
  2435. * Macro that given an attr e.g. hba_queue_depth expands
  2436. * into a function with the name lpfc_hba_queue_depth_init. The macro also
  2437. * takes a default argument, a minimum and maximum argument.
  2438. *
  2439. * lpfc_##attr##_init: Initializes an attribute.
  2440. * @phba: pointer to the adapter structure.
  2441. * @val: integer attribute value.
  2442. *
  2443. * Validates the min and max values then sets the adapter config field
  2444. * accordingly, or uses the default if out of range and prints an error message.
  2445. *
  2446. * Returns:
  2447. * zero on success
  2448. * -EINVAL if default used
  2449. **/
  2450. #define lpfc_param_init(attr, default, minval, maxval) \
  2451. static int \
  2452. lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
  2453. { \
  2454. if (lpfc_rangecheck(val, minval, maxval)) {\
  2455. phba->cfg_##attr = val;\
  2456. return 0;\
  2457. }\
  2458. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  2459. "0449 lpfc_"#attr" attribute cannot be set to %d, "\
  2460. "allowed range is ["#minval", "#maxval"]\n", val); \
  2461. phba->cfg_##attr = default;\
  2462. return -EINVAL;\
  2463. }
  2464. /*
  2465. * lpfc_param_set - Set a cfg attribute value
  2466. *
  2467. * Description:
  2468. * Macro that given an attr e.g. hba_queue_depth expands
  2469. * into a function with the name lpfc_hba_queue_depth_set
  2470. *
  2471. * lpfc_##attr##_set: Sets an attribute value.
  2472. * @phba: pointer to the adapter structure.
  2473. * @val: integer attribute value.
  2474. *
  2475. * Description:
  2476. * Validates the min and max values then sets the
  2477. * adapter config field if in the valid range. prints error message
  2478. * and does not set the parameter if invalid.
  2479. *
  2480. * Returns:
  2481. * zero on success
  2482. * -EINVAL if val is invalid
  2483. **/
  2484. #define lpfc_param_set(attr, default, minval, maxval) \
  2485. static int \
  2486. lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
  2487. { \
  2488. if (lpfc_rangecheck(val, minval, maxval)) {\
  2489. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  2490. "3052 lpfc_" #attr " changed from %d to %d\n", \
  2491. phba->cfg_##attr, val); \
  2492. phba->cfg_##attr = val;\
  2493. return 0;\
  2494. }\
  2495. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  2496. "0450 lpfc_"#attr" attribute cannot be set to %d, "\
  2497. "allowed range is ["#minval", "#maxval"]\n", val); \
  2498. return -EINVAL;\
  2499. }
  2500. /*
  2501. * lpfc_param_store - Set a vport attribute value
  2502. *
  2503. * Description:
  2504. * Macro that given an attr e.g. hba_queue_depth expands
  2505. * into a function with the name lpfc_hba_queue_depth_store.
  2506. *
  2507. * lpfc_##attr##_store: Set an sttribute value.
  2508. * @dev: class device that is converted into a Scsi_host.
  2509. * @attr: device attribute, not used.
  2510. * @buf: contains the attribute value in ascii.
  2511. * @count: not used.
  2512. *
  2513. * Description:
  2514. * Convert the ascii text number to an integer, then
  2515. * use the lpfc_##attr##_set function to set the value.
  2516. *
  2517. * Returns:
  2518. * -EINVAL if val is invalid or lpfc_##attr##_set() fails
  2519. * length of buffer upon success.
  2520. **/
  2521. #define lpfc_param_store(attr) \
  2522. static ssize_t \
  2523. lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
  2524. const char *buf, size_t count) \
  2525. { \
  2526. struct Scsi_Host *shost = class_to_shost(dev);\
  2527. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  2528. struct lpfc_hba *phba = vport->phba;\
  2529. uint val = 0;\
  2530. if (!isdigit(buf[0]))\
  2531. return -EINVAL;\
  2532. if (sscanf(buf, "%i", &val) != 1)\
  2533. return -EINVAL;\
  2534. if (lpfc_##attr##_set(phba, val) == 0) \
  2535. return strlen(buf);\
  2536. else \
  2537. return -EINVAL;\
  2538. }
  2539. /*
  2540. * lpfc_vport_param_show - Return decimal formatted cfg attribute value
  2541. *
  2542. * Description:
  2543. * Macro that given an attr e.g. hba_queue_depth expands
  2544. * into a function with the name lpfc_hba_queue_depth_show
  2545. *
  2546. * lpfc_##attr##_show: prints the attribute value in decimal.
  2547. * @dev: class device that is converted into a Scsi_host.
  2548. * @attr: device attribute, not used.
  2549. * @buf: on return contains the attribute value in decimal.
  2550. *
  2551. * Returns: length of formatted string.
  2552. **/
  2553. #define lpfc_vport_param_show(attr) \
  2554. static ssize_t \
  2555. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  2556. char *buf) \
  2557. { \
  2558. struct Scsi_Host *shost = class_to_shost(dev);\
  2559. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  2560. return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
  2561. }
  2562. /*
  2563. * lpfc_vport_param_hex_show - Return hex formatted attribute value
  2564. *
  2565. * Description:
  2566. * Macro that given an attr e.g.
  2567. * hba_queue_depth expands into a function with the name
  2568. * lpfc_hba_queue_depth_show
  2569. *
  2570. * lpfc_##attr##_show: prints the attribute value in hexadecimal.
  2571. * @dev: class device that is converted into a Scsi_host.
  2572. * @attr: device attribute, not used.
  2573. * @buf: on return contains the attribute value in hexadecimal.
  2574. *
  2575. * Returns: length of formatted string.
  2576. **/
  2577. #define lpfc_vport_param_hex_show(attr) \
  2578. static ssize_t \
  2579. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  2580. char *buf) \
  2581. { \
  2582. struct Scsi_Host *shost = class_to_shost(dev);\
  2583. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  2584. return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
  2585. }
  2586. /*
  2587. * lpfc_vport_param_init - Initialize a vport cfg attribute
  2588. *
  2589. * Description:
  2590. * Macro that given an attr e.g. hba_queue_depth expands
  2591. * into a function with the name lpfc_hba_queue_depth_init. The macro also
  2592. * takes a default argument, a minimum and maximum argument.
  2593. *
  2594. * lpfc_##attr##_init: validates the min and max values then sets the
  2595. * adapter config field accordingly, or uses the default if out of range
  2596. * and prints an error message.
  2597. * @phba: pointer to the adapter structure.
  2598. * @val: integer attribute value.
  2599. *
  2600. * Returns:
  2601. * zero on success
  2602. * -EINVAL if default used
  2603. **/
  2604. #define lpfc_vport_param_init(attr, default, minval, maxval) \
  2605. static int \
  2606. lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
  2607. { \
  2608. if (lpfc_rangecheck(val, minval, maxval)) {\
  2609. vport->cfg_##attr = val;\
  2610. return 0;\
  2611. }\
  2612. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
  2613. "0423 lpfc_"#attr" attribute cannot be set to %d, "\
  2614. "allowed range is ["#minval", "#maxval"]\n", val); \
  2615. vport->cfg_##attr = default;\
  2616. return -EINVAL;\
  2617. }
  2618. /*
  2619. * lpfc_vport_param_set - Set a vport cfg attribute
  2620. *
  2621. * Description:
  2622. * Macro that given an attr e.g. hba_queue_depth expands
  2623. * into a function with the name lpfc_hba_queue_depth_set
  2624. *
  2625. * lpfc_##attr##_set: validates the min and max values then sets the
  2626. * adapter config field if in the valid range. prints error message
  2627. * and does not set the parameter if invalid.
  2628. * @phba: pointer to the adapter structure.
  2629. * @val: integer attribute value.
  2630. *
  2631. * Returns:
  2632. * zero on success
  2633. * -EINVAL if val is invalid
  2634. **/
  2635. #define lpfc_vport_param_set(attr, default, minval, maxval) \
  2636. static int \
  2637. lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
  2638. { \
  2639. if (lpfc_rangecheck(val, minval, maxval)) {\
  2640. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
  2641. "3053 lpfc_" #attr \
  2642. " changed from %d (x%x) to %d (x%x)\n", \
  2643. vport->cfg_##attr, vport->cfg_##attr, \
  2644. val, val); \
  2645. vport->cfg_##attr = val;\
  2646. return 0;\
  2647. }\
  2648. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
  2649. "0424 lpfc_"#attr" attribute cannot be set to %d, "\
  2650. "allowed range is ["#minval", "#maxval"]\n", val); \
  2651. return -EINVAL;\
  2652. }
  2653. /*
  2654. * lpfc_vport_param_store - Set a vport attribute
  2655. *
  2656. * Description:
  2657. * Macro that given an attr e.g. hba_queue_depth
  2658. * expands into a function with the name lpfc_hba_queue_depth_store
  2659. *
  2660. * lpfc_##attr##_store: convert the ascii text number to an integer, then
  2661. * use the lpfc_##attr##_set function to set the value.
  2662. * @cdev: class device that is converted into a Scsi_host.
  2663. * @buf: contains the attribute value in decimal.
  2664. * @count: not used.
  2665. *
  2666. * Returns:
  2667. * -EINVAL if val is invalid or lpfc_##attr##_set() fails
  2668. * length of buffer upon success.
  2669. **/
  2670. #define lpfc_vport_param_store(attr) \
  2671. static ssize_t \
  2672. lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
  2673. const char *buf, size_t count) \
  2674. { \
  2675. struct Scsi_Host *shost = class_to_shost(dev);\
  2676. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  2677. uint val = 0;\
  2678. if (!isdigit(buf[0]))\
  2679. return -EINVAL;\
  2680. if (sscanf(buf, "%i", &val) != 1)\
  2681. return -EINVAL;\
  2682. if (lpfc_##attr##_set(vport, val) == 0) \
  2683. return strlen(buf);\
  2684. else \
  2685. return -EINVAL;\
  2686. }
  2687. static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
  2688. static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
  2689. static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
  2690. static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
  2691. static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
  2692. static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
  2693. static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
  2694. static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
  2695. static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
  2696. static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
  2697. static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
  2698. static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
  2699. static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
  2700. static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
  2701. static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
  2702. lpfc_link_state_store);
  2703. static DEVICE_ATTR(option_rom_version, S_IRUGO,
  2704. lpfc_option_rom_version_show, NULL);
  2705. static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
  2706. lpfc_num_discovered_ports_show, NULL);
  2707. static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
  2708. static DEVICE_ATTR_RO(lpfc_drvr_version);
  2709. static DEVICE_ATTR_RO(lpfc_enable_fip);
  2710. static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
  2711. lpfc_board_mode_show, lpfc_board_mode_store);
  2712. static DEVICE_ATTR_RO(lpfc_xcvr_data);
  2713. static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
  2714. static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
  2715. static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
  2716. static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
  2717. static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
  2718. static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
  2719. static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
  2720. static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
  2721. static DEVICE_ATTR_RO(lpfc_temp_sensor);
  2722. static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
  2723. static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
  2724. static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
  2725. NULL);
  2726. static DEVICE_ATTR(cmf_info, 0444, lpfc_cmf_info_show, NULL);
  2727. #define WWN_SZ 8
  2728. /**
  2729. * lpfc_wwn_set - Convert string to the 8 byte WWN value.
  2730. * @buf: WWN string.
  2731. * @cnt: Length of string.
  2732. * @wwn: Array to receive converted wwn value.
  2733. *
  2734. * Returns:
  2735. * -EINVAL if the buffer does not contain a valid wwn
  2736. * 0 success
  2737. **/
  2738. static size_t
  2739. lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
  2740. {
  2741. unsigned int i, j;
  2742. /* Count may include a LF at end of string */
  2743. if (buf[cnt-1] == '\n')
  2744. cnt--;
  2745. if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
  2746. ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
  2747. return -EINVAL;
  2748. memset(wwn, 0, WWN_SZ);
  2749. /* Validate and store the new name */
  2750. for (i = 0, j = 0; i < 16; i++) {
  2751. if ((*buf >= 'a') && (*buf <= 'f'))
  2752. j = ((j << 4) | ((*buf++ - 'a') + 10));
  2753. else if ((*buf >= 'A') && (*buf <= 'F'))
  2754. j = ((j << 4) | ((*buf++ - 'A') + 10));
  2755. else if ((*buf >= '0') && (*buf <= '9'))
  2756. j = ((j << 4) | (*buf++ - '0'));
  2757. else
  2758. return -EINVAL;
  2759. if (i % 2) {
  2760. wwn[i/2] = j & 0xff;
  2761. j = 0;
  2762. }
  2763. }
  2764. return 0;
  2765. }
  2766. /**
  2767. * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
  2768. * Optimized Access Storage (OAS) operations.
  2769. * @dev: class device that is converted into a Scsi_host.
  2770. * @attr: device attribute, not used.
  2771. * @buf: buffer for passing information.
  2772. *
  2773. * Returns:
  2774. * value of count
  2775. **/
  2776. static ssize_t
  2777. lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
  2778. char *buf)
  2779. {
  2780. struct Scsi_Host *shost = class_to_shost(dev);
  2781. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2782. return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
  2783. wwn_to_u64(phba->cfg_oas_tgt_wwpn));
  2784. }
  2785. /**
  2786. * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
  2787. * Optimized Access Storage (OAS) operations.
  2788. * @dev: class device that is converted into a Scsi_host.
  2789. * @attr: device attribute, not used.
  2790. * @buf: buffer for passing information.
  2791. * @count: Size of the data buffer.
  2792. *
  2793. * Returns:
  2794. * -EINVAL count is invalid, invalid wwpn byte invalid
  2795. * -EPERM oas is not supported by hba
  2796. * value of count on success
  2797. **/
  2798. static ssize_t
  2799. lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
  2800. const char *buf, size_t count)
  2801. {
  2802. struct Scsi_Host *shost = class_to_shost(dev);
  2803. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2804. unsigned int cnt = count;
  2805. uint8_t wwpn[WWN_SZ];
  2806. int rc;
  2807. if (!phba->cfg_fof)
  2808. return -EPERM;
  2809. /* count may include a LF at end of string */
  2810. if (buf[cnt-1] == '\n')
  2811. cnt--;
  2812. rc = lpfc_wwn_set(buf, cnt, wwpn);
  2813. if (rc)
  2814. return rc;
  2815. memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
  2816. memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
  2817. if (wwn_to_u64(wwpn) == 0)
  2818. phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
  2819. else
  2820. phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
  2821. phba->cfg_oas_flags &= ~OAS_LUN_VALID;
  2822. phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
  2823. return count;
  2824. }
  2825. static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
  2826. lpfc_oas_tgt_show, lpfc_oas_tgt_store);
  2827. /**
  2828. * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
  2829. * Optimized Access Storage (OAS) operations.
  2830. * @dev: class device that is converted into a Scsi_host.
  2831. * @attr: device attribute, not used.
  2832. * @buf: buffer for passing information.
  2833. *
  2834. * Returns:
  2835. * value of count
  2836. **/
  2837. static ssize_t
  2838. lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
  2839. char *buf)
  2840. {
  2841. struct Scsi_Host *shost = class_to_shost(dev);
  2842. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2843. return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
  2844. }
  2845. /**
  2846. * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
  2847. * Optimized Access Storage (OAS) operations.
  2848. * @dev: class device that is converted into a Scsi_host.
  2849. * @attr: device attribute, not used.
  2850. * @buf: buffer for passing information.
  2851. * @count: Size of the data buffer.
  2852. *
  2853. * Returns:
  2854. * -EINVAL count is invalid, invalid wwpn byte invalid
  2855. * -EPERM oas is not supported by hba
  2856. * value of count on success
  2857. **/
  2858. static ssize_t
  2859. lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
  2860. const char *buf, size_t count)
  2861. {
  2862. struct Scsi_Host *shost = class_to_shost(dev);
  2863. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2864. unsigned int cnt = count;
  2865. unsigned long val;
  2866. int ret;
  2867. if (!phba->cfg_fof)
  2868. return -EPERM;
  2869. /* count may include a LF at end of string */
  2870. if (buf[cnt-1] == '\n')
  2871. cnt--;
  2872. ret = kstrtoul(buf, 0, &val);
  2873. if (ret || (val > 0x7f))
  2874. return -EINVAL;
  2875. if (val)
  2876. phba->cfg_oas_priority = (uint8_t)val;
  2877. else
  2878. phba->cfg_oas_priority = phba->cfg_XLanePriority;
  2879. return count;
  2880. }
  2881. static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
  2882. lpfc_oas_priority_show, lpfc_oas_priority_store);
  2883. /**
  2884. * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
  2885. * for Optimized Access Storage (OAS) operations.
  2886. * @dev: class device that is converted into a Scsi_host.
  2887. * @attr: device attribute, not used.
  2888. * @buf: buffer for passing information.
  2889. *
  2890. * Returns:
  2891. * value of count on success
  2892. **/
  2893. static ssize_t
  2894. lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
  2895. char *buf)
  2896. {
  2897. struct Scsi_Host *shost = class_to_shost(dev);
  2898. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2899. return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
  2900. wwn_to_u64(phba->cfg_oas_vpt_wwpn));
  2901. }
  2902. /**
  2903. * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
  2904. * for Optimized Access Storage (OAS) operations.
  2905. * @dev: class device that is converted into a Scsi_host.
  2906. * @attr: device attribute, not used.
  2907. * @buf: buffer for passing information.
  2908. * @count: Size of the data buffer.
  2909. *
  2910. * Returns:
  2911. * -EINVAL count is invalid, invalid wwpn byte invalid
  2912. * -EPERM oas is not supported by hba
  2913. * value of count on success
  2914. **/
  2915. static ssize_t
  2916. lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
  2917. const char *buf, size_t count)
  2918. {
  2919. struct Scsi_Host *shost = class_to_shost(dev);
  2920. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2921. unsigned int cnt = count;
  2922. uint8_t wwpn[WWN_SZ];
  2923. int rc;
  2924. if (!phba->cfg_fof)
  2925. return -EPERM;
  2926. /* count may include a LF at end of string */
  2927. if (buf[cnt-1] == '\n')
  2928. cnt--;
  2929. rc = lpfc_wwn_set(buf, cnt, wwpn);
  2930. if (rc)
  2931. return rc;
  2932. memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
  2933. memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
  2934. if (wwn_to_u64(wwpn) == 0)
  2935. phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
  2936. else
  2937. phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
  2938. phba->cfg_oas_flags &= ~OAS_LUN_VALID;
  2939. if (phba->cfg_oas_priority == 0)
  2940. phba->cfg_oas_priority = phba->cfg_XLanePriority;
  2941. phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
  2942. return count;
  2943. }
  2944. static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
  2945. lpfc_oas_vpt_show, lpfc_oas_vpt_store);
  2946. /**
  2947. * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
  2948. * of whether luns will be enabled or disabled
  2949. * for Optimized Access Storage (OAS) operations.
  2950. * @dev: class device that is converted into a Scsi_host.
  2951. * @attr: device attribute, not used.
  2952. * @buf: buffer for passing information.
  2953. *
  2954. * Returns:
  2955. * size of formatted string.
  2956. **/
  2957. static ssize_t
  2958. lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
  2959. char *buf)
  2960. {
  2961. struct Scsi_Host *shost = class_to_shost(dev);
  2962. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2963. return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
  2964. }
  2965. /**
  2966. * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
  2967. * of whether luns will be enabled or disabled
  2968. * for Optimized Access Storage (OAS) operations.
  2969. * @dev: class device that is converted into a Scsi_host.
  2970. * @attr: device attribute, not used.
  2971. * @buf: buffer for passing information.
  2972. * @count: Size of the data buffer.
  2973. *
  2974. * Returns:
  2975. * -EINVAL count is invalid, invalid wwpn byte invalid
  2976. * -EPERM oas is not supported by hba
  2977. * value of count on success
  2978. **/
  2979. static ssize_t
  2980. lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
  2981. const char *buf, size_t count)
  2982. {
  2983. struct Scsi_Host *shost = class_to_shost(dev);
  2984. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2985. int val = 0;
  2986. if (!phba->cfg_fof)
  2987. return -EPERM;
  2988. if (!isdigit(buf[0]))
  2989. return -EINVAL;
  2990. if (sscanf(buf, "%i", &val) != 1)
  2991. return -EINVAL;
  2992. if ((val != 0) && (val != 1))
  2993. return -EINVAL;
  2994. phba->cfg_oas_lun_state = val;
  2995. return strlen(buf);
  2996. }
  2997. static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
  2998. lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
  2999. /**
  3000. * lpfc_oas_lun_status_show - Return the status of the Optimized Access
  3001. * Storage (OAS) lun returned by the
  3002. * lpfc_oas_lun_show function.
  3003. * @dev: class device that is converted into a Scsi_host.
  3004. * @attr: device attribute, not used.
  3005. * @buf: buffer for passing information.
  3006. *
  3007. * Returns:
  3008. * size of formatted string.
  3009. **/
  3010. static ssize_t
  3011. lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
  3012. char *buf)
  3013. {
  3014. struct Scsi_Host *shost = class_to_shost(dev);
  3015. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  3016. if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
  3017. return -EFAULT;
  3018. return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
  3019. }
  3020. static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
  3021. lpfc_oas_lun_status_show, NULL);
  3022. /**
  3023. * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
  3024. * (OAS) operations.
  3025. * @phba: lpfc_hba pointer.
  3026. * @vpt_wwpn: wwpn of the vport associated with the returned lun
  3027. * @tgt_wwpn: wwpn of the target associated with the returned lun
  3028. * @lun: the fc lun for setting oas state.
  3029. * @oas_state: the oas state to be set to the lun.
  3030. * @pri: priority
  3031. *
  3032. * Returns:
  3033. * SUCCESS : 0
  3034. * -EPERM OAS is not enabled or not supported by this port.
  3035. *
  3036. */
  3037. static size_t
  3038. lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
  3039. uint8_t tgt_wwpn[], uint64_t lun,
  3040. uint32_t oas_state, uint8_t pri)
  3041. {
  3042. int rc = 0;
  3043. if (!phba->cfg_fof)
  3044. return -EPERM;
  3045. if (oas_state) {
  3046. if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
  3047. (struct lpfc_name *)tgt_wwpn,
  3048. lun, pri))
  3049. rc = -ENOMEM;
  3050. } else {
  3051. lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
  3052. (struct lpfc_name *)tgt_wwpn, lun, pri);
  3053. }
  3054. return rc;
  3055. }
  3056. /**
  3057. * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
  3058. * Access Storage (OAS) operations.
  3059. * @phba: lpfc_hba pointer.
  3060. * @vpt_wwpn: wwpn of the vport associated with the returned lun
  3061. * @tgt_wwpn: wwpn of the target associated with the returned lun
  3062. * @lun_status: status of the lun returned lun
  3063. * @lun_pri: priority of the lun returned lun
  3064. *
  3065. * Returns the first or next lun enabled for OAS operations for the vport/target
  3066. * specified. If a lun is found, its vport wwpn, target wwpn and status is
  3067. * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
  3068. *
  3069. * Return:
  3070. * lun that is OAS enabled for the vport/target
  3071. * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
  3072. */
  3073. static uint64_t
  3074. lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
  3075. uint8_t tgt_wwpn[], uint32_t *lun_status,
  3076. uint32_t *lun_pri)
  3077. {
  3078. uint64_t found_lun;
  3079. if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
  3080. return NOT_OAS_ENABLED_LUN;
  3081. if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
  3082. phba->sli4_hba.oas_next_vpt_wwpn,
  3083. (struct lpfc_name *)
  3084. phba->sli4_hba.oas_next_tgt_wwpn,
  3085. &phba->sli4_hba.oas_next_lun,
  3086. (struct lpfc_name *)vpt_wwpn,
  3087. (struct lpfc_name *)tgt_wwpn,
  3088. &found_lun, lun_status, lun_pri))
  3089. return found_lun;
  3090. else
  3091. return NOT_OAS_ENABLED_LUN;
  3092. }
  3093. /**
  3094. * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
  3095. * @phba: lpfc_hba pointer.
  3096. * @vpt_wwpn: vport wwpn by reference.
  3097. * @tgt_wwpn: target wwpn by reference.
  3098. * @lun: the fc lun for setting oas state.
  3099. * @oas_state: the oas state to be set to the oas_lun.
  3100. * @pri: priority
  3101. *
  3102. * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
  3103. * a lun for OAS operations.
  3104. *
  3105. * Return:
  3106. * SUCCESS: 0
  3107. * -ENOMEM: failed to enable an lun for OAS operations
  3108. * -EPERM: OAS is not enabled
  3109. */
  3110. static ssize_t
  3111. lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
  3112. uint8_t tgt_wwpn[], uint64_t lun,
  3113. uint32_t oas_state, uint8_t pri)
  3114. {
  3115. int rc;
  3116. rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
  3117. oas_state, pri);
  3118. return rc;
  3119. }
  3120. /**
  3121. * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
  3122. * @dev: class device that is converted into a Scsi_host.
  3123. * @attr: device attribute, not used.
  3124. * @buf: buffer for passing information.
  3125. *
  3126. * This routine returns a lun enabled for OAS each time the function
  3127. * is called.
  3128. *
  3129. * Returns:
  3130. * SUCCESS: size of formatted string.
  3131. * -EFAULT: target or vport wwpn was not set properly.
  3132. * -EPERM: oas is not enabled.
  3133. **/
  3134. static ssize_t
  3135. lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
  3136. char *buf)
  3137. {
  3138. struct Scsi_Host *shost = class_to_shost(dev);
  3139. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  3140. uint64_t oas_lun;
  3141. int len = 0;
  3142. if (!phba->cfg_fof)
  3143. return -EPERM;
  3144. if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
  3145. if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
  3146. return -EFAULT;
  3147. if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
  3148. if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
  3149. return -EFAULT;
  3150. oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
  3151. phba->cfg_oas_tgt_wwpn,
  3152. &phba->cfg_oas_lun_status,
  3153. &phba->cfg_oas_priority);
  3154. if (oas_lun != NOT_OAS_ENABLED_LUN)
  3155. phba->cfg_oas_flags |= OAS_LUN_VALID;
  3156. len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
  3157. return len;
  3158. }
  3159. /**
  3160. * lpfc_oas_lun_store - Sets the OAS state for lun
  3161. * @dev: class device that is converted into a Scsi_host.
  3162. * @attr: device attribute, not used.
  3163. * @buf: buffer for passing information.
  3164. * @count: size of the formatting string
  3165. *
  3166. * This function sets the OAS state for lun. Before this function is called,
  3167. * the vport wwpn, target wwpn, and oas state need to be set.
  3168. *
  3169. * Returns:
  3170. * SUCCESS: size of formatted string.
  3171. * -EFAULT: target or vport wwpn was not set properly.
  3172. * -EPERM: oas is not enabled.
  3173. * size of formatted string.
  3174. **/
  3175. static ssize_t
  3176. lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
  3177. const char *buf, size_t count)
  3178. {
  3179. struct Scsi_Host *shost = class_to_shost(dev);
  3180. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  3181. uint64_t scsi_lun;
  3182. uint32_t pri;
  3183. ssize_t rc;
  3184. if (!phba->cfg_fof)
  3185. return -EPERM;
  3186. if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
  3187. return -EFAULT;
  3188. if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
  3189. return -EFAULT;
  3190. if (!isdigit(buf[0]))
  3191. return -EINVAL;
  3192. if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
  3193. return -EINVAL;
  3194. pri = phba->cfg_oas_priority;
  3195. if (pri == 0)
  3196. pri = phba->cfg_XLanePriority;
  3197. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3198. "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
  3199. "priority 0x%x with oas state %d\n",
  3200. wwn_to_u64(phba->cfg_oas_vpt_wwpn),
  3201. wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
  3202. pri, phba->cfg_oas_lun_state);
  3203. rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
  3204. phba->cfg_oas_tgt_wwpn, scsi_lun,
  3205. phba->cfg_oas_lun_state, pri);
  3206. if (rc)
  3207. return rc;
  3208. return count;
  3209. }
  3210. static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
  3211. lpfc_oas_lun_show, lpfc_oas_lun_store);
  3212. int lpfc_enable_nvmet_cnt;
  3213. unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
  3214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  3215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  3216. module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
  3217. MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
  3218. static int lpfc_poll = 0;
  3219. module_param(lpfc_poll, int, S_IRUGO);
  3220. MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
  3221. " 0 - none,"
  3222. " 1 - poll with interrupts enabled"
  3223. " 3 - poll and disable FCP ring interrupts");
  3224. static DEVICE_ATTR_RW(lpfc_poll);
  3225. int lpfc_no_hba_reset_cnt;
  3226. unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
  3227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  3228. module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
  3229. MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
  3230. LPFC_ATTR(sli_mode, 3, 3, 3,
  3231. "SLI mode selector: 3 - select SLI-3");
  3232. LPFC_ATTR_R(enable_npiv, 1, 0, 1,
  3233. "Enable NPIV functionality");
  3234. LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
  3235. "FCF Fast failover=1 Priority failover=2");
  3236. /*
  3237. * lpfc_fcp_wait_abts_rsp: Modifies criteria for reporting completion of
  3238. * aborted IO.
  3239. * The range is [0,1]. Default value is 0
  3240. * 0, IO completes after ABTS issued (default).
  3241. * 1, IO completes after receipt of ABTS response or timeout.
  3242. */
  3243. LPFC_ATTR_R(fcp_wait_abts_rsp, 0, 0, 1, "Wait for FCP ABTS completion");
  3244. /*
  3245. # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
  3246. # 0x0 = disabled, XRI/OXID use not tracked.
  3247. # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
  3248. # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
  3249. */
  3250. LPFC_ATTR_R(enable_rrq, 2, 0, 2,
  3251. "Enable RRQ functionality");
  3252. /*
  3253. # lpfc_suppress_link_up: Bring link up at initialization
  3254. # 0x0 = bring link up (issue MBX_INIT_LINK)
  3255. # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
  3256. # 0x2 = never bring up link
  3257. # Default value is 0.
  3258. */
  3259. LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
  3260. LPFC_DELAY_INIT_LINK_INDEFINITELY,
  3261. "Suppress Link Up at initialization");
  3262. static ssize_t
  3263. lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)
  3264. {
  3265. struct Scsi_Host *shost = class_to_shost(dev);
  3266. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  3267. return scnprintf(buf, PAGE_SIZE, "%d\n",
  3268. phba->sli4_hba.pc_sli4_params.pls);
  3269. }
  3270. static DEVICE_ATTR(pls, 0444,
  3271. lpfc_pls_show, NULL);
  3272. static ssize_t
  3273. lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)
  3274. {
  3275. struct Scsi_Host *shost = class_to_shost(dev);
  3276. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  3277. return scnprintf(buf, PAGE_SIZE, "%d\n",
  3278. test_bit(HBA_PERSISTENT_TOPO,
  3279. &phba->hba_flag) ? 1 : 0);
  3280. }
  3281. static DEVICE_ATTR(pt, 0444,
  3282. lpfc_pt_show, NULL);
  3283. /*
  3284. # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
  3285. # 1 - (1024)
  3286. # 2 - (2048)
  3287. # 3 - (3072)
  3288. # 4 - (4096)
  3289. # 5 - (5120)
  3290. */
  3291. static ssize_t
  3292. lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
  3293. {
  3294. struct Scsi_Host *shost = class_to_shost(dev);
  3295. struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
  3296. return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
  3297. }
  3298. static DEVICE_ATTR(iocb_hw, S_IRUGO,
  3299. lpfc_iocb_hw_show, NULL);
  3300. static ssize_t
  3301. lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
  3302. {
  3303. struct Scsi_Host *shost = class_to_shost(dev);
  3304. struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
  3305. struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
  3306. return scnprintf(buf, PAGE_SIZE, "%d\n",
  3307. pring ? pring->txq_max : 0);
  3308. }
  3309. static DEVICE_ATTR(txq_hw, S_IRUGO,
  3310. lpfc_txq_hw_show, NULL);
  3311. static ssize_t
  3312. lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
  3313. char *buf)
  3314. {
  3315. struct Scsi_Host *shost = class_to_shost(dev);
  3316. struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
  3317. struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
  3318. return scnprintf(buf, PAGE_SIZE, "%d\n",
  3319. pring ? pring->txcmplq_max : 0);
  3320. }
  3321. static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
  3322. lpfc_txcmplq_hw_show, NULL);
  3323. /*
  3324. # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
  3325. # until the timer expires. Value range is [0,255]. Default value is 30.
  3326. */
  3327. static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
  3328. static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
  3329. module_param(lpfc_nodev_tmo, int, 0);
  3330. MODULE_PARM_DESC(lpfc_nodev_tmo,
  3331. "Seconds driver will hold I/O waiting "
  3332. "for a device to come back");
  3333. /**
  3334. * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
  3335. * @dev: class converted to a Scsi_host structure.
  3336. * @attr: device attribute, not used.
  3337. * @buf: on return contains the dev loss timeout in decimal.
  3338. *
  3339. * Returns: size of formatted string.
  3340. **/
  3341. static ssize_t
  3342. lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
  3343. char *buf)
  3344. {
  3345. struct Scsi_Host *shost = class_to_shost(dev);
  3346. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3347. return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
  3348. }
  3349. /**
  3350. * lpfc_nodev_tmo_init - Set the hba nodev timeout value
  3351. * @vport: lpfc vport structure pointer.
  3352. * @val: contains the nodev timeout value.
  3353. *
  3354. * Description:
  3355. * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
  3356. * a kernel error message is printed and zero is returned.
  3357. * Else if val is in range then nodev tmo and devloss tmo are set to val.
  3358. * Otherwise nodev tmo is set to the default value.
  3359. *
  3360. * Returns:
  3361. * zero if already set or if val is in range
  3362. * -EINVAL val out of range
  3363. **/
  3364. static int
  3365. lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
  3366. {
  3367. if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
  3368. vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
  3369. if (val != LPFC_DEF_DEVLOSS_TMO)
  3370. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3371. "0407 Ignoring lpfc_nodev_tmo module "
  3372. "parameter because lpfc_devloss_tmo "
  3373. "is set.\n");
  3374. return 0;
  3375. }
  3376. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  3377. vport->cfg_nodev_tmo = val;
  3378. vport->cfg_devloss_tmo = val;
  3379. return 0;
  3380. }
  3381. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3382. "0400 lpfc_nodev_tmo attribute cannot be set to"
  3383. " %d, allowed range is [%d, %d]\n",
  3384. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  3385. vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
  3386. return -EINVAL;
  3387. }
  3388. /**
  3389. * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
  3390. * @vport: lpfc vport structure pointer.
  3391. *
  3392. * Description:
  3393. * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
  3394. **/
  3395. static void
  3396. lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
  3397. {
  3398. struct lpfc_nodelist *ndlp;
  3399. unsigned long iflags;
  3400. #if (IS_ENABLED(CONFIG_NVME_FC))
  3401. struct lpfc_nvme_rport *rport;
  3402. struct nvme_fc_remote_port *remoteport = NULL;
  3403. #endif
  3404. spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
  3405. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3406. if (ndlp->rport)
  3407. ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
  3408. #if (IS_ENABLED(CONFIG_NVME_FC))
  3409. spin_lock(&ndlp->lock);
  3410. rport = lpfc_ndlp_get_nrport(ndlp);
  3411. if (rport)
  3412. remoteport = rport->remoteport;
  3413. spin_unlock(&ndlp->lock);
  3414. if (rport && remoteport)
  3415. nvme_fc_set_remoteport_devloss(remoteport,
  3416. vport->cfg_devloss_tmo);
  3417. #endif
  3418. }
  3419. spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
  3420. }
  3421. /**
  3422. * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
  3423. * @vport: lpfc vport structure pointer.
  3424. * @val: contains the tmo value.
  3425. *
  3426. * Description:
  3427. * If the devloss tmo is already set or the vport dev loss tmo has changed
  3428. * then a kernel error message is printed and zero is returned.
  3429. * Else if val is in range then nodev tmo and devloss tmo are set to val.
  3430. * Otherwise nodev tmo is set to the default value.
  3431. *
  3432. * Returns:
  3433. * zero if already set or if val is in range
  3434. * -EINVAL val out of range
  3435. **/
  3436. static int
  3437. lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
  3438. {
  3439. if (vport->dev_loss_tmo_changed ||
  3440. (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
  3441. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3442. "0401 Ignoring change to lpfc_nodev_tmo "
  3443. "because lpfc_devloss_tmo is set.\n");
  3444. return 0;
  3445. }
  3446. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  3447. vport->cfg_nodev_tmo = val;
  3448. vport->cfg_devloss_tmo = val;
  3449. /*
  3450. * For compat: set the fc_host dev loss so new rports
  3451. * will get the value.
  3452. */
  3453. fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
  3454. lpfc_update_rport_devloss_tmo(vport);
  3455. return 0;
  3456. }
  3457. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3458. "0403 lpfc_nodev_tmo attribute cannot be set to "
  3459. "%d, allowed range is [%d, %d]\n",
  3460. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  3461. return -EINVAL;
  3462. }
  3463. lpfc_vport_param_store(nodev_tmo)
  3464. static DEVICE_ATTR_RW(lpfc_nodev_tmo);
  3465. /*
  3466. # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
  3467. # disappear until the timer expires. Value range is [0,255]. Default
  3468. # value is 30.
  3469. */
  3470. module_param(lpfc_devloss_tmo, int, S_IRUGO);
  3471. MODULE_PARM_DESC(lpfc_devloss_tmo,
  3472. "Seconds driver will hold I/O waiting "
  3473. "for a device to come back");
  3474. lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
  3475. LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
  3476. lpfc_vport_param_show(devloss_tmo)
  3477. /**
  3478. * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
  3479. * @vport: lpfc vport structure pointer.
  3480. * @val: contains the tmo value.
  3481. *
  3482. * Description:
  3483. * If val is in a valid range then set the vport nodev tmo,
  3484. * devloss tmo, also set the vport dev loss tmo changed flag.
  3485. * Else a kernel error message is printed.
  3486. *
  3487. * Returns:
  3488. * zero if val is in range
  3489. * -EINVAL val out of range
  3490. **/
  3491. static int
  3492. lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
  3493. {
  3494. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  3495. vport->cfg_nodev_tmo = val;
  3496. vport->cfg_devloss_tmo = val;
  3497. vport->dev_loss_tmo_changed = 1;
  3498. fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
  3499. lpfc_update_rport_devloss_tmo(vport);
  3500. return 0;
  3501. }
  3502. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3503. "0404 lpfc_devloss_tmo attribute cannot be set to "
  3504. "%d, allowed range is [%d, %d]\n",
  3505. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  3506. return -EINVAL;
  3507. }
  3508. lpfc_vport_param_store(devloss_tmo)
  3509. static DEVICE_ATTR_RW(lpfc_devloss_tmo);
  3510. /*
  3511. * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
  3512. * lpfc_suppress_rsp = 0 Disable
  3513. * lpfc_suppress_rsp = 1 Enable (default)
  3514. *
  3515. */
  3516. LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
  3517. "Enable suppress rsp feature is firmware supports it");
  3518. /*
  3519. * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
  3520. * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
  3521. * lpfc_nvmet_mrq = 1 use a single RQ pair
  3522. * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
  3523. *
  3524. */
  3525. LPFC_ATTR_R(nvmet_mrq,
  3526. LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
  3527. "Specify number of RQ pairs for processing NVMET cmds");
  3528. /*
  3529. * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
  3530. * to each NVMET RQ. Range 64 to 2048, default is 512.
  3531. */
  3532. LPFC_ATTR_R(nvmet_mrq_post,
  3533. LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
  3534. LPFC_NVMET_RQE_DEF_COUNT,
  3535. "Specify number of RQ buffers to initially post");
  3536. /*
  3537. * lpfc_enable_fc4_type: Defines what FC4 types are supported.
  3538. * Supported Values: 1 - register just FCP
  3539. * 3 - register both FCP and NVME
  3540. * Supported values are [1,3]. Default value is 3
  3541. */
  3542. LPFC_ATTR_R(enable_fc4_type, LPFC_DEF_ENBL_FC4_TYPE,
  3543. LPFC_ENABLE_FCP, LPFC_MAX_ENBL_FC4_TYPE,
  3544. "Enable FC4 Protocol support - FCP / NVME");
  3545. /*
  3546. # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
  3547. # deluged with LOTS of information.
  3548. # You can set a bit mask to record specific types of verbose messages:
  3549. # See lpfc_logmsh.h for definitions.
  3550. */
  3551. LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
  3552. "Verbose logging bit-mask");
  3553. /*
  3554. # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
  3555. # objects that have been registered with the nameserver after login.
  3556. */
  3557. LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
  3558. "Deregister nameserver objects before LOGO");
  3559. /*
  3560. # lun_queue_depth: This parameter is used to limit the number of outstanding
  3561. # commands per FCP LUN.
  3562. */
  3563. LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,
  3564. "Max number of FCP commands we can queue to a specific LUN");
  3565. /*
  3566. # tgt_queue_depth: This parameter is used to limit the number of outstanding
  3567. # commands per target port. Value range is [10,65535]. Default value is 65535.
  3568. */
  3569. static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
  3570. module_param(lpfc_tgt_queue_depth, uint, 0444);
  3571. MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
  3572. lpfc_vport_param_show(tgt_queue_depth);
  3573. lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
  3574. LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
  3575. /**
  3576. * lpfc_tgt_queue_depth_set: Sets an attribute value.
  3577. * @vport: lpfc vport structure pointer.
  3578. * @val: integer attribute value.
  3579. *
  3580. * Description: Sets the parameter to the new value.
  3581. *
  3582. * Returns:
  3583. * zero on success
  3584. * -EINVAL if val is invalid
  3585. */
  3586. static int
  3587. lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
  3588. {
  3589. struct lpfc_nodelist *ndlp;
  3590. unsigned long iflags;
  3591. if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
  3592. return -EINVAL;
  3593. if (val == vport->cfg_tgt_queue_depth)
  3594. return 0;
  3595. vport->cfg_tgt_queue_depth = val;
  3596. /* Next loop thru nodelist and change cmd_qdepth */
  3597. spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
  3598. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
  3599. ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
  3600. spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
  3601. return 0;
  3602. }
  3603. lpfc_vport_param_store(tgt_queue_depth);
  3604. static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
  3605. /*
  3606. # hba_queue_depth: This parameter is used to limit the number of outstanding
  3607. # commands per lpfc HBA. Value range is [32,8192]. If this parameter
  3608. # value is greater than the maximum number of exchanges supported by the HBA,
  3609. # then maximum number of exchanges supported by the HBA is used to determine
  3610. # the hba_queue_depth.
  3611. */
  3612. LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
  3613. "Max number of FCP commands we can queue to a lpfc HBA");
  3614. /*
  3615. # peer_port_login: This parameter allows/prevents logins
  3616. # between peer ports hosted on the same physical port.
  3617. # When this parameter is set 0 peer ports of same physical port
  3618. # are not allowed to login to each other.
  3619. # When this parameter is set 1 peer ports of same physical port
  3620. # are allowed to login to each other.
  3621. # Default value of this parameter is 0.
  3622. */
  3623. LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
  3624. "Allow peer ports on the same physical port to login to each "
  3625. "other.");
  3626. /*
  3627. # restrict_login: This parameter allows/prevents logins
  3628. # between Virtual Ports and remote initiators.
  3629. # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
  3630. # other initiators and will attempt to PLOGI all remote ports.
  3631. # When this parameter is set (1) Virtual Ports will reject PLOGIs from
  3632. # remote ports and will not attempt to PLOGI to other initiators.
  3633. # This parameter does not restrict to the physical port.
  3634. # This parameter does not restrict logins to Fabric resident remote ports.
  3635. # Default value of this parameter is 1.
  3636. */
  3637. static int lpfc_restrict_login = 1;
  3638. module_param(lpfc_restrict_login, int, S_IRUGO);
  3639. MODULE_PARM_DESC(lpfc_restrict_login,
  3640. "Restrict virtual ports login to remote initiators.");
  3641. lpfc_vport_param_show(restrict_login);
  3642. /**
  3643. * lpfc_restrict_login_init - Set the vport restrict login flag
  3644. * @vport: lpfc vport structure pointer.
  3645. * @val: contains the restrict login value.
  3646. *
  3647. * Description:
  3648. * If val is not in a valid range then log a kernel error message and set
  3649. * the vport restrict login to one.
  3650. * If the port type is physical clear the restrict login flag and return.
  3651. * Else set the restrict login flag to val.
  3652. *
  3653. * Returns:
  3654. * zero if val is in range
  3655. * -EINVAL val out of range
  3656. **/
  3657. static int
  3658. lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
  3659. {
  3660. if (val < 0 || val > 1) {
  3661. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3662. "0422 lpfc_restrict_login attribute cannot "
  3663. "be set to %d, allowed range is [0, 1]\n",
  3664. val);
  3665. vport->cfg_restrict_login = 1;
  3666. return -EINVAL;
  3667. }
  3668. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  3669. vport->cfg_restrict_login = 0;
  3670. return 0;
  3671. }
  3672. vport->cfg_restrict_login = val;
  3673. return 0;
  3674. }
  3675. /**
  3676. * lpfc_restrict_login_set - Set the vport restrict login flag
  3677. * @vport: lpfc vport structure pointer.
  3678. * @val: contains the restrict login value.
  3679. *
  3680. * Description:
  3681. * If val is not in a valid range then log a kernel error message and set
  3682. * the vport restrict login to one.
  3683. * If the port type is physical and the val is not zero log a kernel
  3684. * error message, clear the restrict login flag and return zero.
  3685. * Else set the restrict login flag to val.
  3686. *
  3687. * Returns:
  3688. * zero if val is in range
  3689. * -EINVAL val out of range
  3690. **/
  3691. static int
  3692. lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
  3693. {
  3694. if (val < 0 || val > 1) {
  3695. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3696. "0425 lpfc_restrict_login attribute cannot "
  3697. "be set to %d, allowed range is [0, 1]\n",
  3698. val);
  3699. vport->cfg_restrict_login = 1;
  3700. return -EINVAL;
  3701. }
  3702. if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
  3703. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3704. "0468 lpfc_restrict_login must be 0 for "
  3705. "Physical ports.\n");
  3706. vport->cfg_restrict_login = 0;
  3707. return 0;
  3708. }
  3709. vport->cfg_restrict_login = val;
  3710. return 0;
  3711. }
  3712. lpfc_vport_param_store(restrict_login);
  3713. static DEVICE_ATTR_RW(lpfc_restrict_login);
  3714. /*
  3715. # Some disk devices have a "select ID" or "select Target" capability.
  3716. # From a protocol standpoint "select ID" usually means select the
  3717. # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
  3718. # annex" which contains a table that maps a "select ID" (a number
  3719. # between 0 and 7F) to an ALPA. By default, for compatibility with
  3720. # older drivers, the lpfc driver scans this table from low ALPA to high
  3721. # ALPA.
  3722. #
  3723. # Turning on the scan-down variable (on = 1, off = 0) will
  3724. # cause the lpfc driver to use an inverted table, effectively
  3725. # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
  3726. #
  3727. # (Note: This "select ID" functionality is a LOOP ONLY characteristic
  3728. # and will not work across a fabric. Also this parameter will take
  3729. # effect only in the case when ALPA map is not available.)
  3730. */
  3731. LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
  3732. "Start scanning for devices from highest ALPA to lowest");
  3733. /*
  3734. # lpfc_topology: link topology for init link
  3735. # 0x0 = attempt loop mode then point-to-point
  3736. # 0x01 = internal loopback mode
  3737. # 0x02 = attempt point-to-point mode only
  3738. # 0x04 = attempt loop mode only
  3739. # 0x06 = attempt point-to-point mode then loop
  3740. # Set point-to-point mode if you want to run as an N_Port.
  3741. # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
  3742. # Default value is 0.
  3743. */
  3744. LPFC_ATTR(topology, 0, 0, 6,
  3745. "Select Fibre Channel topology");
  3746. /**
  3747. * lpfc_topology_store - Set the adapters topology field
  3748. * @dev: class device that is converted into a scsi_host.
  3749. * @attr:device attribute, not used.
  3750. * @buf: buffer for passing information.
  3751. * @count: size of the data buffer.
  3752. *
  3753. * Description:
  3754. * If val is in a valid range then set the adapter's topology field and
  3755. * issue a lip; if the lip fails reset the topology to the old value.
  3756. *
  3757. * If the value is not in range log a kernel error message and return an error.
  3758. *
  3759. * Returns:
  3760. * zero if val is in range and lip okay
  3761. * non-zero return value from lpfc_issue_lip()
  3762. * -EINVAL val out of range
  3763. **/
  3764. static ssize_t
  3765. lpfc_topology_store(struct device *dev, struct device_attribute *attr,
  3766. const char *buf, size_t count)
  3767. {
  3768. struct Scsi_Host *shost = class_to_shost(dev);
  3769. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3770. struct lpfc_hba *phba = vport->phba;
  3771. int val = 0;
  3772. int nolip = 0;
  3773. const char *val_buf = buf;
  3774. int err;
  3775. uint32_t prev_val;
  3776. u8 sli_family, if_type;
  3777. if (!strncmp(buf, "nolip ", strlen("nolip "))) {
  3778. nolip = 1;
  3779. val_buf = &buf[strlen("nolip ")];
  3780. }
  3781. if (!isdigit(val_buf[0]))
  3782. return -EINVAL;
  3783. if (sscanf(val_buf, "%i", &val) != 1)
  3784. return -EINVAL;
  3785. if (val >= 0 && val <= 6) {
  3786. prev_val = phba->cfg_topology;
  3787. if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
  3788. val == 4) {
  3789. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3790. "3113 Loop mode not supported at speed %d\n",
  3791. val);
  3792. return -EINVAL;
  3793. }
  3794. /*
  3795. * The 'topology' is not a configurable parameter if :
  3796. * - persistent topology enabled
  3797. * - ASIC_GEN_NUM >= 0xC, with no private loop support
  3798. */
  3799. sli_family = bf_get(lpfc_sli_intf_sli_family,
  3800. &phba->sli4_hba.sli_intf);
  3801. if_type = bf_get(lpfc_sli_intf_if_type,
  3802. &phba->sli4_hba.sli_intf);
  3803. if ((test_bit(HBA_PERSISTENT_TOPO, &phba->hba_flag) ||
  3804. (!phba->sli4_hba.pc_sli4_params.pls &&
  3805. (sli_family == LPFC_SLI_INTF_FAMILY_G6 ||
  3806. if_type == LPFC_SLI_INTF_IF_TYPE_6))) &&
  3807. val == 4) {
  3808. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3809. "3114 Loop mode not supported\n");
  3810. return -EINVAL;
  3811. }
  3812. phba->cfg_topology = val;
  3813. if (nolip)
  3814. return strlen(buf);
  3815. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3816. "3054 lpfc_topology changed from %d to %d\n",
  3817. prev_val, val);
  3818. if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
  3819. phba->fc_topology_changed = 1;
  3820. err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
  3821. if (err) {
  3822. phba->cfg_topology = prev_val;
  3823. return -EINVAL;
  3824. } else
  3825. return strlen(buf);
  3826. }
  3827. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3828. "%d:0467 lpfc_topology attribute cannot be set to %d, "
  3829. "allowed range is [0, 6]\n",
  3830. phba->brd_no, val);
  3831. return -EINVAL;
  3832. }
  3833. lpfc_param_show(topology)
  3834. static DEVICE_ATTR_RW(lpfc_topology);
  3835. /**
  3836. * lpfc_static_vport_show: Read callback function for
  3837. * lpfc_static_vport sysfs file.
  3838. * @dev: Pointer to class device object.
  3839. * @attr: device attribute structure.
  3840. * @buf: Data buffer.
  3841. *
  3842. * This function is the read call back function for
  3843. * lpfc_static_vport sysfs file. The lpfc_static_vport
  3844. * sysfs file report the mageability of the vport.
  3845. **/
  3846. static ssize_t
  3847. lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
  3848. char *buf)
  3849. {
  3850. struct Scsi_Host *shost = class_to_shost(dev);
  3851. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3852. if (vport->vport_flag & STATIC_VPORT)
  3853. sprintf(buf, "1\n");
  3854. else
  3855. sprintf(buf, "0\n");
  3856. return strlen(buf);
  3857. }
  3858. /*
  3859. * Sysfs attribute to control the statistical data collection.
  3860. */
  3861. static DEVICE_ATTR_RO(lpfc_static_vport);
  3862. /*
  3863. # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
  3864. # connection.
  3865. # Value range is [0,16]. Default value is 0.
  3866. */
  3867. /**
  3868. * lpfc_link_speed_store - Set the adapters link speed
  3869. * @dev: Pointer to class device.
  3870. * @attr: Unused.
  3871. * @buf: Data buffer.
  3872. * @count: Size of the data buffer.
  3873. *
  3874. * Description:
  3875. * If val is in a valid range then set the adapter's link speed field and
  3876. * issue a lip; if the lip fails reset the link speed to the old value.
  3877. *
  3878. * Notes:
  3879. * If the value is not in range log a kernel error message and return an error.
  3880. *
  3881. * Returns:
  3882. * zero if val is in range and lip okay.
  3883. * non-zero return value from lpfc_issue_lip()
  3884. * -EINVAL val out of range
  3885. **/
  3886. static ssize_t
  3887. lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
  3888. const char *buf, size_t count)
  3889. {
  3890. struct Scsi_Host *shost = class_to_shost(dev);
  3891. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3892. struct lpfc_hba *phba = vport->phba;
  3893. int val = LPFC_USER_LINK_SPEED_AUTO;
  3894. int nolip = 0;
  3895. const char *val_buf = buf;
  3896. int err;
  3897. uint32_t prev_val, if_type;
  3898. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  3899. if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
  3900. test_bit(HBA_FORCED_LINK_SPEED, &phba->hba_flag))
  3901. return -EPERM;
  3902. if (!strncmp(buf, "nolip ", strlen("nolip "))) {
  3903. nolip = 1;
  3904. val_buf = &buf[strlen("nolip ")];
  3905. }
  3906. if (!isdigit(val_buf[0]))
  3907. return -EINVAL;
  3908. if (sscanf(val_buf, "%i", &val) != 1)
  3909. return -EINVAL;
  3910. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3911. "3055 lpfc_link_speed changed from %d to %d %s\n",
  3912. phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
  3913. if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
  3914. ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
  3915. ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
  3916. ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
  3917. ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
  3918. ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
  3919. ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
  3920. ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
  3921. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3922. "2879 lpfc_link_speed attribute cannot be set "
  3923. "to %d. Speed is not supported by this port.\n",
  3924. val);
  3925. return -EINVAL;
  3926. }
  3927. if (val >= LPFC_USER_LINK_SPEED_16G &&
  3928. phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  3929. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3930. "3112 lpfc_link_speed attribute cannot be set "
  3931. "to %d. Speed is not supported in loop mode.\n",
  3932. val);
  3933. return -EINVAL;
  3934. }
  3935. switch (val) {
  3936. case LPFC_USER_LINK_SPEED_AUTO:
  3937. case LPFC_USER_LINK_SPEED_1G:
  3938. case LPFC_USER_LINK_SPEED_2G:
  3939. case LPFC_USER_LINK_SPEED_4G:
  3940. case LPFC_USER_LINK_SPEED_8G:
  3941. case LPFC_USER_LINK_SPEED_16G:
  3942. case LPFC_USER_LINK_SPEED_32G:
  3943. case LPFC_USER_LINK_SPEED_64G:
  3944. prev_val = phba->cfg_link_speed;
  3945. phba->cfg_link_speed = val;
  3946. if (nolip)
  3947. return strlen(buf);
  3948. err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
  3949. if (err) {
  3950. phba->cfg_link_speed = prev_val;
  3951. return -EINVAL;
  3952. }
  3953. return strlen(buf);
  3954. default:
  3955. break;
  3956. }
  3957. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3958. "0469 lpfc_link_speed attribute cannot be set to %d, "
  3959. "allowed values are [%s]\n",
  3960. val, LPFC_LINK_SPEED_STRING);
  3961. return -EINVAL;
  3962. }
  3963. static int lpfc_link_speed = 0;
  3964. module_param(lpfc_link_speed, int, S_IRUGO);
  3965. MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
  3966. lpfc_param_show(link_speed)
  3967. /**
  3968. * lpfc_link_speed_init - Set the adapters link speed
  3969. * @phba: lpfc_hba pointer.
  3970. * @val: link speed value.
  3971. *
  3972. * Description:
  3973. * If val is in a valid range then set the adapter's link speed field.
  3974. *
  3975. * Notes:
  3976. * If the value is not in range log a kernel error message, clear the link
  3977. * speed and return an error.
  3978. *
  3979. * Returns:
  3980. * zero if val saved.
  3981. * -EINVAL val out of range
  3982. **/
  3983. static int
  3984. lpfc_link_speed_init(struct lpfc_hba *phba, int val)
  3985. {
  3986. if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
  3987. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3988. "3111 lpfc_link_speed of %d cannot "
  3989. "support loop mode, setting topology to default.\n",
  3990. val);
  3991. phba->cfg_topology = 0;
  3992. }
  3993. switch (val) {
  3994. case LPFC_USER_LINK_SPEED_AUTO:
  3995. case LPFC_USER_LINK_SPEED_1G:
  3996. case LPFC_USER_LINK_SPEED_2G:
  3997. case LPFC_USER_LINK_SPEED_4G:
  3998. case LPFC_USER_LINK_SPEED_8G:
  3999. case LPFC_USER_LINK_SPEED_16G:
  4000. case LPFC_USER_LINK_SPEED_32G:
  4001. case LPFC_USER_LINK_SPEED_64G:
  4002. phba->cfg_link_speed = val;
  4003. return 0;
  4004. default:
  4005. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4006. "0405 lpfc_link_speed attribute cannot "
  4007. "be set to %d, allowed values are "
  4008. "["LPFC_LINK_SPEED_STRING"]\n", val);
  4009. phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
  4010. return -EINVAL;
  4011. }
  4012. }
  4013. static DEVICE_ATTR_RW(lpfc_link_speed);
  4014. /*
  4015. # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
  4016. # 1 = aer supported and enabled (default)
  4017. # PCIe error reporting is always enabled by the PCI core, so this always
  4018. # shows 1.
  4019. #
  4020. # N.B. Parts of LPFC_ATTR open-coded since some of the underlying
  4021. # infrastructure (phba->cfg_aer_support) is gone.
  4022. */
  4023. static uint lpfc_aer_support = 1;
  4024. module_param(lpfc_aer_support, uint, S_IRUGO);
  4025. MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
  4026. static ssize_t
  4027. lpfc_aer_support_show(struct device *dev, struct device_attribute *attr,
  4028. char *buf)
  4029. {
  4030. return scnprintf(buf, PAGE_SIZE, "%d\n", lpfc_aer_support);
  4031. }
  4032. /**
  4033. * lpfc_aer_support_store - Set the adapter for aer support
  4034. *
  4035. * @dev: class device that is converted into a Scsi_host.
  4036. * @attr: device attribute, not used.
  4037. * @buf: containing enable or disable aer flag.
  4038. * @count: unused variable.
  4039. *
  4040. * Description:
  4041. * PCIe error reporting is enabled by the PCI core, so drivers don't need
  4042. * to do anything. Retain this interface for backwards compatibility,
  4043. * but do nothing.
  4044. *
  4045. * Returns:
  4046. * length of the buf on success
  4047. * -EINVAL if val out of range
  4048. **/
  4049. static ssize_t
  4050. lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
  4051. const char *buf, size_t count)
  4052. {
  4053. int val = 0;
  4054. if (!isdigit(buf[0]))
  4055. return -EINVAL;
  4056. if (sscanf(buf, "%i", &val) != 1)
  4057. return -EINVAL;
  4058. dev_info_once(dev, "PCIe error reporting automatically enabled by the PCI core; sysfs write ignored\n");
  4059. return strlen(buf);
  4060. }
  4061. static DEVICE_ATTR_RW(lpfc_aer_support);
  4062. /**
  4063. * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
  4064. * @dev: class device that is converted into a Scsi_host.
  4065. * @attr: device attribute, not used.
  4066. * @buf: containing flag 1 for aer cleanup state.
  4067. * @count: unused variable.
  4068. *
  4069. * Description:
  4070. * If the @buf contains 1, invokes the kernel AER helper routine
  4071. * pci_aer_clear_nonfatal_status() to clean up the uncorrectable
  4072. * error status register.
  4073. *
  4074. * Notes:
  4075. *
  4076. * Returns:
  4077. * -EINVAL if the buf does not contain 1
  4078. * -EPERM if the OS cannot clear AER error status, i.e., when platform
  4079. * firmware owns the AER Capability
  4080. **/
  4081. static ssize_t
  4082. lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
  4083. const char *buf, size_t count)
  4084. {
  4085. struct Scsi_Host *shost = class_to_shost(dev);
  4086. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4087. struct lpfc_hba *phba = vport->phba;
  4088. int val, rc = -1;
  4089. if (!isdigit(buf[0]))
  4090. return -EINVAL;
  4091. if (sscanf(buf, "%i", &val) != 1)
  4092. return -EINVAL;
  4093. if (val != 1)
  4094. return -EINVAL;
  4095. rc = pci_aer_clear_nonfatal_status(phba->pcidev);
  4096. if (rc == 0)
  4097. return strlen(buf);
  4098. else
  4099. return -EPERM;
  4100. }
  4101. static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
  4102. lpfc_aer_cleanup_state);
  4103. /**
  4104. * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
  4105. *
  4106. * @dev: class device that is converted into a Scsi_host.
  4107. * @attr: device attribute, not used.
  4108. * @buf: containing the string the number of vfs to be enabled.
  4109. * @count: unused variable.
  4110. *
  4111. * Description:
  4112. * When this api is called either through user sysfs, the driver shall
  4113. * try to enable or disable SR-IOV virtual functions according to the
  4114. * following:
  4115. *
  4116. * If zero virtual function has been enabled to the physical function,
  4117. * the driver shall invoke the pci enable virtual function api trying
  4118. * to enable the virtual functions. If the nr_vfn provided is greater
  4119. * than the maximum supported, the maximum virtual function number will
  4120. * be used for invoking the api; otherwise, the nr_vfn provided shall
  4121. * be used for invoking the api. If the api call returned success, the
  4122. * actual number of virtual functions enabled will be set to the driver
  4123. * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
  4124. * cfg_sriov_nr_virtfn remains zero.
  4125. *
  4126. * If none-zero virtual functions have already been enabled to the
  4127. * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
  4128. * -EINVAL will be returned and the driver does nothing;
  4129. *
  4130. * If the nr_vfn provided is zero and none-zero virtual functions have
  4131. * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
  4132. * disabling virtual function api shall be invoded to disable all the
  4133. * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
  4134. * zero. Otherwise, if zero virtual function has been enabled, do
  4135. * nothing.
  4136. *
  4137. * Returns:
  4138. * length of the buf on success if val is in range the intended mode
  4139. * is supported.
  4140. * -EINVAL if val out of range or intended mode is not supported.
  4141. **/
  4142. static ssize_t
  4143. lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
  4144. const char *buf, size_t count)
  4145. {
  4146. struct Scsi_Host *shost = class_to_shost(dev);
  4147. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  4148. struct lpfc_hba *phba = vport->phba;
  4149. struct pci_dev *pdev = phba->pcidev;
  4150. int val = 0, rc = -EINVAL;
  4151. /* Sanity check on user data */
  4152. if (!isdigit(buf[0]))
  4153. return -EINVAL;
  4154. if (sscanf(buf, "%i", &val) != 1)
  4155. return -EINVAL;
  4156. if (val < 0)
  4157. return -EINVAL;
  4158. /* Request disabling virtual functions */
  4159. if (val == 0) {
  4160. if (phba->cfg_sriov_nr_virtfn > 0) {
  4161. pci_disable_sriov(pdev);
  4162. phba->cfg_sriov_nr_virtfn = 0;
  4163. }
  4164. return strlen(buf);
  4165. }
  4166. /* Request enabling virtual functions */
  4167. if (phba->cfg_sriov_nr_virtfn > 0) {
  4168. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4169. "3018 There are %d virtual functions "
  4170. "enabled on physical function.\n",
  4171. phba->cfg_sriov_nr_virtfn);
  4172. return -EEXIST;
  4173. }
  4174. if (val <= LPFC_MAX_VFN_PER_PFN)
  4175. phba->cfg_sriov_nr_virtfn = val;
  4176. else {
  4177. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4178. "3019 Enabling %d virtual functions is not "
  4179. "allowed.\n", val);
  4180. return -EINVAL;
  4181. }
  4182. rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
  4183. if (rc) {
  4184. phba->cfg_sriov_nr_virtfn = 0;
  4185. rc = -EPERM;
  4186. } else
  4187. rc = strlen(buf);
  4188. return rc;
  4189. }
  4190. LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
  4191. "Enable PCIe device SR-IOV virtual fn");
  4192. lpfc_param_show(sriov_nr_virtfn)
  4193. static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
  4194. /**
  4195. * lpfc_request_firmware_upgrade_store - Request for Linux generic firmware upgrade
  4196. *
  4197. * @dev: class device that is converted into a Scsi_host.
  4198. * @attr: device attribute, not used.
  4199. * @buf: containing the string the number of vfs to be enabled.
  4200. * @count: unused variable.
  4201. *
  4202. * Description:
  4203. *
  4204. * Returns:
  4205. * length of the buf on success if val is in range the intended mode
  4206. * is supported.
  4207. * -EINVAL if val out of range or intended mode is not supported.
  4208. **/
  4209. static ssize_t
  4210. lpfc_request_firmware_upgrade_store(struct device *dev,
  4211. struct device_attribute *attr,
  4212. const char *buf, size_t count)
  4213. {
  4214. struct Scsi_Host *shost = class_to_shost(dev);
  4215. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  4216. struct lpfc_hba *phba = vport->phba;
  4217. int val = 0, rc;
  4218. /* Sanity check on user data */
  4219. if (!isdigit(buf[0]))
  4220. return -EINVAL;
  4221. if (sscanf(buf, "%i", &val) != 1)
  4222. return -EINVAL;
  4223. if (val != 1)
  4224. return -EINVAL;
  4225. rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
  4226. if (rc)
  4227. rc = -EPERM;
  4228. else
  4229. rc = strlen(buf);
  4230. return rc;
  4231. }
  4232. static int lpfc_req_fw_upgrade;
  4233. module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
  4234. MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
  4235. lpfc_param_show(request_firmware_upgrade)
  4236. /**
  4237. * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
  4238. * @phba: lpfc_hba pointer.
  4239. * @val: 0 or 1.
  4240. *
  4241. * Description:
  4242. * Set the initial Linux generic firmware upgrade enable or disable flag.
  4243. *
  4244. * Returns:
  4245. * zero if val saved.
  4246. * -EINVAL val out of range
  4247. **/
  4248. static int
  4249. lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
  4250. {
  4251. if (val >= 0 && val <= 1) {
  4252. phba->cfg_request_firmware_upgrade = val;
  4253. return 0;
  4254. }
  4255. return -EINVAL;
  4256. }
  4257. static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
  4258. lpfc_request_firmware_upgrade_show,
  4259. lpfc_request_firmware_upgrade_store);
  4260. /**
  4261. * lpfc_force_rscn_store
  4262. *
  4263. * @dev: class device that is converted into a Scsi_host.
  4264. * @attr: device attribute, not used.
  4265. * @buf: unused string
  4266. * @count: unused variable.
  4267. *
  4268. * Description:
  4269. * Force the switch to send a RSCN to all other NPorts in our zone
  4270. * If we are direct connect pt2pt, build the RSCN command ourself
  4271. * and send to the other NPort. Not supported for private loop.
  4272. *
  4273. * Returns:
  4274. * 0 - on success
  4275. * -EIO - if command is not sent
  4276. **/
  4277. static ssize_t
  4278. lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,
  4279. const char *buf, size_t count)
  4280. {
  4281. struct Scsi_Host *shost = class_to_shost(dev);
  4282. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  4283. int i;
  4284. i = lpfc_issue_els_rscn(vport, 0);
  4285. if (i)
  4286. return -EIO;
  4287. return strlen(buf);
  4288. }
  4289. /*
  4290. * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
  4291. * connected to the HBA.
  4292. *
  4293. * Value range is any ascii value
  4294. */
  4295. static int lpfc_force_rscn;
  4296. module_param(lpfc_force_rscn, int, 0644);
  4297. MODULE_PARM_DESC(lpfc_force_rscn,
  4298. "Force an RSCN to be sent to all remote NPorts");
  4299. lpfc_param_show(force_rscn)
  4300. /**
  4301. * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
  4302. * @phba: lpfc_hba pointer.
  4303. * @val: unused value.
  4304. *
  4305. * Returns:
  4306. * zero if val saved.
  4307. **/
  4308. static int
  4309. lpfc_force_rscn_init(struct lpfc_hba *phba, int val)
  4310. {
  4311. return 0;
  4312. }
  4313. static DEVICE_ATTR_RW(lpfc_force_rscn);
  4314. /**
  4315. * lpfc_fcp_imax_store
  4316. *
  4317. * @dev: class device that is converted into a Scsi_host.
  4318. * @attr: device attribute, not used.
  4319. * @buf: string with the number of fast-path FCP interrupts per second.
  4320. * @count: unused variable.
  4321. *
  4322. * Description:
  4323. * If val is in a valid range [636,651042], then set the adapter's
  4324. * maximum number of fast-path FCP interrupts per second.
  4325. *
  4326. * Returns:
  4327. * length of the buf on success if val is in range the intended mode
  4328. * is supported.
  4329. * -EINVAL if val out of range or intended mode is not supported.
  4330. **/
  4331. static ssize_t
  4332. lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
  4333. const char *buf, size_t count)
  4334. {
  4335. struct Scsi_Host *shost = class_to_shost(dev);
  4336. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  4337. struct lpfc_hba *phba = vport->phba;
  4338. struct lpfc_eq_intr_info *eqi;
  4339. uint32_t usdelay;
  4340. int val = 0, i;
  4341. /* fcp_imax is only valid for SLI4 */
  4342. if (phba->sli_rev != LPFC_SLI_REV4)
  4343. return -EINVAL;
  4344. /* Sanity check on user data */
  4345. if (!isdigit(buf[0]))
  4346. return -EINVAL;
  4347. if (sscanf(buf, "%i", &val) != 1)
  4348. return -EINVAL;
  4349. /*
  4350. * Value range for the HBA is [5000,5000000]
  4351. * The value for each EQ depends on how many EQs are configured.
  4352. * Allow value == 0
  4353. */
  4354. if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
  4355. return -EINVAL;
  4356. phba->cfg_auto_imax = (val) ? 0 : 1;
  4357. if (phba->cfg_fcp_imax && !val) {
  4358. queue_delayed_work(phba->wq, &phba->eq_delay_work,
  4359. msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
  4360. for_each_present_cpu(i) {
  4361. eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
  4362. eqi->icnt = 0;
  4363. }
  4364. }
  4365. phba->cfg_fcp_imax = (uint32_t)val;
  4366. if (phba->cfg_fcp_imax)
  4367. usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
  4368. else
  4369. usdelay = 0;
  4370. for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
  4371. lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
  4372. usdelay);
  4373. return strlen(buf);
  4374. }
  4375. /*
  4376. # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
  4377. # for the HBA.
  4378. #
  4379. # Value range is [5,000 to 5,000,000]. Default value is 50,000.
  4380. */
  4381. static int lpfc_fcp_imax = LPFC_DEF_IMAX;
  4382. module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
  4383. MODULE_PARM_DESC(lpfc_fcp_imax,
  4384. "Set the maximum number of FCP interrupts per second per HBA");
  4385. lpfc_param_show(fcp_imax)
  4386. /**
  4387. * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
  4388. * @phba: lpfc_hba pointer.
  4389. * @val: link speed value.
  4390. *
  4391. * Description:
  4392. * If val is in a valid range [636,651042], then initialize the adapter's
  4393. * maximum number of fast-path FCP interrupts per second.
  4394. *
  4395. * Returns:
  4396. * zero if val saved.
  4397. * -EINVAL val out of range
  4398. **/
  4399. static int
  4400. lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
  4401. {
  4402. if (phba->sli_rev != LPFC_SLI_REV4) {
  4403. phba->cfg_fcp_imax = 0;
  4404. return 0;
  4405. }
  4406. if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
  4407. (val == 0)) {
  4408. phba->cfg_fcp_imax = val;
  4409. return 0;
  4410. }
  4411. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4412. "3016 lpfc_fcp_imax: %d out of range, using default\n",
  4413. val);
  4414. phba->cfg_fcp_imax = LPFC_DEF_IMAX;
  4415. return 0;
  4416. }
  4417. static DEVICE_ATTR_RW(lpfc_fcp_imax);
  4418. /**
  4419. * lpfc_cq_max_proc_limit_store
  4420. *
  4421. * @dev: class device that is converted into a Scsi_host.
  4422. * @attr: device attribute, not used.
  4423. * @buf: string with the cq max processing limit of cqes
  4424. * @count: unused variable.
  4425. *
  4426. * Description:
  4427. * If val is in a valid range, then set value on each cq
  4428. *
  4429. * Returns:
  4430. * The length of the buf: if successful
  4431. * -ERANGE: if val is not in the valid range
  4432. * -EINVAL: if bad value format or intended mode is not supported.
  4433. **/
  4434. static ssize_t
  4435. lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
  4436. const char *buf, size_t count)
  4437. {
  4438. struct Scsi_Host *shost = class_to_shost(dev);
  4439. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  4440. struct lpfc_hba *phba = vport->phba;
  4441. struct lpfc_queue *eq, *cq;
  4442. unsigned long val;
  4443. int i;
  4444. /* cq_max_proc_limit is only valid for SLI4 */
  4445. if (phba->sli_rev != LPFC_SLI_REV4)
  4446. return -EINVAL;
  4447. /* Sanity check on user data */
  4448. if (!isdigit(buf[0]))
  4449. return -EINVAL;
  4450. if (kstrtoul(buf, 0, &val))
  4451. return -EINVAL;
  4452. if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
  4453. return -ERANGE;
  4454. phba->cfg_cq_max_proc_limit = (uint32_t)val;
  4455. /* set the values on the cq's */
  4456. for (i = 0; i < phba->cfg_irq_chann; i++) {
  4457. /* Get the EQ corresponding to the IRQ vector */
  4458. eq = phba->sli4_hba.hba_eq_hdl[i].eq;
  4459. if (!eq)
  4460. continue;
  4461. list_for_each_entry(cq, &eq->child_list, list)
  4462. cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
  4463. cq->entry_count);
  4464. }
  4465. return strlen(buf);
  4466. }
  4467. /*
  4468. * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
  4469. * itteration of CQ processing.
  4470. */
  4471. static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
  4472. module_param(lpfc_cq_max_proc_limit, int, 0644);
  4473. MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
  4474. "Set the maximum number CQEs processed in an iteration of "
  4475. "CQ processing");
  4476. lpfc_param_show(cq_max_proc_limit)
  4477. /*
  4478. * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
  4479. * single handler call which should request a polled completion rather
  4480. * than re-enabling interrupts.
  4481. */
  4482. LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
  4483. LPFC_CQ_MIN_THRESHOLD_TO_POLL,
  4484. LPFC_CQ_MAX_THRESHOLD_TO_POLL,
  4485. "CQE Processing Threshold to enable Polling");
  4486. /**
  4487. * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
  4488. * @phba: lpfc_hba pointer.
  4489. * @val: entry limit
  4490. *
  4491. * Description:
  4492. * If val is in a valid range, then initialize the adapter's maximum
  4493. * value.
  4494. *
  4495. * Returns:
  4496. * Always returns 0 for success, even if value not always set to
  4497. * requested value. If value out of range or not supported, will fall
  4498. * back to default.
  4499. **/
  4500. static int
  4501. lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
  4502. {
  4503. phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
  4504. if (phba->sli_rev != LPFC_SLI_REV4)
  4505. return 0;
  4506. if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
  4507. phba->cfg_cq_max_proc_limit = val;
  4508. return 0;
  4509. }
  4510. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4511. "0371 lpfc_cq_max_proc_limit: %d out of range, using "
  4512. "default\n",
  4513. phba->cfg_cq_max_proc_limit);
  4514. return 0;
  4515. }
  4516. static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
  4517. /**
  4518. * lpfc_fcp_cpu_map_show - Display current driver CPU affinity
  4519. * @dev: class converted to a Scsi_host structure.
  4520. * @attr: device attribute, not used.
  4521. * @buf: on return contains text describing the state of the link.
  4522. *
  4523. * Returns: size of formatted string.
  4524. **/
  4525. static ssize_t
  4526. lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
  4527. char *buf)
  4528. {
  4529. struct Scsi_Host *shost = class_to_shost(dev);
  4530. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  4531. struct lpfc_hba *phba = vport->phba;
  4532. struct lpfc_vector_map_info *cpup;
  4533. int len = 0;
  4534. if ((phba->sli_rev != LPFC_SLI_REV4) ||
  4535. (phba->intr_type != MSIX))
  4536. return len;
  4537. switch (phba->cfg_fcp_cpu_map) {
  4538. case 0:
  4539. len += scnprintf(buf + len, PAGE_SIZE-len,
  4540. "fcp_cpu_map: No mapping (%d)\n",
  4541. phba->cfg_fcp_cpu_map);
  4542. return len;
  4543. case 1:
  4544. len += scnprintf(buf + len, PAGE_SIZE-len,
  4545. "fcp_cpu_map: HBA centric mapping (%d): "
  4546. "%d of %d CPUs online from %d possible CPUs\n",
  4547. phba->cfg_fcp_cpu_map, num_online_cpus(),
  4548. num_present_cpus(),
  4549. phba->sli4_hba.num_possible_cpu);
  4550. break;
  4551. }
  4552. while (phba->sli4_hba.curr_disp_cpu <
  4553. phba->sli4_hba.num_possible_cpu) {
  4554. cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
  4555. if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
  4556. len += scnprintf(buf + len, PAGE_SIZE - len,
  4557. "CPU %02d not present\n",
  4558. phba->sli4_hba.curr_disp_cpu);
  4559. else if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
  4560. if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
  4561. len += scnprintf(
  4562. buf + len, PAGE_SIZE - len,
  4563. "CPU %02d hdwq None "
  4564. "physid %d coreid %d ht %d ua %d\n",
  4565. phba->sli4_hba.curr_disp_cpu,
  4566. cpup->phys_id, cpup->core_id,
  4567. (cpup->flag & LPFC_CPU_MAP_HYPER),
  4568. (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
  4569. else
  4570. len += scnprintf(
  4571. buf + len, PAGE_SIZE - len,
  4572. "CPU %02d EQ None hdwq %04d "
  4573. "physid %d coreid %d ht %d ua %d\n",
  4574. phba->sli4_hba.curr_disp_cpu,
  4575. cpup->hdwq, cpup->phys_id,
  4576. cpup->core_id,
  4577. (cpup->flag & LPFC_CPU_MAP_HYPER),
  4578. (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
  4579. } else {
  4580. if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
  4581. len += scnprintf(
  4582. buf + len, PAGE_SIZE - len,
  4583. "CPU %02d hdwq None "
  4584. "physid %d coreid %d ht %d ua %d IRQ %d\n",
  4585. phba->sli4_hba.curr_disp_cpu,
  4586. cpup->phys_id,
  4587. cpup->core_id,
  4588. (cpup->flag & LPFC_CPU_MAP_HYPER),
  4589. (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
  4590. lpfc_get_irq(cpup->eq));
  4591. else
  4592. len += scnprintf(
  4593. buf + len, PAGE_SIZE - len,
  4594. "CPU %02d EQ %04d hdwq %04d "
  4595. "physid %d coreid %d ht %d ua %d IRQ %d\n",
  4596. phba->sli4_hba.curr_disp_cpu,
  4597. cpup->eq, cpup->hdwq, cpup->phys_id,
  4598. cpup->core_id,
  4599. (cpup->flag & LPFC_CPU_MAP_HYPER),
  4600. (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
  4601. lpfc_get_irq(cpup->eq));
  4602. }
  4603. phba->sli4_hba.curr_disp_cpu++;
  4604. /* display max number of CPUs keeping some margin */
  4605. if (phba->sli4_hba.curr_disp_cpu <
  4606. phba->sli4_hba.num_possible_cpu &&
  4607. (len >= (PAGE_SIZE - 64))) {
  4608. len += scnprintf(buf + len,
  4609. PAGE_SIZE - len, "more...\n");
  4610. break;
  4611. }
  4612. }
  4613. if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
  4614. phba->sli4_hba.curr_disp_cpu = 0;
  4615. return len;
  4616. }
  4617. /**
  4618. * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
  4619. * @dev: class device that is converted into a Scsi_host.
  4620. * @attr: device attribute, not used.
  4621. * @buf: one or more lpfc_polling_flags values.
  4622. * @count: not used.
  4623. *
  4624. * Returns:
  4625. * -EINVAL - Not implemented yet.
  4626. **/
  4627. static ssize_t
  4628. lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
  4629. const char *buf, size_t count)
  4630. {
  4631. return -EINVAL;
  4632. }
  4633. /*
  4634. # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
  4635. # for the HBA.
  4636. #
  4637. # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
  4638. # 0 - Do not affinitze IRQ vectors
  4639. # 1 - Affintize HBA vectors with respect to each HBA
  4640. # (start with CPU0 for each HBA)
  4641. # This also defines how Hardware Queues are mapped to specific CPUs.
  4642. */
  4643. static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
  4644. module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
  4645. MODULE_PARM_DESC(lpfc_fcp_cpu_map,
  4646. "Defines how to map CPUs to IRQ vectors per HBA");
  4647. /**
  4648. * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
  4649. * @phba: lpfc_hba pointer.
  4650. * @val: link speed value.
  4651. *
  4652. * Description:
  4653. * If val is in a valid range [0-2], then affinitze the adapter's
  4654. * MSIX vectors.
  4655. *
  4656. * Returns:
  4657. * zero if val saved.
  4658. * -EINVAL val out of range
  4659. **/
  4660. static int
  4661. lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
  4662. {
  4663. if (phba->sli_rev != LPFC_SLI_REV4) {
  4664. phba->cfg_fcp_cpu_map = 0;
  4665. return 0;
  4666. }
  4667. if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
  4668. phba->cfg_fcp_cpu_map = val;
  4669. return 0;
  4670. }
  4671. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4672. "3326 lpfc_fcp_cpu_map: %d out of range, using "
  4673. "default\n", val);
  4674. phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
  4675. return 0;
  4676. }
  4677. static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
  4678. /*
  4679. # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
  4680. # Value range is [2,3]. Default value is 3.
  4681. */
  4682. LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
  4683. "Select Fibre Channel class of service for FCP sequences");
  4684. /*
  4685. # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
  4686. # is [0,1]. Default value is 1.
  4687. */
  4688. LPFC_VPORT_ATTR_RW(use_adisc, 1, 0, 1,
  4689. "Use ADISC on rediscovery to authenticate FCP devices");
  4690. /*
  4691. # lpfc_first_burst_size: First burst size to use on the NPorts
  4692. # that support first burst.
  4693. # Value range is [0,65536]. Default value is 0.
  4694. */
  4695. LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
  4696. "First burst size for Targets that support first burst");
  4697. /*
  4698. * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
  4699. * When the driver is configured as an NVME target, this value is
  4700. * communicated to the NVME initiator in the PRLI response. It is
  4701. * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
  4702. * parameters are set and the target is sending the PRLI RSP.
  4703. * Parameter supported on physical port only - no NPIV support.
  4704. * Value range is [0,65536]. Default value is 0.
  4705. */
  4706. LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
  4707. "NVME Target mode first burst size in 512B increments.");
  4708. /*
  4709. * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
  4710. * For the Initiator (I), enabling this parameter means that an NVMET
  4711. * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
  4712. * processed by the initiator for subsequent NVME FCP IO.
  4713. * Currently, this feature is not supported on the NVME target
  4714. * Value range is [0,1]. Default value is 0 (disabled).
  4715. */
  4716. LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
  4717. "Enable First Burst feature for NVME Initiator.");
  4718. /*
  4719. # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
  4720. # depth. Default value is 0. When the value of this parameter is zero the
  4721. # SCSI command completion time is not used for controlling I/O queue depth. When
  4722. # the parameter is set to a non-zero value, the I/O queue depth is controlled
  4723. # to limit the I/O completion time to the parameter value.
  4724. # The value is set in milliseconds.
  4725. */
  4726. LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
  4727. "Use command completion time to control queue depth");
  4728. lpfc_vport_param_show(max_scsicmpl_time);
  4729. static int
  4730. lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
  4731. {
  4732. struct lpfc_nodelist *ndlp, *next_ndlp;
  4733. unsigned long iflags;
  4734. if (val == vport->cfg_max_scsicmpl_time)
  4735. return 0;
  4736. if ((val < 0) || (val > 60000))
  4737. return -EINVAL;
  4738. vport->cfg_max_scsicmpl_time = val;
  4739. spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
  4740. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  4741. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  4742. continue;
  4743. ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
  4744. }
  4745. spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
  4746. return 0;
  4747. }
  4748. lpfc_vport_param_store(max_scsicmpl_time);
  4749. static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
  4750. /*
  4751. # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
  4752. # range is [0,1]. Default value is 0.
  4753. */
  4754. LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
  4755. /*
  4756. # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
  4757. # range is [0,1]. Default value is 1.
  4758. */
  4759. LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
  4760. /*
  4761. * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
  4762. * range is [0,1]. Default value is 0.
  4763. * For [0], FCP commands are issued to Work Queues based on upper layer
  4764. * hardware queue index.
  4765. * For [1], FCP commands are issued to a Work Queue associated with the
  4766. * current CPU.
  4767. *
  4768. * LPFC_FCP_SCHED_BY_HDWQ == 0
  4769. * LPFC_FCP_SCHED_BY_CPU == 1
  4770. *
  4771. * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
  4772. * affinity for FCP/NVME I/Os through Work Queues associated with the current
  4773. * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
  4774. * through WQs will be used.
  4775. */
  4776. LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
  4777. LPFC_FCP_SCHED_BY_HDWQ,
  4778. LPFC_FCP_SCHED_BY_CPU,
  4779. "Determine scheduling algorithm for "
  4780. "issuing commands [0] - Hardware Queue, [1] - Current CPU");
  4781. /*
  4782. * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
  4783. * range is [0,1]. Default value is 0.
  4784. * For [0], GID_FT is used for NameServer queries after RSCN (default)
  4785. * For [1], GID_PT is used for NameServer queries after RSCN
  4786. *
  4787. */
  4788. LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
  4789. LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
  4790. "Determine algorithm NameServer queries after RSCN "
  4791. "[0] - GID_FT, [1] - GID_PT");
  4792. /*
  4793. # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
  4794. # range is [0,1]. Default value is 0.
  4795. # For [0], bus reset issues target reset to ALL devices
  4796. # For [1], bus reset issues target reset to non-FCP2 devices
  4797. */
  4798. LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
  4799. "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
  4800. /*
  4801. # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
  4802. # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
  4803. # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
  4804. # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
  4805. # cr_delay is set to 0.
  4806. */
  4807. LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
  4808. "interrupt response is generated");
  4809. LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
  4810. "interrupt response is generated");
  4811. /*
  4812. # lpfc_multi_ring_support: Determines how many rings to spread available
  4813. # cmd/rsp IOCB entries across.
  4814. # Value range is [1,2]. Default value is 1.
  4815. */
  4816. LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
  4817. "SLI rings to spread IOCB entries across");
  4818. /*
  4819. # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
  4820. # identifies what rctl value to configure the additional ring for.
  4821. # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
  4822. */
  4823. LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
  4824. 255, "Identifies RCTL for additional ring configuration");
  4825. /*
  4826. # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
  4827. # identifies what type value to configure the additional ring for.
  4828. # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
  4829. */
  4830. LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
  4831. 255, "Identifies TYPE for additional ring configuration");
  4832. /*
  4833. # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
  4834. # 0 = SmartSAN functionality disabled (default)
  4835. # 1 = SmartSAN functionality enabled
  4836. # This parameter will override the value of lpfc_fdmi_on module parameter.
  4837. # Value range is [0,1]. Default value is 0.
  4838. */
  4839. LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
  4840. /*
  4841. # lpfc_fdmi_on: Controls FDMI support.
  4842. # 0 No FDMI support
  4843. # 1 Traditional FDMI support (default)
  4844. # Traditional FDMI support means the driver will assume FDMI-2 support;
  4845. # however, if that fails, it will fallback to FDMI-1.
  4846. # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
  4847. # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
  4848. # lpfc_fdmi_on.
  4849. # Value range [0,1]. Default value is 1.
  4850. */
  4851. LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
  4852. /*
  4853. # Specifies the maximum number of ELS cmds we can have outstanding (for
  4854. # discovery). Value range is [1,64]. Default value = 32.
  4855. */
  4856. LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
  4857. "during discovery");
  4858. /*
  4859. # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
  4860. # will be scanned by the SCSI midlayer when sequential scanning is
  4861. # used; and is also the highest LUN ID allowed when the SCSI midlayer
  4862. # parses REPORT_LUN responses. The lpfc driver has no LUN count or
  4863. # LUN ID limit, but the SCSI midlayer requires this field for the uses
  4864. # above. The lpfc driver limits the default value to 255 for two reasons.
  4865. # As it bounds the sequential scan loop, scanning for thousands of luns
  4866. # on a target can take minutes of wall clock time. Additionally,
  4867. # there are FC targets, such as JBODs, that only recognize 8-bits of
  4868. # LUN ID. When they receive a value greater than 8 bits, they chop off
  4869. # the high order bits. In other words, they see LUN IDs 0, 256, 512,
  4870. # and so on all as LUN ID 0. This causes the linux kernel, which sees
  4871. # valid responses at each of the LUN IDs, to believe there are multiple
  4872. # devices present, when in fact, there is only 1.
  4873. # A customer that is aware of their target behaviors, and the results as
  4874. # indicated above, is welcome to increase the lpfc_max_luns value.
  4875. # As mentioned, this value is not used by the lpfc driver, only the
  4876. # SCSI midlayer.
  4877. # Value range is [0,65535]. Default value is 255.
  4878. # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
  4879. */
  4880. LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
  4881. /*
  4882. # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
  4883. # Value range is [1,255], default value is 10.
  4884. */
  4885. LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
  4886. "Milliseconds driver will wait between polling FCP ring");
  4887. /*
  4888. # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
  4889. # to complete in seconds. Value range is [5,180], default value is 60.
  4890. */
  4891. LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
  4892. "Maximum time to wait for task management commands to complete");
  4893. /*
  4894. # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
  4895. # support this feature
  4896. # 0 = MSI disabled
  4897. # 1 = MSI enabled
  4898. # 2 = MSI-X enabled (default)
  4899. # Value range is [0,2]. Default value is 2.
  4900. */
  4901. LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
  4902. "MSI-X (2), if possible");
  4903. /*
  4904. * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
  4905. *
  4906. * 0 = NVME OAS disabled
  4907. * 1 = NVME OAS enabled
  4908. *
  4909. * Value range is [0,1]. Default value is 0.
  4910. */
  4911. LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
  4912. "Use OAS bit on NVME IOs");
  4913. /*
  4914. * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
  4915. *
  4916. * 0 = Put NVME Command in SGL
  4917. * 1 = Embed NVME Command in WQE (unless G7)
  4918. * 2 = Embed NVME Command in WQE (force)
  4919. *
  4920. * Value range is [0,2]. Default value is 1.
  4921. */
  4922. LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
  4923. "Embed NVME Command in WQE");
  4924. /*
  4925. * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
  4926. * the driver will advertise it supports to the SCSI layer.
  4927. *
  4928. * 0 = Set nr_hw_queues by the number of CPUs or HW queues.
  4929. * 1,256 = Manually specify nr_hw_queue value to be advertised,
  4930. *
  4931. * Value range is [0,256]. Default value is 8.
  4932. */
  4933. LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,
  4934. LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,
  4935. "Set the number of SCSI Queues advertised");
  4936. /*
  4937. * lpfc_hdw_queue: Set the number of Hardware Queues the driver
  4938. * will advertise it supports to the NVME and SCSI layers. This also
  4939. * will map to the number of CQ/WQ pairs the driver will create.
  4940. *
  4941. * The NVME Layer will try to create this many, plus 1 administrative
  4942. * hardware queue. The administrative queue will always map to WQ 0
  4943. * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
  4944. *
  4945. * 0 = Configure the number of hdw queues to the number of active CPUs.
  4946. * 1,256 = Manually specify how many hdw queues to use.
  4947. *
  4948. * Value range is [0,256]. Default value is 0.
  4949. */
  4950. LPFC_ATTR_R(hdw_queue,
  4951. LPFC_HBA_HDWQ_DEF,
  4952. LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
  4953. "Set the number of I/O Hardware Queues");
  4954. #if IS_ENABLED(CONFIG_X86)
  4955. /**
  4956. * lpfc_cpumask_irq_mode_init - initalizes cpumask of phba based on
  4957. * irq_chann_mode
  4958. * @phba: Pointer to HBA context object.
  4959. **/
  4960. static void
  4961. lpfc_cpumask_irq_mode_init(struct lpfc_hba *phba)
  4962. {
  4963. unsigned int cpu, first_cpu, numa_node = NUMA_NO_NODE;
  4964. const struct cpumask *sibling_mask;
  4965. struct cpumask *aff_mask = &phba->sli4_hba.irq_aff_mask;
  4966. cpumask_clear(aff_mask);
  4967. if (phba->irq_chann_mode == NUMA_MODE) {
  4968. /* Check if we're a NUMA architecture */
  4969. numa_node = dev_to_node(&phba->pcidev->dev);
  4970. if (numa_node == NUMA_NO_NODE) {
  4971. phba->irq_chann_mode = NORMAL_MODE;
  4972. return;
  4973. }
  4974. }
  4975. for_each_possible_cpu(cpu) {
  4976. switch (phba->irq_chann_mode) {
  4977. case NUMA_MODE:
  4978. if (cpu_to_node(cpu) == numa_node)
  4979. cpumask_set_cpu(cpu, aff_mask);
  4980. break;
  4981. case NHT_MODE:
  4982. sibling_mask = topology_sibling_cpumask(cpu);
  4983. first_cpu = cpumask_first(sibling_mask);
  4984. if (first_cpu < nr_cpu_ids)
  4985. cpumask_set_cpu(first_cpu, aff_mask);
  4986. break;
  4987. default:
  4988. break;
  4989. }
  4990. }
  4991. }
  4992. #endif
  4993. static void
  4994. lpfc_assign_default_irq_chann(struct lpfc_hba *phba)
  4995. {
  4996. #if IS_ENABLED(CONFIG_X86)
  4997. switch (boot_cpu_data.x86_vendor) {
  4998. case X86_VENDOR_AMD:
  4999. /* If AMD architecture, then default is NUMA_MODE */
  5000. phba->irq_chann_mode = NUMA_MODE;
  5001. break;
  5002. case X86_VENDOR_INTEL:
  5003. /* If Intel architecture, then default is no hyperthread mode */
  5004. phba->irq_chann_mode = NHT_MODE;
  5005. break;
  5006. default:
  5007. phba->irq_chann_mode = NORMAL_MODE;
  5008. break;
  5009. }
  5010. lpfc_cpumask_irq_mode_init(phba);
  5011. #else
  5012. phba->irq_chann_mode = NORMAL_MODE;
  5013. #endif
  5014. }
  5015. /*
  5016. * lpfc_irq_chann: Set the number of IRQ vectors that are available
  5017. * for Hardware Queues to utilize. This also will map to the number
  5018. * of EQ / MSI-X vectors the driver will create. This should never be
  5019. * more than the number of Hardware Queues
  5020. *
  5021. * 0 = Configure number of IRQ Channels to:
  5022. * if AMD architecture, number of CPUs on HBA's NUMA node
  5023. * if Intel architecture, number of physical CPUs.
  5024. * otherwise, number of active CPUs.
  5025. * [1,256] = Manually specify how many IRQ Channels to use.
  5026. *
  5027. * Value range is [0,256]. Default value is [0].
  5028. */
  5029. static uint lpfc_irq_chann = LPFC_IRQ_CHANN_DEF;
  5030. module_param(lpfc_irq_chann, uint, 0444);
  5031. MODULE_PARM_DESC(lpfc_irq_chann, "Set number of interrupt vectors to allocate");
  5032. /* lpfc_irq_chann_init - Set the hba irq_chann initial value
  5033. * @phba: lpfc_hba pointer.
  5034. * @val: contains the initial value
  5035. *
  5036. * Description:
  5037. * Validates the initial value is within range and assigns it to the
  5038. * adapter. If not in range, an error message is posted and the
  5039. * default value is assigned.
  5040. *
  5041. * Returns:
  5042. * zero if value is in range and is set
  5043. * -EINVAL if value was out of range
  5044. **/
  5045. static int
  5046. lpfc_irq_chann_init(struct lpfc_hba *phba, uint32_t val)
  5047. {
  5048. const struct cpumask *aff_mask;
  5049. if (phba->cfg_use_msi != 2) {
  5050. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5051. "8532 use_msi = %u ignoring cfg_irq_numa\n",
  5052. phba->cfg_use_msi);
  5053. phba->irq_chann_mode = NORMAL_MODE;
  5054. phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
  5055. return 0;
  5056. }
  5057. /* Check if default setting was passed */
  5058. if (val == LPFC_IRQ_CHANN_DEF &&
  5059. phba->cfg_hdw_queue == LPFC_HBA_HDWQ_DEF &&
  5060. phba->sli_rev == LPFC_SLI_REV4)
  5061. lpfc_assign_default_irq_chann(phba);
  5062. if (phba->irq_chann_mode != NORMAL_MODE) {
  5063. aff_mask = &phba->sli4_hba.irq_aff_mask;
  5064. if (cpumask_empty(aff_mask)) {
  5065. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5066. "8533 Could not identify CPUS for "
  5067. "mode %d, ignoring\n",
  5068. phba->irq_chann_mode);
  5069. phba->irq_chann_mode = NORMAL_MODE;
  5070. phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
  5071. } else {
  5072. phba->cfg_irq_chann = cpumask_weight(aff_mask);
  5073. /* If no hyperthread mode, then set hdwq count to
  5074. * aff_mask weight as well
  5075. */
  5076. if (phba->irq_chann_mode == NHT_MODE)
  5077. phba->cfg_hdw_queue = phba->cfg_irq_chann;
  5078. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5079. "8543 lpfc_irq_chann set to %u "
  5080. "(mode: %d)\n", phba->cfg_irq_chann,
  5081. phba->irq_chann_mode);
  5082. }
  5083. } else {
  5084. if (val > LPFC_IRQ_CHANN_MAX) {
  5085. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5086. "8545 lpfc_irq_chann attribute cannot "
  5087. "be set to %u, allowed range is "
  5088. "[%u,%u]\n",
  5089. val,
  5090. LPFC_IRQ_CHANN_MIN,
  5091. LPFC_IRQ_CHANN_MAX);
  5092. phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
  5093. return -EINVAL;
  5094. }
  5095. if (phba->sli_rev == LPFC_SLI_REV4) {
  5096. phba->cfg_irq_chann = val;
  5097. } else {
  5098. phba->cfg_irq_chann = 2;
  5099. phba->cfg_hdw_queue = 1;
  5100. }
  5101. }
  5102. return 0;
  5103. }
  5104. /**
  5105. * lpfc_irq_chann_show - Display value of irq_chann
  5106. * @dev: class converted to a Scsi_host structure.
  5107. * @attr: device attribute, not used.
  5108. * @buf: on return contains a string with the list sizes
  5109. *
  5110. * Returns: size of formatted string.
  5111. **/
  5112. static ssize_t
  5113. lpfc_irq_chann_show(struct device *dev, struct device_attribute *attr,
  5114. char *buf)
  5115. {
  5116. struct Scsi_Host *shost = class_to_shost(dev);
  5117. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  5118. struct lpfc_hba *phba = vport->phba;
  5119. return scnprintf(buf, PAGE_SIZE, "%u\n", phba->cfg_irq_chann);
  5120. }
  5121. static DEVICE_ATTR_RO(lpfc_irq_chann);
  5122. /*
  5123. # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
  5124. # 0 = HBA resets disabled
  5125. # 1 = HBA resets enabled (default)
  5126. # 2 = HBA reset via PCI bus reset enabled
  5127. # Value range is [0,2]. Default value is 1.
  5128. */
  5129. LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
  5130. /*
  5131. # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
  5132. # 0 = HBA Heartbeat disabled
  5133. # 1 = HBA Heartbeat enabled (default)
  5134. # Value range is [0,1]. Default value is 1.
  5135. */
  5136. LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
  5137. /*
  5138. # lpfc_EnableXLane: Enable Express Lane Feature
  5139. # 0x0 Express Lane Feature disabled
  5140. # 0x1 Express Lane Feature enabled
  5141. # Value range is [0,1]. Default value is 0.
  5142. */
  5143. LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
  5144. /*
  5145. # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
  5146. # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
  5147. # Value range is [0x0,0x7f]. Default value is 0
  5148. */
  5149. LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
  5150. /*
  5151. # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
  5152. # 0 = BlockGuard disabled (default)
  5153. # 1 = BlockGuard enabled
  5154. # Value range is [0,1]. Default value is 0.
  5155. */
  5156. LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
  5157. /*
  5158. # lpfc_prot_mask:
  5159. # - Bit mask of host protection capabilities used to register with the
  5160. # SCSI mid-layer
  5161. # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
  5162. # - Allows you to ultimately specify which profiles to use
  5163. # - Default will result in registering capabilities for all profiles.
  5164. # - SHOST_DIF_TYPE1_PROTECTION 1
  5165. # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
  5166. # - SHOST_DIX_TYPE0_PROTECTION 8
  5167. # HBA supports DIX Type 0: Host to HBA protection only
  5168. # - SHOST_DIX_TYPE1_PROTECTION 16
  5169. # HBA supports DIX Type 1: Host to HBA Type 1 protection
  5170. #
  5171. */
  5172. LPFC_ATTR(prot_mask,
  5173. (SHOST_DIF_TYPE1_PROTECTION |
  5174. SHOST_DIX_TYPE0_PROTECTION |
  5175. SHOST_DIX_TYPE1_PROTECTION),
  5176. 0,
  5177. (SHOST_DIF_TYPE1_PROTECTION |
  5178. SHOST_DIX_TYPE0_PROTECTION |
  5179. SHOST_DIX_TYPE1_PROTECTION),
  5180. "T10-DIF host protection capabilities mask");
  5181. /*
  5182. # lpfc_prot_guard:
  5183. # - Bit mask of protection guard types to register with the SCSI mid-layer
  5184. # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
  5185. # - Allows you to ultimately specify which profiles to use
  5186. # - Default will result in registering capabilities for all guard types
  5187. #
  5188. */
  5189. LPFC_ATTR(prot_guard,
  5190. SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
  5191. "T10-DIF host protection guard type");
  5192. /*
  5193. * Delay initial NPort discovery when Clean Address bit is cleared in
  5194. * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
  5195. * This parameter can have value 0 or 1.
  5196. * When this parameter is set to 0, no delay is added to the initial
  5197. * discovery.
  5198. * When this parameter is set to non-zero value, initial Nport discovery is
  5199. * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
  5200. * accept and FCID/Fabric name/Fabric portname is changed.
  5201. * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
  5202. * when Clean Address bit is cleared in FLOGI/FDISC
  5203. * accept and FCID/Fabric name/Fabric portname is changed.
  5204. * Default value is 0.
  5205. */
  5206. LPFC_ATTR(delay_discovery, 0, 0, 1,
  5207. "Delay NPort discovery when Clean Address bit is cleared.");
  5208. /*
  5209. * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
  5210. * This value can be set to values between 64 and 4096. The default value
  5211. * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
  5212. * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
  5213. * Because of the additional overhead involved in setting up T10-DIF,
  5214. * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
  5215. * and will be limited to 512 if BlockGuard is enabled under SLI3.
  5216. */
  5217. static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
  5218. module_param(lpfc_sg_seg_cnt, uint, 0444);
  5219. MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
  5220. /**
  5221. * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
  5222. * configured for the adapter
  5223. * @dev: class converted to a Scsi_host structure.
  5224. * @attr: device attribute, not used.
  5225. * @buf: on return contains a string with the list sizes
  5226. *
  5227. * Returns: size of formatted string.
  5228. **/
  5229. static ssize_t
  5230. lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
  5231. char *buf)
  5232. {
  5233. struct Scsi_Host *shost = class_to_shost(dev);
  5234. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  5235. struct lpfc_hba *phba = vport->phba;
  5236. int len;
  5237. len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
  5238. phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
  5239. len += scnprintf(buf + len, PAGE_SIZE - len,
  5240. "Cfg: %d SCSI: %d NVME: %d\n",
  5241. phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
  5242. phba->cfg_nvme_seg_cnt);
  5243. return len;
  5244. }
  5245. static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
  5246. /**
  5247. * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
  5248. * @phba: lpfc_hba pointer.
  5249. * @val: contains the initial value
  5250. *
  5251. * Description:
  5252. * Validates the initial value is within range and assigns it to the
  5253. * adapter. If not in range, an error message is posted and the
  5254. * default value is assigned.
  5255. *
  5256. * Returns:
  5257. * zero if value is in range and is set
  5258. * -EINVAL if value was out of range
  5259. **/
  5260. static int
  5261. lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
  5262. {
  5263. if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
  5264. phba->cfg_sg_seg_cnt = val;
  5265. return 0;
  5266. }
  5267. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5268. "0409 lpfc_sg_seg_cnt attribute cannot be set to %d, "
  5269. "allowed range is [%d, %d]\n",
  5270. val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
  5271. phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
  5272. return -EINVAL;
  5273. }
  5274. /*
  5275. * lpfc_enable_mds_diags: Enable MDS Diagnostics
  5276. * 0 = MDS Diagnostics disabled (default)
  5277. * 1 = MDS Diagnostics enabled
  5278. * Value range is [0,1]. Default value is 0.
  5279. */
  5280. LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
  5281. /*
  5282. * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
  5283. * 0 = Disable firmware logging (default)
  5284. * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
  5285. * Value range [0..4]. Default value is 0
  5286. */
  5287. LPFC_ATTR(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
  5288. lpfc_param_show(ras_fwlog_buffsize);
  5289. static ssize_t
  5290. lpfc_ras_fwlog_buffsize_set(struct lpfc_hba *phba, uint val)
  5291. {
  5292. int ret = 0;
  5293. enum ras_state state;
  5294. if (!lpfc_rangecheck(val, 0, 4))
  5295. return -EINVAL;
  5296. if (phba->cfg_ras_fwlog_buffsize == val)
  5297. return 0;
  5298. if (phba->cfg_ras_fwlog_func != PCI_FUNC(phba->pcidev->devfn))
  5299. return -EINVAL;
  5300. spin_lock_irq(&phba->ras_fwlog_lock);
  5301. state = phba->ras_fwlog.state;
  5302. spin_unlock_irq(&phba->ras_fwlog_lock);
  5303. if (state == REG_INPROGRESS) {
  5304. lpfc_printf_log(phba, KERN_ERR, LOG_SLI, "6147 RAS Logging "
  5305. "registration is in progress\n");
  5306. return -EBUSY;
  5307. }
  5308. /* For disable logging: stop the logs and free the DMA.
  5309. * For ras_fwlog_buffsize size change we still need to free and
  5310. * reallocate the DMA in lpfc_sli4_ras_fwlog_init.
  5311. */
  5312. phba->cfg_ras_fwlog_buffsize = val;
  5313. if (state == ACTIVE) {
  5314. lpfc_ras_stop_fwlog(phba);
  5315. lpfc_sli4_ras_dma_free(phba);
  5316. }
  5317. lpfc_sli4_ras_init(phba);
  5318. if (phba->ras_fwlog.ras_enabled)
  5319. ret = lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
  5320. LPFC_RAS_ENABLE_LOGGING);
  5321. return ret;
  5322. }
  5323. lpfc_param_store(ras_fwlog_buffsize);
  5324. static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize);
  5325. /*
  5326. * lpfc_ras_fwlog_level: Firmware logging verbosity level
  5327. * Valid only if firmware logging is enabled
  5328. * 0(Least Verbosity) 4 (most verbosity)
  5329. * Value range is [0..4]. Default value is 0
  5330. */
  5331. LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
  5332. /*
  5333. * lpfc_ras_fwlog_func: Firmware logging enabled on function number
  5334. * Default function which has RAS support : 0
  5335. * Value Range is [0..3].
  5336. * FW logging is a global action and enablement is via a specific
  5337. * port.
  5338. */
  5339. LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 3, "Firmware Logging Enabled on Function");
  5340. /*
  5341. * lpfc_enable_bbcr: Enable BB Credit Recovery
  5342. * 0 = BB Credit Recovery disabled
  5343. * 1 = BB Credit Recovery enabled (default)
  5344. * Value range is [0,1]. Default value is 1.
  5345. */
  5346. LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
  5347. /* Signaling module parameters */
  5348. int lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
  5349. module_param(lpfc_fabric_cgn_frequency, int, 0444);
  5350. MODULE_PARM_DESC(lpfc_fabric_cgn_frequency, "Congestion signaling fabric freq");
  5351. unsigned char lpfc_acqe_cgn_frequency = 10; /* 10 sec default */
  5352. module_param(lpfc_acqe_cgn_frequency, byte, 0444);
  5353. MODULE_PARM_DESC(lpfc_acqe_cgn_frequency, "Congestion signaling ACQE freq");
  5354. int lpfc_use_cgn_signal = 1; /* 0 - only use FPINs, 1 - Use signals if avail */
  5355. module_param(lpfc_use_cgn_signal, int, 0444);
  5356. MODULE_PARM_DESC(lpfc_use_cgn_signal, "Use Congestion signaling if available");
  5357. /*
  5358. * lpfc_enable_dpp: Enable DPP on G7
  5359. * 0 = DPP on G7 disabled
  5360. * 1 = DPP on G7 enabled (default)
  5361. * Value range is [0,1]. Default value is 1.
  5362. */
  5363. LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
  5364. /*
  5365. * lpfc_enable_mi: Enable FDMI MIB
  5366. * 0 = disabled
  5367. * 1 = enabled (default)
  5368. * Value range is [0,1].
  5369. */
  5370. LPFC_ATTR_R(enable_mi, 1, 0, 1, "Enable MI");
  5371. /*
  5372. * lpfc_max_vmid: Maximum number of VMs to be tagged. This is valid only if
  5373. * either vmid_app_header or vmid_priority_tagging is enabled.
  5374. * 4 - 255 = vmid support enabled for 4-255 VMs
  5375. * Value range is [4,255].
  5376. */
  5377. LPFC_ATTR_R(max_vmid, LPFC_MIN_VMID, LPFC_MIN_VMID, LPFC_MAX_VMID,
  5378. "Maximum number of VMs supported");
  5379. /*
  5380. * lpfc_vmid_inactivity_timeout: Inactivity timeout duration in hours
  5381. * 0 = Timeout is disabled
  5382. * Value range is [0,24].
  5383. */
  5384. LPFC_ATTR_R(vmid_inactivity_timeout, 4, 0, 24,
  5385. "Inactivity timeout in hours");
  5386. /*
  5387. * lpfc_vmid_app_header: Enable App Header VMID support
  5388. * 0 = Support is disabled (default)
  5389. * 1 = Support is enabled
  5390. * Value range is [0,1].
  5391. */
  5392. LPFC_ATTR_R(vmid_app_header, LPFC_VMID_APP_HEADER_DISABLE,
  5393. LPFC_VMID_APP_HEADER_DISABLE, LPFC_VMID_APP_HEADER_ENABLE,
  5394. "Enable App Header VMID support");
  5395. /*
  5396. * lpfc_vmid_priority_tagging: Enable Priority Tagging VMID support
  5397. * 0 = Support is disabled (default)
  5398. * 1 = Allow supported targets only
  5399. * 2 = Allow all targets
  5400. * Value range is [0,2].
  5401. */
  5402. LPFC_ATTR_R(vmid_priority_tagging, LPFC_VMID_PRIO_TAG_DISABLE,
  5403. LPFC_VMID_PRIO_TAG_DISABLE,
  5404. LPFC_VMID_PRIO_TAG_ALL_TARGETS,
  5405. "Enable Priority Tagging VMID support");
  5406. static struct attribute *lpfc_hba_attrs[] = {
  5407. &dev_attr_nvme_info.attr,
  5408. &dev_attr_scsi_stat.attr,
  5409. &dev_attr_bg_info.attr,
  5410. &dev_attr_bg_guard_err.attr,
  5411. &dev_attr_bg_apptag_err.attr,
  5412. &dev_attr_bg_reftag_err.attr,
  5413. &dev_attr_info.attr,
  5414. &dev_attr_serialnum.attr,
  5415. &dev_attr_modeldesc.attr,
  5416. &dev_attr_modelname.attr,
  5417. &dev_attr_programtype.attr,
  5418. &dev_attr_portnum.attr,
  5419. &dev_attr_fwrev.attr,
  5420. &dev_attr_hdw.attr,
  5421. &dev_attr_option_rom_version.attr,
  5422. &dev_attr_link_state.attr,
  5423. &dev_attr_num_discovered_ports.attr,
  5424. &dev_attr_lpfc_drvr_version.attr,
  5425. &dev_attr_lpfc_enable_fip.attr,
  5426. &dev_attr_lpfc_temp_sensor.attr,
  5427. &dev_attr_lpfc_log_verbose.attr,
  5428. &dev_attr_lpfc_lun_queue_depth.attr,
  5429. &dev_attr_lpfc_tgt_queue_depth.attr,
  5430. &dev_attr_lpfc_hba_queue_depth.attr,
  5431. &dev_attr_lpfc_peer_port_login.attr,
  5432. &dev_attr_lpfc_nodev_tmo.attr,
  5433. &dev_attr_lpfc_devloss_tmo.attr,
  5434. &dev_attr_lpfc_enable_fc4_type.attr,
  5435. &dev_attr_lpfc_fcp_class.attr,
  5436. &dev_attr_lpfc_use_adisc.attr,
  5437. &dev_attr_lpfc_first_burst_size.attr,
  5438. &dev_attr_lpfc_ack0.attr,
  5439. &dev_attr_lpfc_xri_rebalancing.attr,
  5440. &dev_attr_lpfc_topology.attr,
  5441. &dev_attr_lpfc_scan_down.attr,
  5442. &dev_attr_lpfc_link_speed.attr,
  5443. &dev_attr_lpfc_fcp_io_sched.attr,
  5444. &dev_attr_lpfc_ns_query.attr,
  5445. &dev_attr_lpfc_fcp2_no_tgt_reset.attr,
  5446. &dev_attr_lpfc_cr_delay.attr,
  5447. &dev_attr_lpfc_cr_count.attr,
  5448. &dev_attr_lpfc_multi_ring_support.attr,
  5449. &dev_attr_lpfc_multi_ring_rctl.attr,
  5450. &dev_attr_lpfc_multi_ring_type.attr,
  5451. &dev_attr_lpfc_fdmi_on.attr,
  5452. &dev_attr_lpfc_enable_SmartSAN.attr,
  5453. &dev_attr_lpfc_max_luns.attr,
  5454. &dev_attr_lpfc_enable_npiv.attr,
  5455. &dev_attr_lpfc_fcf_failover_policy.attr,
  5456. &dev_attr_lpfc_enable_rrq.attr,
  5457. &dev_attr_lpfc_fcp_wait_abts_rsp.attr,
  5458. &dev_attr_nport_evt_cnt.attr,
  5459. &dev_attr_board_mode.attr,
  5460. &dev_attr_lpfc_xcvr_data.attr,
  5461. &dev_attr_max_vpi.attr,
  5462. &dev_attr_used_vpi.attr,
  5463. &dev_attr_max_rpi.attr,
  5464. &dev_attr_used_rpi.attr,
  5465. &dev_attr_max_xri.attr,
  5466. &dev_attr_used_xri.attr,
  5467. &dev_attr_npiv_info.attr,
  5468. &dev_attr_issue_reset.attr,
  5469. &dev_attr_lpfc_poll.attr,
  5470. &dev_attr_lpfc_poll_tmo.attr,
  5471. &dev_attr_lpfc_task_mgmt_tmo.attr,
  5472. &dev_attr_lpfc_use_msi.attr,
  5473. &dev_attr_lpfc_nvme_oas.attr,
  5474. &dev_attr_lpfc_nvme_embed_cmd.attr,
  5475. &dev_attr_lpfc_fcp_imax.attr,
  5476. &dev_attr_lpfc_force_rscn.attr,
  5477. &dev_attr_lpfc_cq_poll_threshold.attr,
  5478. &dev_attr_lpfc_cq_max_proc_limit.attr,
  5479. &dev_attr_lpfc_fcp_cpu_map.attr,
  5480. &dev_attr_lpfc_fcp_mq_threshold.attr,
  5481. &dev_attr_lpfc_hdw_queue.attr,
  5482. &dev_attr_lpfc_irq_chann.attr,
  5483. &dev_attr_lpfc_suppress_rsp.attr,
  5484. &dev_attr_lpfc_nvmet_mrq.attr,
  5485. &dev_attr_lpfc_nvmet_mrq_post.attr,
  5486. &dev_attr_lpfc_nvme_enable_fb.attr,
  5487. &dev_attr_lpfc_nvmet_fb_size.attr,
  5488. &dev_attr_lpfc_enable_bg.attr,
  5489. &dev_attr_lpfc_enable_hba_reset.attr,
  5490. &dev_attr_lpfc_enable_hba_heartbeat.attr,
  5491. &dev_attr_lpfc_EnableXLane.attr,
  5492. &dev_attr_lpfc_XLanePriority.attr,
  5493. &dev_attr_lpfc_xlane_lun.attr,
  5494. &dev_attr_lpfc_xlane_tgt.attr,
  5495. &dev_attr_lpfc_xlane_vpt.attr,
  5496. &dev_attr_lpfc_xlane_lun_state.attr,
  5497. &dev_attr_lpfc_xlane_lun_status.attr,
  5498. &dev_attr_lpfc_xlane_priority.attr,
  5499. &dev_attr_lpfc_sg_seg_cnt.attr,
  5500. &dev_attr_lpfc_max_scsicmpl_time.attr,
  5501. &dev_attr_lpfc_aer_support.attr,
  5502. &dev_attr_lpfc_aer_state_cleanup.attr,
  5503. &dev_attr_lpfc_sriov_nr_virtfn.attr,
  5504. &dev_attr_lpfc_req_fw_upgrade.attr,
  5505. &dev_attr_lpfc_suppress_link_up.attr,
  5506. &dev_attr_iocb_hw.attr,
  5507. &dev_attr_pls.attr,
  5508. &dev_attr_pt.attr,
  5509. &dev_attr_txq_hw.attr,
  5510. &dev_attr_txcmplq_hw.attr,
  5511. &dev_attr_lpfc_sriov_hw_max_virtfn.attr,
  5512. &dev_attr_protocol.attr,
  5513. &dev_attr_lpfc_xlane_supported.attr,
  5514. &dev_attr_lpfc_enable_mds_diags.attr,
  5515. &dev_attr_lpfc_ras_fwlog_buffsize.attr,
  5516. &dev_attr_lpfc_ras_fwlog_level.attr,
  5517. &dev_attr_lpfc_ras_fwlog_func.attr,
  5518. &dev_attr_lpfc_enable_bbcr.attr,
  5519. &dev_attr_lpfc_enable_dpp.attr,
  5520. &dev_attr_lpfc_enable_mi.attr,
  5521. &dev_attr_cmf_info.attr,
  5522. &dev_attr_lpfc_max_vmid.attr,
  5523. &dev_attr_lpfc_vmid_inactivity_timeout.attr,
  5524. &dev_attr_lpfc_vmid_app_header.attr,
  5525. &dev_attr_lpfc_vmid_priority_tagging.attr,
  5526. NULL,
  5527. };
  5528. static const struct attribute_group lpfc_hba_attr_group = {
  5529. .attrs = lpfc_hba_attrs
  5530. };
  5531. const struct attribute_group *lpfc_hba_groups[] = {
  5532. &lpfc_hba_attr_group,
  5533. NULL
  5534. };
  5535. static struct attribute *lpfc_vport_attrs[] = {
  5536. &dev_attr_info.attr,
  5537. &dev_attr_link_state.attr,
  5538. &dev_attr_num_discovered_ports.attr,
  5539. &dev_attr_lpfc_drvr_version.attr,
  5540. &dev_attr_lpfc_log_verbose.attr,
  5541. &dev_attr_lpfc_lun_queue_depth.attr,
  5542. &dev_attr_lpfc_tgt_queue_depth.attr,
  5543. &dev_attr_lpfc_nodev_tmo.attr,
  5544. &dev_attr_lpfc_devloss_tmo.attr,
  5545. &dev_attr_lpfc_hba_queue_depth.attr,
  5546. &dev_attr_lpfc_peer_port_login.attr,
  5547. &dev_attr_lpfc_restrict_login.attr,
  5548. &dev_attr_lpfc_fcp_class.attr,
  5549. &dev_attr_lpfc_use_adisc.attr,
  5550. &dev_attr_lpfc_first_burst_size.attr,
  5551. &dev_attr_lpfc_max_luns.attr,
  5552. &dev_attr_nport_evt_cnt.attr,
  5553. &dev_attr_npiv_info.attr,
  5554. &dev_attr_lpfc_enable_da_id.attr,
  5555. &dev_attr_lpfc_max_scsicmpl_time.attr,
  5556. &dev_attr_lpfc_static_vport.attr,
  5557. &dev_attr_cmf_info.attr,
  5558. NULL,
  5559. };
  5560. static const struct attribute_group lpfc_vport_attr_group = {
  5561. .attrs = lpfc_vport_attrs
  5562. };
  5563. const struct attribute_group *lpfc_vport_groups[] = {
  5564. &lpfc_vport_attr_group,
  5565. NULL
  5566. };
  5567. /**
  5568. * sysfs_ctlreg_write - Write method for writing to ctlreg
  5569. * @filp: open sysfs file
  5570. * @kobj: kernel kobject that contains the kernel class device.
  5571. * @bin_attr: kernel attributes passed to us.
  5572. * @buf: contains the data to be written to the adapter IOREG space.
  5573. * @off: offset into buffer to beginning of data.
  5574. * @count: bytes to transfer.
  5575. *
  5576. * Description:
  5577. * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
  5578. * Uses the adapter io control registers to send buf contents to the adapter.
  5579. *
  5580. * Returns:
  5581. * -ERANGE off and count combo out of range
  5582. * -EINVAL off, count or buff address invalid
  5583. * -EPERM adapter is offline
  5584. * value of count, buf contents written
  5585. **/
  5586. static ssize_t
  5587. sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
  5588. struct bin_attribute *bin_attr,
  5589. char *buf, loff_t off, size_t count)
  5590. {
  5591. size_t buf_off;
  5592. struct device *dev = container_of(kobj, struct device, kobj);
  5593. struct Scsi_Host *shost = class_to_shost(dev);
  5594. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  5595. struct lpfc_hba *phba = vport->phba;
  5596. if (phba->sli_rev >= LPFC_SLI_REV4)
  5597. return -EPERM;
  5598. if ((off + count) > FF_REG_AREA_SIZE)
  5599. return -ERANGE;
  5600. if (count <= LPFC_REG_WRITE_KEY_SIZE)
  5601. return 0;
  5602. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  5603. return -EINVAL;
  5604. /* This is to protect HBA registers from accidental writes. */
  5605. if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
  5606. return -EINVAL;
  5607. if (!test_bit(FC_OFFLINE_MODE, &vport->fc_flag))
  5608. return -EPERM;
  5609. spin_lock_irq(&phba->hbalock);
  5610. for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
  5611. buf_off += sizeof(uint32_t))
  5612. writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
  5613. phba->ctrl_regs_memmap_p + off + buf_off);
  5614. spin_unlock_irq(&phba->hbalock);
  5615. return count;
  5616. }
  5617. /**
  5618. * sysfs_ctlreg_read - Read method for reading from ctlreg
  5619. * @filp: open sysfs file
  5620. * @kobj: kernel kobject that contains the kernel class device.
  5621. * @bin_attr: kernel attributes passed to us.
  5622. * @buf: if successful contains the data from the adapter IOREG space.
  5623. * @off: offset into buffer to beginning of data.
  5624. * @count: bytes to transfer.
  5625. *
  5626. * Description:
  5627. * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
  5628. * Uses the adapter io control registers to read data into buf.
  5629. *
  5630. * Returns:
  5631. * -ERANGE off and count combo out of range
  5632. * -EINVAL off, count or buff address invalid
  5633. * value of count, buf contents read
  5634. **/
  5635. static ssize_t
  5636. sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
  5637. struct bin_attribute *bin_attr,
  5638. char *buf, loff_t off, size_t count)
  5639. {
  5640. size_t buf_off;
  5641. uint32_t * tmp_ptr;
  5642. struct device *dev = container_of(kobj, struct device, kobj);
  5643. struct Scsi_Host *shost = class_to_shost(dev);
  5644. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  5645. struct lpfc_hba *phba = vport->phba;
  5646. if (phba->sli_rev >= LPFC_SLI_REV4)
  5647. return -EPERM;
  5648. if (off > FF_REG_AREA_SIZE)
  5649. return -ERANGE;
  5650. if ((off + count) > FF_REG_AREA_SIZE)
  5651. count = FF_REG_AREA_SIZE - off;
  5652. if (count == 0) return 0;
  5653. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  5654. return -EINVAL;
  5655. spin_lock_irq(&phba->hbalock);
  5656. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
  5657. tmp_ptr = (uint32_t *)(buf + buf_off);
  5658. *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
  5659. }
  5660. spin_unlock_irq(&phba->hbalock);
  5661. return count;
  5662. }
  5663. static struct bin_attribute sysfs_ctlreg_attr = {
  5664. .attr = {
  5665. .name = "ctlreg",
  5666. .mode = S_IRUSR | S_IWUSR,
  5667. },
  5668. .size = 256,
  5669. .read = sysfs_ctlreg_read,
  5670. .write = sysfs_ctlreg_write,
  5671. };
  5672. /**
  5673. * sysfs_mbox_write - Write method for writing information via mbox
  5674. * @filp: open sysfs file
  5675. * @kobj: kernel kobject that contains the kernel class device.
  5676. * @bin_attr: kernel attributes passed to us.
  5677. * @buf: contains the data to be written to sysfs mbox.
  5678. * @off: offset into buffer to beginning of data.
  5679. * @count: bytes to transfer.
  5680. *
  5681. * Description:
  5682. * Deprecated function. All mailbox access from user space is performed via the
  5683. * bsg interface.
  5684. *
  5685. * Returns:
  5686. * -EPERM operation not permitted
  5687. **/
  5688. static ssize_t
  5689. sysfs_mbox_write(struct file *filp, struct kobject *kobj,
  5690. struct bin_attribute *bin_attr,
  5691. char *buf, loff_t off, size_t count)
  5692. {
  5693. return -EPERM;
  5694. }
  5695. /**
  5696. * sysfs_mbox_read - Read method for reading information via mbox
  5697. * @filp: open sysfs file
  5698. * @kobj: kernel kobject that contains the kernel class device.
  5699. * @bin_attr: kernel attributes passed to us.
  5700. * @buf: contains the data to be read from sysfs mbox.
  5701. * @off: offset into buffer to beginning of data.
  5702. * @count: bytes to transfer.
  5703. *
  5704. * Description:
  5705. * Deprecated function. All mailbox access from user space is performed via the
  5706. * bsg interface.
  5707. *
  5708. * Returns:
  5709. * -EPERM operation not permitted
  5710. **/
  5711. static ssize_t
  5712. sysfs_mbox_read(struct file *filp, struct kobject *kobj,
  5713. struct bin_attribute *bin_attr,
  5714. char *buf, loff_t off, size_t count)
  5715. {
  5716. return -EPERM;
  5717. }
  5718. static struct bin_attribute sysfs_mbox_attr = {
  5719. .attr = {
  5720. .name = "mbox",
  5721. .mode = S_IRUSR | S_IWUSR,
  5722. },
  5723. .size = MAILBOX_SYSFS_MAX,
  5724. .read = sysfs_mbox_read,
  5725. .write = sysfs_mbox_write,
  5726. };
  5727. /**
  5728. * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
  5729. * @vport: address of lpfc vport structure.
  5730. *
  5731. * Return codes:
  5732. * zero on success
  5733. * error return code from sysfs_create_bin_file()
  5734. **/
  5735. int
  5736. lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
  5737. {
  5738. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5739. int error;
  5740. /* Virtual ports do not need ctrl_reg and mbox */
  5741. if (vport->port_type == LPFC_NPIV_PORT)
  5742. return 0;
  5743. error = sysfs_create_bin_file(&shost->shost_dev.kobj,
  5744. &sysfs_ctlreg_attr);
  5745. if (error)
  5746. goto out;
  5747. error = sysfs_create_bin_file(&shost->shost_dev.kobj,
  5748. &sysfs_mbox_attr);
  5749. if (error)
  5750. goto out_remove_ctlreg_attr;
  5751. return 0;
  5752. out_remove_ctlreg_attr:
  5753. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
  5754. out:
  5755. return error;
  5756. }
  5757. /**
  5758. * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
  5759. * @vport: address of lpfc vport structure.
  5760. **/
  5761. void
  5762. lpfc_free_sysfs_attr(struct lpfc_vport *vport)
  5763. {
  5764. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5765. /* Virtual ports do not need ctrl_reg and mbox */
  5766. if (vport->port_type == LPFC_NPIV_PORT)
  5767. return;
  5768. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
  5769. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
  5770. }
  5771. /*
  5772. * Dynamic FC Host Attributes Support
  5773. */
  5774. /**
  5775. * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
  5776. * @shost: kernel scsi host pointer.
  5777. **/
  5778. static void
  5779. lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
  5780. {
  5781. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  5782. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  5783. sizeof fc_host_symbolic_name(shost));
  5784. }
  5785. /**
  5786. * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
  5787. * @shost: kernel scsi host pointer.
  5788. **/
  5789. static void
  5790. lpfc_get_host_port_id(struct Scsi_Host *shost)
  5791. {
  5792. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  5793. /* note: fc_myDID already in cpu endianness */
  5794. fc_host_port_id(shost) = vport->fc_myDID;
  5795. }
  5796. /**
  5797. * lpfc_get_host_port_type - Set the value of the scsi host port type
  5798. * @shost: kernel scsi host pointer.
  5799. **/
  5800. static void
  5801. lpfc_get_host_port_type(struct Scsi_Host *shost)
  5802. {
  5803. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  5804. struct lpfc_hba *phba = vport->phba;
  5805. if (vport->port_type == LPFC_NPIV_PORT) {
  5806. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  5807. } else if (lpfc_is_link_up(phba)) {
  5808. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  5809. if (test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))
  5810. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  5811. else
  5812. fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
  5813. } else {
  5814. if (test_bit(FC_FABRIC, &vport->fc_flag))
  5815. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  5816. else
  5817. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  5818. }
  5819. } else
  5820. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  5821. }
  5822. /**
  5823. * lpfc_get_host_port_state - Set the value of the scsi host port state
  5824. * @shost: kernel scsi host pointer.
  5825. **/
  5826. static void
  5827. lpfc_get_host_port_state(struct Scsi_Host *shost)
  5828. {
  5829. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  5830. struct lpfc_hba *phba = vport->phba;
  5831. if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag))
  5832. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  5833. else {
  5834. switch (phba->link_state) {
  5835. case LPFC_LINK_UNKNOWN:
  5836. case LPFC_LINK_DOWN:
  5837. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  5838. break;
  5839. case LPFC_LINK_UP:
  5840. case LPFC_CLEAR_LA:
  5841. case LPFC_HBA_READY:
  5842. /* Links up, reports port state accordingly */
  5843. if (vport->port_state < LPFC_VPORT_READY)
  5844. fc_host_port_state(shost) =
  5845. FC_PORTSTATE_BYPASSED;
  5846. else
  5847. fc_host_port_state(shost) =
  5848. FC_PORTSTATE_ONLINE;
  5849. break;
  5850. case LPFC_HBA_ERROR:
  5851. fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
  5852. break;
  5853. default:
  5854. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  5855. break;
  5856. }
  5857. }
  5858. }
  5859. /**
  5860. * lpfc_get_host_speed - Set the value of the scsi host speed
  5861. * @shost: kernel scsi host pointer.
  5862. **/
  5863. static void
  5864. lpfc_get_host_speed(struct Scsi_Host *shost)
  5865. {
  5866. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  5867. struct lpfc_hba *phba = vport->phba;
  5868. if ((lpfc_is_link_up(phba)) &&
  5869. !test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
  5870. switch(phba->fc_linkspeed) {
  5871. case LPFC_LINK_SPEED_1GHZ:
  5872. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  5873. break;
  5874. case LPFC_LINK_SPEED_2GHZ:
  5875. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  5876. break;
  5877. case LPFC_LINK_SPEED_4GHZ:
  5878. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  5879. break;
  5880. case LPFC_LINK_SPEED_8GHZ:
  5881. fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
  5882. break;
  5883. case LPFC_LINK_SPEED_10GHZ:
  5884. fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
  5885. break;
  5886. case LPFC_LINK_SPEED_16GHZ:
  5887. fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
  5888. break;
  5889. case LPFC_LINK_SPEED_32GHZ:
  5890. fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
  5891. break;
  5892. case LPFC_LINK_SPEED_64GHZ:
  5893. fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
  5894. break;
  5895. case LPFC_LINK_SPEED_128GHZ:
  5896. fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
  5897. break;
  5898. case LPFC_LINK_SPEED_256GHZ:
  5899. fc_host_speed(shost) = FC_PORTSPEED_256GBIT;
  5900. break;
  5901. default:
  5902. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  5903. break;
  5904. }
  5905. } else if (lpfc_is_link_up(phba) &&
  5906. test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
  5907. switch (phba->fc_linkspeed) {
  5908. case LPFC_ASYNC_LINK_SPEED_1GBPS:
  5909. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  5910. break;
  5911. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  5912. fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
  5913. break;
  5914. case LPFC_ASYNC_LINK_SPEED_20GBPS:
  5915. fc_host_speed(shost) = FC_PORTSPEED_20GBIT;
  5916. break;
  5917. case LPFC_ASYNC_LINK_SPEED_25GBPS:
  5918. fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
  5919. break;
  5920. case LPFC_ASYNC_LINK_SPEED_40GBPS:
  5921. fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
  5922. break;
  5923. case LPFC_ASYNC_LINK_SPEED_100GBPS:
  5924. fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
  5925. break;
  5926. default:
  5927. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  5928. break;
  5929. }
  5930. } else
  5931. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  5932. }
  5933. /**
  5934. * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
  5935. * @shost: kernel scsi host pointer.
  5936. **/
  5937. static void
  5938. lpfc_get_host_fabric_name (struct Scsi_Host *shost)
  5939. {
  5940. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  5941. struct lpfc_hba *phba = vport->phba;
  5942. u64 node_name;
  5943. if (vport->port_state > LPFC_FLOGI &&
  5944. (test_bit(FC_FABRIC, &vport->fc_flag) ||
  5945. (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
  5946. test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))))
  5947. node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
  5948. else
  5949. /* fabric is local port if there is no F/FL_Port */
  5950. node_name = 0;
  5951. fc_host_fabric_name(shost) = node_name;
  5952. }
  5953. /**
  5954. * lpfc_get_stats - Return statistical information about the adapter
  5955. * @shost: kernel scsi host pointer.
  5956. *
  5957. * Notes:
  5958. * NULL on error for link down, no mbox pool, sli2 active,
  5959. * management not allowed, memory allocation error, or mbox error.
  5960. *
  5961. * Returns:
  5962. * NULL for error
  5963. * address of the adapter host statistics
  5964. **/
  5965. static struct fc_host_statistics *
  5966. lpfc_get_stats(struct Scsi_Host *shost)
  5967. {
  5968. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  5969. struct lpfc_hba *phba = vport->phba;
  5970. struct lpfc_sli *psli = &phba->sli;
  5971. struct fc_host_statistics *hs = &phba->link_stats;
  5972. struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
  5973. LPFC_MBOXQ_t *pmboxq;
  5974. MAILBOX_t *pmb;
  5975. int rc = 0;
  5976. /*
  5977. * prevent udev from issuing mailbox commands until the port is
  5978. * configured.
  5979. */
  5980. if (phba->link_state < LPFC_LINK_DOWN ||
  5981. !phba->mbox_mem_pool ||
  5982. (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
  5983. return NULL;
  5984. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  5985. return NULL;
  5986. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5987. if (!pmboxq)
  5988. return NULL;
  5989. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  5990. pmb = &pmboxq->u.mb;
  5991. pmb->mbxCommand = MBX_READ_STATUS;
  5992. pmb->mbxOwner = OWN_HOST;
  5993. pmboxq->ctx_buf = NULL;
  5994. pmboxq->vport = vport;
  5995. if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
  5996. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  5997. if (rc != MBX_SUCCESS) {
  5998. mempool_free(pmboxq, phba->mbox_mem_pool);
  5999. return NULL;
  6000. }
  6001. } else {
  6002. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  6003. if (rc != MBX_SUCCESS) {
  6004. if (rc != MBX_TIMEOUT)
  6005. mempool_free(pmboxq, phba->mbox_mem_pool);
  6006. return NULL;
  6007. }
  6008. }
  6009. memset(hs, 0, sizeof (struct fc_host_statistics));
  6010. hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
  6011. hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
  6012. /*
  6013. * The MBX_READ_STATUS returns tx_k_bytes which has to be
  6014. * converted to words.
  6015. *
  6016. * Check if extended byte flag is set, to know when to collect upper
  6017. * bits of 64 bit wide statistics counter.
  6018. */
  6019. if (pmb->un.varRdStatus.xkb & RD_ST_XKB) {
  6020. hs->tx_words = (u64)
  6021. ((((u64)(pmb->un.varRdStatus.xmit_xkb &
  6022. RD_ST_XMIT_XKB_MASK) << 32) |
  6023. (u64)pmb->un.varRdStatus.xmitByteCnt) *
  6024. (u64)256);
  6025. hs->rx_words = (u64)
  6026. ((((u64)(pmb->un.varRdStatus.rcv_xkb &
  6027. RD_ST_RCV_XKB_MASK) << 32) |
  6028. (u64)pmb->un.varRdStatus.rcvByteCnt) *
  6029. (u64)256);
  6030. } else {
  6031. hs->tx_words = (uint64_t)
  6032. ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
  6033. * (uint64_t)256);
  6034. hs->rx_words = (uint64_t)
  6035. ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
  6036. * (uint64_t)256);
  6037. }
  6038. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  6039. pmb->mbxCommand = MBX_READ_LNK_STAT;
  6040. pmb->mbxOwner = OWN_HOST;
  6041. pmboxq->ctx_buf = NULL;
  6042. pmboxq->vport = vport;
  6043. if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
  6044. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  6045. if (rc != MBX_SUCCESS) {
  6046. mempool_free(pmboxq, phba->mbox_mem_pool);
  6047. return NULL;
  6048. }
  6049. } else {
  6050. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  6051. if (rc != MBX_SUCCESS) {
  6052. if (rc != MBX_TIMEOUT)
  6053. mempool_free(pmboxq, phba->mbox_mem_pool);
  6054. return NULL;
  6055. }
  6056. }
  6057. hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  6058. hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  6059. hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  6060. hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  6061. hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  6062. hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  6063. hs->error_frames = pmb->un.varRdLnk.crcCnt;
  6064. hs->cn_sig_warn = atomic64_read(&phba->cgn_acqe_stat.warn);
  6065. hs->cn_sig_alarm = atomic64_read(&phba->cgn_acqe_stat.alarm);
  6066. hs->link_failure_count -= lso->link_failure_count;
  6067. hs->loss_of_sync_count -= lso->loss_of_sync_count;
  6068. hs->loss_of_signal_count -= lso->loss_of_signal_count;
  6069. hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
  6070. hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
  6071. hs->invalid_crc_count -= lso->invalid_crc_count;
  6072. hs->error_frames -= lso->error_frames;
  6073. if (test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
  6074. hs->lip_count = -1;
  6075. hs->nos_count = (phba->link_events >> 1);
  6076. hs->nos_count -= lso->link_events;
  6077. } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  6078. hs->lip_count = (phba->fc_eventTag >> 1);
  6079. hs->lip_count -= lso->link_events;
  6080. hs->nos_count = -1;
  6081. } else {
  6082. hs->lip_count = -1;
  6083. hs->nos_count = (phba->fc_eventTag >> 1);
  6084. hs->nos_count -= lso->link_events;
  6085. }
  6086. hs->dumped_frames = -1;
  6087. hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
  6088. mempool_free(pmboxq, phba->mbox_mem_pool);
  6089. return hs;
  6090. }
  6091. /**
  6092. * lpfc_reset_stats - Copy the adapter link stats information
  6093. * @shost: kernel scsi host pointer.
  6094. **/
  6095. static void
  6096. lpfc_reset_stats(struct Scsi_Host *shost)
  6097. {
  6098. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  6099. struct lpfc_hba *phba = vport->phba;
  6100. struct lpfc_sli *psli = &phba->sli;
  6101. struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
  6102. LPFC_MBOXQ_t *pmboxq;
  6103. MAILBOX_t *pmb;
  6104. int rc = 0;
  6105. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  6106. return;
  6107. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6108. if (!pmboxq)
  6109. return;
  6110. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  6111. pmb = &pmboxq->u.mb;
  6112. pmb->mbxCommand = MBX_READ_STATUS;
  6113. pmb->mbxOwner = OWN_HOST;
  6114. pmb->un.varWords[0] = 0x1; /* reset request */
  6115. pmboxq->ctx_buf = NULL;
  6116. pmboxq->vport = vport;
  6117. if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
  6118. !(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6119. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  6120. if (rc != MBX_SUCCESS) {
  6121. mempool_free(pmboxq, phba->mbox_mem_pool);
  6122. return;
  6123. }
  6124. } else {
  6125. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  6126. if (rc != MBX_SUCCESS) {
  6127. if (rc != MBX_TIMEOUT)
  6128. mempool_free(pmboxq, phba->mbox_mem_pool);
  6129. return;
  6130. }
  6131. }
  6132. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  6133. pmb->mbxCommand = MBX_READ_LNK_STAT;
  6134. pmb->mbxOwner = OWN_HOST;
  6135. pmboxq->ctx_buf = NULL;
  6136. pmboxq->vport = vport;
  6137. if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
  6138. !(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6139. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  6140. if (rc != MBX_SUCCESS) {
  6141. mempool_free(pmboxq, phba->mbox_mem_pool);
  6142. return;
  6143. }
  6144. } else {
  6145. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  6146. if (rc != MBX_SUCCESS) {
  6147. if (rc != MBX_TIMEOUT)
  6148. mempool_free(pmboxq, phba->mbox_mem_pool);
  6149. return;
  6150. }
  6151. }
  6152. lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  6153. lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  6154. lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  6155. lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  6156. lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  6157. lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  6158. lso->error_frames = pmb->un.varRdLnk.crcCnt;
  6159. if (test_bit(HBA_FCOE_MODE, &phba->hba_flag))
  6160. lso->link_events = (phba->link_events >> 1);
  6161. else
  6162. lso->link_events = (phba->fc_eventTag >> 1);
  6163. atomic64_set(&phba->cgn_acqe_stat.warn, 0);
  6164. atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
  6165. memset(&shost_to_fc_host(shost)->fpin_stats, 0,
  6166. sizeof(shost_to_fc_host(shost)->fpin_stats));
  6167. psli->stats_start = ktime_get_seconds();
  6168. mempool_free(pmboxq, phba->mbox_mem_pool);
  6169. return;
  6170. }
  6171. /*
  6172. * The LPFC driver treats linkdown handling as target loss events so there
  6173. * are no sysfs handlers for link_down_tmo.
  6174. */
  6175. /**
  6176. * lpfc_get_node_by_target - Return the nodelist for a target
  6177. * @starget: kernel scsi target pointer.
  6178. *
  6179. * Returns:
  6180. * address of the node list if found
  6181. * NULL target not found
  6182. **/
  6183. static struct lpfc_nodelist *
  6184. lpfc_get_node_by_target(struct scsi_target *starget)
  6185. {
  6186. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  6187. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  6188. struct lpfc_nodelist *ndlp;
  6189. unsigned long iflags;
  6190. spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
  6191. /* Search for this, mapped, target ID */
  6192. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  6193. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
  6194. starget->id == ndlp->nlp_sid) {
  6195. spin_unlock_irqrestore(&vport->fc_nodes_list_lock,
  6196. iflags);
  6197. return ndlp;
  6198. }
  6199. }
  6200. spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
  6201. return NULL;
  6202. }
  6203. /**
  6204. * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
  6205. * @starget: kernel scsi target pointer.
  6206. **/
  6207. static void
  6208. lpfc_get_starget_port_id(struct scsi_target *starget)
  6209. {
  6210. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  6211. fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
  6212. }
  6213. /**
  6214. * lpfc_get_starget_node_name - Set the target node name
  6215. * @starget: kernel scsi target pointer.
  6216. *
  6217. * Description: Set the target node name to the ndlp node name wwn or zero.
  6218. **/
  6219. static void
  6220. lpfc_get_starget_node_name(struct scsi_target *starget)
  6221. {
  6222. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  6223. fc_starget_node_name(starget) =
  6224. ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
  6225. }
  6226. /**
  6227. * lpfc_get_starget_port_name - Set the target port name
  6228. * @starget: kernel scsi target pointer.
  6229. *
  6230. * Description: set the target port name to the ndlp port name wwn or zero.
  6231. **/
  6232. static void
  6233. lpfc_get_starget_port_name(struct scsi_target *starget)
  6234. {
  6235. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  6236. fc_starget_port_name(starget) =
  6237. ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
  6238. }
  6239. /**
  6240. * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
  6241. * @rport: fc rport address.
  6242. * @timeout: new value for dev loss tmo.
  6243. *
  6244. * Description:
  6245. * If timeout is non zero set the dev_loss_tmo to timeout, else set
  6246. * dev_loss_tmo to one.
  6247. **/
  6248. static void
  6249. lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  6250. {
  6251. struct lpfc_rport_data *rdata = rport->dd_data;
  6252. struct lpfc_nodelist *ndlp = rdata->pnode;
  6253. #if (IS_ENABLED(CONFIG_NVME_FC))
  6254. struct lpfc_nvme_rport *nrport = NULL;
  6255. #endif
  6256. if (timeout)
  6257. rport->dev_loss_tmo = timeout;
  6258. else
  6259. rport->dev_loss_tmo = 1;
  6260. if (!ndlp) {
  6261. dev_info(&rport->dev, "Cannot find remote node to "
  6262. "set rport dev loss tmo, port_id x%x\n",
  6263. rport->port_id);
  6264. return;
  6265. }
  6266. #if (IS_ENABLED(CONFIG_NVME_FC))
  6267. nrport = lpfc_ndlp_get_nrport(ndlp);
  6268. if (nrport && nrport->remoteport)
  6269. nvme_fc_set_remoteport_devloss(nrport->remoteport,
  6270. rport->dev_loss_tmo);
  6271. #endif
  6272. }
  6273. /*
  6274. * lpfc_rport_show_function - Return rport target information
  6275. *
  6276. * Description:
  6277. * Macro that uses field to generate a function with the name lpfc_show_rport_
  6278. *
  6279. * lpfc_show_rport_##field: returns the bytes formatted in buf
  6280. * @cdev: class converted to an fc_rport.
  6281. * @buf: on return contains the target_field or zero.
  6282. *
  6283. * Returns: size of formatted string.
  6284. **/
  6285. #define lpfc_rport_show_function(field, format_string, sz, cast) \
  6286. static ssize_t \
  6287. lpfc_show_rport_##field (struct device *dev, \
  6288. struct device_attribute *attr, \
  6289. char *buf) \
  6290. { \
  6291. struct fc_rport *rport = transport_class_to_rport(dev); \
  6292. struct lpfc_rport_data *rdata = rport->hostdata; \
  6293. return scnprintf(buf, sz, format_string, \
  6294. (rdata->target) ? cast rdata->target->field : 0); \
  6295. }
  6296. #define lpfc_rport_rd_attr(field, format_string, sz) \
  6297. lpfc_rport_show_function(field, format_string, sz, ) \
  6298. static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
  6299. /**
  6300. * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
  6301. * @fc_vport: The fc_vport who's symbolic name has been changed.
  6302. *
  6303. * Description:
  6304. * This function is called by the transport after the @fc_vport's symbolic name
  6305. * has been changed. This function re-registers the symbolic name with the
  6306. * switch to propagate the change into the fabric if the vport is active.
  6307. **/
  6308. static void
  6309. lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
  6310. {
  6311. struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
  6312. if (vport->port_state == LPFC_VPORT_READY)
  6313. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  6314. }
  6315. /**
  6316. * lpfc_hba_log_verbose_init - Set hba's log verbose level
  6317. * @phba: Pointer to lpfc_hba struct.
  6318. * @verbose: Verbose level to set.
  6319. *
  6320. * This function is called by the lpfc_get_cfgparam() routine to set the
  6321. * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
  6322. * log message according to the module's lpfc_log_verbose parameter setting
  6323. * before hba port or vport created.
  6324. **/
  6325. static void
  6326. lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
  6327. {
  6328. phba->cfg_log_verbose = verbose;
  6329. }
  6330. struct fc_function_template lpfc_transport_functions = {
  6331. /* fixed attributes the driver supports */
  6332. .show_host_node_name = 1,
  6333. .show_host_port_name = 1,
  6334. .show_host_supported_classes = 1,
  6335. .show_host_supported_fc4s = 1,
  6336. .show_host_supported_speeds = 1,
  6337. .show_host_maxframe_size = 1,
  6338. .get_host_symbolic_name = lpfc_get_host_symbolic_name,
  6339. .show_host_symbolic_name = 1,
  6340. /* dynamic attributes the driver supports */
  6341. .get_host_port_id = lpfc_get_host_port_id,
  6342. .show_host_port_id = 1,
  6343. .get_host_port_type = lpfc_get_host_port_type,
  6344. .show_host_port_type = 1,
  6345. .get_host_port_state = lpfc_get_host_port_state,
  6346. .show_host_port_state = 1,
  6347. /* active_fc4s is shown but doesn't change (thus no get function) */
  6348. .show_host_active_fc4s = 1,
  6349. .get_host_speed = lpfc_get_host_speed,
  6350. .show_host_speed = 1,
  6351. .get_host_fabric_name = lpfc_get_host_fabric_name,
  6352. .show_host_fabric_name = 1,
  6353. /*
  6354. * The LPFC driver treats linkdown handling as target loss events
  6355. * so there are no sysfs handlers for link_down_tmo.
  6356. */
  6357. .get_fc_host_stats = lpfc_get_stats,
  6358. .reset_fc_host_stats = lpfc_reset_stats,
  6359. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  6360. .show_rport_maxframe_size = 1,
  6361. .show_rport_supported_classes = 1,
  6362. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  6363. .show_rport_dev_loss_tmo = 1,
  6364. .get_starget_port_id = lpfc_get_starget_port_id,
  6365. .show_starget_port_id = 1,
  6366. .get_starget_node_name = lpfc_get_starget_node_name,
  6367. .show_starget_node_name = 1,
  6368. .get_starget_port_name = lpfc_get_starget_port_name,
  6369. .show_starget_port_name = 1,
  6370. .issue_fc_host_lip = lpfc_issue_lip,
  6371. .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
  6372. .terminate_rport_io = lpfc_terminate_rport_io,
  6373. .dd_fcvport_size = sizeof(struct lpfc_vport *),
  6374. .vport_disable = lpfc_vport_disable,
  6375. .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
  6376. .bsg_request = lpfc_bsg_request,
  6377. .bsg_timeout = lpfc_bsg_timeout,
  6378. };
  6379. struct fc_function_template lpfc_vport_transport_functions = {
  6380. /* fixed attributes the driver supports */
  6381. .show_host_node_name = 1,
  6382. .show_host_port_name = 1,
  6383. .show_host_supported_classes = 1,
  6384. .show_host_supported_fc4s = 1,
  6385. .show_host_supported_speeds = 1,
  6386. .show_host_maxframe_size = 1,
  6387. .get_host_symbolic_name = lpfc_get_host_symbolic_name,
  6388. .show_host_symbolic_name = 1,
  6389. /* dynamic attributes the driver supports */
  6390. .get_host_port_id = lpfc_get_host_port_id,
  6391. .show_host_port_id = 1,
  6392. .get_host_port_type = lpfc_get_host_port_type,
  6393. .show_host_port_type = 1,
  6394. .get_host_port_state = lpfc_get_host_port_state,
  6395. .show_host_port_state = 1,
  6396. /* active_fc4s is shown but doesn't change (thus no get function) */
  6397. .show_host_active_fc4s = 1,
  6398. .get_host_speed = lpfc_get_host_speed,
  6399. .show_host_speed = 1,
  6400. .get_host_fabric_name = lpfc_get_host_fabric_name,
  6401. .show_host_fabric_name = 1,
  6402. /*
  6403. * The LPFC driver treats linkdown handling as target loss events
  6404. * so there are no sysfs handlers for link_down_tmo.
  6405. */
  6406. .get_fc_host_stats = lpfc_get_stats,
  6407. .reset_fc_host_stats = lpfc_reset_stats,
  6408. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  6409. .show_rport_maxframe_size = 1,
  6410. .show_rport_supported_classes = 1,
  6411. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  6412. .show_rport_dev_loss_tmo = 1,
  6413. .get_starget_port_id = lpfc_get_starget_port_id,
  6414. .show_starget_port_id = 1,
  6415. .get_starget_node_name = lpfc_get_starget_node_name,
  6416. .show_starget_node_name = 1,
  6417. .get_starget_port_name = lpfc_get_starget_port_name,
  6418. .show_starget_port_name = 1,
  6419. .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
  6420. .terminate_rport_io = lpfc_terminate_rport_io,
  6421. .vport_disable = lpfc_vport_disable,
  6422. .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
  6423. };
  6424. /**
  6425. * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
  6426. * Mode
  6427. * @phba: lpfc_hba pointer.
  6428. **/
  6429. static void
  6430. lpfc_get_hba_function_mode(struct lpfc_hba *phba)
  6431. {
  6432. /* If the adapter supports FCoE mode */
  6433. switch (phba->pcidev->device) {
  6434. case PCI_DEVICE_ID_SKYHAWK:
  6435. case PCI_DEVICE_ID_SKYHAWK_VF:
  6436. case PCI_DEVICE_ID_LANCER_FCOE:
  6437. case PCI_DEVICE_ID_LANCER_FCOE_VF:
  6438. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  6439. case PCI_DEVICE_ID_TIGERSHARK:
  6440. case PCI_DEVICE_ID_TOMCAT:
  6441. set_bit(HBA_FCOE_MODE, &phba->hba_flag);
  6442. break;
  6443. default:
  6444. /* for others, clear the flag */
  6445. clear_bit(HBA_FCOE_MODE, &phba->hba_flag);
  6446. }
  6447. }
  6448. /**
  6449. * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
  6450. * @phba: lpfc_hba pointer.
  6451. **/
  6452. void
  6453. lpfc_get_cfgparam(struct lpfc_hba *phba)
  6454. {
  6455. lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
  6456. lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
  6457. lpfc_ns_query_init(phba, lpfc_ns_query);
  6458. lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
  6459. lpfc_cr_delay_init(phba, lpfc_cr_delay);
  6460. lpfc_cr_count_init(phba, lpfc_cr_count);
  6461. lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
  6462. lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
  6463. lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
  6464. lpfc_ack0_init(phba, lpfc_ack0);
  6465. lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
  6466. lpfc_topology_init(phba, lpfc_topology);
  6467. lpfc_link_speed_init(phba, lpfc_link_speed);
  6468. lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
  6469. lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
  6470. lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
  6471. lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
  6472. lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
  6473. lpfc_fcp_wait_abts_rsp_init(phba, lpfc_fcp_wait_abts_rsp);
  6474. lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
  6475. lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
  6476. lpfc_use_msi_init(phba, lpfc_use_msi);
  6477. lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
  6478. lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
  6479. lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
  6480. lpfc_force_rscn_init(phba, lpfc_force_rscn);
  6481. lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
  6482. lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
  6483. lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
  6484. lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
  6485. lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
  6486. lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
  6487. /* VMID Inits */
  6488. lpfc_max_vmid_init(phba, lpfc_max_vmid);
  6489. lpfc_vmid_inactivity_timeout_init(phba, lpfc_vmid_inactivity_timeout);
  6490. lpfc_vmid_app_header_init(phba, lpfc_vmid_app_header);
  6491. lpfc_vmid_priority_tagging_init(phba, lpfc_vmid_priority_tagging);
  6492. if (phba->sli_rev != LPFC_SLI_REV4)
  6493. phba->cfg_EnableXLane = 0;
  6494. lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
  6495. memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
  6496. memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
  6497. phba->cfg_oas_lun_state = 0;
  6498. phba->cfg_oas_lun_status = 0;
  6499. phba->cfg_oas_flags = 0;
  6500. phba->cfg_oas_priority = 0;
  6501. lpfc_enable_bg_init(phba, lpfc_enable_bg);
  6502. lpfc_prot_mask_init(phba, lpfc_prot_mask);
  6503. lpfc_prot_guard_init(phba, lpfc_prot_guard);
  6504. if (phba->sli_rev == LPFC_SLI_REV4)
  6505. phba->cfg_poll = 0;
  6506. else
  6507. phba->cfg_poll = lpfc_poll;
  6508. /* Get the function mode */
  6509. lpfc_get_hba_function_mode(phba);
  6510. /* BlockGuard allowed for FC only. */
  6511. if (phba->cfg_enable_bg && test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
  6512. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6513. "0581 BlockGuard feature not supported\n");
  6514. /* If set, clear the BlockGuard support param */
  6515. phba->cfg_enable_bg = 0;
  6516. } else if (phba->cfg_enable_bg) {
  6517. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  6518. }
  6519. lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
  6520. lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
  6521. lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
  6522. lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
  6523. /* Initialize first burst. Target vs Initiator are different. */
  6524. lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
  6525. lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
  6526. lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);
  6527. lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
  6528. lpfc_irq_chann_init(phba, lpfc_irq_chann);
  6529. lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
  6530. lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
  6531. lpfc_enable_mi_init(phba, lpfc_enable_mi);
  6532. phba->cgn_p.cgn_param_mode = LPFC_CFG_OFF;
  6533. phba->cmf_active_mode = LPFC_CFG_OFF;
  6534. if (lpfc_fabric_cgn_frequency > EDC_CG_SIGFREQ_CNT_MAX ||
  6535. lpfc_fabric_cgn_frequency < EDC_CG_SIGFREQ_CNT_MIN)
  6536. lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
  6537. if (phba->sli_rev != LPFC_SLI_REV4) {
  6538. /* NVME only supported on SLI4 */
  6539. phba->nvmet_support = 0;
  6540. phba->cfg_nvmet_mrq = 0;
  6541. phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
  6542. phba->cfg_enable_bbcr = 0;
  6543. phba->cfg_xri_rebalancing = 0;
  6544. } else {
  6545. /* We MUST have FCP support */
  6546. if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
  6547. phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
  6548. }
  6549. phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
  6550. phba->cfg_enable_pbde = 0;
  6551. /* A value of 0 means use the number of CPUs found in the system */
  6552. if (phba->cfg_hdw_queue == 0)
  6553. phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
  6554. if (phba->cfg_irq_chann == 0)
  6555. phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
  6556. if (phba->cfg_irq_chann > phba->cfg_hdw_queue &&
  6557. phba->sli_rev == LPFC_SLI_REV4)
  6558. phba->cfg_irq_chann = phba->cfg_hdw_queue;
  6559. lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
  6560. lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
  6561. lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
  6562. lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
  6563. lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
  6564. lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
  6565. lpfc_sli_mode_init(phba, lpfc_sli_mode);
  6566. lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
  6567. lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
  6568. lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
  6569. lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
  6570. return;
  6571. }
  6572. /**
  6573. * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
  6574. * dependencies between protocols and roles.
  6575. * @phba: lpfc_hba pointer.
  6576. **/
  6577. void
  6578. lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
  6579. {
  6580. int logit = 0;
  6581. if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu) {
  6582. phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
  6583. logit = 1;
  6584. }
  6585. if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu) {
  6586. phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
  6587. logit = 1;
  6588. }
  6589. if (phba->cfg_irq_chann > phba->cfg_hdw_queue) {
  6590. phba->cfg_irq_chann = phba->cfg_hdw_queue;
  6591. logit = 1;
  6592. }
  6593. if (logit)
  6594. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6595. "2006 Reducing Queues - CPU limitation: "
  6596. "IRQ %d HDWQ %d\n",
  6597. phba->cfg_irq_chann,
  6598. phba->cfg_hdw_queue);
  6599. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
  6600. phba->nvmet_support) {
  6601. phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
  6602. lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
  6603. "6013 %s x%x fb_size x%x, fb_max x%x\n",
  6604. "NVME Target PRLI ACC enable_fb ",
  6605. phba->cfg_nvme_enable_fb,
  6606. phba->cfg_nvmet_fb_size,
  6607. LPFC_NVMET_FB_SZ_MAX);
  6608. if (phba->cfg_nvme_enable_fb == 0)
  6609. phba->cfg_nvmet_fb_size = 0;
  6610. else {
  6611. if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
  6612. phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
  6613. }
  6614. if (!phba->cfg_nvmet_mrq)
  6615. phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
  6616. /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
  6617. if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {
  6618. phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
  6619. lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
  6620. "6018 Adjust lpfc_nvmet_mrq to %d\n",
  6621. phba->cfg_nvmet_mrq);
  6622. }
  6623. if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
  6624. phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
  6625. } else {
  6626. /* Not NVME Target mode. Turn off Target parameters. */
  6627. phba->nvmet_support = 0;
  6628. phba->cfg_nvmet_mrq = 0;
  6629. phba->cfg_nvmet_fb_size = 0;
  6630. }
  6631. }
  6632. /**
  6633. * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
  6634. * @vport: lpfc_vport pointer.
  6635. **/
  6636. void
  6637. lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
  6638. {
  6639. lpfc_log_verbose_init(vport, lpfc_log_verbose);
  6640. lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
  6641. lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
  6642. lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
  6643. lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
  6644. lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
  6645. lpfc_restrict_login_init(vport, lpfc_restrict_login);
  6646. lpfc_fcp_class_init(vport, lpfc_fcp_class);
  6647. lpfc_use_adisc_init(vport, lpfc_use_adisc);
  6648. lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
  6649. lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
  6650. lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
  6651. lpfc_max_luns_init(vport, lpfc_max_luns);
  6652. lpfc_scan_down_init(vport, lpfc_scan_down);
  6653. lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
  6654. return;
  6655. }