lpfc_init.c 333 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2014 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/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/idr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/module.h>
  27. #include <linux/kthread.h>
  28. #include <linux/pci.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/ctype.h>
  31. #include <linux/aer.h>
  32. #include <linux/slab.h>
  33. #include <linux/firmware.h>
  34. #include <linux/miscdevice.h>
  35. #include <linux/percpu.h>
  36. #include <scsi/scsi.h>
  37. #include <scsi/scsi_device.h>
  38. #include <scsi/scsi_host.h>
  39. #include <scsi/scsi_transport_fc.h>
  40. #include "lpfc_hw4.h"
  41. #include "lpfc_hw.h"
  42. #include "lpfc_sli.h"
  43. #include "lpfc_sli4.h"
  44. #include "lpfc_nl.h"
  45. #include "lpfc_disc.h"
  46. #include "lpfc_scsi.h"
  47. #include "lpfc.h"
  48. #include "lpfc_logmsg.h"
  49. #include "lpfc_crtn.h"
  50. #include "lpfc_vport.h"
  51. #include "lpfc_version.h"
  52. char *_dump_buf_data;
  53. unsigned long _dump_buf_data_order;
  54. char *_dump_buf_dif;
  55. unsigned long _dump_buf_dif_order;
  56. spinlock_t _dump_buf_lock;
  57. /* Used when mapping IRQ vectors in a driver centric manner */
  58. uint16_t *lpfc_used_cpu;
  59. uint32_t lpfc_present_cpu;
  60. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  61. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  62. static int lpfc_sli4_queue_verify(struct lpfc_hba *);
  63. static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
  64. static int lpfc_setup_endian_order(struct lpfc_hba *);
  65. static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
  66. static void lpfc_free_els_sgl_list(struct lpfc_hba *);
  67. static void lpfc_init_sgl_list(struct lpfc_hba *);
  68. static int lpfc_init_active_sgl_array(struct lpfc_hba *);
  69. static void lpfc_free_active_sgl(struct lpfc_hba *);
  70. static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
  71. static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
  72. static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
  73. static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
  74. static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
  75. static void lpfc_sli4_disable_intr(struct lpfc_hba *);
  76. static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
  77. static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
  78. static struct scsi_transport_template *lpfc_transport_template = NULL;
  79. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  80. static DEFINE_IDR(lpfc_hba_index);
  81. /**
  82. * lpfc_config_port_prep - Perform lpfc initialization prior to config port
  83. * @phba: pointer to lpfc hba data structure.
  84. *
  85. * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
  86. * mailbox command. It retrieves the revision information from the HBA and
  87. * collects the Vital Product Data (VPD) about the HBA for preparing the
  88. * configuration of the HBA.
  89. *
  90. * Return codes:
  91. * 0 - success.
  92. * -ERESTART - requests the SLI layer to reset the HBA and try again.
  93. * Any other value - indicates an error.
  94. **/
  95. int
  96. lpfc_config_port_prep(struct lpfc_hba *phba)
  97. {
  98. lpfc_vpd_t *vp = &phba->vpd;
  99. int i = 0, rc;
  100. LPFC_MBOXQ_t *pmb;
  101. MAILBOX_t *mb;
  102. char *lpfc_vpd_data = NULL;
  103. uint16_t offset = 0;
  104. static char licensed[56] =
  105. "key unlock for use with gnu public licensed code only\0";
  106. static int init_key = 1;
  107. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  108. if (!pmb) {
  109. phba->link_state = LPFC_HBA_ERROR;
  110. return -ENOMEM;
  111. }
  112. mb = &pmb->u.mb;
  113. phba->link_state = LPFC_INIT_MBX_CMDS;
  114. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  115. if (init_key) {
  116. uint32_t *ptext = (uint32_t *) licensed;
  117. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  118. *ptext = cpu_to_be32(*ptext);
  119. init_key = 0;
  120. }
  121. lpfc_read_nv(phba, pmb);
  122. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  123. sizeof (mb->un.varRDnvp.rsvd3));
  124. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  125. sizeof (licensed));
  126. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  127. if (rc != MBX_SUCCESS) {
  128. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  129. "0324 Config Port initialization "
  130. "error, mbxCmd x%x READ_NVPARM, "
  131. "mbxStatus x%x\n",
  132. mb->mbxCommand, mb->mbxStatus);
  133. mempool_free(pmb, phba->mbox_mem_pool);
  134. return -ERESTART;
  135. }
  136. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  137. sizeof(phba->wwnn));
  138. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  139. sizeof(phba->wwpn));
  140. }
  141. phba->sli3_options = 0x0;
  142. /* Setup and issue mailbox READ REV command */
  143. lpfc_read_rev(phba, pmb);
  144. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  145. if (rc != MBX_SUCCESS) {
  146. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  147. "0439 Adapter failed to init, mbxCmd x%x "
  148. "READ_REV, mbxStatus x%x\n",
  149. mb->mbxCommand, mb->mbxStatus);
  150. mempool_free( pmb, phba->mbox_mem_pool);
  151. return -ERESTART;
  152. }
  153. /*
  154. * The value of rr must be 1 since the driver set the cv field to 1.
  155. * This setting requires the FW to set all revision fields.
  156. */
  157. if (mb->un.varRdRev.rr == 0) {
  158. vp->rev.rBit = 0;
  159. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  160. "0440 Adapter failed to init, READ_REV has "
  161. "missing revision information.\n");
  162. mempool_free(pmb, phba->mbox_mem_pool);
  163. return -ERESTART;
  164. }
  165. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
  166. mempool_free(pmb, phba->mbox_mem_pool);
  167. return -EINVAL;
  168. }
  169. /* Save information as VPD data */
  170. vp->rev.rBit = 1;
  171. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  172. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  173. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  174. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  175. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  176. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  177. vp->rev.smRev = mb->un.varRdRev.smRev;
  178. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  179. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  180. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  181. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  182. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  183. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  184. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  185. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  186. /* If the sli feature level is less then 9, we must
  187. * tear down all RPIs and VPIs on link down if NPIV
  188. * is enabled.
  189. */
  190. if (vp->rev.feaLevelHigh < 9)
  191. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  192. if (lpfc_is_LC_HBA(phba->pcidev->device))
  193. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  194. sizeof (phba->RandomData));
  195. /* Get adapter VPD information */
  196. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  197. if (!lpfc_vpd_data)
  198. goto out_free_mbox;
  199. do {
  200. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
  201. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  202. if (rc != MBX_SUCCESS) {
  203. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  204. "0441 VPD not present on adapter, "
  205. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  206. mb->mbxCommand, mb->mbxStatus);
  207. mb->un.varDmp.word_cnt = 0;
  208. }
  209. /* dump mem may return a zero when finished or we got a
  210. * mailbox error, either way we are done.
  211. */
  212. if (mb->un.varDmp.word_cnt == 0)
  213. break;
  214. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  215. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  216. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  217. lpfc_vpd_data + offset,
  218. mb->un.varDmp.word_cnt);
  219. offset += mb->un.varDmp.word_cnt;
  220. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  221. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  222. kfree(lpfc_vpd_data);
  223. out_free_mbox:
  224. mempool_free(pmb, phba->mbox_mem_pool);
  225. return 0;
  226. }
  227. /**
  228. * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
  229. * @phba: pointer to lpfc hba data structure.
  230. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  231. *
  232. * This is the completion handler for driver's configuring asynchronous event
  233. * mailbox command to the device. If the mailbox command returns successfully,
  234. * it will set internal async event support flag to 1; otherwise, it will
  235. * set internal async event support flag to 0.
  236. **/
  237. static void
  238. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  239. {
  240. if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
  241. phba->temp_sensor_support = 1;
  242. else
  243. phba->temp_sensor_support = 0;
  244. mempool_free(pmboxq, phba->mbox_mem_pool);
  245. return;
  246. }
  247. /**
  248. * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
  249. * @phba: pointer to lpfc hba data structure.
  250. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  251. *
  252. * This is the completion handler for dump mailbox command for getting
  253. * wake up parameters. When this command complete, the response contain
  254. * Option rom version of the HBA. This function translate the version number
  255. * into a human readable string and store it in OptionROMVersion.
  256. **/
  257. static void
  258. lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  259. {
  260. struct prog_id *prg;
  261. uint32_t prog_id_word;
  262. char dist = ' ';
  263. /* character array used for decoding dist type. */
  264. char dist_char[] = "nabx";
  265. if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
  266. mempool_free(pmboxq, phba->mbox_mem_pool);
  267. return;
  268. }
  269. prg = (struct prog_id *) &prog_id_word;
  270. /* word 7 contain option rom version */
  271. prog_id_word = pmboxq->u.mb.un.varWords[7];
  272. /* Decode the Option rom version word to a readable string */
  273. if (prg->dist < 4)
  274. dist = dist_char[prg->dist];
  275. if ((prg->dist == 3) && (prg->num == 0))
  276. snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
  277. prg->ver, prg->rev, prg->lev);
  278. else
  279. snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
  280. prg->ver, prg->rev, prg->lev,
  281. dist, prg->num);
  282. mempool_free(pmboxq, phba->mbox_mem_pool);
  283. return;
  284. }
  285. /**
  286. * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
  287. * cfg_soft_wwnn, cfg_soft_wwpn
  288. * @vport: pointer to lpfc vport data structure.
  289. *
  290. *
  291. * Return codes
  292. * None.
  293. **/
  294. void
  295. lpfc_update_vport_wwn(struct lpfc_vport *vport)
  296. {
  297. /* If the soft name exists then update it using the service params */
  298. if (vport->phba->cfg_soft_wwnn)
  299. u64_to_wwn(vport->phba->cfg_soft_wwnn,
  300. vport->fc_sparam.nodeName.u.wwn);
  301. if (vport->phba->cfg_soft_wwpn)
  302. u64_to_wwn(vport->phba->cfg_soft_wwpn,
  303. vport->fc_sparam.portName.u.wwn);
  304. /*
  305. * If the name is empty or there exists a soft name
  306. * then copy the service params name, otherwise use the fc name
  307. */
  308. if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
  309. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  310. sizeof(struct lpfc_name));
  311. else
  312. memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
  313. sizeof(struct lpfc_name));
  314. if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
  315. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  316. sizeof(struct lpfc_name));
  317. else
  318. memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
  319. sizeof(struct lpfc_name));
  320. }
  321. /**
  322. * lpfc_config_port_post - Perform lpfc initialization after config port
  323. * @phba: pointer to lpfc hba data structure.
  324. *
  325. * This routine will do LPFC initialization after the CONFIG_PORT mailbox
  326. * command call. It performs all internal resource and state setups on the
  327. * port: post IOCB buffers, enable appropriate host interrupt attentions,
  328. * ELS ring timers, etc.
  329. *
  330. * Return codes
  331. * 0 - success.
  332. * Any other value - error.
  333. **/
  334. int
  335. lpfc_config_port_post(struct lpfc_hba *phba)
  336. {
  337. struct lpfc_vport *vport = phba->pport;
  338. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  339. LPFC_MBOXQ_t *pmb;
  340. MAILBOX_t *mb;
  341. struct lpfc_dmabuf *mp;
  342. struct lpfc_sli *psli = &phba->sli;
  343. uint32_t status, timeout;
  344. int i, j;
  345. int rc;
  346. spin_lock_irq(&phba->hbalock);
  347. /*
  348. * If the Config port completed correctly the HBA is not
  349. * over heated any more.
  350. */
  351. if (phba->over_temp_state == HBA_OVER_TEMP)
  352. phba->over_temp_state = HBA_NORMAL_TEMP;
  353. spin_unlock_irq(&phba->hbalock);
  354. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  355. if (!pmb) {
  356. phba->link_state = LPFC_HBA_ERROR;
  357. return -ENOMEM;
  358. }
  359. mb = &pmb->u.mb;
  360. /* Get login parameters for NID. */
  361. rc = lpfc_read_sparam(phba, pmb, 0);
  362. if (rc) {
  363. mempool_free(pmb, phba->mbox_mem_pool);
  364. return -ENOMEM;
  365. }
  366. pmb->vport = vport;
  367. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  368. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  369. "0448 Adapter failed init, mbxCmd x%x "
  370. "READ_SPARM mbxStatus x%x\n",
  371. mb->mbxCommand, mb->mbxStatus);
  372. phba->link_state = LPFC_HBA_ERROR;
  373. mp = (struct lpfc_dmabuf *) pmb->context1;
  374. mempool_free(pmb, phba->mbox_mem_pool);
  375. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  376. kfree(mp);
  377. return -EIO;
  378. }
  379. mp = (struct lpfc_dmabuf *) pmb->context1;
  380. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  381. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  382. kfree(mp);
  383. pmb->context1 = NULL;
  384. lpfc_update_vport_wwn(vport);
  385. /* Update the fc_host data structures with new wwn. */
  386. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  387. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  388. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  389. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  390. /* This should be consolidated into parse_vpd ? - mr */
  391. if (phba->SerialNumber[0] == 0) {
  392. uint8_t *outptr;
  393. outptr = &vport->fc_nodename.u.s.IEEE[0];
  394. for (i = 0; i < 12; i++) {
  395. status = *outptr++;
  396. j = ((status & 0xf0) >> 4);
  397. if (j <= 9)
  398. phba->SerialNumber[i] =
  399. (char)((uint8_t) 0x30 + (uint8_t) j);
  400. else
  401. phba->SerialNumber[i] =
  402. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  403. i++;
  404. j = (status & 0xf);
  405. if (j <= 9)
  406. phba->SerialNumber[i] =
  407. (char)((uint8_t) 0x30 + (uint8_t) j);
  408. else
  409. phba->SerialNumber[i] =
  410. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  411. }
  412. }
  413. lpfc_read_config(phba, pmb);
  414. pmb->vport = vport;
  415. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  416. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  417. "0453 Adapter failed to init, mbxCmd x%x "
  418. "READ_CONFIG, mbxStatus x%x\n",
  419. mb->mbxCommand, mb->mbxStatus);
  420. phba->link_state = LPFC_HBA_ERROR;
  421. mempool_free( pmb, phba->mbox_mem_pool);
  422. return -EIO;
  423. }
  424. /* Check if the port is disabled */
  425. lpfc_sli_read_link_ste(phba);
  426. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  427. i = (mb->un.varRdConfig.max_xri + 1);
  428. if (phba->cfg_hba_queue_depth > i) {
  429. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  430. "3359 HBA queue depth changed from %d to %d\n",
  431. phba->cfg_hba_queue_depth, i);
  432. phba->cfg_hba_queue_depth = i;
  433. }
  434. /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
  435. i = (mb->un.varRdConfig.max_xri >> 3);
  436. if (phba->pport->cfg_lun_queue_depth > i) {
  437. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  438. "3360 LUN queue depth changed from %d to %d\n",
  439. phba->pport->cfg_lun_queue_depth, i);
  440. phba->pport->cfg_lun_queue_depth = i;
  441. }
  442. phba->lmt = mb->un.varRdConfig.lmt;
  443. /* Get the default values for Model Name and Description */
  444. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  445. phba->link_state = LPFC_LINK_DOWN;
  446. /* Only process IOCBs on ELS ring till hba_state is READY */
  447. if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr)
  448. psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
  449. if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr)
  450. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  451. if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr)
  452. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  453. /* Post receive buffers for desired rings */
  454. if (phba->sli_rev != 3)
  455. lpfc_post_rcv_buf(phba);
  456. /*
  457. * Configure HBA MSI-X attention conditions to messages if MSI-X mode
  458. */
  459. if (phba->intr_type == MSIX) {
  460. rc = lpfc_config_msi(phba, pmb);
  461. if (rc) {
  462. mempool_free(pmb, phba->mbox_mem_pool);
  463. return -EIO;
  464. }
  465. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  466. if (rc != MBX_SUCCESS) {
  467. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  468. "0352 Config MSI mailbox command "
  469. "failed, mbxCmd x%x, mbxStatus x%x\n",
  470. pmb->u.mb.mbxCommand,
  471. pmb->u.mb.mbxStatus);
  472. mempool_free(pmb, phba->mbox_mem_pool);
  473. return -EIO;
  474. }
  475. }
  476. spin_lock_irq(&phba->hbalock);
  477. /* Initialize ERATT handling flag */
  478. phba->hba_flag &= ~HBA_ERATT_HANDLED;
  479. /* Enable appropriate host interrupts */
  480. if (lpfc_readl(phba->HCregaddr, &status)) {
  481. spin_unlock_irq(&phba->hbalock);
  482. return -EIO;
  483. }
  484. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  485. if (psli->num_rings > 0)
  486. status |= HC_R0INT_ENA;
  487. if (psli->num_rings > 1)
  488. status |= HC_R1INT_ENA;
  489. if (psli->num_rings > 2)
  490. status |= HC_R2INT_ENA;
  491. if (psli->num_rings > 3)
  492. status |= HC_R3INT_ENA;
  493. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  494. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  495. status &= ~(HC_R0INT_ENA);
  496. writel(status, phba->HCregaddr);
  497. readl(phba->HCregaddr); /* flush */
  498. spin_unlock_irq(&phba->hbalock);
  499. /* Set up ring-0 (ELS) timer */
  500. timeout = phba->fc_ratov * 2;
  501. mod_timer(&vport->els_tmofunc,
  502. jiffies + msecs_to_jiffies(1000 * timeout));
  503. /* Set up heart beat (HB) timer */
  504. mod_timer(&phba->hb_tmofunc,
  505. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  506. phba->hb_outstanding = 0;
  507. phba->last_completion_time = jiffies;
  508. /* Set up error attention (ERATT) polling timer */
  509. mod_timer(&phba->eratt_poll,
  510. jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
  511. if (phba->hba_flag & LINK_DISABLED) {
  512. lpfc_printf_log(phba,
  513. KERN_ERR, LOG_INIT,
  514. "2598 Adapter Link is disabled.\n");
  515. lpfc_down_link(phba, pmb);
  516. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  517. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  518. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  519. lpfc_printf_log(phba,
  520. KERN_ERR, LOG_INIT,
  521. "2599 Adapter failed to issue DOWN_LINK"
  522. " mbox command rc 0x%x\n", rc);
  523. mempool_free(pmb, phba->mbox_mem_pool);
  524. return -EIO;
  525. }
  526. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  527. mempool_free(pmb, phba->mbox_mem_pool);
  528. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  529. if (rc)
  530. return rc;
  531. }
  532. /* MBOX buffer will be freed in mbox compl */
  533. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  534. if (!pmb) {
  535. phba->link_state = LPFC_HBA_ERROR;
  536. return -ENOMEM;
  537. }
  538. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  539. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  540. pmb->vport = phba->pport;
  541. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  542. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  543. lpfc_printf_log(phba,
  544. KERN_ERR,
  545. LOG_INIT,
  546. "0456 Adapter failed to issue "
  547. "ASYNCEVT_ENABLE mbox status x%x\n",
  548. rc);
  549. mempool_free(pmb, phba->mbox_mem_pool);
  550. }
  551. /* Get Option rom version */
  552. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  553. if (!pmb) {
  554. phba->link_state = LPFC_HBA_ERROR;
  555. return -ENOMEM;
  556. }
  557. lpfc_dump_wakeup_param(phba, pmb);
  558. pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
  559. pmb->vport = phba->pport;
  560. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  561. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  562. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
  563. "to get Option ROM version status x%x\n", rc);
  564. mempool_free(pmb, phba->mbox_mem_pool);
  565. }
  566. return 0;
  567. }
  568. /**
  569. * lpfc_hba_init_link - Initialize the FC link
  570. * @phba: pointer to lpfc hba data structure.
  571. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  572. *
  573. * This routine will issue the INIT_LINK mailbox command call.
  574. * It is available to other drivers through the lpfc_hba data
  575. * structure for use as a delayed link up mechanism with the
  576. * module parameter lpfc_suppress_link_up.
  577. *
  578. * Return code
  579. * 0 - success
  580. * Any other value - error
  581. **/
  582. static int
  583. lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
  584. {
  585. return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
  586. }
  587. /**
  588. * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
  589. * @phba: pointer to lpfc hba data structure.
  590. * @fc_topology: desired fc topology.
  591. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  592. *
  593. * This routine will issue the INIT_LINK mailbox command call.
  594. * It is available to other drivers through the lpfc_hba data
  595. * structure for use as a delayed link up mechanism with the
  596. * module parameter lpfc_suppress_link_up.
  597. *
  598. * Return code
  599. * 0 - success
  600. * Any other value - error
  601. **/
  602. int
  603. lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
  604. uint32_t flag)
  605. {
  606. struct lpfc_vport *vport = phba->pport;
  607. LPFC_MBOXQ_t *pmb;
  608. MAILBOX_t *mb;
  609. int rc;
  610. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  611. if (!pmb) {
  612. phba->link_state = LPFC_HBA_ERROR;
  613. return -ENOMEM;
  614. }
  615. mb = &pmb->u.mb;
  616. pmb->vport = vport;
  617. if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
  618. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
  619. !(phba->lmt & LMT_1Gb)) ||
  620. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
  621. !(phba->lmt & LMT_2Gb)) ||
  622. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
  623. !(phba->lmt & LMT_4Gb)) ||
  624. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
  625. !(phba->lmt & LMT_8Gb)) ||
  626. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
  627. !(phba->lmt & LMT_10Gb)) ||
  628. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
  629. !(phba->lmt & LMT_16Gb))) {
  630. /* Reset link speed to auto */
  631. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  632. "1302 Invalid speed for this board:%d "
  633. "Reset link speed to auto.\n",
  634. phba->cfg_link_speed);
  635. phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
  636. }
  637. lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
  638. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  639. if (phba->sli_rev < LPFC_SLI_REV4)
  640. lpfc_set_loopback_flag(phba);
  641. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  642. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  643. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  644. "0498 Adapter failed to init, mbxCmd x%x "
  645. "INIT_LINK, mbxStatus x%x\n",
  646. mb->mbxCommand, mb->mbxStatus);
  647. if (phba->sli_rev <= LPFC_SLI_REV3) {
  648. /* Clear all interrupt enable conditions */
  649. writel(0, phba->HCregaddr);
  650. readl(phba->HCregaddr); /* flush */
  651. /* Clear all pending interrupts */
  652. writel(0xffffffff, phba->HAregaddr);
  653. readl(phba->HAregaddr); /* flush */
  654. }
  655. phba->link_state = LPFC_HBA_ERROR;
  656. if (rc != MBX_BUSY || flag == MBX_POLL)
  657. mempool_free(pmb, phba->mbox_mem_pool);
  658. return -EIO;
  659. }
  660. phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
  661. if (flag == MBX_POLL)
  662. mempool_free(pmb, phba->mbox_mem_pool);
  663. return 0;
  664. }
  665. /**
  666. * lpfc_hba_down_link - this routine downs the FC link
  667. * @phba: pointer to lpfc hba data structure.
  668. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  669. *
  670. * This routine will issue the DOWN_LINK mailbox command call.
  671. * It is available to other drivers through the lpfc_hba data
  672. * structure for use to stop the link.
  673. *
  674. * Return code
  675. * 0 - success
  676. * Any other value - error
  677. **/
  678. static int
  679. lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
  680. {
  681. LPFC_MBOXQ_t *pmb;
  682. int rc;
  683. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  684. if (!pmb) {
  685. phba->link_state = LPFC_HBA_ERROR;
  686. return -ENOMEM;
  687. }
  688. lpfc_printf_log(phba,
  689. KERN_ERR, LOG_INIT,
  690. "0491 Adapter Link is disabled.\n");
  691. lpfc_down_link(phba, pmb);
  692. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  693. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  694. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  695. lpfc_printf_log(phba,
  696. KERN_ERR, LOG_INIT,
  697. "2522 Adapter failed to issue DOWN_LINK"
  698. " mbox command rc 0x%x\n", rc);
  699. mempool_free(pmb, phba->mbox_mem_pool);
  700. return -EIO;
  701. }
  702. if (flag == MBX_POLL)
  703. mempool_free(pmb, phba->mbox_mem_pool);
  704. return 0;
  705. }
  706. /**
  707. * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
  708. * @phba: pointer to lpfc HBA data structure.
  709. *
  710. * This routine will do LPFC uninitialization before the HBA is reset when
  711. * bringing down the SLI Layer.
  712. *
  713. * Return codes
  714. * 0 - success.
  715. * Any other value - error.
  716. **/
  717. int
  718. lpfc_hba_down_prep(struct lpfc_hba *phba)
  719. {
  720. struct lpfc_vport **vports;
  721. int i;
  722. if (phba->sli_rev <= LPFC_SLI_REV3) {
  723. /* Disable interrupts */
  724. writel(0, phba->HCregaddr);
  725. readl(phba->HCregaddr); /* flush */
  726. }
  727. if (phba->pport->load_flag & FC_UNLOADING)
  728. lpfc_cleanup_discovery_resources(phba->pport);
  729. else {
  730. vports = lpfc_create_vport_work_array(phba);
  731. if (vports != NULL)
  732. for (i = 0; i <= phba->max_vports &&
  733. vports[i] != NULL; i++)
  734. lpfc_cleanup_discovery_resources(vports[i]);
  735. lpfc_destroy_vport_work_array(phba, vports);
  736. }
  737. return 0;
  738. }
  739. /**
  740. * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
  741. * rspiocb which got deferred
  742. *
  743. * @phba: pointer to lpfc HBA data structure.
  744. *
  745. * This routine will cleanup completed slow path events after HBA is reset
  746. * when bringing down the SLI Layer.
  747. *
  748. *
  749. * Return codes
  750. * void.
  751. **/
  752. static void
  753. lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
  754. {
  755. struct lpfc_iocbq *rspiocbq;
  756. struct hbq_dmabuf *dmabuf;
  757. struct lpfc_cq_event *cq_event;
  758. spin_lock_irq(&phba->hbalock);
  759. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  760. spin_unlock_irq(&phba->hbalock);
  761. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  762. /* Get the response iocb from the head of work queue */
  763. spin_lock_irq(&phba->hbalock);
  764. list_remove_head(&phba->sli4_hba.sp_queue_event,
  765. cq_event, struct lpfc_cq_event, list);
  766. spin_unlock_irq(&phba->hbalock);
  767. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  768. case CQE_CODE_COMPL_WQE:
  769. rspiocbq = container_of(cq_event, struct lpfc_iocbq,
  770. cq_event);
  771. lpfc_sli_release_iocbq(phba, rspiocbq);
  772. break;
  773. case CQE_CODE_RECEIVE:
  774. case CQE_CODE_RECEIVE_V1:
  775. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  776. cq_event);
  777. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  778. }
  779. }
  780. }
  781. /**
  782. * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
  783. * @phba: pointer to lpfc HBA data structure.
  784. *
  785. * This routine will cleanup posted ELS buffers after the HBA is reset
  786. * when bringing down the SLI Layer.
  787. *
  788. *
  789. * Return codes
  790. * void.
  791. **/
  792. static void
  793. lpfc_hba_free_post_buf(struct lpfc_hba *phba)
  794. {
  795. struct lpfc_sli *psli = &phba->sli;
  796. struct lpfc_sli_ring *pring;
  797. struct lpfc_dmabuf *mp, *next_mp;
  798. LIST_HEAD(buflist);
  799. int count;
  800. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  801. lpfc_sli_hbqbuf_free_all(phba);
  802. else {
  803. /* Cleanup preposted buffers on the ELS ring */
  804. pring = &psli->ring[LPFC_ELS_RING];
  805. spin_lock_irq(&phba->hbalock);
  806. list_splice_init(&pring->postbufq, &buflist);
  807. spin_unlock_irq(&phba->hbalock);
  808. count = 0;
  809. list_for_each_entry_safe(mp, next_mp, &buflist, list) {
  810. list_del(&mp->list);
  811. count++;
  812. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  813. kfree(mp);
  814. }
  815. spin_lock_irq(&phba->hbalock);
  816. pring->postbufq_cnt -= count;
  817. spin_unlock_irq(&phba->hbalock);
  818. }
  819. }
  820. /**
  821. * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
  822. * @phba: pointer to lpfc HBA data structure.
  823. *
  824. * This routine will cleanup the txcmplq after the HBA is reset when bringing
  825. * down the SLI Layer.
  826. *
  827. * Return codes
  828. * void
  829. **/
  830. static void
  831. lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
  832. {
  833. struct lpfc_sli *psli = &phba->sli;
  834. struct lpfc_sli_ring *pring;
  835. LIST_HEAD(completions);
  836. int i;
  837. for (i = 0; i < psli->num_rings; i++) {
  838. pring = &psli->ring[i];
  839. if (phba->sli_rev >= LPFC_SLI_REV4)
  840. spin_lock_irq(&pring->ring_lock);
  841. else
  842. spin_lock_irq(&phba->hbalock);
  843. /* At this point in time the HBA is either reset or DOA. Either
  844. * way, nothing should be on txcmplq as it will NEVER complete.
  845. */
  846. list_splice_init(&pring->txcmplq, &completions);
  847. pring->txcmplq_cnt = 0;
  848. if (phba->sli_rev >= LPFC_SLI_REV4)
  849. spin_unlock_irq(&pring->ring_lock);
  850. else
  851. spin_unlock_irq(&phba->hbalock);
  852. /* Cancel all the IOCBs from the completions list */
  853. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  854. IOERR_SLI_ABORTED);
  855. lpfc_sli_abort_iocb_ring(phba, pring);
  856. }
  857. }
  858. /**
  859. * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
  860. int i;
  861. * @phba: pointer to lpfc HBA data structure.
  862. *
  863. * This routine will do uninitialization after the HBA is reset when bring
  864. * down the SLI Layer.
  865. *
  866. * Return codes
  867. * 0 - success.
  868. * Any other value - error.
  869. **/
  870. static int
  871. lpfc_hba_down_post_s3(struct lpfc_hba *phba)
  872. {
  873. lpfc_hba_free_post_buf(phba);
  874. lpfc_hba_clean_txcmplq(phba);
  875. return 0;
  876. }
  877. /**
  878. * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
  879. * @phba: pointer to lpfc HBA data structure.
  880. *
  881. * This routine will do uninitialization after the HBA is reset when bring
  882. * down the SLI Layer.
  883. *
  884. * Return codes
  885. * 0 - success.
  886. * Any other value - error.
  887. **/
  888. static int
  889. lpfc_hba_down_post_s4(struct lpfc_hba *phba)
  890. {
  891. struct lpfc_scsi_buf *psb, *psb_next;
  892. LIST_HEAD(aborts);
  893. unsigned long iflag = 0;
  894. struct lpfc_sglq *sglq_entry = NULL;
  895. struct lpfc_sli *psli = &phba->sli;
  896. struct lpfc_sli_ring *pring;
  897. lpfc_hba_free_post_buf(phba);
  898. lpfc_hba_clean_txcmplq(phba);
  899. pring = &psli->ring[LPFC_ELS_RING];
  900. /* At this point in time the HBA is either reset or DOA. Either
  901. * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
  902. * on the lpfc_sgl_list so that it can either be freed if the
  903. * driver is unloading or reposted if the driver is restarting
  904. * the port.
  905. */
  906. spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
  907. /* scsl_buf_list */
  908. /* abts_sgl_list_lock required because worker thread uses this
  909. * list.
  910. */
  911. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  912. list_for_each_entry(sglq_entry,
  913. &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
  914. sglq_entry->state = SGL_FREED;
  915. spin_lock(&pring->ring_lock);
  916. list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
  917. &phba->sli4_hba.lpfc_sgl_list);
  918. spin_unlock(&pring->ring_lock);
  919. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  920. /* abts_scsi_buf_list_lock required because worker thread uses this
  921. * list.
  922. */
  923. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  924. list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
  925. &aborts);
  926. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  927. spin_unlock_irq(&phba->hbalock);
  928. list_for_each_entry_safe(psb, psb_next, &aborts, list) {
  929. psb->pCmd = NULL;
  930. psb->status = IOSTAT_SUCCESS;
  931. }
  932. spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
  933. list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
  934. spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
  935. lpfc_sli4_free_sp_events(phba);
  936. return 0;
  937. }
  938. /**
  939. * lpfc_hba_down_post - Wrapper func for hba down post routine
  940. * @phba: pointer to lpfc HBA data structure.
  941. *
  942. * This routine wraps the actual SLI3 or SLI4 routine for performing
  943. * uninitialization after the HBA is reset when bring down the SLI Layer.
  944. *
  945. * Return codes
  946. * 0 - success.
  947. * Any other value - error.
  948. **/
  949. int
  950. lpfc_hba_down_post(struct lpfc_hba *phba)
  951. {
  952. return (*phba->lpfc_hba_down_post)(phba);
  953. }
  954. /**
  955. * lpfc_hb_timeout - The HBA-timer timeout handler
  956. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  957. *
  958. * This is the HBA-timer timeout handler registered to the lpfc driver. When
  959. * this timer fires, a HBA timeout event shall be posted to the lpfc driver
  960. * work-port-events bitmap and the worker thread is notified. This timeout
  961. * event will be used by the worker thread to invoke the actual timeout
  962. * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
  963. * be performed in the timeout handler and the HBA timeout event bit shall
  964. * be cleared by the worker thread after it has taken the event bitmap out.
  965. **/
  966. static void
  967. lpfc_hb_timeout(unsigned long ptr)
  968. {
  969. struct lpfc_hba *phba;
  970. uint32_t tmo_posted;
  971. unsigned long iflag;
  972. phba = (struct lpfc_hba *)ptr;
  973. /* Check for heart beat timeout conditions */
  974. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  975. tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
  976. if (!tmo_posted)
  977. phba->pport->work_port_events |= WORKER_HB_TMO;
  978. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  979. /* Tell the worker thread there is work to do */
  980. if (!tmo_posted)
  981. lpfc_worker_wake_up(phba);
  982. return;
  983. }
  984. /**
  985. * lpfc_rrq_timeout - The RRQ-timer timeout handler
  986. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  987. *
  988. * This is the RRQ-timer timeout handler registered to the lpfc driver. When
  989. * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
  990. * work-port-events bitmap and the worker thread is notified. This timeout
  991. * event will be used by the worker thread to invoke the actual timeout
  992. * handler routine, lpfc_rrq_handler. Any periodical operations will
  993. * be performed in the timeout handler and the RRQ timeout event bit shall
  994. * be cleared by the worker thread after it has taken the event bitmap out.
  995. **/
  996. static void
  997. lpfc_rrq_timeout(unsigned long ptr)
  998. {
  999. struct lpfc_hba *phba;
  1000. unsigned long iflag;
  1001. phba = (struct lpfc_hba *)ptr;
  1002. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  1003. if (!(phba->pport->load_flag & FC_UNLOADING))
  1004. phba->hba_flag |= HBA_RRQ_ACTIVE;
  1005. else
  1006. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  1007. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  1008. if (!(phba->pport->load_flag & FC_UNLOADING))
  1009. lpfc_worker_wake_up(phba);
  1010. }
  1011. /**
  1012. * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
  1013. * @phba: pointer to lpfc hba data structure.
  1014. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  1015. *
  1016. * This is the callback function to the lpfc heart-beat mailbox command.
  1017. * If configured, the lpfc driver issues the heart-beat mailbox command to
  1018. * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
  1019. * heart-beat mailbox command is issued, the driver shall set up heart-beat
  1020. * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
  1021. * heart-beat outstanding state. Once the mailbox command comes back and
  1022. * no error conditions detected, the heart-beat mailbox command timer is
  1023. * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
  1024. * state is cleared for the next heart-beat. If the timer expired with the
  1025. * heart-beat outstanding state set, the driver will put the HBA offline.
  1026. **/
  1027. static void
  1028. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  1029. {
  1030. unsigned long drvr_flag;
  1031. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1032. phba->hb_outstanding = 0;
  1033. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1034. /* Check and reset heart-beat timer is necessary */
  1035. mempool_free(pmboxq, phba->mbox_mem_pool);
  1036. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  1037. !(phba->link_state == LPFC_HBA_ERROR) &&
  1038. !(phba->pport->load_flag & FC_UNLOADING))
  1039. mod_timer(&phba->hb_tmofunc,
  1040. jiffies +
  1041. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  1042. return;
  1043. }
  1044. /**
  1045. * lpfc_hb_timeout_handler - The HBA-timer timeout handler
  1046. * @phba: pointer to lpfc hba data structure.
  1047. *
  1048. * This is the actual HBA-timer timeout handler to be invoked by the worker
  1049. * thread whenever the HBA timer fired and HBA-timeout event posted. This
  1050. * handler performs any periodic operations needed for the device. If such
  1051. * periodic event has already been attended to either in the interrupt handler
  1052. * or by processing slow-ring or fast-ring events within the HBA-timer
  1053. * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
  1054. * the timer for the next timeout period. If lpfc heart-beat mailbox command
  1055. * is configured and there is no heart-beat mailbox command outstanding, a
  1056. * heart-beat mailbox is issued and timer set properly. Otherwise, if there
  1057. * has been a heart-beat mailbox command outstanding, the HBA shall be put
  1058. * to offline.
  1059. **/
  1060. void
  1061. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  1062. {
  1063. struct lpfc_vport **vports;
  1064. LPFC_MBOXQ_t *pmboxq;
  1065. struct lpfc_dmabuf *buf_ptr;
  1066. int retval, i;
  1067. struct lpfc_sli *psli = &phba->sli;
  1068. LIST_HEAD(completions);
  1069. vports = lpfc_create_vport_work_array(phba);
  1070. if (vports != NULL)
  1071. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  1072. lpfc_rcv_seq_check_edtov(vports[i]);
  1073. lpfc_destroy_vport_work_array(phba, vports);
  1074. if ((phba->link_state == LPFC_HBA_ERROR) ||
  1075. (phba->pport->load_flag & FC_UNLOADING) ||
  1076. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  1077. return;
  1078. spin_lock_irq(&phba->pport->work_port_lock);
  1079. if (time_after(phba->last_completion_time +
  1080. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
  1081. jiffies)) {
  1082. spin_unlock_irq(&phba->pport->work_port_lock);
  1083. if (!phba->hb_outstanding)
  1084. mod_timer(&phba->hb_tmofunc,
  1085. jiffies +
  1086. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  1087. else
  1088. mod_timer(&phba->hb_tmofunc,
  1089. jiffies +
  1090. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  1091. return;
  1092. }
  1093. spin_unlock_irq(&phba->pport->work_port_lock);
  1094. if (phba->elsbuf_cnt &&
  1095. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  1096. spin_lock_irq(&phba->hbalock);
  1097. list_splice_init(&phba->elsbuf, &completions);
  1098. phba->elsbuf_cnt = 0;
  1099. phba->elsbuf_prev_cnt = 0;
  1100. spin_unlock_irq(&phba->hbalock);
  1101. while (!list_empty(&completions)) {
  1102. list_remove_head(&completions, buf_ptr,
  1103. struct lpfc_dmabuf, list);
  1104. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1105. kfree(buf_ptr);
  1106. }
  1107. }
  1108. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  1109. /* If there is no heart beat outstanding, issue a heartbeat command */
  1110. if (phba->cfg_enable_hba_heartbeat) {
  1111. if (!phba->hb_outstanding) {
  1112. if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
  1113. (list_empty(&psli->mboxq))) {
  1114. pmboxq = mempool_alloc(phba->mbox_mem_pool,
  1115. GFP_KERNEL);
  1116. if (!pmboxq) {
  1117. mod_timer(&phba->hb_tmofunc,
  1118. jiffies +
  1119. msecs_to_jiffies(1000 *
  1120. LPFC_HB_MBOX_INTERVAL));
  1121. return;
  1122. }
  1123. lpfc_heart_beat(phba, pmboxq);
  1124. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  1125. pmboxq->vport = phba->pport;
  1126. retval = lpfc_sli_issue_mbox(phba, pmboxq,
  1127. MBX_NOWAIT);
  1128. if (retval != MBX_BUSY &&
  1129. retval != MBX_SUCCESS) {
  1130. mempool_free(pmboxq,
  1131. phba->mbox_mem_pool);
  1132. mod_timer(&phba->hb_tmofunc,
  1133. jiffies +
  1134. msecs_to_jiffies(1000 *
  1135. LPFC_HB_MBOX_INTERVAL));
  1136. return;
  1137. }
  1138. phba->skipped_hb = 0;
  1139. phba->hb_outstanding = 1;
  1140. } else if (time_before_eq(phba->last_completion_time,
  1141. phba->skipped_hb)) {
  1142. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1143. "2857 Last completion time not "
  1144. " updated in %d ms\n",
  1145. jiffies_to_msecs(jiffies
  1146. - phba->last_completion_time));
  1147. } else
  1148. phba->skipped_hb = jiffies;
  1149. mod_timer(&phba->hb_tmofunc,
  1150. jiffies +
  1151. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  1152. return;
  1153. } else {
  1154. /*
  1155. * If heart beat timeout called with hb_outstanding set
  1156. * we need to give the hb mailbox cmd a chance to
  1157. * complete or TMO.
  1158. */
  1159. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1160. "0459 Adapter heartbeat still out"
  1161. "standing:last compl time was %d ms.\n",
  1162. jiffies_to_msecs(jiffies
  1163. - phba->last_completion_time));
  1164. mod_timer(&phba->hb_tmofunc,
  1165. jiffies +
  1166. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  1167. }
  1168. }
  1169. }
  1170. /**
  1171. * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
  1172. * @phba: pointer to lpfc hba data structure.
  1173. *
  1174. * This routine is called to bring the HBA offline when HBA hardware error
  1175. * other than Port Error 6 has been detected.
  1176. **/
  1177. static void
  1178. lpfc_offline_eratt(struct lpfc_hba *phba)
  1179. {
  1180. struct lpfc_sli *psli = &phba->sli;
  1181. spin_lock_irq(&phba->hbalock);
  1182. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1183. spin_unlock_irq(&phba->hbalock);
  1184. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1185. lpfc_offline(phba);
  1186. lpfc_reset_barrier(phba);
  1187. spin_lock_irq(&phba->hbalock);
  1188. lpfc_sli_brdreset(phba);
  1189. spin_unlock_irq(&phba->hbalock);
  1190. lpfc_hba_down_post(phba);
  1191. lpfc_sli_brdready(phba, HS_MBRDY);
  1192. lpfc_unblock_mgmt_io(phba);
  1193. phba->link_state = LPFC_HBA_ERROR;
  1194. return;
  1195. }
  1196. /**
  1197. * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
  1198. * @phba: pointer to lpfc hba data structure.
  1199. *
  1200. * This routine is called to bring a SLI4 HBA offline when HBA hardware error
  1201. * other than Port Error 6 has been detected.
  1202. **/
  1203. void
  1204. lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
  1205. {
  1206. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1207. lpfc_offline(phba);
  1208. lpfc_sli4_brdreset(phba);
  1209. lpfc_hba_down_post(phba);
  1210. lpfc_sli4_post_status_check(phba);
  1211. lpfc_unblock_mgmt_io(phba);
  1212. phba->link_state = LPFC_HBA_ERROR;
  1213. }
  1214. /**
  1215. * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
  1216. * @phba: pointer to lpfc hba data structure.
  1217. *
  1218. * This routine is invoked to handle the deferred HBA hardware error
  1219. * conditions. This type of error is indicated by HBA by setting ER1
  1220. * and another ER bit in the host status register. The driver will
  1221. * wait until the ER1 bit clears before handling the error condition.
  1222. **/
  1223. static void
  1224. lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
  1225. {
  1226. uint32_t old_host_status = phba->work_hs;
  1227. struct lpfc_sli *psli = &phba->sli;
  1228. /* If the pci channel is offline, ignore possible errors,
  1229. * since we cannot communicate with the pci card anyway.
  1230. */
  1231. if (pci_channel_offline(phba->pcidev)) {
  1232. spin_lock_irq(&phba->hbalock);
  1233. phba->hba_flag &= ~DEFER_ERATT;
  1234. spin_unlock_irq(&phba->hbalock);
  1235. return;
  1236. }
  1237. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1238. "0479 Deferred Adapter Hardware Error "
  1239. "Data: x%x x%x x%x\n",
  1240. phba->work_hs,
  1241. phba->work_status[0], phba->work_status[1]);
  1242. spin_lock_irq(&phba->hbalock);
  1243. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1244. spin_unlock_irq(&phba->hbalock);
  1245. /*
  1246. * Firmware stops when it triggred erratt. That could cause the I/Os
  1247. * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
  1248. * SCSI layer retry it after re-establishing link.
  1249. */
  1250. lpfc_sli_abort_fcp_rings(phba);
  1251. /*
  1252. * There was a firmware error. Take the hba offline and then
  1253. * attempt to restart it.
  1254. */
  1255. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  1256. lpfc_offline(phba);
  1257. /* Wait for the ER1 bit to clear.*/
  1258. while (phba->work_hs & HS_FFER1) {
  1259. msleep(100);
  1260. if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
  1261. phba->work_hs = UNPLUG_ERR ;
  1262. break;
  1263. }
  1264. /* If driver is unloading let the worker thread continue */
  1265. if (phba->pport->load_flag & FC_UNLOADING) {
  1266. phba->work_hs = 0;
  1267. break;
  1268. }
  1269. }
  1270. /*
  1271. * This is to ptrotect against a race condition in which
  1272. * first write to the host attention register clear the
  1273. * host status register.
  1274. */
  1275. if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
  1276. phba->work_hs = old_host_status & ~HS_FFER1;
  1277. spin_lock_irq(&phba->hbalock);
  1278. phba->hba_flag &= ~DEFER_ERATT;
  1279. spin_unlock_irq(&phba->hbalock);
  1280. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  1281. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  1282. }
  1283. static void
  1284. lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
  1285. {
  1286. struct lpfc_board_event_header board_event;
  1287. struct Scsi_Host *shost;
  1288. board_event.event_type = FC_REG_BOARD_EVENT;
  1289. board_event.subcategory = LPFC_EVENT_PORTINTERR;
  1290. shost = lpfc_shost_from_vport(phba->pport);
  1291. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1292. sizeof(board_event),
  1293. (char *) &board_event,
  1294. LPFC_NL_VENDOR_ID);
  1295. }
  1296. /**
  1297. * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
  1298. * @phba: pointer to lpfc hba data structure.
  1299. *
  1300. * This routine is invoked to handle the following HBA hardware error
  1301. * conditions:
  1302. * 1 - HBA error attention interrupt
  1303. * 2 - DMA ring index out of range
  1304. * 3 - Mailbox command came back as unknown
  1305. **/
  1306. static void
  1307. lpfc_handle_eratt_s3(struct lpfc_hba *phba)
  1308. {
  1309. struct lpfc_vport *vport = phba->pport;
  1310. struct lpfc_sli *psli = &phba->sli;
  1311. uint32_t event_data;
  1312. unsigned long temperature;
  1313. struct temp_event temp_event_data;
  1314. struct Scsi_Host *shost;
  1315. /* If the pci channel is offline, ignore possible errors,
  1316. * since we cannot communicate with the pci card anyway.
  1317. */
  1318. if (pci_channel_offline(phba->pcidev)) {
  1319. spin_lock_irq(&phba->hbalock);
  1320. phba->hba_flag &= ~DEFER_ERATT;
  1321. spin_unlock_irq(&phba->hbalock);
  1322. return;
  1323. }
  1324. /* If resets are disabled then leave the HBA alone and return */
  1325. if (!phba->cfg_enable_hba_reset)
  1326. return;
  1327. /* Send an internal error event to mgmt application */
  1328. lpfc_board_errevt_to_mgmt(phba);
  1329. if (phba->hba_flag & DEFER_ERATT)
  1330. lpfc_handle_deferred_eratt(phba);
  1331. if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
  1332. if (phba->work_hs & HS_FFER6)
  1333. /* Re-establishing Link */
  1334. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1335. "1301 Re-establishing Link "
  1336. "Data: x%x x%x x%x\n",
  1337. phba->work_hs, phba->work_status[0],
  1338. phba->work_status[1]);
  1339. if (phba->work_hs & HS_FFER8)
  1340. /* Device Zeroization */
  1341. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1342. "2861 Host Authentication device "
  1343. "zeroization Data:x%x x%x x%x\n",
  1344. phba->work_hs, phba->work_status[0],
  1345. phba->work_status[1]);
  1346. spin_lock_irq(&phba->hbalock);
  1347. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1348. spin_unlock_irq(&phba->hbalock);
  1349. /*
  1350. * Firmware stops when it triggled erratt with HS_FFER6.
  1351. * That could cause the I/Os dropped by the firmware.
  1352. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1353. * retry it after re-establishing link.
  1354. */
  1355. lpfc_sli_abort_fcp_rings(phba);
  1356. /*
  1357. * There was a firmware error. Take the hba offline and then
  1358. * attempt to restart it.
  1359. */
  1360. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1361. lpfc_offline(phba);
  1362. lpfc_sli_brdrestart(phba);
  1363. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  1364. lpfc_unblock_mgmt_io(phba);
  1365. return;
  1366. }
  1367. lpfc_unblock_mgmt_io(phba);
  1368. } else if (phba->work_hs & HS_CRIT_TEMP) {
  1369. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  1370. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  1371. temp_event_data.event_code = LPFC_CRIT_TEMP;
  1372. temp_event_data.data = (uint32_t)temperature;
  1373. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1374. "0406 Adapter maximum temperature exceeded "
  1375. "(%ld), taking this port offline "
  1376. "Data: x%x x%x x%x\n",
  1377. temperature, phba->work_hs,
  1378. phba->work_status[0], phba->work_status[1]);
  1379. shost = lpfc_shost_from_vport(phba->pport);
  1380. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1381. sizeof(temp_event_data),
  1382. (char *) &temp_event_data,
  1383. SCSI_NL_VID_TYPE_PCI
  1384. | PCI_VENDOR_ID_EMULEX);
  1385. spin_lock_irq(&phba->hbalock);
  1386. phba->over_temp_state = HBA_OVER_TEMP;
  1387. spin_unlock_irq(&phba->hbalock);
  1388. lpfc_offline_eratt(phba);
  1389. } else {
  1390. /* The if clause above forces this code path when the status
  1391. * failure is a value other than FFER6. Do not call the offline
  1392. * twice. This is the adapter hardware error path.
  1393. */
  1394. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1395. "0457 Adapter Hardware Error "
  1396. "Data: x%x x%x x%x\n",
  1397. phba->work_hs,
  1398. phba->work_status[0], phba->work_status[1]);
  1399. event_data = FC_REG_DUMP_EVENT;
  1400. shost = lpfc_shost_from_vport(vport);
  1401. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1402. sizeof(event_data), (char *) &event_data,
  1403. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1404. lpfc_offline_eratt(phba);
  1405. }
  1406. return;
  1407. }
  1408. /**
  1409. * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
  1410. * @phba: pointer to lpfc hba data structure.
  1411. * @mbx_action: flag for mailbox shutdown action.
  1412. *
  1413. * This routine is invoked to perform an SLI4 port PCI function reset in
  1414. * response to port status register polling attention. It waits for port
  1415. * status register (ERR, RDY, RN) bits before proceeding with function reset.
  1416. * During this process, interrupt vectors are freed and later requested
  1417. * for handling possible port resource change.
  1418. **/
  1419. static int
  1420. lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
  1421. bool en_rn_msg)
  1422. {
  1423. int rc;
  1424. uint32_t intr_mode;
  1425. /*
  1426. * On error status condition, driver need to wait for port
  1427. * ready before performing reset.
  1428. */
  1429. rc = lpfc_sli4_pdev_status_reg_wait(phba);
  1430. if (!rc) {
  1431. /* need reset: attempt for port recovery */
  1432. if (en_rn_msg)
  1433. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1434. "2887 Reset Needed: Attempting Port "
  1435. "Recovery...\n");
  1436. lpfc_offline_prep(phba, mbx_action);
  1437. lpfc_offline(phba);
  1438. /* release interrupt for possible resource change */
  1439. lpfc_sli4_disable_intr(phba);
  1440. lpfc_sli_brdrestart(phba);
  1441. /* request and enable interrupt */
  1442. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  1443. if (intr_mode == LPFC_INTR_ERROR) {
  1444. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1445. "3175 Failed to enable interrupt\n");
  1446. return -EIO;
  1447. } else {
  1448. phba->intr_mode = intr_mode;
  1449. }
  1450. rc = lpfc_online(phba);
  1451. if (rc == 0)
  1452. lpfc_unblock_mgmt_io(phba);
  1453. }
  1454. return rc;
  1455. }
  1456. /**
  1457. * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
  1458. * @phba: pointer to lpfc hba data structure.
  1459. *
  1460. * This routine is invoked to handle the SLI4 HBA hardware error attention
  1461. * conditions.
  1462. **/
  1463. static void
  1464. lpfc_handle_eratt_s4(struct lpfc_hba *phba)
  1465. {
  1466. struct lpfc_vport *vport = phba->pport;
  1467. uint32_t event_data;
  1468. struct Scsi_Host *shost;
  1469. uint32_t if_type;
  1470. struct lpfc_register portstat_reg = {0};
  1471. uint32_t reg_err1, reg_err2;
  1472. uint32_t uerrlo_reg, uemasklo_reg;
  1473. uint32_t pci_rd_rc1, pci_rd_rc2;
  1474. bool en_rn_msg = true;
  1475. int rc;
  1476. /* If the pci channel is offline, ignore possible errors, since
  1477. * we cannot communicate with the pci card anyway.
  1478. */
  1479. if (pci_channel_offline(phba->pcidev))
  1480. return;
  1481. /* If resets are disabled then leave the HBA alone and return */
  1482. if (!phba->cfg_enable_hba_reset)
  1483. return;
  1484. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  1485. switch (if_type) {
  1486. case LPFC_SLI_INTF_IF_TYPE_0:
  1487. pci_rd_rc1 = lpfc_readl(
  1488. phba->sli4_hba.u.if_type0.UERRLOregaddr,
  1489. &uerrlo_reg);
  1490. pci_rd_rc2 = lpfc_readl(
  1491. phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
  1492. &uemasklo_reg);
  1493. /* consider PCI bus read error as pci_channel_offline */
  1494. if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
  1495. return;
  1496. lpfc_sli4_offline_eratt(phba);
  1497. break;
  1498. case LPFC_SLI_INTF_IF_TYPE_2:
  1499. pci_rd_rc1 = lpfc_readl(
  1500. phba->sli4_hba.u.if_type2.STATUSregaddr,
  1501. &portstat_reg.word0);
  1502. /* consider PCI bus read error as pci_channel_offline */
  1503. if (pci_rd_rc1 == -EIO) {
  1504. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1505. "3151 PCI bus read access failure: x%x\n",
  1506. readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
  1507. return;
  1508. }
  1509. reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  1510. reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  1511. if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
  1512. /* TODO: Register for Overtemp async events. */
  1513. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1514. "2889 Port Overtemperature event, "
  1515. "taking port offline\n");
  1516. spin_lock_irq(&phba->hbalock);
  1517. phba->over_temp_state = HBA_OVER_TEMP;
  1518. spin_unlock_irq(&phba->hbalock);
  1519. lpfc_sli4_offline_eratt(phba);
  1520. break;
  1521. }
  1522. if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1523. reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
  1524. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1525. "3143 Port Down: Firmware Update "
  1526. "Detected\n");
  1527. en_rn_msg = false;
  1528. } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1529. reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
  1530. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1531. "3144 Port Down: Debug Dump\n");
  1532. else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1533. reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
  1534. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1535. "3145 Port Down: Provisioning\n");
  1536. /* Check port status register for function reset */
  1537. rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
  1538. en_rn_msg);
  1539. if (rc == 0) {
  1540. /* don't report event on forced debug dump */
  1541. if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1542. reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
  1543. return;
  1544. else
  1545. break;
  1546. }
  1547. /* fall through for not able to recover */
  1548. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1549. "3152 Unrecoverable error, bring the port "
  1550. "offline\n");
  1551. lpfc_sli4_offline_eratt(phba);
  1552. break;
  1553. case LPFC_SLI_INTF_IF_TYPE_1:
  1554. default:
  1555. break;
  1556. }
  1557. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1558. "3123 Report dump event to upper layer\n");
  1559. /* Send an internal error event to mgmt application */
  1560. lpfc_board_errevt_to_mgmt(phba);
  1561. event_data = FC_REG_DUMP_EVENT;
  1562. shost = lpfc_shost_from_vport(vport);
  1563. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1564. sizeof(event_data), (char *) &event_data,
  1565. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1566. }
  1567. /**
  1568. * lpfc_handle_eratt - Wrapper func for handling hba error attention
  1569. * @phba: pointer to lpfc HBA data structure.
  1570. *
  1571. * This routine wraps the actual SLI3 or SLI4 hba error attention handling
  1572. * routine from the API jump table function pointer from the lpfc_hba struct.
  1573. *
  1574. * Return codes
  1575. * 0 - success.
  1576. * Any other value - error.
  1577. **/
  1578. void
  1579. lpfc_handle_eratt(struct lpfc_hba *phba)
  1580. {
  1581. (*phba->lpfc_handle_eratt)(phba);
  1582. }
  1583. /**
  1584. * lpfc_handle_latt - The HBA link event handler
  1585. * @phba: pointer to lpfc hba data structure.
  1586. *
  1587. * This routine is invoked from the worker thread to handle a HBA host
  1588. * attention link event.
  1589. **/
  1590. void
  1591. lpfc_handle_latt(struct lpfc_hba *phba)
  1592. {
  1593. struct lpfc_vport *vport = phba->pport;
  1594. struct lpfc_sli *psli = &phba->sli;
  1595. LPFC_MBOXQ_t *pmb;
  1596. volatile uint32_t control;
  1597. struct lpfc_dmabuf *mp;
  1598. int rc = 0;
  1599. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1600. if (!pmb) {
  1601. rc = 1;
  1602. goto lpfc_handle_latt_err_exit;
  1603. }
  1604. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1605. if (!mp) {
  1606. rc = 2;
  1607. goto lpfc_handle_latt_free_pmb;
  1608. }
  1609. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  1610. if (!mp->virt) {
  1611. rc = 3;
  1612. goto lpfc_handle_latt_free_mp;
  1613. }
  1614. /* Cleanup any outstanding ELS commands */
  1615. lpfc_els_flush_all_cmd(phba);
  1616. psli->slistat.link_event++;
  1617. lpfc_read_topology(phba, pmb, mp);
  1618. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  1619. pmb->vport = vport;
  1620. /* Block ELS IOCBs until we have processed this mbox command */
  1621. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  1622. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  1623. if (rc == MBX_NOT_FINISHED) {
  1624. rc = 4;
  1625. goto lpfc_handle_latt_free_mbuf;
  1626. }
  1627. /* Clear Link Attention in HA REG */
  1628. spin_lock_irq(&phba->hbalock);
  1629. writel(HA_LATT, phba->HAregaddr);
  1630. readl(phba->HAregaddr); /* flush */
  1631. spin_unlock_irq(&phba->hbalock);
  1632. return;
  1633. lpfc_handle_latt_free_mbuf:
  1634. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  1635. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1636. lpfc_handle_latt_free_mp:
  1637. kfree(mp);
  1638. lpfc_handle_latt_free_pmb:
  1639. mempool_free(pmb, phba->mbox_mem_pool);
  1640. lpfc_handle_latt_err_exit:
  1641. /* Enable Link attention interrupts */
  1642. spin_lock_irq(&phba->hbalock);
  1643. psli->sli_flag |= LPFC_PROCESS_LA;
  1644. control = readl(phba->HCregaddr);
  1645. control |= HC_LAINT_ENA;
  1646. writel(control, phba->HCregaddr);
  1647. readl(phba->HCregaddr); /* flush */
  1648. /* Clear Link Attention in HA REG */
  1649. writel(HA_LATT, phba->HAregaddr);
  1650. readl(phba->HAregaddr); /* flush */
  1651. spin_unlock_irq(&phba->hbalock);
  1652. lpfc_linkdown(phba);
  1653. phba->link_state = LPFC_HBA_ERROR;
  1654. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1655. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  1656. return;
  1657. }
  1658. /**
  1659. * lpfc_parse_vpd - Parse VPD (Vital Product Data)
  1660. * @phba: pointer to lpfc hba data structure.
  1661. * @vpd: pointer to the vital product data.
  1662. * @len: length of the vital product data in bytes.
  1663. *
  1664. * This routine parses the Vital Product Data (VPD). The VPD is treated as
  1665. * an array of characters. In this routine, the ModelName, ProgramType, and
  1666. * ModelDesc, etc. fields of the phba data structure will be populated.
  1667. *
  1668. * Return codes
  1669. * 0 - pointer to the VPD passed in is NULL
  1670. * 1 - success
  1671. **/
  1672. int
  1673. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  1674. {
  1675. uint8_t lenlo, lenhi;
  1676. int Length;
  1677. int i, j;
  1678. int finished = 0;
  1679. int index = 0;
  1680. if (!vpd)
  1681. return 0;
  1682. /* Vital Product */
  1683. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1684. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  1685. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  1686. (uint32_t) vpd[3]);
  1687. while (!finished && (index < (len - 4))) {
  1688. switch (vpd[index]) {
  1689. case 0x82:
  1690. case 0x91:
  1691. index += 1;
  1692. lenlo = vpd[index];
  1693. index += 1;
  1694. lenhi = vpd[index];
  1695. index += 1;
  1696. i = ((((unsigned short)lenhi) << 8) + lenlo);
  1697. index += i;
  1698. break;
  1699. case 0x90:
  1700. index += 1;
  1701. lenlo = vpd[index];
  1702. index += 1;
  1703. lenhi = vpd[index];
  1704. index += 1;
  1705. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  1706. if (Length > len - index)
  1707. Length = len - index;
  1708. while (Length > 0) {
  1709. /* Look for Serial Number */
  1710. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  1711. index += 2;
  1712. i = vpd[index];
  1713. index += 1;
  1714. j = 0;
  1715. Length -= (3+i);
  1716. while(i--) {
  1717. phba->SerialNumber[j++] = vpd[index++];
  1718. if (j == 31)
  1719. break;
  1720. }
  1721. phba->SerialNumber[j] = 0;
  1722. continue;
  1723. }
  1724. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  1725. phba->vpd_flag |= VPD_MODEL_DESC;
  1726. index += 2;
  1727. i = vpd[index];
  1728. index += 1;
  1729. j = 0;
  1730. Length -= (3+i);
  1731. while(i--) {
  1732. phba->ModelDesc[j++] = vpd[index++];
  1733. if (j == 255)
  1734. break;
  1735. }
  1736. phba->ModelDesc[j] = 0;
  1737. continue;
  1738. }
  1739. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  1740. phba->vpd_flag |= VPD_MODEL_NAME;
  1741. index += 2;
  1742. i = vpd[index];
  1743. index += 1;
  1744. j = 0;
  1745. Length -= (3+i);
  1746. while(i--) {
  1747. phba->ModelName[j++] = vpd[index++];
  1748. if (j == 79)
  1749. break;
  1750. }
  1751. phba->ModelName[j] = 0;
  1752. continue;
  1753. }
  1754. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  1755. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  1756. index += 2;
  1757. i = vpd[index];
  1758. index += 1;
  1759. j = 0;
  1760. Length -= (3+i);
  1761. while(i--) {
  1762. phba->ProgramType[j++] = vpd[index++];
  1763. if (j == 255)
  1764. break;
  1765. }
  1766. phba->ProgramType[j] = 0;
  1767. continue;
  1768. }
  1769. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  1770. phba->vpd_flag |= VPD_PORT;
  1771. index += 2;
  1772. i = vpd[index];
  1773. index += 1;
  1774. j = 0;
  1775. Length -= (3+i);
  1776. while(i--) {
  1777. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  1778. (phba->sli4_hba.pport_name_sta ==
  1779. LPFC_SLI4_PPNAME_GET)) {
  1780. j++;
  1781. index++;
  1782. } else
  1783. phba->Port[j++] = vpd[index++];
  1784. if (j == 19)
  1785. break;
  1786. }
  1787. if ((phba->sli_rev != LPFC_SLI_REV4) ||
  1788. (phba->sli4_hba.pport_name_sta ==
  1789. LPFC_SLI4_PPNAME_NON))
  1790. phba->Port[j] = 0;
  1791. continue;
  1792. }
  1793. else {
  1794. index += 2;
  1795. i = vpd[index];
  1796. index += 1;
  1797. index += i;
  1798. Length -= (3 + i);
  1799. }
  1800. }
  1801. finished = 0;
  1802. break;
  1803. case 0x78:
  1804. finished = 1;
  1805. break;
  1806. default:
  1807. index ++;
  1808. break;
  1809. }
  1810. }
  1811. return(1);
  1812. }
  1813. /**
  1814. * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
  1815. * @phba: pointer to lpfc hba data structure.
  1816. * @mdp: pointer to the data structure to hold the derived model name.
  1817. * @descp: pointer to the data structure to hold the derived description.
  1818. *
  1819. * This routine retrieves HBA's description based on its registered PCI device
  1820. * ID. The @descp passed into this function points to an array of 256 chars. It
  1821. * shall be returned with the model name, maximum speed, and the host bus type.
  1822. * The @mdp passed into this function points to an array of 80 chars. When the
  1823. * function returns, the @mdp will be filled with the model name.
  1824. **/
  1825. static void
  1826. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  1827. {
  1828. lpfc_vpd_t *vp;
  1829. uint16_t dev_id = phba->pcidev->device;
  1830. int max_speed;
  1831. int GE = 0;
  1832. int oneConnect = 0; /* default is not a oneConnect */
  1833. struct {
  1834. char *name;
  1835. char *bus;
  1836. char *function;
  1837. } m = {"<Unknown>", "", ""};
  1838. if (mdp && mdp[0] != '\0'
  1839. && descp && descp[0] != '\0')
  1840. return;
  1841. if (phba->lmt & LMT_16Gb)
  1842. max_speed = 16;
  1843. else if (phba->lmt & LMT_10Gb)
  1844. max_speed = 10;
  1845. else if (phba->lmt & LMT_8Gb)
  1846. max_speed = 8;
  1847. else if (phba->lmt & LMT_4Gb)
  1848. max_speed = 4;
  1849. else if (phba->lmt & LMT_2Gb)
  1850. max_speed = 2;
  1851. else if (phba->lmt & LMT_1Gb)
  1852. max_speed = 1;
  1853. else
  1854. max_speed = 0;
  1855. vp = &phba->vpd;
  1856. switch (dev_id) {
  1857. case PCI_DEVICE_ID_FIREFLY:
  1858. m = (typeof(m)){"LP6000", "PCI",
  1859. "Obsolete, Unsupported Fibre Channel Adapter"};
  1860. break;
  1861. case PCI_DEVICE_ID_SUPERFLY:
  1862. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  1863. m = (typeof(m)){"LP7000", "PCI", ""};
  1864. else
  1865. m = (typeof(m)){"LP7000E", "PCI", ""};
  1866. m.function = "Obsolete, Unsupported Fibre Channel Adapter";
  1867. break;
  1868. case PCI_DEVICE_ID_DRAGONFLY:
  1869. m = (typeof(m)){"LP8000", "PCI",
  1870. "Obsolete, Unsupported Fibre Channel Adapter"};
  1871. break;
  1872. case PCI_DEVICE_ID_CENTAUR:
  1873. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  1874. m = (typeof(m)){"LP9002", "PCI", ""};
  1875. else
  1876. m = (typeof(m)){"LP9000", "PCI", ""};
  1877. m.function = "Obsolete, Unsupported Fibre Channel Adapter";
  1878. break;
  1879. case PCI_DEVICE_ID_RFLY:
  1880. m = (typeof(m)){"LP952", "PCI",
  1881. "Obsolete, Unsupported Fibre Channel Adapter"};
  1882. break;
  1883. case PCI_DEVICE_ID_PEGASUS:
  1884. m = (typeof(m)){"LP9802", "PCI-X",
  1885. "Obsolete, Unsupported Fibre Channel Adapter"};
  1886. break;
  1887. case PCI_DEVICE_ID_THOR:
  1888. m = (typeof(m)){"LP10000", "PCI-X",
  1889. "Obsolete, Unsupported Fibre Channel Adapter"};
  1890. break;
  1891. case PCI_DEVICE_ID_VIPER:
  1892. m = (typeof(m)){"LPX1000", "PCI-X",
  1893. "Obsolete, Unsupported Fibre Channel Adapter"};
  1894. break;
  1895. case PCI_DEVICE_ID_PFLY:
  1896. m = (typeof(m)){"LP982", "PCI-X",
  1897. "Obsolete, Unsupported Fibre Channel Adapter"};
  1898. break;
  1899. case PCI_DEVICE_ID_TFLY:
  1900. m = (typeof(m)){"LP1050", "PCI-X",
  1901. "Obsolete, Unsupported Fibre Channel Adapter"};
  1902. break;
  1903. case PCI_DEVICE_ID_HELIOS:
  1904. m = (typeof(m)){"LP11000", "PCI-X2",
  1905. "Obsolete, Unsupported Fibre Channel Adapter"};
  1906. break;
  1907. case PCI_DEVICE_ID_HELIOS_SCSP:
  1908. m = (typeof(m)){"LP11000-SP", "PCI-X2",
  1909. "Obsolete, Unsupported Fibre Channel Adapter"};
  1910. break;
  1911. case PCI_DEVICE_ID_HELIOS_DCSP:
  1912. m = (typeof(m)){"LP11002-SP", "PCI-X2",
  1913. "Obsolete, Unsupported Fibre Channel Adapter"};
  1914. break;
  1915. case PCI_DEVICE_ID_NEPTUNE:
  1916. m = (typeof(m)){"LPe1000", "PCIe",
  1917. "Obsolete, Unsupported Fibre Channel Adapter"};
  1918. break;
  1919. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  1920. m = (typeof(m)){"LPe1000-SP", "PCIe",
  1921. "Obsolete, Unsupported Fibre Channel Adapter"};
  1922. break;
  1923. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  1924. m = (typeof(m)){"LPe1002-SP", "PCIe",
  1925. "Obsolete, Unsupported Fibre Channel Adapter"};
  1926. break;
  1927. case PCI_DEVICE_ID_BMID:
  1928. m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
  1929. break;
  1930. case PCI_DEVICE_ID_BSMB:
  1931. m = (typeof(m)){"LP111", "PCI-X2",
  1932. "Obsolete, Unsupported Fibre Channel Adapter"};
  1933. break;
  1934. case PCI_DEVICE_ID_ZEPHYR:
  1935. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  1936. break;
  1937. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  1938. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  1939. break;
  1940. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  1941. m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
  1942. GE = 1;
  1943. break;
  1944. case PCI_DEVICE_ID_ZMID:
  1945. m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
  1946. break;
  1947. case PCI_DEVICE_ID_ZSMB:
  1948. m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
  1949. break;
  1950. case PCI_DEVICE_ID_LP101:
  1951. m = (typeof(m)){"LP101", "PCI-X",
  1952. "Obsolete, Unsupported Fibre Channel Adapter"};
  1953. break;
  1954. case PCI_DEVICE_ID_LP10000S:
  1955. m = (typeof(m)){"LP10000-S", "PCI",
  1956. "Obsolete, Unsupported Fibre Channel Adapter"};
  1957. break;
  1958. case PCI_DEVICE_ID_LP11000S:
  1959. m = (typeof(m)){"LP11000-S", "PCI-X2",
  1960. "Obsolete, Unsupported Fibre Channel Adapter"};
  1961. break;
  1962. case PCI_DEVICE_ID_LPE11000S:
  1963. m = (typeof(m)){"LPe11000-S", "PCIe",
  1964. "Obsolete, Unsupported Fibre Channel Adapter"};
  1965. break;
  1966. case PCI_DEVICE_ID_SAT:
  1967. m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
  1968. break;
  1969. case PCI_DEVICE_ID_SAT_MID:
  1970. m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
  1971. break;
  1972. case PCI_DEVICE_ID_SAT_SMB:
  1973. m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
  1974. break;
  1975. case PCI_DEVICE_ID_SAT_DCSP:
  1976. m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
  1977. break;
  1978. case PCI_DEVICE_ID_SAT_SCSP:
  1979. m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
  1980. break;
  1981. case PCI_DEVICE_ID_SAT_S:
  1982. m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
  1983. break;
  1984. case PCI_DEVICE_ID_HORNET:
  1985. m = (typeof(m)){"LP21000", "PCIe",
  1986. "Obsolete, Unsupported FCoE Adapter"};
  1987. GE = 1;
  1988. break;
  1989. case PCI_DEVICE_ID_PROTEUS_VF:
  1990. m = (typeof(m)){"LPev12000", "PCIe IOV",
  1991. "Obsolete, Unsupported Fibre Channel Adapter"};
  1992. break;
  1993. case PCI_DEVICE_ID_PROTEUS_PF:
  1994. m = (typeof(m)){"LPev12000", "PCIe IOV",
  1995. "Obsolete, Unsupported Fibre Channel Adapter"};
  1996. break;
  1997. case PCI_DEVICE_ID_PROTEUS_S:
  1998. m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
  1999. "Obsolete, Unsupported Fibre Channel Adapter"};
  2000. break;
  2001. case PCI_DEVICE_ID_TIGERSHARK:
  2002. oneConnect = 1;
  2003. m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
  2004. break;
  2005. case PCI_DEVICE_ID_TOMCAT:
  2006. oneConnect = 1;
  2007. m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
  2008. break;
  2009. case PCI_DEVICE_ID_FALCON:
  2010. m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
  2011. "EmulexSecure Fibre"};
  2012. break;
  2013. case PCI_DEVICE_ID_BALIUS:
  2014. m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
  2015. "Obsolete, Unsupported Fibre Channel Adapter"};
  2016. break;
  2017. case PCI_DEVICE_ID_LANCER_FC:
  2018. m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
  2019. break;
  2020. case PCI_DEVICE_ID_LANCER_FC_VF:
  2021. m = (typeof(m)){"LPe16000", "PCIe",
  2022. "Obsolete, Unsupported Fibre Channel Adapter"};
  2023. break;
  2024. case PCI_DEVICE_ID_LANCER_FCOE:
  2025. oneConnect = 1;
  2026. m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
  2027. break;
  2028. case PCI_DEVICE_ID_LANCER_FCOE_VF:
  2029. oneConnect = 1;
  2030. m = (typeof(m)){"OCe15100", "PCIe",
  2031. "Obsolete, Unsupported FCoE"};
  2032. break;
  2033. case PCI_DEVICE_ID_SKYHAWK:
  2034. case PCI_DEVICE_ID_SKYHAWK_VF:
  2035. oneConnect = 1;
  2036. m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
  2037. break;
  2038. default:
  2039. m = (typeof(m)){"Unknown", "", ""};
  2040. break;
  2041. }
  2042. if (mdp && mdp[0] == '\0')
  2043. snprintf(mdp, 79,"%s", m.name);
  2044. /*
  2045. * oneConnect hba requires special processing, they are all initiators
  2046. * and we put the port number on the end
  2047. */
  2048. if (descp && descp[0] == '\0') {
  2049. if (oneConnect)
  2050. snprintf(descp, 255,
  2051. "Emulex OneConnect %s, %s Initiator %s",
  2052. m.name, m.function,
  2053. phba->Port);
  2054. else if (max_speed == 0)
  2055. snprintf(descp, 255,
  2056. "Emulex %s %s %s ",
  2057. m.name, m.bus, m.function);
  2058. else
  2059. snprintf(descp, 255,
  2060. "Emulex %s %d%s %s %s",
  2061. m.name, max_speed, (GE) ? "GE" : "Gb",
  2062. m.bus, m.function);
  2063. }
  2064. }
  2065. /**
  2066. * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
  2067. * @phba: pointer to lpfc hba data structure.
  2068. * @pring: pointer to a IOCB ring.
  2069. * @cnt: the number of IOCBs to be posted to the IOCB ring.
  2070. *
  2071. * This routine posts a given number of IOCBs with the associated DMA buffer
  2072. * descriptors specified by the cnt argument to the given IOCB ring.
  2073. *
  2074. * Return codes
  2075. * The number of IOCBs NOT able to be posted to the IOCB ring.
  2076. **/
  2077. int
  2078. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
  2079. {
  2080. IOCB_t *icmd;
  2081. struct lpfc_iocbq *iocb;
  2082. struct lpfc_dmabuf *mp1, *mp2;
  2083. cnt += pring->missbufcnt;
  2084. /* While there are buffers to post */
  2085. while (cnt > 0) {
  2086. /* Allocate buffer for command iocb */
  2087. iocb = lpfc_sli_get_iocbq(phba);
  2088. if (iocb == NULL) {
  2089. pring->missbufcnt = cnt;
  2090. return cnt;
  2091. }
  2092. icmd = &iocb->iocb;
  2093. /* 2 buffers can be posted per command */
  2094. /* Allocate buffer to post */
  2095. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  2096. if (mp1)
  2097. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  2098. if (!mp1 || !mp1->virt) {
  2099. kfree(mp1);
  2100. lpfc_sli_release_iocbq(phba, iocb);
  2101. pring->missbufcnt = cnt;
  2102. return cnt;
  2103. }
  2104. INIT_LIST_HEAD(&mp1->list);
  2105. /* Allocate buffer to post */
  2106. if (cnt > 1) {
  2107. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  2108. if (mp2)
  2109. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  2110. &mp2->phys);
  2111. if (!mp2 || !mp2->virt) {
  2112. kfree(mp2);
  2113. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  2114. kfree(mp1);
  2115. lpfc_sli_release_iocbq(phba, iocb);
  2116. pring->missbufcnt = cnt;
  2117. return cnt;
  2118. }
  2119. INIT_LIST_HEAD(&mp2->list);
  2120. } else {
  2121. mp2 = NULL;
  2122. }
  2123. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  2124. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  2125. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  2126. icmd->ulpBdeCount = 1;
  2127. cnt--;
  2128. if (mp2) {
  2129. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  2130. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  2131. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  2132. cnt--;
  2133. icmd->ulpBdeCount = 2;
  2134. }
  2135. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  2136. icmd->ulpLe = 1;
  2137. if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
  2138. IOCB_ERROR) {
  2139. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  2140. kfree(mp1);
  2141. cnt++;
  2142. if (mp2) {
  2143. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  2144. kfree(mp2);
  2145. cnt++;
  2146. }
  2147. lpfc_sli_release_iocbq(phba, iocb);
  2148. pring->missbufcnt = cnt;
  2149. return cnt;
  2150. }
  2151. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  2152. if (mp2)
  2153. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  2154. }
  2155. pring->missbufcnt = 0;
  2156. return 0;
  2157. }
  2158. /**
  2159. * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
  2160. * @phba: pointer to lpfc hba data structure.
  2161. *
  2162. * This routine posts initial receive IOCB buffers to the ELS ring. The
  2163. * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
  2164. * set to 64 IOCBs.
  2165. *
  2166. * Return codes
  2167. * 0 - success (currently always success)
  2168. **/
  2169. static int
  2170. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  2171. {
  2172. struct lpfc_sli *psli = &phba->sli;
  2173. /* Ring 0, ELS / CT buffers */
  2174. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
  2175. /* Ring 2 - FCP no buffers needed */
  2176. return 0;
  2177. }
  2178. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  2179. /**
  2180. * lpfc_sha_init - Set up initial array of hash table entries
  2181. * @HashResultPointer: pointer to an array as hash table.
  2182. *
  2183. * This routine sets up the initial values to the array of hash table entries
  2184. * for the LC HBAs.
  2185. **/
  2186. static void
  2187. lpfc_sha_init(uint32_t * HashResultPointer)
  2188. {
  2189. HashResultPointer[0] = 0x67452301;
  2190. HashResultPointer[1] = 0xEFCDAB89;
  2191. HashResultPointer[2] = 0x98BADCFE;
  2192. HashResultPointer[3] = 0x10325476;
  2193. HashResultPointer[4] = 0xC3D2E1F0;
  2194. }
  2195. /**
  2196. * lpfc_sha_iterate - Iterate initial hash table with the working hash table
  2197. * @HashResultPointer: pointer to an initial/result hash table.
  2198. * @HashWorkingPointer: pointer to an working hash table.
  2199. *
  2200. * This routine iterates an initial hash table pointed by @HashResultPointer
  2201. * with the values from the working hash table pointeed by @HashWorkingPointer.
  2202. * The results are putting back to the initial hash table, returned through
  2203. * the @HashResultPointer as the result hash table.
  2204. **/
  2205. static void
  2206. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  2207. {
  2208. int t;
  2209. uint32_t TEMP;
  2210. uint32_t A, B, C, D, E;
  2211. t = 16;
  2212. do {
  2213. HashWorkingPointer[t] =
  2214. S(1,
  2215. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  2216. 8] ^
  2217. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  2218. } while (++t <= 79);
  2219. t = 0;
  2220. A = HashResultPointer[0];
  2221. B = HashResultPointer[1];
  2222. C = HashResultPointer[2];
  2223. D = HashResultPointer[3];
  2224. E = HashResultPointer[4];
  2225. do {
  2226. if (t < 20) {
  2227. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  2228. } else if (t < 40) {
  2229. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  2230. } else if (t < 60) {
  2231. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  2232. } else {
  2233. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  2234. }
  2235. TEMP += S(5, A) + E + HashWorkingPointer[t];
  2236. E = D;
  2237. D = C;
  2238. C = S(30, B);
  2239. B = A;
  2240. A = TEMP;
  2241. } while (++t <= 79);
  2242. HashResultPointer[0] += A;
  2243. HashResultPointer[1] += B;
  2244. HashResultPointer[2] += C;
  2245. HashResultPointer[3] += D;
  2246. HashResultPointer[4] += E;
  2247. }
  2248. /**
  2249. * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
  2250. * @RandomChallenge: pointer to the entry of host challenge random number array.
  2251. * @HashWorking: pointer to the entry of the working hash array.
  2252. *
  2253. * This routine calculates the working hash array referred by @HashWorking
  2254. * from the challenge random numbers associated with the host, referred by
  2255. * @RandomChallenge. The result is put into the entry of the working hash
  2256. * array and returned by reference through @HashWorking.
  2257. **/
  2258. static void
  2259. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  2260. {
  2261. *HashWorking = (*RandomChallenge ^ *HashWorking);
  2262. }
  2263. /**
  2264. * lpfc_hba_init - Perform special handling for LC HBA initialization
  2265. * @phba: pointer to lpfc hba data structure.
  2266. * @hbainit: pointer to an array of unsigned 32-bit integers.
  2267. *
  2268. * This routine performs the special handling for LC HBA initialization.
  2269. **/
  2270. void
  2271. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  2272. {
  2273. int t;
  2274. uint32_t *HashWorking;
  2275. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  2276. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  2277. if (!HashWorking)
  2278. return;
  2279. HashWorking[0] = HashWorking[78] = *pwwnn++;
  2280. HashWorking[1] = HashWorking[79] = *pwwnn;
  2281. for (t = 0; t < 7; t++)
  2282. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  2283. lpfc_sha_init(hbainit);
  2284. lpfc_sha_iterate(hbainit, HashWorking);
  2285. kfree(HashWorking);
  2286. }
  2287. /**
  2288. * lpfc_cleanup - Performs vport cleanups before deleting a vport
  2289. * @vport: pointer to a virtual N_Port data structure.
  2290. *
  2291. * This routine performs the necessary cleanups before deleting the @vport.
  2292. * It invokes the discovery state machine to perform necessary state
  2293. * transitions and to release the ndlps associated with the @vport. Note,
  2294. * the physical port is treated as @vport 0.
  2295. **/
  2296. void
  2297. lpfc_cleanup(struct lpfc_vport *vport)
  2298. {
  2299. struct lpfc_hba *phba = vport->phba;
  2300. struct lpfc_nodelist *ndlp, *next_ndlp;
  2301. int i = 0;
  2302. if (phba->link_state > LPFC_LINK_DOWN)
  2303. lpfc_port_link_failure(vport);
  2304. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2305. if (!NLP_CHK_NODE_ACT(ndlp)) {
  2306. ndlp = lpfc_enable_node(vport, ndlp,
  2307. NLP_STE_UNUSED_NODE);
  2308. if (!ndlp)
  2309. continue;
  2310. spin_lock_irq(&phba->ndlp_lock);
  2311. NLP_SET_FREE_REQ(ndlp);
  2312. spin_unlock_irq(&phba->ndlp_lock);
  2313. /* Trigger the release of the ndlp memory */
  2314. lpfc_nlp_put(ndlp);
  2315. continue;
  2316. }
  2317. spin_lock_irq(&phba->ndlp_lock);
  2318. if (NLP_CHK_FREE_REQ(ndlp)) {
  2319. /* The ndlp should not be in memory free mode already */
  2320. spin_unlock_irq(&phba->ndlp_lock);
  2321. continue;
  2322. } else
  2323. /* Indicate request for freeing ndlp memory */
  2324. NLP_SET_FREE_REQ(ndlp);
  2325. spin_unlock_irq(&phba->ndlp_lock);
  2326. if (vport->port_type != LPFC_PHYSICAL_PORT &&
  2327. ndlp->nlp_DID == Fabric_DID) {
  2328. /* Just free up ndlp with Fabric_DID for vports */
  2329. lpfc_nlp_put(ndlp);
  2330. continue;
  2331. }
  2332. /* take care of nodes in unused state before the state
  2333. * machine taking action.
  2334. */
  2335. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  2336. lpfc_nlp_put(ndlp);
  2337. continue;
  2338. }
  2339. if (ndlp->nlp_type & NLP_FABRIC)
  2340. lpfc_disc_state_machine(vport, ndlp, NULL,
  2341. NLP_EVT_DEVICE_RECOVERY);
  2342. lpfc_disc_state_machine(vport, ndlp, NULL,
  2343. NLP_EVT_DEVICE_RM);
  2344. }
  2345. /* At this point, ALL ndlp's should be gone
  2346. * because of the previous NLP_EVT_DEVICE_RM.
  2347. * Lets wait for this to happen, if needed.
  2348. */
  2349. while (!list_empty(&vport->fc_nodes)) {
  2350. if (i++ > 3000) {
  2351. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2352. "0233 Nodelist not empty\n");
  2353. list_for_each_entry_safe(ndlp, next_ndlp,
  2354. &vport->fc_nodes, nlp_listp) {
  2355. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  2356. LOG_NODE,
  2357. "0282 did:x%x ndlp:x%p "
  2358. "usgmap:x%x refcnt:%d\n",
  2359. ndlp->nlp_DID, (void *)ndlp,
  2360. ndlp->nlp_usg_map,
  2361. atomic_read(
  2362. &ndlp->kref.refcount));
  2363. }
  2364. break;
  2365. }
  2366. /* Wait for any activity on ndlps to settle */
  2367. msleep(10);
  2368. }
  2369. lpfc_cleanup_vports_rrqs(vport, NULL);
  2370. }
  2371. /**
  2372. * lpfc_stop_vport_timers - Stop all the timers associated with a vport
  2373. * @vport: pointer to a virtual N_Port data structure.
  2374. *
  2375. * This routine stops all the timers associated with a @vport. This function
  2376. * is invoked before disabling or deleting a @vport. Note that the physical
  2377. * port is treated as @vport 0.
  2378. **/
  2379. void
  2380. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  2381. {
  2382. del_timer_sync(&vport->els_tmofunc);
  2383. del_timer_sync(&vport->fc_fdmitmo);
  2384. del_timer_sync(&vport->delayed_disc_tmo);
  2385. lpfc_can_disctmo(vport);
  2386. return;
  2387. }
  2388. /**
  2389. * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
  2390. * @phba: pointer to lpfc hba data structure.
  2391. *
  2392. * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
  2393. * caller of this routine should already hold the host lock.
  2394. **/
  2395. void
  2396. __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
  2397. {
  2398. /* Clear pending FCF rediscovery wait flag */
  2399. phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
  2400. /* Now, try to stop the timer */
  2401. del_timer(&phba->fcf.redisc_wait);
  2402. }
  2403. /**
  2404. * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
  2405. * @phba: pointer to lpfc hba data structure.
  2406. *
  2407. * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
  2408. * checks whether the FCF rediscovery wait timer is pending with the host
  2409. * lock held before proceeding with disabling the timer and clearing the
  2410. * wait timer pendig flag.
  2411. **/
  2412. void
  2413. lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
  2414. {
  2415. spin_lock_irq(&phba->hbalock);
  2416. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
  2417. /* FCF rediscovery timer already fired or stopped */
  2418. spin_unlock_irq(&phba->hbalock);
  2419. return;
  2420. }
  2421. __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
  2422. /* Clear failover in progress flags */
  2423. phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
  2424. spin_unlock_irq(&phba->hbalock);
  2425. }
  2426. /**
  2427. * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
  2428. * @phba: pointer to lpfc hba data structure.
  2429. *
  2430. * This routine stops all the timers associated with a HBA. This function is
  2431. * invoked before either putting a HBA offline or unloading the driver.
  2432. **/
  2433. void
  2434. lpfc_stop_hba_timers(struct lpfc_hba *phba)
  2435. {
  2436. lpfc_stop_vport_timers(phba->pport);
  2437. del_timer_sync(&phba->sli.mbox_tmo);
  2438. del_timer_sync(&phba->fabric_block_timer);
  2439. del_timer_sync(&phba->eratt_poll);
  2440. del_timer_sync(&phba->hb_tmofunc);
  2441. if (phba->sli_rev == LPFC_SLI_REV4) {
  2442. del_timer_sync(&phba->rrq_tmr);
  2443. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  2444. }
  2445. phba->hb_outstanding = 0;
  2446. switch (phba->pci_dev_grp) {
  2447. case LPFC_PCI_DEV_LP:
  2448. /* Stop any LightPulse device specific driver timers */
  2449. del_timer_sync(&phba->fcp_poll_timer);
  2450. break;
  2451. case LPFC_PCI_DEV_OC:
  2452. /* Stop any OneConnect device sepcific driver timers */
  2453. lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
  2454. break;
  2455. default:
  2456. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2457. "0297 Invalid device group (x%x)\n",
  2458. phba->pci_dev_grp);
  2459. break;
  2460. }
  2461. return;
  2462. }
  2463. /**
  2464. * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
  2465. * @phba: pointer to lpfc hba data structure.
  2466. *
  2467. * This routine marks a HBA's management interface as blocked. Once the HBA's
  2468. * management interface is marked as blocked, all the user space access to
  2469. * the HBA, whether they are from sysfs interface or libdfc interface will
  2470. * all be blocked. The HBA is set to block the management interface when the
  2471. * driver prepares the HBA interface for online or offline.
  2472. **/
  2473. static void
  2474. lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
  2475. {
  2476. unsigned long iflag;
  2477. uint8_t actcmd = MBX_HEARTBEAT;
  2478. unsigned long timeout;
  2479. spin_lock_irqsave(&phba->hbalock, iflag);
  2480. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  2481. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2482. if (mbx_action == LPFC_MBX_NO_WAIT)
  2483. return;
  2484. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  2485. spin_lock_irqsave(&phba->hbalock, iflag);
  2486. if (phba->sli.mbox_active) {
  2487. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  2488. /* Determine how long we might wait for the active mailbox
  2489. * command to be gracefully completed by firmware.
  2490. */
  2491. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  2492. phba->sli.mbox_active) * 1000) + jiffies;
  2493. }
  2494. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2495. /* Wait for the outstnading mailbox command to complete */
  2496. while (phba->sli.mbox_active) {
  2497. /* Check active mailbox complete status every 2ms */
  2498. msleep(2);
  2499. if (time_after(jiffies, timeout)) {
  2500. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2501. "2813 Mgmt IO is Blocked %x "
  2502. "- mbox cmd %x still active\n",
  2503. phba->sli.sli_flag, actcmd);
  2504. break;
  2505. }
  2506. }
  2507. }
  2508. /**
  2509. * lpfc_sli4_node_prep - Assign RPIs for active nodes.
  2510. * @phba: pointer to lpfc hba data structure.
  2511. *
  2512. * Allocate RPIs for all active remote nodes. This is needed whenever
  2513. * an SLI4 adapter is reset and the driver is not unloading. Its purpose
  2514. * is to fixup the temporary rpi assignments.
  2515. **/
  2516. void
  2517. lpfc_sli4_node_prep(struct lpfc_hba *phba)
  2518. {
  2519. struct lpfc_nodelist *ndlp, *next_ndlp;
  2520. struct lpfc_vport **vports;
  2521. int i;
  2522. if (phba->sli_rev != LPFC_SLI_REV4)
  2523. return;
  2524. vports = lpfc_create_vport_work_array(phba);
  2525. if (vports != NULL) {
  2526. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2527. if (vports[i]->load_flag & FC_UNLOADING)
  2528. continue;
  2529. list_for_each_entry_safe(ndlp, next_ndlp,
  2530. &vports[i]->fc_nodes,
  2531. nlp_listp) {
  2532. if (NLP_CHK_NODE_ACT(ndlp))
  2533. ndlp->nlp_rpi =
  2534. lpfc_sli4_alloc_rpi(phba);
  2535. }
  2536. }
  2537. }
  2538. lpfc_destroy_vport_work_array(phba, vports);
  2539. }
  2540. /**
  2541. * lpfc_online - Initialize and bring a HBA online
  2542. * @phba: pointer to lpfc hba data structure.
  2543. *
  2544. * This routine initializes the HBA and brings a HBA online. During this
  2545. * process, the management interface is blocked to prevent user space access
  2546. * to the HBA interfering with the driver initialization.
  2547. *
  2548. * Return codes
  2549. * 0 - successful
  2550. * 1 - failed
  2551. **/
  2552. int
  2553. lpfc_online(struct lpfc_hba *phba)
  2554. {
  2555. struct lpfc_vport *vport;
  2556. struct lpfc_vport **vports;
  2557. int i;
  2558. bool vpis_cleared = false;
  2559. if (!phba)
  2560. return 0;
  2561. vport = phba->pport;
  2562. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  2563. return 0;
  2564. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2565. "0458 Bring Adapter online\n");
  2566. lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
  2567. if (!lpfc_sli_queue_setup(phba)) {
  2568. lpfc_unblock_mgmt_io(phba);
  2569. return 1;
  2570. }
  2571. if (phba->sli_rev == LPFC_SLI_REV4) {
  2572. if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
  2573. lpfc_unblock_mgmt_io(phba);
  2574. return 1;
  2575. }
  2576. spin_lock_irq(&phba->hbalock);
  2577. if (!phba->sli4_hba.max_cfg_param.vpi_used)
  2578. vpis_cleared = true;
  2579. spin_unlock_irq(&phba->hbalock);
  2580. } else {
  2581. if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
  2582. lpfc_unblock_mgmt_io(phba);
  2583. return 1;
  2584. }
  2585. }
  2586. vports = lpfc_create_vport_work_array(phba);
  2587. if (vports != NULL)
  2588. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2589. struct Scsi_Host *shost;
  2590. shost = lpfc_shost_from_vport(vports[i]);
  2591. spin_lock_irq(shost->host_lock);
  2592. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  2593. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  2594. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2595. if (phba->sli_rev == LPFC_SLI_REV4) {
  2596. vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  2597. if ((vpis_cleared) &&
  2598. (vports[i]->port_type !=
  2599. LPFC_PHYSICAL_PORT))
  2600. vports[i]->vpi = 0;
  2601. }
  2602. spin_unlock_irq(shost->host_lock);
  2603. }
  2604. lpfc_destroy_vport_work_array(phba, vports);
  2605. lpfc_unblock_mgmt_io(phba);
  2606. return 0;
  2607. }
  2608. /**
  2609. * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
  2610. * @phba: pointer to lpfc hba data structure.
  2611. *
  2612. * This routine marks a HBA's management interface as not blocked. Once the
  2613. * HBA's management interface is marked as not blocked, all the user space
  2614. * access to the HBA, whether they are from sysfs interface or libdfc
  2615. * interface will be allowed. The HBA is set to block the management interface
  2616. * when the driver prepares the HBA interface for online or offline and then
  2617. * set to unblock the management interface afterwards.
  2618. **/
  2619. void
  2620. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  2621. {
  2622. unsigned long iflag;
  2623. spin_lock_irqsave(&phba->hbalock, iflag);
  2624. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  2625. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2626. }
  2627. /**
  2628. * lpfc_offline_prep - Prepare a HBA to be brought offline
  2629. * @phba: pointer to lpfc hba data structure.
  2630. *
  2631. * This routine is invoked to prepare a HBA to be brought offline. It performs
  2632. * unregistration login to all the nodes on all vports and flushes the mailbox
  2633. * queue to make it ready to be brought offline.
  2634. **/
  2635. void
  2636. lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
  2637. {
  2638. struct lpfc_vport *vport = phba->pport;
  2639. struct lpfc_nodelist *ndlp, *next_ndlp;
  2640. struct lpfc_vport **vports;
  2641. struct Scsi_Host *shost;
  2642. int i;
  2643. if (vport->fc_flag & FC_OFFLINE_MODE)
  2644. return;
  2645. lpfc_block_mgmt_io(phba, mbx_action);
  2646. lpfc_linkdown(phba);
  2647. /* Issue an unreg_login to all nodes on all vports */
  2648. vports = lpfc_create_vport_work_array(phba);
  2649. if (vports != NULL) {
  2650. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2651. if (vports[i]->load_flag & FC_UNLOADING)
  2652. continue;
  2653. shost = lpfc_shost_from_vport(vports[i]);
  2654. spin_lock_irq(shost->host_lock);
  2655. vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
  2656. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2657. vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
  2658. spin_unlock_irq(shost->host_lock);
  2659. shost = lpfc_shost_from_vport(vports[i]);
  2660. list_for_each_entry_safe(ndlp, next_ndlp,
  2661. &vports[i]->fc_nodes,
  2662. nlp_listp) {
  2663. if (!NLP_CHK_NODE_ACT(ndlp))
  2664. continue;
  2665. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  2666. continue;
  2667. if (ndlp->nlp_type & NLP_FABRIC) {
  2668. lpfc_disc_state_machine(vports[i], ndlp,
  2669. NULL, NLP_EVT_DEVICE_RECOVERY);
  2670. lpfc_disc_state_machine(vports[i], ndlp,
  2671. NULL, NLP_EVT_DEVICE_RM);
  2672. }
  2673. spin_lock_irq(shost->host_lock);
  2674. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2675. spin_unlock_irq(shost->host_lock);
  2676. /*
  2677. * Whenever an SLI4 port goes offline, free the
  2678. * RPI. Get a new RPI when the adapter port
  2679. * comes back online.
  2680. */
  2681. if (phba->sli_rev == LPFC_SLI_REV4)
  2682. lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
  2683. lpfc_unreg_rpi(vports[i], ndlp);
  2684. }
  2685. }
  2686. }
  2687. lpfc_destroy_vport_work_array(phba, vports);
  2688. lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
  2689. }
  2690. /**
  2691. * lpfc_offline - Bring a HBA offline
  2692. * @phba: pointer to lpfc hba data structure.
  2693. *
  2694. * This routine actually brings a HBA offline. It stops all the timers
  2695. * associated with the HBA, brings down the SLI layer, and eventually
  2696. * marks the HBA as in offline state for the upper layer protocol.
  2697. **/
  2698. void
  2699. lpfc_offline(struct lpfc_hba *phba)
  2700. {
  2701. struct Scsi_Host *shost;
  2702. struct lpfc_vport **vports;
  2703. int i;
  2704. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  2705. return;
  2706. /* stop port and all timers associated with this hba */
  2707. lpfc_stop_port(phba);
  2708. vports = lpfc_create_vport_work_array(phba);
  2709. if (vports != NULL)
  2710. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  2711. lpfc_stop_vport_timers(vports[i]);
  2712. lpfc_destroy_vport_work_array(phba, vports);
  2713. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2714. "0460 Bring Adapter offline\n");
  2715. /* Bring down the SLI Layer and cleanup. The HBA is offline
  2716. now. */
  2717. lpfc_sli_hba_down(phba);
  2718. spin_lock_irq(&phba->hbalock);
  2719. phba->work_ha = 0;
  2720. spin_unlock_irq(&phba->hbalock);
  2721. vports = lpfc_create_vport_work_array(phba);
  2722. if (vports != NULL)
  2723. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2724. shost = lpfc_shost_from_vport(vports[i]);
  2725. spin_lock_irq(shost->host_lock);
  2726. vports[i]->work_port_events = 0;
  2727. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  2728. spin_unlock_irq(shost->host_lock);
  2729. }
  2730. lpfc_destroy_vport_work_array(phba, vports);
  2731. }
  2732. /**
  2733. * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
  2734. * @phba: pointer to lpfc hba data structure.
  2735. *
  2736. * This routine is to free all the SCSI buffers and IOCBs from the driver
  2737. * list back to kernel. It is called from lpfc_pci_remove_one to free
  2738. * the internal resources before the device is removed from the system.
  2739. **/
  2740. static void
  2741. lpfc_scsi_free(struct lpfc_hba *phba)
  2742. {
  2743. struct lpfc_scsi_buf *sb, *sb_next;
  2744. struct lpfc_iocbq *io, *io_next;
  2745. spin_lock_irq(&phba->hbalock);
  2746. /* Release all the lpfc_scsi_bufs maintained by this host. */
  2747. spin_lock(&phba->scsi_buf_list_put_lock);
  2748. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
  2749. list) {
  2750. list_del(&sb->list);
  2751. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  2752. sb->dma_handle);
  2753. kfree(sb);
  2754. phba->total_scsi_bufs--;
  2755. }
  2756. spin_unlock(&phba->scsi_buf_list_put_lock);
  2757. spin_lock(&phba->scsi_buf_list_get_lock);
  2758. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
  2759. list) {
  2760. list_del(&sb->list);
  2761. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  2762. sb->dma_handle);
  2763. kfree(sb);
  2764. phba->total_scsi_bufs--;
  2765. }
  2766. spin_unlock(&phba->scsi_buf_list_get_lock);
  2767. /* Release all the lpfc_iocbq entries maintained by this host. */
  2768. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  2769. list_del(&io->list);
  2770. kfree(io);
  2771. phba->total_iocbq_bufs--;
  2772. }
  2773. spin_unlock_irq(&phba->hbalock);
  2774. }
  2775. /**
  2776. * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
  2777. * @phba: pointer to lpfc hba data structure.
  2778. *
  2779. * This routine first calculates the sizes of the current els and allocated
  2780. * scsi sgl lists, and then goes through all sgls to updates the physical
  2781. * XRIs assigned due to port function reset. During port initialization, the
  2782. * current els and allocated scsi sgl lists are 0s.
  2783. *
  2784. * Return codes
  2785. * 0 - successful (for now, it always returns 0)
  2786. **/
  2787. int
  2788. lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
  2789. {
  2790. struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
  2791. struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
  2792. uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
  2793. LIST_HEAD(els_sgl_list);
  2794. LIST_HEAD(scsi_sgl_list);
  2795. int rc;
  2796. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  2797. /*
  2798. * update on pci function's els xri-sgl list
  2799. */
  2800. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  2801. if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
  2802. /* els xri-sgl expanded */
  2803. xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
  2804. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2805. "3157 ELS xri-sgl count increased from "
  2806. "%d to %d\n", phba->sli4_hba.els_xri_cnt,
  2807. els_xri_cnt);
  2808. /* allocate the additional els sgls */
  2809. for (i = 0; i < xri_cnt; i++) {
  2810. sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
  2811. GFP_KERNEL);
  2812. if (sglq_entry == NULL) {
  2813. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2814. "2562 Failure to allocate an "
  2815. "ELS sgl entry:%d\n", i);
  2816. rc = -ENOMEM;
  2817. goto out_free_mem;
  2818. }
  2819. sglq_entry->buff_type = GEN_BUFF_TYPE;
  2820. sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
  2821. &sglq_entry->phys);
  2822. if (sglq_entry->virt == NULL) {
  2823. kfree(sglq_entry);
  2824. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2825. "2563 Failure to allocate an "
  2826. "ELS mbuf:%d\n", i);
  2827. rc = -ENOMEM;
  2828. goto out_free_mem;
  2829. }
  2830. sglq_entry->sgl = sglq_entry->virt;
  2831. memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
  2832. sglq_entry->state = SGL_FREED;
  2833. list_add_tail(&sglq_entry->list, &els_sgl_list);
  2834. }
  2835. spin_lock_irq(&phba->hbalock);
  2836. spin_lock(&pring->ring_lock);
  2837. list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
  2838. spin_unlock(&pring->ring_lock);
  2839. spin_unlock_irq(&phba->hbalock);
  2840. } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
  2841. /* els xri-sgl shrinked */
  2842. xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
  2843. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2844. "3158 ELS xri-sgl count decreased from "
  2845. "%d to %d\n", phba->sli4_hba.els_xri_cnt,
  2846. els_xri_cnt);
  2847. spin_lock_irq(&phba->hbalock);
  2848. spin_lock(&pring->ring_lock);
  2849. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
  2850. spin_unlock(&pring->ring_lock);
  2851. spin_unlock_irq(&phba->hbalock);
  2852. /* release extra els sgls from list */
  2853. for (i = 0; i < xri_cnt; i++) {
  2854. list_remove_head(&els_sgl_list,
  2855. sglq_entry, struct lpfc_sglq, list);
  2856. if (sglq_entry) {
  2857. lpfc_mbuf_free(phba, sglq_entry->virt,
  2858. sglq_entry->phys);
  2859. kfree(sglq_entry);
  2860. }
  2861. }
  2862. spin_lock_irq(&phba->hbalock);
  2863. spin_lock(&pring->ring_lock);
  2864. list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
  2865. spin_unlock(&pring->ring_lock);
  2866. spin_unlock_irq(&phba->hbalock);
  2867. } else
  2868. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2869. "3163 ELS xri-sgl count unchanged: %d\n",
  2870. els_xri_cnt);
  2871. phba->sli4_hba.els_xri_cnt = els_xri_cnt;
  2872. /* update xris to els sgls on the list */
  2873. sglq_entry = NULL;
  2874. sglq_entry_next = NULL;
  2875. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  2876. &phba->sli4_hba.lpfc_sgl_list, list) {
  2877. lxri = lpfc_sli4_next_xritag(phba);
  2878. if (lxri == NO_XRI) {
  2879. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2880. "2400 Failed to allocate xri for "
  2881. "ELS sgl\n");
  2882. rc = -ENOMEM;
  2883. goto out_free_mem;
  2884. }
  2885. sglq_entry->sli4_lxritag = lxri;
  2886. sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  2887. }
  2888. /*
  2889. * update on pci function's allocated scsi xri-sgl list
  2890. */
  2891. phba->total_scsi_bufs = 0;
  2892. /* maximum number of xris available for scsi buffers */
  2893. phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
  2894. els_xri_cnt;
  2895. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2896. "2401 Current allocated SCSI xri-sgl count:%d, "
  2897. "maximum SCSI xri count:%d\n",
  2898. phba->sli4_hba.scsi_xri_cnt,
  2899. phba->sli4_hba.scsi_xri_max);
  2900. spin_lock_irq(&phba->scsi_buf_list_get_lock);
  2901. spin_lock(&phba->scsi_buf_list_put_lock);
  2902. list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
  2903. list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
  2904. spin_unlock(&phba->scsi_buf_list_put_lock);
  2905. spin_unlock_irq(&phba->scsi_buf_list_get_lock);
  2906. if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
  2907. /* max scsi xri shrinked below the allocated scsi buffers */
  2908. scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
  2909. phba->sli4_hba.scsi_xri_max;
  2910. /* release the extra allocated scsi buffers */
  2911. for (i = 0; i < scsi_xri_cnt; i++) {
  2912. list_remove_head(&scsi_sgl_list, psb,
  2913. struct lpfc_scsi_buf, list);
  2914. if (psb) {
  2915. pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
  2916. psb->data, psb->dma_handle);
  2917. kfree(psb);
  2918. }
  2919. }
  2920. spin_lock_irq(&phba->scsi_buf_list_get_lock);
  2921. phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
  2922. spin_unlock_irq(&phba->scsi_buf_list_get_lock);
  2923. }
  2924. /* update xris associated to remaining allocated scsi buffers */
  2925. psb = NULL;
  2926. psb_next = NULL;
  2927. list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
  2928. lxri = lpfc_sli4_next_xritag(phba);
  2929. if (lxri == NO_XRI) {
  2930. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2931. "2560 Failed to allocate xri for "
  2932. "scsi buffer\n");
  2933. rc = -ENOMEM;
  2934. goto out_free_mem;
  2935. }
  2936. psb->cur_iocbq.sli4_lxritag = lxri;
  2937. psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  2938. }
  2939. spin_lock_irq(&phba->scsi_buf_list_get_lock);
  2940. spin_lock(&phba->scsi_buf_list_put_lock);
  2941. list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
  2942. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
  2943. spin_unlock(&phba->scsi_buf_list_put_lock);
  2944. spin_unlock_irq(&phba->scsi_buf_list_get_lock);
  2945. return 0;
  2946. out_free_mem:
  2947. lpfc_free_els_sgl_list(phba);
  2948. lpfc_scsi_free(phba);
  2949. return rc;
  2950. }
  2951. /**
  2952. * lpfc_create_port - Create an FC port
  2953. * @phba: pointer to lpfc hba data structure.
  2954. * @instance: a unique integer ID to this FC port.
  2955. * @dev: pointer to the device data structure.
  2956. *
  2957. * This routine creates a FC port for the upper layer protocol. The FC port
  2958. * can be created on top of either a physical port or a virtual port provided
  2959. * by the HBA. This routine also allocates a SCSI host data structure (shost)
  2960. * and associates the FC port created before adding the shost into the SCSI
  2961. * layer.
  2962. *
  2963. * Return codes
  2964. * @vport - pointer to the virtual N_Port data structure.
  2965. * NULL - port create failed.
  2966. **/
  2967. struct lpfc_vport *
  2968. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  2969. {
  2970. struct lpfc_vport *vport;
  2971. struct Scsi_Host *shost;
  2972. int error = 0;
  2973. if (dev != &phba->pcidev->dev)
  2974. shost = scsi_host_alloc(&lpfc_vport_template,
  2975. sizeof(struct lpfc_vport));
  2976. else
  2977. shost = scsi_host_alloc(&lpfc_template,
  2978. sizeof(struct lpfc_vport));
  2979. if (!shost)
  2980. goto out;
  2981. vport = (struct lpfc_vport *) shost->hostdata;
  2982. vport->phba = phba;
  2983. vport->load_flag |= FC_LOADING;
  2984. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2985. vport->fc_rscn_flush = 0;
  2986. lpfc_get_vport_cfgparam(vport);
  2987. shost->unique_id = instance;
  2988. shost->max_id = LPFC_MAX_TARGET;
  2989. shost->max_lun = vport->cfg_max_luns;
  2990. shost->this_id = -1;
  2991. shost->max_cmd_len = 16;
  2992. if (phba->sli_rev == LPFC_SLI_REV4) {
  2993. shost->dma_boundary =
  2994. phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
  2995. shost->sg_tablesize = phba->cfg_sg_seg_cnt;
  2996. }
  2997. /*
  2998. * Set initial can_queue value since 0 is no longer supported and
  2999. * scsi_add_host will fail. This will be adjusted later based on the
  3000. * max xri value determined in hba setup.
  3001. */
  3002. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  3003. if (dev != &phba->pcidev->dev) {
  3004. shost->transportt = lpfc_vport_transport_template;
  3005. vport->port_type = LPFC_NPIV_PORT;
  3006. } else {
  3007. shost->transportt = lpfc_transport_template;
  3008. vport->port_type = LPFC_PHYSICAL_PORT;
  3009. }
  3010. /* Initialize all internally managed lists. */
  3011. INIT_LIST_HEAD(&vport->fc_nodes);
  3012. INIT_LIST_HEAD(&vport->rcv_buffer_list);
  3013. spin_lock_init(&vport->work_port_lock);
  3014. init_timer(&vport->fc_disctmo);
  3015. vport->fc_disctmo.function = lpfc_disc_timeout;
  3016. vport->fc_disctmo.data = (unsigned long)vport;
  3017. init_timer(&vport->fc_fdmitmo);
  3018. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  3019. vport->fc_fdmitmo.data = (unsigned long)vport;
  3020. init_timer(&vport->els_tmofunc);
  3021. vport->els_tmofunc.function = lpfc_els_timeout;
  3022. vport->els_tmofunc.data = (unsigned long)vport;
  3023. init_timer(&vport->delayed_disc_tmo);
  3024. vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
  3025. vport->delayed_disc_tmo.data = (unsigned long)vport;
  3026. error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
  3027. if (error)
  3028. goto out_put_shost;
  3029. spin_lock_irq(&phba->hbalock);
  3030. list_add_tail(&vport->listentry, &phba->port_list);
  3031. spin_unlock_irq(&phba->hbalock);
  3032. return vport;
  3033. out_put_shost:
  3034. scsi_host_put(shost);
  3035. out:
  3036. return NULL;
  3037. }
  3038. /**
  3039. * destroy_port - destroy an FC port
  3040. * @vport: pointer to an lpfc virtual N_Port data structure.
  3041. *
  3042. * This routine destroys a FC port from the upper layer protocol. All the
  3043. * resources associated with the port are released.
  3044. **/
  3045. void
  3046. destroy_port(struct lpfc_vport *vport)
  3047. {
  3048. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3049. struct lpfc_hba *phba = vport->phba;
  3050. lpfc_debugfs_terminate(vport);
  3051. fc_remove_host(shost);
  3052. scsi_remove_host(shost);
  3053. spin_lock_irq(&phba->hbalock);
  3054. list_del_init(&vport->listentry);
  3055. spin_unlock_irq(&phba->hbalock);
  3056. lpfc_cleanup(vport);
  3057. return;
  3058. }
  3059. /**
  3060. * lpfc_get_instance - Get a unique integer ID
  3061. *
  3062. * This routine allocates a unique integer ID from lpfc_hba_index pool. It
  3063. * uses the kernel idr facility to perform the task.
  3064. *
  3065. * Return codes:
  3066. * instance - a unique integer ID allocated as the new instance.
  3067. * -1 - lpfc get instance failed.
  3068. **/
  3069. int
  3070. lpfc_get_instance(void)
  3071. {
  3072. int ret;
  3073. ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
  3074. return ret < 0 ? -1 : ret;
  3075. }
  3076. /**
  3077. * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
  3078. * @shost: pointer to SCSI host data structure.
  3079. * @time: elapsed time of the scan in jiffies.
  3080. *
  3081. * This routine is called by the SCSI layer with a SCSI host to determine
  3082. * whether the scan host is finished.
  3083. *
  3084. * Note: there is no scan_start function as adapter initialization will have
  3085. * asynchronously kicked off the link initialization.
  3086. *
  3087. * Return codes
  3088. * 0 - SCSI host scan is not over yet.
  3089. * 1 - SCSI host scan is over.
  3090. **/
  3091. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  3092. {
  3093. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3094. struct lpfc_hba *phba = vport->phba;
  3095. int stat = 0;
  3096. spin_lock_irq(shost->host_lock);
  3097. if (vport->load_flag & FC_UNLOADING) {
  3098. stat = 1;
  3099. goto finished;
  3100. }
  3101. if (time >= msecs_to_jiffies(30 * 1000)) {
  3102. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3103. "0461 Scanning longer than 30 "
  3104. "seconds. Continuing initialization\n");
  3105. stat = 1;
  3106. goto finished;
  3107. }
  3108. if (time >= msecs_to_jiffies(15 * 1000) &&
  3109. phba->link_state <= LPFC_LINK_DOWN) {
  3110. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3111. "0465 Link down longer than 15 "
  3112. "seconds. Continuing initialization\n");
  3113. stat = 1;
  3114. goto finished;
  3115. }
  3116. if (vport->port_state != LPFC_VPORT_READY)
  3117. goto finished;
  3118. if (vport->num_disc_nodes || vport->fc_prli_sent)
  3119. goto finished;
  3120. if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
  3121. goto finished;
  3122. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  3123. goto finished;
  3124. stat = 1;
  3125. finished:
  3126. spin_unlock_irq(shost->host_lock);
  3127. return stat;
  3128. }
  3129. /**
  3130. * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
  3131. * @shost: pointer to SCSI host data structure.
  3132. *
  3133. * This routine initializes a given SCSI host attributes on a FC port. The
  3134. * SCSI host can be either on top of a physical port or a virtual port.
  3135. **/
  3136. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  3137. {
  3138. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3139. struct lpfc_hba *phba = vport->phba;
  3140. /*
  3141. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  3142. */
  3143. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  3144. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  3145. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  3146. memset(fc_host_supported_fc4s(shost), 0,
  3147. sizeof(fc_host_supported_fc4s(shost)));
  3148. fc_host_supported_fc4s(shost)[2] = 1;
  3149. fc_host_supported_fc4s(shost)[7] = 1;
  3150. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  3151. sizeof fc_host_symbolic_name(shost));
  3152. fc_host_supported_speeds(shost) = 0;
  3153. if (phba->lmt & LMT_16Gb)
  3154. fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
  3155. if (phba->lmt & LMT_10Gb)
  3156. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  3157. if (phba->lmt & LMT_8Gb)
  3158. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  3159. if (phba->lmt & LMT_4Gb)
  3160. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  3161. if (phba->lmt & LMT_2Gb)
  3162. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  3163. if (phba->lmt & LMT_1Gb)
  3164. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  3165. fc_host_maxframe_size(shost) =
  3166. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  3167. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  3168. fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
  3169. /* This value is also unchanging */
  3170. memset(fc_host_active_fc4s(shost), 0,
  3171. sizeof(fc_host_active_fc4s(shost)));
  3172. fc_host_active_fc4s(shost)[2] = 1;
  3173. fc_host_active_fc4s(shost)[7] = 1;
  3174. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  3175. spin_lock_irq(shost->host_lock);
  3176. vport->load_flag &= ~FC_LOADING;
  3177. spin_unlock_irq(shost->host_lock);
  3178. }
  3179. /**
  3180. * lpfc_stop_port_s3 - Stop SLI3 device port
  3181. * @phba: pointer to lpfc hba data structure.
  3182. *
  3183. * This routine is invoked to stop an SLI3 device port, it stops the device
  3184. * from generating interrupts and stops the device driver's timers for the
  3185. * device.
  3186. **/
  3187. static void
  3188. lpfc_stop_port_s3(struct lpfc_hba *phba)
  3189. {
  3190. /* Clear all interrupt enable conditions */
  3191. writel(0, phba->HCregaddr);
  3192. readl(phba->HCregaddr); /* flush */
  3193. /* Clear all pending interrupts */
  3194. writel(0xffffffff, phba->HAregaddr);
  3195. readl(phba->HAregaddr); /* flush */
  3196. /* Reset some HBA SLI setup states */
  3197. lpfc_stop_hba_timers(phba);
  3198. phba->pport->work_port_events = 0;
  3199. }
  3200. /**
  3201. * lpfc_stop_port_s4 - Stop SLI4 device port
  3202. * @phba: pointer to lpfc hba data structure.
  3203. *
  3204. * This routine is invoked to stop an SLI4 device port, it stops the device
  3205. * from generating interrupts and stops the device driver's timers for the
  3206. * device.
  3207. **/
  3208. static void
  3209. lpfc_stop_port_s4(struct lpfc_hba *phba)
  3210. {
  3211. /* Reset some HBA SLI4 setup states */
  3212. lpfc_stop_hba_timers(phba);
  3213. phba->pport->work_port_events = 0;
  3214. phba->sli4_hba.intr_enable = 0;
  3215. }
  3216. /**
  3217. * lpfc_stop_port - Wrapper function for stopping hba port
  3218. * @phba: Pointer to HBA context object.
  3219. *
  3220. * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
  3221. * the API jump table function pointer from the lpfc_hba struct.
  3222. **/
  3223. void
  3224. lpfc_stop_port(struct lpfc_hba *phba)
  3225. {
  3226. phba->lpfc_stop_port(phba);
  3227. }
  3228. /**
  3229. * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
  3230. * @phba: Pointer to hba for which this call is being executed.
  3231. *
  3232. * This routine starts the timer waiting for the FCF rediscovery to complete.
  3233. **/
  3234. void
  3235. lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
  3236. {
  3237. unsigned long fcf_redisc_wait_tmo =
  3238. (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
  3239. /* Start fcf rediscovery wait period timer */
  3240. mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
  3241. spin_lock_irq(&phba->hbalock);
  3242. /* Allow action to new fcf asynchronous event */
  3243. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
  3244. /* Mark the FCF rediscovery pending state */
  3245. phba->fcf.fcf_flag |= FCF_REDISC_PEND;
  3246. spin_unlock_irq(&phba->hbalock);
  3247. }
  3248. /**
  3249. * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
  3250. * @ptr: Map to lpfc_hba data structure pointer.
  3251. *
  3252. * This routine is invoked when waiting for FCF table rediscover has been
  3253. * timed out. If new FCF record(s) has (have) been discovered during the
  3254. * wait period, a new FCF event shall be added to the FCOE async event
  3255. * list, and then worker thread shall be waked up for processing from the
  3256. * worker thread context.
  3257. **/
  3258. static void
  3259. lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
  3260. {
  3261. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  3262. /* Don't send FCF rediscovery event if timer cancelled */
  3263. spin_lock_irq(&phba->hbalock);
  3264. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
  3265. spin_unlock_irq(&phba->hbalock);
  3266. return;
  3267. }
  3268. /* Clear FCF rediscovery timer pending flag */
  3269. phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
  3270. /* FCF rediscovery event to worker thread */
  3271. phba->fcf.fcf_flag |= FCF_REDISC_EVT;
  3272. spin_unlock_irq(&phba->hbalock);
  3273. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  3274. "2776 FCF rediscover quiescent timer expired\n");
  3275. /* wake up worker thread */
  3276. lpfc_worker_wake_up(phba);
  3277. }
  3278. /**
  3279. * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
  3280. * @phba: pointer to lpfc hba data structure.
  3281. * @acqe_link: pointer to the async link completion queue entry.
  3282. *
  3283. * This routine is to parse the SLI4 link-attention link fault code and
  3284. * translate it into the base driver's read link attention mailbox command
  3285. * status.
  3286. *
  3287. * Return: Link-attention status in terms of base driver's coding.
  3288. **/
  3289. static uint16_t
  3290. lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
  3291. struct lpfc_acqe_link *acqe_link)
  3292. {
  3293. uint16_t latt_fault;
  3294. switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
  3295. case LPFC_ASYNC_LINK_FAULT_NONE:
  3296. case LPFC_ASYNC_LINK_FAULT_LOCAL:
  3297. case LPFC_ASYNC_LINK_FAULT_REMOTE:
  3298. latt_fault = 0;
  3299. break;
  3300. default:
  3301. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3302. "0398 Invalid link fault code: x%x\n",
  3303. bf_get(lpfc_acqe_link_fault, acqe_link));
  3304. latt_fault = MBXERR_ERROR;
  3305. break;
  3306. }
  3307. return latt_fault;
  3308. }
  3309. /**
  3310. * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
  3311. * @phba: pointer to lpfc hba data structure.
  3312. * @acqe_link: pointer to the async link completion queue entry.
  3313. *
  3314. * This routine is to parse the SLI4 link attention type and translate it
  3315. * into the base driver's link attention type coding.
  3316. *
  3317. * Return: Link attention type in terms of base driver's coding.
  3318. **/
  3319. static uint8_t
  3320. lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
  3321. struct lpfc_acqe_link *acqe_link)
  3322. {
  3323. uint8_t att_type;
  3324. switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
  3325. case LPFC_ASYNC_LINK_STATUS_DOWN:
  3326. case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
  3327. att_type = LPFC_ATT_LINK_DOWN;
  3328. break;
  3329. case LPFC_ASYNC_LINK_STATUS_UP:
  3330. /* Ignore physical link up events - wait for logical link up */
  3331. att_type = LPFC_ATT_RESERVED;
  3332. break;
  3333. case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
  3334. att_type = LPFC_ATT_LINK_UP;
  3335. break;
  3336. default:
  3337. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3338. "0399 Invalid link attention type: x%x\n",
  3339. bf_get(lpfc_acqe_link_status, acqe_link));
  3340. att_type = LPFC_ATT_RESERVED;
  3341. break;
  3342. }
  3343. return att_type;
  3344. }
  3345. /**
  3346. * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
  3347. * @phba: pointer to lpfc hba data structure.
  3348. * @acqe_link: pointer to the async link completion queue entry.
  3349. *
  3350. * This routine is to parse the SLI4 link-attention link speed and translate
  3351. * it into the base driver's link-attention link speed coding.
  3352. *
  3353. * Return: Link-attention link speed in terms of base driver's coding.
  3354. **/
  3355. static uint8_t
  3356. lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
  3357. struct lpfc_acqe_link *acqe_link)
  3358. {
  3359. uint8_t link_speed;
  3360. switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
  3361. case LPFC_ASYNC_LINK_SPEED_ZERO:
  3362. case LPFC_ASYNC_LINK_SPEED_10MBPS:
  3363. case LPFC_ASYNC_LINK_SPEED_100MBPS:
  3364. link_speed = LPFC_LINK_SPEED_UNKNOWN;
  3365. break;
  3366. case LPFC_ASYNC_LINK_SPEED_1GBPS:
  3367. link_speed = LPFC_LINK_SPEED_1GHZ;
  3368. break;
  3369. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  3370. link_speed = LPFC_LINK_SPEED_10GHZ;
  3371. break;
  3372. default:
  3373. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3374. "0483 Invalid link-attention link speed: x%x\n",
  3375. bf_get(lpfc_acqe_link_speed, acqe_link));
  3376. link_speed = LPFC_LINK_SPEED_UNKNOWN;
  3377. break;
  3378. }
  3379. return link_speed;
  3380. }
  3381. /**
  3382. * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
  3383. * @phba: pointer to lpfc hba data structure.
  3384. *
  3385. * This routine is to get an SLI3 FC port's link speed in Mbps.
  3386. *
  3387. * Return: link speed in terms of Mbps.
  3388. **/
  3389. uint32_t
  3390. lpfc_sli_port_speed_get(struct lpfc_hba *phba)
  3391. {
  3392. uint32_t link_speed;
  3393. if (!lpfc_is_link_up(phba))
  3394. return 0;
  3395. switch (phba->fc_linkspeed) {
  3396. case LPFC_LINK_SPEED_1GHZ:
  3397. link_speed = 1000;
  3398. break;
  3399. case LPFC_LINK_SPEED_2GHZ:
  3400. link_speed = 2000;
  3401. break;
  3402. case LPFC_LINK_SPEED_4GHZ:
  3403. link_speed = 4000;
  3404. break;
  3405. case LPFC_LINK_SPEED_8GHZ:
  3406. link_speed = 8000;
  3407. break;
  3408. case LPFC_LINK_SPEED_10GHZ:
  3409. link_speed = 10000;
  3410. break;
  3411. case LPFC_LINK_SPEED_16GHZ:
  3412. link_speed = 16000;
  3413. break;
  3414. default:
  3415. link_speed = 0;
  3416. }
  3417. return link_speed;
  3418. }
  3419. /**
  3420. * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
  3421. * @phba: pointer to lpfc hba data structure.
  3422. * @evt_code: asynchronous event code.
  3423. * @speed_code: asynchronous event link speed code.
  3424. *
  3425. * This routine is to parse the giving SLI4 async event link speed code into
  3426. * value of Mbps for the link speed.
  3427. *
  3428. * Return: link speed in terms of Mbps.
  3429. **/
  3430. static uint32_t
  3431. lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
  3432. uint8_t speed_code)
  3433. {
  3434. uint32_t port_speed;
  3435. switch (evt_code) {
  3436. case LPFC_TRAILER_CODE_LINK:
  3437. switch (speed_code) {
  3438. case LPFC_EVT_CODE_LINK_NO_LINK:
  3439. port_speed = 0;
  3440. break;
  3441. case LPFC_EVT_CODE_LINK_10_MBIT:
  3442. port_speed = 10;
  3443. break;
  3444. case LPFC_EVT_CODE_LINK_100_MBIT:
  3445. port_speed = 100;
  3446. break;
  3447. case LPFC_EVT_CODE_LINK_1_GBIT:
  3448. port_speed = 1000;
  3449. break;
  3450. case LPFC_EVT_CODE_LINK_10_GBIT:
  3451. port_speed = 10000;
  3452. break;
  3453. default:
  3454. port_speed = 0;
  3455. }
  3456. break;
  3457. case LPFC_TRAILER_CODE_FC:
  3458. switch (speed_code) {
  3459. case LPFC_EVT_CODE_FC_NO_LINK:
  3460. port_speed = 0;
  3461. break;
  3462. case LPFC_EVT_CODE_FC_1_GBAUD:
  3463. port_speed = 1000;
  3464. break;
  3465. case LPFC_EVT_CODE_FC_2_GBAUD:
  3466. port_speed = 2000;
  3467. break;
  3468. case LPFC_EVT_CODE_FC_4_GBAUD:
  3469. port_speed = 4000;
  3470. break;
  3471. case LPFC_EVT_CODE_FC_8_GBAUD:
  3472. port_speed = 8000;
  3473. break;
  3474. case LPFC_EVT_CODE_FC_10_GBAUD:
  3475. port_speed = 10000;
  3476. break;
  3477. case LPFC_EVT_CODE_FC_16_GBAUD:
  3478. port_speed = 16000;
  3479. break;
  3480. default:
  3481. port_speed = 0;
  3482. }
  3483. break;
  3484. default:
  3485. port_speed = 0;
  3486. }
  3487. return port_speed;
  3488. }
  3489. /**
  3490. * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
  3491. * @phba: pointer to lpfc hba data structure.
  3492. * @acqe_link: pointer to the async link completion queue entry.
  3493. *
  3494. * This routine is to handle the SLI4 asynchronous FCoE link event.
  3495. **/
  3496. static void
  3497. lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
  3498. struct lpfc_acqe_link *acqe_link)
  3499. {
  3500. struct lpfc_dmabuf *mp;
  3501. LPFC_MBOXQ_t *pmb;
  3502. MAILBOX_t *mb;
  3503. struct lpfc_mbx_read_top *la;
  3504. uint8_t att_type;
  3505. int rc;
  3506. att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
  3507. if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
  3508. return;
  3509. phba->fcoe_eventtag = acqe_link->event_tag;
  3510. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3511. if (!pmb) {
  3512. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3513. "0395 The mboxq allocation failed\n");
  3514. return;
  3515. }
  3516. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3517. if (!mp) {
  3518. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3519. "0396 The lpfc_dmabuf allocation failed\n");
  3520. goto out_free_pmb;
  3521. }
  3522. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  3523. if (!mp->virt) {
  3524. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3525. "0397 The mbuf allocation failed\n");
  3526. goto out_free_dmabuf;
  3527. }
  3528. /* Cleanup any outstanding ELS commands */
  3529. lpfc_els_flush_all_cmd(phba);
  3530. /* Block ELS IOCBs until we have done process link event */
  3531. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  3532. /* Update link event statistics */
  3533. phba->sli.slistat.link_event++;
  3534. /* Create lpfc_handle_latt mailbox command from link ACQE */
  3535. lpfc_read_topology(phba, pmb, mp);
  3536. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  3537. pmb->vport = phba->pport;
  3538. /* Keep the link status for extra SLI4 state machine reference */
  3539. phba->sli4_hba.link_state.speed =
  3540. lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
  3541. bf_get(lpfc_acqe_link_speed, acqe_link));
  3542. phba->sli4_hba.link_state.duplex =
  3543. bf_get(lpfc_acqe_link_duplex, acqe_link);
  3544. phba->sli4_hba.link_state.status =
  3545. bf_get(lpfc_acqe_link_status, acqe_link);
  3546. phba->sli4_hba.link_state.type =
  3547. bf_get(lpfc_acqe_link_type, acqe_link);
  3548. phba->sli4_hba.link_state.number =
  3549. bf_get(lpfc_acqe_link_number, acqe_link);
  3550. phba->sli4_hba.link_state.fault =
  3551. bf_get(lpfc_acqe_link_fault, acqe_link);
  3552. phba->sli4_hba.link_state.logical_speed =
  3553. bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
  3554. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3555. "2900 Async FC/FCoE Link event - Speed:%dGBit "
  3556. "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
  3557. "Logical speed:%dMbps Fault:%d\n",
  3558. phba->sli4_hba.link_state.speed,
  3559. phba->sli4_hba.link_state.topology,
  3560. phba->sli4_hba.link_state.status,
  3561. phba->sli4_hba.link_state.type,
  3562. phba->sli4_hba.link_state.number,
  3563. phba->sli4_hba.link_state.logical_speed,
  3564. phba->sli4_hba.link_state.fault);
  3565. /*
  3566. * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
  3567. * topology info. Note: Optional for non FC-AL ports.
  3568. */
  3569. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  3570. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3571. if (rc == MBX_NOT_FINISHED)
  3572. goto out_free_dmabuf;
  3573. return;
  3574. }
  3575. /*
  3576. * For FCoE Mode: fill in all the topology information we need and call
  3577. * the READ_TOPOLOGY completion routine to continue without actually
  3578. * sending the READ_TOPOLOGY mailbox command to the port.
  3579. */
  3580. /* Parse and translate status field */
  3581. mb = &pmb->u.mb;
  3582. mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
  3583. /* Parse and translate link attention fields */
  3584. la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
  3585. la->eventTag = acqe_link->event_tag;
  3586. bf_set(lpfc_mbx_read_top_att_type, la, att_type);
  3587. bf_set(lpfc_mbx_read_top_link_spd, la,
  3588. lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
  3589. /* Fake the the following irrelvant fields */
  3590. bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
  3591. bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
  3592. bf_set(lpfc_mbx_read_top_il, la, 0);
  3593. bf_set(lpfc_mbx_read_top_pb, la, 0);
  3594. bf_set(lpfc_mbx_read_top_fa, la, 0);
  3595. bf_set(lpfc_mbx_read_top_mm, la, 0);
  3596. /* Invoke the lpfc_handle_latt mailbox command callback function */
  3597. lpfc_mbx_cmpl_read_topology(phba, pmb);
  3598. return;
  3599. out_free_dmabuf:
  3600. kfree(mp);
  3601. out_free_pmb:
  3602. mempool_free(pmb, phba->mbox_mem_pool);
  3603. }
  3604. /**
  3605. * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
  3606. * @phba: pointer to lpfc hba data structure.
  3607. * @acqe_fc: pointer to the async fc completion queue entry.
  3608. *
  3609. * This routine is to handle the SLI4 asynchronous FC event. It will simply log
  3610. * that the event was received and then issue a read_topology mailbox command so
  3611. * that the rest of the driver will treat it the same as SLI3.
  3612. **/
  3613. static void
  3614. lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
  3615. {
  3616. struct lpfc_dmabuf *mp;
  3617. LPFC_MBOXQ_t *pmb;
  3618. int rc;
  3619. if (bf_get(lpfc_trailer_type, acqe_fc) !=
  3620. LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
  3621. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3622. "2895 Non FC link Event detected.(%d)\n",
  3623. bf_get(lpfc_trailer_type, acqe_fc));
  3624. return;
  3625. }
  3626. /* Keep the link status for extra SLI4 state machine reference */
  3627. phba->sli4_hba.link_state.speed =
  3628. lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
  3629. bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
  3630. phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
  3631. phba->sli4_hba.link_state.topology =
  3632. bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
  3633. phba->sli4_hba.link_state.status =
  3634. bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
  3635. phba->sli4_hba.link_state.type =
  3636. bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
  3637. phba->sli4_hba.link_state.number =
  3638. bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
  3639. phba->sli4_hba.link_state.fault =
  3640. bf_get(lpfc_acqe_link_fault, acqe_fc);
  3641. phba->sli4_hba.link_state.logical_speed =
  3642. bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
  3643. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3644. "2896 Async FC event - Speed:%dGBaud Topology:x%x "
  3645. "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
  3646. "%dMbps Fault:%d\n",
  3647. phba->sli4_hba.link_state.speed,
  3648. phba->sli4_hba.link_state.topology,
  3649. phba->sli4_hba.link_state.status,
  3650. phba->sli4_hba.link_state.type,
  3651. phba->sli4_hba.link_state.number,
  3652. phba->sli4_hba.link_state.logical_speed,
  3653. phba->sli4_hba.link_state.fault);
  3654. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3655. if (!pmb) {
  3656. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3657. "2897 The mboxq allocation failed\n");
  3658. return;
  3659. }
  3660. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3661. if (!mp) {
  3662. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3663. "2898 The lpfc_dmabuf allocation failed\n");
  3664. goto out_free_pmb;
  3665. }
  3666. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  3667. if (!mp->virt) {
  3668. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3669. "2899 The mbuf allocation failed\n");
  3670. goto out_free_dmabuf;
  3671. }
  3672. /* Cleanup any outstanding ELS commands */
  3673. lpfc_els_flush_all_cmd(phba);
  3674. /* Block ELS IOCBs until we have done process link event */
  3675. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  3676. /* Update link event statistics */
  3677. phba->sli.slistat.link_event++;
  3678. /* Create lpfc_handle_latt mailbox command from link ACQE */
  3679. lpfc_read_topology(phba, pmb, mp);
  3680. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  3681. pmb->vport = phba->pport;
  3682. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3683. if (rc == MBX_NOT_FINISHED)
  3684. goto out_free_dmabuf;
  3685. return;
  3686. out_free_dmabuf:
  3687. kfree(mp);
  3688. out_free_pmb:
  3689. mempool_free(pmb, phba->mbox_mem_pool);
  3690. }
  3691. /**
  3692. * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
  3693. * @phba: pointer to lpfc hba data structure.
  3694. * @acqe_fc: pointer to the async SLI completion queue entry.
  3695. *
  3696. * This routine is to handle the SLI4 asynchronous SLI events.
  3697. **/
  3698. static void
  3699. lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
  3700. {
  3701. char port_name;
  3702. char message[128];
  3703. uint8_t status;
  3704. struct lpfc_acqe_misconfigured_event *misconfigured;
  3705. /* special case misconfigured event as it contains data for all ports */
  3706. if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  3707. LPFC_SLI_INTF_IF_TYPE_2) ||
  3708. (bf_get(lpfc_trailer_type, acqe_sli) !=
  3709. LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) {
  3710. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3711. "2901 Async SLI event - Event Data1:x%08x Event Data2:"
  3712. "x%08x SLI Event Type:%d\n",
  3713. acqe_sli->event_data1, acqe_sli->event_data2,
  3714. bf_get(lpfc_trailer_type, acqe_sli));
  3715. return;
  3716. }
  3717. port_name = phba->Port[0];
  3718. if (port_name == 0x00)
  3719. port_name = '?'; /* get port name is empty */
  3720. misconfigured = (struct lpfc_acqe_misconfigured_event *)
  3721. &acqe_sli->event_data1;
  3722. /* fetch the status for this port */
  3723. switch (phba->sli4_hba.lnk_info.lnk_no) {
  3724. case LPFC_LINK_NUMBER_0:
  3725. status = bf_get(lpfc_sli_misconfigured_port0,
  3726. &misconfigured->theEvent);
  3727. break;
  3728. case LPFC_LINK_NUMBER_1:
  3729. status = bf_get(lpfc_sli_misconfigured_port1,
  3730. &misconfigured->theEvent);
  3731. break;
  3732. case LPFC_LINK_NUMBER_2:
  3733. status = bf_get(lpfc_sli_misconfigured_port2,
  3734. &misconfigured->theEvent);
  3735. break;
  3736. case LPFC_LINK_NUMBER_3:
  3737. status = bf_get(lpfc_sli_misconfigured_port3,
  3738. &misconfigured->theEvent);
  3739. break;
  3740. default:
  3741. status = ~LPFC_SLI_EVENT_STATUS_VALID;
  3742. break;
  3743. }
  3744. switch (status) {
  3745. case LPFC_SLI_EVENT_STATUS_VALID:
  3746. return; /* no message if the sfp is okay */
  3747. case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
  3748. sprintf(message, "Optics faulted/incorrectly installed/not " \
  3749. "installed - Reseat optics, if issue not "
  3750. "resolved, replace.");
  3751. break;
  3752. case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
  3753. sprintf(message,
  3754. "Optics of two types installed - Remove one optic or " \
  3755. "install matching pair of optics.");
  3756. break;
  3757. case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
  3758. sprintf(message, "Incompatible optics - Replace with " \
  3759. "compatible optics for card to function.");
  3760. break;
  3761. default:
  3762. /* firmware is reporting a status we don't know about */
  3763. sprintf(message, "Unknown event status x%02x", status);
  3764. break;
  3765. }
  3766. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3767. "3176 Misconfigured Physical Port - "
  3768. "Port Name %c %s\n", port_name, message);
  3769. }
  3770. /**
  3771. * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
  3772. * @vport: pointer to vport data structure.
  3773. *
  3774. * This routine is to perform Clear Virtual Link (CVL) on a vport in
  3775. * response to a CVL event.
  3776. *
  3777. * Return the pointer to the ndlp with the vport if successful, otherwise
  3778. * return NULL.
  3779. **/
  3780. static struct lpfc_nodelist *
  3781. lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
  3782. {
  3783. struct lpfc_nodelist *ndlp;
  3784. struct Scsi_Host *shost;
  3785. struct lpfc_hba *phba;
  3786. if (!vport)
  3787. return NULL;
  3788. phba = vport->phba;
  3789. if (!phba)
  3790. return NULL;
  3791. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  3792. if (!ndlp) {
  3793. /* Cannot find existing Fabric ndlp, so allocate a new one */
  3794. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3795. if (!ndlp)
  3796. return 0;
  3797. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  3798. /* Set the node type */
  3799. ndlp->nlp_type |= NLP_FABRIC;
  3800. /* Put ndlp onto node list */
  3801. lpfc_enqueue_node(vport, ndlp);
  3802. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3803. /* re-setup ndlp without removing from node list */
  3804. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  3805. if (!ndlp)
  3806. return 0;
  3807. }
  3808. if ((phba->pport->port_state < LPFC_FLOGI) &&
  3809. (phba->pport->port_state != LPFC_VPORT_FAILED))
  3810. return NULL;
  3811. /* If virtual link is not yet instantiated ignore CVL */
  3812. if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
  3813. && (vport->port_state != LPFC_VPORT_FAILED))
  3814. return NULL;
  3815. shost = lpfc_shost_from_vport(vport);
  3816. if (!shost)
  3817. return NULL;
  3818. lpfc_linkdown_port(vport);
  3819. lpfc_cleanup_pending_mbox(vport);
  3820. spin_lock_irq(shost->host_lock);
  3821. vport->fc_flag |= FC_VPORT_CVL_RCVD;
  3822. spin_unlock_irq(shost->host_lock);
  3823. return ndlp;
  3824. }
  3825. /**
  3826. * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
  3827. * @vport: pointer to lpfc hba data structure.
  3828. *
  3829. * This routine is to perform Clear Virtual Link (CVL) on all vports in
  3830. * response to a FCF dead event.
  3831. **/
  3832. static void
  3833. lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
  3834. {
  3835. struct lpfc_vport **vports;
  3836. int i;
  3837. vports = lpfc_create_vport_work_array(phba);
  3838. if (vports)
  3839. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  3840. lpfc_sli4_perform_vport_cvl(vports[i]);
  3841. lpfc_destroy_vport_work_array(phba, vports);
  3842. }
  3843. /**
  3844. * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
  3845. * @phba: pointer to lpfc hba data structure.
  3846. * @acqe_link: pointer to the async fcoe completion queue entry.
  3847. *
  3848. * This routine is to handle the SLI4 asynchronous fcoe event.
  3849. **/
  3850. static void
  3851. lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
  3852. struct lpfc_acqe_fip *acqe_fip)
  3853. {
  3854. uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
  3855. int rc;
  3856. struct lpfc_vport *vport;
  3857. struct lpfc_nodelist *ndlp;
  3858. struct Scsi_Host *shost;
  3859. int active_vlink_present;
  3860. struct lpfc_vport **vports;
  3861. int i;
  3862. phba->fc_eventTag = acqe_fip->event_tag;
  3863. phba->fcoe_eventtag = acqe_fip->event_tag;
  3864. switch (event_type) {
  3865. case LPFC_FIP_EVENT_TYPE_NEW_FCF:
  3866. case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
  3867. if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
  3868. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3869. LOG_DISCOVERY,
  3870. "2546 New FCF event, evt_tag:x%x, "
  3871. "index:x%x\n",
  3872. acqe_fip->event_tag,
  3873. acqe_fip->index);
  3874. else
  3875. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
  3876. LOG_DISCOVERY,
  3877. "2788 FCF param modified event, "
  3878. "evt_tag:x%x, index:x%x\n",
  3879. acqe_fip->event_tag,
  3880. acqe_fip->index);
  3881. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3882. /*
  3883. * During period of FCF discovery, read the FCF
  3884. * table record indexed by the event to update
  3885. * FCF roundrobin failover eligible FCF bmask.
  3886. */
  3887. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  3888. LOG_DISCOVERY,
  3889. "2779 Read FCF (x%x) for updating "
  3890. "roundrobin FCF failover bmask\n",
  3891. acqe_fip->index);
  3892. rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
  3893. }
  3894. /* If the FCF discovery is in progress, do nothing. */
  3895. spin_lock_irq(&phba->hbalock);
  3896. if (phba->hba_flag & FCF_TS_INPROG) {
  3897. spin_unlock_irq(&phba->hbalock);
  3898. break;
  3899. }
  3900. /* If fast FCF failover rescan event is pending, do nothing */
  3901. if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
  3902. spin_unlock_irq(&phba->hbalock);
  3903. break;
  3904. }
  3905. /* If the FCF has been in discovered state, do nothing. */
  3906. if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
  3907. spin_unlock_irq(&phba->hbalock);
  3908. break;
  3909. }
  3910. spin_unlock_irq(&phba->hbalock);
  3911. /* Otherwise, scan the entire FCF table and re-discover SAN */
  3912. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3913. "2770 Start FCF table scan per async FCF "
  3914. "event, evt_tag:x%x, index:x%x\n",
  3915. acqe_fip->event_tag, acqe_fip->index);
  3916. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  3917. LPFC_FCOE_FCF_GET_FIRST);
  3918. if (rc)
  3919. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3920. "2547 Issue FCF scan read FCF mailbox "
  3921. "command failed (x%x)\n", rc);
  3922. break;
  3923. case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
  3924. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3925. "2548 FCF Table full count 0x%x tag 0x%x\n",
  3926. bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
  3927. acqe_fip->event_tag);
  3928. break;
  3929. case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
  3930. phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
  3931. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3932. "2549 FCF (x%x) disconnected from network, "
  3933. "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
  3934. /*
  3935. * If we are in the middle of FCF failover process, clear
  3936. * the corresponding FCF bit in the roundrobin bitmap.
  3937. */
  3938. spin_lock_irq(&phba->hbalock);
  3939. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3940. spin_unlock_irq(&phba->hbalock);
  3941. /* Update FLOGI FCF failover eligible FCF bmask */
  3942. lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
  3943. break;
  3944. }
  3945. spin_unlock_irq(&phba->hbalock);
  3946. /* If the event is not for currently used fcf do nothing */
  3947. if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
  3948. break;
  3949. /*
  3950. * Otherwise, request the port to rediscover the entire FCF
  3951. * table for a fast recovery from case that the current FCF
  3952. * is no longer valid as we are not in the middle of FCF
  3953. * failover process already.
  3954. */
  3955. spin_lock_irq(&phba->hbalock);
  3956. /* Mark the fast failover process in progress */
  3957. phba->fcf.fcf_flag |= FCF_DEAD_DISC;
  3958. spin_unlock_irq(&phba->hbalock);
  3959. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3960. "2771 Start FCF fast failover process due to "
  3961. "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
  3962. "\n", acqe_fip->event_tag, acqe_fip->index);
  3963. rc = lpfc_sli4_redisc_fcf_table(phba);
  3964. if (rc) {
  3965. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3966. LOG_DISCOVERY,
  3967. "2772 Issue FCF rediscover mabilbox "
  3968. "command failed, fail through to FCF "
  3969. "dead event\n");
  3970. spin_lock_irq(&phba->hbalock);
  3971. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  3972. spin_unlock_irq(&phba->hbalock);
  3973. /*
  3974. * Last resort will fail over by treating this
  3975. * as a link down to FCF registration.
  3976. */
  3977. lpfc_sli4_fcf_dead_failthrough(phba);
  3978. } else {
  3979. /* Reset FCF roundrobin bmask for new discovery */
  3980. lpfc_sli4_clear_fcf_rr_bmask(phba);
  3981. /*
  3982. * Handling fast FCF failover to a DEAD FCF event is
  3983. * considered equalivant to receiving CVL to all vports.
  3984. */
  3985. lpfc_sli4_perform_all_vport_cvl(phba);
  3986. }
  3987. break;
  3988. case LPFC_FIP_EVENT_TYPE_CVL:
  3989. phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
  3990. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3991. "2718 Clear Virtual Link Received for VPI 0x%x"
  3992. " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
  3993. vport = lpfc_find_vport_by_vpid(phba,
  3994. acqe_fip->index);
  3995. ndlp = lpfc_sli4_perform_vport_cvl(vport);
  3996. if (!ndlp)
  3997. break;
  3998. active_vlink_present = 0;
  3999. vports = lpfc_create_vport_work_array(phba);
  4000. if (vports) {
  4001. for (i = 0; i <= phba->max_vports && vports[i] != NULL;
  4002. i++) {
  4003. if ((!(vports[i]->fc_flag &
  4004. FC_VPORT_CVL_RCVD)) &&
  4005. (vports[i]->port_state > LPFC_FDISC)) {
  4006. active_vlink_present = 1;
  4007. break;
  4008. }
  4009. }
  4010. lpfc_destroy_vport_work_array(phba, vports);
  4011. }
  4012. if (active_vlink_present) {
  4013. /*
  4014. * If there are other active VLinks present,
  4015. * re-instantiate the Vlink using FDISC.
  4016. */
  4017. mod_timer(&ndlp->nlp_delayfunc,
  4018. jiffies + msecs_to_jiffies(1000));
  4019. shost = lpfc_shost_from_vport(vport);
  4020. spin_lock_irq(shost->host_lock);
  4021. ndlp->nlp_flag |= NLP_DELAY_TMO;
  4022. spin_unlock_irq(shost->host_lock);
  4023. ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
  4024. vport->port_state = LPFC_FDISC;
  4025. } else {
  4026. /*
  4027. * Otherwise, we request port to rediscover
  4028. * the entire FCF table for a fast recovery
  4029. * from possible case that the current FCF
  4030. * is no longer valid if we are not already
  4031. * in the FCF failover process.
  4032. */
  4033. spin_lock_irq(&phba->hbalock);
  4034. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  4035. spin_unlock_irq(&phba->hbalock);
  4036. break;
  4037. }
  4038. /* Mark the fast failover process in progress */
  4039. phba->fcf.fcf_flag |= FCF_ACVL_DISC;
  4040. spin_unlock_irq(&phba->hbalock);
  4041. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  4042. LOG_DISCOVERY,
  4043. "2773 Start FCF failover per CVL, "
  4044. "evt_tag:x%x\n", acqe_fip->event_tag);
  4045. rc = lpfc_sli4_redisc_fcf_table(phba);
  4046. if (rc) {
  4047. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  4048. LOG_DISCOVERY,
  4049. "2774 Issue FCF rediscover "
  4050. "mabilbox command failed, "
  4051. "through to CVL event\n");
  4052. spin_lock_irq(&phba->hbalock);
  4053. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  4054. spin_unlock_irq(&phba->hbalock);
  4055. /*
  4056. * Last resort will be re-try on the
  4057. * the current registered FCF entry.
  4058. */
  4059. lpfc_retry_pport_discovery(phba);
  4060. } else
  4061. /*
  4062. * Reset FCF roundrobin bmask for new
  4063. * discovery.
  4064. */
  4065. lpfc_sli4_clear_fcf_rr_bmask(phba);
  4066. }
  4067. break;
  4068. default:
  4069. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4070. "0288 Unknown FCoE event type 0x%x event tag "
  4071. "0x%x\n", event_type, acqe_fip->event_tag);
  4072. break;
  4073. }
  4074. }
  4075. /**
  4076. * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
  4077. * @phba: pointer to lpfc hba data structure.
  4078. * @acqe_link: pointer to the async dcbx completion queue entry.
  4079. *
  4080. * This routine is to handle the SLI4 asynchronous dcbx event.
  4081. **/
  4082. static void
  4083. lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
  4084. struct lpfc_acqe_dcbx *acqe_dcbx)
  4085. {
  4086. phba->fc_eventTag = acqe_dcbx->event_tag;
  4087. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4088. "0290 The SLI4 DCBX asynchronous event is not "
  4089. "handled yet\n");
  4090. }
  4091. /**
  4092. * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
  4093. * @phba: pointer to lpfc hba data structure.
  4094. * @acqe_link: pointer to the async grp5 completion queue entry.
  4095. *
  4096. * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
  4097. * is an asynchronous notified of a logical link speed change. The Port
  4098. * reports the logical link speed in units of 10Mbps.
  4099. **/
  4100. static void
  4101. lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
  4102. struct lpfc_acqe_grp5 *acqe_grp5)
  4103. {
  4104. uint16_t prev_ll_spd;
  4105. phba->fc_eventTag = acqe_grp5->event_tag;
  4106. phba->fcoe_eventtag = acqe_grp5->event_tag;
  4107. prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
  4108. phba->sli4_hba.link_state.logical_speed =
  4109. (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
  4110. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4111. "2789 GRP5 Async Event: Updating logical link speed "
  4112. "from %dMbps to %dMbps\n", prev_ll_spd,
  4113. phba->sli4_hba.link_state.logical_speed);
  4114. }
  4115. /**
  4116. * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
  4117. * @phba: pointer to lpfc hba data structure.
  4118. *
  4119. * This routine is invoked by the worker thread to process all the pending
  4120. * SLI4 asynchronous events.
  4121. **/
  4122. void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
  4123. {
  4124. struct lpfc_cq_event *cq_event;
  4125. /* First, declare the async event has been handled */
  4126. spin_lock_irq(&phba->hbalock);
  4127. phba->hba_flag &= ~ASYNC_EVENT;
  4128. spin_unlock_irq(&phba->hbalock);
  4129. /* Now, handle all the async events */
  4130. while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
  4131. /* Get the first event from the head of the event queue */
  4132. spin_lock_irq(&phba->hbalock);
  4133. list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
  4134. cq_event, struct lpfc_cq_event, list);
  4135. spin_unlock_irq(&phba->hbalock);
  4136. /* Process the asynchronous event */
  4137. switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
  4138. case LPFC_TRAILER_CODE_LINK:
  4139. lpfc_sli4_async_link_evt(phba,
  4140. &cq_event->cqe.acqe_link);
  4141. break;
  4142. case LPFC_TRAILER_CODE_FCOE:
  4143. lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
  4144. break;
  4145. case LPFC_TRAILER_CODE_DCBX:
  4146. lpfc_sli4_async_dcbx_evt(phba,
  4147. &cq_event->cqe.acqe_dcbx);
  4148. break;
  4149. case LPFC_TRAILER_CODE_GRP5:
  4150. lpfc_sli4_async_grp5_evt(phba,
  4151. &cq_event->cqe.acqe_grp5);
  4152. break;
  4153. case LPFC_TRAILER_CODE_FC:
  4154. lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
  4155. break;
  4156. case LPFC_TRAILER_CODE_SLI:
  4157. lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
  4158. break;
  4159. default:
  4160. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4161. "1804 Invalid asynchrous event code: "
  4162. "x%x\n", bf_get(lpfc_trailer_code,
  4163. &cq_event->cqe.mcqe_cmpl));
  4164. break;
  4165. }
  4166. /* Free the completion event processed to the free pool */
  4167. lpfc_sli4_cq_event_release(phba, cq_event);
  4168. }
  4169. }
  4170. /**
  4171. * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
  4172. * @phba: pointer to lpfc hba data structure.
  4173. *
  4174. * This routine is invoked by the worker thread to process FCF table
  4175. * rediscovery pending completion event.
  4176. **/
  4177. void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
  4178. {
  4179. int rc;
  4180. spin_lock_irq(&phba->hbalock);
  4181. /* Clear FCF rediscovery timeout event */
  4182. phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
  4183. /* Clear driver fast failover FCF record flag */
  4184. phba->fcf.failover_rec.flag = 0;
  4185. /* Set state for FCF fast failover */
  4186. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  4187. spin_unlock_irq(&phba->hbalock);
  4188. /* Scan FCF table from the first entry to re-discover SAN */
  4189. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  4190. "2777 Start post-quiescent FCF table scan\n");
  4191. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  4192. if (rc)
  4193. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  4194. "2747 Issue FCF scan read FCF mailbox "
  4195. "command failed 0x%x\n", rc);
  4196. }
  4197. /**
  4198. * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
  4199. * @phba: pointer to lpfc hba data structure.
  4200. * @dev_grp: The HBA PCI-Device group number.
  4201. *
  4202. * This routine is invoked to set up the per HBA PCI-Device group function
  4203. * API jump table entries.
  4204. *
  4205. * Return: 0 if success, otherwise -ENODEV
  4206. **/
  4207. int
  4208. lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4209. {
  4210. int rc;
  4211. /* Set up lpfc PCI-device group */
  4212. phba->pci_dev_grp = dev_grp;
  4213. /* The LPFC_PCI_DEV_OC uses SLI4 */
  4214. if (dev_grp == LPFC_PCI_DEV_OC)
  4215. phba->sli_rev = LPFC_SLI_REV4;
  4216. /* Set up device INIT API function jump table */
  4217. rc = lpfc_init_api_table_setup(phba, dev_grp);
  4218. if (rc)
  4219. return -ENODEV;
  4220. /* Set up SCSI API function jump table */
  4221. rc = lpfc_scsi_api_table_setup(phba, dev_grp);
  4222. if (rc)
  4223. return -ENODEV;
  4224. /* Set up SLI API function jump table */
  4225. rc = lpfc_sli_api_table_setup(phba, dev_grp);
  4226. if (rc)
  4227. return -ENODEV;
  4228. /* Set up MBOX API function jump table */
  4229. rc = lpfc_mbox_api_table_setup(phba, dev_grp);
  4230. if (rc)
  4231. return -ENODEV;
  4232. return 0;
  4233. }
  4234. /**
  4235. * lpfc_log_intr_mode - Log the active interrupt mode
  4236. * @phba: pointer to lpfc hba data structure.
  4237. * @intr_mode: active interrupt mode adopted.
  4238. *
  4239. * This routine it invoked to log the currently used active interrupt mode
  4240. * to the device.
  4241. **/
  4242. static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
  4243. {
  4244. switch (intr_mode) {
  4245. case 0:
  4246. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4247. "0470 Enable INTx interrupt mode.\n");
  4248. break;
  4249. case 1:
  4250. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4251. "0481 Enabled MSI interrupt mode.\n");
  4252. break;
  4253. case 2:
  4254. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4255. "0480 Enabled MSI-X interrupt mode.\n");
  4256. break;
  4257. default:
  4258. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4259. "0482 Illegal interrupt mode.\n");
  4260. break;
  4261. }
  4262. return;
  4263. }
  4264. /**
  4265. * lpfc_enable_pci_dev - Enable a generic PCI device.
  4266. * @phba: pointer to lpfc hba data structure.
  4267. *
  4268. * This routine is invoked to enable the PCI device that is common to all
  4269. * PCI devices.
  4270. *
  4271. * Return codes
  4272. * 0 - successful
  4273. * other values - error
  4274. **/
  4275. static int
  4276. lpfc_enable_pci_dev(struct lpfc_hba *phba)
  4277. {
  4278. struct pci_dev *pdev;
  4279. int bars = 0;
  4280. /* Obtain PCI device reference */
  4281. if (!phba->pcidev)
  4282. goto out_error;
  4283. else
  4284. pdev = phba->pcidev;
  4285. /* Select PCI BARs */
  4286. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  4287. /* Enable PCI device */
  4288. if (pci_enable_device_mem(pdev))
  4289. goto out_error;
  4290. /* Request PCI resource for the device */
  4291. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  4292. goto out_disable_device;
  4293. /* Set up device as PCI master and save state for EEH */
  4294. pci_set_master(pdev);
  4295. pci_try_set_mwi(pdev);
  4296. pci_save_state(pdev);
  4297. /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
  4298. if (pci_is_pcie(pdev))
  4299. pdev->needs_freset = 1;
  4300. return 0;
  4301. out_disable_device:
  4302. pci_disable_device(pdev);
  4303. out_error:
  4304. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4305. "1401 Failed to enable pci device, bars:x%x\n", bars);
  4306. return -ENODEV;
  4307. }
  4308. /**
  4309. * lpfc_disable_pci_dev - Disable a generic PCI device.
  4310. * @phba: pointer to lpfc hba data structure.
  4311. *
  4312. * This routine is invoked to disable the PCI device that is common to all
  4313. * PCI devices.
  4314. **/
  4315. static void
  4316. lpfc_disable_pci_dev(struct lpfc_hba *phba)
  4317. {
  4318. struct pci_dev *pdev;
  4319. int bars;
  4320. /* Obtain PCI device reference */
  4321. if (!phba->pcidev)
  4322. return;
  4323. else
  4324. pdev = phba->pcidev;
  4325. /* Select PCI BARs */
  4326. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  4327. /* Release PCI resource and disable PCI device */
  4328. pci_release_selected_regions(pdev, bars);
  4329. pci_disable_device(pdev);
  4330. return;
  4331. }
  4332. /**
  4333. * lpfc_reset_hba - Reset a hba
  4334. * @phba: pointer to lpfc hba data structure.
  4335. *
  4336. * This routine is invoked to reset a hba device. It brings the HBA
  4337. * offline, performs a board restart, and then brings the board back
  4338. * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
  4339. * on outstanding mailbox commands.
  4340. **/
  4341. void
  4342. lpfc_reset_hba(struct lpfc_hba *phba)
  4343. {
  4344. /* If resets are disabled then set error state and return. */
  4345. if (!phba->cfg_enable_hba_reset) {
  4346. phba->link_state = LPFC_HBA_ERROR;
  4347. return;
  4348. }
  4349. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  4350. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  4351. else
  4352. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  4353. lpfc_offline(phba);
  4354. lpfc_sli_brdrestart(phba);
  4355. lpfc_online(phba);
  4356. lpfc_unblock_mgmt_io(phba);
  4357. }
  4358. /**
  4359. * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
  4360. * @phba: pointer to lpfc hba data structure.
  4361. *
  4362. * This function enables the PCI SR-IOV virtual functions to a physical
  4363. * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
  4364. * enable the number of virtual functions to the physical function. As
  4365. * not all devices support SR-IOV, the return code from the pci_enable_sriov()
  4366. * API call does not considered as an error condition for most of the device.
  4367. **/
  4368. uint16_t
  4369. lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
  4370. {
  4371. struct pci_dev *pdev = phba->pcidev;
  4372. uint16_t nr_virtfn;
  4373. int pos;
  4374. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
  4375. if (pos == 0)
  4376. return 0;
  4377. pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
  4378. return nr_virtfn;
  4379. }
  4380. /**
  4381. * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
  4382. * @phba: pointer to lpfc hba data structure.
  4383. * @nr_vfn: number of virtual functions to be enabled.
  4384. *
  4385. * This function enables the PCI SR-IOV virtual functions to a physical
  4386. * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
  4387. * enable the number of virtual functions to the physical function. As
  4388. * not all devices support SR-IOV, the return code from the pci_enable_sriov()
  4389. * API call does not considered as an error condition for most of the device.
  4390. **/
  4391. int
  4392. lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
  4393. {
  4394. struct pci_dev *pdev = phba->pcidev;
  4395. uint16_t max_nr_vfn;
  4396. int rc;
  4397. max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
  4398. if (nr_vfn > max_nr_vfn) {
  4399. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4400. "3057 Requested vfs (%d) greater than "
  4401. "supported vfs (%d)", nr_vfn, max_nr_vfn);
  4402. return -EINVAL;
  4403. }
  4404. rc = pci_enable_sriov(pdev, nr_vfn);
  4405. if (rc) {
  4406. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4407. "2806 Failed to enable sriov on this device "
  4408. "with vfn number nr_vf:%d, rc:%d\n",
  4409. nr_vfn, rc);
  4410. } else
  4411. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4412. "2807 Successful enable sriov on this device "
  4413. "with vfn number nr_vf:%d\n", nr_vfn);
  4414. return rc;
  4415. }
  4416. /**
  4417. * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
  4418. * @phba: pointer to lpfc hba data structure.
  4419. *
  4420. * This routine is invoked to set up the driver internal resources specific to
  4421. * support the SLI-3 HBA device it attached to.
  4422. *
  4423. * Return codes
  4424. * 0 - successful
  4425. * other values - error
  4426. **/
  4427. static int
  4428. lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
  4429. {
  4430. struct lpfc_sli *psli;
  4431. int rc;
  4432. /*
  4433. * Initialize timers used by driver
  4434. */
  4435. /* Heartbeat timer */
  4436. init_timer(&phba->hb_tmofunc);
  4437. phba->hb_tmofunc.function = lpfc_hb_timeout;
  4438. phba->hb_tmofunc.data = (unsigned long)phba;
  4439. psli = &phba->sli;
  4440. /* MBOX heartbeat timer */
  4441. init_timer(&psli->mbox_tmo);
  4442. psli->mbox_tmo.function = lpfc_mbox_timeout;
  4443. psli->mbox_tmo.data = (unsigned long) phba;
  4444. /* FCP polling mode timer */
  4445. init_timer(&phba->fcp_poll_timer);
  4446. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  4447. phba->fcp_poll_timer.data = (unsigned long) phba;
  4448. /* Fabric block timer */
  4449. init_timer(&phba->fabric_block_timer);
  4450. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  4451. phba->fabric_block_timer.data = (unsigned long) phba;
  4452. /* EA polling mode timer */
  4453. init_timer(&phba->eratt_poll);
  4454. phba->eratt_poll.function = lpfc_poll_eratt;
  4455. phba->eratt_poll.data = (unsigned long) phba;
  4456. /* Host attention work mask setup */
  4457. phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
  4458. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  4459. /* Get all the module params for configuring this host */
  4460. lpfc_get_cfgparam(phba);
  4461. if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
  4462. phba->menlo_flag |= HBA_MENLO_SUPPORT;
  4463. /* check for menlo minimum sg count */
  4464. if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
  4465. phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
  4466. }
  4467. if (!phba->sli.ring)
  4468. phba->sli.ring = (struct lpfc_sli_ring *)
  4469. kzalloc(LPFC_SLI3_MAX_RING *
  4470. sizeof(struct lpfc_sli_ring), GFP_KERNEL);
  4471. if (!phba->sli.ring)
  4472. return -ENOMEM;
  4473. /*
  4474. * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
  4475. * used to create the sg_dma_buf_pool must be dynamically calculated.
  4476. */
  4477. /* Initialize the host templates the configured values. */
  4478. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4479. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4480. /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
  4481. if (phba->cfg_enable_bg) {
  4482. /*
  4483. * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
  4484. * the FCP rsp, and a BDE for each. Sice we have no control
  4485. * over how many protection data segments the SCSI Layer
  4486. * will hand us (ie: there could be one for every block
  4487. * in the IO), we just allocate enough BDEs to accomidate
  4488. * our max amount and we need to limit lpfc_sg_seg_cnt to
  4489. * minimize the risk of running out.
  4490. */
  4491. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4492. sizeof(struct fcp_rsp) +
  4493. (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
  4494. if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
  4495. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
  4496. /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
  4497. phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
  4498. } else {
  4499. /*
  4500. * The scsi_buf for a regular I/O will hold the FCP cmnd,
  4501. * the FCP rsp, a BDE for each, and a BDE for up to
  4502. * cfg_sg_seg_cnt data segments.
  4503. */
  4504. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4505. sizeof(struct fcp_rsp) +
  4506. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
  4507. /* Total BDEs in BPL for scsi_sg_list */
  4508. phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
  4509. }
  4510. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
  4511. "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
  4512. phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
  4513. phba->cfg_total_seg_cnt);
  4514. phba->max_vpi = LPFC_MAX_VPI;
  4515. /* This will be set to correct value after config_port mbox */
  4516. phba->max_vports = 0;
  4517. /*
  4518. * Initialize the SLI Layer to run with lpfc HBAs.
  4519. */
  4520. lpfc_sli_setup(phba);
  4521. lpfc_sli_queue_setup(phba);
  4522. /* Allocate device driver memory */
  4523. if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
  4524. return -ENOMEM;
  4525. /*
  4526. * Enable sr-iov virtual functions if supported and configured
  4527. * through the module parameter.
  4528. */
  4529. if (phba->cfg_sriov_nr_virtfn > 0) {
  4530. rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
  4531. phba->cfg_sriov_nr_virtfn);
  4532. if (rc) {
  4533. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4534. "2808 Requested number of SR-IOV "
  4535. "virtual functions (%d) is not "
  4536. "supported\n",
  4537. phba->cfg_sriov_nr_virtfn);
  4538. phba->cfg_sriov_nr_virtfn = 0;
  4539. }
  4540. }
  4541. return 0;
  4542. }
  4543. /**
  4544. * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
  4545. * @phba: pointer to lpfc hba data structure.
  4546. *
  4547. * This routine is invoked to unset the driver internal resources set up
  4548. * specific for supporting the SLI-3 HBA device it attached to.
  4549. **/
  4550. static void
  4551. lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
  4552. {
  4553. /* Free device driver memory allocated */
  4554. lpfc_mem_free_all(phba);
  4555. return;
  4556. }
  4557. /**
  4558. * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
  4559. * @phba: pointer to lpfc hba data structure.
  4560. *
  4561. * This routine is invoked to set up the driver internal resources specific to
  4562. * support the SLI-4 HBA device it attached to.
  4563. *
  4564. * Return codes
  4565. * 0 - successful
  4566. * other values - error
  4567. **/
  4568. static int
  4569. lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
  4570. {
  4571. struct lpfc_vector_map_info *cpup;
  4572. struct lpfc_sli *psli;
  4573. LPFC_MBOXQ_t *mboxq;
  4574. int rc, i, hbq_count, max_buf_size;
  4575. uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
  4576. struct lpfc_mqe *mqe;
  4577. int longs;
  4578. int fof_vectors = 0;
  4579. /* Get all the module params for configuring this host */
  4580. lpfc_get_cfgparam(phba);
  4581. /* Before proceed, wait for POST done and device ready */
  4582. rc = lpfc_sli4_post_status_check(phba);
  4583. if (rc)
  4584. return -ENODEV;
  4585. /*
  4586. * Initialize timers used by driver
  4587. */
  4588. /* Heartbeat timer */
  4589. init_timer(&phba->hb_tmofunc);
  4590. phba->hb_tmofunc.function = lpfc_hb_timeout;
  4591. phba->hb_tmofunc.data = (unsigned long)phba;
  4592. init_timer(&phba->rrq_tmr);
  4593. phba->rrq_tmr.function = lpfc_rrq_timeout;
  4594. phba->rrq_tmr.data = (unsigned long)phba;
  4595. psli = &phba->sli;
  4596. /* MBOX heartbeat timer */
  4597. init_timer(&psli->mbox_tmo);
  4598. psli->mbox_tmo.function = lpfc_mbox_timeout;
  4599. psli->mbox_tmo.data = (unsigned long) phba;
  4600. /* Fabric block timer */
  4601. init_timer(&phba->fabric_block_timer);
  4602. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  4603. phba->fabric_block_timer.data = (unsigned long) phba;
  4604. /* EA polling mode timer */
  4605. init_timer(&phba->eratt_poll);
  4606. phba->eratt_poll.function = lpfc_poll_eratt;
  4607. phba->eratt_poll.data = (unsigned long) phba;
  4608. /* FCF rediscover timer */
  4609. init_timer(&phba->fcf.redisc_wait);
  4610. phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
  4611. phba->fcf.redisc_wait.data = (unsigned long)phba;
  4612. /*
  4613. * Control structure for handling external multi-buffer mailbox
  4614. * command pass-through.
  4615. */
  4616. memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
  4617. sizeof(struct lpfc_mbox_ext_buf_ctx));
  4618. INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
  4619. phba->max_vpi = LPFC_MAX_VPI;
  4620. /* This will be set to correct value after the read_config mbox */
  4621. phba->max_vports = 0;
  4622. /* Program the default value of vlan_id and fc_map */
  4623. phba->valid_vlan = 0;
  4624. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4625. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4626. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4627. /*
  4628. * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
  4629. * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
  4630. */
  4631. if (!phba->sli.ring)
  4632. phba->sli.ring = kzalloc(
  4633. (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
  4634. sizeof(struct lpfc_sli_ring), GFP_KERNEL);
  4635. if (!phba->sli.ring)
  4636. return -ENOMEM;
  4637. /*
  4638. * It doesn't matter what family our adapter is in, we are
  4639. * limited to 2 Pages, 512 SGEs, for our SGL.
  4640. * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
  4641. */
  4642. max_buf_size = (2 * SLI4_PAGE_SIZE);
  4643. if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
  4644. phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
  4645. /*
  4646. * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
  4647. * used to create the sg_dma_buf_pool must be dynamically calculated.
  4648. */
  4649. if (phba->cfg_enable_bg) {
  4650. /*
  4651. * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
  4652. * the FCP rsp, and a SGE for each. Sice we have no control
  4653. * over how many protection data segments the SCSI Layer
  4654. * will hand us (ie: there could be one for every block
  4655. * in the IO), we just allocate enough SGEs to accomidate
  4656. * our max amount and we need to limit lpfc_sg_seg_cnt to
  4657. * minimize the risk of running out.
  4658. */
  4659. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4660. sizeof(struct fcp_rsp) + max_buf_size;
  4661. /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
  4662. phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
  4663. if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
  4664. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
  4665. } else {
  4666. /*
  4667. * The scsi_buf for a regular I/O will hold the FCP cmnd,
  4668. * the FCP rsp, a SGE for each, and a SGE for up to
  4669. * cfg_sg_seg_cnt data segments.
  4670. */
  4671. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4672. sizeof(struct fcp_rsp) +
  4673. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
  4674. /* Total SGEs for scsi_sg_list */
  4675. phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
  4676. /*
  4677. * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
  4678. * to post 1 page for the SGL.
  4679. */
  4680. }
  4681. /* Initialize the host templates with the updated values. */
  4682. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4683. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4684. if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
  4685. phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
  4686. else
  4687. phba->cfg_sg_dma_buf_size =
  4688. SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
  4689. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
  4690. "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
  4691. phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
  4692. phba->cfg_total_seg_cnt);
  4693. /* Initialize buffer queue management fields */
  4694. hbq_count = lpfc_sli_hbq_count();
  4695. for (i = 0; i < hbq_count; ++i)
  4696. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  4697. INIT_LIST_HEAD(&phba->rb_pend_list);
  4698. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
  4699. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
  4700. /*
  4701. * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
  4702. */
  4703. /* Initialize the Abort scsi buffer list used by driver */
  4704. spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
  4705. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  4706. /* This abort list used by worker thread */
  4707. spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
  4708. /*
  4709. * Initialize driver internal slow-path work queues
  4710. */
  4711. /* Driver internel slow-path CQ Event pool */
  4712. INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
  4713. /* Response IOCB work queue list */
  4714. INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
  4715. /* Asynchronous event CQ Event work queue list */
  4716. INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
  4717. /* Fast-path XRI aborted CQ Event work queue list */
  4718. INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  4719. /* Slow-path XRI aborted CQ Event work queue list */
  4720. INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
  4721. /* Receive queue CQ Event work queue list */
  4722. INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
  4723. /* Initialize extent block lists. */
  4724. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
  4725. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
  4726. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
  4727. INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
  4728. /* Initialize the driver internal SLI layer lists. */
  4729. lpfc_sli_setup(phba);
  4730. lpfc_sli_queue_setup(phba);
  4731. /* Allocate device driver memory */
  4732. rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
  4733. if (rc)
  4734. return -ENOMEM;
  4735. /* IF Type 2 ports get initialized now. */
  4736. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  4737. LPFC_SLI_INTF_IF_TYPE_2) {
  4738. rc = lpfc_pci_function_reset(phba);
  4739. if (unlikely(rc))
  4740. return -ENODEV;
  4741. }
  4742. /* Create the bootstrap mailbox command */
  4743. rc = lpfc_create_bootstrap_mbox(phba);
  4744. if (unlikely(rc))
  4745. goto out_free_mem;
  4746. /* Set up the host's endian order with the device. */
  4747. rc = lpfc_setup_endian_order(phba);
  4748. if (unlikely(rc))
  4749. goto out_free_bsmbx;
  4750. /* Set up the hba's configuration parameters. */
  4751. rc = lpfc_sli4_read_config(phba);
  4752. if (unlikely(rc))
  4753. goto out_free_bsmbx;
  4754. rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
  4755. if (unlikely(rc))
  4756. goto out_free_bsmbx;
  4757. /* IF Type 0 ports get initialized now. */
  4758. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  4759. LPFC_SLI_INTF_IF_TYPE_0) {
  4760. rc = lpfc_pci_function_reset(phba);
  4761. if (unlikely(rc))
  4762. goto out_free_bsmbx;
  4763. }
  4764. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  4765. GFP_KERNEL);
  4766. if (!mboxq) {
  4767. rc = -ENOMEM;
  4768. goto out_free_bsmbx;
  4769. }
  4770. /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
  4771. lpfc_supported_pages(mboxq);
  4772. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4773. if (!rc) {
  4774. mqe = &mboxq->u.mqe;
  4775. memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
  4776. LPFC_MAX_SUPPORTED_PAGES);
  4777. for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
  4778. switch (pn_page[i]) {
  4779. case LPFC_SLI4_PARAMETERS:
  4780. phba->sli4_hba.pc_sli4_params.supported = 1;
  4781. break;
  4782. default:
  4783. break;
  4784. }
  4785. }
  4786. /* Read the port's SLI4 Parameters capabilities if supported. */
  4787. if (phba->sli4_hba.pc_sli4_params.supported)
  4788. rc = lpfc_pc_sli4_params_get(phba, mboxq);
  4789. if (rc) {
  4790. mempool_free(mboxq, phba->mbox_mem_pool);
  4791. rc = -EIO;
  4792. goto out_free_bsmbx;
  4793. }
  4794. }
  4795. /*
  4796. * Get sli4 parameters that override parameters from Port capabilities.
  4797. * If this call fails, it isn't critical unless the SLI4 parameters come
  4798. * back in conflict.
  4799. */
  4800. rc = lpfc_get_sli4_parameters(phba, mboxq);
  4801. if (rc) {
  4802. if (phba->sli4_hba.extents_in_use &&
  4803. phba->sli4_hba.rpi_hdrs_in_use) {
  4804. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4805. "2999 Unsupported SLI4 Parameters "
  4806. "Extents and RPI headers enabled.\n");
  4807. goto out_free_bsmbx;
  4808. }
  4809. }
  4810. mempool_free(mboxq, phba->mbox_mem_pool);
  4811. /* Verify OAS is supported */
  4812. lpfc_sli4_oas_verify(phba);
  4813. if (phba->cfg_fof)
  4814. fof_vectors = 1;
  4815. /* Verify all the SLI4 queues */
  4816. rc = lpfc_sli4_queue_verify(phba);
  4817. if (rc)
  4818. goto out_free_bsmbx;
  4819. /* Create driver internal CQE event pool */
  4820. rc = lpfc_sli4_cq_event_pool_create(phba);
  4821. if (rc)
  4822. goto out_free_bsmbx;
  4823. /* Initialize sgl lists per host */
  4824. lpfc_init_sgl_list(phba);
  4825. /* Allocate and initialize active sgl array */
  4826. rc = lpfc_init_active_sgl_array(phba);
  4827. if (rc) {
  4828. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4829. "1430 Failed to initialize sgl list.\n");
  4830. goto out_destroy_cq_event_pool;
  4831. }
  4832. rc = lpfc_sli4_init_rpi_hdrs(phba);
  4833. if (rc) {
  4834. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4835. "1432 Failed to initialize rpi headers.\n");
  4836. goto out_free_active_sgl;
  4837. }
  4838. /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
  4839. longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
  4840. phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
  4841. GFP_KERNEL);
  4842. if (!phba->fcf.fcf_rr_bmask) {
  4843. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4844. "2759 Failed allocate memory for FCF round "
  4845. "robin failover bmask\n");
  4846. rc = -ENOMEM;
  4847. goto out_remove_rpi_hdrs;
  4848. }
  4849. phba->sli4_hba.fcp_eq_hdl =
  4850. kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
  4851. (fof_vectors + phba->cfg_fcp_io_channel)),
  4852. GFP_KERNEL);
  4853. if (!phba->sli4_hba.fcp_eq_hdl) {
  4854. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4855. "2572 Failed allocate memory for "
  4856. "fast-path per-EQ handle array\n");
  4857. rc = -ENOMEM;
  4858. goto out_free_fcf_rr_bmask;
  4859. }
  4860. phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
  4861. (fof_vectors +
  4862. phba->cfg_fcp_io_channel)), GFP_KERNEL);
  4863. if (!phba->sli4_hba.msix_entries) {
  4864. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4865. "2573 Failed allocate memory for msi-x "
  4866. "interrupt vector entries\n");
  4867. rc = -ENOMEM;
  4868. goto out_free_fcp_eq_hdl;
  4869. }
  4870. phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
  4871. phba->sli4_hba.num_present_cpu),
  4872. GFP_KERNEL);
  4873. if (!phba->sli4_hba.cpu_map) {
  4874. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4875. "3327 Failed allocate memory for msi-x "
  4876. "interrupt vector mapping\n");
  4877. rc = -ENOMEM;
  4878. goto out_free_msix;
  4879. }
  4880. if (lpfc_used_cpu == NULL) {
  4881. lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu),
  4882. GFP_KERNEL);
  4883. if (!lpfc_used_cpu) {
  4884. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4885. "3335 Failed allocate memory for msi-x "
  4886. "interrupt vector mapping\n");
  4887. kfree(phba->sli4_hba.cpu_map);
  4888. rc = -ENOMEM;
  4889. goto out_free_msix;
  4890. }
  4891. for (i = 0; i < lpfc_present_cpu; i++)
  4892. lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
  4893. }
  4894. /* Initialize io channels for round robin */
  4895. cpup = phba->sli4_hba.cpu_map;
  4896. rc = 0;
  4897. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  4898. cpup->channel_id = rc;
  4899. rc++;
  4900. if (rc >= phba->cfg_fcp_io_channel)
  4901. rc = 0;
  4902. }
  4903. /*
  4904. * Enable sr-iov virtual functions if supported and configured
  4905. * through the module parameter.
  4906. */
  4907. if (phba->cfg_sriov_nr_virtfn > 0) {
  4908. rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
  4909. phba->cfg_sriov_nr_virtfn);
  4910. if (rc) {
  4911. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4912. "3020 Requested number of SR-IOV "
  4913. "virtual functions (%d) is not "
  4914. "supported\n",
  4915. phba->cfg_sriov_nr_virtfn);
  4916. phba->cfg_sriov_nr_virtfn = 0;
  4917. }
  4918. }
  4919. return 0;
  4920. out_free_msix:
  4921. kfree(phba->sli4_hba.msix_entries);
  4922. out_free_fcp_eq_hdl:
  4923. kfree(phba->sli4_hba.fcp_eq_hdl);
  4924. out_free_fcf_rr_bmask:
  4925. kfree(phba->fcf.fcf_rr_bmask);
  4926. out_remove_rpi_hdrs:
  4927. lpfc_sli4_remove_rpi_hdrs(phba);
  4928. out_free_active_sgl:
  4929. lpfc_free_active_sgl(phba);
  4930. out_destroy_cq_event_pool:
  4931. lpfc_sli4_cq_event_pool_destroy(phba);
  4932. out_free_bsmbx:
  4933. lpfc_destroy_bootstrap_mbox(phba);
  4934. out_free_mem:
  4935. lpfc_mem_free(phba);
  4936. return rc;
  4937. }
  4938. /**
  4939. * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
  4940. * @phba: pointer to lpfc hba data structure.
  4941. *
  4942. * This routine is invoked to unset the driver internal resources set up
  4943. * specific for supporting the SLI-4 HBA device it attached to.
  4944. **/
  4945. static void
  4946. lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
  4947. {
  4948. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  4949. /* Free memory allocated for msi-x interrupt vector to CPU mapping */
  4950. kfree(phba->sli4_hba.cpu_map);
  4951. phba->sli4_hba.num_present_cpu = 0;
  4952. phba->sli4_hba.num_online_cpu = 0;
  4953. phba->sli4_hba.curr_disp_cpu = 0;
  4954. /* Free memory allocated for msi-x interrupt vector entries */
  4955. kfree(phba->sli4_hba.msix_entries);
  4956. /* Free memory allocated for fast-path work queue handles */
  4957. kfree(phba->sli4_hba.fcp_eq_hdl);
  4958. /* Free the allocated rpi headers. */
  4959. lpfc_sli4_remove_rpi_hdrs(phba);
  4960. lpfc_sli4_remove_rpis(phba);
  4961. /* Free eligible FCF index bmask */
  4962. kfree(phba->fcf.fcf_rr_bmask);
  4963. /* Free the ELS sgl list */
  4964. lpfc_free_active_sgl(phba);
  4965. lpfc_free_els_sgl_list(phba);
  4966. /* Free the completion queue EQ event pool */
  4967. lpfc_sli4_cq_event_release_all(phba);
  4968. lpfc_sli4_cq_event_pool_destroy(phba);
  4969. /* Release resource identifiers. */
  4970. lpfc_sli4_dealloc_resource_identifiers(phba);
  4971. /* Free the bsmbx region. */
  4972. lpfc_destroy_bootstrap_mbox(phba);
  4973. /* Free the SLI Layer memory with SLI4 HBAs */
  4974. lpfc_mem_free_all(phba);
  4975. /* Free the current connect table */
  4976. list_for_each_entry_safe(conn_entry, next_conn_entry,
  4977. &phba->fcf_conn_rec_list, list) {
  4978. list_del_init(&conn_entry->list);
  4979. kfree(conn_entry);
  4980. }
  4981. return;
  4982. }
  4983. /**
  4984. * lpfc_init_api_table_setup - Set up init api function jump table
  4985. * @phba: The hba struct for which this call is being executed.
  4986. * @dev_grp: The HBA PCI-Device group number.
  4987. *
  4988. * This routine sets up the device INIT interface API function jump table
  4989. * in @phba struct.
  4990. *
  4991. * Returns: 0 - success, -ENODEV - failure.
  4992. **/
  4993. int
  4994. lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4995. {
  4996. phba->lpfc_hba_init_link = lpfc_hba_init_link;
  4997. phba->lpfc_hba_down_link = lpfc_hba_down_link;
  4998. phba->lpfc_selective_reset = lpfc_selective_reset;
  4999. switch (dev_grp) {
  5000. case LPFC_PCI_DEV_LP:
  5001. phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
  5002. phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
  5003. phba->lpfc_stop_port = lpfc_stop_port_s3;
  5004. break;
  5005. case LPFC_PCI_DEV_OC:
  5006. phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
  5007. phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
  5008. phba->lpfc_stop_port = lpfc_stop_port_s4;
  5009. break;
  5010. default:
  5011. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5012. "1431 Invalid HBA PCI-device group: 0x%x\n",
  5013. dev_grp);
  5014. return -ENODEV;
  5015. break;
  5016. }
  5017. return 0;
  5018. }
  5019. /**
  5020. * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
  5021. * @phba: pointer to lpfc hba data structure.
  5022. *
  5023. * This routine is invoked to set up the driver internal resources before the
  5024. * device specific resource setup to support the HBA device it attached to.
  5025. *
  5026. * Return codes
  5027. * 0 - successful
  5028. * other values - error
  5029. **/
  5030. static int
  5031. lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
  5032. {
  5033. /*
  5034. * Driver resources common to all SLI revisions
  5035. */
  5036. atomic_set(&phba->fast_event_count, 0);
  5037. spin_lock_init(&phba->hbalock);
  5038. /* Initialize ndlp management spinlock */
  5039. spin_lock_init(&phba->ndlp_lock);
  5040. INIT_LIST_HEAD(&phba->port_list);
  5041. INIT_LIST_HEAD(&phba->work_list);
  5042. init_waitqueue_head(&phba->wait_4_mlo_m_q);
  5043. /* Initialize the wait queue head for the kernel thread */
  5044. init_waitqueue_head(&phba->work_waitq);
  5045. /* Initialize the scsi buffer list used by driver for scsi IO */
  5046. spin_lock_init(&phba->scsi_buf_list_get_lock);
  5047. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
  5048. spin_lock_init(&phba->scsi_buf_list_put_lock);
  5049. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
  5050. /* Initialize the fabric iocb list */
  5051. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  5052. /* Initialize list to save ELS buffers */
  5053. INIT_LIST_HEAD(&phba->elsbuf);
  5054. /* Initialize FCF connection rec list */
  5055. INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
  5056. /* Initialize OAS configuration list */
  5057. spin_lock_init(&phba->devicelock);
  5058. INIT_LIST_HEAD(&phba->luns);
  5059. return 0;
  5060. }
  5061. /**
  5062. * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
  5063. * @phba: pointer to lpfc hba data structure.
  5064. *
  5065. * This routine is invoked to set up the driver internal resources after the
  5066. * device specific resource setup to support the HBA device it attached to.
  5067. *
  5068. * Return codes
  5069. * 0 - successful
  5070. * other values - error
  5071. **/
  5072. static int
  5073. lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
  5074. {
  5075. int error;
  5076. /* Startup the kernel thread for this host adapter. */
  5077. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  5078. "lpfc_worker_%d", phba->brd_no);
  5079. if (IS_ERR(phba->worker_thread)) {
  5080. error = PTR_ERR(phba->worker_thread);
  5081. return error;
  5082. }
  5083. return 0;
  5084. }
  5085. /**
  5086. * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
  5087. * @phba: pointer to lpfc hba data structure.
  5088. *
  5089. * This routine is invoked to unset the driver internal resources set up after
  5090. * the device specific resource setup for supporting the HBA device it
  5091. * attached to.
  5092. **/
  5093. static void
  5094. lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
  5095. {
  5096. /* Stop kernel worker thread */
  5097. kthread_stop(phba->worker_thread);
  5098. }
  5099. /**
  5100. * lpfc_free_iocb_list - Free iocb list.
  5101. * @phba: pointer to lpfc hba data structure.
  5102. *
  5103. * This routine is invoked to free the driver's IOCB list and memory.
  5104. **/
  5105. static void
  5106. lpfc_free_iocb_list(struct lpfc_hba *phba)
  5107. {
  5108. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  5109. spin_lock_irq(&phba->hbalock);
  5110. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  5111. &phba->lpfc_iocb_list, list) {
  5112. list_del(&iocbq_entry->list);
  5113. kfree(iocbq_entry);
  5114. phba->total_iocbq_bufs--;
  5115. }
  5116. spin_unlock_irq(&phba->hbalock);
  5117. return;
  5118. }
  5119. /**
  5120. * lpfc_init_iocb_list - Allocate and initialize iocb list.
  5121. * @phba: pointer to lpfc hba data structure.
  5122. *
  5123. * This routine is invoked to allocate and initizlize the driver's IOCB
  5124. * list and set up the IOCB tag array accordingly.
  5125. *
  5126. * Return codes
  5127. * 0 - successful
  5128. * other values - error
  5129. **/
  5130. static int
  5131. lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
  5132. {
  5133. struct lpfc_iocbq *iocbq_entry = NULL;
  5134. uint16_t iotag;
  5135. int i;
  5136. /* Initialize and populate the iocb list per host. */
  5137. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  5138. for (i = 0; i < iocb_count; i++) {
  5139. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  5140. if (iocbq_entry == NULL) {
  5141. printk(KERN_ERR "%s: only allocated %d iocbs of "
  5142. "expected %d count. Unloading driver.\n",
  5143. __func__, i, LPFC_IOCB_LIST_CNT);
  5144. goto out_free_iocbq;
  5145. }
  5146. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  5147. if (iotag == 0) {
  5148. kfree(iocbq_entry);
  5149. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  5150. "Unloading driver.\n", __func__);
  5151. goto out_free_iocbq;
  5152. }
  5153. iocbq_entry->sli4_lxritag = NO_XRI;
  5154. iocbq_entry->sli4_xritag = NO_XRI;
  5155. spin_lock_irq(&phba->hbalock);
  5156. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  5157. phba->total_iocbq_bufs++;
  5158. spin_unlock_irq(&phba->hbalock);
  5159. }
  5160. return 0;
  5161. out_free_iocbq:
  5162. lpfc_free_iocb_list(phba);
  5163. return -ENOMEM;
  5164. }
  5165. /**
  5166. * lpfc_free_sgl_list - Free a given sgl list.
  5167. * @phba: pointer to lpfc hba data structure.
  5168. * @sglq_list: pointer to the head of sgl list.
  5169. *
  5170. * This routine is invoked to free a give sgl list and memory.
  5171. **/
  5172. void
  5173. lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
  5174. {
  5175. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  5176. list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
  5177. list_del(&sglq_entry->list);
  5178. lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
  5179. kfree(sglq_entry);
  5180. }
  5181. }
  5182. /**
  5183. * lpfc_free_els_sgl_list - Free els sgl list.
  5184. * @phba: pointer to lpfc hba data structure.
  5185. *
  5186. * This routine is invoked to free the driver's els sgl list and memory.
  5187. **/
  5188. static void
  5189. lpfc_free_els_sgl_list(struct lpfc_hba *phba)
  5190. {
  5191. LIST_HEAD(sglq_list);
  5192. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  5193. /* Retrieve all els sgls from driver list */
  5194. spin_lock_irq(&phba->hbalock);
  5195. spin_lock(&pring->ring_lock);
  5196. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
  5197. spin_unlock(&pring->ring_lock);
  5198. spin_unlock_irq(&phba->hbalock);
  5199. /* Now free the sgl list */
  5200. lpfc_free_sgl_list(phba, &sglq_list);
  5201. }
  5202. /**
  5203. * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
  5204. * @phba: pointer to lpfc hba data structure.
  5205. *
  5206. * This routine is invoked to allocate the driver's active sgl memory.
  5207. * This array will hold the sglq_entry's for active IOs.
  5208. **/
  5209. static int
  5210. lpfc_init_active_sgl_array(struct lpfc_hba *phba)
  5211. {
  5212. int size;
  5213. size = sizeof(struct lpfc_sglq *);
  5214. size *= phba->sli4_hba.max_cfg_param.max_xri;
  5215. phba->sli4_hba.lpfc_sglq_active_list =
  5216. kzalloc(size, GFP_KERNEL);
  5217. if (!phba->sli4_hba.lpfc_sglq_active_list)
  5218. return -ENOMEM;
  5219. return 0;
  5220. }
  5221. /**
  5222. * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
  5223. * @phba: pointer to lpfc hba data structure.
  5224. *
  5225. * This routine is invoked to walk through the array of active sglq entries
  5226. * and free all of the resources.
  5227. * This is just a place holder for now.
  5228. **/
  5229. static void
  5230. lpfc_free_active_sgl(struct lpfc_hba *phba)
  5231. {
  5232. kfree(phba->sli4_hba.lpfc_sglq_active_list);
  5233. }
  5234. /**
  5235. * lpfc_init_sgl_list - Allocate and initialize sgl list.
  5236. * @phba: pointer to lpfc hba data structure.
  5237. *
  5238. * This routine is invoked to allocate and initizlize the driver's sgl
  5239. * list and set up the sgl xritag tag array accordingly.
  5240. *
  5241. **/
  5242. static void
  5243. lpfc_init_sgl_list(struct lpfc_hba *phba)
  5244. {
  5245. /* Initialize and populate the sglq list per host/VF. */
  5246. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
  5247. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  5248. /* els xri-sgl book keeping */
  5249. phba->sli4_hba.els_xri_cnt = 0;
  5250. /* scsi xri-buffer book keeping */
  5251. phba->sli4_hba.scsi_xri_cnt = 0;
  5252. }
  5253. /**
  5254. * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
  5255. * @phba: pointer to lpfc hba data structure.
  5256. *
  5257. * This routine is invoked to post rpi header templates to the
  5258. * port for those SLI4 ports that do not support extents. This routine
  5259. * posts a PAGE_SIZE memory region to the port to hold up to
  5260. * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
  5261. * and should be called only when interrupts are disabled.
  5262. *
  5263. * Return codes
  5264. * 0 - successful
  5265. * -ERROR - otherwise.
  5266. **/
  5267. int
  5268. lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
  5269. {
  5270. int rc = 0;
  5271. struct lpfc_rpi_hdr *rpi_hdr;
  5272. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
  5273. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5274. return rc;
  5275. if (phba->sli4_hba.extents_in_use)
  5276. return -EIO;
  5277. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  5278. if (!rpi_hdr) {
  5279. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5280. "0391 Error during rpi post operation\n");
  5281. lpfc_sli4_remove_rpis(phba);
  5282. rc = -ENODEV;
  5283. }
  5284. return rc;
  5285. }
  5286. /**
  5287. * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
  5288. * @phba: pointer to lpfc hba data structure.
  5289. *
  5290. * This routine is invoked to allocate a single 4KB memory region to
  5291. * support rpis and stores them in the phba. This single region
  5292. * provides support for up to 64 rpis. The region is used globally
  5293. * by the device.
  5294. *
  5295. * Returns:
  5296. * A valid rpi hdr on success.
  5297. * A NULL pointer on any failure.
  5298. **/
  5299. struct lpfc_rpi_hdr *
  5300. lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
  5301. {
  5302. uint16_t rpi_limit, curr_rpi_range;
  5303. struct lpfc_dmabuf *dmabuf;
  5304. struct lpfc_rpi_hdr *rpi_hdr;
  5305. uint32_t rpi_count;
  5306. /*
  5307. * If the SLI4 port supports extents, posting the rpi header isn't
  5308. * required. Set the expected maximum count and let the actual value
  5309. * get set when extents are fully allocated.
  5310. */
  5311. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5312. return NULL;
  5313. if (phba->sli4_hba.extents_in_use)
  5314. return NULL;
  5315. /* The limit on the logical index is just the max_rpi count. */
  5316. rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
  5317. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  5318. spin_lock_irq(&phba->hbalock);
  5319. /*
  5320. * Establish the starting RPI in this header block. The starting
  5321. * rpi is normalized to a zero base because the physical rpi is
  5322. * port based.
  5323. */
  5324. curr_rpi_range = phba->sli4_hba.next_rpi;
  5325. spin_unlock_irq(&phba->hbalock);
  5326. /*
  5327. * The port has a limited number of rpis. The increment here
  5328. * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
  5329. * and to allow the full max_rpi range per port.
  5330. */
  5331. if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
  5332. rpi_count = rpi_limit - curr_rpi_range;
  5333. else
  5334. rpi_count = LPFC_RPI_HDR_COUNT;
  5335. if (!rpi_count)
  5336. return NULL;
  5337. /*
  5338. * First allocate the protocol header region for the port. The
  5339. * port expects a 4KB DMA-mapped memory region that is 4K aligned.
  5340. */
  5341. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  5342. if (!dmabuf)
  5343. return NULL;
  5344. dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
  5345. LPFC_HDR_TEMPLATE_SIZE,
  5346. &dmabuf->phys, GFP_KERNEL);
  5347. if (!dmabuf->virt) {
  5348. rpi_hdr = NULL;
  5349. goto err_free_dmabuf;
  5350. }
  5351. if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
  5352. rpi_hdr = NULL;
  5353. goto err_free_coherent;
  5354. }
  5355. /* Save the rpi header data for cleanup later. */
  5356. rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
  5357. if (!rpi_hdr)
  5358. goto err_free_coherent;
  5359. rpi_hdr->dmabuf = dmabuf;
  5360. rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
  5361. rpi_hdr->page_count = 1;
  5362. spin_lock_irq(&phba->hbalock);
  5363. /* The rpi_hdr stores the logical index only. */
  5364. rpi_hdr->start_rpi = curr_rpi_range;
  5365. list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
  5366. /*
  5367. * The next_rpi stores the next logical module-64 rpi value used
  5368. * to post physical rpis in subsequent rpi postings.
  5369. */
  5370. phba->sli4_hba.next_rpi += rpi_count;
  5371. spin_unlock_irq(&phba->hbalock);
  5372. return rpi_hdr;
  5373. err_free_coherent:
  5374. dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
  5375. dmabuf->virt, dmabuf->phys);
  5376. err_free_dmabuf:
  5377. kfree(dmabuf);
  5378. return NULL;
  5379. }
  5380. /**
  5381. * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
  5382. * @phba: pointer to lpfc hba data structure.
  5383. *
  5384. * This routine is invoked to remove all memory resources allocated
  5385. * to support rpis for SLI4 ports not supporting extents. This routine
  5386. * presumes the caller has released all rpis consumed by fabric or port
  5387. * logins and is prepared to have the header pages removed.
  5388. **/
  5389. void
  5390. lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
  5391. {
  5392. struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
  5393. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5394. goto exit;
  5395. list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
  5396. &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  5397. list_del(&rpi_hdr->list);
  5398. dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
  5399. rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
  5400. kfree(rpi_hdr->dmabuf);
  5401. kfree(rpi_hdr);
  5402. }
  5403. exit:
  5404. /* There are no rpis available to the port now. */
  5405. phba->sli4_hba.next_rpi = 0;
  5406. }
  5407. /**
  5408. * lpfc_hba_alloc - Allocate driver hba data structure for a device.
  5409. * @pdev: pointer to pci device data structure.
  5410. *
  5411. * This routine is invoked to allocate the driver hba data structure for an
  5412. * HBA device. If the allocation is successful, the phba reference to the
  5413. * PCI device data structure is set.
  5414. *
  5415. * Return codes
  5416. * pointer to @phba - successful
  5417. * NULL - error
  5418. **/
  5419. static struct lpfc_hba *
  5420. lpfc_hba_alloc(struct pci_dev *pdev)
  5421. {
  5422. struct lpfc_hba *phba;
  5423. /* Allocate memory for HBA structure */
  5424. phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
  5425. if (!phba) {
  5426. dev_err(&pdev->dev, "failed to allocate hba struct\n");
  5427. return NULL;
  5428. }
  5429. /* Set reference to PCI device in HBA structure */
  5430. phba->pcidev = pdev;
  5431. /* Assign an unused board number */
  5432. phba->brd_no = lpfc_get_instance();
  5433. if (phba->brd_no < 0) {
  5434. kfree(phba);
  5435. return NULL;
  5436. }
  5437. spin_lock_init(&phba->ct_ev_lock);
  5438. INIT_LIST_HEAD(&phba->ct_ev_waiters);
  5439. return phba;
  5440. }
  5441. /**
  5442. * lpfc_hba_free - Free driver hba data structure with a device.
  5443. * @phba: pointer to lpfc hba data structure.
  5444. *
  5445. * This routine is invoked to free the driver hba data structure with an
  5446. * HBA device.
  5447. **/
  5448. static void
  5449. lpfc_hba_free(struct lpfc_hba *phba)
  5450. {
  5451. /* Release the driver assigned board number */
  5452. idr_remove(&lpfc_hba_index, phba->brd_no);
  5453. /* Free memory allocated with sli rings */
  5454. kfree(phba->sli.ring);
  5455. phba->sli.ring = NULL;
  5456. kfree(phba);
  5457. return;
  5458. }
  5459. /**
  5460. * lpfc_create_shost - Create hba physical port with associated scsi host.
  5461. * @phba: pointer to lpfc hba data structure.
  5462. *
  5463. * This routine is invoked to create HBA physical port and associate a SCSI
  5464. * host with it.
  5465. *
  5466. * Return codes
  5467. * 0 - successful
  5468. * other values - error
  5469. **/
  5470. static int
  5471. lpfc_create_shost(struct lpfc_hba *phba)
  5472. {
  5473. struct lpfc_vport *vport;
  5474. struct Scsi_Host *shost;
  5475. /* Initialize HBA FC structure */
  5476. phba->fc_edtov = FF_DEF_EDTOV;
  5477. phba->fc_ratov = FF_DEF_RATOV;
  5478. phba->fc_altov = FF_DEF_ALTOV;
  5479. phba->fc_arbtov = FF_DEF_ARBTOV;
  5480. atomic_set(&phba->sdev_cnt, 0);
  5481. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  5482. if (!vport)
  5483. return -ENODEV;
  5484. shost = lpfc_shost_from_vport(vport);
  5485. phba->pport = vport;
  5486. lpfc_debugfs_initialize(vport);
  5487. /* Put reference to SCSI host to driver's device private data */
  5488. pci_set_drvdata(phba->pcidev, shost);
  5489. return 0;
  5490. }
  5491. /**
  5492. * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
  5493. * @phba: pointer to lpfc hba data structure.
  5494. *
  5495. * This routine is invoked to destroy HBA physical port and the associated
  5496. * SCSI host.
  5497. **/
  5498. static void
  5499. lpfc_destroy_shost(struct lpfc_hba *phba)
  5500. {
  5501. struct lpfc_vport *vport = phba->pport;
  5502. /* Destroy physical port that associated with the SCSI host */
  5503. destroy_port(vport);
  5504. return;
  5505. }
  5506. /**
  5507. * lpfc_setup_bg - Setup Block guard structures and debug areas.
  5508. * @phba: pointer to lpfc hba data structure.
  5509. * @shost: the shost to be used to detect Block guard settings.
  5510. *
  5511. * This routine sets up the local Block guard protocol settings for @shost.
  5512. * This routine also allocates memory for debugging bg buffers.
  5513. **/
  5514. static void
  5515. lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
  5516. {
  5517. uint32_t old_mask;
  5518. uint32_t old_guard;
  5519. int pagecnt = 10;
  5520. if (lpfc_prot_mask && lpfc_prot_guard) {
  5521. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5522. "1478 Registering BlockGuard with the "
  5523. "SCSI layer\n");
  5524. old_mask = lpfc_prot_mask;
  5525. old_guard = lpfc_prot_guard;
  5526. /* Only allow supported values */
  5527. lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
  5528. SHOST_DIX_TYPE0_PROTECTION |
  5529. SHOST_DIX_TYPE1_PROTECTION);
  5530. lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
  5531. /* DIF Type 1 protection for profiles AST1/C1 is end to end */
  5532. if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
  5533. lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
  5534. if (lpfc_prot_mask && lpfc_prot_guard) {
  5535. if ((old_mask != lpfc_prot_mask) ||
  5536. (old_guard != lpfc_prot_guard))
  5537. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5538. "1475 Registering BlockGuard with the "
  5539. "SCSI layer: mask %d guard %d\n",
  5540. lpfc_prot_mask, lpfc_prot_guard);
  5541. scsi_host_set_prot(shost, lpfc_prot_mask);
  5542. scsi_host_set_guard(shost, lpfc_prot_guard);
  5543. } else
  5544. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5545. "1479 Not Registering BlockGuard with the SCSI "
  5546. "layer, Bad protection parameters: %d %d\n",
  5547. old_mask, old_guard);
  5548. }
  5549. if (!_dump_buf_data) {
  5550. while (pagecnt) {
  5551. spin_lock_init(&_dump_buf_lock);
  5552. _dump_buf_data =
  5553. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  5554. if (_dump_buf_data) {
  5555. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5556. "9043 BLKGRD: allocated %d pages for "
  5557. "_dump_buf_data at 0x%p\n",
  5558. (1 << pagecnt), _dump_buf_data);
  5559. _dump_buf_data_order = pagecnt;
  5560. memset(_dump_buf_data, 0,
  5561. ((1 << PAGE_SHIFT) << pagecnt));
  5562. break;
  5563. } else
  5564. --pagecnt;
  5565. }
  5566. if (!_dump_buf_data_order)
  5567. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5568. "9044 BLKGRD: ERROR unable to allocate "
  5569. "memory for hexdump\n");
  5570. } else
  5571. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5572. "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
  5573. "\n", _dump_buf_data);
  5574. if (!_dump_buf_dif) {
  5575. while (pagecnt) {
  5576. _dump_buf_dif =
  5577. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  5578. if (_dump_buf_dif) {
  5579. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5580. "9046 BLKGRD: allocated %d pages for "
  5581. "_dump_buf_dif at 0x%p\n",
  5582. (1 << pagecnt), _dump_buf_dif);
  5583. _dump_buf_dif_order = pagecnt;
  5584. memset(_dump_buf_dif, 0,
  5585. ((1 << PAGE_SHIFT) << pagecnt));
  5586. break;
  5587. } else
  5588. --pagecnt;
  5589. }
  5590. if (!_dump_buf_dif_order)
  5591. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5592. "9047 BLKGRD: ERROR unable to allocate "
  5593. "memory for hexdump\n");
  5594. } else
  5595. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5596. "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
  5597. _dump_buf_dif);
  5598. }
  5599. /**
  5600. * lpfc_post_init_setup - Perform necessary device post initialization setup.
  5601. * @phba: pointer to lpfc hba data structure.
  5602. *
  5603. * This routine is invoked to perform all the necessary post initialization
  5604. * setup for the device.
  5605. **/
  5606. static void
  5607. lpfc_post_init_setup(struct lpfc_hba *phba)
  5608. {
  5609. struct Scsi_Host *shost;
  5610. struct lpfc_adapter_event_header adapter_event;
  5611. /* Get the default values for Model Name and Description */
  5612. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  5613. /*
  5614. * hba setup may have changed the hba_queue_depth so we need to
  5615. * adjust the value of can_queue.
  5616. */
  5617. shost = pci_get_drvdata(phba->pcidev);
  5618. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  5619. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  5620. lpfc_setup_bg(phba, shost);
  5621. lpfc_host_attrib_init(shost);
  5622. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  5623. spin_lock_irq(shost->host_lock);
  5624. lpfc_poll_start_timer(phba);
  5625. spin_unlock_irq(shost->host_lock);
  5626. }
  5627. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5628. "0428 Perform SCSI scan\n");
  5629. /* Send board arrival event to upper layer */
  5630. adapter_event.event_type = FC_REG_ADAPTER_EVENT;
  5631. adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
  5632. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5633. sizeof(adapter_event),
  5634. (char *) &adapter_event,
  5635. LPFC_NL_VENDOR_ID);
  5636. return;
  5637. }
  5638. /**
  5639. * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
  5640. * @phba: pointer to lpfc hba data structure.
  5641. *
  5642. * This routine is invoked to set up the PCI device memory space for device
  5643. * with SLI-3 interface spec.
  5644. *
  5645. * Return codes
  5646. * 0 - successful
  5647. * other values - error
  5648. **/
  5649. static int
  5650. lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
  5651. {
  5652. struct pci_dev *pdev;
  5653. unsigned long bar0map_len, bar2map_len;
  5654. int i, hbq_count;
  5655. void *ptr;
  5656. int error = -ENODEV;
  5657. /* Obtain PCI device reference */
  5658. if (!phba->pcidev)
  5659. return error;
  5660. else
  5661. pdev = phba->pcidev;
  5662. /* Set the device DMA mask size */
  5663. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  5664. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  5665. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  5666. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  5667. return error;
  5668. }
  5669. }
  5670. /* Get the bus address of Bar0 and Bar2 and the number of bytes
  5671. * required by each mapping.
  5672. */
  5673. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  5674. bar0map_len = pci_resource_len(pdev, 0);
  5675. phba->pci_bar2_map = pci_resource_start(pdev, 2);
  5676. bar2map_len = pci_resource_len(pdev, 2);
  5677. /* Map HBA SLIM to a kernel virtual address. */
  5678. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  5679. if (!phba->slim_memmap_p) {
  5680. dev_printk(KERN_ERR, &pdev->dev,
  5681. "ioremap failed for SLIM memory.\n");
  5682. goto out;
  5683. }
  5684. /* Map HBA Control Registers to a kernel virtual address. */
  5685. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  5686. if (!phba->ctrl_regs_memmap_p) {
  5687. dev_printk(KERN_ERR, &pdev->dev,
  5688. "ioremap failed for HBA control registers.\n");
  5689. goto out_iounmap_slim;
  5690. }
  5691. /* Allocate memory for SLI-2 structures */
  5692. phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  5693. &phba->slim2p.phys, GFP_KERNEL);
  5694. if (!phba->slim2p.virt)
  5695. goto out_iounmap;
  5696. phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
  5697. phba->mbox_ext = (phba->slim2p.virt +
  5698. offsetof(struct lpfc_sli2_slim, mbx_ext_words));
  5699. phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
  5700. phba->IOCBs = (phba->slim2p.virt +
  5701. offsetof(struct lpfc_sli2_slim, IOCBs));
  5702. phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
  5703. lpfc_sli_hbq_size(),
  5704. &phba->hbqslimp.phys,
  5705. GFP_KERNEL);
  5706. if (!phba->hbqslimp.virt)
  5707. goto out_free_slim;
  5708. hbq_count = lpfc_sli_hbq_count();
  5709. ptr = phba->hbqslimp.virt;
  5710. for (i = 0; i < hbq_count; ++i) {
  5711. phba->hbqs[i].hbq_virt = ptr;
  5712. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  5713. ptr += (lpfc_hbq_defs[i]->entry_count *
  5714. sizeof(struct lpfc_hbq_entry));
  5715. }
  5716. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  5717. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  5718. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  5719. INIT_LIST_HEAD(&phba->rb_pend_list);
  5720. phba->MBslimaddr = phba->slim_memmap_p;
  5721. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  5722. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  5723. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  5724. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  5725. return 0;
  5726. out_free_slim:
  5727. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  5728. phba->slim2p.virt, phba->slim2p.phys);
  5729. out_iounmap:
  5730. iounmap(phba->ctrl_regs_memmap_p);
  5731. out_iounmap_slim:
  5732. iounmap(phba->slim_memmap_p);
  5733. out:
  5734. return error;
  5735. }
  5736. /**
  5737. * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
  5738. * @phba: pointer to lpfc hba data structure.
  5739. *
  5740. * This routine is invoked to unset the PCI device memory space for device
  5741. * with SLI-3 interface spec.
  5742. **/
  5743. static void
  5744. lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
  5745. {
  5746. struct pci_dev *pdev;
  5747. /* Obtain PCI device reference */
  5748. if (!phba->pcidev)
  5749. return;
  5750. else
  5751. pdev = phba->pcidev;
  5752. /* Free coherent DMA memory allocated */
  5753. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  5754. phba->hbqslimp.virt, phba->hbqslimp.phys);
  5755. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  5756. phba->slim2p.virt, phba->slim2p.phys);
  5757. /* I/O memory unmap */
  5758. iounmap(phba->ctrl_regs_memmap_p);
  5759. iounmap(phba->slim_memmap_p);
  5760. return;
  5761. }
  5762. /**
  5763. * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
  5764. * @phba: pointer to lpfc hba data structure.
  5765. *
  5766. * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
  5767. * done and check status.
  5768. *
  5769. * Return 0 if successful, otherwise -ENODEV.
  5770. **/
  5771. int
  5772. lpfc_sli4_post_status_check(struct lpfc_hba *phba)
  5773. {
  5774. struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
  5775. struct lpfc_register reg_data;
  5776. int i, port_error = 0;
  5777. uint32_t if_type;
  5778. memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
  5779. memset(&reg_data, 0, sizeof(reg_data));
  5780. if (!phba->sli4_hba.PSMPHRregaddr)
  5781. return -ENODEV;
  5782. /* Wait up to 30 seconds for the SLI Port POST done and ready */
  5783. for (i = 0; i < 3000; i++) {
  5784. if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  5785. &portsmphr_reg.word0) ||
  5786. (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
  5787. /* Port has a fatal POST error, break out */
  5788. port_error = -ENODEV;
  5789. break;
  5790. }
  5791. if (LPFC_POST_STAGE_PORT_READY ==
  5792. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
  5793. break;
  5794. msleep(10);
  5795. }
  5796. /*
  5797. * If there was a port error during POST, then don't proceed with
  5798. * other register reads as the data may not be valid. Just exit.
  5799. */
  5800. if (port_error) {
  5801. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5802. "1408 Port Failed POST - portsmphr=0x%x, "
  5803. "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
  5804. "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
  5805. portsmphr_reg.word0,
  5806. bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
  5807. bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
  5808. bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
  5809. bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
  5810. bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
  5811. bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
  5812. bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
  5813. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
  5814. } else {
  5815. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5816. "2534 Device Info: SLIFamily=0x%x, "
  5817. "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
  5818. "SLIHint_2=0x%x, FT=0x%x\n",
  5819. bf_get(lpfc_sli_intf_sli_family,
  5820. &phba->sli4_hba.sli_intf),
  5821. bf_get(lpfc_sli_intf_slirev,
  5822. &phba->sli4_hba.sli_intf),
  5823. bf_get(lpfc_sli_intf_if_type,
  5824. &phba->sli4_hba.sli_intf),
  5825. bf_get(lpfc_sli_intf_sli_hint1,
  5826. &phba->sli4_hba.sli_intf),
  5827. bf_get(lpfc_sli_intf_sli_hint2,
  5828. &phba->sli4_hba.sli_intf),
  5829. bf_get(lpfc_sli_intf_func_type,
  5830. &phba->sli4_hba.sli_intf));
  5831. /*
  5832. * Check for other Port errors during the initialization
  5833. * process. Fail the load if the port did not come up
  5834. * correctly.
  5835. */
  5836. if_type = bf_get(lpfc_sli_intf_if_type,
  5837. &phba->sli4_hba.sli_intf);
  5838. switch (if_type) {
  5839. case LPFC_SLI_INTF_IF_TYPE_0:
  5840. phba->sli4_hba.ue_mask_lo =
  5841. readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
  5842. phba->sli4_hba.ue_mask_hi =
  5843. readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
  5844. uerrlo_reg.word0 =
  5845. readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
  5846. uerrhi_reg.word0 =
  5847. readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
  5848. if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
  5849. (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
  5850. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5851. "1422 Unrecoverable Error "
  5852. "Detected during POST "
  5853. "uerr_lo_reg=0x%x, "
  5854. "uerr_hi_reg=0x%x, "
  5855. "ue_mask_lo_reg=0x%x, "
  5856. "ue_mask_hi_reg=0x%x\n",
  5857. uerrlo_reg.word0,
  5858. uerrhi_reg.word0,
  5859. phba->sli4_hba.ue_mask_lo,
  5860. phba->sli4_hba.ue_mask_hi);
  5861. port_error = -ENODEV;
  5862. }
  5863. break;
  5864. case LPFC_SLI_INTF_IF_TYPE_2:
  5865. /* Final checks. The port status should be clean. */
  5866. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  5867. &reg_data.word0) ||
  5868. (bf_get(lpfc_sliport_status_err, &reg_data) &&
  5869. !bf_get(lpfc_sliport_status_rn, &reg_data))) {
  5870. phba->work_status[0] =
  5871. readl(phba->sli4_hba.u.if_type2.
  5872. ERR1regaddr);
  5873. phba->work_status[1] =
  5874. readl(phba->sli4_hba.u.if_type2.
  5875. ERR2regaddr);
  5876. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5877. "2888 Unrecoverable port error "
  5878. "following POST: port status reg "
  5879. "0x%x, port_smphr reg 0x%x, "
  5880. "error 1=0x%x, error 2=0x%x\n",
  5881. reg_data.word0,
  5882. portsmphr_reg.word0,
  5883. phba->work_status[0],
  5884. phba->work_status[1]);
  5885. port_error = -ENODEV;
  5886. }
  5887. break;
  5888. case LPFC_SLI_INTF_IF_TYPE_1:
  5889. default:
  5890. break;
  5891. }
  5892. }
  5893. return port_error;
  5894. }
  5895. /**
  5896. * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
  5897. * @phba: pointer to lpfc hba data structure.
  5898. * @if_type: The SLI4 interface type getting configured.
  5899. *
  5900. * This routine is invoked to set up SLI4 BAR0 PCI config space register
  5901. * memory map.
  5902. **/
  5903. static void
  5904. lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
  5905. {
  5906. switch (if_type) {
  5907. case LPFC_SLI_INTF_IF_TYPE_0:
  5908. phba->sli4_hba.u.if_type0.UERRLOregaddr =
  5909. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
  5910. phba->sli4_hba.u.if_type0.UERRHIregaddr =
  5911. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
  5912. phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
  5913. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
  5914. phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
  5915. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
  5916. phba->sli4_hba.SLIINTFregaddr =
  5917. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  5918. break;
  5919. case LPFC_SLI_INTF_IF_TYPE_2:
  5920. phba->sli4_hba.u.if_type2.ERR1regaddr =
  5921. phba->sli4_hba.conf_regs_memmap_p +
  5922. LPFC_CTL_PORT_ER1_OFFSET;
  5923. phba->sli4_hba.u.if_type2.ERR2regaddr =
  5924. phba->sli4_hba.conf_regs_memmap_p +
  5925. LPFC_CTL_PORT_ER2_OFFSET;
  5926. phba->sli4_hba.u.if_type2.CTRLregaddr =
  5927. phba->sli4_hba.conf_regs_memmap_p +
  5928. LPFC_CTL_PORT_CTL_OFFSET;
  5929. phba->sli4_hba.u.if_type2.STATUSregaddr =
  5930. phba->sli4_hba.conf_regs_memmap_p +
  5931. LPFC_CTL_PORT_STA_OFFSET;
  5932. phba->sli4_hba.SLIINTFregaddr =
  5933. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  5934. phba->sli4_hba.PSMPHRregaddr =
  5935. phba->sli4_hba.conf_regs_memmap_p +
  5936. LPFC_CTL_PORT_SEM_OFFSET;
  5937. phba->sli4_hba.RQDBregaddr =
  5938. phba->sli4_hba.conf_regs_memmap_p +
  5939. LPFC_ULP0_RQ_DOORBELL;
  5940. phba->sli4_hba.WQDBregaddr =
  5941. phba->sli4_hba.conf_regs_memmap_p +
  5942. LPFC_ULP0_WQ_DOORBELL;
  5943. phba->sli4_hba.EQCQDBregaddr =
  5944. phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
  5945. phba->sli4_hba.MQDBregaddr =
  5946. phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
  5947. phba->sli4_hba.BMBXregaddr =
  5948. phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
  5949. break;
  5950. case LPFC_SLI_INTF_IF_TYPE_1:
  5951. default:
  5952. dev_printk(KERN_ERR, &phba->pcidev->dev,
  5953. "FATAL - unsupported SLI4 interface type - %d\n",
  5954. if_type);
  5955. break;
  5956. }
  5957. }
  5958. /**
  5959. * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
  5960. * @phba: pointer to lpfc hba data structure.
  5961. *
  5962. * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
  5963. * memory map.
  5964. **/
  5965. static void
  5966. lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
  5967. {
  5968. phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5969. LPFC_SLIPORT_IF0_SMPHR;
  5970. phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5971. LPFC_HST_ISR0;
  5972. phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5973. LPFC_HST_IMR0;
  5974. phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5975. LPFC_HST_ISCR0;
  5976. }
  5977. /**
  5978. * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
  5979. * @phba: pointer to lpfc hba data structure.
  5980. * @vf: virtual function number
  5981. *
  5982. * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
  5983. * based on the given viftual function number, @vf.
  5984. *
  5985. * Return 0 if successful, otherwise -ENODEV.
  5986. **/
  5987. static int
  5988. lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
  5989. {
  5990. if (vf > LPFC_VIR_FUNC_MAX)
  5991. return -ENODEV;
  5992. phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5993. vf * LPFC_VFR_PAGE_SIZE +
  5994. LPFC_ULP0_RQ_DOORBELL);
  5995. phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5996. vf * LPFC_VFR_PAGE_SIZE +
  5997. LPFC_ULP0_WQ_DOORBELL);
  5998. phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5999. vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
  6000. phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  6001. vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
  6002. phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  6003. vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
  6004. return 0;
  6005. }
  6006. /**
  6007. * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
  6008. * @phba: pointer to lpfc hba data structure.
  6009. *
  6010. * This routine is invoked to create the bootstrap mailbox
  6011. * region consistent with the SLI-4 interface spec. This
  6012. * routine allocates all memory necessary to communicate
  6013. * mailbox commands to the port and sets up all alignment
  6014. * needs. No locks are expected to be held when calling
  6015. * this routine.
  6016. *
  6017. * Return codes
  6018. * 0 - successful
  6019. * -ENOMEM - could not allocated memory.
  6020. **/
  6021. static int
  6022. lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
  6023. {
  6024. uint32_t bmbx_size;
  6025. struct lpfc_dmabuf *dmabuf;
  6026. struct dma_address *dma_address;
  6027. uint32_t pa_addr;
  6028. uint64_t phys_addr;
  6029. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  6030. if (!dmabuf)
  6031. return -ENOMEM;
  6032. /*
  6033. * The bootstrap mailbox region is comprised of 2 parts
  6034. * plus an alignment restriction of 16 bytes.
  6035. */
  6036. bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
  6037. dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
  6038. &dmabuf->phys, GFP_KERNEL);
  6039. if (!dmabuf->virt) {
  6040. kfree(dmabuf);
  6041. return -ENOMEM;
  6042. }
  6043. /*
  6044. * Initialize the bootstrap mailbox pointers now so that the register
  6045. * operations are simple later. The mailbox dma address is required
  6046. * to be 16-byte aligned. Also align the virtual memory as each
  6047. * maibox is copied into the bmbx mailbox region before issuing the
  6048. * command to the port.
  6049. */
  6050. phba->sli4_hba.bmbx.dmabuf = dmabuf;
  6051. phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
  6052. phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
  6053. LPFC_ALIGN_16_BYTE);
  6054. phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
  6055. LPFC_ALIGN_16_BYTE);
  6056. /*
  6057. * Set the high and low physical addresses now. The SLI4 alignment
  6058. * requirement is 16 bytes and the mailbox is posted to the port
  6059. * as two 30-bit addresses. The other data is a bit marking whether
  6060. * the 30-bit address is the high or low address.
  6061. * Upcast bmbx aphys to 64bits so shift instruction compiles
  6062. * clean on 32 bit machines.
  6063. */
  6064. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6065. phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
  6066. pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
  6067. dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
  6068. LPFC_BMBX_BIT1_ADDR_HI);
  6069. pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
  6070. dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
  6071. LPFC_BMBX_BIT1_ADDR_LO);
  6072. return 0;
  6073. }
  6074. /**
  6075. * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
  6076. * @phba: pointer to lpfc hba data structure.
  6077. *
  6078. * This routine is invoked to teardown the bootstrap mailbox
  6079. * region and release all host resources. This routine requires
  6080. * the caller to ensure all mailbox commands recovered, no
  6081. * additional mailbox comands are sent, and interrupts are disabled
  6082. * before calling this routine.
  6083. *
  6084. **/
  6085. static void
  6086. lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
  6087. {
  6088. dma_free_coherent(&phba->pcidev->dev,
  6089. phba->sli4_hba.bmbx.bmbx_size,
  6090. phba->sli4_hba.bmbx.dmabuf->virt,
  6091. phba->sli4_hba.bmbx.dmabuf->phys);
  6092. kfree(phba->sli4_hba.bmbx.dmabuf);
  6093. memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
  6094. }
  6095. /**
  6096. * lpfc_sli4_read_config - Get the config parameters.
  6097. * @phba: pointer to lpfc hba data structure.
  6098. *
  6099. * This routine is invoked to read the configuration parameters from the HBA.
  6100. * The configuration parameters are used to set the base and maximum values
  6101. * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
  6102. * allocation for the port.
  6103. *
  6104. * Return codes
  6105. * 0 - successful
  6106. * -ENOMEM - No available memory
  6107. * -EIO - The mailbox failed to complete successfully.
  6108. **/
  6109. int
  6110. lpfc_sli4_read_config(struct lpfc_hba *phba)
  6111. {
  6112. LPFC_MBOXQ_t *pmb;
  6113. struct lpfc_mbx_read_config *rd_config;
  6114. union lpfc_sli4_cfg_shdr *shdr;
  6115. uint32_t shdr_status, shdr_add_status;
  6116. struct lpfc_mbx_get_func_cfg *get_func_cfg;
  6117. struct lpfc_rsrc_desc_fcfcoe *desc;
  6118. char *pdesc_0;
  6119. int length, i, rc = 0, rc2;
  6120. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6121. if (!pmb) {
  6122. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6123. "2011 Unable to allocate memory for issuing "
  6124. "SLI_CONFIG_SPECIAL mailbox command\n");
  6125. return -ENOMEM;
  6126. }
  6127. lpfc_read_config(phba, pmb);
  6128. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  6129. if (rc != MBX_SUCCESS) {
  6130. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6131. "2012 Mailbox failed , mbxCmd x%x "
  6132. "READ_CONFIG, mbxStatus x%x\n",
  6133. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  6134. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  6135. rc = -EIO;
  6136. } else {
  6137. rd_config = &pmb->u.mqe.un.rd_config;
  6138. if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
  6139. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  6140. phba->sli4_hba.lnk_info.lnk_tp =
  6141. bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
  6142. phba->sli4_hba.lnk_info.lnk_no =
  6143. bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
  6144. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6145. "3081 lnk_type:%d, lnk_numb:%d\n",
  6146. phba->sli4_hba.lnk_info.lnk_tp,
  6147. phba->sli4_hba.lnk_info.lnk_no);
  6148. } else
  6149. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  6150. "3082 Mailbox (x%x) returned ldv:x0\n",
  6151. bf_get(lpfc_mqe_command, &pmb->u.mqe));
  6152. phba->sli4_hba.extents_in_use =
  6153. bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
  6154. phba->sli4_hba.max_cfg_param.max_xri =
  6155. bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  6156. phba->sli4_hba.max_cfg_param.xri_base =
  6157. bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
  6158. phba->sli4_hba.max_cfg_param.max_vpi =
  6159. bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
  6160. phba->sli4_hba.max_cfg_param.vpi_base =
  6161. bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
  6162. phba->sli4_hba.max_cfg_param.max_rpi =
  6163. bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  6164. phba->sli4_hba.max_cfg_param.rpi_base =
  6165. bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
  6166. phba->sli4_hba.max_cfg_param.max_vfi =
  6167. bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
  6168. phba->sli4_hba.max_cfg_param.vfi_base =
  6169. bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
  6170. phba->sli4_hba.max_cfg_param.max_fcfi =
  6171. bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
  6172. phba->sli4_hba.max_cfg_param.max_eq =
  6173. bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
  6174. phba->sli4_hba.max_cfg_param.max_rq =
  6175. bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
  6176. phba->sli4_hba.max_cfg_param.max_wq =
  6177. bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
  6178. phba->sli4_hba.max_cfg_param.max_cq =
  6179. bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
  6180. phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
  6181. phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
  6182. phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
  6183. phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
  6184. phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
  6185. (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
  6186. phba->max_vports = phba->max_vpi;
  6187. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6188. "2003 cfg params Extents? %d "
  6189. "XRI(B:%d M:%d), "
  6190. "VPI(B:%d M:%d) "
  6191. "VFI(B:%d M:%d) "
  6192. "RPI(B:%d M:%d) "
  6193. "FCFI(Count:%d)\n",
  6194. phba->sli4_hba.extents_in_use,
  6195. phba->sli4_hba.max_cfg_param.xri_base,
  6196. phba->sli4_hba.max_cfg_param.max_xri,
  6197. phba->sli4_hba.max_cfg_param.vpi_base,
  6198. phba->sli4_hba.max_cfg_param.max_vpi,
  6199. phba->sli4_hba.max_cfg_param.vfi_base,
  6200. phba->sli4_hba.max_cfg_param.max_vfi,
  6201. phba->sli4_hba.max_cfg_param.rpi_base,
  6202. phba->sli4_hba.max_cfg_param.max_rpi,
  6203. phba->sli4_hba.max_cfg_param.max_fcfi);
  6204. }
  6205. if (rc)
  6206. goto read_cfg_out;
  6207. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  6208. length = phba->sli4_hba.max_cfg_param.max_xri -
  6209. lpfc_sli4_get_els_iocb_cnt(phba);
  6210. if (phba->cfg_hba_queue_depth > length) {
  6211. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6212. "3361 HBA queue depth changed from %d to %d\n",
  6213. phba->cfg_hba_queue_depth, length);
  6214. phba->cfg_hba_queue_depth = length;
  6215. }
  6216. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  6217. LPFC_SLI_INTF_IF_TYPE_2)
  6218. goto read_cfg_out;
  6219. /* get the pf# and vf# for SLI4 if_type 2 port */
  6220. length = (sizeof(struct lpfc_mbx_get_func_cfg) -
  6221. sizeof(struct lpfc_sli4_cfg_mhdr));
  6222. lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
  6223. LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
  6224. length, LPFC_SLI4_MBX_EMBED);
  6225. rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  6226. shdr = (union lpfc_sli4_cfg_shdr *)
  6227. &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
  6228. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6229. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  6230. if (rc2 || shdr_status || shdr_add_status) {
  6231. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6232. "3026 Mailbox failed , mbxCmd x%x "
  6233. "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
  6234. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  6235. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  6236. goto read_cfg_out;
  6237. }
  6238. /* search for fc_fcoe resrouce descriptor */
  6239. get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
  6240. pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
  6241. desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
  6242. length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
  6243. if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
  6244. length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
  6245. else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
  6246. goto read_cfg_out;
  6247. for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
  6248. desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
  6249. if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
  6250. bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
  6251. phba->sli4_hba.iov.pf_number =
  6252. bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
  6253. phba->sli4_hba.iov.vf_number =
  6254. bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
  6255. break;
  6256. }
  6257. }
  6258. if (i < LPFC_RSRC_DESC_MAX_NUM)
  6259. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6260. "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
  6261. "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
  6262. phba->sli4_hba.iov.vf_number);
  6263. else
  6264. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6265. "3028 GET_FUNCTION_CONFIG: failed to find "
  6266. "Resrouce Descriptor:x%x\n",
  6267. LPFC_RSRC_DESC_TYPE_FCFCOE);
  6268. read_cfg_out:
  6269. mempool_free(pmb, phba->mbox_mem_pool);
  6270. return rc;
  6271. }
  6272. /**
  6273. * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
  6274. * @phba: pointer to lpfc hba data structure.
  6275. *
  6276. * This routine is invoked to setup the port-side endian order when
  6277. * the port if_type is 0. This routine has no function for other
  6278. * if_types.
  6279. *
  6280. * Return codes
  6281. * 0 - successful
  6282. * -ENOMEM - No available memory
  6283. * -EIO - The mailbox failed to complete successfully.
  6284. **/
  6285. static int
  6286. lpfc_setup_endian_order(struct lpfc_hba *phba)
  6287. {
  6288. LPFC_MBOXQ_t *mboxq;
  6289. uint32_t if_type, rc = 0;
  6290. uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
  6291. HOST_ENDIAN_HIGH_WORD1};
  6292. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  6293. switch (if_type) {
  6294. case LPFC_SLI_INTF_IF_TYPE_0:
  6295. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  6296. GFP_KERNEL);
  6297. if (!mboxq) {
  6298. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6299. "0492 Unable to allocate memory for "
  6300. "issuing SLI_CONFIG_SPECIAL mailbox "
  6301. "command\n");
  6302. return -ENOMEM;
  6303. }
  6304. /*
  6305. * The SLI4_CONFIG_SPECIAL mailbox command requires the first
  6306. * two words to contain special data values and no other data.
  6307. */
  6308. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  6309. memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
  6310. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6311. if (rc != MBX_SUCCESS) {
  6312. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6313. "0493 SLI_CONFIG_SPECIAL mailbox "
  6314. "failed with status x%x\n",
  6315. rc);
  6316. rc = -EIO;
  6317. }
  6318. mempool_free(mboxq, phba->mbox_mem_pool);
  6319. break;
  6320. case LPFC_SLI_INTF_IF_TYPE_2:
  6321. case LPFC_SLI_INTF_IF_TYPE_1:
  6322. default:
  6323. break;
  6324. }
  6325. return rc;
  6326. }
  6327. /**
  6328. * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
  6329. * @phba: pointer to lpfc hba data structure.
  6330. *
  6331. * This routine is invoked to check the user settable queue counts for EQs and
  6332. * CQs. after this routine is called the counts will be set to valid values that
  6333. * adhere to the constraints of the system's interrupt vectors and the port's
  6334. * queue resources.
  6335. *
  6336. * Return codes
  6337. * 0 - successful
  6338. * -ENOMEM - No available memory
  6339. **/
  6340. static int
  6341. lpfc_sli4_queue_verify(struct lpfc_hba *phba)
  6342. {
  6343. int cfg_fcp_io_channel;
  6344. uint32_t cpu;
  6345. uint32_t i = 0;
  6346. int fof_vectors = phba->cfg_fof ? 1 : 0;
  6347. /*
  6348. * Sanity check for configured queue parameters against the run-time
  6349. * device parameters
  6350. */
  6351. /* Sanity check on HBA EQ parameters */
  6352. cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
  6353. /* It doesn't make sense to have more io channels then online CPUs */
  6354. for_each_present_cpu(cpu) {
  6355. if (cpu_online(cpu))
  6356. i++;
  6357. }
  6358. phba->sli4_hba.num_online_cpu = i;
  6359. phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
  6360. phba->sli4_hba.curr_disp_cpu = 0;
  6361. if (i < cfg_fcp_io_channel) {
  6362. lpfc_printf_log(phba,
  6363. KERN_ERR, LOG_INIT,
  6364. "3188 Reducing IO channels to match number of "
  6365. "online CPUs: from %d to %d\n",
  6366. cfg_fcp_io_channel, i);
  6367. cfg_fcp_io_channel = i;
  6368. }
  6369. if (cfg_fcp_io_channel + fof_vectors >
  6370. phba->sli4_hba.max_cfg_param.max_eq) {
  6371. if (phba->sli4_hba.max_cfg_param.max_eq <
  6372. LPFC_FCP_IO_CHAN_MIN) {
  6373. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6374. "2574 Not enough EQs (%d) from the "
  6375. "pci function for supporting FCP "
  6376. "EQs (%d)\n",
  6377. phba->sli4_hba.max_cfg_param.max_eq,
  6378. phba->cfg_fcp_io_channel);
  6379. goto out_error;
  6380. }
  6381. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6382. "2575 Reducing IO channels to match number of "
  6383. "available EQs: from %d to %d\n",
  6384. cfg_fcp_io_channel,
  6385. phba->sli4_hba.max_cfg_param.max_eq);
  6386. cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq -
  6387. fof_vectors;
  6388. }
  6389. /* The actual number of FCP event queues adopted */
  6390. phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
  6391. /* Get EQ depth from module parameter, fake the default for now */
  6392. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  6393. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  6394. /* Get CQ depth from module parameter, fake the default for now */
  6395. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  6396. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  6397. return 0;
  6398. out_error:
  6399. return -ENOMEM;
  6400. }
  6401. /**
  6402. * lpfc_sli4_queue_create - Create all the SLI4 queues
  6403. * @phba: pointer to lpfc hba data structure.
  6404. *
  6405. * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
  6406. * operation. For each SLI4 queue type, the parameters such as queue entry
  6407. * count (queue depth) shall be taken from the module parameter. For now,
  6408. * we just use some constant number as place holder.
  6409. *
  6410. * Return codes
  6411. * 0 - successful
  6412. * -ENOMEM - No availble memory
  6413. * -EIO - The mailbox failed to complete successfully.
  6414. **/
  6415. int
  6416. lpfc_sli4_queue_create(struct lpfc_hba *phba)
  6417. {
  6418. struct lpfc_queue *qdesc;
  6419. int idx;
  6420. /*
  6421. * Create HBA Record arrays.
  6422. */
  6423. if (!phba->cfg_fcp_io_channel)
  6424. return -ERANGE;
  6425. phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
  6426. phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
  6427. phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
  6428. phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
  6429. phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
  6430. phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
  6431. phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
  6432. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6433. if (!phba->sli4_hba.hba_eq) {
  6434. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6435. "2576 Failed allocate memory for "
  6436. "fast-path EQ record array\n");
  6437. goto out_error;
  6438. }
  6439. phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
  6440. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6441. if (!phba->sli4_hba.fcp_cq) {
  6442. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6443. "2577 Failed allocate memory for fast-path "
  6444. "CQ record array\n");
  6445. goto out_error;
  6446. }
  6447. phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
  6448. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6449. if (!phba->sli4_hba.fcp_wq) {
  6450. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6451. "2578 Failed allocate memory for fast-path "
  6452. "WQ record array\n");
  6453. goto out_error;
  6454. }
  6455. /*
  6456. * Since the first EQ can have multiple CQs associated with it,
  6457. * this array is used to quickly see if we have a FCP fast-path
  6458. * CQ match.
  6459. */
  6460. phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
  6461. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6462. if (!phba->sli4_hba.fcp_cq_map) {
  6463. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6464. "2545 Failed allocate memory for fast-path "
  6465. "CQ map\n");
  6466. goto out_error;
  6467. }
  6468. /*
  6469. * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
  6470. * how many EQs to create.
  6471. */
  6472. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6473. /* Create EQs */
  6474. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  6475. phba->sli4_hba.eq_ecount);
  6476. if (!qdesc) {
  6477. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6478. "0497 Failed allocate EQ (%d)\n", idx);
  6479. goto out_error;
  6480. }
  6481. phba->sli4_hba.hba_eq[idx] = qdesc;
  6482. /* Create Fast Path FCP CQs */
  6483. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6484. phba->sli4_hba.cq_ecount);
  6485. if (!qdesc) {
  6486. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6487. "0499 Failed allocate fast-path FCP "
  6488. "CQ (%d)\n", idx);
  6489. goto out_error;
  6490. }
  6491. phba->sli4_hba.fcp_cq[idx] = qdesc;
  6492. /* Create Fast Path FCP WQs */
  6493. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  6494. phba->sli4_hba.wq_ecount);
  6495. if (!qdesc) {
  6496. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6497. "0503 Failed allocate fast-path FCP "
  6498. "WQ (%d)\n", idx);
  6499. goto out_error;
  6500. }
  6501. phba->sli4_hba.fcp_wq[idx] = qdesc;
  6502. }
  6503. /*
  6504. * Create Slow Path Completion Queues (CQs)
  6505. */
  6506. /* Create slow-path Mailbox Command Complete Queue */
  6507. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6508. phba->sli4_hba.cq_ecount);
  6509. if (!qdesc) {
  6510. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6511. "0500 Failed allocate slow-path mailbox CQ\n");
  6512. goto out_error;
  6513. }
  6514. phba->sli4_hba.mbx_cq = qdesc;
  6515. /* Create slow-path ELS Complete Queue */
  6516. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6517. phba->sli4_hba.cq_ecount);
  6518. if (!qdesc) {
  6519. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6520. "0501 Failed allocate slow-path ELS CQ\n");
  6521. goto out_error;
  6522. }
  6523. phba->sli4_hba.els_cq = qdesc;
  6524. /*
  6525. * Create Slow Path Work Queues (WQs)
  6526. */
  6527. /* Create Mailbox Command Queue */
  6528. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
  6529. phba->sli4_hba.mq_ecount);
  6530. if (!qdesc) {
  6531. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6532. "0505 Failed allocate slow-path MQ\n");
  6533. goto out_error;
  6534. }
  6535. phba->sli4_hba.mbx_wq = qdesc;
  6536. /*
  6537. * Create ELS Work Queues
  6538. */
  6539. /* Create slow-path ELS Work Queue */
  6540. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  6541. phba->sli4_hba.wq_ecount);
  6542. if (!qdesc) {
  6543. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6544. "0504 Failed allocate slow-path ELS WQ\n");
  6545. goto out_error;
  6546. }
  6547. phba->sli4_hba.els_wq = qdesc;
  6548. /*
  6549. * Create Receive Queue (RQ)
  6550. */
  6551. /* Create Receive Queue for header */
  6552. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  6553. phba->sli4_hba.rq_ecount);
  6554. if (!qdesc) {
  6555. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6556. "0506 Failed allocate receive HRQ\n");
  6557. goto out_error;
  6558. }
  6559. phba->sli4_hba.hdr_rq = qdesc;
  6560. /* Create Receive Queue for data */
  6561. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  6562. phba->sli4_hba.rq_ecount);
  6563. if (!qdesc) {
  6564. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6565. "0507 Failed allocate receive DRQ\n");
  6566. goto out_error;
  6567. }
  6568. phba->sli4_hba.dat_rq = qdesc;
  6569. /* Create the Queues needed for Flash Optimized Fabric operations */
  6570. if (phba->cfg_fof)
  6571. lpfc_fof_queue_create(phba);
  6572. return 0;
  6573. out_error:
  6574. lpfc_sli4_queue_destroy(phba);
  6575. return -ENOMEM;
  6576. }
  6577. /**
  6578. * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
  6579. * @phba: pointer to lpfc hba data structure.
  6580. *
  6581. * This routine is invoked to release all the SLI4 queues with the FCoE HBA
  6582. * operation.
  6583. *
  6584. * Return codes
  6585. * 0 - successful
  6586. * -ENOMEM - No available memory
  6587. * -EIO - The mailbox failed to complete successfully.
  6588. **/
  6589. void
  6590. lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
  6591. {
  6592. int idx;
  6593. if (phba->cfg_fof)
  6594. lpfc_fof_queue_destroy(phba);
  6595. if (phba->sli4_hba.hba_eq != NULL) {
  6596. /* Release HBA event queue */
  6597. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6598. if (phba->sli4_hba.hba_eq[idx] != NULL) {
  6599. lpfc_sli4_queue_free(
  6600. phba->sli4_hba.hba_eq[idx]);
  6601. phba->sli4_hba.hba_eq[idx] = NULL;
  6602. }
  6603. }
  6604. kfree(phba->sli4_hba.hba_eq);
  6605. phba->sli4_hba.hba_eq = NULL;
  6606. }
  6607. if (phba->sli4_hba.fcp_cq != NULL) {
  6608. /* Release FCP completion queue */
  6609. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6610. if (phba->sli4_hba.fcp_cq[idx] != NULL) {
  6611. lpfc_sli4_queue_free(
  6612. phba->sli4_hba.fcp_cq[idx]);
  6613. phba->sli4_hba.fcp_cq[idx] = NULL;
  6614. }
  6615. }
  6616. kfree(phba->sli4_hba.fcp_cq);
  6617. phba->sli4_hba.fcp_cq = NULL;
  6618. }
  6619. if (phba->sli4_hba.fcp_wq != NULL) {
  6620. /* Release FCP work queue */
  6621. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6622. if (phba->sli4_hba.fcp_wq[idx] != NULL) {
  6623. lpfc_sli4_queue_free(
  6624. phba->sli4_hba.fcp_wq[idx]);
  6625. phba->sli4_hba.fcp_wq[idx] = NULL;
  6626. }
  6627. }
  6628. kfree(phba->sli4_hba.fcp_wq);
  6629. phba->sli4_hba.fcp_wq = NULL;
  6630. }
  6631. /* Release FCP CQ mapping array */
  6632. if (phba->sli4_hba.fcp_cq_map != NULL) {
  6633. kfree(phba->sli4_hba.fcp_cq_map);
  6634. phba->sli4_hba.fcp_cq_map = NULL;
  6635. }
  6636. /* Release mailbox command work queue */
  6637. if (phba->sli4_hba.mbx_wq != NULL) {
  6638. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  6639. phba->sli4_hba.mbx_wq = NULL;
  6640. }
  6641. /* Release ELS work queue */
  6642. if (phba->sli4_hba.els_wq != NULL) {
  6643. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  6644. phba->sli4_hba.els_wq = NULL;
  6645. }
  6646. /* Release unsolicited receive queue */
  6647. if (phba->sli4_hba.hdr_rq != NULL) {
  6648. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  6649. phba->sli4_hba.hdr_rq = NULL;
  6650. }
  6651. if (phba->sli4_hba.dat_rq != NULL) {
  6652. lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
  6653. phba->sli4_hba.dat_rq = NULL;
  6654. }
  6655. /* Release ELS complete queue */
  6656. if (phba->sli4_hba.els_cq != NULL) {
  6657. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  6658. phba->sli4_hba.els_cq = NULL;
  6659. }
  6660. /* Release mailbox command complete queue */
  6661. if (phba->sli4_hba.mbx_cq != NULL) {
  6662. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  6663. phba->sli4_hba.mbx_cq = NULL;
  6664. }
  6665. return;
  6666. }
  6667. /**
  6668. * lpfc_sli4_queue_setup - Set up all the SLI4 queues
  6669. * @phba: pointer to lpfc hba data structure.
  6670. *
  6671. * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
  6672. * operation.
  6673. *
  6674. * Return codes
  6675. * 0 - successful
  6676. * -ENOMEM - No available memory
  6677. * -EIO - The mailbox failed to complete successfully.
  6678. **/
  6679. int
  6680. lpfc_sli4_queue_setup(struct lpfc_hba *phba)
  6681. {
  6682. struct lpfc_sli *psli = &phba->sli;
  6683. struct lpfc_sli_ring *pring;
  6684. int rc = -ENOMEM;
  6685. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  6686. int fcp_cq_index = 0;
  6687. uint32_t shdr_status, shdr_add_status;
  6688. union lpfc_sli4_cfg_shdr *shdr;
  6689. LPFC_MBOXQ_t *mboxq;
  6690. uint32_t length;
  6691. /* Check for dual-ULP support */
  6692. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6693. if (!mboxq) {
  6694. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6695. "3249 Unable to allocate memory for "
  6696. "QUERY_FW_CFG mailbox command\n");
  6697. return -ENOMEM;
  6698. }
  6699. length = (sizeof(struct lpfc_mbx_query_fw_config) -
  6700. sizeof(struct lpfc_sli4_cfg_mhdr));
  6701. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  6702. LPFC_MBOX_OPCODE_QUERY_FW_CFG,
  6703. length, LPFC_SLI4_MBX_EMBED);
  6704. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6705. shdr = (union lpfc_sli4_cfg_shdr *)
  6706. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  6707. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6708. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  6709. if (shdr_status || shdr_add_status || rc) {
  6710. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6711. "3250 QUERY_FW_CFG mailbox failed with status "
  6712. "x%x add_status x%x, mbx status x%x\n",
  6713. shdr_status, shdr_add_status, rc);
  6714. if (rc != MBX_TIMEOUT)
  6715. mempool_free(mboxq, phba->mbox_mem_pool);
  6716. rc = -ENXIO;
  6717. goto out_error;
  6718. }
  6719. phba->sli4_hba.fw_func_mode =
  6720. mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
  6721. phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
  6722. phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
  6723. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6724. "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
  6725. "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
  6726. phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
  6727. if (rc != MBX_TIMEOUT)
  6728. mempool_free(mboxq, phba->mbox_mem_pool);
  6729. /*
  6730. * Set up HBA Event Queues (EQs)
  6731. */
  6732. /* Set up HBA event queue */
  6733. if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
  6734. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6735. "3147 Fast-path EQs not allocated\n");
  6736. rc = -ENOMEM;
  6737. goto out_error;
  6738. }
  6739. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
  6740. if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
  6741. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6742. "0522 Fast-path EQ (%d) not "
  6743. "allocated\n", fcp_eqidx);
  6744. rc = -ENOMEM;
  6745. goto out_destroy_hba_eq;
  6746. }
  6747. rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
  6748. (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
  6749. if (rc) {
  6750. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6751. "0523 Failed setup of fast-path EQ "
  6752. "(%d), rc = 0x%x\n", fcp_eqidx,
  6753. (uint32_t)rc);
  6754. goto out_destroy_hba_eq;
  6755. }
  6756. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6757. "2584 HBA EQ setup: "
  6758. "queue[%d]-id=%d\n", fcp_eqidx,
  6759. phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
  6760. }
  6761. /* Set up fast-path FCP Response Complete Queue */
  6762. if (!phba->sli4_hba.fcp_cq) {
  6763. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6764. "3148 Fast-path FCP CQ array not "
  6765. "allocated\n");
  6766. rc = -ENOMEM;
  6767. goto out_destroy_hba_eq;
  6768. }
  6769. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
  6770. if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
  6771. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6772. "0526 Fast-path FCP CQ (%d) not "
  6773. "allocated\n", fcp_cqidx);
  6774. rc = -ENOMEM;
  6775. goto out_destroy_fcp_cq;
  6776. }
  6777. rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
  6778. phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
  6779. if (rc) {
  6780. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6781. "0527 Failed setup of fast-path FCP "
  6782. "CQ (%d), rc = 0x%x\n", fcp_cqidx,
  6783. (uint32_t)rc);
  6784. goto out_destroy_fcp_cq;
  6785. }
  6786. /* Setup fcp_cq_map for fast lookup */
  6787. phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
  6788. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
  6789. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6790. "2588 FCP CQ setup: cq[%d]-id=%d, "
  6791. "parent seq[%d]-id=%d\n",
  6792. fcp_cqidx,
  6793. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
  6794. fcp_cqidx,
  6795. phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
  6796. }
  6797. /* Set up fast-path FCP Work Queue */
  6798. if (!phba->sli4_hba.fcp_wq) {
  6799. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6800. "3149 Fast-path FCP WQ array not "
  6801. "allocated\n");
  6802. rc = -ENOMEM;
  6803. goto out_destroy_fcp_cq;
  6804. }
  6805. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
  6806. if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
  6807. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6808. "0534 Fast-path FCP WQ (%d) not "
  6809. "allocated\n", fcp_wqidx);
  6810. rc = -ENOMEM;
  6811. goto out_destroy_fcp_wq;
  6812. }
  6813. rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
  6814. phba->sli4_hba.fcp_cq[fcp_wqidx],
  6815. LPFC_FCP);
  6816. if (rc) {
  6817. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6818. "0535 Failed setup of fast-path FCP "
  6819. "WQ (%d), rc = 0x%x\n", fcp_wqidx,
  6820. (uint32_t)rc);
  6821. goto out_destroy_fcp_wq;
  6822. }
  6823. /* Bind this WQ to the next FCP ring */
  6824. pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
  6825. pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
  6826. phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
  6827. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6828. "2591 FCP WQ setup: wq[%d]-id=%d, "
  6829. "parent cq[%d]-id=%d\n",
  6830. fcp_wqidx,
  6831. phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
  6832. fcp_cq_index,
  6833. phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
  6834. }
  6835. /*
  6836. * Set up Complete Queues (CQs)
  6837. */
  6838. /* Set up slow-path MBOX Complete Queue as the first CQ */
  6839. if (!phba->sli4_hba.mbx_cq) {
  6840. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6841. "0528 Mailbox CQ not allocated\n");
  6842. rc = -ENOMEM;
  6843. goto out_destroy_fcp_wq;
  6844. }
  6845. rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
  6846. phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
  6847. if (rc) {
  6848. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6849. "0529 Failed setup of slow-path mailbox CQ: "
  6850. "rc = 0x%x\n", (uint32_t)rc);
  6851. goto out_destroy_fcp_wq;
  6852. }
  6853. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6854. "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
  6855. phba->sli4_hba.mbx_cq->queue_id,
  6856. phba->sli4_hba.hba_eq[0]->queue_id);
  6857. /* Set up slow-path ELS Complete Queue */
  6858. if (!phba->sli4_hba.els_cq) {
  6859. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6860. "0530 ELS CQ not allocated\n");
  6861. rc = -ENOMEM;
  6862. goto out_destroy_mbx_cq;
  6863. }
  6864. rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
  6865. phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
  6866. if (rc) {
  6867. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6868. "0531 Failed setup of slow-path ELS CQ: "
  6869. "rc = 0x%x\n", (uint32_t)rc);
  6870. goto out_destroy_mbx_cq;
  6871. }
  6872. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6873. "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
  6874. phba->sli4_hba.els_cq->queue_id,
  6875. phba->sli4_hba.hba_eq[0]->queue_id);
  6876. /*
  6877. * Set up all the Work Queues (WQs)
  6878. */
  6879. /* Set up Mailbox Command Queue */
  6880. if (!phba->sli4_hba.mbx_wq) {
  6881. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6882. "0538 Slow-path MQ not allocated\n");
  6883. rc = -ENOMEM;
  6884. goto out_destroy_els_cq;
  6885. }
  6886. rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
  6887. phba->sli4_hba.mbx_cq, LPFC_MBOX);
  6888. if (rc) {
  6889. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6890. "0539 Failed setup of slow-path MQ: "
  6891. "rc = 0x%x\n", rc);
  6892. goto out_destroy_els_cq;
  6893. }
  6894. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6895. "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
  6896. phba->sli4_hba.mbx_wq->queue_id,
  6897. phba->sli4_hba.mbx_cq->queue_id);
  6898. /* Set up slow-path ELS Work Queue */
  6899. if (!phba->sli4_hba.els_wq) {
  6900. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6901. "0536 Slow-path ELS WQ not allocated\n");
  6902. rc = -ENOMEM;
  6903. goto out_destroy_mbx_wq;
  6904. }
  6905. rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
  6906. phba->sli4_hba.els_cq, LPFC_ELS);
  6907. if (rc) {
  6908. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6909. "0537 Failed setup of slow-path ELS WQ: "
  6910. "rc = 0x%x\n", (uint32_t)rc);
  6911. goto out_destroy_mbx_wq;
  6912. }
  6913. /* Bind this WQ to the ELS ring */
  6914. pring = &psli->ring[LPFC_ELS_RING];
  6915. pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
  6916. phba->sli4_hba.els_cq->pring = pring;
  6917. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6918. "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
  6919. phba->sli4_hba.els_wq->queue_id,
  6920. phba->sli4_hba.els_cq->queue_id);
  6921. /*
  6922. * Create Receive Queue (RQ)
  6923. */
  6924. if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
  6925. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6926. "0540 Receive Queue not allocated\n");
  6927. rc = -ENOMEM;
  6928. goto out_destroy_els_wq;
  6929. }
  6930. lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
  6931. lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
  6932. rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  6933. phba->sli4_hba.els_cq, LPFC_USOL);
  6934. if (rc) {
  6935. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6936. "0541 Failed setup of Receive Queue: "
  6937. "rc = 0x%x\n", (uint32_t)rc);
  6938. goto out_destroy_fcp_wq;
  6939. }
  6940. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6941. "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
  6942. "parent cq-id=%d\n",
  6943. phba->sli4_hba.hdr_rq->queue_id,
  6944. phba->sli4_hba.dat_rq->queue_id,
  6945. phba->sli4_hba.els_cq->queue_id);
  6946. if (phba->cfg_fof) {
  6947. rc = lpfc_fof_queue_setup(phba);
  6948. if (rc) {
  6949. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6950. "0549 Failed setup of FOF Queues: "
  6951. "rc = 0x%x\n", rc);
  6952. goto out_destroy_els_rq;
  6953. }
  6954. }
  6955. return 0;
  6956. out_destroy_els_rq:
  6957. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
  6958. out_destroy_els_wq:
  6959. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  6960. out_destroy_mbx_wq:
  6961. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  6962. out_destroy_els_cq:
  6963. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  6964. out_destroy_mbx_cq:
  6965. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  6966. out_destroy_fcp_wq:
  6967. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
  6968. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
  6969. out_destroy_fcp_cq:
  6970. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
  6971. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
  6972. out_destroy_hba_eq:
  6973. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
  6974. lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
  6975. out_error:
  6976. return rc;
  6977. }
  6978. /**
  6979. * lpfc_sli4_queue_unset - Unset all the SLI4 queues
  6980. * @phba: pointer to lpfc hba data structure.
  6981. *
  6982. * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
  6983. * operation.
  6984. *
  6985. * Return codes
  6986. * 0 - successful
  6987. * -ENOMEM - No available memory
  6988. * -EIO - The mailbox failed to complete successfully.
  6989. **/
  6990. void
  6991. lpfc_sli4_queue_unset(struct lpfc_hba *phba)
  6992. {
  6993. int fcp_qidx;
  6994. /* Unset the queues created for Flash Optimized Fabric operations */
  6995. if (phba->cfg_fof)
  6996. lpfc_fof_queue_destroy(phba);
  6997. /* Unset mailbox command work queue */
  6998. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  6999. /* Unset ELS work queue */
  7000. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  7001. /* Unset unsolicited receive queue */
  7002. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
  7003. /* Unset FCP work queue */
  7004. if (phba->sli4_hba.fcp_wq) {
  7005. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  7006. fcp_qidx++)
  7007. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
  7008. }
  7009. /* Unset mailbox command complete queue */
  7010. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  7011. /* Unset ELS complete queue */
  7012. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  7013. /* Unset FCP response complete queue */
  7014. if (phba->sli4_hba.fcp_cq) {
  7015. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  7016. fcp_qidx++)
  7017. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
  7018. }
  7019. /* Unset fast-path event queue */
  7020. if (phba->sli4_hba.hba_eq) {
  7021. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  7022. fcp_qidx++)
  7023. lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
  7024. }
  7025. }
  7026. /**
  7027. * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
  7028. * @phba: pointer to lpfc hba data structure.
  7029. *
  7030. * This routine is invoked to allocate and set up a pool of completion queue
  7031. * events. The body of the completion queue event is a completion queue entry
  7032. * CQE. For now, this pool is used for the interrupt service routine to queue
  7033. * the following HBA completion queue events for the worker thread to process:
  7034. * - Mailbox asynchronous events
  7035. * - Receive queue completion unsolicited events
  7036. * Later, this can be used for all the slow-path events.
  7037. *
  7038. * Return codes
  7039. * 0 - successful
  7040. * -ENOMEM - No available memory
  7041. **/
  7042. static int
  7043. lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
  7044. {
  7045. struct lpfc_cq_event *cq_event;
  7046. int i;
  7047. for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
  7048. cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
  7049. if (!cq_event)
  7050. goto out_pool_create_fail;
  7051. list_add_tail(&cq_event->list,
  7052. &phba->sli4_hba.sp_cqe_event_pool);
  7053. }
  7054. return 0;
  7055. out_pool_create_fail:
  7056. lpfc_sli4_cq_event_pool_destroy(phba);
  7057. return -ENOMEM;
  7058. }
  7059. /**
  7060. * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
  7061. * @phba: pointer to lpfc hba data structure.
  7062. *
  7063. * This routine is invoked to free the pool of completion queue events at
  7064. * driver unload time. Note that, it is the responsibility of the driver
  7065. * cleanup routine to free all the outstanding completion-queue events
  7066. * allocated from this pool back into the pool before invoking this routine
  7067. * to destroy the pool.
  7068. **/
  7069. static void
  7070. lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
  7071. {
  7072. struct lpfc_cq_event *cq_event, *next_cq_event;
  7073. list_for_each_entry_safe(cq_event, next_cq_event,
  7074. &phba->sli4_hba.sp_cqe_event_pool, list) {
  7075. list_del(&cq_event->list);
  7076. kfree(cq_event);
  7077. }
  7078. }
  7079. /**
  7080. * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  7081. * @phba: pointer to lpfc hba data structure.
  7082. *
  7083. * This routine is the lock free version of the API invoked to allocate a
  7084. * completion-queue event from the free pool.
  7085. *
  7086. * Return: Pointer to the newly allocated completion-queue event if successful
  7087. * NULL otherwise.
  7088. **/
  7089. struct lpfc_cq_event *
  7090. __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  7091. {
  7092. struct lpfc_cq_event *cq_event = NULL;
  7093. list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
  7094. struct lpfc_cq_event, list);
  7095. return cq_event;
  7096. }
  7097. /**
  7098. * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  7099. * @phba: pointer to lpfc hba data structure.
  7100. *
  7101. * This routine is the lock version of the API invoked to allocate a
  7102. * completion-queue event from the free pool.
  7103. *
  7104. * Return: Pointer to the newly allocated completion-queue event if successful
  7105. * NULL otherwise.
  7106. **/
  7107. struct lpfc_cq_event *
  7108. lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  7109. {
  7110. struct lpfc_cq_event *cq_event;
  7111. unsigned long iflags;
  7112. spin_lock_irqsave(&phba->hbalock, iflags);
  7113. cq_event = __lpfc_sli4_cq_event_alloc(phba);
  7114. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7115. return cq_event;
  7116. }
  7117. /**
  7118. * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  7119. * @phba: pointer to lpfc hba data structure.
  7120. * @cq_event: pointer to the completion queue event to be freed.
  7121. *
  7122. * This routine is the lock free version of the API invoked to release a
  7123. * completion-queue event back into the free pool.
  7124. **/
  7125. void
  7126. __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  7127. struct lpfc_cq_event *cq_event)
  7128. {
  7129. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
  7130. }
  7131. /**
  7132. * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  7133. * @phba: pointer to lpfc hba data structure.
  7134. * @cq_event: pointer to the completion queue event to be freed.
  7135. *
  7136. * This routine is the lock version of the API invoked to release a
  7137. * completion-queue event back into the free pool.
  7138. **/
  7139. void
  7140. lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  7141. struct lpfc_cq_event *cq_event)
  7142. {
  7143. unsigned long iflags;
  7144. spin_lock_irqsave(&phba->hbalock, iflags);
  7145. __lpfc_sli4_cq_event_release(phba, cq_event);
  7146. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7147. }
  7148. /**
  7149. * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
  7150. * @phba: pointer to lpfc hba data structure.
  7151. *
  7152. * This routine is to free all the pending completion-queue events to the
  7153. * back into the free pool for device reset.
  7154. **/
  7155. static void
  7156. lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
  7157. {
  7158. LIST_HEAD(cqelist);
  7159. struct lpfc_cq_event *cqe;
  7160. unsigned long iflags;
  7161. /* Retrieve all the pending WCQEs from pending WCQE lists */
  7162. spin_lock_irqsave(&phba->hbalock, iflags);
  7163. /* Pending FCP XRI abort events */
  7164. list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7165. &cqelist);
  7166. /* Pending ELS XRI abort events */
  7167. list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7168. &cqelist);
  7169. /* Pending asynnc events */
  7170. list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
  7171. &cqelist);
  7172. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7173. while (!list_empty(&cqelist)) {
  7174. list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
  7175. lpfc_sli4_cq_event_release(phba, cqe);
  7176. }
  7177. }
  7178. /**
  7179. * lpfc_pci_function_reset - Reset pci function.
  7180. * @phba: pointer to lpfc hba data structure.
  7181. *
  7182. * This routine is invoked to request a PCI function reset. It will destroys
  7183. * all resources assigned to the PCI function which originates this request.
  7184. *
  7185. * Return codes
  7186. * 0 - successful
  7187. * -ENOMEM - No available memory
  7188. * -EIO - The mailbox failed to complete successfully.
  7189. **/
  7190. int
  7191. lpfc_pci_function_reset(struct lpfc_hba *phba)
  7192. {
  7193. LPFC_MBOXQ_t *mboxq;
  7194. uint32_t rc = 0, if_type;
  7195. uint32_t shdr_status, shdr_add_status;
  7196. uint32_t rdy_chk;
  7197. uint32_t port_reset = 0;
  7198. union lpfc_sli4_cfg_shdr *shdr;
  7199. struct lpfc_register reg_data;
  7200. uint16_t devid;
  7201. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7202. switch (if_type) {
  7203. case LPFC_SLI_INTF_IF_TYPE_0:
  7204. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  7205. GFP_KERNEL);
  7206. if (!mboxq) {
  7207. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7208. "0494 Unable to allocate memory for "
  7209. "issuing SLI_FUNCTION_RESET mailbox "
  7210. "command\n");
  7211. return -ENOMEM;
  7212. }
  7213. /* Setup PCI function reset mailbox-ioctl command */
  7214. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  7215. LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
  7216. LPFC_SLI4_MBX_EMBED);
  7217. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7218. shdr = (union lpfc_sli4_cfg_shdr *)
  7219. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  7220. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  7221. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  7222. &shdr->response);
  7223. if (rc != MBX_TIMEOUT)
  7224. mempool_free(mboxq, phba->mbox_mem_pool);
  7225. if (shdr_status || shdr_add_status || rc) {
  7226. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7227. "0495 SLI_FUNCTION_RESET mailbox "
  7228. "failed with status x%x add_status x%x,"
  7229. " mbx status x%x\n",
  7230. shdr_status, shdr_add_status, rc);
  7231. rc = -ENXIO;
  7232. }
  7233. break;
  7234. case LPFC_SLI_INTF_IF_TYPE_2:
  7235. wait:
  7236. /*
  7237. * Poll the Port Status Register and wait for RDY for
  7238. * up to 30 seconds. If the port doesn't respond, treat
  7239. * it as an error.
  7240. */
  7241. for (rdy_chk = 0; rdy_chk < 3000; rdy_chk++) {
  7242. if (lpfc_readl(phba->sli4_hba.u.if_type2.
  7243. STATUSregaddr, &reg_data.word0)) {
  7244. rc = -ENODEV;
  7245. goto out;
  7246. }
  7247. if (bf_get(lpfc_sliport_status_rdy, &reg_data))
  7248. break;
  7249. msleep(20);
  7250. }
  7251. if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
  7252. phba->work_status[0] = readl(
  7253. phba->sli4_hba.u.if_type2.ERR1regaddr);
  7254. phba->work_status[1] = readl(
  7255. phba->sli4_hba.u.if_type2.ERR2regaddr);
  7256. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7257. "2890 Port not ready, port status reg "
  7258. "0x%x error 1=0x%x, error 2=0x%x\n",
  7259. reg_data.word0,
  7260. phba->work_status[0],
  7261. phba->work_status[1]);
  7262. rc = -ENODEV;
  7263. goto out;
  7264. }
  7265. if (!port_reset) {
  7266. /*
  7267. * Reset the port now
  7268. */
  7269. reg_data.word0 = 0;
  7270. bf_set(lpfc_sliport_ctrl_end, &reg_data,
  7271. LPFC_SLIPORT_LITTLE_ENDIAN);
  7272. bf_set(lpfc_sliport_ctrl_ip, &reg_data,
  7273. LPFC_SLIPORT_INIT_PORT);
  7274. writel(reg_data.word0, phba->sli4_hba.u.if_type2.
  7275. CTRLregaddr);
  7276. /* flush */
  7277. pci_read_config_word(phba->pcidev,
  7278. PCI_DEVICE_ID, &devid);
  7279. port_reset = 1;
  7280. msleep(20);
  7281. goto wait;
  7282. } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
  7283. rc = -ENODEV;
  7284. goto out;
  7285. }
  7286. break;
  7287. case LPFC_SLI_INTF_IF_TYPE_1:
  7288. default:
  7289. break;
  7290. }
  7291. out:
  7292. /* Catch the not-ready port failure after a port reset. */
  7293. if (rc) {
  7294. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7295. "3317 HBA not functional: IP Reset Failed "
  7296. "try: echo fw_reset > board_mode\n");
  7297. rc = -ENODEV;
  7298. }
  7299. return rc;
  7300. }
  7301. /**
  7302. * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
  7303. * @phba: pointer to lpfc hba data structure.
  7304. *
  7305. * This routine is invoked to set up the PCI device memory space for device
  7306. * with SLI-4 interface spec.
  7307. *
  7308. * Return codes
  7309. * 0 - successful
  7310. * other values - error
  7311. **/
  7312. static int
  7313. lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
  7314. {
  7315. struct pci_dev *pdev;
  7316. unsigned long bar0map_len, bar1map_len, bar2map_len;
  7317. int error = -ENODEV;
  7318. uint32_t if_type;
  7319. /* Obtain PCI device reference */
  7320. if (!phba->pcidev)
  7321. return error;
  7322. else
  7323. pdev = phba->pcidev;
  7324. /* Set the device DMA mask size */
  7325. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  7326. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  7327. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  7328. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  7329. return error;
  7330. }
  7331. }
  7332. /*
  7333. * The BARs and register set definitions and offset locations are
  7334. * dependent on the if_type.
  7335. */
  7336. if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
  7337. &phba->sli4_hba.sli_intf.word0)) {
  7338. return error;
  7339. }
  7340. /* There is no SLI3 failback for SLI4 devices. */
  7341. if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
  7342. LPFC_SLI_INTF_VALID) {
  7343. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7344. "2894 SLI_INTF reg contents invalid "
  7345. "sli_intf reg 0x%x\n",
  7346. phba->sli4_hba.sli_intf.word0);
  7347. return error;
  7348. }
  7349. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7350. /*
  7351. * Get the bus address of SLI4 device Bar regions and the
  7352. * number of bytes required by each mapping. The mapping of the
  7353. * particular PCI BARs regions is dependent on the type of
  7354. * SLI4 device.
  7355. */
  7356. if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
  7357. phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
  7358. bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
  7359. /*
  7360. * Map SLI4 PCI Config Space Register base to a kernel virtual
  7361. * addr
  7362. */
  7363. phba->sli4_hba.conf_regs_memmap_p =
  7364. ioremap(phba->pci_bar0_map, bar0map_len);
  7365. if (!phba->sli4_hba.conf_regs_memmap_p) {
  7366. dev_printk(KERN_ERR, &pdev->dev,
  7367. "ioremap failed for SLI4 PCI config "
  7368. "registers.\n");
  7369. goto out;
  7370. }
  7371. phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
  7372. /* Set up BAR0 PCI config space register memory map */
  7373. lpfc_sli4_bar0_register_memmap(phba, if_type);
  7374. } else {
  7375. phba->pci_bar0_map = pci_resource_start(pdev, 1);
  7376. bar0map_len = pci_resource_len(pdev, 1);
  7377. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7378. dev_printk(KERN_ERR, &pdev->dev,
  7379. "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
  7380. goto out;
  7381. }
  7382. phba->sli4_hba.conf_regs_memmap_p =
  7383. ioremap(phba->pci_bar0_map, bar0map_len);
  7384. if (!phba->sli4_hba.conf_regs_memmap_p) {
  7385. dev_printk(KERN_ERR, &pdev->dev,
  7386. "ioremap failed for SLI4 PCI config "
  7387. "registers.\n");
  7388. goto out;
  7389. }
  7390. lpfc_sli4_bar0_register_memmap(phba, if_type);
  7391. }
  7392. if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
  7393. (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
  7394. /*
  7395. * Map SLI4 if type 0 HBA Control Register base to a kernel
  7396. * virtual address and setup the registers.
  7397. */
  7398. phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
  7399. bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
  7400. phba->sli4_hba.ctrl_regs_memmap_p =
  7401. ioremap(phba->pci_bar1_map, bar1map_len);
  7402. if (!phba->sli4_hba.ctrl_regs_memmap_p) {
  7403. dev_printk(KERN_ERR, &pdev->dev,
  7404. "ioremap failed for SLI4 HBA control registers.\n");
  7405. goto out_iounmap_conf;
  7406. }
  7407. phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
  7408. lpfc_sli4_bar1_register_memmap(phba);
  7409. }
  7410. if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
  7411. (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
  7412. /*
  7413. * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
  7414. * virtual address and setup the registers.
  7415. */
  7416. phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
  7417. bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
  7418. phba->sli4_hba.drbl_regs_memmap_p =
  7419. ioremap(phba->pci_bar2_map, bar2map_len);
  7420. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  7421. dev_printk(KERN_ERR, &pdev->dev,
  7422. "ioremap failed for SLI4 HBA doorbell registers.\n");
  7423. goto out_iounmap_ctrl;
  7424. }
  7425. phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
  7426. error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
  7427. if (error)
  7428. goto out_iounmap_all;
  7429. }
  7430. return 0;
  7431. out_iounmap_all:
  7432. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  7433. out_iounmap_ctrl:
  7434. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  7435. out_iounmap_conf:
  7436. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7437. out:
  7438. return error;
  7439. }
  7440. /**
  7441. * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
  7442. * @phba: pointer to lpfc hba data structure.
  7443. *
  7444. * This routine is invoked to unset the PCI device memory space for device
  7445. * with SLI-4 interface spec.
  7446. **/
  7447. static void
  7448. lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
  7449. {
  7450. uint32_t if_type;
  7451. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7452. switch (if_type) {
  7453. case LPFC_SLI_INTF_IF_TYPE_0:
  7454. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  7455. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  7456. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7457. break;
  7458. case LPFC_SLI_INTF_IF_TYPE_2:
  7459. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7460. break;
  7461. case LPFC_SLI_INTF_IF_TYPE_1:
  7462. default:
  7463. dev_printk(KERN_ERR, &phba->pcidev->dev,
  7464. "FATAL - unsupported SLI4 interface type - %d\n",
  7465. if_type);
  7466. break;
  7467. }
  7468. }
  7469. /**
  7470. * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
  7471. * @phba: pointer to lpfc hba data structure.
  7472. *
  7473. * This routine is invoked to enable the MSI-X interrupt vectors to device
  7474. * with SLI-3 interface specs. The kernel function pci_enable_msix_exact()
  7475. * is called to enable the MSI-X vectors. Note that pci_enable_msix_exact(),
  7476. * once invoked, enables either all or nothing, depending on the current
  7477. * availability of PCI vector resources. The device driver is responsible
  7478. * for calling the individual request_irq() to register each MSI-X vector
  7479. * with a interrupt handler, which is done in this function. Note that
  7480. * later when device is unloading, the driver should always call free_irq()
  7481. * on all MSI-X vectors it has done request_irq() on before calling
  7482. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  7483. * will be left with MSI-X enabled and leaks its vectors.
  7484. *
  7485. * Return codes
  7486. * 0 - successful
  7487. * other values - error
  7488. **/
  7489. static int
  7490. lpfc_sli_enable_msix(struct lpfc_hba *phba)
  7491. {
  7492. int rc, i;
  7493. LPFC_MBOXQ_t *pmb;
  7494. /* Set up MSI-X multi-message vectors */
  7495. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7496. phba->msix_entries[i].entry = i;
  7497. /* Configure MSI-X capability structure */
  7498. rc = pci_enable_msix_exact(phba->pcidev, phba->msix_entries,
  7499. LPFC_MSIX_VECTORS);
  7500. if (rc) {
  7501. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7502. "0420 PCI enable MSI-X failed (%d)\n", rc);
  7503. goto vec_fail_out;
  7504. }
  7505. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7506. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7507. "0477 MSI-X entry[%d]: vector=x%x "
  7508. "message=%d\n", i,
  7509. phba->msix_entries[i].vector,
  7510. phba->msix_entries[i].entry);
  7511. /*
  7512. * Assign MSI-X vectors to interrupt handlers
  7513. */
  7514. /* vector-0 is associated to slow-path handler */
  7515. rc = request_irq(phba->msix_entries[0].vector,
  7516. &lpfc_sli_sp_intr_handler, IRQF_SHARED,
  7517. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  7518. if (rc) {
  7519. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7520. "0421 MSI-X slow-path request_irq failed "
  7521. "(%d)\n", rc);
  7522. goto msi_fail_out;
  7523. }
  7524. /* vector-1 is associated to fast-path handler */
  7525. rc = request_irq(phba->msix_entries[1].vector,
  7526. &lpfc_sli_fp_intr_handler, IRQF_SHARED,
  7527. LPFC_FP_DRIVER_HANDLER_NAME, phba);
  7528. if (rc) {
  7529. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7530. "0429 MSI-X fast-path request_irq failed "
  7531. "(%d)\n", rc);
  7532. goto irq_fail_out;
  7533. }
  7534. /*
  7535. * Configure HBA MSI-X attention conditions to messages
  7536. */
  7537. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7538. if (!pmb) {
  7539. rc = -ENOMEM;
  7540. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7541. "0474 Unable to allocate memory for issuing "
  7542. "MBOX_CONFIG_MSI command\n");
  7543. goto mem_fail_out;
  7544. }
  7545. rc = lpfc_config_msi(phba, pmb);
  7546. if (rc)
  7547. goto mbx_fail_out;
  7548. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  7549. if (rc != MBX_SUCCESS) {
  7550. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  7551. "0351 Config MSI mailbox command failed, "
  7552. "mbxCmd x%x, mbxStatus x%x\n",
  7553. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
  7554. goto mbx_fail_out;
  7555. }
  7556. /* Free memory allocated for mailbox command */
  7557. mempool_free(pmb, phba->mbox_mem_pool);
  7558. return rc;
  7559. mbx_fail_out:
  7560. /* Free memory allocated for mailbox command */
  7561. mempool_free(pmb, phba->mbox_mem_pool);
  7562. mem_fail_out:
  7563. /* free the irq already requested */
  7564. free_irq(phba->msix_entries[1].vector, phba);
  7565. irq_fail_out:
  7566. /* free the irq already requested */
  7567. free_irq(phba->msix_entries[0].vector, phba);
  7568. msi_fail_out:
  7569. /* Unconfigure MSI-X capability structure */
  7570. pci_disable_msix(phba->pcidev);
  7571. vec_fail_out:
  7572. return rc;
  7573. }
  7574. /**
  7575. * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
  7576. * @phba: pointer to lpfc hba data structure.
  7577. *
  7578. * This routine is invoked to release the MSI-X vectors and then disable the
  7579. * MSI-X interrupt mode to device with SLI-3 interface spec.
  7580. **/
  7581. static void
  7582. lpfc_sli_disable_msix(struct lpfc_hba *phba)
  7583. {
  7584. int i;
  7585. /* Free up MSI-X multi-message vectors */
  7586. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7587. free_irq(phba->msix_entries[i].vector, phba);
  7588. /* Disable MSI-X */
  7589. pci_disable_msix(phba->pcidev);
  7590. return;
  7591. }
  7592. /**
  7593. * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
  7594. * @phba: pointer to lpfc hba data structure.
  7595. *
  7596. * This routine is invoked to enable the MSI interrupt mode to device with
  7597. * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
  7598. * enable the MSI vector. The device driver is responsible for calling the
  7599. * request_irq() to register MSI vector with a interrupt the handler, which
  7600. * is done in this function.
  7601. *
  7602. * Return codes
  7603. * 0 - successful
  7604. * other values - error
  7605. */
  7606. static int
  7607. lpfc_sli_enable_msi(struct lpfc_hba *phba)
  7608. {
  7609. int rc;
  7610. rc = pci_enable_msi(phba->pcidev);
  7611. if (!rc)
  7612. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7613. "0462 PCI enable MSI mode success.\n");
  7614. else {
  7615. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7616. "0471 PCI enable MSI mode failed (%d)\n", rc);
  7617. return rc;
  7618. }
  7619. rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  7620. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7621. if (rc) {
  7622. pci_disable_msi(phba->pcidev);
  7623. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7624. "0478 MSI request_irq failed (%d)\n", rc);
  7625. }
  7626. return rc;
  7627. }
  7628. /**
  7629. * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
  7630. * @phba: pointer to lpfc hba data structure.
  7631. *
  7632. * This routine is invoked to disable the MSI interrupt mode to device with
  7633. * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
  7634. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  7635. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  7636. * its vector.
  7637. */
  7638. static void
  7639. lpfc_sli_disable_msi(struct lpfc_hba *phba)
  7640. {
  7641. free_irq(phba->pcidev->irq, phba);
  7642. pci_disable_msi(phba->pcidev);
  7643. return;
  7644. }
  7645. /**
  7646. * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
  7647. * @phba: pointer to lpfc hba data structure.
  7648. *
  7649. * This routine is invoked to enable device interrupt and associate driver's
  7650. * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
  7651. * spec. Depends on the interrupt mode configured to the driver, the driver
  7652. * will try to fallback from the configured interrupt mode to an interrupt
  7653. * mode which is supported by the platform, kernel, and device in the order
  7654. * of:
  7655. * MSI-X -> MSI -> IRQ.
  7656. *
  7657. * Return codes
  7658. * 0 - successful
  7659. * other values - error
  7660. **/
  7661. static uint32_t
  7662. lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  7663. {
  7664. uint32_t intr_mode = LPFC_INTR_ERROR;
  7665. int retval;
  7666. if (cfg_mode == 2) {
  7667. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  7668. retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  7669. if (!retval) {
  7670. /* Now, try to enable MSI-X interrupt mode */
  7671. retval = lpfc_sli_enable_msix(phba);
  7672. if (!retval) {
  7673. /* Indicate initialization to MSI-X mode */
  7674. phba->intr_type = MSIX;
  7675. intr_mode = 2;
  7676. }
  7677. }
  7678. }
  7679. /* Fallback to MSI if MSI-X initialization failed */
  7680. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  7681. retval = lpfc_sli_enable_msi(phba);
  7682. if (!retval) {
  7683. /* Indicate initialization to MSI mode */
  7684. phba->intr_type = MSI;
  7685. intr_mode = 1;
  7686. }
  7687. }
  7688. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  7689. if (phba->intr_type == NONE) {
  7690. retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  7691. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7692. if (!retval) {
  7693. /* Indicate initialization to INTx mode */
  7694. phba->intr_type = INTx;
  7695. intr_mode = 0;
  7696. }
  7697. }
  7698. return intr_mode;
  7699. }
  7700. /**
  7701. * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
  7702. * @phba: pointer to lpfc hba data structure.
  7703. *
  7704. * This routine is invoked to disable device interrupt and disassociate the
  7705. * driver's interrupt handler(s) from interrupt vector(s) to device with
  7706. * SLI-3 interface spec. Depending on the interrupt mode, the driver will
  7707. * release the interrupt vector(s) for the message signaled interrupt.
  7708. **/
  7709. static void
  7710. lpfc_sli_disable_intr(struct lpfc_hba *phba)
  7711. {
  7712. /* Disable the currently initialized interrupt mode */
  7713. if (phba->intr_type == MSIX)
  7714. lpfc_sli_disable_msix(phba);
  7715. else if (phba->intr_type == MSI)
  7716. lpfc_sli_disable_msi(phba);
  7717. else if (phba->intr_type == INTx)
  7718. free_irq(phba->pcidev->irq, phba);
  7719. /* Reset interrupt management states */
  7720. phba->intr_type = NONE;
  7721. phba->sli.slistat.sli_intr = 0;
  7722. return;
  7723. }
  7724. /**
  7725. * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
  7726. * @phba: pointer to lpfc hba data structure.
  7727. *
  7728. * Find next available CPU to use for IRQ to CPU affinity.
  7729. */
  7730. static int
  7731. lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
  7732. {
  7733. struct lpfc_vector_map_info *cpup;
  7734. int cpu;
  7735. cpup = phba->sli4_hba.cpu_map;
  7736. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7737. /* CPU must be online */
  7738. if (cpu_online(cpu)) {
  7739. if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
  7740. (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
  7741. (cpup->phys_id == phys_id)) {
  7742. return cpu;
  7743. }
  7744. }
  7745. cpup++;
  7746. }
  7747. /*
  7748. * If we get here, we have used ALL CPUs for the specific
  7749. * phys_id. Now we need to clear out lpfc_used_cpu and start
  7750. * reusing CPUs.
  7751. */
  7752. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7753. if (lpfc_used_cpu[cpu] == phys_id)
  7754. lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
  7755. }
  7756. cpup = phba->sli4_hba.cpu_map;
  7757. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7758. /* CPU must be online */
  7759. if (cpu_online(cpu)) {
  7760. if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
  7761. (cpup->phys_id == phys_id)) {
  7762. return cpu;
  7763. }
  7764. }
  7765. cpup++;
  7766. }
  7767. return LPFC_VECTOR_MAP_EMPTY;
  7768. }
  7769. /**
  7770. * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
  7771. * @phba: pointer to lpfc hba data structure.
  7772. * @vectors: number of HBA vectors
  7773. *
  7774. * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
  7775. * affinization across multple physical CPUs (numa nodes).
  7776. * In addition, this routine will assign an IO channel for each CPU
  7777. * to use when issuing I/Os.
  7778. */
  7779. static int
  7780. lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
  7781. {
  7782. int i, idx, saved_chann, used_chann, cpu, phys_id;
  7783. int max_phys_id, min_phys_id;
  7784. int num_io_channel, first_cpu, chan;
  7785. struct lpfc_vector_map_info *cpup;
  7786. #ifdef CONFIG_X86
  7787. struct cpuinfo_x86 *cpuinfo;
  7788. #endif
  7789. struct cpumask *mask;
  7790. uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
  7791. /* If there is no mapping, just return */
  7792. if (!phba->cfg_fcp_cpu_map)
  7793. return 1;
  7794. /* Init cpu_map array */
  7795. memset(phba->sli4_hba.cpu_map, 0xff,
  7796. (sizeof(struct lpfc_vector_map_info) *
  7797. phba->sli4_hba.num_present_cpu));
  7798. max_phys_id = 0;
  7799. min_phys_id = 0xff;
  7800. phys_id = 0;
  7801. num_io_channel = 0;
  7802. first_cpu = LPFC_VECTOR_MAP_EMPTY;
  7803. /* Update CPU map with physical id and core id of each CPU */
  7804. cpup = phba->sli4_hba.cpu_map;
  7805. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7806. #ifdef CONFIG_X86
  7807. cpuinfo = &cpu_data(cpu);
  7808. cpup->phys_id = cpuinfo->phys_proc_id;
  7809. cpup->core_id = cpuinfo->cpu_core_id;
  7810. #else
  7811. /* No distinction between CPUs for other platforms */
  7812. cpup->phys_id = 0;
  7813. cpup->core_id = 0;
  7814. #endif
  7815. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7816. "3328 CPU physid %d coreid %d\n",
  7817. cpup->phys_id, cpup->core_id);
  7818. if (cpup->phys_id > max_phys_id)
  7819. max_phys_id = cpup->phys_id;
  7820. if (cpup->phys_id < min_phys_id)
  7821. min_phys_id = cpup->phys_id;
  7822. cpup++;
  7823. }
  7824. phys_id = min_phys_id;
  7825. /* Now associate the HBA vectors with specific CPUs */
  7826. for (idx = 0; idx < vectors; idx++) {
  7827. cpup = phba->sli4_hba.cpu_map;
  7828. cpu = lpfc_find_next_cpu(phba, phys_id);
  7829. if (cpu == LPFC_VECTOR_MAP_EMPTY) {
  7830. /* Try for all phys_id's */
  7831. for (i = 1; i < max_phys_id; i++) {
  7832. phys_id++;
  7833. if (phys_id > max_phys_id)
  7834. phys_id = min_phys_id;
  7835. cpu = lpfc_find_next_cpu(phba, phys_id);
  7836. if (cpu == LPFC_VECTOR_MAP_EMPTY)
  7837. continue;
  7838. goto found;
  7839. }
  7840. /* Use round robin for scheduling */
  7841. phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN;
  7842. chan = 0;
  7843. cpup = phba->sli4_hba.cpu_map;
  7844. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  7845. cpup->channel_id = chan;
  7846. cpup++;
  7847. chan++;
  7848. if (chan >= phba->cfg_fcp_io_channel)
  7849. chan = 0;
  7850. }
  7851. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7852. "3329 Cannot set affinity:"
  7853. "Error mapping vector %d (%d)\n",
  7854. idx, vectors);
  7855. return 0;
  7856. }
  7857. found:
  7858. cpup += cpu;
  7859. if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
  7860. lpfc_used_cpu[cpu] = phys_id;
  7861. /* Associate vector with selected CPU */
  7862. cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
  7863. /* Associate IO channel with selected CPU */
  7864. cpup->channel_id = idx;
  7865. num_io_channel++;
  7866. if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
  7867. first_cpu = cpu;
  7868. /* Now affinitize to the selected CPU */
  7869. mask = &cpup->maskbits;
  7870. cpumask_clear(mask);
  7871. cpumask_set_cpu(cpu, mask);
  7872. i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
  7873. vector, mask);
  7874. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7875. "3330 Set Affinity: CPU %d channel %d "
  7876. "irq %d (%x)\n",
  7877. cpu, cpup->channel_id,
  7878. phba->sli4_hba.msix_entries[idx].vector, i);
  7879. /* Spread vector mapping across multple physical CPU nodes */
  7880. phys_id++;
  7881. if (phys_id > max_phys_id)
  7882. phys_id = min_phys_id;
  7883. }
  7884. /*
  7885. * Finally fill in the IO channel for any remaining CPUs.
  7886. * At this point, all IO channels have been assigned to a specific
  7887. * MSIx vector, mapped to a specific CPU.
  7888. * Base the remaining IO channel assigned, to IO channels already
  7889. * assigned to other CPUs on the same phys_id.
  7890. */
  7891. for (i = min_phys_id; i <= max_phys_id; i++) {
  7892. /*
  7893. * If there are no io channels already mapped to
  7894. * this phys_id, just round robin thru the io_channels.
  7895. * Setup chann[] for round robin.
  7896. */
  7897. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
  7898. chann[idx] = idx;
  7899. saved_chann = 0;
  7900. used_chann = 0;
  7901. /*
  7902. * First build a list of IO channels already assigned
  7903. * to this phys_id before reassigning the same IO
  7904. * channels to the remaining CPUs.
  7905. */
  7906. cpup = phba->sli4_hba.cpu_map;
  7907. cpu = first_cpu;
  7908. cpup += cpu;
  7909. for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
  7910. idx++) {
  7911. if (cpup->phys_id == i) {
  7912. /*
  7913. * Save any IO channels that are
  7914. * already mapped to this phys_id.
  7915. */
  7916. if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
  7917. chann[saved_chann] =
  7918. cpup->channel_id;
  7919. saved_chann++;
  7920. goto out;
  7921. }
  7922. /* See if we are using round-robin */
  7923. if (saved_chann == 0)
  7924. saved_chann =
  7925. phba->cfg_fcp_io_channel;
  7926. /* Associate next IO channel with CPU */
  7927. cpup->channel_id = chann[used_chann];
  7928. num_io_channel++;
  7929. used_chann++;
  7930. if (used_chann == saved_chann)
  7931. used_chann = 0;
  7932. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7933. "3331 Set IO_CHANN "
  7934. "CPU %d channel %d\n",
  7935. idx, cpup->channel_id);
  7936. }
  7937. out:
  7938. cpu++;
  7939. if (cpu >= phba->sli4_hba.num_present_cpu) {
  7940. cpup = phba->sli4_hba.cpu_map;
  7941. cpu = 0;
  7942. } else {
  7943. cpup++;
  7944. }
  7945. }
  7946. }
  7947. if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
  7948. cpup = phba->sli4_hba.cpu_map;
  7949. for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
  7950. if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
  7951. cpup->channel_id = 0;
  7952. num_io_channel++;
  7953. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7954. "3332 Assign IO_CHANN "
  7955. "CPU %d channel %d\n",
  7956. idx, cpup->channel_id);
  7957. }
  7958. cpup++;
  7959. }
  7960. }
  7961. /* Sanity check */
  7962. if (num_io_channel != phba->sli4_hba.num_present_cpu)
  7963. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7964. "3333 Set affinity mismatch:"
  7965. "%d chann != %d cpus: %d vectors\n",
  7966. num_io_channel, phba->sli4_hba.num_present_cpu,
  7967. vectors);
  7968. /* Enable using cpu affinity for scheduling */
  7969. phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
  7970. return 1;
  7971. }
  7972. /**
  7973. * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
  7974. * @phba: pointer to lpfc hba data structure.
  7975. *
  7976. * This routine is invoked to enable the MSI-X interrupt vectors to device
  7977. * with SLI-4 interface spec. The kernel function pci_enable_msix_range()
  7978. * is called to enable the MSI-X vectors. The device driver is responsible
  7979. * for calling the individual request_irq() to register each MSI-X vector
  7980. * with a interrupt handler, which is done in this function. Note that
  7981. * later when device is unloading, the driver should always call free_irq()
  7982. * on all MSI-X vectors it has done request_irq() on before calling
  7983. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  7984. * will be left with MSI-X enabled and leaks its vectors.
  7985. *
  7986. * Return codes
  7987. * 0 - successful
  7988. * other values - error
  7989. **/
  7990. static int
  7991. lpfc_sli4_enable_msix(struct lpfc_hba *phba)
  7992. {
  7993. int vectors, rc, index;
  7994. /* Set up MSI-X multi-message vectors */
  7995. for (index = 0; index < phba->cfg_fcp_io_channel; index++)
  7996. phba->sli4_hba.msix_entries[index].entry = index;
  7997. /* Configure MSI-X capability structure */
  7998. vectors = phba->cfg_fcp_io_channel;
  7999. if (phba->cfg_fof) {
  8000. phba->sli4_hba.msix_entries[index].entry = index;
  8001. vectors++;
  8002. }
  8003. rc = pci_enable_msix_range(phba->pcidev, phba->sli4_hba.msix_entries,
  8004. 2, vectors);
  8005. if (rc < 0) {
  8006. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8007. "0484 PCI enable MSI-X failed (%d)\n", rc);
  8008. goto vec_fail_out;
  8009. }
  8010. vectors = rc;
  8011. /* Log MSI-X vector assignment */
  8012. for (index = 0; index < vectors; index++)
  8013. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8014. "0489 MSI-X entry[%d]: vector=x%x "
  8015. "message=%d\n", index,
  8016. phba->sli4_hba.msix_entries[index].vector,
  8017. phba->sli4_hba.msix_entries[index].entry);
  8018. /* Assign MSI-X vectors to interrupt handlers */
  8019. for (index = 0; index < vectors; index++) {
  8020. memset(&phba->sli4_hba.handler_name[index], 0, 16);
  8021. snprintf((char *)&phba->sli4_hba.handler_name[index],
  8022. LPFC_SLI4_HANDLER_NAME_SZ,
  8023. LPFC_DRIVER_HANDLER_NAME"%d", index);
  8024. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  8025. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  8026. atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
  8027. if (phba->cfg_fof && (index == (vectors - 1)))
  8028. rc = request_irq(
  8029. phba->sli4_hba.msix_entries[index].vector,
  8030. &lpfc_sli4_fof_intr_handler, IRQF_SHARED,
  8031. (char *)&phba->sli4_hba.handler_name[index],
  8032. &phba->sli4_hba.fcp_eq_hdl[index]);
  8033. else
  8034. rc = request_irq(
  8035. phba->sli4_hba.msix_entries[index].vector,
  8036. &lpfc_sli4_hba_intr_handler, IRQF_SHARED,
  8037. (char *)&phba->sli4_hba.handler_name[index],
  8038. &phba->sli4_hba.fcp_eq_hdl[index]);
  8039. if (rc) {
  8040. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  8041. "0486 MSI-X fast-path (%d) "
  8042. "request_irq failed (%d)\n", index, rc);
  8043. goto cfg_fail_out;
  8044. }
  8045. }
  8046. if (phba->cfg_fof)
  8047. vectors--;
  8048. if (vectors != phba->cfg_fcp_io_channel) {
  8049. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8050. "3238 Reducing IO channels to match number of "
  8051. "MSI-X vectors, requested %d got %d\n",
  8052. phba->cfg_fcp_io_channel, vectors);
  8053. phba->cfg_fcp_io_channel = vectors;
  8054. }
  8055. lpfc_sli4_set_affinity(phba, vectors);
  8056. return rc;
  8057. cfg_fail_out:
  8058. /* free the irq already requested */
  8059. for (--index; index >= 0; index--) {
  8060. irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
  8061. vector, NULL);
  8062. free_irq(phba->sli4_hba.msix_entries[index].vector,
  8063. &phba->sli4_hba.fcp_eq_hdl[index]);
  8064. }
  8065. /* Unconfigure MSI-X capability structure */
  8066. pci_disable_msix(phba->pcidev);
  8067. vec_fail_out:
  8068. return rc;
  8069. }
  8070. /**
  8071. * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
  8072. * @phba: pointer to lpfc hba data structure.
  8073. *
  8074. * This routine is invoked to release the MSI-X vectors and then disable the
  8075. * MSI-X interrupt mode to device with SLI-4 interface spec.
  8076. **/
  8077. static void
  8078. lpfc_sli4_disable_msix(struct lpfc_hba *phba)
  8079. {
  8080. int index;
  8081. /* Free up MSI-X multi-message vectors */
  8082. for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
  8083. irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
  8084. vector, NULL);
  8085. free_irq(phba->sli4_hba.msix_entries[index].vector,
  8086. &phba->sli4_hba.fcp_eq_hdl[index]);
  8087. }
  8088. if (phba->cfg_fof) {
  8089. free_irq(phba->sli4_hba.msix_entries[index].vector,
  8090. &phba->sli4_hba.fcp_eq_hdl[index]);
  8091. }
  8092. /* Disable MSI-X */
  8093. pci_disable_msix(phba->pcidev);
  8094. return;
  8095. }
  8096. /**
  8097. * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
  8098. * @phba: pointer to lpfc hba data structure.
  8099. *
  8100. * This routine is invoked to enable the MSI interrupt mode to device with
  8101. * SLI-4 interface spec. The kernel function pci_enable_msi() is called
  8102. * to enable the MSI vector. The device driver is responsible for calling
  8103. * the request_irq() to register MSI vector with a interrupt the handler,
  8104. * which is done in this function.
  8105. *
  8106. * Return codes
  8107. * 0 - successful
  8108. * other values - error
  8109. **/
  8110. static int
  8111. lpfc_sli4_enable_msi(struct lpfc_hba *phba)
  8112. {
  8113. int rc, index;
  8114. rc = pci_enable_msi(phba->pcidev);
  8115. if (!rc)
  8116. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8117. "0487 PCI enable MSI mode success.\n");
  8118. else {
  8119. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8120. "0488 PCI enable MSI mode failed (%d)\n", rc);
  8121. return rc;
  8122. }
  8123. rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  8124. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  8125. if (rc) {
  8126. pci_disable_msi(phba->pcidev);
  8127. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  8128. "0490 MSI request_irq failed (%d)\n", rc);
  8129. return rc;
  8130. }
  8131. for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
  8132. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  8133. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  8134. }
  8135. if (phba->cfg_fof) {
  8136. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  8137. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  8138. }
  8139. return 0;
  8140. }
  8141. /**
  8142. * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
  8143. * @phba: pointer to lpfc hba data structure.
  8144. *
  8145. * This routine is invoked to disable the MSI interrupt mode to device with
  8146. * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
  8147. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  8148. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  8149. * its vector.
  8150. **/
  8151. static void
  8152. lpfc_sli4_disable_msi(struct lpfc_hba *phba)
  8153. {
  8154. free_irq(phba->pcidev->irq, phba);
  8155. pci_disable_msi(phba->pcidev);
  8156. return;
  8157. }
  8158. /**
  8159. * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
  8160. * @phba: pointer to lpfc hba data structure.
  8161. *
  8162. * This routine is invoked to enable device interrupt and associate driver's
  8163. * interrupt handler(s) to interrupt vector(s) to device with SLI-4
  8164. * interface spec. Depends on the interrupt mode configured to the driver,
  8165. * the driver will try to fallback from the configured interrupt mode to an
  8166. * interrupt mode which is supported by the platform, kernel, and device in
  8167. * the order of:
  8168. * MSI-X -> MSI -> IRQ.
  8169. *
  8170. * Return codes
  8171. * 0 - successful
  8172. * other values - error
  8173. **/
  8174. static uint32_t
  8175. lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  8176. {
  8177. uint32_t intr_mode = LPFC_INTR_ERROR;
  8178. int retval, index;
  8179. if (cfg_mode == 2) {
  8180. /* Preparation before conf_msi mbox cmd */
  8181. retval = 0;
  8182. if (!retval) {
  8183. /* Now, try to enable MSI-X interrupt mode */
  8184. retval = lpfc_sli4_enable_msix(phba);
  8185. if (!retval) {
  8186. /* Indicate initialization to MSI-X mode */
  8187. phba->intr_type = MSIX;
  8188. intr_mode = 2;
  8189. }
  8190. }
  8191. }
  8192. /* Fallback to MSI if MSI-X initialization failed */
  8193. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  8194. retval = lpfc_sli4_enable_msi(phba);
  8195. if (!retval) {
  8196. /* Indicate initialization to MSI mode */
  8197. phba->intr_type = MSI;
  8198. intr_mode = 1;
  8199. }
  8200. }
  8201. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  8202. if (phba->intr_type == NONE) {
  8203. retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  8204. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  8205. if (!retval) {
  8206. /* Indicate initialization to INTx mode */
  8207. phba->intr_type = INTx;
  8208. intr_mode = 0;
  8209. for (index = 0; index < phba->cfg_fcp_io_channel;
  8210. index++) {
  8211. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  8212. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  8213. atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
  8214. fcp_eq_in_use, 1);
  8215. }
  8216. if (phba->cfg_fof) {
  8217. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  8218. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  8219. atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
  8220. fcp_eq_in_use, 1);
  8221. }
  8222. }
  8223. }
  8224. return intr_mode;
  8225. }
  8226. /**
  8227. * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
  8228. * @phba: pointer to lpfc hba data structure.
  8229. *
  8230. * This routine is invoked to disable device interrupt and disassociate
  8231. * the driver's interrupt handler(s) from interrupt vector(s) to device
  8232. * with SLI-4 interface spec. Depending on the interrupt mode, the driver
  8233. * will release the interrupt vector(s) for the message signaled interrupt.
  8234. **/
  8235. static void
  8236. lpfc_sli4_disable_intr(struct lpfc_hba *phba)
  8237. {
  8238. /* Disable the currently initialized interrupt mode */
  8239. if (phba->intr_type == MSIX)
  8240. lpfc_sli4_disable_msix(phba);
  8241. else if (phba->intr_type == MSI)
  8242. lpfc_sli4_disable_msi(phba);
  8243. else if (phba->intr_type == INTx)
  8244. free_irq(phba->pcidev->irq, phba);
  8245. /* Reset interrupt management states */
  8246. phba->intr_type = NONE;
  8247. phba->sli.slistat.sli_intr = 0;
  8248. return;
  8249. }
  8250. /**
  8251. * lpfc_unset_hba - Unset SLI3 hba device initialization
  8252. * @phba: pointer to lpfc hba data structure.
  8253. *
  8254. * This routine is invoked to unset the HBA device initialization steps to
  8255. * a device with SLI-3 interface spec.
  8256. **/
  8257. static void
  8258. lpfc_unset_hba(struct lpfc_hba *phba)
  8259. {
  8260. struct lpfc_vport *vport = phba->pport;
  8261. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  8262. spin_lock_irq(shost->host_lock);
  8263. vport->load_flag |= FC_UNLOADING;
  8264. spin_unlock_irq(shost->host_lock);
  8265. kfree(phba->vpi_bmask);
  8266. kfree(phba->vpi_ids);
  8267. lpfc_stop_hba_timers(phba);
  8268. phba->pport->work_port_events = 0;
  8269. lpfc_sli_hba_down(phba);
  8270. lpfc_sli_brdrestart(phba);
  8271. lpfc_sli_disable_intr(phba);
  8272. return;
  8273. }
  8274. /**
  8275. * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
  8276. * @phba: Pointer to HBA context object.
  8277. *
  8278. * This function is called in the SLI4 code path to wait for completion
  8279. * of device's XRIs exchange busy. It will check the XRI exchange busy
  8280. * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
  8281. * that, it will check the XRI exchange busy on outstanding FCP and ELS
  8282. * I/Os every 30 seconds, log error message, and wait forever. Only when
  8283. * all XRI exchange busy complete, the driver unload shall proceed with
  8284. * invoking the function reset ioctl mailbox command to the CNA and the
  8285. * the rest of the driver unload resource release.
  8286. **/
  8287. static void
  8288. lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
  8289. {
  8290. int wait_time = 0;
  8291. int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  8292. int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  8293. while (!fcp_xri_cmpl || !els_xri_cmpl) {
  8294. if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
  8295. if (!fcp_xri_cmpl)
  8296. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8297. "2877 FCP XRI exchange busy "
  8298. "wait time: %d seconds.\n",
  8299. wait_time/1000);
  8300. if (!els_xri_cmpl)
  8301. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8302. "2878 ELS XRI exchange busy "
  8303. "wait time: %d seconds.\n",
  8304. wait_time/1000);
  8305. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
  8306. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
  8307. } else {
  8308. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
  8309. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
  8310. }
  8311. fcp_xri_cmpl =
  8312. list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  8313. els_xri_cmpl =
  8314. list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  8315. }
  8316. }
  8317. /**
  8318. * lpfc_sli4_hba_unset - Unset the fcoe hba
  8319. * @phba: Pointer to HBA context object.
  8320. *
  8321. * This function is called in the SLI4 code path to reset the HBA's FCoE
  8322. * function. The caller is not required to hold any lock. This routine
  8323. * issues PCI function reset mailbox command to reset the FCoE function.
  8324. * At the end of the function, it calls lpfc_hba_down_post function to
  8325. * free any pending commands.
  8326. **/
  8327. static void
  8328. lpfc_sli4_hba_unset(struct lpfc_hba *phba)
  8329. {
  8330. int wait_cnt = 0;
  8331. LPFC_MBOXQ_t *mboxq;
  8332. struct pci_dev *pdev = phba->pcidev;
  8333. lpfc_stop_hba_timers(phba);
  8334. phba->sli4_hba.intr_enable = 0;
  8335. /*
  8336. * Gracefully wait out the potential current outstanding asynchronous
  8337. * mailbox command.
  8338. */
  8339. /* First, block any pending async mailbox command from posted */
  8340. spin_lock_irq(&phba->hbalock);
  8341. phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  8342. spin_unlock_irq(&phba->hbalock);
  8343. /* Now, trying to wait it out if we can */
  8344. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  8345. msleep(10);
  8346. if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
  8347. break;
  8348. }
  8349. /* Forcefully release the outstanding mailbox command if timed out */
  8350. if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  8351. spin_lock_irq(&phba->hbalock);
  8352. mboxq = phba->sli.mbox_active;
  8353. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8354. __lpfc_mbox_cmpl_put(phba, mboxq);
  8355. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8356. phba->sli.mbox_active = NULL;
  8357. spin_unlock_irq(&phba->hbalock);
  8358. }
  8359. /* Abort all iocbs associated with the hba */
  8360. lpfc_sli_hba_iocb_abort(phba);
  8361. /* Wait for completion of device XRI exchange busy */
  8362. lpfc_sli4_xri_exchange_busy_wait(phba);
  8363. /* Disable PCI subsystem interrupt */
  8364. lpfc_sli4_disable_intr(phba);
  8365. /* Disable SR-IOV if enabled */
  8366. if (phba->cfg_sriov_nr_virtfn)
  8367. pci_disable_sriov(pdev);
  8368. /* Stop kthread signal shall trigger work_done one more time */
  8369. kthread_stop(phba->worker_thread);
  8370. /* Reset SLI4 HBA FCoE function */
  8371. lpfc_pci_function_reset(phba);
  8372. lpfc_sli4_queue_destroy(phba);
  8373. /* Stop the SLI4 device port */
  8374. phba->pport->work_port_events = 0;
  8375. }
  8376. /**
  8377. * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
  8378. * @phba: Pointer to HBA context object.
  8379. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  8380. *
  8381. * This function is called in the SLI4 code path to read the port's
  8382. * sli4 capabilities.
  8383. *
  8384. * This function may be be called from any context that can block-wait
  8385. * for the completion. The expectation is that this routine is called
  8386. * typically from probe_one or from the online routine.
  8387. **/
  8388. int
  8389. lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  8390. {
  8391. int rc;
  8392. struct lpfc_mqe *mqe;
  8393. struct lpfc_pc_sli4_params *sli4_params;
  8394. uint32_t mbox_tmo;
  8395. rc = 0;
  8396. mqe = &mboxq->u.mqe;
  8397. /* Read the port's SLI4 Parameters port capabilities */
  8398. lpfc_pc_sli4_params(mboxq);
  8399. if (!phba->sli4_hba.intr_enable)
  8400. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  8401. else {
  8402. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  8403. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  8404. }
  8405. if (unlikely(rc))
  8406. return 1;
  8407. sli4_params = &phba->sli4_hba.pc_sli4_params;
  8408. sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
  8409. sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
  8410. sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
  8411. sli4_params->featurelevel_1 = bf_get(featurelevel_1,
  8412. &mqe->un.sli4_params);
  8413. sli4_params->featurelevel_2 = bf_get(featurelevel_2,
  8414. &mqe->un.sli4_params);
  8415. sli4_params->proto_types = mqe->un.sli4_params.word3;
  8416. sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
  8417. sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
  8418. sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
  8419. sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
  8420. sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
  8421. sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
  8422. sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
  8423. sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
  8424. sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
  8425. sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
  8426. sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
  8427. sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
  8428. sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
  8429. sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
  8430. sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
  8431. sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
  8432. sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
  8433. sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
  8434. sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
  8435. sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
  8436. /* Make sure that sge_supp_len can be handled by the driver */
  8437. if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
  8438. sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
  8439. return rc;
  8440. }
  8441. /**
  8442. * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
  8443. * @phba: Pointer to HBA context object.
  8444. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  8445. *
  8446. * This function is called in the SLI4 code path to read the port's
  8447. * sli4 capabilities.
  8448. *
  8449. * This function may be be called from any context that can block-wait
  8450. * for the completion. The expectation is that this routine is called
  8451. * typically from probe_one or from the online routine.
  8452. **/
  8453. int
  8454. lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  8455. {
  8456. int rc;
  8457. struct lpfc_mqe *mqe = &mboxq->u.mqe;
  8458. struct lpfc_pc_sli4_params *sli4_params;
  8459. uint32_t mbox_tmo;
  8460. int length;
  8461. struct lpfc_sli4_parameters *mbx_sli4_parameters;
  8462. /*
  8463. * By default, the driver assumes the SLI4 port requires RPI
  8464. * header postings. The SLI4_PARAM response will correct this
  8465. * assumption.
  8466. */
  8467. phba->sli4_hba.rpi_hdrs_in_use = 1;
  8468. /* Read the port's SLI4 Config Parameters */
  8469. length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
  8470. sizeof(struct lpfc_sli4_cfg_mhdr));
  8471. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  8472. LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
  8473. length, LPFC_SLI4_MBX_EMBED);
  8474. if (!phba->sli4_hba.intr_enable)
  8475. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  8476. else {
  8477. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  8478. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  8479. }
  8480. if (unlikely(rc))
  8481. return rc;
  8482. sli4_params = &phba->sli4_hba.pc_sli4_params;
  8483. mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
  8484. sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
  8485. sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
  8486. sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
  8487. sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
  8488. mbx_sli4_parameters);
  8489. sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
  8490. mbx_sli4_parameters);
  8491. if (bf_get(cfg_phwq, mbx_sli4_parameters))
  8492. phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
  8493. else
  8494. phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
  8495. sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
  8496. sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
  8497. sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
  8498. sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
  8499. sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
  8500. sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
  8501. sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
  8502. sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
  8503. sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
  8504. mbx_sli4_parameters);
  8505. sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
  8506. mbx_sli4_parameters);
  8507. phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
  8508. phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
  8509. /* Make sure that sge_supp_len can be handled by the driver */
  8510. if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
  8511. sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
  8512. return 0;
  8513. }
  8514. /**
  8515. * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
  8516. * @pdev: pointer to PCI device
  8517. * @pid: pointer to PCI device identifier
  8518. *
  8519. * This routine is to be called to attach a device with SLI-3 interface spec
  8520. * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  8521. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  8522. * information of the device and driver to see if the driver state that it can
  8523. * support this kind of device. If the match is successful, the driver core
  8524. * invokes this routine. If this routine determines it can claim the HBA, it
  8525. * does all the initialization that it needs to do to handle the HBA properly.
  8526. *
  8527. * Return code
  8528. * 0 - driver can claim the device
  8529. * negative value - driver can not claim the device
  8530. **/
  8531. static int
  8532. lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
  8533. {
  8534. struct lpfc_hba *phba;
  8535. struct lpfc_vport *vport = NULL;
  8536. struct Scsi_Host *shost = NULL;
  8537. int error;
  8538. uint32_t cfg_mode, intr_mode;
  8539. /* Allocate memory for HBA structure */
  8540. phba = lpfc_hba_alloc(pdev);
  8541. if (!phba)
  8542. return -ENOMEM;
  8543. /* Perform generic PCI device enabling operation */
  8544. error = lpfc_enable_pci_dev(phba);
  8545. if (error)
  8546. goto out_free_phba;
  8547. /* Set up SLI API function jump table for PCI-device group-0 HBAs */
  8548. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
  8549. if (error)
  8550. goto out_disable_pci_dev;
  8551. /* Set up SLI-3 specific device PCI memory space */
  8552. error = lpfc_sli_pci_mem_setup(phba);
  8553. if (error) {
  8554. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8555. "1402 Failed to set up pci memory space.\n");
  8556. goto out_disable_pci_dev;
  8557. }
  8558. /* Set up phase-1 common device driver resources */
  8559. error = lpfc_setup_driver_resource_phase1(phba);
  8560. if (error) {
  8561. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8562. "1403 Failed to set up driver resource.\n");
  8563. goto out_unset_pci_mem_s3;
  8564. }
  8565. /* Set up SLI-3 specific device driver resources */
  8566. error = lpfc_sli_driver_resource_setup(phba);
  8567. if (error) {
  8568. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8569. "1404 Failed to set up driver resource.\n");
  8570. goto out_unset_pci_mem_s3;
  8571. }
  8572. /* Initialize and populate the iocb list per host */
  8573. error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
  8574. if (error) {
  8575. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8576. "1405 Failed to initialize iocb list.\n");
  8577. goto out_unset_driver_resource_s3;
  8578. }
  8579. /* Set up common device driver resources */
  8580. error = lpfc_setup_driver_resource_phase2(phba);
  8581. if (error) {
  8582. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8583. "1406 Failed to set up driver resource.\n");
  8584. goto out_free_iocb_list;
  8585. }
  8586. /* Get the default values for Model Name and Description */
  8587. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  8588. /* Create SCSI host to the physical port */
  8589. error = lpfc_create_shost(phba);
  8590. if (error) {
  8591. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8592. "1407 Failed to create scsi host.\n");
  8593. goto out_unset_driver_resource;
  8594. }
  8595. /* Configure sysfs attributes */
  8596. vport = phba->pport;
  8597. error = lpfc_alloc_sysfs_attr(vport);
  8598. if (error) {
  8599. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8600. "1476 Failed to allocate sysfs attr\n");
  8601. goto out_destroy_shost;
  8602. }
  8603. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  8604. /* Now, trying to enable interrupt and bring up the device */
  8605. cfg_mode = phba->cfg_use_msi;
  8606. while (true) {
  8607. /* Put device to a known state before enabling interrupt */
  8608. lpfc_stop_port(phba);
  8609. /* Configure and enable interrupt */
  8610. intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
  8611. if (intr_mode == LPFC_INTR_ERROR) {
  8612. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8613. "0431 Failed to enable interrupt.\n");
  8614. error = -ENODEV;
  8615. goto out_free_sysfs_attr;
  8616. }
  8617. /* SLI-3 HBA setup */
  8618. if (lpfc_sli_hba_setup(phba)) {
  8619. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8620. "1477 Failed to set up hba\n");
  8621. error = -ENODEV;
  8622. goto out_remove_device;
  8623. }
  8624. /* Wait 50ms for the interrupts of previous mailbox commands */
  8625. msleep(50);
  8626. /* Check active interrupts on message signaled interrupts */
  8627. if (intr_mode == 0 ||
  8628. phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
  8629. /* Log the current active interrupt mode */
  8630. phba->intr_mode = intr_mode;
  8631. lpfc_log_intr_mode(phba, intr_mode);
  8632. break;
  8633. } else {
  8634. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8635. "0447 Configure interrupt mode (%d) "
  8636. "failed active interrupt test.\n",
  8637. intr_mode);
  8638. /* Disable the current interrupt mode */
  8639. lpfc_sli_disable_intr(phba);
  8640. /* Try next level of interrupt mode */
  8641. cfg_mode = --intr_mode;
  8642. }
  8643. }
  8644. /* Perform post initialization setup */
  8645. lpfc_post_init_setup(phba);
  8646. /* Check if there are static vports to be created. */
  8647. lpfc_create_static_vport(phba);
  8648. return 0;
  8649. out_remove_device:
  8650. lpfc_unset_hba(phba);
  8651. out_free_sysfs_attr:
  8652. lpfc_free_sysfs_attr(vport);
  8653. out_destroy_shost:
  8654. lpfc_destroy_shost(phba);
  8655. out_unset_driver_resource:
  8656. lpfc_unset_driver_resource_phase2(phba);
  8657. out_free_iocb_list:
  8658. lpfc_free_iocb_list(phba);
  8659. out_unset_driver_resource_s3:
  8660. lpfc_sli_driver_resource_unset(phba);
  8661. out_unset_pci_mem_s3:
  8662. lpfc_sli_pci_mem_unset(phba);
  8663. out_disable_pci_dev:
  8664. lpfc_disable_pci_dev(phba);
  8665. if (shost)
  8666. scsi_host_put(shost);
  8667. out_free_phba:
  8668. lpfc_hba_free(phba);
  8669. return error;
  8670. }
  8671. /**
  8672. * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
  8673. * @pdev: pointer to PCI device
  8674. *
  8675. * This routine is to be called to disattach a device with SLI-3 interface
  8676. * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  8677. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  8678. * device to be removed from the PCI subsystem properly.
  8679. **/
  8680. static void
  8681. lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  8682. {
  8683. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8684. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  8685. struct lpfc_vport **vports;
  8686. struct lpfc_hba *phba = vport->phba;
  8687. int i;
  8688. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  8689. spin_lock_irq(&phba->hbalock);
  8690. vport->load_flag |= FC_UNLOADING;
  8691. spin_unlock_irq(&phba->hbalock);
  8692. lpfc_free_sysfs_attr(vport);
  8693. /* Release all the vports against this physical port */
  8694. vports = lpfc_create_vport_work_array(phba);
  8695. if (vports != NULL)
  8696. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  8697. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  8698. continue;
  8699. fc_vport_terminate(vports[i]->fc_vport);
  8700. }
  8701. lpfc_destroy_vport_work_array(phba, vports);
  8702. /* Remove FC host and then SCSI host with the physical port */
  8703. fc_remove_host(shost);
  8704. scsi_remove_host(shost);
  8705. lpfc_cleanup(vport);
  8706. /*
  8707. * Bring down the SLI Layer. This step disable all interrupts,
  8708. * clears the rings, discards all mailbox commands, and resets
  8709. * the HBA.
  8710. */
  8711. /* HBA interrupt will be disabled after this call */
  8712. lpfc_sli_hba_down(phba);
  8713. /* Stop kthread signal shall trigger work_done one more time */
  8714. kthread_stop(phba->worker_thread);
  8715. /* Final cleanup of txcmplq and reset the HBA */
  8716. lpfc_sli_brdrestart(phba);
  8717. kfree(phba->vpi_bmask);
  8718. kfree(phba->vpi_ids);
  8719. lpfc_stop_hba_timers(phba);
  8720. spin_lock_irq(&phba->hbalock);
  8721. list_del_init(&vport->listentry);
  8722. spin_unlock_irq(&phba->hbalock);
  8723. lpfc_debugfs_terminate(vport);
  8724. /* Disable SR-IOV if enabled */
  8725. if (phba->cfg_sriov_nr_virtfn)
  8726. pci_disable_sriov(pdev);
  8727. /* Disable interrupt */
  8728. lpfc_sli_disable_intr(phba);
  8729. scsi_host_put(shost);
  8730. /*
  8731. * Call scsi_free before mem_free since scsi bufs are released to their
  8732. * corresponding pools here.
  8733. */
  8734. lpfc_scsi_free(phba);
  8735. lpfc_mem_free_all(phba);
  8736. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  8737. phba->hbqslimp.virt, phba->hbqslimp.phys);
  8738. /* Free resources associated with SLI2 interface */
  8739. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  8740. phba->slim2p.virt, phba->slim2p.phys);
  8741. /* unmap adapter SLIM and Control Registers */
  8742. iounmap(phba->ctrl_regs_memmap_p);
  8743. iounmap(phba->slim_memmap_p);
  8744. lpfc_hba_free(phba);
  8745. pci_release_selected_regions(pdev, bars);
  8746. pci_disable_device(pdev);
  8747. }
  8748. /**
  8749. * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
  8750. * @pdev: pointer to PCI device
  8751. * @msg: power management message
  8752. *
  8753. * This routine is to be called from the kernel's PCI subsystem to support
  8754. * system Power Management (PM) to device with SLI-3 interface spec. When
  8755. * PM invokes this method, it quiesces the device by stopping the driver's
  8756. * worker thread for the device, turning off device's interrupt and DMA,
  8757. * and bring the device offline. Note that as the driver implements the
  8758. * minimum PM requirements to a power-aware driver's PM support for the
  8759. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  8760. * to the suspend() method call will be treated as SUSPEND and the driver will
  8761. * fully reinitialize its device during resume() method call, the driver will
  8762. * set device to PCI_D3hot state in PCI config space instead of setting it
  8763. * according to the @msg provided by the PM.
  8764. *
  8765. * Return code
  8766. * 0 - driver suspended the device
  8767. * Error otherwise
  8768. **/
  8769. static int
  8770. lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
  8771. {
  8772. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8773. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8774. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8775. "0473 PCI device Power Management suspend.\n");
  8776. /* Bring down the device */
  8777. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  8778. lpfc_offline(phba);
  8779. kthread_stop(phba->worker_thread);
  8780. /* Disable interrupt from device */
  8781. lpfc_sli_disable_intr(phba);
  8782. /* Save device state to PCI config space */
  8783. pci_save_state(pdev);
  8784. pci_set_power_state(pdev, PCI_D3hot);
  8785. return 0;
  8786. }
  8787. /**
  8788. * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
  8789. * @pdev: pointer to PCI device
  8790. *
  8791. * This routine is to be called from the kernel's PCI subsystem to support
  8792. * system Power Management (PM) to device with SLI-3 interface spec. When PM
  8793. * invokes this method, it restores the device's PCI config space state and
  8794. * fully reinitializes the device and brings it online. Note that as the
  8795. * driver implements the minimum PM requirements to a power-aware driver's
  8796. * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
  8797. * FREEZE) to the suspend() method call will be treated as SUSPEND and the
  8798. * driver will fully reinitialize its device during resume() method call,
  8799. * the device will be set to PCI_D0 directly in PCI config space before
  8800. * restoring the state.
  8801. *
  8802. * Return code
  8803. * 0 - driver suspended the device
  8804. * Error otherwise
  8805. **/
  8806. static int
  8807. lpfc_pci_resume_one_s3(struct pci_dev *pdev)
  8808. {
  8809. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8810. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8811. uint32_t intr_mode;
  8812. int error;
  8813. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8814. "0452 PCI device Power Management resume.\n");
  8815. /* Restore device state from PCI config space */
  8816. pci_set_power_state(pdev, PCI_D0);
  8817. pci_restore_state(pdev);
  8818. /*
  8819. * As the new kernel behavior of pci_restore_state() API call clears
  8820. * device saved_state flag, need to save the restored state again.
  8821. */
  8822. pci_save_state(pdev);
  8823. if (pdev->is_busmaster)
  8824. pci_set_master(pdev);
  8825. /* Startup the kernel thread for this host adapter. */
  8826. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  8827. "lpfc_worker_%d", phba->brd_no);
  8828. if (IS_ERR(phba->worker_thread)) {
  8829. error = PTR_ERR(phba->worker_thread);
  8830. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8831. "0434 PM resume failed to start worker "
  8832. "thread: error=x%x.\n", error);
  8833. return error;
  8834. }
  8835. /* Configure and enable interrupt */
  8836. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  8837. if (intr_mode == LPFC_INTR_ERROR) {
  8838. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8839. "0430 PM resume Failed to enable interrupt\n");
  8840. return -EIO;
  8841. } else
  8842. phba->intr_mode = intr_mode;
  8843. /* Restart HBA and bring it online */
  8844. lpfc_sli_brdrestart(phba);
  8845. lpfc_online(phba);
  8846. /* Log the current active interrupt mode */
  8847. lpfc_log_intr_mode(phba, phba->intr_mode);
  8848. return 0;
  8849. }
  8850. /**
  8851. * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
  8852. * @phba: pointer to lpfc hba data structure.
  8853. *
  8854. * This routine is called to prepare the SLI3 device for PCI slot recover. It
  8855. * aborts all the outstanding SCSI I/Os to the pci device.
  8856. **/
  8857. static void
  8858. lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
  8859. {
  8860. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8861. "2723 PCI channel I/O abort preparing for recovery\n");
  8862. /*
  8863. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  8864. * and let the SCSI mid-layer to retry them to recover.
  8865. */
  8866. lpfc_sli_abort_fcp_rings(phba);
  8867. }
  8868. /**
  8869. * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
  8870. * @phba: pointer to lpfc hba data structure.
  8871. *
  8872. * This routine is called to prepare the SLI3 device for PCI slot reset. It
  8873. * disables the device interrupt and pci device, and aborts the internal FCP
  8874. * pending I/Os.
  8875. **/
  8876. static void
  8877. lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
  8878. {
  8879. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8880. "2710 PCI channel disable preparing for reset\n");
  8881. /* Block any management I/Os to the device */
  8882. lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
  8883. /* Block all SCSI devices' I/Os on the host */
  8884. lpfc_scsi_dev_block(phba);
  8885. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  8886. lpfc_sli_flush_fcp_rings(phba);
  8887. /* stop all timers */
  8888. lpfc_stop_hba_timers(phba);
  8889. /* Disable interrupt and pci device */
  8890. lpfc_sli_disable_intr(phba);
  8891. pci_disable_device(phba->pcidev);
  8892. }
  8893. /**
  8894. * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
  8895. * @phba: pointer to lpfc hba data structure.
  8896. *
  8897. * This routine is called to prepare the SLI3 device for PCI slot permanently
  8898. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  8899. * pending I/Os.
  8900. **/
  8901. static void
  8902. lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  8903. {
  8904. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8905. "2711 PCI channel permanent disable for failure\n");
  8906. /* Block all SCSI devices' I/Os on the host */
  8907. lpfc_scsi_dev_block(phba);
  8908. /* stop all timers */
  8909. lpfc_stop_hba_timers(phba);
  8910. /* Clean up all driver's outstanding SCSI I/Os */
  8911. lpfc_sli_flush_fcp_rings(phba);
  8912. }
  8913. /**
  8914. * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
  8915. * @pdev: pointer to PCI device.
  8916. * @state: the current PCI connection state.
  8917. *
  8918. * This routine is called from the PCI subsystem for I/O error handling to
  8919. * device with SLI-3 interface spec. This function is called by the PCI
  8920. * subsystem after a PCI bus error affecting this device has been detected.
  8921. * When this function is invoked, it will need to stop all the I/Os and
  8922. * interrupt(s) to the device. Once that is done, it will return
  8923. * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
  8924. * as desired.
  8925. *
  8926. * Return codes
  8927. * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
  8928. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  8929. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8930. **/
  8931. static pci_ers_result_t
  8932. lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
  8933. {
  8934. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8935. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8936. switch (state) {
  8937. case pci_channel_io_normal:
  8938. /* Non-fatal error, prepare for recovery */
  8939. lpfc_sli_prep_dev_for_recover(phba);
  8940. return PCI_ERS_RESULT_CAN_RECOVER;
  8941. case pci_channel_io_frozen:
  8942. /* Fatal error, prepare for slot reset */
  8943. lpfc_sli_prep_dev_for_reset(phba);
  8944. return PCI_ERS_RESULT_NEED_RESET;
  8945. case pci_channel_io_perm_failure:
  8946. /* Permanent failure, prepare for device down */
  8947. lpfc_sli_prep_dev_for_perm_failure(phba);
  8948. return PCI_ERS_RESULT_DISCONNECT;
  8949. default:
  8950. /* Unknown state, prepare and request slot reset */
  8951. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8952. "0472 Unknown PCI error state: x%x\n", state);
  8953. lpfc_sli_prep_dev_for_reset(phba);
  8954. return PCI_ERS_RESULT_NEED_RESET;
  8955. }
  8956. }
  8957. /**
  8958. * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
  8959. * @pdev: pointer to PCI device.
  8960. *
  8961. * This routine is called from the PCI subsystem for error handling to
  8962. * device with SLI-3 interface spec. This is called after PCI bus has been
  8963. * reset to restart the PCI card from scratch, as if from a cold-boot.
  8964. * During the PCI subsystem error recovery, after driver returns
  8965. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  8966. * recovery and then call this routine before calling the .resume method
  8967. * to recover the device. This function will initialize the HBA device,
  8968. * enable the interrupt, but it will just put the HBA to offline state
  8969. * without passing any I/O traffic.
  8970. *
  8971. * Return codes
  8972. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  8973. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8974. */
  8975. static pci_ers_result_t
  8976. lpfc_io_slot_reset_s3(struct pci_dev *pdev)
  8977. {
  8978. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8979. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8980. struct lpfc_sli *psli = &phba->sli;
  8981. uint32_t intr_mode;
  8982. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  8983. if (pci_enable_device_mem(pdev)) {
  8984. printk(KERN_ERR "lpfc: Cannot re-enable "
  8985. "PCI device after reset.\n");
  8986. return PCI_ERS_RESULT_DISCONNECT;
  8987. }
  8988. pci_restore_state(pdev);
  8989. /*
  8990. * As the new kernel behavior of pci_restore_state() API call clears
  8991. * device saved_state flag, need to save the restored state again.
  8992. */
  8993. pci_save_state(pdev);
  8994. if (pdev->is_busmaster)
  8995. pci_set_master(pdev);
  8996. spin_lock_irq(&phba->hbalock);
  8997. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  8998. spin_unlock_irq(&phba->hbalock);
  8999. /* Configure and enable interrupt */
  9000. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  9001. if (intr_mode == LPFC_INTR_ERROR) {
  9002. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9003. "0427 Cannot re-enable interrupt after "
  9004. "slot reset.\n");
  9005. return PCI_ERS_RESULT_DISCONNECT;
  9006. } else
  9007. phba->intr_mode = intr_mode;
  9008. /* Take device offline, it will perform cleanup */
  9009. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  9010. lpfc_offline(phba);
  9011. lpfc_sli_brdrestart(phba);
  9012. /* Log the current active interrupt mode */
  9013. lpfc_log_intr_mode(phba, phba->intr_mode);
  9014. return PCI_ERS_RESULT_RECOVERED;
  9015. }
  9016. /**
  9017. * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
  9018. * @pdev: pointer to PCI device
  9019. *
  9020. * This routine is called from the PCI subsystem for error handling to device
  9021. * with SLI-3 interface spec. It is called when kernel error recovery tells
  9022. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  9023. * error recovery. After this call, traffic can start to flow from this device
  9024. * again.
  9025. */
  9026. static void
  9027. lpfc_io_resume_s3(struct pci_dev *pdev)
  9028. {
  9029. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9030. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9031. /* Bring device online, it will be no-op for non-fatal error resume */
  9032. lpfc_online(phba);
  9033. /* Clean up Advanced Error Reporting (AER) if needed */
  9034. if (phba->hba_flag & HBA_AER_ENABLED)
  9035. pci_cleanup_aer_uncorrect_error_status(pdev);
  9036. }
  9037. /**
  9038. * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
  9039. * @phba: pointer to lpfc hba data structure.
  9040. *
  9041. * returns the number of ELS/CT IOCBs to reserve
  9042. **/
  9043. int
  9044. lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
  9045. {
  9046. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  9047. if (phba->sli_rev == LPFC_SLI_REV4) {
  9048. if (max_xri <= 100)
  9049. return 10;
  9050. else if (max_xri <= 256)
  9051. return 25;
  9052. else if (max_xri <= 512)
  9053. return 50;
  9054. else if (max_xri <= 1024)
  9055. return 100;
  9056. else if (max_xri <= 1536)
  9057. return 150;
  9058. else if (max_xri <= 2048)
  9059. return 200;
  9060. else
  9061. return 250;
  9062. } else
  9063. return 0;
  9064. }
  9065. /**
  9066. * lpfc_write_firmware - attempt to write a firmware image to the port
  9067. * @fw: pointer to firmware image returned from request_firmware.
  9068. * @phba: pointer to lpfc hba data structure.
  9069. *
  9070. **/
  9071. static void
  9072. lpfc_write_firmware(const struct firmware *fw, void *context)
  9073. {
  9074. struct lpfc_hba *phba = (struct lpfc_hba *)context;
  9075. char fwrev[FW_REV_STR_SIZE];
  9076. struct lpfc_grp_hdr *image;
  9077. struct list_head dma_buffer_list;
  9078. int i, rc = 0;
  9079. struct lpfc_dmabuf *dmabuf, *next;
  9080. uint32_t offset = 0, temp_offset = 0;
  9081. /* It can be null in no-wait mode, sanity check */
  9082. if (!fw) {
  9083. rc = -ENXIO;
  9084. goto out;
  9085. }
  9086. image = (struct lpfc_grp_hdr *)fw->data;
  9087. INIT_LIST_HEAD(&dma_buffer_list);
  9088. if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
  9089. (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
  9090. LPFC_FILE_TYPE_GROUP) ||
  9091. (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
  9092. (be32_to_cpu(image->size) != fw->size)) {
  9093. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9094. "3022 Invalid FW image found. "
  9095. "Magic:%x Type:%x ID:%x\n",
  9096. be32_to_cpu(image->magic_number),
  9097. bf_get_be32(lpfc_grp_hdr_file_type, image),
  9098. bf_get_be32(lpfc_grp_hdr_id, image));
  9099. rc = -EINVAL;
  9100. goto release_out;
  9101. }
  9102. lpfc_decode_firmware_rev(phba, fwrev, 1);
  9103. if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
  9104. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9105. "3023 Updating Firmware, Current Version:%s "
  9106. "New Version:%s\n",
  9107. fwrev, image->revision);
  9108. for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
  9109. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
  9110. GFP_KERNEL);
  9111. if (!dmabuf) {
  9112. rc = -ENOMEM;
  9113. goto release_out;
  9114. }
  9115. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  9116. SLI4_PAGE_SIZE,
  9117. &dmabuf->phys,
  9118. GFP_KERNEL);
  9119. if (!dmabuf->virt) {
  9120. kfree(dmabuf);
  9121. rc = -ENOMEM;
  9122. goto release_out;
  9123. }
  9124. list_add_tail(&dmabuf->list, &dma_buffer_list);
  9125. }
  9126. while (offset < fw->size) {
  9127. temp_offset = offset;
  9128. list_for_each_entry(dmabuf, &dma_buffer_list, list) {
  9129. if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
  9130. memcpy(dmabuf->virt,
  9131. fw->data + temp_offset,
  9132. fw->size - temp_offset);
  9133. temp_offset = fw->size;
  9134. break;
  9135. }
  9136. memcpy(dmabuf->virt, fw->data + temp_offset,
  9137. SLI4_PAGE_SIZE);
  9138. temp_offset += SLI4_PAGE_SIZE;
  9139. }
  9140. rc = lpfc_wr_object(phba, &dma_buffer_list,
  9141. (fw->size - offset), &offset);
  9142. if (rc)
  9143. goto release_out;
  9144. }
  9145. rc = offset;
  9146. }
  9147. release_out:
  9148. list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
  9149. list_del(&dmabuf->list);
  9150. dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
  9151. dmabuf->virt, dmabuf->phys);
  9152. kfree(dmabuf);
  9153. }
  9154. release_firmware(fw);
  9155. out:
  9156. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9157. "3024 Firmware update done: %d.\n", rc);
  9158. return;
  9159. }
  9160. /**
  9161. * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
  9162. * @phba: pointer to lpfc hba data structure.
  9163. *
  9164. * This routine is called to perform Linux generic firmware upgrade on device
  9165. * that supports such feature.
  9166. **/
  9167. int
  9168. lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
  9169. {
  9170. uint8_t file_name[ELX_MODEL_NAME_SIZE];
  9171. int ret;
  9172. const struct firmware *fw;
  9173. /* Only supported on SLI4 interface type 2 for now */
  9174. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  9175. LPFC_SLI_INTF_IF_TYPE_2)
  9176. return -EPERM;
  9177. snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
  9178. if (fw_upgrade == INT_FW_UPGRADE) {
  9179. ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
  9180. file_name, &phba->pcidev->dev,
  9181. GFP_KERNEL, (void *)phba,
  9182. lpfc_write_firmware);
  9183. } else if (fw_upgrade == RUN_FW_UPGRADE) {
  9184. ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
  9185. if (!ret)
  9186. lpfc_write_firmware(fw, (void *)phba);
  9187. } else {
  9188. ret = -EINVAL;
  9189. }
  9190. return ret;
  9191. }
  9192. /**
  9193. * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
  9194. * @pdev: pointer to PCI device
  9195. * @pid: pointer to PCI device identifier
  9196. *
  9197. * This routine is called from the kernel's PCI subsystem to device with
  9198. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  9199. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  9200. * information of the device and driver to see if the driver state that it
  9201. * can support this kind of device. If the match is successful, the driver
  9202. * core invokes this routine. If this routine determines it can claim the HBA,
  9203. * it does all the initialization that it needs to do to handle the HBA
  9204. * properly.
  9205. *
  9206. * Return code
  9207. * 0 - driver can claim the device
  9208. * negative value - driver can not claim the device
  9209. **/
  9210. static int
  9211. lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
  9212. {
  9213. struct lpfc_hba *phba;
  9214. struct lpfc_vport *vport = NULL;
  9215. struct Scsi_Host *shost = NULL;
  9216. int error, ret;
  9217. uint32_t cfg_mode, intr_mode;
  9218. int adjusted_fcp_io_channel;
  9219. /* Allocate memory for HBA structure */
  9220. phba = lpfc_hba_alloc(pdev);
  9221. if (!phba)
  9222. return -ENOMEM;
  9223. /* Perform generic PCI device enabling operation */
  9224. error = lpfc_enable_pci_dev(phba);
  9225. if (error)
  9226. goto out_free_phba;
  9227. /* Set up SLI API function jump table for PCI-device group-1 HBAs */
  9228. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
  9229. if (error)
  9230. goto out_disable_pci_dev;
  9231. /* Set up SLI-4 specific device PCI memory space */
  9232. error = lpfc_sli4_pci_mem_setup(phba);
  9233. if (error) {
  9234. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9235. "1410 Failed to set up pci memory space.\n");
  9236. goto out_disable_pci_dev;
  9237. }
  9238. /* Set up phase-1 common device driver resources */
  9239. error = lpfc_setup_driver_resource_phase1(phba);
  9240. if (error) {
  9241. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9242. "1411 Failed to set up driver resource.\n");
  9243. goto out_unset_pci_mem_s4;
  9244. }
  9245. /* Set up SLI-4 Specific device driver resources */
  9246. error = lpfc_sli4_driver_resource_setup(phba);
  9247. if (error) {
  9248. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9249. "1412 Failed to set up driver resource.\n");
  9250. goto out_unset_pci_mem_s4;
  9251. }
  9252. /* Initialize and populate the iocb list per host */
  9253. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9254. "2821 initialize iocb list %d.\n",
  9255. phba->cfg_iocb_cnt*1024);
  9256. error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
  9257. if (error) {
  9258. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9259. "1413 Failed to initialize iocb list.\n");
  9260. goto out_unset_driver_resource_s4;
  9261. }
  9262. INIT_LIST_HEAD(&phba->active_rrq_list);
  9263. INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
  9264. /* Set up common device driver resources */
  9265. error = lpfc_setup_driver_resource_phase2(phba);
  9266. if (error) {
  9267. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9268. "1414 Failed to set up driver resource.\n");
  9269. goto out_free_iocb_list;
  9270. }
  9271. /* Get the default values for Model Name and Description */
  9272. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  9273. /* Create SCSI host to the physical port */
  9274. error = lpfc_create_shost(phba);
  9275. if (error) {
  9276. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9277. "1415 Failed to create scsi host.\n");
  9278. goto out_unset_driver_resource;
  9279. }
  9280. /* Configure sysfs attributes */
  9281. vport = phba->pport;
  9282. error = lpfc_alloc_sysfs_attr(vport);
  9283. if (error) {
  9284. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9285. "1416 Failed to allocate sysfs attr\n");
  9286. goto out_destroy_shost;
  9287. }
  9288. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  9289. /* Now, trying to enable interrupt and bring up the device */
  9290. cfg_mode = phba->cfg_use_msi;
  9291. /* Put device to a known state before enabling interrupt */
  9292. lpfc_stop_port(phba);
  9293. /* Configure and enable interrupt */
  9294. intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
  9295. if (intr_mode == LPFC_INTR_ERROR) {
  9296. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9297. "0426 Failed to enable interrupt.\n");
  9298. error = -ENODEV;
  9299. goto out_free_sysfs_attr;
  9300. }
  9301. /* Default to single EQ for non-MSI-X */
  9302. if (phba->intr_type != MSIX)
  9303. adjusted_fcp_io_channel = 1;
  9304. else
  9305. adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
  9306. phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
  9307. /* Set up SLI-4 HBA */
  9308. if (lpfc_sli4_hba_setup(phba)) {
  9309. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9310. "1421 Failed to set up hba\n");
  9311. error = -ENODEV;
  9312. goto out_disable_intr;
  9313. }
  9314. /* Log the current active interrupt mode */
  9315. phba->intr_mode = intr_mode;
  9316. lpfc_log_intr_mode(phba, intr_mode);
  9317. /* Perform post initialization setup */
  9318. lpfc_post_init_setup(phba);
  9319. /* check for firmware upgrade or downgrade */
  9320. if (phba->cfg_request_firmware_upgrade)
  9321. ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
  9322. /* Check if there are static vports to be created. */
  9323. lpfc_create_static_vport(phba);
  9324. return 0;
  9325. out_disable_intr:
  9326. lpfc_sli4_disable_intr(phba);
  9327. out_free_sysfs_attr:
  9328. lpfc_free_sysfs_attr(vport);
  9329. out_destroy_shost:
  9330. lpfc_destroy_shost(phba);
  9331. out_unset_driver_resource:
  9332. lpfc_unset_driver_resource_phase2(phba);
  9333. out_free_iocb_list:
  9334. lpfc_free_iocb_list(phba);
  9335. out_unset_driver_resource_s4:
  9336. lpfc_sli4_driver_resource_unset(phba);
  9337. out_unset_pci_mem_s4:
  9338. lpfc_sli4_pci_mem_unset(phba);
  9339. out_disable_pci_dev:
  9340. lpfc_disable_pci_dev(phba);
  9341. if (shost)
  9342. scsi_host_put(shost);
  9343. out_free_phba:
  9344. lpfc_hba_free(phba);
  9345. return error;
  9346. }
  9347. /**
  9348. * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
  9349. * @pdev: pointer to PCI device
  9350. *
  9351. * This routine is called from the kernel's PCI subsystem to device with
  9352. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  9353. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  9354. * device to be removed from the PCI subsystem properly.
  9355. **/
  9356. static void
  9357. lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  9358. {
  9359. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9360. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  9361. struct lpfc_vport **vports;
  9362. struct lpfc_hba *phba = vport->phba;
  9363. int i;
  9364. /* Mark the device unloading flag */
  9365. spin_lock_irq(&phba->hbalock);
  9366. vport->load_flag |= FC_UNLOADING;
  9367. spin_unlock_irq(&phba->hbalock);
  9368. /* Free the HBA sysfs attributes */
  9369. lpfc_free_sysfs_attr(vport);
  9370. /* Release all the vports against this physical port */
  9371. vports = lpfc_create_vport_work_array(phba);
  9372. if (vports != NULL)
  9373. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  9374. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  9375. continue;
  9376. fc_vport_terminate(vports[i]->fc_vport);
  9377. }
  9378. lpfc_destroy_vport_work_array(phba, vports);
  9379. /* Remove FC host and then SCSI host with the physical port */
  9380. fc_remove_host(shost);
  9381. scsi_remove_host(shost);
  9382. /* Perform cleanup on the physical port */
  9383. lpfc_cleanup(vport);
  9384. /*
  9385. * Bring down the SLI Layer. This step disables all interrupts,
  9386. * clears the rings, discards all mailbox commands, and resets
  9387. * the HBA FCoE function.
  9388. */
  9389. lpfc_debugfs_terminate(vport);
  9390. lpfc_sli4_hba_unset(phba);
  9391. spin_lock_irq(&phba->hbalock);
  9392. list_del_init(&vport->listentry);
  9393. spin_unlock_irq(&phba->hbalock);
  9394. /* Perform scsi free before driver resource_unset since scsi
  9395. * buffers are released to their corresponding pools here.
  9396. */
  9397. lpfc_scsi_free(phba);
  9398. lpfc_sli4_driver_resource_unset(phba);
  9399. /* Unmap adapter Control and Doorbell registers */
  9400. lpfc_sli4_pci_mem_unset(phba);
  9401. /* Release PCI resources and disable device's PCI function */
  9402. scsi_host_put(shost);
  9403. lpfc_disable_pci_dev(phba);
  9404. /* Finally, free the driver's device data structure */
  9405. lpfc_hba_free(phba);
  9406. return;
  9407. }
  9408. /**
  9409. * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
  9410. * @pdev: pointer to PCI device
  9411. * @msg: power management message
  9412. *
  9413. * This routine is called from the kernel's PCI subsystem to support system
  9414. * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
  9415. * this method, it quiesces the device by stopping the driver's worker
  9416. * thread for the device, turning off device's interrupt and DMA, and bring
  9417. * the device offline. Note that as the driver implements the minimum PM
  9418. * requirements to a power-aware driver's PM support for suspend/resume -- all
  9419. * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
  9420. * method call will be treated as SUSPEND and the driver will fully
  9421. * reinitialize its device during resume() method call, the driver will set
  9422. * device to PCI_D3hot state in PCI config space instead of setting it
  9423. * according to the @msg provided by the PM.
  9424. *
  9425. * Return code
  9426. * 0 - driver suspended the device
  9427. * Error otherwise
  9428. **/
  9429. static int
  9430. lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
  9431. {
  9432. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9433. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9434. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9435. "2843 PCI device Power Management suspend.\n");
  9436. /* Bring down the device */
  9437. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  9438. lpfc_offline(phba);
  9439. kthread_stop(phba->worker_thread);
  9440. /* Disable interrupt from device */
  9441. lpfc_sli4_disable_intr(phba);
  9442. lpfc_sli4_queue_destroy(phba);
  9443. /* Save device state to PCI config space */
  9444. pci_save_state(pdev);
  9445. pci_set_power_state(pdev, PCI_D3hot);
  9446. return 0;
  9447. }
  9448. /**
  9449. * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
  9450. * @pdev: pointer to PCI device
  9451. *
  9452. * This routine is called from the kernel's PCI subsystem to support system
  9453. * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
  9454. * this method, it restores the device's PCI config space state and fully
  9455. * reinitializes the device and brings it online. Note that as the driver
  9456. * implements the minimum PM requirements to a power-aware driver's PM for
  9457. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  9458. * to the suspend() method call will be treated as SUSPEND and the driver
  9459. * will fully reinitialize its device during resume() method call, the device
  9460. * will be set to PCI_D0 directly in PCI config space before restoring the
  9461. * state.
  9462. *
  9463. * Return code
  9464. * 0 - driver suspended the device
  9465. * Error otherwise
  9466. **/
  9467. static int
  9468. lpfc_pci_resume_one_s4(struct pci_dev *pdev)
  9469. {
  9470. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9471. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9472. uint32_t intr_mode;
  9473. int error;
  9474. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9475. "0292 PCI device Power Management resume.\n");
  9476. /* Restore device state from PCI config space */
  9477. pci_set_power_state(pdev, PCI_D0);
  9478. pci_restore_state(pdev);
  9479. /*
  9480. * As the new kernel behavior of pci_restore_state() API call clears
  9481. * device saved_state flag, need to save the restored state again.
  9482. */
  9483. pci_save_state(pdev);
  9484. if (pdev->is_busmaster)
  9485. pci_set_master(pdev);
  9486. /* Startup the kernel thread for this host adapter. */
  9487. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  9488. "lpfc_worker_%d", phba->brd_no);
  9489. if (IS_ERR(phba->worker_thread)) {
  9490. error = PTR_ERR(phba->worker_thread);
  9491. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9492. "0293 PM resume failed to start worker "
  9493. "thread: error=x%x.\n", error);
  9494. return error;
  9495. }
  9496. /* Configure and enable interrupt */
  9497. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  9498. if (intr_mode == LPFC_INTR_ERROR) {
  9499. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9500. "0294 PM resume Failed to enable interrupt\n");
  9501. return -EIO;
  9502. } else
  9503. phba->intr_mode = intr_mode;
  9504. /* Restart HBA and bring it online */
  9505. lpfc_sli_brdrestart(phba);
  9506. lpfc_online(phba);
  9507. /* Log the current active interrupt mode */
  9508. lpfc_log_intr_mode(phba, phba->intr_mode);
  9509. return 0;
  9510. }
  9511. /**
  9512. * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
  9513. * @phba: pointer to lpfc hba data structure.
  9514. *
  9515. * This routine is called to prepare the SLI4 device for PCI slot recover. It
  9516. * aborts all the outstanding SCSI I/Os to the pci device.
  9517. **/
  9518. static void
  9519. lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
  9520. {
  9521. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9522. "2828 PCI channel I/O abort preparing for recovery\n");
  9523. /*
  9524. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  9525. * and let the SCSI mid-layer to retry them to recover.
  9526. */
  9527. lpfc_sli_abort_fcp_rings(phba);
  9528. }
  9529. /**
  9530. * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
  9531. * @phba: pointer to lpfc hba data structure.
  9532. *
  9533. * This routine is called to prepare the SLI4 device for PCI slot reset. It
  9534. * disables the device interrupt and pci device, and aborts the internal FCP
  9535. * pending I/Os.
  9536. **/
  9537. static void
  9538. lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
  9539. {
  9540. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9541. "2826 PCI channel disable preparing for reset\n");
  9542. /* Block any management I/Os to the device */
  9543. lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
  9544. /* Block all SCSI devices' I/Os on the host */
  9545. lpfc_scsi_dev_block(phba);
  9546. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  9547. lpfc_sli_flush_fcp_rings(phba);
  9548. /* stop all timers */
  9549. lpfc_stop_hba_timers(phba);
  9550. /* Disable interrupt and pci device */
  9551. lpfc_sli4_disable_intr(phba);
  9552. lpfc_sli4_queue_destroy(phba);
  9553. pci_disable_device(phba->pcidev);
  9554. }
  9555. /**
  9556. * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
  9557. * @phba: pointer to lpfc hba data structure.
  9558. *
  9559. * This routine is called to prepare the SLI4 device for PCI slot permanently
  9560. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  9561. * pending I/Os.
  9562. **/
  9563. static void
  9564. lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  9565. {
  9566. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9567. "2827 PCI channel permanent disable for failure\n");
  9568. /* Block all SCSI devices' I/Os on the host */
  9569. lpfc_scsi_dev_block(phba);
  9570. /* stop all timers */
  9571. lpfc_stop_hba_timers(phba);
  9572. /* Clean up all driver's outstanding SCSI I/Os */
  9573. lpfc_sli_flush_fcp_rings(phba);
  9574. }
  9575. /**
  9576. * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
  9577. * @pdev: pointer to PCI device.
  9578. * @state: the current PCI connection state.
  9579. *
  9580. * This routine is called from the PCI subsystem for error handling to device
  9581. * with SLI-4 interface spec. This function is called by the PCI subsystem
  9582. * after a PCI bus error affecting this device has been detected. When this
  9583. * function is invoked, it will need to stop all the I/Os and interrupt(s)
  9584. * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
  9585. * for the PCI subsystem to perform proper recovery as desired.
  9586. *
  9587. * Return codes
  9588. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  9589. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9590. **/
  9591. static pci_ers_result_t
  9592. lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
  9593. {
  9594. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9595. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9596. switch (state) {
  9597. case pci_channel_io_normal:
  9598. /* Non-fatal error, prepare for recovery */
  9599. lpfc_sli4_prep_dev_for_recover(phba);
  9600. return PCI_ERS_RESULT_CAN_RECOVER;
  9601. case pci_channel_io_frozen:
  9602. /* Fatal error, prepare for slot reset */
  9603. lpfc_sli4_prep_dev_for_reset(phba);
  9604. return PCI_ERS_RESULT_NEED_RESET;
  9605. case pci_channel_io_perm_failure:
  9606. /* Permanent failure, prepare for device down */
  9607. lpfc_sli4_prep_dev_for_perm_failure(phba);
  9608. return PCI_ERS_RESULT_DISCONNECT;
  9609. default:
  9610. /* Unknown state, prepare and request slot reset */
  9611. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9612. "2825 Unknown PCI error state: x%x\n", state);
  9613. lpfc_sli4_prep_dev_for_reset(phba);
  9614. return PCI_ERS_RESULT_NEED_RESET;
  9615. }
  9616. }
  9617. /**
  9618. * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
  9619. * @pdev: pointer to PCI device.
  9620. *
  9621. * This routine is called from the PCI subsystem for error handling to device
  9622. * with SLI-4 interface spec. It is called after PCI bus has been reset to
  9623. * restart the PCI card from scratch, as if from a cold-boot. During the
  9624. * PCI subsystem error recovery, after the driver returns
  9625. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  9626. * recovery and then call this routine before calling the .resume method to
  9627. * recover the device. This function will initialize the HBA device, enable
  9628. * the interrupt, but it will just put the HBA to offline state without
  9629. * passing any I/O traffic.
  9630. *
  9631. * Return codes
  9632. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  9633. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9634. */
  9635. static pci_ers_result_t
  9636. lpfc_io_slot_reset_s4(struct pci_dev *pdev)
  9637. {
  9638. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9639. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9640. struct lpfc_sli *psli = &phba->sli;
  9641. uint32_t intr_mode;
  9642. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  9643. if (pci_enable_device_mem(pdev)) {
  9644. printk(KERN_ERR "lpfc: Cannot re-enable "
  9645. "PCI device after reset.\n");
  9646. return PCI_ERS_RESULT_DISCONNECT;
  9647. }
  9648. pci_restore_state(pdev);
  9649. /*
  9650. * As the new kernel behavior of pci_restore_state() API call clears
  9651. * device saved_state flag, need to save the restored state again.
  9652. */
  9653. pci_save_state(pdev);
  9654. if (pdev->is_busmaster)
  9655. pci_set_master(pdev);
  9656. spin_lock_irq(&phba->hbalock);
  9657. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  9658. spin_unlock_irq(&phba->hbalock);
  9659. /* Configure and enable interrupt */
  9660. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  9661. if (intr_mode == LPFC_INTR_ERROR) {
  9662. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9663. "2824 Cannot re-enable interrupt after "
  9664. "slot reset.\n");
  9665. return PCI_ERS_RESULT_DISCONNECT;
  9666. } else
  9667. phba->intr_mode = intr_mode;
  9668. /* Log the current active interrupt mode */
  9669. lpfc_log_intr_mode(phba, phba->intr_mode);
  9670. return PCI_ERS_RESULT_RECOVERED;
  9671. }
  9672. /**
  9673. * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
  9674. * @pdev: pointer to PCI device
  9675. *
  9676. * This routine is called from the PCI subsystem for error handling to device
  9677. * with SLI-4 interface spec. It is called when kernel error recovery tells
  9678. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  9679. * error recovery. After this call, traffic can start to flow from this device
  9680. * again.
  9681. **/
  9682. static void
  9683. lpfc_io_resume_s4(struct pci_dev *pdev)
  9684. {
  9685. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9686. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9687. /*
  9688. * In case of slot reset, as function reset is performed through
  9689. * mailbox command which needs DMA to be enabled, this operation
  9690. * has to be moved to the io resume phase. Taking device offline
  9691. * will perform the necessary cleanup.
  9692. */
  9693. if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
  9694. /* Perform device reset */
  9695. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  9696. lpfc_offline(phba);
  9697. lpfc_sli_brdrestart(phba);
  9698. /* Bring the device back online */
  9699. lpfc_online(phba);
  9700. }
  9701. /* Clean up Advanced Error Reporting (AER) if needed */
  9702. if (phba->hba_flag & HBA_AER_ENABLED)
  9703. pci_cleanup_aer_uncorrect_error_status(pdev);
  9704. }
  9705. /**
  9706. * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
  9707. * @pdev: pointer to PCI device
  9708. * @pid: pointer to PCI device identifier
  9709. *
  9710. * This routine is to be registered to the kernel's PCI subsystem. When an
  9711. * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
  9712. * at PCI device-specific information of the device and driver to see if the
  9713. * driver state that it can support this kind of device. If the match is
  9714. * successful, the driver core invokes this routine. This routine dispatches
  9715. * the action to the proper SLI-3 or SLI-4 device probing routine, which will
  9716. * do all the initialization that it needs to do to handle the HBA device
  9717. * properly.
  9718. *
  9719. * Return code
  9720. * 0 - driver can claim the device
  9721. * negative value - driver can not claim the device
  9722. **/
  9723. static int
  9724. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  9725. {
  9726. int rc;
  9727. struct lpfc_sli_intf intf;
  9728. if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
  9729. return -ENODEV;
  9730. if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
  9731. (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
  9732. rc = lpfc_pci_probe_one_s4(pdev, pid);
  9733. else
  9734. rc = lpfc_pci_probe_one_s3(pdev, pid);
  9735. return rc;
  9736. }
  9737. /**
  9738. * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
  9739. * @pdev: pointer to PCI device
  9740. *
  9741. * This routine is to be registered to the kernel's PCI subsystem. When an
  9742. * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
  9743. * This routine dispatches the action to the proper SLI-3 or SLI-4 device
  9744. * remove routine, which will perform all the necessary cleanup for the
  9745. * device to be removed from the PCI subsystem properly.
  9746. **/
  9747. static void
  9748. lpfc_pci_remove_one(struct pci_dev *pdev)
  9749. {
  9750. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9751. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9752. switch (phba->pci_dev_grp) {
  9753. case LPFC_PCI_DEV_LP:
  9754. lpfc_pci_remove_one_s3(pdev);
  9755. break;
  9756. case LPFC_PCI_DEV_OC:
  9757. lpfc_pci_remove_one_s4(pdev);
  9758. break;
  9759. default:
  9760. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9761. "1424 Invalid PCI device group: 0x%x\n",
  9762. phba->pci_dev_grp);
  9763. break;
  9764. }
  9765. return;
  9766. }
  9767. /**
  9768. * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
  9769. * @pdev: pointer to PCI device
  9770. * @msg: power management message
  9771. *
  9772. * This routine is to be registered to the kernel's PCI subsystem to support
  9773. * system Power Management (PM). When PM invokes this method, it dispatches
  9774. * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
  9775. * suspend the device.
  9776. *
  9777. * Return code
  9778. * 0 - driver suspended the device
  9779. * Error otherwise
  9780. **/
  9781. static int
  9782. lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
  9783. {
  9784. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9785. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9786. int rc = -ENODEV;
  9787. switch (phba->pci_dev_grp) {
  9788. case LPFC_PCI_DEV_LP:
  9789. rc = lpfc_pci_suspend_one_s3(pdev, msg);
  9790. break;
  9791. case LPFC_PCI_DEV_OC:
  9792. rc = lpfc_pci_suspend_one_s4(pdev, msg);
  9793. break;
  9794. default:
  9795. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9796. "1425 Invalid PCI device group: 0x%x\n",
  9797. phba->pci_dev_grp);
  9798. break;
  9799. }
  9800. return rc;
  9801. }
  9802. /**
  9803. * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
  9804. * @pdev: pointer to PCI device
  9805. *
  9806. * This routine is to be registered to the kernel's PCI subsystem to support
  9807. * system Power Management (PM). When PM invokes this method, it dispatches
  9808. * the action to the proper SLI-3 or SLI-4 device resume routine, which will
  9809. * resume the device.
  9810. *
  9811. * Return code
  9812. * 0 - driver suspended the device
  9813. * Error otherwise
  9814. **/
  9815. static int
  9816. lpfc_pci_resume_one(struct pci_dev *pdev)
  9817. {
  9818. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9819. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9820. int rc = -ENODEV;
  9821. switch (phba->pci_dev_grp) {
  9822. case LPFC_PCI_DEV_LP:
  9823. rc = lpfc_pci_resume_one_s3(pdev);
  9824. break;
  9825. case LPFC_PCI_DEV_OC:
  9826. rc = lpfc_pci_resume_one_s4(pdev);
  9827. break;
  9828. default:
  9829. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9830. "1426 Invalid PCI device group: 0x%x\n",
  9831. phba->pci_dev_grp);
  9832. break;
  9833. }
  9834. return rc;
  9835. }
  9836. /**
  9837. * lpfc_io_error_detected - lpfc method for handling PCI I/O error
  9838. * @pdev: pointer to PCI device.
  9839. * @state: the current PCI connection state.
  9840. *
  9841. * This routine is registered to the PCI subsystem for error handling. This
  9842. * function is called by the PCI subsystem after a PCI bus error affecting
  9843. * this device has been detected. When this routine is invoked, it dispatches
  9844. * the action to the proper SLI-3 or SLI-4 device error detected handling
  9845. * routine, which will perform the proper error detected operation.
  9846. *
  9847. * Return codes
  9848. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  9849. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9850. **/
  9851. static pci_ers_result_t
  9852. lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  9853. {
  9854. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9855. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9856. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  9857. switch (phba->pci_dev_grp) {
  9858. case LPFC_PCI_DEV_LP:
  9859. rc = lpfc_io_error_detected_s3(pdev, state);
  9860. break;
  9861. case LPFC_PCI_DEV_OC:
  9862. rc = lpfc_io_error_detected_s4(pdev, state);
  9863. break;
  9864. default:
  9865. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9866. "1427 Invalid PCI device group: 0x%x\n",
  9867. phba->pci_dev_grp);
  9868. break;
  9869. }
  9870. return rc;
  9871. }
  9872. /**
  9873. * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
  9874. * @pdev: pointer to PCI device.
  9875. *
  9876. * This routine is registered to the PCI subsystem for error handling. This
  9877. * function is called after PCI bus has been reset to restart the PCI card
  9878. * from scratch, as if from a cold-boot. When this routine is invoked, it
  9879. * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
  9880. * routine, which will perform the proper device reset.
  9881. *
  9882. * Return codes
  9883. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  9884. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9885. **/
  9886. static pci_ers_result_t
  9887. lpfc_io_slot_reset(struct pci_dev *pdev)
  9888. {
  9889. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9890. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9891. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  9892. switch (phba->pci_dev_grp) {
  9893. case LPFC_PCI_DEV_LP:
  9894. rc = lpfc_io_slot_reset_s3(pdev);
  9895. break;
  9896. case LPFC_PCI_DEV_OC:
  9897. rc = lpfc_io_slot_reset_s4(pdev);
  9898. break;
  9899. default:
  9900. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9901. "1428 Invalid PCI device group: 0x%x\n",
  9902. phba->pci_dev_grp);
  9903. break;
  9904. }
  9905. return rc;
  9906. }
  9907. /**
  9908. * lpfc_io_resume - lpfc method for resuming PCI I/O operation
  9909. * @pdev: pointer to PCI device
  9910. *
  9911. * This routine is registered to the PCI subsystem for error handling. It
  9912. * is called when kernel error recovery tells the lpfc driver that it is
  9913. * OK to resume normal PCI operation after PCI bus error recovery. When
  9914. * this routine is invoked, it dispatches the action to the proper SLI-3
  9915. * or SLI-4 device io_resume routine, which will resume the device operation.
  9916. **/
  9917. static void
  9918. lpfc_io_resume(struct pci_dev *pdev)
  9919. {
  9920. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9921. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9922. switch (phba->pci_dev_grp) {
  9923. case LPFC_PCI_DEV_LP:
  9924. lpfc_io_resume_s3(pdev);
  9925. break;
  9926. case LPFC_PCI_DEV_OC:
  9927. lpfc_io_resume_s4(pdev);
  9928. break;
  9929. default:
  9930. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9931. "1429 Invalid PCI device group: 0x%x\n",
  9932. phba->pci_dev_grp);
  9933. break;
  9934. }
  9935. return;
  9936. }
  9937. /**
  9938. * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
  9939. * @phba: pointer to lpfc hba data structure.
  9940. *
  9941. * This routine checks to see if OAS is supported for this adapter. If
  9942. * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
  9943. * the enable oas flag is cleared and the pool created for OAS device data
  9944. * is destroyed.
  9945. *
  9946. **/
  9947. void
  9948. lpfc_sli4_oas_verify(struct lpfc_hba *phba)
  9949. {
  9950. if (!phba->cfg_EnableXLane)
  9951. return;
  9952. if (phba->sli4_hba.pc_sli4_params.oas_supported) {
  9953. phba->cfg_fof = 1;
  9954. } else {
  9955. phba->cfg_fof = 0;
  9956. if (phba->device_data_mem_pool)
  9957. mempool_destroy(phba->device_data_mem_pool);
  9958. phba->device_data_mem_pool = NULL;
  9959. }
  9960. return;
  9961. }
  9962. /**
  9963. * lpfc_fof_queue_setup - Set up all the fof queues
  9964. * @phba: pointer to lpfc hba data structure.
  9965. *
  9966. * This routine is invoked to set up all the fof queues for the FC HBA
  9967. * operation.
  9968. *
  9969. * Return codes
  9970. * 0 - successful
  9971. * -ENOMEM - No available memory
  9972. **/
  9973. int
  9974. lpfc_fof_queue_setup(struct lpfc_hba *phba)
  9975. {
  9976. struct lpfc_sli *psli = &phba->sli;
  9977. int rc;
  9978. rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
  9979. if (rc)
  9980. return -ENOMEM;
  9981. if (phba->cfg_fof) {
  9982. rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
  9983. phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
  9984. if (rc)
  9985. goto out_oas_cq;
  9986. rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
  9987. phba->sli4_hba.oas_cq, LPFC_FCP);
  9988. if (rc)
  9989. goto out_oas_wq;
  9990. phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING];
  9991. phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING];
  9992. }
  9993. return 0;
  9994. out_oas_wq:
  9995. lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
  9996. out_oas_cq:
  9997. lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
  9998. return rc;
  9999. }
  10000. /**
  10001. * lpfc_fof_queue_create - Create all the fof queues
  10002. * @phba: pointer to lpfc hba data structure.
  10003. *
  10004. * This routine is invoked to allocate all the fof queues for the FC HBA
  10005. * operation. For each SLI4 queue type, the parameters such as queue entry
  10006. * count (queue depth) shall be taken from the module parameter. For now,
  10007. * we just use some constant number as place holder.
  10008. *
  10009. * Return codes
  10010. * 0 - successful
  10011. * -ENOMEM - No availble memory
  10012. * -EIO - The mailbox failed to complete successfully.
  10013. **/
  10014. int
  10015. lpfc_fof_queue_create(struct lpfc_hba *phba)
  10016. {
  10017. struct lpfc_queue *qdesc;
  10018. /* Create FOF EQ */
  10019. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  10020. phba->sli4_hba.eq_ecount);
  10021. if (!qdesc)
  10022. goto out_error;
  10023. phba->sli4_hba.fof_eq = qdesc;
  10024. if (phba->cfg_fof) {
  10025. /* Create OAS CQ */
  10026. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  10027. phba->sli4_hba.cq_ecount);
  10028. if (!qdesc)
  10029. goto out_error;
  10030. phba->sli4_hba.oas_cq = qdesc;
  10031. /* Create OAS WQ */
  10032. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  10033. phba->sli4_hba.wq_ecount);
  10034. if (!qdesc)
  10035. goto out_error;
  10036. phba->sli4_hba.oas_wq = qdesc;
  10037. }
  10038. return 0;
  10039. out_error:
  10040. lpfc_fof_queue_destroy(phba);
  10041. return -ENOMEM;
  10042. }
  10043. /**
  10044. * lpfc_fof_queue_destroy - Destroy all the fof queues
  10045. * @phba: pointer to lpfc hba data structure.
  10046. *
  10047. * This routine is invoked to release all the SLI4 queues with the FC HBA
  10048. * operation.
  10049. *
  10050. * Return codes
  10051. * 0 - successful
  10052. **/
  10053. int
  10054. lpfc_fof_queue_destroy(struct lpfc_hba *phba)
  10055. {
  10056. /* Release FOF Event queue */
  10057. if (phba->sli4_hba.fof_eq != NULL) {
  10058. lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
  10059. phba->sli4_hba.fof_eq = NULL;
  10060. }
  10061. /* Release OAS Completion queue */
  10062. if (phba->sli4_hba.oas_cq != NULL) {
  10063. lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
  10064. phba->sli4_hba.oas_cq = NULL;
  10065. }
  10066. /* Release OAS Work queue */
  10067. if (phba->sli4_hba.oas_wq != NULL) {
  10068. lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
  10069. phba->sli4_hba.oas_wq = NULL;
  10070. }
  10071. return 0;
  10072. }
  10073. static struct pci_device_id lpfc_id_table[] = {
  10074. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  10075. PCI_ANY_ID, PCI_ANY_ID, },
  10076. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  10077. PCI_ANY_ID, PCI_ANY_ID, },
  10078. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  10079. PCI_ANY_ID, PCI_ANY_ID, },
  10080. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  10081. PCI_ANY_ID, PCI_ANY_ID, },
  10082. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  10083. PCI_ANY_ID, PCI_ANY_ID, },
  10084. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  10085. PCI_ANY_ID, PCI_ANY_ID, },
  10086. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  10087. PCI_ANY_ID, PCI_ANY_ID, },
  10088. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  10089. PCI_ANY_ID, PCI_ANY_ID, },
  10090. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  10091. PCI_ANY_ID, PCI_ANY_ID, },
  10092. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  10093. PCI_ANY_ID, PCI_ANY_ID, },
  10094. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  10095. PCI_ANY_ID, PCI_ANY_ID, },
  10096. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  10097. PCI_ANY_ID, PCI_ANY_ID, },
  10098. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  10099. PCI_ANY_ID, PCI_ANY_ID, },
  10100. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  10101. PCI_ANY_ID, PCI_ANY_ID, },
  10102. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  10103. PCI_ANY_ID, PCI_ANY_ID, },
  10104. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  10105. PCI_ANY_ID, PCI_ANY_ID, },
  10106. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  10107. PCI_ANY_ID, PCI_ANY_ID, },
  10108. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  10109. PCI_ANY_ID, PCI_ANY_ID, },
  10110. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
  10111. PCI_ANY_ID, PCI_ANY_ID, },
  10112. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  10113. PCI_ANY_ID, PCI_ANY_ID, },
  10114. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  10115. PCI_ANY_ID, PCI_ANY_ID, },
  10116. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  10117. PCI_ANY_ID, PCI_ANY_ID, },
  10118. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  10119. PCI_ANY_ID, PCI_ANY_ID, },
  10120. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  10121. PCI_ANY_ID, PCI_ANY_ID, },
  10122. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  10123. PCI_ANY_ID, PCI_ANY_ID, },
  10124. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  10125. PCI_ANY_ID, PCI_ANY_ID, },
  10126. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  10127. PCI_ANY_ID, PCI_ANY_ID, },
  10128. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  10129. PCI_ANY_ID, PCI_ANY_ID, },
  10130. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  10131. PCI_ANY_ID, PCI_ANY_ID, },
  10132. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  10133. PCI_ANY_ID, PCI_ANY_ID, },
  10134. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  10135. PCI_ANY_ID, PCI_ANY_ID, },
  10136. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  10137. PCI_ANY_ID, PCI_ANY_ID, },
  10138. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  10139. PCI_ANY_ID, PCI_ANY_ID, },
  10140. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  10141. PCI_ANY_ID, PCI_ANY_ID, },
  10142. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
  10143. PCI_ANY_ID, PCI_ANY_ID, },
  10144. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
  10145. PCI_ANY_ID, PCI_ANY_ID, },
  10146. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
  10147. PCI_ANY_ID, PCI_ANY_ID, },
  10148. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
  10149. PCI_ANY_ID, PCI_ANY_ID, },
  10150. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
  10151. PCI_ANY_ID, PCI_ANY_ID, },
  10152. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
  10153. PCI_ANY_ID, PCI_ANY_ID, },
  10154. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
  10155. PCI_ANY_ID, PCI_ANY_ID, },
  10156. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
  10157. PCI_ANY_ID, PCI_ANY_ID, },
  10158. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
  10159. PCI_ANY_ID, PCI_ANY_ID, },
  10160. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
  10161. PCI_ANY_ID, PCI_ANY_ID, },
  10162. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
  10163. PCI_ANY_ID, PCI_ANY_ID, },
  10164. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
  10165. PCI_ANY_ID, PCI_ANY_ID, },
  10166. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
  10167. PCI_ANY_ID, PCI_ANY_ID, },
  10168. { 0 }
  10169. };
  10170. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  10171. static const struct pci_error_handlers lpfc_err_handler = {
  10172. .error_detected = lpfc_io_error_detected,
  10173. .slot_reset = lpfc_io_slot_reset,
  10174. .resume = lpfc_io_resume,
  10175. };
  10176. static struct pci_driver lpfc_driver = {
  10177. .name = LPFC_DRIVER_NAME,
  10178. .id_table = lpfc_id_table,
  10179. .probe = lpfc_pci_probe_one,
  10180. .remove = lpfc_pci_remove_one,
  10181. .suspend = lpfc_pci_suspend_one,
  10182. .resume = lpfc_pci_resume_one,
  10183. .err_handler = &lpfc_err_handler,
  10184. };
  10185. static const struct file_operations lpfc_mgmt_fop = {
  10186. .owner = THIS_MODULE,
  10187. };
  10188. static struct miscdevice lpfc_mgmt_dev = {
  10189. .minor = MISC_DYNAMIC_MINOR,
  10190. .name = "lpfcmgmt",
  10191. .fops = &lpfc_mgmt_fop,
  10192. };
  10193. /**
  10194. * lpfc_init - lpfc module initialization routine
  10195. *
  10196. * This routine is to be invoked when the lpfc module is loaded into the
  10197. * kernel. The special kernel macro module_init() is used to indicate the
  10198. * role of this routine to the kernel as lpfc module entry point.
  10199. *
  10200. * Return codes
  10201. * 0 - successful
  10202. * -ENOMEM - FC attach transport failed
  10203. * all others - failed
  10204. */
  10205. static int __init
  10206. lpfc_init(void)
  10207. {
  10208. int cpu;
  10209. int error = 0;
  10210. printk(LPFC_MODULE_DESC "\n");
  10211. printk(LPFC_COPYRIGHT "\n");
  10212. error = misc_register(&lpfc_mgmt_dev);
  10213. if (error)
  10214. printk(KERN_ERR "Could not register lpfcmgmt device, "
  10215. "misc_register returned with status %d", error);
  10216. if (lpfc_enable_npiv) {
  10217. lpfc_transport_functions.vport_create = lpfc_vport_create;
  10218. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  10219. }
  10220. lpfc_transport_template =
  10221. fc_attach_transport(&lpfc_transport_functions);
  10222. if (lpfc_transport_template == NULL)
  10223. return -ENOMEM;
  10224. if (lpfc_enable_npiv) {
  10225. lpfc_vport_transport_template =
  10226. fc_attach_transport(&lpfc_vport_transport_functions);
  10227. if (lpfc_vport_transport_template == NULL) {
  10228. fc_release_transport(lpfc_transport_template);
  10229. return -ENOMEM;
  10230. }
  10231. }
  10232. /* Initialize in case vector mapping is needed */
  10233. lpfc_used_cpu = NULL;
  10234. lpfc_present_cpu = 0;
  10235. for_each_present_cpu(cpu)
  10236. lpfc_present_cpu++;
  10237. error = pci_register_driver(&lpfc_driver);
  10238. if (error) {
  10239. fc_release_transport(lpfc_transport_template);
  10240. if (lpfc_enable_npiv)
  10241. fc_release_transport(lpfc_vport_transport_template);
  10242. }
  10243. return error;
  10244. }
  10245. /**
  10246. * lpfc_exit - lpfc module removal routine
  10247. *
  10248. * This routine is invoked when the lpfc module is removed from the kernel.
  10249. * The special kernel macro module_exit() is used to indicate the role of
  10250. * this routine to the kernel as lpfc module exit point.
  10251. */
  10252. static void __exit
  10253. lpfc_exit(void)
  10254. {
  10255. misc_deregister(&lpfc_mgmt_dev);
  10256. pci_unregister_driver(&lpfc_driver);
  10257. fc_release_transport(lpfc_transport_template);
  10258. if (lpfc_enable_npiv)
  10259. fc_release_transport(lpfc_vport_transport_template);
  10260. if (_dump_buf_data) {
  10261. printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
  10262. "_dump_buf_data at 0x%p\n",
  10263. (1L << _dump_buf_data_order), _dump_buf_data);
  10264. free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
  10265. }
  10266. if (_dump_buf_dif) {
  10267. printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
  10268. "_dump_buf_dif at 0x%p\n",
  10269. (1L << _dump_buf_dif_order), _dump_buf_dif);
  10270. free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
  10271. }
  10272. kfree(lpfc_used_cpu);
  10273. }
  10274. module_init(lpfc_init);
  10275. module_exit(lpfc_exit);
  10276. MODULE_LICENSE("GPL");
  10277. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  10278. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  10279. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);