lpfc_attr.c 176 KB

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