lpfc_hbadisc.c 178 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2012 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/slab.h>
  24. #include <linux/pci.h>
  25. #include <linux/kthread.h>
  26. #include <linux/interrupt.h>
  27. #include <scsi/scsi.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include "lpfc_hw4.h"
  32. #include "lpfc_hw.h"
  33. #include "lpfc_nl.h"
  34. #include "lpfc_disc.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_scsi.h"
  38. #include "lpfc.h"
  39. #include "lpfc_logmsg.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_vport.h"
  42. #include "lpfc_debugfs.h"
  43. /* AlpaArray for assignment of scsid for scan-down and bind_method */
  44. static uint8_t lpfcAlpaArray[] = {
  45. 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
  46. 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
  47. 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
  48. 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
  49. 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
  50. 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
  51. 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
  52. 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
  53. 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
  54. 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
  55. 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
  56. 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
  57. 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
  58. };
  59. static void lpfc_disc_timeout_handler(struct lpfc_vport *);
  60. static void lpfc_disc_flush_list(struct lpfc_vport *vport);
  61. static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
  62. static int lpfc_fcf_inuse(struct lpfc_hba *);
  63. void
  64. lpfc_terminate_rport_io(struct fc_rport *rport)
  65. {
  66. struct lpfc_rport_data *rdata;
  67. struct lpfc_nodelist * ndlp;
  68. struct lpfc_hba *phba;
  69. rdata = rport->dd_data;
  70. ndlp = rdata->pnode;
  71. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  72. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  73. printk(KERN_ERR "Cannot find remote node"
  74. " to terminate I/O Data x%x\n",
  75. rport->port_id);
  76. return;
  77. }
  78. phba = ndlp->phba;
  79. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  80. "rport terminate: sid:x%x did:x%x flg:x%x",
  81. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  82. if (ndlp->nlp_sid != NLP_NO_SID) {
  83. lpfc_sli_abort_iocb(ndlp->vport,
  84. &phba->sli.ring[phba->sli.fcp_ring],
  85. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  86. }
  87. }
  88. /*
  89. * This function will be called when dev_loss_tmo fire.
  90. */
  91. void
  92. lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
  93. {
  94. struct lpfc_rport_data *rdata;
  95. struct lpfc_nodelist * ndlp;
  96. struct lpfc_vport *vport;
  97. struct lpfc_hba *phba;
  98. struct lpfc_work_evt *evtp;
  99. int put_node;
  100. int put_rport;
  101. rdata = rport->dd_data;
  102. ndlp = rdata->pnode;
  103. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  104. return;
  105. vport = ndlp->vport;
  106. phba = vport->phba;
  107. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  108. "rport devlosscb: sid:x%x did:x%x flg:x%x",
  109. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  110. /* Don't defer this if we are in the process of deleting the vport
  111. * or unloading the driver. The unload will cleanup the node
  112. * appropriately we just need to cleanup the ndlp rport info here.
  113. */
  114. if (vport->load_flag & FC_UNLOADING) {
  115. put_node = rdata->pnode != NULL;
  116. put_rport = ndlp->rport != NULL;
  117. rdata->pnode = NULL;
  118. ndlp->rport = NULL;
  119. if (put_node)
  120. lpfc_nlp_put(ndlp);
  121. if (put_rport)
  122. put_device(&rport->dev);
  123. return;
  124. }
  125. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
  126. return;
  127. evtp = &ndlp->dev_loss_evt;
  128. if (!list_empty(&evtp->evt_listp))
  129. return;
  130. spin_lock_irq(&phba->hbalock);
  131. /* We need to hold the node by incrementing the reference
  132. * count until this queued work is done
  133. */
  134. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  135. if (evtp->evt_arg1) {
  136. evtp->evt = LPFC_EVT_DEV_LOSS;
  137. list_add_tail(&evtp->evt_listp, &phba->work_list);
  138. lpfc_worker_wake_up(phba);
  139. }
  140. spin_unlock_irq(&phba->hbalock);
  141. return;
  142. }
  143. /**
  144. * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
  145. * @ndlp: Pointer to remote node object.
  146. *
  147. * This function is called from the worker thread when devloss timeout timer
  148. * expires. For SLI4 host, this routine shall return 1 when at lease one
  149. * remote node, including this @ndlp, is still in use of FCF; otherwise, this
  150. * routine shall return 0 when there is no remote node is still in use of FCF
  151. * when devloss timeout happened to this @ndlp.
  152. **/
  153. static int
  154. lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
  155. {
  156. struct lpfc_rport_data *rdata;
  157. struct fc_rport *rport;
  158. struct lpfc_vport *vport;
  159. struct lpfc_hba *phba;
  160. uint8_t *name;
  161. int put_node;
  162. int put_rport;
  163. int warn_on = 0;
  164. int fcf_inuse = 0;
  165. rport = ndlp->rport;
  166. if (!rport)
  167. return fcf_inuse;
  168. rdata = rport->dd_data;
  169. name = (uint8_t *) &ndlp->nlp_portname;
  170. vport = ndlp->vport;
  171. phba = vport->phba;
  172. if (phba->sli_rev == LPFC_SLI_REV4)
  173. fcf_inuse = lpfc_fcf_inuse(phba);
  174. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  175. "rport devlosstmo:did:x%x type:x%x id:x%x",
  176. ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
  177. /* Don't defer this if we are in the process of deleting the vport
  178. * or unloading the driver. The unload will cleanup the node
  179. * appropriately we just need to cleanup the ndlp rport info here.
  180. */
  181. if (vport->load_flag & FC_UNLOADING) {
  182. if (ndlp->nlp_sid != NLP_NO_SID) {
  183. /* flush the target */
  184. lpfc_sli_abort_iocb(vport,
  185. &phba->sli.ring[phba->sli.fcp_ring],
  186. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  187. }
  188. put_node = rdata->pnode != NULL;
  189. put_rport = ndlp->rport != NULL;
  190. rdata->pnode = NULL;
  191. ndlp->rport = NULL;
  192. if (put_node)
  193. lpfc_nlp_put(ndlp);
  194. if (put_rport)
  195. put_device(&rport->dev);
  196. return fcf_inuse;
  197. }
  198. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
  199. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  200. "0284 Devloss timeout Ignored on "
  201. "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
  202. "NPort x%x\n",
  203. *name, *(name+1), *(name+2), *(name+3),
  204. *(name+4), *(name+5), *(name+6), *(name+7),
  205. ndlp->nlp_DID);
  206. return fcf_inuse;
  207. }
  208. if (ndlp->nlp_type & NLP_FABRIC) {
  209. /* We will clean up these Nodes in linkup */
  210. put_node = rdata->pnode != NULL;
  211. put_rport = ndlp->rport != NULL;
  212. rdata->pnode = NULL;
  213. ndlp->rport = NULL;
  214. if (put_node)
  215. lpfc_nlp_put(ndlp);
  216. if (put_rport)
  217. put_device(&rport->dev);
  218. return fcf_inuse;
  219. }
  220. if (ndlp->nlp_sid != NLP_NO_SID) {
  221. warn_on = 1;
  222. /* flush the target */
  223. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  224. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  225. }
  226. if (warn_on) {
  227. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  228. "0203 Devloss timeout on "
  229. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
  230. "NPort x%06x Data: x%x x%x x%x\n",
  231. *name, *(name+1), *(name+2), *(name+3),
  232. *(name+4), *(name+5), *(name+6), *(name+7),
  233. ndlp->nlp_DID, ndlp->nlp_flag,
  234. ndlp->nlp_state, ndlp->nlp_rpi);
  235. } else {
  236. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  237. "0204 Devloss timeout on "
  238. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
  239. "NPort x%06x Data: x%x x%x x%x\n",
  240. *name, *(name+1), *(name+2), *(name+3),
  241. *(name+4), *(name+5), *(name+6), *(name+7),
  242. ndlp->nlp_DID, ndlp->nlp_flag,
  243. ndlp->nlp_state, ndlp->nlp_rpi);
  244. }
  245. put_node = rdata->pnode != NULL;
  246. put_rport = ndlp->rport != NULL;
  247. rdata->pnode = NULL;
  248. ndlp->rport = NULL;
  249. if (put_node)
  250. lpfc_nlp_put(ndlp);
  251. if (put_rport)
  252. put_device(&rport->dev);
  253. if (!(vport->load_flag & FC_UNLOADING) &&
  254. !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  255. !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
  256. (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  257. (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
  258. (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
  259. lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
  260. return fcf_inuse;
  261. }
  262. /**
  263. * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
  264. * @phba: Pointer to hba context object.
  265. * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
  266. * @nlp_did: remote node identifer with devloss timeout.
  267. *
  268. * This function is called from the worker thread after invoking devloss
  269. * timeout handler and releasing the reference count for the ndlp with
  270. * which the devloss timeout was handled for SLI4 host. For the devloss
  271. * timeout of the last remote node which had been in use of FCF, when this
  272. * routine is invoked, it shall be guaranteed that none of the remote are
  273. * in-use of FCF. When devloss timeout to the last remote using the FCF,
  274. * if the FIP engine is neither in FCF table scan process nor roundrobin
  275. * failover process, the in-use FCF shall be unregistered. If the FIP
  276. * engine is in FCF discovery process, the devloss timeout state shall
  277. * be set for either the FCF table scan process or roundrobin failover
  278. * process to unregister the in-use FCF.
  279. **/
  280. static void
  281. lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
  282. uint32_t nlp_did)
  283. {
  284. /* If devloss timeout happened to a remote node when FCF had no
  285. * longer been in-use, do nothing.
  286. */
  287. if (!fcf_inuse)
  288. return;
  289. if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
  290. spin_lock_irq(&phba->hbalock);
  291. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  292. if (phba->hba_flag & HBA_DEVLOSS_TMO) {
  293. spin_unlock_irq(&phba->hbalock);
  294. return;
  295. }
  296. phba->hba_flag |= HBA_DEVLOSS_TMO;
  297. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  298. "2847 Last remote node (x%x) using "
  299. "FCF devloss tmo\n", nlp_did);
  300. }
  301. if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
  302. spin_unlock_irq(&phba->hbalock);
  303. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  304. "2868 Devloss tmo to FCF rediscovery "
  305. "in progress\n");
  306. return;
  307. }
  308. if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
  309. spin_unlock_irq(&phba->hbalock);
  310. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  311. "2869 Devloss tmo to idle FIP engine, "
  312. "unreg in-use FCF and rescan.\n");
  313. /* Unregister in-use FCF and rescan */
  314. lpfc_unregister_fcf_rescan(phba);
  315. return;
  316. }
  317. spin_unlock_irq(&phba->hbalock);
  318. if (phba->hba_flag & FCF_TS_INPROG)
  319. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  320. "2870 FCF table scan in progress\n");
  321. if (phba->hba_flag & FCF_RR_INPROG)
  322. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  323. "2871 FLOGI roundrobin FCF failover "
  324. "in progress\n");
  325. }
  326. lpfc_unregister_unused_fcf(phba);
  327. }
  328. /**
  329. * lpfc_alloc_fast_evt - Allocates data structure for posting event
  330. * @phba: Pointer to hba context object.
  331. *
  332. * This function is called from the functions which need to post
  333. * events from interrupt context. This function allocates data
  334. * structure required for posting event. It also keeps track of
  335. * number of events pending and prevent event storm when there are
  336. * too many events.
  337. **/
  338. struct lpfc_fast_path_event *
  339. lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
  340. struct lpfc_fast_path_event *ret;
  341. /* If there are lot of fast event do not exhaust memory due to this */
  342. if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
  343. return NULL;
  344. ret = kzalloc(sizeof(struct lpfc_fast_path_event),
  345. GFP_ATOMIC);
  346. if (ret) {
  347. atomic_inc(&phba->fast_event_count);
  348. INIT_LIST_HEAD(&ret->work_evt.evt_listp);
  349. ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
  350. }
  351. return ret;
  352. }
  353. /**
  354. * lpfc_free_fast_evt - Frees event data structure
  355. * @phba: Pointer to hba context object.
  356. * @evt: Event object which need to be freed.
  357. *
  358. * This function frees the data structure required for posting
  359. * events.
  360. **/
  361. void
  362. lpfc_free_fast_evt(struct lpfc_hba *phba,
  363. struct lpfc_fast_path_event *evt) {
  364. atomic_dec(&phba->fast_event_count);
  365. kfree(evt);
  366. }
  367. /**
  368. * lpfc_send_fastpath_evt - Posts events generated from fast path
  369. * @phba: Pointer to hba context object.
  370. * @evtp: Event data structure.
  371. *
  372. * This function is called from worker thread, when the interrupt
  373. * context need to post an event. This function posts the event
  374. * to fc transport netlink interface.
  375. **/
  376. static void
  377. lpfc_send_fastpath_evt(struct lpfc_hba *phba,
  378. struct lpfc_work_evt *evtp)
  379. {
  380. unsigned long evt_category, evt_sub_category;
  381. struct lpfc_fast_path_event *fast_evt_data;
  382. char *evt_data;
  383. uint32_t evt_data_size;
  384. struct Scsi_Host *shost;
  385. fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
  386. work_evt);
  387. evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
  388. evt_sub_category = (unsigned long) fast_evt_data->un.
  389. fabric_evt.subcategory;
  390. shost = lpfc_shost_from_vport(fast_evt_data->vport);
  391. if (evt_category == FC_REG_FABRIC_EVENT) {
  392. if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
  393. evt_data = (char *) &fast_evt_data->un.read_check_error;
  394. evt_data_size = sizeof(fast_evt_data->un.
  395. read_check_error);
  396. } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
  397. (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
  398. evt_data = (char *) &fast_evt_data->un.fabric_evt;
  399. evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
  400. } else {
  401. lpfc_free_fast_evt(phba, fast_evt_data);
  402. return;
  403. }
  404. } else if (evt_category == FC_REG_SCSI_EVENT) {
  405. switch (evt_sub_category) {
  406. case LPFC_EVENT_QFULL:
  407. case LPFC_EVENT_DEVBSY:
  408. evt_data = (char *) &fast_evt_data->un.scsi_evt;
  409. evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
  410. break;
  411. case LPFC_EVENT_CHECK_COND:
  412. evt_data = (char *) &fast_evt_data->un.check_cond_evt;
  413. evt_data_size = sizeof(fast_evt_data->un.
  414. check_cond_evt);
  415. break;
  416. case LPFC_EVENT_VARQUEDEPTH:
  417. evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
  418. evt_data_size = sizeof(fast_evt_data->un.
  419. queue_depth_evt);
  420. break;
  421. default:
  422. lpfc_free_fast_evt(phba, fast_evt_data);
  423. return;
  424. }
  425. } else {
  426. lpfc_free_fast_evt(phba, fast_evt_data);
  427. return;
  428. }
  429. fc_host_post_vendor_event(shost,
  430. fc_get_event_number(),
  431. evt_data_size,
  432. evt_data,
  433. LPFC_NL_VENDOR_ID);
  434. lpfc_free_fast_evt(phba, fast_evt_data);
  435. return;
  436. }
  437. static void
  438. lpfc_work_list_done(struct lpfc_hba *phba)
  439. {
  440. struct lpfc_work_evt *evtp = NULL;
  441. struct lpfc_nodelist *ndlp;
  442. int free_evt;
  443. int fcf_inuse;
  444. uint32_t nlp_did;
  445. spin_lock_irq(&phba->hbalock);
  446. while (!list_empty(&phba->work_list)) {
  447. list_remove_head((&phba->work_list), evtp, typeof(*evtp),
  448. evt_listp);
  449. spin_unlock_irq(&phba->hbalock);
  450. free_evt = 1;
  451. switch (evtp->evt) {
  452. case LPFC_EVT_ELS_RETRY:
  453. ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
  454. lpfc_els_retry_delay_handler(ndlp);
  455. free_evt = 0; /* evt is part of ndlp */
  456. /* decrement the node reference count held
  457. * for this queued work
  458. */
  459. lpfc_nlp_put(ndlp);
  460. break;
  461. case LPFC_EVT_DEV_LOSS:
  462. ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
  463. fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
  464. free_evt = 0;
  465. /* decrement the node reference count held for
  466. * this queued work
  467. */
  468. nlp_did = ndlp->nlp_DID;
  469. lpfc_nlp_put(ndlp);
  470. if (phba->sli_rev == LPFC_SLI_REV4)
  471. lpfc_sli4_post_dev_loss_tmo_handler(phba,
  472. fcf_inuse,
  473. nlp_did);
  474. break;
  475. case LPFC_EVT_ONLINE:
  476. if (phba->link_state < LPFC_LINK_DOWN)
  477. *(int *) (evtp->evt_arg1) = lpfc_online(phba);
  478. else
  479. *(int *) (evtp->evt_arg1) = 0;
  480. complete((struct completion *)(evtp->evt_arg2));
  481. break;
  482. case LPFC_EVT_OFFLINE_PREP:
  483. if (phba->link_state >= LPFC_LINK_DOWN)
  484. lpfc_offline_prep(phba);
  485. *(int *)(evtp->evt_arg1) = 0;
  486. complete((struct completion *)(evtp->evt_arg2));
  487. break;
  488. case LPFC_EVT_OFFLINE:
  489. lpfc_offline(phba);
  490. lpfc_sli_brdrestart(phba);
  491. *(int *)(evtp->evt_arg1) =
  492. lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
  493. lpfc_unblock_mgmt_io(phba);
  494. complete((struct completion *)(evtp->evt_arg2));
  495. break;
  496. case LPFC_EVT_WARM_START:
  497. lpfc_offline(phba);
  498. lpfc_reset_barrier(phba);
  499. lpfc_sli_brdreset(phba);
  500. lpfc_hba_down_post(phba);
  501. *(int *)(evtp->evt_arg1) =
  502. lpfc_sli_brdready(phba, HS_MBRDY);
  503. lpfc_unblock_mgmt_io(phba);
  504. complete((struct completion *)(evtp->evt_arg2));
  505. break;
  506. case LPFC_EVT_KILL:
  507. lpfc_offline(phba);
  508. *(int *)(evtp->evt_arg1)
  509. = (phba->pport->stopped)
  510. ? 0 : lpfc_sli_brdkill(phba);
  511. lpfc_unblock_mgmt_io(phba);
  512. complete((struct completion *)(evtp->evt_arg2));
  513. break;
  514. case LPFC_EVT_FASTPATH_MGMT_EVT:
  515. lpfc_send_fastpath_evt(phba, evtp);
  516. free_evt = 0;
  517. break;
  518. case LPFC_EVT_RESET_HBA:
  519. if (!(phba->pport->load_flag & FC_UNLOADING))
  520. lpfc_reset_hba(phba);
  521. break;
  522. }
  523. if (free_evt)
  524. kfree(evtp);
  525. spin_lock_irq(&phba->hbalock);
  526. }
  527. spin_unlock_irq(&phba->hbalock);
  528. }
  529. static void
  530. lpfc_work_done(struct lpfc_hba *phba)
  531. {
  532. struct lpfc_sli_ring *pring;
  533. uint32_t ha_copy, status, control, work_port_events;
  534. struct lpfc_vport **vports;
  535. struct lpfc_vport *vport;
  536. int i;
  537. spin_lock_irq(&phba->hbalock);
  538. ha_copy = phba->work_ha;
  539. phba->work_ha = 0;
  540. spin_unlock_irq(&phba->hbalock);
  541. /* First, try to post the next mailbox command to SLI4 device */
  542. if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
  543. lpfc_sli4_post_async_mbox(phba);
  544. if (ha_copy & HA_ERATT)
  545. /* Handle the error attention event */
  546. lpfc_handle_eratt(phba);
  547. if (ha_copy & HA_MBATT)
  548. lpfc_sli_handle_mb_event(phba);
  549. if (ha_copy & HA_LATT)
  550. lpfc_handle_latt(phba);
  551. /* Process SLI4 events */
  552. if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
  553. if (phba->hba_flag & HBA_RRQ_ACTIVE)
  554. lpfc_handle_rrq_active(phba);
  555. if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
  556. lpfc_sli4_fcp_xri_abort_event_proc(phba);
  557. if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
  558. lpfc_sli4_els_xri_abort_event_proc(phba);
  559. if (phba->hba_flag & ASYNC_EVENT)
  560. lpfc_sli4_async_event_proc(phba);
  561. if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
  562. spin_lock_irq(&phba->hbalock);
  563. phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
  564. spin_unlock_irq(&phba->hbalock);
  565. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  566. }
  567. if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
  568. lpfc_sli4_fcf_redisc_event_proc(phba);
  569. }
  570. vports = lpfc_create_vport_work_array(phba);
  571. if (vports != NULL)
  572. for (i = 0; i <= phba->max_vports; i++) {
  573. /*
  574. * We could have no vports in array if unloading, so if
  575. * this happens then just use the pport
  576. */
  577. if (vports[i] == NULL && i == 0)
  578. vport = phba->pport;
  579. else
  580. vport = vports[i];
  581. if (vport == NULL)
  582. break;
  583. spin_lock_irq(&vport->work_port_lock);
  584. work_port_events = vport->work_port_events;
  585. vport->work_port_events &= ~work_port_events;
  586. spin_unlock_irq(&vport->work_port_lock);
  587. if (work_port_events & WORKER_DISC_TMO)
  588. lpfc_disc_timeout_handler(vport);
  589. if (work_port_events & WORKER_ELS_TMO)
  590. lpfc_els_timeout_handler(vport);
  591. if (work_port_events & WORKER_HB_TMO)
  592. lpfc_hb_timeout_handler(phba);
  593. if (work_port_events & WORKER_MBOX_TMO)
  594. lpfc_mbox_timeout_handler(phba);
  595. if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
  596. lpfc_unblock_fabric_iocbs(phba);
  597. if (work_port_events & WORKER_FDMI_TMO)
  598. lpfc_fdmi_timeout_handler(vport);
  599. if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
  600. lpfc_ramp_down_queue_handler(phba);
  601. if (work_port_events & WORKER_RAMP_UP_QUEUE)
  602. lpfc_ramp_up_queue_handler(phba);
  603. if (work_port_events & WORKER_DELAYED_DISC_TMO)
  604. lpfc_delayed_disc_timeout_handler(vport);
  605. }
  606. lpfc_destroy_vport_work_array(phba, vports);
  607. pring = &phba->sli.ring[LPFC_ELS_RING];
  608. status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  609. status >>= (4*LPFC_ELS_RING);
  610. if ((status & HA_RXMASK) ||
  611. (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
  612. (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
  613. if (pring->flag & LPFC_STOP_IOCB_EVENT) {
  614. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  615. /* Set the lpfc data pending flag */
  616. set_bit(LPFC_DATA_READY, &phba->data_flags);
  617. } else {
  618. pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
  619. lpfc_sli_handle_slow_ring_event(phba, pring,
  620. (status &
  621. HA_RXMASK));
  622. }
  623. if ((phba->sli_rev == LPFC_SLI_REV4) && pring->txq_cnt)
  624. lpfc_drain_txq(phba);
  625. /*
  626. * Turn on Ring interrupts
  627. */
  628. if (phba->sli_rev <= LPFC_SLI_REV3) {
  629. spin_lock_irq(&phba->hbalock);
  630. control = readl(phba->HCregaddr);
  631. if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
  632. lpfc_debugfs_slow_ring_trc(phba,
  633. "WRK Enable ring: cntl:x%x hacopy:x%x",
  634. control, ha_copy, 0);
  635. control |= (HC_R0INT_ENA << LPFC_ELS_RING);
  636. writel(control, phba->HCregaddr);
  637. readl(phba->HCregaddr); /* flush */
  638. } else {
  639. lpfc_debugfs_slow_ring_trc(phba,
  640. "WRK Ring ok: cntl:x%x hacopy:x%x",
  641. control, ha_copy, 0);
  642. }
  643. spin_unlock_irq(&phba->hbalock);
  644. }
  645. }
  646. lpfc_work_list_done(phba);
  647. }
  648. int
  649. lpfc_do_work(void *p)
  650. {
  651. struct lpfc_hba *phba = p;
  652. int rc;
  653. set_user_nice(current, -20);
  654. phba->data_flags = 0;
  655. while (!kthread_should_stop()) {
  656. /* wait and check worker queue activities */
  657. rc = wait_event_interruptible(phba->work_waitq,
  658. (test_and_clear_bit(LPFC_DATA_READY,
  659. &phba->data_flags)
  660. || kthread_should_stop()));
  661. /* Signal wakeup shall terminate the worker thread */
  662. if (rc) {
  663. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  664. "0433 Wakeup on signal: rc=x%x\n", rc);
  665. break;
  666. }
  667. /* Attend pending lpfc data processing */
  668. lpfc_work_done(phba);
  669. }
  670. phba->worker_thread = NULL;
  671. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  672. "0432 Worker thread stopped.\n");
  673. return 0;
  674. }
  675. /*
  676. * This is only called to handle FC worker events. Since this a rare
  677. * occurrence, we allocate a struct lpfc_work_evt structure here instead of
  678. * embedding it in the IOCB.
  679. */
  680. int
  681. lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
  682. uint32_t evt)
  683. {
  684. struct lpfc_work_evt *evtp;
  685. unsigned long flags;
  686. /*
  687. * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
  688. * be queued to worker thread for processing
  689. */
  690. evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
  691. if (!evtp)
  692. return 0;
  693. evtp->evt_arg1 = arg1;
  694. evtp->evt_arg2 = arg2;
  695. evtp->evt = evt;
  696. spin_lock_irqsave(&phba->hbalock, flags);
  697. list_add_tail(&evtp->evt_listp, &phba->work_list);
  698. spin_unlock_irqrestore(&phba->hbalock, flags);
  699. lpfc_worker_wake_up(phba);
  700. return 1;
  701. }
  702. void
  703. lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
  704. {
  705. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  706. struct lpfc_hba *phba = vport->phba;
  707. struct lpfc_nodelist *ndlp, *next_ndlp;
  708. int rc;
  709. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  710. if (!NLP_CHK_NODE_ACT(ndlp))
  711. continue;
  712. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  713. continue;
  714. if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
  715. ((vport->port_type == LPFC_NPIV_PORT) &&
  716. (ndlp->nlp_DID == NameServer_DID)))
  717. lpfc_unreg_rpi(vport, ndlp);
  718. /* Leave Fabric nodes alone on link down */
  719. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  720. (!remove && ndlp->nlp_type & NLP_FABRIC))
  721. continue;
  722. rc = lpfc_disc_state_machine(vport, ndlp, NULL,
  723. remove
  724. ? NLP_EVT_DEVICE_RM
  725. : NLP_EVT_DEVICE_RECOVERY);
  726. }
  727. if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
  728. if (phba->sli_rev == LPFC_SLI_REV4)
  729. lpfc_sli4_unreg_all_rpis(vport);
  730. lpfc_mbx_unreg_vpi(vport);
  731. spin_lock_irq(shost->host_lock);
  732. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  733. spin_unlock_irq(shost->host_lock);
  734. }
  735. }
  736. void
  737. lpfc_port_link_failure(struct lpfc_vport *vport)
  738. {
  739. lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
  740. /* Cleanup any outstanding received buffers */
  741. lpfc_cleanup_rcv_buffers(vport);
  742. /* Cleanup any outstanding RSCN activity */
  743. lpfc_els_flush_rscn(vport);
  744. /* Cleanup any outstanding ELS commands */
  745. lpfc_els_flush_cmd(vport);
  746. lpfc_cleanup_rpis(vport, 0);
  747. /* Turn off discovery timer if its running */
  748. lpfc_can_disctmo(vport);
  749. }
  750. void
  751. lpfc_linkdown_port(struct lpfc_vport *vport)
  752. {
  753. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  754. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
  755. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  756. "Link Down: state:x%x rtry:x%x flg:x%x",
  757. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  758. lpfc_port_link_failure(vport);
  759. /* Stop delayed Nport discovery */
  760. spin_lock_irq(shost->host_lock);
  761. vport->fc_flag &= ~FC_DISC_DELAYED;
  762. spin_unlock_irq(shost->host_lock);
  763. del_timer_sync(&vport->delayed_disc_tmo);
  764. }
  765. int
  766. lpfc_linkdown(struct lpfc_hba *phba)
  767. {
  768. struct lpfc_vport *vport = phba->pport;
  769. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  770. struct lpfc_vport **vports;
  771. LPFC_MBOXQ_t *mb;
  772. int i;
  773. if (phba->link_state == LPFC_LINK_DOWN)
  774. return 0;
  775. /* Block all SCSI stack I/Os */
  776. lpfc_scsi_dev_block(phba);
  777. spin_lock_irq(&phba->hbalock);
  778. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
  779. spin_unlock_irq(&phba->hbalock);
  780. if (phba->link_state > LPFC_LINK_DOWN) {
  781. phba->link_state = LPFC_LINK_DOWN;
  782. spin_lock_irq(shost->host_lock);
  783. phba->pport->fc_flag &= ~FC_LBIT;
  784. spin_unlock_irq(shost->host_lock);
  785. }
  786. vports = lpfc_create_vport_work_array(phba);
  787. if (vports != NULL)
  788. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  789. /* Issue a LINK DOWN event to all nodes */
  790. lpfc_linkdown_port(vports[i]);
  791. }
  792. lpfc_destroy_vport_work_array(phba, vports);
  793. /* Clean up any firmware default rpi's */
  794. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  795. if (mb) {
  796. lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
  797. mb->vport = vport;
  798. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  799. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  800. == MBX_NOT_FINISHED) {
  801. mempool_free(mb, phba->mbox_mem_pool);
  802. }
  803. }
  804. /* Setup myDID for link up if we are in pt2pt mode */
  805. if (phba->pport->fc_flag & FC_PT2PT) {
  806. phba->pport->fc_myDID = 0;
  807. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  808. if (mb) {
  809. lpfc_config_link(phba, mb);
  810. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  811. mb->vport = vport;
  812. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  813. == MBX_NOT_FINISHED) {
  814. mempool_free(mb, phba->mbox_mem_pool);
  815. }
  816. }
  817. spin_lock_irq(shost->host_lock);
  818. phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
  819. spin_unlock_irq(shost->host_lock);
  820. }
  821. return 0;
  822. }
  823. static void
  824. lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
  825. {
  826. struct lpfc_nodelist *ndlp;
  827. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  828. if (!NLP_CHK_NODE_ACT(ndlp))
  829. continue;
  830. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  831. continue;
  832. if (ndlp->nlp_type & NLP_FABRIC) {
  833. /* On Linkup its safe to clean up the ndlp
  834. * from Fabric connections.
  835. */
  836. if (ndlp->nlp_DID != Fabric_DID)
  837. lpfc_unreg_rpi(vport, ndlp);
  838. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  839. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  840. /* Fail outstanding IO now since device is
  841. * marked for PLOGI.
  842. */
  843. lpfc_unreg_rpi(vport, ndlp);
  844. }
  845. }
  846. }
  847. static void
  848. lpfc_linkup_port(struct lpfc_vport *vport)
  849. {
  850. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  851. struct lpfc_hba *phba = vport->phba;
  852. if ((vport->load_flag & FC_UNLOADING) != 0)
  853. return;
  854. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  855. "Link Up: top:x%x speed:x%x flg:x%x",
  856. phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
  857. /* If NPIV is not enabled, only bring the physical port up */
  858. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  859. (vport != phba->pport))
  860. return;
  861. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
  862. spin_lock_irq(shost->host_lock);
  863. vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
  864. FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
  865. vport->fc_flag |= FC_NDISC_ACTIVE;
  866. vport->fc_ns_retry = 0;
  867. spin_unlock_irq(shost->host_lock);
  868. if (vport->fc_flag & FC_LBIT)
  869. lpfc_linkup_cleanup_nodes(vport);
  870. }
  871. static int
  872. lpfc_linkup(struct lpfc_hba *phba)
  873. {
  874. struct lpfc_vport **vports;
  875. int i;
  876. lpfc_cleanup_wt_rrqs(phba);
  877. phba->link_state = LPFC_LINK_UP;
  878. /* Unblock fabric iocbs if they are blocked */
  879. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  880. del_timer_sync(&phba->fabric_block_timer);
  881. vports = lpfc_create_vport_work_array(phba);
  882. if (vports != NULL)
  883. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  884. lpfc_linkup_port(vports[i]);
  885. lpfc_destroy_vport_work_array(phba, vports);
  886. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  887. (phba->sli_rev < LPFC_SLI_REV4))
  888. lpfc_issue_clear_la(phba, phba->pport);
  889. return 0;
  890. }
  891. /*
  892. * This routine handles processing a CLEAR_LA mailbox
  893. * command upon completion. It is setup in the LPFC_MBOXQ
  894. * as the completion routine when the command is
  895. * handed off to the SLI layer.
  896. */
  897. static void
  898. lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  899. {
  900. struct lpfc_vport *vport = pmb->vport;
  901. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  902. struct lpfc_sli *psli = &phba->sli;
  903. MAILBOX_t *mb = &pmb->u.mb;
  904. uint32_t control;
  905. /* Since we don't do discovery right now, turn these off here */
  906. psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  907. psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  908. psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  909. /* Check for error */
  910. if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
  911. /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
  912. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  913. "0320 CLEAR_LA mbxStatus error x%x hba "
  914. "state x%x\n",
  915. mb->mbxStatus, vport->port_state);
  916. phba->link_state = LPFC_HBA_ERROR;
  917. goto out;
  918. }
  919. if (vport->port_type == LPFC_PHYSICAL_PORT)
  920. phba->link_state = LPFC_HBA_READY;
  921. spin_lock_irq(&phba->hbalock);
  922. psli->sli_flag |= LPFC_PROCESS_LA;
  923. control = readl(phba->HCregaddr);
  924. control |= HC_LAINT_ENA;
  925. writel(control, phba->HCregaddr);
  926. readl(phba->HCregaddr); /* flush */
  927. spin_unlock_irq(&phba->hbalock);
  928. mempool_free(pmb, phba->mbox_mem_pool);
  929. return;
  930. out:
  931. /* Device Discovery completes */
  932. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  933. "0225 Device Discovery completes\n");
  934. mempool_free(pmb, phba->mbox_mem_pool);
  935. spin_lock_irq(shost->host_lock);
  936. vport->fc_flag &= ~FC_ABORT_DISCOVERY;
  937. spin_unlock_irq(shost->host_lock);
  938. lpfc_can_disctmo(vport);
  939. /* turn on Link Attention interrupts */
  940. spin_lock_irq(&phba->hbalock);
  941. psli->sli_flag |= LPFC_PROCESS_LA;
  942. control = readl(phba->HCregaddr);
  943. control |= HC_LAINT_ENA;
  944. writel(control, phba->HCregaddr);
  945. readl(phba->HCregaddr); /* flush */
  946. spin_unlock_irq(&phba->hbalock);
  947. return;
  948. }
  949. static void
  950. lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  951. {
  952. struct lpfc_vport *vport = pmb->vport;
  953. if (pmb->u.mb.mbxStatus)
  954. goto out;
  955. mempool_free(pmb, phba->mbox_mem_pool);
  956. /* don't perform discovery for SLI4 loopback diagnostic test */
  957. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  958. !(phba->hba_flag & HBA_FCOE_MODE) &&
  959. (phba->link_flag & LS_LOOPBACK_MODE))
  960. return;
  961. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
  962. vport->fc_flag & FC_PUBLIC_LOOP &&
  963. !(vport->fc_flag & FC_LBIT)) {
  964. /* Need to wait for FAN - use discovery timer
  965. * for timeout. port_state is identically
  966. * LPFC_LOCAL_CFG_LINK while waiting for FAN
  967. */
  968. lpfc_set_disctmo(vport);
  969. return;
  970. }
  971. /* Start discovery by sending a FLOGI. port_state is identically
  972. * LPFC_FLOGI while waiting for FLOGI cmpl
  973. */
  974. if (vport->port_state != LPFC_FLOGI)
  975. lpfc_initial_flogi(vport);
  976. return;
  977. out:
  978. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  979. "0306 CONFIG_LINK mbxStatus error x%x "
  980. "HBA state x%x\n",
  981. pmb->u.mb.mbxStatus, vport->port_state);
  982. mempool_free(pmb, phba->mbox_mem_pool);
  983. lpfc_linkdown(phba);
  984. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  985. "0200 CONFIG_LINK bad hba state x%x\n",
  986. vport->port_state);
  987. lpfc_issue_clear_la(phba, vport);
  988. return;
  989. }
  990. /**
  991. * lpfc_sli4_clear_fcf_rr_bmask
  992. * @phba pointer to the struct lpfc_hba for this port.
  993. * This fucnction resets the round robin bit mask and clears the
  994. * fcf priority list. The list deletions are done while holding the
  995. * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
  996. * from the lpfc_fcf_pri record.
  997. **/
  998. void
  999. lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
  1000. {
  1001. struct lpfc_fcf_pri *fcf_pri;
  1002. struct lpfc_fcf_pri *next_fcf_pri;
  1003. memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
  1004. spin_lock_irq(&phba->hbalock);
  1005. list_for_each_entry_safe(fcf_pri, next_fcf_pri,
  1006. &phba->fcf.fcf_pri_list, list) {
  1007. list_del_init(&fcf_pri->list);
  1008. fcf_pri->fcf_rec.flag = 0;
  1009. }
  1010. spin_unlock_irq(&phba->hbalock);
  1011. }
  1012. static void
  1013. lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1014. {
  1015. struct lpfc_vport *vport = mboxq->vport;
  1016. if (mboxq->u.mb.mbxStatus) {
  1017. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1018. "2017 REG_FCFI mbxStatus error x%x "
  1019. "HBA state x%x\n",
  1020. mboxq->u.mb.mbxStatus, vport->port_state);
  1021. goto fail_out;
  1022. }
  1023. /* Start FCoE discovery by sending a FLOGI. */
  1024. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
  1025. /* Set the FCFI registered flag */
  1026. spin_lock_irq(&phba->hbalock);
  1027. phba->fcf.fcf_flag |= FCF_REGISTERED;
  1028. spin_unlock_irq(&phba->hbalock);
  1029. /* If there is a pending FCoE event, restart FCF table scan. */
  1030. if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
  1031. lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
  1032. goto fail_out;
  1033. /* Mark successful completion of FCF table scan */
  1034. spin_lock_irq(&phba->hbalock);
  1035. phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
  1036. phba->hba_flag &= ~FCF_TS_INPROG;
  1037. if (vport->port_state != LPFC_FLOGI) {
  1038. phba->hba_flag |= FCF_RR_INPROG;
  1039. spin_unlock_irq(&phba->hbalock);
  1040. lpfc_issue_init_vfi(vport);
  1041. goto out;
  1042. }
  1043. spin_unlock_irq(&phba->hbalock);
  1044. goto out;
  1045. fail_out:
  1046. spin_lock_irq(&phba->hbalock);
  1047. phba->hba_flag &= ~FCF_RR_INPROG;
  1048. spin_unlock_irq(&phba->hbalock);
  1049. out:
  1050. mempool_free(mboxq, phba->mbox_mem_pool);
  1051. }
  1052. /**
  1053. * lpfc_fab_name_match - Check if the fcf fabric name match.
  1054. * @fab_name: pointer to fabric name.
  1055. * @new_fcf_record: pointer to fcf record.
  1056. *
  1057. * This routine compare the fcf record's fabric name with provided
  1058. * fabric name. If the fabric name are identical this function
  1059. * returns 1 else return 0.
  1060. **/
  1061. static uint32_t
  1062. lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
  1063. {
  1064. if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
  1065. return 0;
  1066. if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
  1067. return 0;
  1068. if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
  1069. return 0;
  1070. if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
  1071. return 0;
  1072. if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
  1073. return 0;
  1074. if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
  1075. return 0;
  1076. if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
  1077. return 0;
  1078. if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
  1079. return 0;
  1080. return 1;
  1081. }
  1082. /**
  1083. * lpfc_sw_name_match - Check if the fcf switch name match.
  1084. * @fab_name: pointer to fabric name.
  1085. * @new_fcf_record: pointer to fcf record.
  1086. *
  1087. * This routine compare the fcf record's switch name with provided
  1088. * switch name. If the switch name are identical this function
  1089. * returns 1 else return 0.
  1090. **/
  1091. static uint32_t
  1092. lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
  1093. {
  1094. if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
  1095. return 0;
  1096. if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
  1097. return 0;
  1098. if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
  1099. return 0;
  1100. if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
  1101. return 0;
  1102. if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
  1103. return 0;
  1104. if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
  1105. return 0;
  1106. if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
  1107. return 0;
  1108. if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
  1109. return 0;
  1110. return 1;
  1111. }
  1112. /**
  1113. * lpfc_mac_addr_match - Check if the fcf mac address match.
  1114. * @mac_addr: pointer to mac address.
  1115. * @new_fcf_record: pointer to fcf record.
  1116. *
  1117. * This routine compare the fcf record's mac address with HBA's
  1118. * FCF mac address. If the mac addresses are identical this function
  1119. * returns 1 else return 0.
  1120. **/
  1121. static uint32_t
  1122. lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
  1123. {
  1124. if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
  1125. return 0;
  1126. if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
  1127. return 0;
  1128. if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
  1129. return 0;
  1130. if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
  1131. return 0;
  1132. if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
  1133. return 0;
  1134. if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
  1135. return 0;
  1136. return 1;
  1137. }
  1138. static bool
  1139. lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
  1140. {
  1141. return (curr_vlan_id == new_vlan_id);
  1142. }
  1143. /**
  1144. * lpfc_update_fcf_record - Update driver fcf record
  1145. * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
  1146. * @phba: pointer to lpfc hba data structure.
  1147. * @fcf_index: Index for the lpfc_fcf_record.
  1148. * @new_fcf_record: pointer to hba fcf record.
  1149. *
  1150. * This routine updates the driver FCF priority record from the new HBA FCF
  1151. * record. This routine is called with the host lock held.
  1152. **/
  1153. static void
  1154. __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
  1155. struct fcf_record *new_fcf_record
  1156. )
  1157. {
  1158. struct lpfc_fcf_pri *fcf_pri;
  1159. fcf_pri = &phba->fcf.fcf_pri[fcf_index];
  1160. fcf_pri->fcf_rec.fcf_index = fcf_index;
  1161. /* FCF record priority */
  1162. fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
  1163. }
  1164. /**
  1165. * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
  1166. * @fcf: pointer to driver fcf record.
  1167. * @new_fcf_record: pointer to fcf record.
  1168. *
  1169. * This routine copies the FCF information from the FCF
  1170. * record to lpfc_hba data structure.
  1171. **/
  1172. static void
  1173. lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
  1174. struct fcf_record *new_fcf_record)
  1175. {
  1176. /* Fabric name */
  1177. fcf_rec->fabric_name[0] =
  1178. bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
  1179. fcf_rec->fabric_name[1] =
  1180. bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
  1181. fcf_rec->fabric_name[2] =
  1182. bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
  1183. fcf_rec->fabric_name[3] =
  1184. bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
  1185. fcf_rec->fabric_name[4] =
  1186. bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
  1187. fcf_rec->fabric_name[5] =
  1188. bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
  1189. fcf_rec->fabric_name[6] =
  1190. bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
  1191. fcf_rec->fabric_name[7] =
  1192. bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
  1193. /* Mac address */
  1194. fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
  1195. fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
  1196. fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
  1197. fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
  1198. fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
  1199. fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
  1200. /* FCF record index */
  1201. fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  1202. /* FCF record priority */
  1203. fcf_rec->priority = new_fcf_record->fip_priority;
  1204. /* Switch name */
  1205. fcf_rec->switch_name[0] =
  1206. bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
  1207. fcf_rec->switch_name[1] =
  1208. bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
  1209. fcf_rec->switch_name[2] =
  1210. bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
  1211. fcf_rec->switch_name[3] =
  1212. bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
  1213. fcf_rec->switch_name[4] =
  1214. bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
  1215. fcf_rec->switch_name[5] =
  1216. bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
  1217. fcf_rec->switch_name[6] =
  1218. bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
  1219. fcf_rec->switch_name[7] =
  1220. bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
  1221. }
  1222. /**
  1223. * lpfc_update_fcf_record - Update driver fcf record
  1224. * @phba: pointer to lpfc hba data structure.
  1225. * @fcf_rec: pointer to driver fcf record.
  1226. * @new_fcf_record: pointer to hba fcf record.
  1227. * @addr_mode: address mode to be set to the driver fcf record.
  1228. * @vlan_id: vlan tag to be set to the driver fcf record.
  1229. * @flag: flag bits to be set to the driver fcf record.
  1230. *
  1231. * This routine updates the driver FCF record from the new HBA FCF record
  1232. * together with the address mode, vlan_id, and other informations. This
  1233. * routine is called with the host lock held.
  1234. **/
  1235. static void
  1236. __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
  1237. struct fcf_record *new_fcf_record, uint32_t addr_mode,
  1238. uint16_t vlan_id, uint32_t flag)
  1239. {
  1240. /* Copy the fields from the HBA's FCF record */
  1241. lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
  1242. /* Update other fields of driver FCF record */
  1243. fcf_rec->addr_mode = addr_mode;
  1244. fcf_rec->vlan_id = vlan_id;
  1245. fcf_rec->flag |= (flag | RECORD_VALID);
  1246. __lpfc_update_fcf_record_pri(phba,
  1247. bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
  1248. new_fcf_record);
  1249. }
  1250. /**
  1251. * lpfc_register_fcf - Register the FCF with hba.
  1252. * @phba: pointer to lpfc hba data structure.
  1253. *
  1254. * This routine issues a register fcfi mailbox command to register
  1255. * the fcf with HBA.
  1256. **/
  1257. static void
  1258. lpfc_register_fcf(struct lpfc_hba *phba)
  1259. {
  1260. LPFC_MBOXQ_t *fcf_mbxq;
  1261. int rc;
  1262. spin_lock_irq(&phba->hbalock);
  1263. /* If the FCF is not available do nothing. */
  1264. if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
  1265. phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
  1266. spin_unlock_irq(&phba->hbalock);
  1267. return;
  1268. }
  1269. /* The FCF is already registered, start discovery */
  1270. if (phba->fcf.fcf_flag & FCF_REGISTERED) {
  1271. phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
  1272. phba->hba_flag &= ~FCF_TS_INPROG;
  1273. if (phba->pport->port_state != LPFC_FLOGI) {
  1274. phba->hba_flag |= FCF_RR_INPROG;
  1275. spin_unlock_irq(&phba->hbalock);
  1276. lpfc_initial_flogi(phba->pport);
  1277. return;
  1278. }
  1279. spin_unlock_irq(&phba->hbalock);
  1280. return;
  1281. }
  1282. spin_unlock_irq(&phba->hbalock);
  1283. fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1284. if (!fcf_mbxq) {
  1285. spin_lock_irq(&phba->hbalock);
  1286. phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
  1287. spin_unlock_irq(&phba->hbalock);
  1288. return;
  1289. }
  1290. lpfc_reg_fcfi(phba, fcf_mbxq);
  1291. fcf_mbxq->vport = phba->pport;
  1292. fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
  1293. rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
  1294. if (rc == MBX_NOT_FINISHED) {
  1295. spin_lock_irq(&phba->hbalock);
  1296. phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
  1297. spin_unlock_irq(&phba->hbalock);
  1298. mempool_free(fcf_mbxq, phba->mbox_mem_pool);
  1299. }
  1300. return;
  1301. }
  1302. /**
  1303. * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
  1304. * @phba: pointer to lpfc hba data structure.
  1305. * @new_fcf_record: pointer to fcf record.
  1306. * @boot_flag: Indicates if this record used by boot bios.
  1307. * @addr_mode: The address mode to be used by this FCF
  1308. * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
  1309. *
  1310. * This routine compare the fcf record with connect list obtained from the
  1311. * config region to decide if this FCF can be used for SAN discovery. It returns
  1312. * 1 if this record can be used for SAN discovery else return zero. If this FCF
  1313. * record can be used for SAN discovery, the boot_flag will indicate if this FCF
  1314. * is used by boot bios and addr_mode will indicate the addressing mode to be
  1315. * used for this FCF when the function returns.
  1316. * If the FCF record need to be used with a particular vlan id, the vlan is
  1317. * set in the vlan_id on return of the function. If not VLAN tagging need to
  1318. * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
  1319. **/
  1320. static int
  1321. lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
  1322. struct fcf_record *new_fcf_record,
  1323. uint32_t *boot_flag, uint32_t *addr_mode,
  1324. uint16_t *vlan_id)
  1325. {
  1326. struct lpfc_fcf_conn_entry *conn_entry;
  1327. int i, j, fcf_vlan_id = 0;
  1328. /* Find the lowest VLAN id in the FCF record */
  1329. for (i = 0; i < 512; i++) {
  1330. if (new_fcf_record->vlan_bitmap[i]) {
  1331. fcf_vlan_id = i * 8;
  1332. j = 0;
  1333. while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
  1334. j++;
  1335. fcf_vlan_id++;
  1336. }
  1337. break;
  1338. }
  1339. }
  1340. /* If FCF not available return 0 */
  1341. if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
  1342. !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record))
  1343. return 0;
  1344. if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
  1345. *boot_flag = 0;
  1346. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1347. new_fcf_record);
  1348. if (phba->valid_vlan)
  1349. *vlan_id = phba->vlan_id;
  1350. else
  1351. *vlan_id = LPFC_FCOE_NULL_VID;
  1352. return 1;
  1353. }
  1354. /*
  1355. * If there are no FCF connection table entry, driver connect to all
  1356. * FCFs.
  1357. */
  1358. if (list_empty(&phba->fcf_conn_rec_list)) {
  1359. *boot_flag = 0;
  1360. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1361. new_fcf_record);
  1362. /*
  1363. * When there are no FCF connect entries, use driver's default
  1364. * addressing mode - FPMA.
  1365. */
  1366. if (*addr_mode & LPFC_FCF_FPMA)
  1367. *addr_mode = LPFC_FCF_FPMA;
  1368. /* If FCF record report a vlan id use that vlan id */
  1369. if (fcf_vlan_id)
  1370. *vlan_id = fcf_vlan_id;
  1371. else
  1372. *vlan_id = LPFC_FCOE_NULL_VID;
  1373. return 1;
  1374. }
  1375. list_for_each_entry(conn_entry,
  1376. &phba->fcf_conn_rec_list, list) {
  1377. if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
  1378. continue;
  1379. if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
  1380. !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
  1381. new_fcf_record))
  1382. continue;
  1383. if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
  1384. !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
  1385. new_fcf_record))
  1386. continue;
  1387. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
  1388. /*
  1389. * If the vlan bit map does not have the bit set for the
  1390. * vlan id to be used, then it is not a match.
  1391. */
  1392. if (!(new_fcf_record->vlan_bitmap
  1393. [conn_entry->conn_rec.vlan_tag / 8] &
  1394. (1 << (conn_entry->conn_rec.vlan_tag % 8))))
  1395. continue;
  1396. }
  1397. /*
  1398. * If connection record does not support any addressing mode,
  1399. * skip the FCF record.
  1400. */
  1401. if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
  1402. & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
  1403. continue;
  1404. /*
  1405. * Check if the connection record specifies a required
  1406. * addressing mode.
  1407. */
  1408. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1409. !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
  1410. /*
  1411. * If SPMA required but FCF not support this continue.
  1412. */
  1413. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1414. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1415. new_fcf_record) & LPFC_FCF_SPMA))
  1416. continue;
  1417. /*
  1418. * If FPMA required but FCF not support this continue.
  1419. */
  1420. if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1421. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1422. new_fcf_record) & LPFC_FCF_FPMA))
  1423. continue;
  1424. }
  1425. /*
  1426. * This fcf record matches filtering criteria.
  1427. */
  1428. if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
  1429. *boot_flag = 1;
  1430. else
  1431. *boot_flag = 0;
  1432. /*
  1433. * If user did not specify any addressing mode, or if the
  1434. * preferred addressing mode specified by user is not supported
  1435. * by FCF, allow fabric to pick the addressing mode.
  1436. */
  1437. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1438. new_fcf_record);
  1439. /*
  1440. * If the user specified a required address mode, assign that
  1441. * address mode
  1442. */
  1443. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1444. (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
  1445. *addr_mode = (conn_entry->conn_rec.flags &
  1446. FCFCNCT_AM_SPMA) ?
  1447. LPFC_FCF_SPMA : LPFC_FCF_FPMA;
  1448. /*
  1449. * If the user specified a preferred address mode, use the
  1450. * addr mode only if FCF support the addr_mode.
  1451. */
  1452. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1453. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1454. (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1455. (*addr_mode & LPFC_FCF_SPMA))
  1456. *addr_mode = LPFC_FCF_SPMA;
  1457. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1458. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1459. !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1460. (*addr_mode & LPFC_FCF_FPMA))
  1461. *addr_mode = LPFC_FCF_FPMA;
  1462. /* If matching connect list has a vlan id, use it */
  1463. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
  1464. *vlan_id = conn_entry->conn_rec.vlan_tag;
  1465. /*
  1466. * If no vlan id is specified in connect list, use the vlan id
  1467. * in the FCF record
  1468. */
  1469. else if (fcf_vlan_id)
  1470. *vlan_id = fcf_vlan_id;
  1471. else
  1472. *vlan_id = LPFC_FCOE_NULL_VID;
  1473. return 1;
  1474. }
  1475. return 0;
  1476. }
  1477. /**
  1478. * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
  1479. * @phba: pointer to lpfc hba data structure.
  1480. * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
  1481. *
  1482. * This function check if there is any fcoe event pending while driver
  1483. * scan FCF entries. If there is any pending event, it will restart the
  1484. * FCF saning and return 1 else return 0.
  1485. */
  1486. int
  1487. lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
  1488. {
  1489. /*
  1490. * If the Link is up and no FCoE events while in the
  1491. * FCF discovery, no need to restart FCF discovery.
  1492. */
  1493. if ((phba->link_state >= LPFC_LINK_UP) &&
  1494. (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
  1495. return 0;
  1496. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1497. "2768 Pending link or FCF event during current "
  1498. "handling of the previous event: link_state:x%x, "
  1499. "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
  1500. phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
  1501. phba->fcoe_eventtag);
  1502. spin_lock_irq(&phba->hbalock);
  1503. phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
  1504. spin_unlock_irq(&phba->hbalock);
  1505. if (phba->link_state >= LPFC_LINK_UP) {
  1506. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  1507. "2780 Restart FCF table scan due to "
  1508. "pending FCF event:evt_tag_at_scan:x%x, "
  1509. "evt_tag_current:x%x\n",
  1510. phba->fcoe_eventtag_at_fcf_scan,
  1511. phba->fcoe_eventtag);
  1512. lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  1513. } else {
  1514. /*
  1515. * Do not continue FCF discovery and clear FCF_TS_INPROG
  1516. * flag
  1517. */
  1518. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  1519. "2833 Stop FCF discovery process due to link "
  1520. "state change (x%x)\n", phba->link_state);
  1521. spin_lock_irq(&phba->hbalock);
  1522. phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
  1523. phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
  1524. spin_unlock_irq(&phba->hbalock);
  1525. }
  1526. /* Unregister the currently registered FCF if required */
  1527. if (unreg_fcf) {
  1528. spin_lock_irq(&phba->hbalock);
  1529. phba->fcf.fcf_flag &= ~FCF_REGISTERED;
  1530. spin_unlock_irq(&phba->hbalock);
  1531. lpfc_sli4_unregister_fcf(phba);
  1532. }
  1533. return 1;
  1534. }
  1535. /**
  1536. * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
  1537. * @phba: pointer to lpfc hba data structure.
  1538. * @fcf_cnt: number of eligible fcf record seen so far.
  1539. *
  1540. * This function makes an running random selection decision on FCF record to
  1541. * use through a sequence of @fcf_cnt eligible FCF records with equal
  1542. * probability. To perform integer manunipulation of random numbers with
  1543. * size unit32_t, the lower 16 bits of the 32-bit random number returned
  1544. * from random32() are taken as the random random number generated.
  1545. *
  1546. * Returns true when outcome is for the newly read FCF record should be
  1547. * chosen; otherwise, return false when outcome is for keeping the previously
  1548. * chosen FCF record.
  1549. **/
  1550. static bool
  1551. lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
  1552. {
  1553. uint32_t rand_num;
  1554. /* Get 16-bit uniform random number */
  1555. rand_num = (0xFFFF & random32());
  1556. /* Decision with probability 1/fcf_cnt */
  1557. if ((fcf_cnt * rand_num) < 0xFFFF)
  1558. return true;
  1559. else
  1560. return false;
  1561. }
  1562. /**
  1563. * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
  1564. * @phba: pointer to lpfc hba data structure.
  1565. * @mboxq: pointer to mailbox object.
  1566. * @next_fcf_index: pointer to holder of next fcf index.
  1567. *
  1568. * This routine parses the non-embedded fcf mailbox command by performing the
  1569. * necessarily error checking, non-embedded read FCF record mailbox command
  1570. * SGE parsing, and endianness swapping.
  1571. *
  1572. * Returns the pointer to the new FCF record in the non-embedded mailbox
  1573. * command DMA memory if successfully, other NULL.
  1574. */
  1575. static struct fcf_record *
  1576. lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  1577. uint16_t *next_fcf_index)
  1578. {
  1579. void *virt_addr;
  1580. dma_addr_t phys_addr;
  1581. struct lpfc_mbx_sge sge;
  1582. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  1583. uint32_t shdr_status, shdr_add_status;
  1584. union lpfc_sli4_cfg_shdr *shdr;
  1585. struct fcf_record *new_fcf_record;
  1586. /* Get the first SGE entry from the non-embedded DMA memory. This
  1587. * routine only uses a single SGE.
  1588. */
  1589. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  1590. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  1591. if (unlikely(!mboxq->sge_array)) {
  1592. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1593. "2524 Failed to get the non-embedded SGE "
  1594. "virtual address\n");
  1595. return NULL;
  1596. }
  1597. virt_addr = mboxq->sge_array->addr[0];
  1598. shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
  1599. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  1600. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  1601. if (shdr_status || shdr_add_status) {
  1602. if (shdr_status == STATUS_FCF_TABLE_EMPTY)
  1603. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1604. "2726 READ_FCF_RECORD Indicates empty "
  1605. "FCF table.\n");
  1606. else
  1607. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1608. "2521 READ_FCF_RECORD mailbox failed "
  1609. "with status x%x add_status x%x, "
  1610. "mbx\n", shdr_status, shdr_add_status);
  1611. return NULL;
  1612. }
  1613. /* Interpreting the returned information of the FCF record */
  1614. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  1615. lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
  1616. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1617. *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
  1618. new_fcf_record = (struct fcf_record *)(virt_addr +
  1619. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1620. lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
  1621. offsetof(struct fcf_record, vlan_bitmap));
  1622. new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
  1623. new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
  1624. return new_fcf_record;
  1625. }
  1626. /**
  1627. * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
  1628. * @phba: pointer to lpfc hba data structure.
  1629. * @fcf_record: pointer to the fcf record.
  1630. * @vlan_id: the lowest vlan identifier associated to this fcf record.
  1631. * @next_fcf_index: the index to the next fcf record in hba's fcf table.
  1632. *
  1633. * This routine logs the detailed FCF record if the LOG_FIP loggin is
  1634. * enabled.
  1635. **/
  1636. static void
  1637. lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
  1638. struct fcf_record *fcf_record,
  1639. uint16_t vlan_id,
  1640. uint16_t next_fcf_index)
  1641. {
  1642. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1643. "2764 READ_FCF_RECORD:\n"
  1644. "\tFCF_Index : x%x\n"
  1645. "\tFCF_Avail : x%x\n"
  1646. "\tFCF_Valid : x%x\n"
  1647. "\tFIP_Priority : x%x\n"
  1648. "\tMAC_Provider : x%x\n"
  1649. "\tLowest VLANID : x%x\n"
  1650. "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
  1651. "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
  1652. "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
  1653. "\tNext_FCF_Index: x%x\n",
  1654. bf_get(lpfc_fcf_record_fcf_index, fcf_record),
  1655. bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
  1656. bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
  1657. fcf_record->fip_priority,
  1658. bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
  1659. vlan_id,
  1660. bf_get(lpfc_fcf_record_mac_0, fcf_record),
  1661. bf_get(lpfc_fcf_record_mac_1, fcf_record),
  1662. bf_get(lpfc_fcf_record_mac_2, fcf_record),
  1663. bf_get(lpfc_fcf_record_mac_3, fcf_record),
  1664. bf_get(lpfc_fcf_record_mac_4, fcf_record),
  1665. bf_get(lpfc_fcf_record_mac_5, fcf_record),
  1666. bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
  1667. bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
  1668. bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
  1669. bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
  1670. bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
  1671. bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
  1672. bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
  1673. bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
  1674. bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
  1675. bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
  1676. bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
  1677. bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
  1678. bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
  1679. bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
  1680. bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
  1681. bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
  1682. next_fcf_index);
  1683. }
  1684. /**
  1685. lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
  1686. * @phba: pointer to lpfc hba data structure.
  1687. * @fcf_rec: pointer to an existing FCF record.
  1688. * @new_fcf_record: pointer to a new FCF record.
  1689. * @new_vlan_id: vlan id from the new FCF record.
  1690. *
  1691. * This function performs matching test of a new FCF record against an existing
  1692. * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
  1693. * will not be used as part of the FCF record matching criteria.
  1694. *
  1695. * Returns true if all the fields matching, otherwise returns false.
  1696. */
  1697. static bool
  1698. lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
  1699. struct lpfc_fcf_rec *fcf_rec,
  1700. struct fcf_record *new_fcf_record,
  1701. uint16_t new_vlan_id)
  1702. {
  1703. if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
  1704. if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
  1705. return false;
  1706. if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
  1707. return false;
  1708. if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
  1709. return false;
  1710. if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
  1711. return false;
  1712. if (fcf_rec->priority != new_fcf_record->fip_priority)
  1713. return false;
  1714. return true;
  1715. }
  1716. /**
  1717. * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
  1718. * @vport: Pointer to vport object.
  1719. * @fcf_index: index to next fcf.
  1720. *
  1721. * This function processing the roundrobin fcf failover to next fcf index.
  1722. * When this function is invoked, there will be a current fcf registered
  1723. * for flogi.
  1724. * Return: 0 for continue retrying flogi on currently registered fcf;
  1725. * 1 for stop flogi on currently registered fcf;
  1726. */
  1727. int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
  1728. {
  1729. struct lpfc_hba *phba = vport->phba;
  1730. int rc;
  1731. if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
  1732. spin_lock_irq(&phba->hbalock);
  1733. if (phba->hba_flag & HBA_DEVLOSS_TMO) {
  1734. spin_unlock_irq(&phba->hbalock);
  1735. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1736. "2872 Devloss tmo with no eligible "
  1737. "FCF, unregister in-use FCF (x%x) "
  1738. "and rescan FCF table\n",
  1739. phba->fcf.current_rec.fcf_indx);
  1740. lpfc_unregister_fcf_rescan(phba);
  1741. goto stop_flogi_current_fcf;
  1742. }
  1743. /* Mark the end to FLOGI roundrobin failover */
  1744. phba->hba_flag &= ~FCF_RR_INPROG;
  1745. /* Allow action to new fcf asynchronous event */
  1746. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
  1747. spin_unlock_irq(&phba->hbalock);
  1748. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1749. "2865 No FCF available, stop roundrobin FCF "
  1750. "failover and change port state:x%x/x%x\n",
  1751. phba->pport->port_state, LPFC_VPORT_UNKNOWN);
  1752. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  1753. goto stop_flogi_current_fcf;
  1754. } else {
  1755. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
  1756. "2794 Try FLOGI roundrobin FCF failover to "
  1757. "(x%x)\n", fcf_index);
  1758. rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
  1759. if (rc)
  1760. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
  1761. "2761 FLOGI roundrobin FCF failover "
  1762. "failed (rc:x%x) to read FCF (x%x)\n",
  1763. rc, phba->fcf.current_rec.fcf_indx);
  1764. else
  1765. goto stop_flogi_current_fcf;
  1766. }
  1767. return 0;
  1768. stop_flogi_current_fcf:
  1769. lpfc_can_disctmo(vport);
  1770. return 1;
  1771. }
  1772. /**
  1773. * lpfc_sli4_fcf_pri_list_del
  1774. * @phba: pointer to lpfc hba data structure.
  1775. * @fcf_index the index of the fcf record to delete
  1776. * This routine checks the on list flag of the fcf_index to be deleted.
  1777. * If it is one the list then it is removed from the list, and the flag
  1778. * is cleared. This routine grab the hbalock before removing the fcf
  1779. * record from the list.
  1780. **/
  1781. static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
  1782. uint16_t fcf_index)
  1783. {
  1784. struct lpfc_fcf_pri *new_fcf_pri;
  1785. new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
  1786. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1787. "3058 deleting idx x%x pri x%x flg x%x\n",
  1788. fcf_index, new_fcf_pri->fcf_rec.priority,
  1789. new_fcf_pri->fcf_rec.flag);
  1790. spin_lock_irq(&phba->hbalock);
  1791. if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
  1792. if (phba->fcf.current_rec.priority ==
  1793. new_fcf_pri->fcf_rec.priority)
  1794. phba->fcf.eligible_fcf_cnt--;
  1795. list_del_init(&new_fcf_pri->list);
  1796. new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
  1797. }
  1798. spin_unlock_irq(&phba->hbalock);
  1799. }
  1800. /**
  1801. * lpfc_sli4_set_fcf_flogi_fail
  1802. * @phba: pointer to lpfc hba data structure.
  1803. * @fcf_index the index of the fcf record to update
  1804. * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
  1805. * flag so the the round robin slection for the particular priority level
  1806. * will try a different fcf record that does not have this bit set.
  1807. * If the fcf record is re-read for any reason this flag is cleared brfore
  1808. * adding it to the priority list.
  1809. **/
  1810. void
  1811. lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
  1812. {
  1813. struct lpfc_fcf_pri *new_fcf_pri;
  1814. new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
  1815. spin_lock_irq(&phba->hbalock);
  1816. new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
  1817. spin_unlock_irq(&phba->hbalock);
  1818. }
  1819. /**
  1820. * lpfc_sli4_fcf_pri_list_add
  1821. * @phba: pointer to lpfc hba data structure.
  1822. * @fcf_index the index of the fcf record to add
  1823. * This routine checks the priority of the fcf_index to be added.
  1824. * If it is a lower priority than the current head of the fcf_pri list
  1825. * then it is added to the list in the right order.
  1826. * If it is the same priority as the current head of the list then it
  1827. * is added to the head of the list and its bit in the rr_bmask is set.
  1828. * If the fcf_index to be added is of a higher priority than the current
  1829. * head of the list then the rr_bmask is cleared, its bit is set in the
  1830. * rr_bmask and it is added to the head of the list.
  1831. * returns:
  1832. * 0=success 1=failure
  1833. **/
  1834. int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, uint16_t fcf_index,
  1835. struct fcf_record *new_fcf_record)
  1836. {
  1837. uint16_t current_fcf_pri;
  1838. uint16_t last_index;
  1839. struct lpfc_fcf_pri *fcf_pri;
  1840. struct lpfc_fcf_pri *next_fcf_pri;
  1841. struct lpfc_fcf_pri *new_fcf_pri;
  1842. int ret;
  1843. new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
  1844. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1845. "3059 adding idx x%x pri x%x flg x%x\n",
  1846. fcf_index, new_fcf_record->fip_priority,
  1847. new_fcf_pri->fcf_rec.flag);
  1848. spin_lock_irq(&phba->hbalock);
  1849. if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
  1850. list_del_init(&new_fcf_pri->list);
  1851. new_fcf_pri->fcf_rec.fcf_index = fcf_index;
  1852. new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
  1853. if (list_empty(&phba->fcf.fcf_pri_list)) {
  1854. list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
  1855. ret = lpfc_sli4_fcf_rr_index_set(phba,
  1856. new_fcf_pri->fcf_rec.fcf_index);
  1857. goto out;
  1858. }
  1859. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  1860. LPFC_SLI4_FCF_TBL_INDX_MAX);
  1861. if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  1862. ret = 0; /* Empty rr list */
  1863. goto out;
  1864. }
  1865. current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
  1866. if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
  1867. list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
  1868. if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
  1869. memset(phba->fcf.fcf_rr_bmask, 0,
  1870. sizeof(*phba->fcf.fcf_rr_bmask));
  1871. /* fcfs_at_this_priority_level = 1; */
  1872. phba->fcf.eligible_fcf_cnt = 1;
  1873. } else
  1874. /* fcfs_at_this_priority_level++; */
  1875. phba->fcf.eligible_fcf_cnt++;
  1876. ret = lpfc_sli4_fcf_rr_index_set(phba,
  1877. new_fcf_pri->fcf_rec.fcf_index);
  1878. goto out;
  1879. }
  1880. list_for_each_entry_safe(fcf_pri, next_fcf_pri,
  1881. &phba->fcf.fcf_pri_list, list) {
  1882. if (new_fcf_pri->fcf_rec.priority <=
  1883. fcf_pri->fcf_rec.priority) {
  1884. if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
  1885. list_add(&new_fcf_pri->list,
  1886. &phba->fcf.fcf_pri_list);
  1887. else
  1888. list_add(&new_fcf_pri->list,
  1889. &((struct lpfc_fcf_pri *)
  1890. fcf_pri->list.prev)->list);
  1891. ret = 0;
  1892. goto out;
  1893. } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
  1894. || new_fcf_pri->fcf_rec.priority <
  1895. next_fcf_pri->fcf_rec.priority) {
  1896. list_add(&new_fcf_pri->list, &fcf_pri->list);
  1897. ret = 0;
  1898. goto out;
  1899. }
  1900. if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
  1901. continue;
  1902. }
  1903. ret = 1;
  1904. out:
  1905. /* we use = instead of |= to clear the FLOGI_FAILED flag. */
  1906. new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
  1907. spin_unlock_irq(&phba->hbalock);
  1908. return ret;
  1909. }
  1910. /**
  1911. * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
  1912. * @phba: pointer to lpfc hba data structure.
  1913. * @mboxq: pointer to mailbox object.
  1914. *
  1915. * This function iterates through all the fcf records available in
  1916. * HBA and chooses the optimal FCF record for discovery. After finding
  1917. * the FCF for discovery it registers the FCF record and kicks start
  1918. * discovery.
  1919. * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
  1920. * use an FCF record which matches fabric name and mac address of the
  1921. * currently used FCF record.
  1922. * If the driver supports only one FCF, it will try to use the FCF record
  1923. * used by BOOT_BIOS.
  1924. */
  1925. void
  1926. lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1927. {
  1928. struct fcf_record *new_fcf_record;
  1929. uint32_t boot_flag, addr_mode;
  1930. uint16_t fcf_index, next_fcf_index;
  1931. struct lpfc_fcf_rec *fcf_rec = NULL;
  1932. uint16_t vlan_id;
  1933. uint32_t seed;
  1934. bool select_new_fcf;
  1935. int rc;
  1936. /* If there is pending FCoE event restart FCF table scan */
  1937. if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
  1938. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1939. return;
  1940. }
  1941. /* Parse the FCF record from the non-embedded mailbox command */
  1942. new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
  1943. &next_fcf_index);
  1944. if (!new_fcf_record) {
  1945. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1946. "2765 Mailbox command READ_FCF_RECORD "
  1947. "failed to retrieve a FCF record.\n");
  1948. /* Let next new FCF event trigger fast failover */
  1949. spin_lock_irq(&phba->hbalock);
  1950. phba->hba_flag &= ~FCF_TS_INPROG;
  1951. spin_unlock_irq(&phba->hbalock);
  1952. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1953. return;
  1954. }
  1955. /* Check the FCF record against the connection list */
  1956. rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
  1957. &addr_mode, &vlan_id);
  1958. /* Log the FCF record information if turned on */
  1959. lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
  1960. next_fcf_index);
  1961. /*
  1962. * If the fcf record does not match with connect list entries
  1963. * read the next entry; otherwise, this is an eligible FCF
  1964. * record for roundrobin FCF failover.
  1965. */
  1966. if (!rc) {
  1967. lpfc_sli4_fcf_pri_list_del(phba,
  1968. bf_get(lpfc_fcf_record_fcf_index,
  1969. new_fcf_record));
  1970. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  1971. "2781 FCF (x%x) failed connection "
  1972. "list check: (x%x/x%x)\n",
  1973. bf_get(lpfc_fcf_record_fcf_index,
  1974. new_fcf_record),
  1975. bf_get(lpfc_fcf_record_fcf_avail,
  1976. new_fcf_record),
  1977. bf_get(lpfc_fcf_record_fcf_valid,
  1978. new_fcf_record));
  1979. if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
  1980. lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
  1981. new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
  1982. if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
  1983. phba->fcf.current_rec.fcf_indx) {
  1984. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1985. "2862 FCF (x%x) matches property "
  1986. "of in-use FCF (x%x)\n",
  1987. bf_get(lpfc_fcf_record_fcf_index,
  1988. new_fcf_record),
  1989. phba->fcf.current_rec.fcf_indx);
  1990. goto read_next_fcf;
  1991. }
  1992. /*
  1993. * In case the current in-use FCF record becomes
  1994. * invalid/unavailable during FCF discovery that
  1995. * was not triggered by fast FCF failover process,
  1996. * treat it as fast FCF failover.
  1997. */
  1998. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
  1999. !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
  2000. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  2001. "2835 Invalid in-use FCF "
  2002. "(x%x), enter FCF failover "
  2003. "table scan.\n",
  2004. phba->fcf.current_rec.fcf_indx);
  2005. spin_lock_irq(&phba->hbalock);
  2006. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  2007. spin_unlock_irq(&phba->hbalock);
  2008. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  2009. lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  2010. LPFC_FCOE_FCF_GET_FIRST);
  2011. return;
  2012. }
  2013. }
  2014. goto read_next_fcf;
  2015. } else {
  2016. fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  2017. rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
  2018. new_fcf_record);
  2019. if (rc)
  2020. goto read_next_fcf;
  2021. }
  2022. /*
  2023. * If this is not the first FCF discovery of the HBA, use last
  2024. * FCF record for the discovery. The condition that a rescan
  2025. * matches the in-use FCF record: fabric name, switch name, mac
  2026. * address, and vlan_id.
  2027. */
  2028. spin_lock_irq(&phba->hbalock);
  2029. if (phba->fcf.fcf_flag & FCF_IN_USE) {
  2030. if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
  2031. lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
  2032. new_fcf_record, vlan_id)) {
  2033. if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
  2034. phba->fcf.current_rec.fcf_indx) {
  2035. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  2036. if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
  2037. /* Stop FCF redisc wait timer */
  2038. __lpfc_sli4_stop_fcf_redisc_wait_timer(
  2039. phba);
  2040. else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
  2041. /* Fast failover, mark completed */
  2042. phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
  2043. spin_unlock_irq(&phba->hbalock);
  2044. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2045. "2836 New FCF matches in-use "
  2046. "FCF (x%x)\n",
  2047. phba->fcf.current_rec.fcf_indx);
  2048. goto out;
  2049. } else
  2050. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  2051. "2863 New FCF (x%x) matches "
  2052. "property of in-use FCF (x%x)\n",
  2053. bf_get(lpfc_fcf_record_fcf_index,
  2054. new_fcf_record),
  2055. phba->fcf.current_rec.fcf_indx);
  2056. }
  2057. /*
  2058. * Read next FCF record from HBA searching for the matching
  2059. * with in-use record only if not during the fast failover
  2060. * period. In case of fast failover period, it shall try to
  2061. * determine whether the FCF record just read should be the
  2062. * next candidate.
  2063. */
  2064. if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
  2065. spin_unlock_irq(&phba->hbalock);
  2066. goto read_next_fcf;
  2067. }
  2068. }
  2069. /*
  2070. * Update on failover FCF record only if it's in FCF fast-failover
  2071. * period; otherwise, update on current FCF record.
  2072. */
  2073. if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
  2074. fcf_rec = &phba->fcf.failover_rec;
  2075. else
  2076. fcf_rec = &phba->fcf.current_rec;
  2077. if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
  2078. /*
  2079. * If the driver FCF record does not have boot flag
  2080. * set and new hba fcf record has boot flag set, use
  2081. * the new hba fcf record.
  2082. */
  2083. if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
  2084. /* Choose this FCF record */
  2085. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2086. "2837 Update current FCF record "
  2087. "(x%x) with new FCF record (x%x)\n",
  2088. fcf_rec->fcf_indx,
  2089. bf_get(lpfc_fcf_record_fcf_index,
  2090. new_fcf_record));
  2091. __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
  2092. addr_mode, vlan_id, BOOT_ENABLE);
  2093. spin_unlock_irq(&phba->hbalock);
  2094. goto read_next_fcf;
  2095. }
  2096. /*
  2097. * If the driver FCF record has boot flag set and the
  2098. * new hba FCF record does not have boot flag, read
  2099. * the next FCF record.
  2100. */
  2101. if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
  2102. spin_unlock_irq(&phba->hbalock);
  2103. goto read_next_fcf;
  2104. }
  2105. /*
  2106. * If the new hba FCF record has lower priority value
  2107. * than the driver FCF record, use the new record.
  2108. */
  2109. if (new_fcf_record->fip_priority < fcf_rec->priority) {
  2110. /* Choose the new FCF record with lower priority */
  2111. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2112. "2838 Update current FCF record "
  2113. "(x%x) with new FCF record (x%x)\n",
  2114. fcf_rec->fcf_indx,
  2115. bf_get(lpfc_fcf_record_fcf_index,
  2116. new_fcf_record));
  2117. __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
  2118. addr_mode, vlan_id, 0);
  2119. /* Reset running random FCF selection count */
  2120. phba->fcf.eligible_fcf_cnt = 1;
  2121. } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
  2122. /* Update running random FCF selection count */
  2123. phba->fcf.eligible_fcf_cnt++;
  2124. select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
  2125. phba->fcf.eligible_fcf_cnt);
  2126. if (select_new_fcf) {
  2127. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2128. "2839 Update current FCF record "
  2129. "(x%x) with new FCF record (x%x)\n",
  2130. fcf_rec->fcf_indx,
  2131. bf_get(lpfc_fcf_record_fcf_index,
  2132. new_fcf_record));
  2133. /* Choose the new FCF by random selection */
  2134. __lpfc_update_fcf_record(phba, fcf_rec,
  2135. new_fcf_record,
  2136. addr_mode, vlan_id, 0);
  2137. }
  2138. }
  2139. spin_unlock_irq(&phba->hbalock);
  2140. goto read_next_fcf;
  2141. }
  2142. /*
  2143. * This is the first suitable FCF record, choose this record for
  2144. * initial best-fit FCF.
  2145. */
  2146. if (fcf_rec) {
  2147. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2148. "2840 Update initial FCF candidate "
  2149. "with FCF (x%x)\n",
  2150. bf_get(lpfc_fcf_record_fcf_index,
  2151. new_fcf_record));
  2152. __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
  2153. addr_mode, vlan_id, (boot_flag ?
  2154. BOOT_ENABLE : 0));
  2155. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  2156. /* Setup initial running random FCF selection count */
  2157. phba->fcf.eligible_fcf_cnt = 1;
  2158. /* Seeding the random number generator for random selection */
  2159. seed = (uint32_t)(0xFFFFFFFF & jiffies);
  2160. srandom32(seed);
  2161. }
  2162. spin_unlock_irq(&phba->hbalock);
  2163. goto read_next_fcf;
  2164. read_next_fcf:
  2165. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  2166. if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
  2167. if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
  2168. /*
  2169. * Case of FCF fast failover scan
  2170. */
  2171. /*
  2172. * It has not found any suitable FCF record, cancel
  2173. * FCF scan inprogress, and do nothing
  2174. */
  2175. if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
  2176. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  2177. "2782 No suitable FCF found: "
  2178. "(x%x/x%x)\n",
  2179. phba->fcoe_eventtag_at_fcf_scan,
  2180. bf_get(lpfc_fcf_record_fcf_index,
  2181. new_fcf_record));
  2182. spin_lock_irq(&phba->hbalock);
  2183. if (phba->hba_flag & HBA_DEVLOSS_TMO) {
  2184. phba->hba_flag &= ~FCF_TS_INPROG;
  2185. spin_unlock_irq(&phba->hbalock);
  2186. /* Unregister in-use FCF and rescan */
  2187. lpfc_printf_log(phba, KERN_INFO,
  2188. LOG_FIP,
  2189. "2864 On devloss tmo "
  2190. "unreg in-use FCF and "
  2191. "rescan FCF table\n");
  2192. lpfc_unregister_fcf_rescan(phba);
  2193. return;
  2194. }
  2195. /*
  2196. * Let next new FCF event trigger fast failover
  2197. */
  2198. phba->hba_flag &= ~FCF_TS_INPROG;
  2199. spin_unlock_irq(&phba->hbalock);
  2200. return;
  2201. }
  2202. /*
  2203. * It has found a suitable FCF record that is not
  2204. * the same as in-use FCF record, unregister the
  2205. * in-use FCF record, replace the in-use FCF record
  2206. * with the new FCF record, mark FCF fast failover
  2207. * completed, and then start register the new FCF
  2208. * record.
  2209. */
  2210. /* Unregister the current in-use FCF record */
  2211. lpfc_unregister_fcf(phba);
  2212. /* Replace in-use record with the new record */
  2213. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2214. "2842 Replace in-use FCF (x%x) "
  2215. "with failover FCF (x%x)\n",
  2216. phba->fcf.current_rec.fcf_indx,
  2217. phba->fcf.failover_rec.fcf_indx);
  2218. memcpy(&phba->fcf.current_rec,
  2219. &phba->fcf.failover_rec,
  2220. sizeof(struct lpfc_fcf_rec));
  2221. /*
  2222. * Mark the fast FCF failover rediscovery completed
  2223. * and the start of the first round of the roundrobin
  2224. * FCF failover.
  2225. */
  2226. spin_lock_irq(&phba->hbalock);
  2227. phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
  2228. spin_unlock_irq(&phba->hbalock);
  2229. /* Register to the new FCF record */
  2230. lpfc_register_fcf(phba);
  2231. } else {
  2232. /*
  2233. * In case of transaction period to fast FCF failover,
  2234. * do nothing when search to the end of the FCF table.
  2235. */
  2236. if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
  2237. (phba->fcf.fcf_flag & FCF_REDISC_PEND))
  2238. return;
  2239. if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
  2240. phba->fcf.fcf_flag & FCF_IN_USE) {
  2241. /*
  2242. * In case the current in-use FCF record no
  2243. * longer existed during FCF discovery that
  2244. * was not triggered by fast FCF failover
  2245. * process, treat it as fast FCF failover.
  2246. */
  2247. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2248. "2841 In-use FCF record (x%x) "
  2249. "not reported, entering fast "
  2250. "FCF failover mode scanning.\n",
  2251. phba->fcf.current_rec.fcf_indx);
  2252. spin_lock_irq(&phba->hbalock);
  2253. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  2254. spin_unlock_irq(&phba->hbalock);
  2255. lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  2256. LPFC_FCOE_FCF_GET_FIRST);
  2257. return;
  2258. }
  2259. /* Register to the new FCF record */
  2260. lpfc_register_fcf(phba);
  2261. }
  2262. } else
  2263. lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
  2264. return;
  2265. out:
  2266. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  2267. lpfc_register_fcf(phba);
  2268. return;
  2269. }
  2270. /**
  2271. * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
  2272. * @phba: pointer to lpfc hba data structure.
  2273. * @mboxq: pointer to mailbox object.
  2274. *
  2275. * This is the callback function for FLOGI failure roundrobin FCF failover
  2276. * read FCF record mailbox command from the eligible FCF record bmask for
  2277. * performing the failover. If the FCF read back is not valid/available, it
  2278. * fails through to retrying FLOGI to the currently registered FCF again.
  2279. * Otherwise, if the FCF read back is valid and available, it will set the
  2280. * newly read FCF record to the failover FCF record, unregister currently
  2281. * registered FCF record, copy the failover FCF record to the current
  2282. * FCF record, and then register the current FCF record before proceeding
  2283. * to trying FLOGI on the new failover FCF.
  2284. */
  2285. void
  2286. lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2287. {
  2288. struct fcf_record *new_fcf_record;
  2289. uint32_t boot_flag, addr_mode;
  2290. uint16_t next_fcf_index, fcf_index;
  2291. uint16_t current_fcf_index;
  2292. uint16_t vlan_id;
  2293. int rc;
  2294. /* If link state is not up, stop the roundrobin failover process */
  2295. if (phba->link_state < LPFC_LINK_UP) {
  2296. spin_lock_irq(&phba->hbalock);
  2297. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  2298. phba->hba_flag &= ~FCF_RR_INPROG;
  2299. spin_unlock_irq(&phba->hbalock);
  2300. goto out;
  2301. }
  2302. /* Parse the FCF record from the non-embedded mailbox command */
  2303. new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
  2304. &next_fcf_index);
  2305. if (!new_fcf_record) {
  2306. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  2307. "2766 Mailbox command READ_FCF_RECORD "
  2308. "failed to retrieve a FCF record.\n");
  2309. goto error_out;
  2310. }
  2311. /* Get the needed parameters from FCF record */
  2312. rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
  2313. &addr_mode, &vlan_id);
  2314. /* Log the FCF record information if turned on */
  2315. lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
  2316. next_fcf_index);
  2317. fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  2318. if (!rc) {
  2319. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2320. "2848 Remove ineligible FCF (x%x) from "
  2321. "from roundrobin bmask\n", fcf_index);
  2322. /* Clear roundrobin bmask bit for ineligible FCF */
  2323. lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
  2324. /* Perform next round of roundrobin FCF failover */
  2325. fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
  2326. rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
  2327. if (rc)
  2328. goto out;
  2329. goto error_out;
  2330. }
  2331. if (fcf_index == phba->fcf.current_rec.fcf_indx) {
  2332. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2333. "2760 Perform FLOGI roundrobin FCF failover: "
  2334. "FCF (x%x) back to FCF (x%x)\n",
  2335. phba->fcf.current_rec.fcf_indx, fcf_index);
  2336. /* Wait 500 ms before retrying FLOGI to current FCF */
  2337. msleep(500);
  2338. lpfc_issue_init_vfi(phba->pport);
  2339. goto out;
  2340. }
  2341. /* Upload new FCF record to the failover FCF record */
  2342. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2343. "2834 Update current FCF (x%x) with new FCF (x%x)\n",
  2344. phba->fcf.failover_rec.fcf_indx, fcf_index);
  2345. spin_lock_irq(&phba->hbalock);
  2346. __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
  2347. new_fcf_record, addr_mode, vlan_id,
  2348. (boot_flag ? BOOT_ENABLE : 0));
  2349. spin_unlock_irq(&phba->hbalock);
  2350. current_fcf_index = phba->fcf.current_rec.fcf_indx;
  2351. /* Unregister the current in-use FCF record */
  2352. lpfc_unregister_fcf(phba);
  2353. /* Replace in-use record with the new record */
  2354. memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
  2355. sizeof(struct lpfc_fcf_rec));
  2356. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2357. "2783 Perform FLOGI roundrobin FCF failover: FCF "
  2358. "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
  2359. error_out:
  2360. lpfc_register_fcf(phba);
  2361. out:
  2362. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  2363. }
  2364. /**
  2365. * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
  2366. * @phba: pointer to lpfc hba data structure.
  2367. * @mboxq: pointer to mailbox object.
  2368. *
  2369. * This is the callback function of read FCF record mailbox command for
  2370. * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
  2371. * failover when a new FCF event happened. If the FCF read back is
  2372. * valid/available and it passes the connection list check, it updates
  2373. * the bmask for the eligible FCF record for roundrobin failover.
  2374. */
  2375. void
  2376. lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2377. {
  2378. struct fcf_record *new_fcf_record;
  2379. uint32_t boot_flag, addr_mode;
  2380. uint16_t fcf_index, next_fcf_index;
  2381. uint16_t vlan_id;
  2382. int rc;
  2383. /* If link state is not up, no need to proceed */
  2384. if (phba->link_state < LPFC_LINK_UP)
  2385. goto out;
  2386. /* If FCF discovery period is over, no need to proceed */
  2387. if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
  2388. goto out;
  2389. /* Parse the FCF record from the non-embedded mailbox command */
  2390. new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
  2391. &next_fcf_index);
  2392. if (!new_fcf_record) {
  2393. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2394. "2767 Mailbox command READ_FCF_RECORD "
  2395. "failed to retrieve a FCF record.\n");
  2396. goto out;
  2397. }
  2398. /* Check the connection list for eligibility */
  2399. rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
  2400. &addr_mode, &vlan_id);
  2401. /* Log the FCF record information if turned on */
  2402. lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
  2403. next_fcf_index);
  2404. if (!rc)
  2405. goto out;
  2406. /* Update the eligible FCF record index bmask */
  2407. fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  2408. rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
  2409. out:
  2410. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  2411. }
  2412. /**
  2413. * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
  2414. * @phba: pointer to lpfc hba data structure.
  2415. * @mboxq: pointer to mailbox data structure.
  2416. *
  2417. * This function handles completion of init vfi mailbox command.
  2418. */
  2419. void
  2420. lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2421. {
  2422. struct lpfc_vport *vport = mboxq->vport;
  2423. /*
  2424. * VFI not supported on interface type 0, just do the flogi
  2425. * Also continue if the VFI is in use - just use the same one.
  2426. */
  2427. if (mboxq->u.mb.mbxStatus &&
  2428. (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  2429. LPFC_SLI_INTF_IF_TYPE_0) &&
  2430. mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
  2431. lpfc_printf_vlog(vport, KERN_ERR,
  2432. LOG_MBOX,
  2433. "2891 Init VFI mailbox failed 0x%x\n",
  2434. mboxq->u.mb.mbxStatus);
  2435. mempool_free(mboxq, phba->mbox_mem_pool);
  2436. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2437. return;
  2438. }
  2439. lpfc_initial_flogi(vport);
  2440. mempool_free(mboxq, phba->mbox_mem_pool);
  2441. return;
  2442. }
  2443. /**
  2444. * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
  2445. * @vport: pointer to lpfc_vport data structure.
  2446. *
  2447. * This function issue a init_vfi mailbox command to initialize the VFI and
  2448. * VPI for the physical port.
  2449. */
  2450. void
  2451. lpfc_issue_init_vfi(struct lpfc_vport *vport)
  2452. {
  2453. LPFC_MBOXQ_t *mboxq;
  2454. int rc;
  2455. struct lpfc_hba *phba = vport->phba;
  2456. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2457. if (!mboxq) {
  2458. lpfc_printf_vlog(vport, KERN_ERR,
  2459. LOG_MBOX, "2892 Failed to allocate "
  2460. "init_vfi mailbox\n");
  2461. return;
  2462. }
  2463. lpfc_init_vfi(mboxq, vport);
  2464. mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
  2465. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  2466. if (rc == MBX_NOT_FINISHED) {
  2467. lpfc_printf_vlog(vport, KERN_ERR,
  2468. LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
  2469. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  2470. }
  2471. }
  2472. /**
  2473. * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
  2474. * @phba: pointer to lpfc hba data structure.
  2475. * @mboxq: pointer to mailbox data structure.
  2476. *
  2477. * This function handles completion of init vpi mailbox command.
  2478. */
  2479. void
  2480. lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2481. {
  2482. struct lpfc_vport *vport = mboxq->vport;
  2483. struct lpfc_nodelist *ndlp;
  2484. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2485. if (mboxq->u.mb.mbxStatus) {
  2486. lpfc_printf_vlog(vport, KERN_ERR,
  2487. LOG_MBOX,
  2488. "2609 Init VPI mailbox failed 0x%x\n",
  2489. mboxq->u.mb.mbxStatus);
  2490. mempool_free(mboxq, phba->mbox_mem_pool);
  2491. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2492. return;
  2493. }
  2494. spin_lock_irq(shost->host_lock);
  2495. vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
  2496. spin_unlock_irq(shost->host_lock);
  2497. /* If this port is physical port or FDISC is done, do reg_vpi */
  2498. if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
  2499. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  2500. if (!ndlp)
  2501. lpfc_printf_vlog(vport, KERN_ERR,
  2502. LOG_DISCOVERY,
  2503. "2731 Cannot find fabric "
  2504. "controller node\n");
  2505. else
  2506. lpfc_register_new_vport(phba, vport, ndlp);
  2507. mempool_free(mboxq, phba->mbox_mem_pool);
  2508. return;
  2509. }
  2510. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  2511. lpfc_initial_fdisc(vport);
  2512. else {
  2513. lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
  2514. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2515. "2606 No NPIV Fabric support\n");
  2516. }
  2517. mempool_free(mboxq, phba->mbox_mem_pool);
  2518. return;
  2519. }
  2520. /**
  2521. * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
  2522. * @vport: pointer to lpfc_vport data structure.
  2523. *
  2524. * This function issue a init_vpi mailbox command to initialize
  2525. * VPI for the vport.
  2526. */
  2527. void
  2528. lpfc_issue_init_vpi(struct lpfc_vport *vport)
  2529. {
  2530. LPFC_MBOXQ_t *mboxq;
  2531. int rc;
  2532. mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
  2533. if (!mboxq) {
  2534. lpfc_printf_vlog(vport, KERN_ERR,
  2535. LOG_MBOX, "2607 Failed to allocate "
  2536. "init_vpi mailbox\n");
  2537. return;
  2538. }
  2539. lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
  2540. mboxq->vport = vport;
  2541. mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
  2542. rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
  2543. if (rc == MBX_NOT_FINISHED) {
  2544. lpfc_printf_vlog(vport, KERN_ERR,
  2545. LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
  2546. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  2547. }
  2548. }
  2549. /**
  2550. * lpfc_start_fdiscs - send fdiscs for each vports on this port.
  2551. * @phba: pointer to lpfc hba data structure.
  2552. *
  2553. * This function loops through the list of vports on the @phba and issues an
  2554. * FDISC if possible.
  2555. */
  2556. void
  2557. lpfc_start_fdiscs(struct lpfc_hba *phba)
  2558. {
  2559. struct lpfc_vport **vports;
  2560. int i;
  2561. vports = lpfc_create_vport_work_array(phba);
  2562. if (vports != NULL) {
  2563. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2564. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  2565. continue;
  2566. /* There are no vpi for this vport */
  2567. if (vports[i]->vpi > phba->max_vpi) {
  2568. lpfc_vport_set_state(vports[i],
  2569. FC_VPORT_FAILED);
  2570. continue;
  2571. }
  2572. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  2573. lpfc_vport_set_state(vports[i],
  2574. FC_VPORT_LINKDOWN);
  2575. continue;
  2576. }
  2577. if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
  2578. lpfc_issue_init_vpi(vports[i]);
  2579. continue;
  2580. }
  2581. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  2582. lpfc_initial_fdisc(vports[i]);
  2583. else {
  2584. lpfc_vport_set_state(vports[i],
  2585. FC_VPORT_NO_FABRIC_SUPP);
  2586. lpfc_printf_vlog(vports[i], KERN_ERR,
  2587. LOG_ELS,
  2588. "0259 No NPIV "
  2589. "Fabric support\n");
  2590. }
  2591. }
  2592. }
  2593. lpfc_destroy_vport_work_array(phba, vports);
  2594. }
  2595. void
  2596. lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2597. {
  2598. struct lpfc_dmabuf *dmabuf = mboxq->context1;
  2599. struct lpfc_vport *vport = mboxq->vport;
  2600. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2601. /*
  2602. * VFI not supported for interface type 0, so ignore any mailbox
  2603. * error (except VFI in use) and continue with the discovery.
  2604. */
  2605. if (mboxq->u.mb.mbxStatus &&
  2606. (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  2607. LPFC_SLI_INTF_IF_TYPE_0) &&
  2608. mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
  2609. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2610. "2018 REG_VFI mbxStatus error x%x "
  2611. "HBA state x%x\n",
  2612. mboxq->u.mb.mbxStatus, vport->port_state);
  2613. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  2614. /* FLOGI failed, use loop map to make discovery list */
  2615. lpfc_disc_list_loopmap(vport);
  2616. /* Start discovery */
  2617. lpfc_disc_start(vport);
  2618. goto out_free_mem;
  2619. }
  2620. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2621. goto out_free_mem;
  2622. }
  2623. /* The VPI is implicitly registered when the VFI is registered */
  2624. spin_lock_irq(shost->host_lock);
  2625. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2626. vport->fc_flag |= FC_VFI_REGISTERED;
  2627. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  2628. vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
  2629. spin_unlock_irq(shost->host_lock);
  2630. /* In case SLI4 FC loopback test, we are ready */
  2631. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  2632. (phba->link_flag & LS_LOOPBACK_MODE)) {
  2633. phba->link_state = LPFC_HBA_READY;
  2634. goto out_free_mem;
  2635. }
  2636. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  2637. /* For private loop just start discovery and we are done. */
  2638. if ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
  2639. !(vport->fc_flag & FC_PUBLIC_LOOP)) {
  2640. /* Use loop map to make discovery list */
  2641. lpfc_disc_list_loopmap(vport);
  2642. /* Start discovery */
  2643. lpfc_disc_start(vport);
  2644. } else {
  2645. lpfc_start_fdiscs(phba);
  2646. lpfc_do_scr_ns_plogi(phba, vport);
  2647. }
  2648. }
  2649. out_free_mem:
  2650. mempool_free(mboxq, phba->mbox_mem_pool);
  2651. lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
  2652. kfree(dmabuf);
  2653. return;
  2654. }
  2655. static void
  2656. lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2657. {
  2658. MAILBOX_t *mb = &pmb->u.mb;
  2659. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
  2660. struct lpfc_vport *vport = pmb->vport;
  2661. /* Check for error */
  2662. if (mb->mbxStatus) {
  2663. /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
  2664. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2665. "0319 READ_SPARAM mbxStatus error x%x "
  2666. "hba state x%x>\n",
  2667. mb->mbxStatus, vport->port_state);
  2668. lpfc_linkdown(phba);
  2669. goto out;
  2670. }
  2671. memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
  2672. sizeof (struct serv_parm));
  2673. lpfc_update_vport_wwn(vport);
  2674. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  2675. memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
  2676. memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
  2677. }
  2678. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2679. kfree(mp);
  2680. mempool_free(pmb, phba->mbox_mem_pool);
  2681. return;
  2682. out:
  2683. pmb->context1 = NULL;
  2684. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2685. kfree(mp);
  2686. lpfc_issue_clear_la(phba, vport);
  2687. mempool_free(pmb, phba->mbox_mem_pool);
  2688. return;
  2689. }
  2690. static void
  2691. lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
  2692. {
  2693. struct lpfc_vport *vport = phba->pport;
  2694. LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
  2695. struct Scsi_Host *shost;
  2696. int i;
  2697. struct lpfc_dmabuf *mp;
  2698. int rc;
  2699. struct fcf_record *fcf_record;
  2700. spin_lock_irq(&phba->hbalock);
  2701. switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
  2702. case LPFC_LINK_SPEED_1GHZ:
  2703. case LPFC_LINK_SPEED_2GHZ:
  2704. case LPFC_LINK_SPEED_4GHZ:
  2705. case LPFC_LINK_SPEED_8GHZ:
  2706. case LPFC_LINK_SPEED_10GHZ:
  2707. case LPFC_LINK_SPEED_16GHZ:
  2708. phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
  2709. break;
  2710. default:
  2711. phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
  2712. break;
  2713. }
  2714. phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
  2715. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  2716. shost = lpfc_shost_from_vport(vport);
  2717. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  2718. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  2719. /* if npiv is enabled and this adapter supports npiv log
  2720. * a message that npiv is not supported in this topology
  2721. */
  2722. if (phba->cfg_enable_npiv && phba->max_vpi)
  2723. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2724. "1309 Link Up Event npiv not supported in loop "
  2725. "topology\n");
  2726. /* Get Loop Map information */
  2727. if (bf_get(lpfc_mbx_read_top_il, la)) {
  2728. spin_lock(shost->host_lock);
  2729. vport->fc_flag |= FC_LBIT;
  2730. spin_unlock(shost->host_lock);
  2731. }
  2732. vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
  2733. i = la->lilpBde64.tus.f.bdeSize;
  2734. if (i == 0) {
  2735. phba->alpa_map[0] = 0;
  2736. } else {
  2737. if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
  2738. int numalpa, j, k;
  2739. union {
  2740. uint8_t pamap[16];
  2741. struct {
  2742. uint32_t wd1;
  2743. uint32_t wd2;
  2744. uint32_t wd3;
  2745. uint32_t wd4;
  2746. } pa;
  2747. } un;
  2748. numalpa = phba->alpa_map[0];
  2749. j = 0;
  2750. while (j < numalpa) {
  2751. memset(un.pamap, 0, 16);
  2752. for (k = 1; j < numalpa; k++) {
  2753. un.pamap[k - 1] =
  2754. phba->alpa_map[j + 1];
  2755. j++;
  2756. if (k == 16)
  2757. break;
  2758. }
  2759. /* Link Up Event ALPA map */
  2760. lpfc_printf_log(phba,
  2761. KERN_WARNING,
  2762. LOG_LINK_EVENT,
  2763. "1304 Link Up Event "
  2764. "ALPA map Data: x%x "
  2765. "x%x x%x x%x\n",
  2766. un.pa.wd1, un.pa.wd2,
  2767. un.pa.wd3, un.pa.wd4);
  2768. }
  2769. }
  2770. }
  2771. } else {
  2772. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
  2773. if (phba->max_vpi && phba->cfg_enable_npiv &&
  2774. (phba->sli_rev >= LPFC_SLI_REV3))
  2775. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  2776. }
  2777. vport->fc_myDID = phba->fc_pref_DID;
  2778. spin_lock(shost->host_lock);
  2779. vport->fc_flag |= FC_LBIT;
  2780. spin_unlock(shost->host_lock);
  2781. }
  2782. spin_unlock_irq(&phba->hbalock);
  2783. lpfc_linkup(phba);
  2784. sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2785. if (!sparam_mbox)
  2786. goto out;
  2787. rc = lpfc_read_sparam(phba, sparam_mbox, 0);
  2788. if (rc) {
  2789. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  2790. goto out;
  2791. }
  2792. sparam_mbox->vport = vport;
  2793. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  2794. rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
  2795. if (rc == MBX_NOT_FINISHED) {
  2796. mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
  2797. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2798. kfree(mp);
  2799. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  2800. goto out;
  2801. }
  2802. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  2803. cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2804. if (!cfglink_mbox)
  2805. goto out;
  2806. vport->port_state = LPFC_LOCAL_CFG_LINK;
  2807. lpfc_config_link(phba, cfglink_mbox);
  2808. cfglink_mbox->vport = vport;
  2809. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  2810. rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
  2811. if (rc == MBX_NOT_FINISHED) {
  2812. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  2813. goto out;
  2814. }
  2815. } else {
  2816. vport->port_state = LPFC_VPORT_UNKNOWN;
  2817. /*
  2818. * Add the driver's default FCF record at FCF index 0 now. This
  2819. * is phase 1 implementation that support FCF index 0 and driver
  2820. * defaults.
  2821. */
  2822. if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
  2823. fcf_record = kzalloc(sizeof(struct fcf_record),
  2824. GFP_KERNEL);
  2825. if (unlikely(!fcf_record)) {
  2826. lpfc_printf_log(phba, KERN_ERR,
  2827. LOG_MBOX | LOG_SLI,
  2828. "2554 Could not allocate memory for "
  2829. "fcf record\n");
  2830. rc = -ENODEV;
  2831. goto out;
  2832. }
  2833. lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
  2834. LPFC_FCOE_FCF_DEF_INDEX);
  2835. rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
  2836. if (unlikely(rc)) {
  2837. lpfc_printf_log(phba, KERN_ERR,
  2838. LOG_MBOX | LOG_SLI,
  2839. "2013 Could not manually add FCF "
  2840. "record 0, status %d\n", rc);
  2841. rc = -ENODEV;
  2842. kfree(fcf_record);
  2843. goto out;
  2844. }
  2845. kfree(fcf_record);
  2846. }
  2847. /*
  2848. * The driver is expected to do FIP/FCF. Call the port
  2849. * and get the FCF Table.
  2850. */
  2851. spin_lock_irq(&phba->hbalock);
  2852. if (phba->hba_flag & FCF_TS_INPROG) {
  2853. spin_unlock_irq(&phba->hbalock);
  2854. return;
  2855. }
  2856. /* This is the initial FCF discovery scan */
  2857. phba->fcf.fcf_flag |= FCF_INIT_DISC;
  2858. spin_unlock_irq(&phba->hbalock);
  2859. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  2860. "2778 Start FCF table scan at linkup\n");
  2861. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  2862. LPFC_FCOE_FCF_GET_FIRST);
  2863. if (rc) {
  2864. spin_lock_irq(&phba->hbalock);
  2865. phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
  2866. spin_unlock_irq(&phba->hbalock);
  2867. goto out;
  2868. }
  2869. /* Reset FCF roundrobin bmask for new discovery */
  2870. lpfc_sli4_clear_fcf_rr_bmask(phba);
  2871. }
  2872. return;
  2873. out:
  2874. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2875. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2876. "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
  2877. vport->port_state, sparam_mbox, cfglink_mbox);
  2878. lpfc_issue_clear_la(phba, vport);
  2879. return;
  2880. }
  2881. static void
  2882. lpfc_enable_la(struct lpfc_hba *phba)
  2883. {
  2884. uint32_t control;
  2885. struct lpfc_sli *psli = &phba->sli;
  2886. spin_lock_irq(&phba->hbalock);
  2887. psli->sli_flag |= LPFC_PROCESS_LA;
  2888. if (phba->sli_rev <= LPFC_SLI_REV3) {
  2889. control = readl(phba->HCregaddr);
  2890. control |= HC_LAINT_ENA;
  2891. writel(control, phba->HCregaddr);
  2892. readl(phba->HCregaddr); /* flush */
  2893. }
  2894. spin_unlock_irq(&phba->hbalock);
  2895. }
  2896. static void
  2897. lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
  2898. {
  2899. lpfc_linkdown(phba);
  2900. lpfc_enable_la(phba);
  2901. lpfc_unregister_unused_fcf(phba);
  2902. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  2903. }
  2904. /*
  2905. * This routine handles processing a READ_TOPOLOGY mailbox
  2906. * command upon completion. It is setup in the LPFC_MBOXQ
  2907. * as the completion routine when the command is
  2908. * handed off to the SLI layer.
  2909. */
  2910. void
  2911. lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2912. {
  2913. struct lpfc_vport *vport = pmb->vport;
  2914. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2915. struct lpfc_mbx_read_top *la;
  2916. MAILBOX_t *mb = &pmb->u.mb;
  2917. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2918. /* Unblock ELS traffic */
  2919. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  2920. /* Check for error */
  2921. if (mb->mbxStatus) {
  2922. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  2923. "1307 READ_LA mbox error x%x state x%x\n",
  2924. mb->mbxStatus, vport->port_state);
  2925. lpfc_mbx_issue_link_down(phba);
  2926. phba->link_state = LPFC_HBA_ERROR;
  2927. goto lpfc_mbx_cmpl_read_topology_free_mbuf;
  2928. }
  2929. la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
  2930. memcpy(&phba->alpa_map[0], mp->virt, 128);
  2931. spin_lock_irq(shost->host_lock);
  2932. if (bf_get(lpfc_mbx_read_top_pb, la))
  2933. vport->fc_flag |= FC_BYPASSED_MODE;
  2934. else
  2935. vport->fc_flag &= ~FC_BYPASSED_MODE;
  2936. spin_unlock_irq(shost->host_lock);
  2937. if ((phba->fc_eventTag < la->eventTag) ||
  2938. (phba->fc_eventTag == la->eventTag)) {
  2939. phba->fc_stat.LinkMultiEvent++;
  2940. if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)
  2941. if (phba->fc_eventTag != 0)
  2942. lpfc_linkdown(phba);
  2943. }
  2944. phba->fc_eventTag = la->eventTag;
  2945. spin_lock_irq(&phba->hbalock);
  2946. if (bf_get(lpfc_mbx_read_top_mm, la))
  2947. phba->sli.sli_flag |= LPFC_MENLO_MAINT;
  2948. else
  2949. phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
  2950. spin_unlock_irq(&phba->hbalock);
  2951. phba->link_events++;
  2952. if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) &&
  2953. (!bf_get(lpfc_mbx_read_top_mm, la))) {
  2954. phba->fc_stat.LinkUp++;
  2955. if (phba->link_flag & LS_LOOPBACK_MODE) {
  2956. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2957. "1306 Link Up Event in loop back mode "
  2958. "x%x received Data: x%x x%x x%x x%x\n",
  2959. la->eventTag, phba->fc_eventTag,
  2960. bf_get(lpfc_mbx_read_top_alpa_granted,
  2961. la),
  2962. bf_get(lpfc_mbx_read_top_link_spd, la),
  2963. phba->alpa_map[0]);
  2964. } else {
  2965. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2966. "1303 Link Up Event x%x received "
  2967. "Data: x%x x%x x%x x%x x%x x%x %d\n",
  2968. la->eventTag, phba->fc_eventTag,
  2969. bf_get(lpfc_mbx_read_top_alpa_granted,
  2970. la),
  2971. bf_get(lpfc_mbx_read_top_link_spd, la),
  2972. phba->alpa_map[0],
  2973. bf_get(lpfc_mbx_read_top_mm, la),
  2974. bf_get(lpfc_mbx_read_top_fa, la),
  2975. phba->wait_4_mlo_maint_flg);
  2976. }
  2977. lpfc_mbx_process_link_up(phba, la);
  2978. } else if (bf_get(lpfc_mbx_read_top_att_type, la) ==
  2979. LPFC_ATT_LINK_DOWN) {
  2980. phba->fc_stat.LinkDown++;
  2981. if (phba->link_flag & LS_LOOPBACK_MODE)
  2982. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2983. "1308 Link Down Event in loop back mode "
  2984. "x%x received "
  2985. "Data: x%x x%x x%x\n",
  2986. la->eventTag, phba->fc_eventTag,
  2987. phba->pport->port_state, vport->fc_flag);
  2988. else
  2989. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2990. "1305 Link Down Event x%x received "
  2991. "Data: x%x x%x x%x x%x x%x\n",
  2992. la->eventTag, phba->fc_eventTag,
  2993. phba->pport->port_state, vport->fc_flag,
  2994. bf_get(lpfc_mbx_read_top_mm, la),
  2995. bf_get(lpfc_mbx_read_top_fa, la));
  2996. lpfc_mbx_issue_link_down(phba);
  2997. }
  2998. if ((bf_get(lpfc_mbx_read_top_mm, la)) &&
  2999. (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)) {
  3000. if (phba->link_state != LPFC_LINK_DOWN) {
  3001. phba->fc_stat.LinkDown++;
  3002. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  3003. "1312 Link Down Event x%x received "
  3004. "Data: x%x x%x x%x\n",
  3005. la->eventTag, phba->fc_eventTag,
  3006. phba->pport->port_state, vport->fc_flag);
  3007. lpfc_mbx_issue_link_down(phba);
  3008. } else
  3009. lpfc_enable_la(phba);
  3010. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  3011. "1310 Menlo Maint Mode Link up Event x%x rcvd "
  3012. "Data: x%x x%x x%x\n",
  3013. la->eventTag, phba->fc_eventTag,
  3014. phba->pport->port_state, vport->fc_flag);
  3015. /*
  3016. * The cmnd that triggered this will be waiting for this
  3017. * signal.
  3018. */
  3019. /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
  3020. if (phba->wait_4_mlo_maint_flg) {
  3021. phba->wait_4_mlo_maint_flg = 0;
  3022. wake_up_interruptible(&phba->wait_4_mlo_m_q);
  3023. }
  3024. }
  3025. if (bf_get(lpfc_mbx_read_top_fa, la)) {
  3026. if (bf_get(lpfc_mbx_read_top_mm, la))
  3027. lpfc_issue_clear_la(phba, vport);
  3028. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  3029. "1311 fa %d\n",
  3030. bf_get(lpfc_mbx_read_top_fa, la));
  3031. }
  3032. lpfc_mbx_cmpl_read_topology_free_mbuf:
  3033. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3034. kfree(mp);
  3035. mempool_free(pmb, phba->mbox_mem_pool);
  3036. return;
  3037. }
  3038. /*
  3039. * This routine handles processing a REG_LOGIN mailbox
  3040. * command upon completion. It is setup in the LPFC_MBOXQ
  3041. * as the completion routine when the command is
  3042. * handed off to the SLI layer.
  3043. */
  3044. void
  3045. lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3046. {
  3047. struct lpfc_vport *vport = pmb->vport;
  3048. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3049. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3050. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3051. pmb->context1 = NULL;
  3052. pmb->context2 = NULL;
  3053. if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
  3054. ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
  3055. if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
  3056. ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
  3057. /* We rcvd a rscn after issuing this
  3058. * mbox reg login, we may have cycled
  3059. * back through the state and be
  3060. * back at reg login state so this
  3061. * mbox needs to be ignored becase
  3062. * there is another reg login in
  3063. * process.
  3064. */
  3065. spin_lock_irq(shost->host_lock);
  3066. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  3067. spin_unlock_irq(shost->host_lock);
  3068. } else
  3069. /* Good status, call state machine */
  3070. lpfc_disc_state_machine(vport, ndlp, pmb,
  3071. NLP_EVT_CMPL_REG_LOGIN);
  3072. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3073. kfree(mp);
  3074. mempool_free(pmb, phba->mbox_mem_pool);
  3075. /* decrement the node reference count held for this callback
  3076. * function.
  3077. */
  3078. lpfc_nlp_put(ndlp);
  3079. return;
  3080. }
  3081. static void
  3082. lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3083. {
  3084. MAILBOX_t *mb = &pmb->u.mb;
  3085. struct lpfc_vport *vport = pmb->vport;
  3086. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3087. switch (mb->mbxStatus) {
  3088. case 0x0011:
  3089. case 0x0020:
  3090. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3091. "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
  3092. mb->mbxStatus);
  3093. break;
  3094. /* If VPI is busy, reset the HBA */
  3095. case 0x9700:
  3096. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  3097. "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
  3098. vport->vpi, mb->mbxStatus);
  3099. if (!(phba->pport->load_flag & FC_UNLOADING))
  3100. lpfc_workq_post_event(phba, NULL, NULL,
  3101. LPFC_EVT_RESET_HBA);
  3102. }
  3103. spin_lock_irq(shost->host_lock);
  3104. vport->vpi_state &= ~LPFC_VPI_REGISTERED;
  3105. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3106. spin_unlock_irq(shost->host_lock);
  3107. vport->unreg_vpi_cmpl = VPORT_OK;
  3108. mempool_free(pmb, phba->mbox_mem_pool);
  3109. lpfc_cleanup_vports_rrqs(vport, NULL);
  3110. /*
  3111. * This shost reference might have been taken at the beginning of
  3112. * lpfc_vport_delete()
  3113. */
  3114. if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
  3115. scsi_host_put(shost);
  3116. }
  3117. int
  3118. lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
  3119. {
  3120. struct lpfc_hba *phba = vport->phba;
  3121. LPFC_MBOXQ_t *mbox;
  3122. int rc;
  3123. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3124. if (!mbox)
  3125. return 1;
  3126. lpfc_unreg_vpi(phba, vport->vpi, mbox);
  3127. mbox->vport = vport;
  3128. mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
  3129. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3130. if (rc == MBX_NOT_FINISHED) {
  3131. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  3132. "1800 Could not issue unreg_vpi\n");
  3133. mempool_free(mbox, phba->mbox_mem_pool);
  3134. vport->unreg_vpi_cmpl = VPORT_ERROR;
  3135. return rc;
  3136. }
  3137. return 0;
  3138. }
  3139. static void
  3140. lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3141. {
  3142. struct lpfc_vport *vport = pmb->vport;
  3143. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3144. MAILBOX_t *mb = &pmb->u.mb;
  3145. switch (mb->mbxStatus) {
  3146. case 0x0011:
  3147. case 0x9601:
  3148. case 0x9602:
  3149. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3150. "0912 cmpl_reg_vpi, mb status = 0x%x\n",
  3151. mb->mbxStatus);
  3152. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3153. spin_lock_irq(shost->host_lock);
  3154. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  3155. spin_unlock_irq(shost->host_lock);
  3156. vport->fc_myDID = 0;
  3157. goto out;
  3158. }
  3159. spin_lock_irq(shost->host_lock);
  3160. vport->vpi_state |= LPFC_VPI_REGISTERED;
  3161. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3162. spin_unlock_irq(shost->host_lock);
  3163. vport->num_disc_nodes = 0;
  3164. /* go thru NPR list and issue ELS PLOGIs */
  3165. if (vport->fc_npr_cnt)
  3166. lpfc_els_disc_plogi(vport);
  3167. if (!vport->num_disc_nodes) {
  3168. spin_lock_irq(shost->host_lock);
  3169. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  3170. spin_unlock_irq(shost->host_lock);
  3171. lpfc_can_disctmo(vport);
  3172. }
  3173. vport->port_state = LPFC_VPORT_READY;
  3174. out:
  3175. mempool_free(pmb, phba->mbox_mem_pool);
  3176. return;
  3177. }
  3178. /**
  3179. * lpfc_create_static_vport - Read HBA config region to create static vports.
  3180. * @phba: pointer to lpfc hba data structure.
  3181. *
  3182. * This routine issue a DUMP mailbox command for config region 22 to get
  3183. * the list of static vports to be created. The function create vports
  3184. * based on the information returned from the HBA.
  3185. **/
  3186. void
  3187. lpfc_create_static_vport(struct lpfc_hba *phba)
  3188. {
  3189. LPFC_MBOXQ_t *pmb = NULL;
  3190. MAILBOX_t *mb;
  3191. struct static_vport_info *vport_info;
  3192. int rc = 0, i;
  3193. struct fc_vport_identifiers vport_id;
  3194. struct fc_vport *new_fc_vport;
  3195. struct Scsi_Host *shost;
  3196. struct lpfc_vport *vport;
  3197. uint16_t offset = 0;
  3198. uint8_t *vport_buff;
  3199. struct lpfc_dmabuf *mp;
  3200. uint32_t byte_count = 0;
  3201. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3202. if (!pmb) {
  3203. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3204. "0542 lpfc_create_static_vport failed to"
  3205. " allocate mailbox memory\n");
  3206. return;
  3207. }
  3208. mb = &pmb->u.mb;
  3209. vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
  3210. if (!vport_info) {
  3211. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3212. "0543 lpfc_create_static_vport failed to"
  3213. " allocate vport_info\n");
  3214. mempool_free(pmb, phba->mbox_mem_pool);
  3215. return;
  3216. }
  3217. vport_buff = (uint8_t *) vport_info;
  3218. do {
  3219. if (lpfc_dump_static_vport(phba, pmb, offset))
  3220. goto out;
  3221. pmb->vport = phba->pport;
  3222. rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
  3223. if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
  3224. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3225. "0544 lpfc_create_static_vport failed to"
  3226. " issue dump mailbox command ret 0x%x "
  3227. "status 0x%x\n",
  3228. rc, mb->mbxStatus);
  3229. goto out;
  3230. }
  3231. if (phba->sli_rev == LPFC_SLI_REV4) {
  3232. byte_count = pmb->u.mqe.un.mb_words[5];
  3233. mp = (struct lpfc_dmabuf *) pmb->context2;
  3234. if (byte_count > sizeof(struct static_vport_info) -
  3235. offset)
  3236. byte_count = sizeof(struct static_vport_info)
  3237. - offset;
  3238. memcpy(vport_buff + offset, mp->virt, byte_count);
  3239. offset += byte_count;
  3240. } else {
  3241. if (mb->un.varDmp.word_cnt >
  3242. sizeof(struct static_vport_info) - offset)
  3243. mb->un.varDmp.word_cnt =
  3244. sizeof(struct static_vport_info)
  3245. - offset;
  3246. byte_count = mb->un.varDmp.word_cnt;
  3247. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  3248. vport_buff + offset,
  3249. byte_count);
  3250. offset += byte_count;
  3251. }
  3252. } while (byte_count &&
  3253. offset < sizeof(struct static_vport_info));
  3254. if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
  3255. ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
  3256. != VPORT_INFO_REV)) {
  3257. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3258. "0545 lpfc_create_static_vport bad"
  3259. " information header 0x%x 0x%x\n",
  3260. le32_to_cpu(vport_info->signature),
  3261. le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
  3262. goto out;
  3263. }
  3264. shost = lpfc_shost_from_vport(phba->pport);
  3265. for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
  3266. memset(&vport_id, 0, sizeof(vport_id));
  3267. vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
  3268. vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
  3269. if (!vport_id.port_name || !vport_id.node_name)
  3270. continue;
  3271. vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
  3272. vport_id.vport_type = FC_PORTTYPE_NPIV;
  3273. vport_id.disable = false;
  3274. new_fc_vport = fc_vport_create(shost, 0, &vport_id);
  3275. if (!new_fc_vport) {
  3276. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3277. "0546 lpfc_create_static_vport failed to"
  3278. " create vport\n");
  3279. continue;
  3280. }
  3281. vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
  3282. vport->vport_flag |= STATIC_VPORT;
  3283. }
  3284. out:
  3285. kfree(vport_info);
  3286. if (rc != MBX_TIMEOUT) {
  3287. if (pmb->context2) {
  3288. mp = (struct lpfc_dmabuf *) pmb->context2;
  3289. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3290. kfree(mp);
  3291. }
  3292. mempool_free(pmb, phba->mbox_mem_pool);
  3293. }
  3294. return;
  3295. }
  3296. /*
  3297. * This routine handles processing a Fabric REG_LOGIN mailbox
  3298. * command upon completion. It is setup in the LPFC_MBOXQ
  3299. * as the completion routine when the command is
  3300. * handed off to the SLI layer.
  3301. */
  3302. void
  3303. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3304. {
  3305. struct lpfc_vport *vport = pmb->vport;
  3306. MAILBOX_t *mb = &pmb->u.mb;
  3307. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3308. struct lpfc_nodelist *ndlp;
  3309. struct Scsi_Host *shost;
  3310. ndlp = (struct lpfc_nodelist *) pmb->context2;
  3311. pmb->context1 = NULL;
  3312. pmb->context2 = NULL;
  3313. if (mb->mbxStatus) {
  3314. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3315. "0258 Register Fabric login error: 0x%x\n",
  3316. mb->mbxStatus);
  3317. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3318. kfree(mp);
  3319. mempool_free(pmb, phba->mbox_mem_pool);
  3320. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  3321. /* FLOGI failed, use loop map to make discovery list */
  3322. lpfc_disc_list_loopmap(vport);
  3323. /* Start discovery */
  3324. lpfc_disc_start(vport);
  3325. /* Decrement the reference count to ndlp after the
  3326. * reference to the ndlp are done.
  3327. */
  3328. lpfc_nlp_put(ndlp);
  3329. return;
  3330. }
  3331. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3332. /* Decrement the reference count to ndlp after the reference
  3333. * to the ndlp are done.
  3334. */
  3335. lpfc_nlp_put(ndlp);
  3336. return;
  3337. }
  3338. if (phba->sli_rev < LPFC_SLI_REV4)
  3339. ndlp->nlp_rpi = mb->un.varWords[0];
  3340. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  3341. ndlp->nlp_type |= NLP_FABRIC;
  3342. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  3343. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  3344. /* when physical port receive logo donot start
  3345. * vport discovery */
  3346. if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
  3347. lpfc_start_fdiscs(phba);
  3348. else {
  3349. shost = lpfc_shost_from_vport(vport);
  3350. spin_lock_irq(shost->host_lock);
  3351. vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
  3352. spin_unlock_irq(shost->host_lock);
  3353. }
  3354. lpfc_do_scr_ns_plogi(phba, vport);
  3355. }
  3356. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3357. kfree(mp);
  3358. mempool_free(pmb, phba->mbox_mem_pool);
  3359. /* Drop the reference count from the mbox at the end after
  3360. * all the current reference to the ndlp have been done.
  3361. */
  3362. lpfc_nlp_put(ndlp);
  3363. return;
  3364. }
  3365. /*
  3366. * This routine handles processing a NameServer REG_LOGIN mailbox
  3367. * command upon completion. It is setup in the LPFC_MBOXQ
  3368. * as the completion routine when the command is
  3369. * handed off to the SLI layer.
  3370. */
  3371. void
  3372. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3373. {
  3374. MAILBOX_t *mb = &pmb->u.mb;
  3375. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3376. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3377. struct lpfc_vport *vport = pmb->vport;
  3378. pmb->context1 = NULL;
  3379. pmb->context2 = NULL;
  3380. if (mb->mbxStatus) {
  3381. out:
  3382. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3383. "0260 Register NameServer error: 0x%x\n",
  3384. mb->mbxStatus);
  3385. /* decrement the node reference count held for this
  3386. * callback function.
  3387. */
  3388. lpfc_nlp_put(ndlp);
  3389. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3390. kfree(mp);
  3391. mempool_free(pmb, phba->mbox_mem_pool);
  3392. /* If no other thread is using the ndlp, free it */
  3393. lpfc_nlp_not_used(ndlp);
  3394. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  3395. /*
  3396. * RegLogin failed, use loop map to make discovery
  3397. * list
  3398. */
  3399. lpfc_disc_list_loopmap(vport);
  3400. /* Start discovery */
  3401. lpfc_disc_start(vport);
  3402. return;
  3403. }
  3404. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3405. return;
  3406. }
  3407. if (phba->sli_rev < LPFC_SLI_REV4)
  3408. ndlp->nlp_rpi = mb->un.varWords[0];
  3409. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  3410. ndlp->nlp_type |= NLP_FABRIC;
  3411. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  3412. if (vport->port_state < LPFC_VPORT_READY) {
  3413. /* Link up discovery requires Fabric registration. */
  3414. lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
  3415. lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
  3416. lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
  3417. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  3418. lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
  3419. /* Issue SCR just before NameServer GID_FT Query */
  3420. lpfc_issue_els_scr(vport, SCR_DID, 0);
  3421. }
  3422. vport->fc_ns_retry = 0;
  3423. /* Good status, issue CT Request to NameServer */
  3424. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
  3425. /* Cannot issue NameServer Query, so finish up discovery */
  3426. goto out;
  3427. }
  3428. /* decrement the node reference count held for this
  3429. * callback function.
  3430. */
  3431. lpfc_nlp_put(ndlp);
  3432. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3433. kfree(mp);
  3434. mempool_free(pmb, phba->mbox_mem_pool);
  3435. return;
  3436. }
  3437. static void
  3438. lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3439. {
  3440. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3441. struct fc_rport *rport;
  3442. struct lpfc_rport_data *rdata;
  3443. struct fc_rport_identifiers rport_ids;
  3444. struct lpfc_hba *phba = vport->phba;
  3445. /* Remote port has reappeared. Re-register w/ FC transport */
  3446. rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  3447. rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  3448. rport_ids.port_id = ndlp->nlp_DID;
  3449. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  3450. /*
  3451. * We leave our node pointer in rport->dd_data when we unregister a
  3452. * FCP target port. But fc_remote_port_add zeros the space to which
  3453. * rport->dd_data points. So, if we're reusing a previously
  3454. * registered port, drop the reference that we took the last time we
  3455. * registered the port.
  3456. */
  3457. if (ndlp->rport && ndlp->rport->dd_data &&
  3458. ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
  3459. lpfc_nlp_put(ndlp);
  3460. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  3461. "rport add: did:x%x flg:x%x type x%x",
  3462. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  3463. /* Don't add the remote port if unloading. */
  3464. if (vport->load_flag & FC_UNLOADING)
  3465. return;
  3466. ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
  3467. if (!rport || !get_device(&rport->dev)) {
  3468. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  3469. "Warning: fc_remote_port_add failed\n");
  3470. return;
  3471. }
  3472. /* initialize static port data */
  3473. rport->maxframe_size = ndlp->nlp_maxframe;
  3474. rport->supported_classes = ndlp->nlp_class_sup;
  3475. rdata = rport->dd_data;
  3476. rdata->pnode = lpfc_nlp_get(ndlp);
  3477. if (ndlp->nlp_type & NLP_FCP_TARGET)
  3478. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  3479. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  3480. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  3481. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  3482. fc_remote_port_rolechg(rport, rport_ids.roles);
  3483. if ((rport->scsi_target_id != -1) &&
  3484. (rport->scsi_target_id < LPFC_MAX_TARGET)) {
  3485. ndlp->nlp_sid = rport->scsi_target_id;
  3486. }
  3487. return;
  3488. }
  3489. static void
  3490. lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
  3491. {
  3492. struct fc_rport *rport = ndlp->rport;
  3493. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  3494. "rport delete: did:x%x flg:x%x type x%x",
  3495. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  3496. fc_remote_port_delete(rport);
  3497. return;
  3498. }
  3499. static void
  3500. lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
  3501. {
  3502. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3503. spin_lock_irq(shost->host_lock);
  3504. switch (state) {
  3505. case NLP_STE_UNUSED_NODE:
  3506. vport->fc_unused_cnt += count;
  3507. break;
  3508. case NLP_STE_PLOGI_ISSUE:
  3509. vport->fc_plogi_cnt += count;
  3510. break;
  3511. case NLP_STE_ADISC_ISSUE:
  3512. vport->fc_adisc_cnt += count;
  3513. break;
  3514. case NLP_STE_REG_LOGIN_ISSUE:
  3515. vport->fc_reglogin_cnt += count;
  3516. break;
  3517. case NLP_STE_PRLI_ISSUE:
  3518. vport->fc_prli_cnt += count;
  3519. break;
  3520. case NLP_STE_UNMAPPED_NODE:
  3521. vport->fc_unmap_cnt += count;
  3522. break;
  3523. case NLP_STE_MAPPED_NODE:
  3524. vport->fc_map_cnt += count;
  3525. break;
  3526. case NLP_STE_NPR_NODE:
  3527. vport->fc_npr_cnt += count;
  3528. break;
  3529. }
  3530. spin_unlock_irq(shost->host_lock);
  3531. }
  3532. static void
  3533. lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3534. int old_state, int new_state)
  3535. {
  3536. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3537. if (new_state == NLP_STE_UNMAPPED_NODE) {
  3538. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  3539. ndlp->nlp_type |= NLP_FC_NODE;
  3540. }
  3541. if (new_state == NLP_STE_MAPPED_NODE)
  3542. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  3543. if (new_state == NLP_STE_NPR_NODE)
  3544. ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
  3545. /* Transport interface */
  3546. if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
  3547. old_state == NLP_STE_UNMAPPED_NODE)) {
  3548. vport->phba->nport_event_cnt++;
  3549. lpfc_unregister_remote_port(ndlp);
  3550. }
  3551. if (new_state == NLP_STE_MAPPED_NODE ||
  3552. new_state == NLP_STE_UNMAPPED_NODE) {
  3553. vport->phba->nport_event_cnt++;
  3554. /*
  3555. * Tell the fc transport about the port, if we haven't
  3556. * already. If we have, and it's a scsi entity, be
  3557. * sure to unblock any attached scsi devices
  3558. */
  3559. lpfc_register_remote_port(vport, ndlp);
  3560. }
  3561. if ((new_state == NLP_STE_MAPPED_NODE) &&
  3562. (vport->stat_data_enabled)) {
  3563. /*
  3564. * A new target is discovered, if there is no buffer for
  3565. * statistical data collection allocate buffer.
  3566. */
  3567. ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
  3568. sizeof(struct lpfc_scsicmd_bkt),
  3569. GFP_KERNEL);
  3570. if (!ndlp->lat_data)
  3571. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  3572. "0286 lpfc_nlp_state_cleanup failed to "
  3573. "allocate statistical data buffer DID "
  3574. "0x%x\n", ndlp->nlp_DID);
  3575. }
  3576. /*
  3577. * if we added to Mapped list, but the remote port
  3578. * registration failed or assigned a target id outside
  3579. * our presentable range - move the node to the
  3580. * Unmapped List
  3581. */
  3582. if (new_state == NLP_STE_MAPPED_NODE &&
  3583. (!ndlp->rport ||
  3584. ndlp->rport->scsi_target_id == -1 ||
  3585. ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
  3586. spin_lock_irq(shost->host_lock);
  3587. ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  3588. spin_unlock_irq(shost->host_lock);
  3589. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  3590. }
  3591. }
  3592. static char *
  3593. lpfc_nlp_state_name(char *buffer, size_t size, int state)
  3594. {
  3595. static char *states[] = {
  3596. [NLP_STE_UNUSED_NODE] = "UNUSED",
  3597. [NLP_STE_PLOGI_ISSUE] = "PLOGI",
  3598. [NLP_STE_ADISC_ISSUE] = "ADISC",
  3599. [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
  3600. [NLP_STE_PRLI_ISSUE] = "PRLI",
  3601. [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
  3602. [NLP_STE_MAPPED_NODE] = "MAPPED",
  3603. [NLP_STE_NPR_NODE] = "NPR",
  3604. };
  3605. if (state < NLP_STE_MAX_STATE && states[state])
  3606. strlcpy(buffer, states[state], size);
  3607. else
  3608. snprintf(buffer, size, "unknown (%d)", state);
  3609. return buffer;
  3610. }
  3611. void
  3612. lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3613. int state)
  3614. {
  3615. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3616. int old_state = ndlp->nlp_state;
  3617. char name1[16], name2[16];
  3618. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3619. "0904 NPort state transition x%06x, %s -> %s\n",
  3620. ndlp->nlp_DID,
  3621. lpfc_nlp_state_name(name1, sizeof(name1), old_state),
  3622. lpfc_nlp_state_name(name2, sizeof(name2), state));
  3623. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  3624. "node statechg did:x%x old:%d ste:%d",
  3625. ndlp->nlp_DID, old_state, state);
  3626. if (old_state == NLP_STE_NPR_NODE &&
  3627. state != NLP_STE_NPR_NODE)
  3628. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3629. if (old_state == NLP_STE_UNMAPPED_NODE) {
  3630. ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  3631. ndlp->nlp_type &= ~NLP_FC_NODE;
  3632. }
  3633. if (list_empty(&ndlp->nlp_listp)) {
  3634. spin_lock_irq(shost->host_lock);
  3635. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  3636. spin_unlock_irq(shost->host_lock);
  3637. } else if (old_state)
  3638. lpfc_nlp_counters(vport, old_state, -1);
  3639. ndlp->nlp_state = state;
  3640. lpfc_nlp_counters(vport, state, 1);
  3641. lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
  3642. }
  3643. void
  3644. lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3645. {
  3646. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3647. if (list_empty(&ndlp->nlp_listp)) {
  3648. spin_lock_irq(shost->host_lock);
  3649. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  3650. spin_unlock_irq(shost->host_lock);
  3651. }
  3652. }
  3653. void
  3654. lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3655. {
  3656. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3657. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3658. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  3659. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  3660. spin_lock_irq(shost->host_lock);
  3661. list_del_init(&ndlp->nlp_listp);
  3662. spin_unlock_irq(shost->host_lock);
  3663. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  3664. NLP_STE_UNUSED_NODE);
  3665. }
  3666. static void
  3667. lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3668. {
  3669. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3670. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  3671. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  3672. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  3673. NLP_STE_UNUSED_NODE);
  3674. }
  3675. /**
  3676. * lpfc_initialize_node - Initialize all fields of node object
  3677. * @vport: Pointer to Virtual Port object.
  3678. * @ndlp: Pointer to FC node object.
  3679. * @did: FC_ID of the node.
  3680. *
  3681. * This function is always called when node object need to be initialized.
  3682. * It initializes all the fields of the node object. Although the reference
  3683. * to phba from @ndlp can be obtained indirectly through it's reference to
  3684. * @vport, a direct reference to phba is taken here by @ndlp. This is due
  3685. * to the life-span of the @ndlp might go beyond the existence of @vport as
  3686. * the final release of ndlp is determined by its reference count. And, the
  3687. * operation on @ndlp needs the reference to phba.
  3688. **/
  3689. static inline void
  3690. lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3691. uint32_t did)
  3692. {
  3693. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  3694. INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
  3695. init_timer(&ndlp->nlp_delayfunc);
  3696. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  3697. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  3698. ndlp->nlp_DID = did;
  3699. ndlp->vport = vport;
  3700. ndlp->phba = vport->phba;
  3701. ndlp->nlp_sid = NLP_NO_SID;
  3702. kref_init(&ndlp->kref);
  3703. NLP_INT_NODE_ACT(ndlp);
  3704. atomic_set(&ndlp->cmd_pending, 0);
  3705. ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
  3706. if (vport->phba->sli_rev == LPFC_SLI_REV4)
  3707. ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
  3708. }
  3709. struct lpfc_nodelist *
  3710. lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3711. int state)
  3712. {
  3713. struct lpfc_hba *phba = vport->phba;
  3714. uint32_t did;
  3715. unsigned long flags;
  3716. if (!ndlp)
  3717. return NULL;
  3718. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3719. /* The ndlp should not be in memory free mode */
  3720. if (NLP_CHK_FREE_REQ(ndlp)) {
  3721. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3722. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  3723. "0277 lpfc_enable_node: ndlp:x%p "
  3724. "usgmap:x%x refcnt:%d\n",
  3725. (void *)ndlp, ndlp->nlp_usg_map,
  3726. atomic_read(&ndlp->kref.refcount));
  3727. return NULL;
  3728. }
  3729. /* The ndlp should not already be in active mode */
  3730. if (NLP_CHK_NODE_ACT(ndlp)) {
  3731. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3732. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  3733. "0278 lpfc_enable_node: ndlp:x%p "
  3734. "usgmap:x%x refcnt:%d\n",
  3735. (void *)ndlp, ndlp->nlp_usg_map,
  3736. atomic_read(&ndlp->kref.refcount));
  3737. return NULL;
  3738. }
  3739. /* Keep the original DID */
  3740. did = ndlp->nlp_DID;
  3741. /* re-initialize ndlp except of ndlp linked list pointer */
  3742. memset((((char *)ndlp) + sizeof (struct list_head)), 0,
  3743. sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
  3744. lpfc_initialize_node(vport, ndlp, did);
  3745. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3746. if (state != NLP_STE_UNUSED_NODE)
  3747. lpfc_nlp_set_state(vport, ndlp, state);
  3748. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  3749. "node enable: did:x%x",
  3750. ndlp->nlp_DID, 0, 0);
  3751. return ndlp;
  3752. }
  3753. void
  3754. lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3755. {
  3756. /*
  3757. * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
  3758. * be used if we wish to issue the "last" lpfc_nlp_put() to remove
  3759. * the ndlp from the vport. The ndlp marked as UNUSED on the list
  3760. * until ALL other outstanding threads have completed. We check
  3761. * that the ndlp not already in the UNUSED state before we proceed.
  3762. */
  3763. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  3764. return;
  3765. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
  3766. if (vport->phba->sli_rev == LPFC_SLI_REV4)
  3767. lpfc_cleanup_vports_rrqs(vport, ndlp);
  3768. lpfc_nlp_put(ndlp);
  3769. return;
  3770. }
  3771. /*
  3772. * Start / ReStart rescue timer for Discovery / RSCN handling
  3773. */
  3774. void
  3775. lpfc_set_disctmo(struct lpfc_vport *vport)
  3776. {
  3777. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3778. struct lpfc_hba *phba = vport->phba;
  3779. uint32_t tmo;
  3780. if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
  3781. /* For FAN, timeout should be greater than edtov */
  3782. tmo = (((phba->fc_edtov + 999) / 1000) + 1);
  3783. } else {
  3784. /* Normal discovery timeout should be > than ELS/CT timeout
  3785. * FC spec states we need 3 * ratov for CT requests
  3786. */
  3787. tmo = ((phba->fc_ratov * 3) + 3);
  3788. }
  3789. if (!timer_pending(&vport->fc_disctmo)) {
  3790. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3791. "set disc timer: tmo:x%x state:x%x flg:x%x",
  3792. tmo, vport->port_state, vport->fc_flag);
  3793. }
  3794. mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
  3795. spin_lock_irq(shost->host_lock);
  3796. vport->fc_flag |= FC_DISC_TMO;
  3797. spin_unlock_irq(shost->host_lock);
  3798. /* Start Discovery Timer state <hba_state> */
  3799. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3800. "0247 Start Discovery Timer state x%x "
  3801. "Data: x%x x%lx x%x x%x\n",
  3802. vport->port_state, tmo,
  3803. (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
  3804. vport->fc_adisc_cnt);
  3805. return;
  3806. }
  3807. /*
  3808. * Cancel rescue timer for Discovery / RSCN handling
  3809. */
  3810. int
  3811. lpfc_can_disctmo(struct lpfc_vport *vport)
  3812. {
  3813. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3814. unsigned long iflags;
  3815. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3816. "can disc timer: state:x%x rtry:x%x flg:x%x",
  3817. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  3818. /* Turn off discovery timer if its running */
  3819. if (vport->fc_flag & FC_DISC_TMO) {
  3820. spin_lock_irqsave(shost->host_lock, iflags);
  3821. vport->fc_flag &= ~FC_DISC_TMO;
  3822. spin_unlock_irqrestore(shost->host_lock, iflags);
  3823. del_timer_sync(&vport->fc_disctmo);
  3824. spin_lock_irqsave(&vport->work_port_lock, iflags);
  3825. vport->work_port_events &= ~WORKER_DISC_TMO;
  3826. spin_unlock_irqrestore(&vport->work_port_lock, iflags);
  3827. }
  3828. /* Cancel Discovery Timer state <hba_state> */
  3829. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3830. "0248 Cancel Discovery Timer state x%x "
  3831. "Data: x%x x%x x%x\n",
  3832. vport->port_state, vport->fc_flag,
  3833. vport->fc_plogi_cnt, vport->fc_adisc_cnt);
  3834. return 0;
  3835. }
  3836. /*
  3837. * Check specified ring for outstanding IOCB on the SLI queue
  3838. * Return true if iocb matches the specified nport
  3839. */
  3840. int
  3841. lpfc_check_sli_ndlp(struct lpfc_hba *phba,
  3842. struct lpfc_sli_ring *pring,
  3843. struct lpfc_iocbq *iocb,
  3844. struct lpfc_nodelist *ndlp)
  3845. {
  3846. struct lpfc_sli *psli = &phba->sli;
  3847. IOCB_t *icmd = &iocb->iocb;
  3848. struct lpfc_vport *vport = ndlp->vport;
  3849. if (iocb->vport != vport)
  3850. return 0;
  3851. if (pring->ringno == LPFC_ELS_RING) {
  3852. switch (icmd->ulpCommand) {
  3853. case CMD_GEN_REQUEST64_CR:
  3854. if (iocb->context_un.ndlp == ndlp)
  3855. return 1;
  3856. case CMD_ELS_REQUEST64_CR:
  3857. if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
  3858. return 1;
  3859. case CMD_XMIT_ELS_RSP64_CX:
  3860. if (iocb->context1 == (uint8_t *) ndlp)
  3861. return 1;
  3862. }
  3863. } else if (pring->ringno == psli->extra_ring) {
  3864. } else if (pring->ringno == psli->fcp_ring) {
  3865. /* Skip match check if waiting to relogin to FCP target */
  3866. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  3867. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  3868. return 0;
  3869. }
  3870. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  3871. return 1;
  3872. }
  3873. } else if (pring->ringno == psli->next_ring) {
  3874. }
  3875. return 0;
  3876. }
  3877. /*
  3878. * Free resources / clean up outstanding I/Os
  3879. * associated with nlp_rpi in the LPFC_NODELIST entry.
  3880. */
  3881. static int
  3882. lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  3883. {
  3884. LIST_HEAD(completions);
  3885. struct lpfc_sli *psli;
  3886. struct lpfc_sli_ring *pring;
  3887. struct lpfc_iocbq *iocb, *next_iocb;
  3888. uint32_t i;
  3889. lpfc_fabric_abort_nport(ndlp);
  3890. /*
  3891. * Everything that matches on txcmplq will be returned
  3892. * by firmware with a no rpi error.
  3893. */
  3894. psli = &phba->sli;
  3895. if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
  3896. /* Now process each ring */
  3897. for (i = 0; i < psli->num_rings; i++) {
  3898. pring = &psli->ring[i];
  3899. spin_lock_irq(&phba->hbalock);
  3900. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  3901. list) {
  3902. /*
  3903. * Check to see if iocb matches the nport we are
  3904. * looking for
  3905. */
  3906. if ((lpfc_check_sli_ndlp(phba, pring, iocb,
  3907. ndlp))) {
  3908. /* It matches, so deque and call compl
  3909. with an error */
  3910. list_move_tail(&iocb->list,
  3911. &completions);
  3912. pring->txq_cnt--;
  3913. }
  3914. }
  3915. spin_unlock_irq(&phba->hbalock);
  3916. }
  3917. }
  3918. /* Cancel all the IOCBs from the completions list */
  3919. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3920. IOERR_SLI_ABORTED);
  3921. return 0;
  3922. }
  3923. /*
  3924. * Free rpi associated with LPFC_NODELIST entry.
  3925. * This routine is called from lpfc_freenode(), when we are removing
  3926. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  3927. * LOGO that completes successfully, and we are waiting to PLOGI back
  3928. * to the remote NPort. In addition, it is called after we receive
  3929. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  3930. * we are waiting to PLOGI back to the remote NPort.
  3931. */
  3932. int
  3933. lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3934. {
  3935. struct lpfc_hba *phba = vport->phba;
  3936. LPFC_MBOXQ_t *mbox;
  3937. int rc;
  3938. uint16_t rpi;
  3939. if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
  3940. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3941. if (mbox) {
  3942. /* SLI4 ports require the physical rpi value. */
  3943. rpi = ndlp->nlp_rpi;
  3944. if (phba->sli_rev == LPFC_SLI_REV4)
  3945. rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  3946. lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
  3947. mbox->vport = vport;
  3948. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3949. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3950. if (rc == MBX_NOT_FINISHED)
  3951. mempool_free(mbox, phba->mbox_mem_pool);
  3952. }
  3953. lpfc_no_rpi(phba, ndlp);
  3954. if (phba->sli_rev != LPFC_SLI_REV4)
  3955. ndlp->nlp_rpi = 0;
  3956. ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
  3957. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  3958. return 1;
  3959. }
  3960. return 0;
  3961. }
  3962. /**
  3963. * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
  3964. * @phba: pointer to lpfc hba data structure.
  3965. *
  3966. * This routine is invoked to unregister all the currently registered RPIs
  3967. * to the HBA.
  3968. **/
  3969. void
  3970. lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
  3971. {
  3972. struct lpfc_vport **vports;
  3973. struct lpfc_nodelist *ndlp;
  3974. struct Scsi_Host *shost;
  3975. int i;
  3976. vports = lpfc_create_vport_work_array(phba);
  3977. if (!vports) {
  3978. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  3979. "2884 Vport array allocation failed \n");
  3980. return;
  3981. }
  3982. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3983. shost = lpfc_shost_from_vport(vports[i]);
  3984. spin_lock_irq(shost->host_lock);
  3985. list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
  3986. if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
  3987. /* The mempool_alloc might sleep */
  3988. spin_unlock_irq(shost->host_lock);
  3989. lpfc_unreg_rpi(vports[i], ndlp);
  3990. spin_lock_irq(shost->host_lock);
  3991. }
  3992. }
  3993. spin_unlock_irq(shost->host_lock);
  3994. }
  3995. lpfc_destroy_vport_work_array(phba, vports);
  3996. }
  3997. void
  3998. lpfc_unreg_all_rpis(struct lpfc_vport *vport)
  3999. {
  4000. struct lpfc_hba *phba = vport->phba;
  4001. LPFC_MBOXQ_t *mbox;
  4002. int rc;
  4003. if (phba->sli_rev == LPFC_SLI_REV4) {
  4004. lpfc_sli4_unreg_all_rpis(vport);
  4005. return;
  4006. }
  4007. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4008. if (mbox) {
  4009. lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
  4010. mbox);
  4011. mbox->vport = vport;
  4012. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4013. mbox->context1 = NULL;
  4014. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  4015. if (rc != MBX_TIMEOUT)
  4016. mempool_free(mbox, phba->mbox_mem_pool);
  4017. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  4018. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  4019. "1836 Could not issue "
  4020. "unreg_login(all_rpis) status %d\n", rc);
  4021. }
  4022. }
  4023. void
  4024. lpfc_unreg_default_rpis(struct lpfc_vport *vport)
  4025. {
  4026. struct lpfc_hba *phba = vport->phba;
  4027. LPFC_MBOXQ_t *mbox;
  4028. int rc;
  4029. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4030. if (mbox) {
  4031. lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
  4032. mbox);
  4033. mbox->vport = vport;
  4034. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4035. mbox->context1 = NULL;
  4036. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  4037. if (rc != MBX_TIMEOUT)
  4038. mempool_free(mbox, phba->mbox_mem_pool);
  4039. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  4040. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  4041. "1815 Could not issue "
  4042. "unreg_did (default rpis) status %d\n",
  4043. rc);
  4044. }
  4045. }
  4046. /*
  4047. * Free resources associated with LPFC_NODELIST entry
  4048. * so it can be freed.
  4049. */
  4050. static int
  4051. lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  4052. {
  4053. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4054. struct lpfc_hba *phba = vport->phba;
  4055. LPFC_MBOXQ_t *mb, *nextmb;
  4056. struct lpfc_dmabuf *mp;
  4057. /* Cleanup node for NPort <nlp_DID> */
  4058. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  4059. "0900 Cleanup node for NPort x%x "
  4060. "Data: x%x x%x x%x\n",
  4061. ndlp->nlp_DID, ndlp->nlp_flag,
  4062. ndlp->nlp_state, ndlp->nlp_rpi);
  4063. if (NLP_CHK_FREE_REQ(ndlp)) {
  4064. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  4065. "0280 lpfc_cleanup_node: ndlp:x%p "
  4066. "usgmap:x%x refcnt:%d\n",
  4067. (void *)ndlp, ndlp->nlp_usg_map,
  4068. atomic_read(&ndlp->kref.refcount));
  4069. lpfc_dequeue_node(vport, ndlp);
  4070. } else {
  4071. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  4072. "0281 lpfc_cleanup_node: ndlp:x%p "
  4073. "usgmap:x%x refcnt:%d\n",
  4074. (void *)ndlp, ndlp->nlp_usg_map,
  4075. atomic_read(&ndlp->kref.refcount));
  4076. lpfc_disable_node(vport, ndlp);
  4077. }
  4078. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  4079. if ((mb = phba->sli.mbox_active)) {
  4080. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  4081. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  4082. mb->context2 = NULL;
  4083. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4084. }
  4085. }
  4086. spin_lock_irq(&phba->hbalock);
  4087. /* Cleanup REG_LOGIN completions which are not yet processed */
  4088. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  4089. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
  4090. (ndlp != (struct lpfc_nodelist *) mb->context2))
  4091. continue;
  4092. mb->context2 = NULL;
  4093. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4094. }
  4095. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  4096. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  4097. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  4098. mp = (struct lpfc_dmabuf *) (mb->context1);
  4099. if (mp) {
  4100. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4101. kfree(mp);
  4102. }
  4103. list_del(&mb->list);
  4104. mempool_free(mb, phba->mbox_mem_pool);
  4105. /* We shall not invoke the lpfc_nlp_put to decrement
  4106. * the ndlp reference count as we are in the process
  4107. * of lpfc_nlp_release.
  4108. */
  4109. }
  4110. }
  4111. spin_unlock_irq(&phba->hbalock);
  4112. lpfc_els_abort(phba, ndlp);
  4113. spin_lock_irq(shost->host_lock);
  4114. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  4115. spin_unlock_irq(shost->host_lock);
  4116. ndlp->nlp_last_elscmd = 0;
  4117. del_timer_sync(&ndlp->nlp_delayfunc);
  4118. list_del_init(&ndlp->els_retry_evt.evt_listp);
  4119. list_del_init(&ndlp->dev_loss_evt.evt_listp);
  4120. lpfc_cleanup_vports_rrqs(vport, ndlp);
  4121. lpfc_unreg_rpi(vport, ndlp);
  4122. return 0;
  4123. }
  4124. /*
  4125. * Check to see if we can free the nlp back to the freelist.
  4126. * If we are in the middle of using the nlp in the discovery state
  4127. * machine, defer the free till we reach the end of the state machine.
  4128. */
  4129. static void
  4130. lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  4131. {
  4132. struct lpfc_hba *phba = vport->phba;
  4133. struct lpfc_rport_data *rdata;
  4134. LPFC_MBOXQ_t *mbox;
  4135. int rc;
  4136. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  4137. if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
  4138. !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
  4139. !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
  4140. /* For this case we need to cleanup the default rpi
  4141. * allocated by the firmware.
  4142. */
  4143. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
  4144. != NULL) {
  4145. rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
  4146. (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
  4147. if (rc) {
  4148. mempool_free(mbox, phba->mbox_mem_pool);
  4149. }
  4150. else {
  4151. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  4152. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  4153. mbox->vport = vport;
  4154. mbox->context2 = NULL;
  4155. rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4156. if (rc == MBX_NOT_FINISHED) {
  4157. mempool_free(mbox, phba->mbox_mem_pool);
  4158. }
  4159. }
  4160. }
  4161. }
  4162. lpfc_cleanup_node(vport, ndlp);
  4163. /*
  4164. * We can get here with a non-NULL ndlp->rport because when we
  4165. * unregister a rport we don't break the rport/node linkage. So if we
  4166. * do, make sure we don't leaving any dangling pointers behind.
  4167. */
  4168. if (ndlp->rport) {
  4169. rdata = ndlp->rport->dd_data;
  4170. rdata->pnode = NULL;
  4171. ndlp->rport = NULL;
  4172. }
  4173. }
  4174. static int
  4175. lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  4176. uint32_t did)
  4177. {
  4178. D_ID mydid, ndlpdid, matchdid;
  4179. if (did == Bcast_DID)
  4180. return 0;
  4181. /* First check for Direct match */
  4182. if (ndlp->nlp_DID == did)
  4183. return 1;
  4184. /* Next check for area/domain identically equals 0 match */
  4185. mydid.un.word = vport->fc_myDID;
  4186. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  4187. return 0;
  4188. }
  4189. matchdid.un.word = did;
  4190. ndlpdid.un.word = ndlp->nlp_DID;
  4191. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  4192. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  4193. (mydid.un.b.area == matchdid.un.b.area)) {
  4194. if ((ndlpdid.un.b.domain == 0) &&
  4195. (ndlpdid.un.b.area == 0)) {
  4196. if (ndlpdid.un.b.id)
  4197. return 1;
  4198. }
  4199. return 0;
  4200. }
  4201. matchdid.un.word = ndlp->nlp_DID;
  4202. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  4203. (mydid.un.b.area == ndlpdid.un.b.area)) {
  4204. if ((matchdid.un.b.domain == 0) &&
  4205. (matchdid.un.b.area == 0)) {
  4206. if (matchdid.un.b.id)
  4207. return 1;
  4208. }
  4209. }
  4210. }
  4211. return 0;
  4212. }
  4213. /* Search for a nodelist entry */
  4214. static struct lpfc_nodelist *
  4215. __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  4216. {
  4217. struct lpfc_nodelist *ndlp;
  4218. uint32_t data1;
  4219. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  4220. if (lpfc_matchdid(vport, ndlp, did)) {
  4221. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  4222. ((uint32_t) ndlp->nlp_xri << 16) |
  4223. ((uint32_t) ndlp->nlp_type << 8) |
  4224. ((uint32_t) ndlp->nlp_rpi & 0xff));
  4225. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  4226. "0929 FIND node DID "
  4227. "Data: x%p x%x x%x x%x\n",
  4228. ndlp, ndlp->nlp_DID,
  4229. ndlp->nlp_flag, data1);
  4230. return ndlp;
  4231. }
  4232. }
  4233. /* FIND node did <did> NOT FOUND */
  4234. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  4235. "0932 FIND node did x%x NOT FOUND.\n", did);
  4236. return NULL;
  4237. }
  4238. struct lpfc_nodelist *
  4239. lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  4240. {
  4241. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4242. struct lpfc_nodelist *ndlp;
  4243. unsigned long iflags;
  4244. spin_lock_irqsave(shost->host_lock, iflags);
  4245. ndlp = __lpfc_findnode_did(vport, did);
  4246. spin_unlock_irqrestore(shost->host_lock, iflags);
  4247. return ndlp;
  4248. }
  4249. struct lpfc_nodelist *
  4250. lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
  4251. {
  4252. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4253. struct lpfc_nodelist *ndlp;
  4254. ndlp = lpfc_findnode_did(vport, did);
  4255. if (!ndlp) {
  4256. if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
  4257. lpfc_rscn_payload_check(vport, did) == 0)
  4258. return NULL;
  4259. ndlp = (struct lpfc_nodelist *)
  4260. mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
  4261. if (!ndlp)
  4262. return NULL;
  4263. lpfc_nlp_init(vport, ndlp, did);
  4264. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  4265. spin_lock_irq(shost->host_lock);
  4266. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  4267. spin_unlock_irq(shost->host_lock);
  4268. return ndlp;
  4269. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  4270. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
  4271. if (!ndlp)
  4272. return NULL;
  4273. spin_lock_irq(shost->host_lock);
  4274. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  4275. spin_unlock_irq(shost->host_lock);
  4276. return ndlp;
  4277. }
  4278. if ((vport->fc_flag & FC_RSCN_MODE) &&
  4279. !(vport->fc_flag & FC_NDISC_ACTIVE)) {
  4280. if (lpfc_rscn_payload_check(vport, did)) {
  4281. /* If we've already received a PLOGI from this NPort
  4282. * we don't need to try to discover it again.
  4283. */
  4284. if (ndlp->nlp_flag & NLP_RCV_PLOGI)
  4285. return NULL;
  4286. /* Since this node is marked for discovery,
  4287. * delay timeout is not needed.
  4288. */
  4289. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  4290. spin_lock_irq(shost->host_lock);
  4291. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  4292. spin_unlock_irq(shost->host_lock);
  4293. } else
  4294. ndlp = NULL;
  4295. } else {
  4296. /* If we've already received a PLOGI from this NPort,
  4297. * or we are already in the process of discovery on it,
  4298. * we don't need to try to discover it again.
  4299. */
  4300. if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
  4301. ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  4302. ndlp->nlp_flag & NLP_RCV_PLOGI)
  4303. return NULL;
  4304. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  4305. spin_lock_irq(shost->host_lock);
  4306. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  4307. spin_unlock_irq(shost->host_lock);
  4308. }
  4309. return ndlp;
  4310. }
  4311. /* Build a list of nodes to discover based on the loopmap */
  4312. void
  4313. lpfc_disc_list_loopmap(struct lpfc_vport *vport)
  4314. {
  4315. struct lpfc_hba *phba = vport->phba;
  4316. int j;
  4317. uint32_t alpa, index;
  4318. if (!lpfc_is_link_up(phba))
  4319. return;
  4320. if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
  4321. return;
  4322. /* Check for loop map present or not */
  4323. if (phba->alpa_map[0]) {
  4324. for (j = 1; j <= phba->alpa_map[0]; j++) {
  4325. alpa = phba->alpa_map[j];
  4326. if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
  4327. continue;
  4328. lpfc_setup_disc_node(vport, alpa);
  4329. }
  4330. } else {
  4331. /* No alpamap, so try all alpa's */
  4332. for (j = 0; j < FC_MAXLOOP; j++) {
  4333. /* If cfg_scan_down is set, start from highest
  4334. * ALPA (0xef) to lowest (0x1).
  4335. */
  4336. if (vport->cfg_scan_down)
  4337. index = j;
  4338. else
  4339. index = FC_MAXLOOP - j - 1;
  4340. alpa = lpfcAlpaArray[index];
  4341. if ((vport->fc_myDID & 0xff) == alpa)
  4342. continue;
  4343. lpfc_setup_disc_node(vport, alpa);
  4344. }
  4345. }
  4346. return;
  4347. }
  4348. void
  4349. lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
  4350. {
  4351. LPFC_MBOXQ_t *mbox;
  4352. struct lpfc_sli *psli = &phba->sli;
  4353. struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
  4354. struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
  4355. struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
  4356. int rc;
  4357. /*
  4358. * if it's not a physical port or if we already send
  4359. * clear_la then don't send it.
  4360. */
  4361. if ((phba->link_state >= LPFC_CLEAR_LA) ||
  4362. (vport->port_type != LPFC_PHYSICAL_PORT) ||
  4363. (phba->sli_rev == LPFC_SLI_REV4))
  4364. return;
  4365. /* Link up discovery */
  4366. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
  4367. phba->link_state = LPFC_CLEAR_LA;
  4368. lpfc_clear_la(phba, mbox);
  4369. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  4370. mbox->vport = vport;
  4371. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4372. if (rc == MBX_NOT_FINISHED) {
  4373. mempool_free(mbox, phba->mbox_mem_pool);
  4374. lpfc_disc_flush_list(vport);
  4375. extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  4376. fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  4377. next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  4378. phba->link_state = LPFC_HBA_ERROR;
  4379. }
  4380. }
  4381. }
  4382. /* Reg_vpi to tell firmware to resume normal operations */
  4383. void
  4384. lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  4385. {
  4386. LPFC_MBOXQ_t *regvpimbox;
  4387. regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4388. if (regvpimbox) {
  4389. lpfc_reg_vpi(vport, regvpimbox);
  4390. regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
  4391. regvpimbox->vport = vport;
  4392. if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
  4393. == MBX_NOT_FINISHED) {
  4394. mempool_free(regvpimbox, phba->mbox_mem_pool);
  4395. }
  4396. }
  4397. }
  4398. /* Start Link up / RSCN discovery on NPR nodes */
  4399. void
  4400. lpfc_disc_start(struct lpfc_vport *vport)
  4401. {
  4402. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4403. struct lpfc_hba *phba = vport->phba;
  4404. uint32_t num_sent;
  4405. uint32_t clear_la_pending;
  4406. int did_changed;
  4407. if (!lpfc_is_link_up(phba))
  4408. return;
  4409. if (phba->link_state == LPFC_CLEAR_LA)
  4410. clear_la_pending = 1;
  4411. else
  4412. clear_la_pending = 0;
  4413. if (vport->port_state < LPFC_VPORT_READY)
  4414. vport->port_state = LPFC_DISC_AUTH;
  4415. lpfc_set_disctmo(vport);
  4416. if (vport->fc_prevDID == vport->fc_myDID)
  4417. did_changed = 0;
  4418. else
  4419. did_changed = 1;
  4420. vport->fc_prevDID = vport->fc_myDID;
  4421. vport->num_disc_nodes = 0;
  4422. /* Start Discovery state <hba_state> */
  4423. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4424. "0202 Start Discovery hba state x%x "
  4425. "Data: x%x x%x x%x\n",
  4426. vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
  4427. vport->fc_adisc_cnt);
  4428. /* First do ADISCs - if any */
  4429. num_sent = lpfc_els_disc_adisc(vport);
  4430. if (num_sent)
  4431. return;
  4432. /* Register the VPI for SLI3, NON-NPIV only. */
  4433. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  4434. !(vport->fc_flag & FC_PT2PT) &&
  4435. !(vport->fc_flag & FC_RSCN_MODE) &&
  4436. (phba->sli_rev < LPFC_SLI_REV4)) {
  4437. lpfc_issue_reg_vpi(phba, vport);
  4438. return;
  4439. }
  4440. /*
  4441. * For SLI2, we need to set port_state to READY and continue
  4442. * discovery.
  4443. */
  4444. if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
  4445. /* If we get here, there is nothing to ADISC */
  4446. if (vport->port_type == LPFC_PHYSICAL_PORT)
  4447. lpfc_issue_clear_la(phba, vport);
  4448. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  4449. vport->num_disc_nodes = 0;
  4450. /* go thru NPR nodes and issue ELS PLOGIs */
  4451. if (vport->fc_npr_cnt)
  4452. lpfc_els_disc_plogi(vport);
  4453. if (!vport->num_disc_nodes) {
  4454. spin_lock_irq(shost->host_lock);
  4455. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  4456. spin_unlock_irq(shost->host_lock);
  4457. lpfc_can_disctmo(vport);
  4458. }
  4459. }
  4460. vport->port_state = LPFC_VPORT_READY;
  4461. } else {
  4462. /* Next do PLOGIs - if any */
  4463. num_sent = lpfc_els_disc_plogi(vport);
  4464. if (num_sent)
  4465. return;
  4466. if (vport->fc_flag & FC_RSCN_MODE) {
  4467. /* Check to see if more RSCNs came in while we
  4468. * were processing this one.
  4469. */
  4470. if ((vport->fc_rscn_id_cnt == 0) &&
  4471. (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
  4472. spin_lock_irq(shost->host_lock);
  4473. vport->fc_flag &= ~FC_RSCN_MODE;
  4474. spin_unlock_irq(shost->host_lock);
  4475. lpfc_can_disctmo(vport);
  4476. } else
  4477. lpfc_els_handle_rscn(vport);
  4478. }
  4479. }
  4480. return;
  4481. }
  4482. /*
  4483. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  4484. * ring the match the sppecified nodelist.
  4485. */
  4486. static void
  4487. lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  4488. {
  4489. LIST_HEAD(completions);
  4490. struct lpfc_sli *psli;
  4491. IOCB_t *icmd;
  4492. struct lpfc_iocbq *iocb, *next_iocb;
  4493. struct lpfc_sli_ring *pring;
  4494. psli = &phba->sli;
  4495. pring = &psli->ring[LPFC_ELS_RING];
  4496. /* Error matching iocb on txq or txcmplq
  4497. * First check the txq.
  4498. */
  4499. spin_lock_irq(&phba->hbalock);
  4500. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  4501. if (iocb->context1 != ndlp) {
  4502. continue;
  4503. }
  4504. icmd = &iocb->iocb;
  4505. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  4506. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  4507. list_move_tail(&iocb->list, &completions);
  4508. pring->txq_cnt--;
  4509. }
  4510. }
  4511. /* Next check the txcmplq */
  4512. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  4513. if (iocb->context1 != ndlp) {
  4514. continue;
  4515. }
  4516. icmd = &iocb->iocb;
  4517. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
  4518. icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
  4519. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  4520. }
  4521. }
  4522. spin_unlock_irq(&phba->hbalock);
  4523. /* Cancel all the IOCBs from the completions list */
  4524. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  4525. IOERR_SLI_ABORTED);
  4526. }
  4527. static void
  4528. lpfc_disc_flush_list(struct lpfc_vport *vport)
  4529. {
  4530. struct lpfc_nodelist *ndlp, *next_ndlp;
  4531. struct lpfc_hba *phba = vport->phba;
  4532. if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
  4533. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  4534. nlp_listp) {
  4535. if (!NLP_CHK_NODE_ACT(ndlp))
  4536. continue;
  4537. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  4538. ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
  4539. lpfc_free_tx(phba, ndlp);
  4540. }
  4541. }
  4542. }
  4543. }
  4544. void
  4545. lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
  4546. {
  4547. lpfc_els_flush_rscn(vport);
  4548. lpfc_els_flush_cmd(vport);
  4549. lpfc_disc_flush_list(vport);
  4550. }
  4551. /*****************************************************************************/
  4552. /*
  4553. * NAME: lpfc_disc_timeout
  4554. *
  4555. * FUNCTION: Fibre Channel driver discovery timeout routine.
  4556. *
  4557. * EXECUTION ENVIRONMENT: interrupt only
  4558. *
  4559. * CALLED FROM:
  4560. * Timer function
  4561. *
  4562. * RETURNS:
  4563. * none
  4564. */
  4565. /*****************************************************************************/
  4566. void
  4567. lpfc_disc_timeout(unsigned long ptr)
  4568. {
  4569. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  4570. struct lpfc_hba *phba = vport->phba;
  4571. uint32_t tmo_posted;
  4572. unsigned long flags = 0;
  4573. if (unlikely(!phba))
  4574. return;
  4575. spin_lock_irqsave(&vport->work_port_lock, flags);
  4576. tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
  4577. if (!tmo_posted)
  4578. vport->work_port_events |= WORKER_DISC_TMO;
  4579. spin_unlock_irqrestore(&vport->work_port_lock, flags);
  4580. if (!tmo_posted)
  4581. lpfc_worker_wake_up(phba);
  4582. return;
  4583. }
  4584. static void
  4585. lpfc_disc_timeout_handler(struct lpfc_vport *vport)
  4586. {
  4587. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4588. struct lpfc_hba *phba = vport->phba;
  4589. struct lpfc_sli *psli = &phba->sli;
  4590. struct lpfc_nodelist *ndlp, *next_ndlp;
  4591. LPFC_MBOXQ_t *initlinkmbox;
  4592. int rc, clrlaerr = 0;
  4593. if (!(vport->fc_flag & FC_DISC_TMO))
  4594. return;
  4595. spin_lock_irq(shost->host_lock);
  4596. vport->fc_flag &= ~FC_DISC_TMO;
  4597. spin_unlock_irq(shost->host_lock);
  4598. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4599. "disc timeout: state:x%x rtry:x%x flg:x%x",
  4600. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  4601. switch (vport->port_state) {
  4602. case LPFC_LOCAL_CFG_LINK:
  4603. /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
  4604. * FAN
  4605. */
  4606. /* FAN timeout */
  4607. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  4608. "0221 FAN timeout\n");
  4609. /* Start discovery by sending FLOGI, clean up old rpis */
  4610. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  4611. nlp_listp) {
  4612. if (!NLP_CHK_NODE_ACT(ndlp))
  4613. continue;
  4614. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  4615. continue;
  4616. if (ndlp->nlp_type & NLP_FABRIC) {
  4617. /* Clean up the ndlp on Fabric connections */
  4618. lpfc_drop_node(vport, ndlp);
  4619. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  4620. /* Fail outstanding IO now since device
  4621. * is marked for PLOGI.
  4622. */
  4623. lpfc_unreg_rpi(vport, ndlp);
  4624. }
  4625. }
  4626. if (vport->port_state != LPFC_FLOGI) {
  4627. if (phba->sli_rev <= LPFC_SLI_REV3)
  4628. lpfc_initial_flogi(vport);
  4629. else
  4630. lpfc_issue_init_vfi(vport);
  4631. return;
  4632. }
  4633. break;
  4634. case LPFC_FDISC:
  4635. case LPFC_FLOGI:
  4636. /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  4637. /* Initial FLOGI timeout */
  4638. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4639. "0222 Initial %s timeout\n",
  4640. vport->vpi ? "FDISC" : "FLOGI");
  4641. /* Assume no Fabric and go on with discovery.
  4642. * Check for outstanding ELS FLOGI to abort.
  4643. */
  4644. /* FLOGI failed, so just use loop map to make discovery list */
  4645. lpfc_disc_list_loopmap(vport);
  4646. /* Start discovery */
  4647. lpfc_disc_start(vport);
  4648. break;
  4649. case LPFC_FABRIC_CFG_LINK:
  4650. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  4651. NameServer login */
  4652. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4653. "0223 Timeout while waiting for "
  4654. "NameServer login\n");
  4655. /* Next look for NameServer ndlp */
  4656. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  4657. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  4658. lpfc_els_abort(phba, ndlp);
  4659. /* ReStart discovery */
  4660. goto restart_disc;
  4661. case LPFC_NS_QRY:
  4662. /* Check for wait for NameServer Rsp timeout */
  4663. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4664. "0224 NameServer Query timeout "
  4665. "Data: x%x x%x\n",
  4666. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  4667. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  4668. /* Try it one more time */
  4669. vport->fc_ns_retry++;
  4670. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  4671. vport->fc_ns_retry, 0);
  4672. if (rc == 0)
  4673. break;
  4674. }
  4675. vport->fc_ns_retry = 0;
  4676. restart_disc:
  4677. /*
  4678. * Discovery is over.
  4679. * set port_state to PORT_READY if SLI2.
  4680. * cmpl_reg_vpi will set port_state to READY for SLI3.
  4681. */
  4682. if (phba->sli_rev < LPFC_SLI_REV4) {
  4683. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  4684. lpfc_issue_reg_vpi(phba, vport);
  4685. else {
  4686. lpfc_issue_clear_la(phba, vport);
  4687. vport->port_state = LPFC_VPORT_READY;
  4688. }
  4689. }
  4690. /* Setup and issue mailbox INITIALIZE LINK command */
  4691. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4692. if (!initlinkmbox) {
  4693. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4694. "0206 Device Discovery "
  4695. "completion error\n");
  4696. phba->link_state = LPFC_HBA_ERROR;
  4697. break;
  4698. }
  4699. lpfc_linkdown(phba);
  4700. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  4701. phba->cfg_link_speed);
  4702. initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  4703. initlinkmbox->vport = vport;
  4704. initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4705. rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
  4706. lpfc_set_loopback_flag(phba);
  4707. if (rc == MBX_NOT_FINISHED)
  4708. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  4709. break;
  4710. case LPFC_DISC_AUTH:
  4711. /* Node Authentication timeout */
  4712. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4713. "0227 Node Authentication timeout\n");
  4714. lpfc_disc_flush_list(vport);
  4715. /*
  4716. * set port_state to PORT_READY if SLI2.
  4717. * cmpl_reg_vpi will set port_state to READY for SLI3.
  4718. */
  4719. if (phba->sli_rev < LPFC_SLI_REV4) {
  4720. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  4721. lpfc_issue_reg_vpi(phba, vport);
  4722. else { /* NPIV Not enabled */
  4723. lpfc_issue_clear_la(phba, vport);
  4724. vport->port_state = LPFC_VPORT_READY;
  4725. }
  4726. }
  4727. break;
  4728. case LPFC_VPORT_READY:
  4729. if (vport->fc_flag & FC_RSCN_MODE) {
  4730. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4731. "0231 RSCN timeout Data: x%x "
  4732. "x%x\n",
  4733. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  4734. /* Cleanup any outstanding ELS commands */
  4735. lpfc_els_flush_cmd(vport);
  4736. lpfc_els_flush_rscn(vport);
  4737. lpfc_disc_flush_list(vport);
  4738. }
  4739. break;
  4740. default:
  4741. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4742. "0273 Unexpected discovery timeout, "
  4743. "vport State x%x\n", vport->port_state);
  4744. break;
  4745. }
  4746. switch (phba->link_state) {
  4747. case LPFC_CLEAR_LA:
  4748. /* CLEAR LA timeout */
  4749. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4750. "0228 CLEAR LA timeout\n");
  4751. clrlaerr = 1;
  4752. break;
  4753. case LPFC_LINK_UP:
  4754. lpfc_issue_clear_la(phba, vport);
  4755. /* Drop thru */
  4756. case LPFC_LINK_UNKNOWN:
  4757. case LPFC_WARM_START:
  4758. case LPFC_INIT_START:
  4759. case LPFC_INIT_MBX_CMDS:
  4760. case LPFC_LINK_DOWN:
  4761. case LPFC_HBA_ERROR:
  4762. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4763. "0230 Unexpected timeout, hba link "
  4764. "state x%x\n", phba->link_state);
  4765. clrlaerr = 1;
  4766. break;
  4767. case LPFC_HBA_READY:
  4768. break;
  4769. }
  4770. if (clrlaerr) {
  4771. lpfc_disc_flush_list(vport);
  4772. psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  4773. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  4774. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  4775. vport->port_state = LPFC_VPORT_READY;
  4776. }
  4777. return;
  4778. }
  4779. /*
  4780. * This routine handles processing a NameServer REG_LOGIN mailbox
  4781. * command upon completion. It is setup in the LPFC_MBOXQ
  4782. * as the completion routine when the command is
  4783. * handed off to the SLI layer.
  4784. */
  4785. void
  4786. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4787. {
  4788. MAILBOX_t *mb = &pmb->u.mb;
  4789. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  4790. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  4791. struct lpfc_vport *vport = pmb->vport;
  4792. pmb->context1 = NULL;
  4793. pmb->context2 = NULL;
  4794. if (phba->sli_rev < LPFC_SLI_REV4)
  4795. ndlp->nlp_rpi = mb->un.varWords[0];
  4796. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  4797. ndlp->nlp_type |= NLP_FABRIC;
  4798. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  4799. /*
  4800. * Start issuing Fabric-Device Management Interface (FDMI) command to
  4801. * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
  4802. * fdmi-on=2 (supporting RPA/hostnmae)
  4803. */
  4804. if (vport->cfg_fdmi_on == 1)
  4805. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  4806. else
  4807. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  4808. /* decrement the node reference count held for this callback
  4809. * function.
  4810. */
  4811. lpfc_nlp_put(ndlp);
  4812. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4813. kfree(mp);
  4814. mempool_free(pmb, phba->mbox_mem_pool);
  4815. return;
  4816. }
  4817. static int
  4818. lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
  4819. {
  4820. uint16_t *rpi = param;
  4821. /* check for active node */
  4822. if (!NLP_CHK_NODE_ACT(ndlp))
  4823. return 0;
  4824. return ndlp->nlp_rpi == *rpi;
  4825. }
  4826. static int
  4827. lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
  4828. {
  4829. return memcmp(&ndlp->nlp_portname, param,
  4830. sizeof(ndlp->nlp_portname)) == 0;
  4831. }
  4832. static struct lpfc_nodelist *
  4833. __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
  4834. {
  4835. struct lpfc_nodelist *ndlp;
  4836. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  4837. if (filter(ndlp, param))
  4838. return ndlp;
  4839. }
  4840. return NULL;
  4841. }
  4842. /*
  4843. * This routine looks up the ndlp lists for the given RPI. If rpi found it
  4844. * returns the node list element pointer else return NULL.
  4845. */
  4846. struct lpfc_nodelist *
  4847. __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  4848. {
  4849. return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
  4850. }
  4851. /*
  4852. * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
  4853. * returns the node element list pointer else return NULL.
  4854. */
  4855. struct lpfc_nodelist *
  4856. lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
  4857. {
  4858. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4859. struct lpfc_nodelist *ndlp;
  4860. spin_lock_irq(shost->host_lock);
  4861. ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
  4862. spin_unlock_irq(shost->host_lock);
  4863. return ndlp;
  4864. }
  4865. /*
  4866. * This routine looks up the ndlp lists for the given RPI. If the rpi
  4867. * is found, the routine returns the node element list pointer else
  4868. * return NULL.
  4869. */
  4870. struct lpfc_nodelist *
  4871. lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  4872. {
  4873. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4874. struct lpfc_nodelist *ndlp;
  4875. spin_lock_irq(shost->host_lock);
  4876. ndlp = __lpfc_findnode_rpi(vport, rpi);
  4877. spin_unlock_irq(shost->host_lock);
  4878. return ndlp;
  4879. }
  4880. /**
  4881. * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
  4882. * @phba: pointer to lpfc hba data structure.
  4883. * @vpi: the physical host virtual N_Port identifier.
  4884. *
  4885. * This routine finds a vport on a HBA (referred by @phba) through a
  4886. * @vpi. The function walks the HBA's vport list and returns the address
  4887. * of the vport with the matching @vpi.
  4888. *
  4889. * Return code
  4890. * NULL - No vport with the matching @vpi found
  4891. * Otherwise - Address to the vport with the matching @vpi.
  4892. **/
  4893. struct lpfc_vport *
  4894. lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
  4895. {
  4896. struct lpfc_vport *vport;
  4897. unsigned long flags;
  4898. int i = 0;
  4899. /* The physical ports are always vpi 0 - translate is unnecessary. */
  4900. if (vpi > 0) {
  4901. /*
  4902. * Translate the physical vpi to the logical vpi. The
  4903. * vport stores the logical vpi.
  4904. */
  4905. for (i = 0; i < phba->max_vpi; i++) {
  4906. if (vpi == phba->vpi_ids[i])
  4907. break;
  4908. }
  4909. if (i >= phba->max_vpi) {
  4910. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  4911. "2936 Could not find Vport mapped "
  4912. "to vpi %d\n", vpi);
  4913. return NULL;
  4914. }
  4915. }
  4916. spin_lock_irqsave(&phba->hbalock, flags);
  4917. list_for_each_entry(vport, &phba->port_list, listentry) {
  4918. if (vport->vpi == i) {
  4919. spin_unlock_irqrestore(&phba->hbalock, flags);
  4920. return vport;
  4921. }
  4922. }
  4923. spin_unlock_irqrestore(&phba->hbalock, flags);
  4924. return NULL;
  4925. }
  4926. void
  4927. lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  4928. uint32_t did)
  4929. {
  4930. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  4931. lpfc_initialize_node(vport, ndlp, did);
  4932. INIT_LIST_HEAD(&ndlp->nlp_listp);
  4933. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  4934. "node init: did:x%x",
  4935. ndlp->nlp_DID, 0, 0);
  4936. return;
  4937. }
  4938. /* This routine releases all resources associated with a specifc NPort's ndlp
  4939. * and mempool_free's the nodelist.
  4940. */
  4941. static void
  4942. lpfc_nlp_release(struct kref *kref)
  4943. {
  4944. struct lpfc_hba *phba;
  4945. unsigned long flags;
  4946. struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
  4947. kref);
  4948. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  4949. "node release: did:x%x flg:x%x type:x%x",
  4950. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  4951. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
  4952. "0279 lpfc_nlp_release: ndlp:x%p "
  4953. "usgmap:x%x refcnt:%d\n",
  4954. (void *)ndlp, ndlp->nlp_usg_map,
  4955. atomic_read(&ndlp->kref.refcount));
  4956. /* remove ndlp from action. */
  4957. lpfc_nlp_remove(ndlp->vport, ndlp);
  4958. /* clear the ndlp active flag for all release cases */
  4959. phba = ndlp->phba;
  4960. spin_lock_irqsave(&phba->ndlp_lock, flags);
  4961. NLP_CLR_NODE_ACT(ndlp);
  4962. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  4963. if (phba->sli_rev == LPFC_SLI_REV4)
  4964. lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
  4965. /* free ndlp memory for final ndlp release */
  4966. if (NLP_CHK_FREE_REQ(ndlp)) {
  4967. kfree(ndlp->lat_data);
  4968. mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
  4969. }
  4970. }
  4971. /* This routine bumps the reference count for a ndlp structure to ensure
  4972. * that one discovery thread won't free a ndlp while another discovery thread
  4973. * is using it.
  4974. */
  4975. struct lpfc_nodelist *
  4976. lpfc_nlp_get(struct lpfc_nodelist *ndlp)
  4977. {
  4978. struct lpfc_hba *phba;
  4979. unsigned long flags;
  4980. if (ndlp) {
  4981. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  4982. "node get: did:x%x flg:x%x refcnt:x%x",
  4983. ndlp->nlp_DID, ndlp->nlp_flag,
  4984. atomic_read(&ndlp->kref.refcount));
  4985. /* The check of ndlp usage to prevent incrementing the
  4986. * ndlp reference count that is in the process of being
  4987. * released.
  4988. */
  4989. phba = ndlp->phba;
  4990. spin_lock_irqsave(&phba->ndlp_lock, flags);
  4991. if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
  4992. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  4993. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  4994. "0276 lpfc_nlp_get: ndlp:x%p "
  4995. "usgmap:x%x refcnt:%d\n",
  4996. (void *)ndlp, ndlp->nlp_usg_map,
  4997. atomic_read(&ndlp->kref.refcount));
  4998. return NULL;
  4999. } else
  5000. kref_get(&ndlp->kref);
  5001. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  5002. }
  5003. return ndlp;
  5004. }
  5005. /* This routine decrements the reference count for a ndlp structure. If the
  5006. * count goes to 0, this indicates the the associated nodelist should be
  5007. * freed. Returning 1 indicates the ndlp resource has been released; on the
  5008. * other hand, returning 0 indicates the ndlp resource has not been released
  5009. * yet.
  5010. */
  5011. int
  5012. lpfc_nlp_put(struct lpfc_nodelist *ndlp)
  5013. {
  5014. struct lpfc_hba *phba;
  5015. unsigned long flags;
  5016. if (!ndlp)
  5017. return 1;
  5018. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  5019. "node put: did:x%x flg:x%x refcnt:x%x",
  5020. ndlp->nlp_DID, ndlp->nlp_flag,
  5021. atomic_read(&ndlp->kref.refcount));
  5022. phba = ndlp->phba;
  5023. spin_lock_irqsave(&phba->ndlp_lock, flags);
  5024. /* Check the ndlp memory free acknowledge flag to avoid the
  5025. * possible race condition that kref_put got invoked again
  5026. * after previous one has done ndlp memory free.
  5027. */
  5028. if (NLP_CHK_FREE_ACK(ndlp)) {
  5029. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  5030. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  5031. "0274 lpfc_nlp_put: ndlp:x%p "
  5032. "usgmap:x%x refcnt:%d\n",
  5033. (void *)ndlp, ndlp->nlp_usg_map,
  5034. atomic_read(&ndlp->kref.refcount));
  5035. return 1;
  5036. }
  5037. /* Check the ndlp inactivate log flag to avoid the possible
  5038. * race condition that kref_put got invoked again after ndlp
  5039. * is already in inactivating state.
  5040. */
  5041. if (NLP_CHK_IACT_REQ(ndlp)) {
  5042. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  5043. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  5044. "0275 lpfc_nlp_put: ndlp:x%p "
  5045. "usgmap:x%x refcnt:%d\n",
  5046. (void *)ndlp, ndlp->nlp_usg_map,
  5047. atomic_read(&ndlp->kref.refcount));
  5048. return 1;
  5049. }
  5050. /* For last put, mark the ndlp usage flags to make sure no
  5051. * other kref_get and kref_put on the same ndlp shall get
  5052. * in between the process when the final kref_put has been
  5053. * invoked on this ndlp.
  5054. */
  5055. if (atomic_read(&ndlp->kref.refcount) == 1) {
  5056. /* Indicate ndlp is put to inactive state. */
  5057. NLP_SET_IACT_REQ(ndlp);
  5058. /* Acknowledge ndlp memory free has been seen. */
  5059. if (NLP_CHK_FREE_REQ(ndlp))
  5060. NLP_SET_FREE_ACK(ndlp);
  5061. }
  5062. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  5063. /* Note, the kref_put returns 1 when decrementing a reference
  5064. * count that was 1, it invokes the release callback function,
  5065. * but it still left the reference count as 1 (not actually
  5066. * performs the last decrementation). Otherwise, it actually
  5067. * decrements the reference count and returns 0.
  5068. */
  5069. return kref_put(&ndlp->kref, lpfc_nlp_release);
  5070. }
  5071. /* This routine free's the specified nodelist if it is not in use
  5072. * by any other discovery thread. This routine returns 1 if the
  5073. * ndlp has been freed. A return value of 0 indicates the ndlp is
  5074. * not yet been released.
  5075. */
  5076. int
  5077. lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
  5078. {
  5079. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  5080. "node not used: did:x%x flg:x%x refcnt:x%x",
  5081. ndlp->nlp_DID, ndlp->nlp_flag,
  5082. atomic_read(&ndlp->kref.refcount));
  5083. if (atomic_read(&ndlp->kref.refcount) == 1)
  5084. if (lpfc_nlp_put(ndlp))
  5085. return 1;
  5086. return 0;
  5087. }
  5088. /**
  5089. * lpfc_fcf_inuse - Check if FCF can be unregistered.
  5090. * @phba: Pointer to hba context object.
  5091. *
  5092. * This function iterate through all FC nodes associated
  5093. * will all vports to check if there is any node with
  5094. * fc_rports associated with it. If there is an fc_rport
  5095. * associated with the node, then the node is either in
  5096. * discovered state or its devloss_timer is pending.
  5097. */
  5098. static int
  5099. lpfc_fcf_inuse(struct lpfc_hba *phba)
  5100. {
  5101. struct lpfc_vport **vports;
  5102. int i, ret = 0;
  5103. struct lpfc_nodelist *ndlp;
  5104. struct Scsi_Host *shost;
  5105. vports = lpfc_create_vport_work_array(phba);
  5106. /* If driver cannot allocate memory, indicate fcf is in use */
  5107. if (!vports)
  5108. return 1;
  5109. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  5110. shost = lpfc_shost_from_vport(vports[i]);
  5111. spin_lock_irq(shost->host_lock);
  5112. /*
  5113. * IF the CVL_RCVD bit is not set then we have sent the
  5114. * flogi.
  5115. * If dev_loss fires while we are waiting we do not want to
  5116. * unreg the fcf.
  5117. */
  5118. if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
  5119. spin_unlock_irq(shost->host_lock);
  5120. ret = 1;
  5121. goto out;
  5122. }
  5123. list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
  5124. if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
  5125. (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
  5126. ret = 1;
  5127. spin_unlock_irq(shost->host_lock);
  5128. goto out;
  5129. } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
  5130. ret = 1;
  5131. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  5132. "2624 RPI %x DID %x flag %x "
  5133. "still logged in\n",
  5134. ndlp->nlp_rpi, ndlp->nlp_DID,
  5135. ndlp->nlp_flag);
  5136. }
  5137. }
  5138. spin_unlock_irq(shost->host_lock);
  5139. }
  5140. out:
  5141. lpfc_destroy_vport_work_array(phba, vports);
  5142. return ret;
  5143. }
  5144. /**
  5145. * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
  5146. * @phba: Pointer to hba context object.
  5147. * @mboxq: Pointer to mailbox object.
  5148. *
  5149. * This function frees memory associated with the mailbox command.
  5150. */
  5151. void
  5152. lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5153. {
  5154. struct lpfc_vport *vport = mboxq->vport;
  5155. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5156. if (mboxq->u.mb.mbxStatus) {
  5157. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  5158. "2555 UNREG_VFI mbxStatus error x%x "
  5159. "HBA state x%x\n",
  5160. mboxq->u.mb.mbxStatus, vport->port_state);
  5161. }
  5162. spin_lock_irq(shost->host_lock);
  5163. phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
  5164. spin_unlock_irq(shost->host_lock);
  5165. mempool_free(mboxq, phba->mbox_mem_pool);
  5166. return;
  5167. }
  5168. /**
  5169. * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
  5170. * @phba: Pointer to hba context object.
  5171. * @mboxq: Pointer to mailbox object.
  5172. *
  5173. * This function frees memory associated with the mailbox command.
  5174. */
  5175. static void
  5176. lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5177. {
  5178. struct lpfc_vport *vport = mboxq->vport;
  5179. if (mboxq->u.mb.mbxStatus) {
  5180. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  5181. "2550 UNREG_FCFI mbxStatus error x%x "
  5182. "HBA state x%x\n",
  5183. mboxq->u.mb.mbxStatus, vport->port_state);
  5184. }
  5185. mempool_free(mboxq, phba->mbox_mem_pool);
  5186. return;
  5187. }
  5188. /**
  5189. * lpfc_unregister_fcf_prep - Unregister fcf record preparation
  5190. * @phba: Pointer to hba context object.
  5191. *
  5192. * This function prepare the HBA for unregistering the currently registered
  5193. * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
  5194. * VFIs.
  5195. */
  5196. int
  5197. lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
  5198. {
  5199. struct lpfc_vport **vports;
  5200. struct lpfc_nodelist *ndlp;
  5201. struct Scsi_Host *shost;
  5202. int i, rc;
  5203. /* Unregister RPIs */
  5204. if (lpfc_fcf_inuse(phba))
  5205. lpfc_unreg_hba_rpis(phba);
  5206. /* At this point, all discovery is aborted */
  5207. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  5208. /* Unregister VPIs */
  5209. vports = lpfc_create_vport_work_array(phba);
  5210. if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
  5211. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  5212. /* Stop FLOGI/FDISC retries */
  5213. ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
  5214. if (ndlp)
  5215. lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
  5216. lpfc_cleanup_pending_mbox(vports[i]);
  5217. if (phba->sli_rev == LPFC_SLI_REV4)
  5218. lpfc_sli4_unreg_all_rpis(vports[i]);
  5219. lpfc_mbx_unreg_vpi(vports[i]);
  5220. shost = lpfc_shost_from_vport(vports[i]);
  5221. spin_lock_irq(shost->host_lock);
  5222. vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  5223. vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
  5224. spin_unlock_irq(shost->host_lock);
  5225. }
  5226. lpfc_destroy_vport_work_array(phba, vports);
  5227. /* Cleanup any outstanding ELS commands */
  5228. lpfc_els_flush_all_cmd(phba);
  5229. /* Unregister the physical port VFI */
  5230. rc = lpfc_issue_unreg_vfi(phba->pport);
  5231. return rc;
  5232. }
  5233. /**
  5234. * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
  5235. * @phba: Pointer to hba context object.
  5236. *
  5237. * This function issues synchronous unregister FCF mailbox command to HBA to
  5238. * unregister the currently registered FCF record. The driver does not reset
  5239. * the driver FCF usage state flags.
  5240. *
  5241. * Return 0 if successfully issued, none-zero otherwise.
  5242. */
  5243. int
  5244. lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
  5245. {
  5246. LPFC_MBOXQ_t *mbox;
  5247. int rc;
  5248. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5249. if (!mbox) {
  5250. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  5251. "2551 UNREG_FCFI mbox allocation failed"
  5252. "HBA state x%x\n", phba->pport->port_state);
  5253. return -ENOMEM;
  5254. }
  5255. lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
  5256. mbox->vport = phba->pport;
  5257. mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
  5258. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  5259. if (rc == MBX_NOT_FINISHED) {
  5260. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5261. "2552 Unregister FCFI command failed rc x%x "
  5262. "HBA state x%x\n",
  5263. rc, phba->pport->port_state);
  5264. return -EINVAL;
  5265. }
  5266. return 0;
  5267. }
  5268. /**
  5269. * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
  5270. * @phba: Pointer to hba context object.
  5271. *
  5272. * This function unregisters the currently reigstered FCF. This function
  5273. * also tries to find another FCF for discovery by rescan the HBA FCF table.
  5274. */
  5275. void
  5276. lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
  5277. {
  5278. int rc;
  5279. /* Preparation for unregistering fcf */
  5280. rc = lpfc_unregister_fcf_prep(phba);
  5281. if (rc) {
  5282. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  5283. "2748 Failed to prepare for unregistering "
  5284. "HBA's FCF record: rc=%d\n", rc);
  5285. return;
  5286. }
  5287. /* Now, unregister FCF record and reset HBA FCF state */
  5288. rc = lpfc_sli4_unregister_fcf(phba);
  5289. if (rc)
  5290. return;
  5291. /* Reset HBA FCF states after successful unregister FCF */
  5292. phba->fcf.fcf_flag = 0;
  5293. phba->fcf.current_rec.flag = 0;
  5294. /*
  5295. * If driver is not unloading, check if there is any other
  5296. * FCF record that can be used for discovery.
  5297. */
  5298. if ((phba->pport->load_flag & FC_UNLOADING) ||
  5299. (phba->link_state < LPFC_LINK_UP))
  5300. return;
  5301. /* This is considered as the initial FCF discovery scan */
  5302. spin_lock_irq(&phba->hbalock);
  5303. phba->fcf.fcf_flag |= FCF_INIT_DISC;
  5304. spin_unlock_irq(&phba->hbalock);
  5305. /* Reset FCF roundrobin bmask for new discovery */
  5306. lpfc_sli4_clear_fcf_rr_bmask(phba);
  5307. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  5308. if (rc) {
  5309. spin_lock_irq(&phba->hbalock);
  5310. phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
  5311. spin_unlock_irq(&phba->hbalock);
  5312. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  5313. "2553 lpfc_unregister_unused_fcf failed "
  5314. "to read FCF record HBA state x%x\n",
  5315. phba->pport->port_state);
  5316. }
  5317. }
  5318. /**
  5319. * lpfc_unregister_fcf - Unregister the currently registered fcf record
  5320. * @phba: Pointer to hba context object.
  5321. *
  5322. * This function just unregisters the currently reigstered FCF. It does not
  5323. * try to find another FCF for discovery.
  5324. */
  5325. void
  5326. lpfc_unregister_fcf(struct lpfc_hba *phba)
  5327. {
  5328. int rc;
  5329. /* Preparation for unregistering fcf */
  5330. rc = lpfc_unregister_fcf_prep(phba);
  5331. if (rc) {
  5332. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  5333. "2749 Failed to prepare for unregistering "
  5334. "HBA's FCF record: rc=%d\n", rc);
  5335. return;
  5336. }
  5337. /* Now, unregister FCF record and reset HBA FCF state */
  5338. rc = lpfc_sli4_unregister_fcf(phba);
  5339. if (rc)
  5340. return;
  5341. /* Set proper HBA FCF states after successful unregister FCF */
  5342. spin_lock_irq(&phba->hbalock);
  5343. phba->fcf.fcf_flag &= ~FCF_REGISTERED;
  5344. spin_unlock_irq(&phba->hbalock);
  5345. }
  5346. /**
  5347. * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
  5348. * @phba: Pointer to hba context object.
  5349. *
  5350. * This function check if there are any connected remote port for the FCF and
  5351. * if all the devices are disconnected, this function unregister FCFI.
  5352. * This function also tries to use another FCF for discovery.
  5353. */
  5354. void
  5355. lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
  5356. {
  5357. /*
  5358. * If HBA is not running in FIP mode, if HBA does not support
  5359. * FCoE, if FCF discovery is ongoing, or if FCF has not been
  5360. * registered, do nothing.
  5361. */
  5362. spin_lock_irq(&phba->hbalock);
  5363. if (!(phba->hba_flag & HBA_FCOE_MODE) ||
  5364. !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
  5365. !(phba->hba_flag & HBA_FIP_SUPPORT) ||
  5366. (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
  5367. (phba->pport->port_state == LPFC_FLOGI)) {
  5368. spin_unlock_irq(&phba->hbalock);
  5369. return;
  5370. }
  5371. spin_unlock_irq(&phba->hbalock);
  5372. if (lpfc_fcf_inuse(phba))
  5373. return;
  5374. lpfc_unregister_fcf_rescan(phba);
  5375. }
  5376. /**
  5377. * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
  5378. * @phba: Pointer to hba context object.
  5379. * @buff: Buffer containing the FCF connection table as in the config
  5380. * region.
  5381. * This function create driver data structure for the FCF connection
  5382. * record table read from config region 23.
  5383. */
  5384. static void
  5385. lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
  5386. uint8_t *buff)
  5387. {
  5388. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  5389. struct lpfc_fcf_conn_hdr *conn_hdr;
  5390. struct lpfc_fcf_conn_rec *conn_rec;
  5391. uint32_t record_count;
  5392. int i;
  5393. /* Free the current connect table */
  5394. list_for_each_entry_safe(conn_entry, next_conn_entry,
  5395. &phba->fcf_conn_rec_list, list) {
  5396. list_del_init(&conn_entry->list);
  5397. kfree(conn_entry);
  5398. }
  5399. conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
  5400. record_count = conn_hdr->length * sizeof(uint32_t)/
  5401. sizeof(struct lpfc_fcf_conn_rec);
  5402. conn_rec = (struct lpfc_fcf_conn_rec *)
  5403. (buff + sizeof(struct lpfc_fcf_conn_hdr));
  5404. for (i = 0; i < record_count; i++) {
  5405. if (!(conn_rec[i].flags & FCFCNCT_VALID))
  5406. continue;
  5407. conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
  5408. GFP_KERNEL);
  5409. if (!conn_entry) {
  5410. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5411. "2566 Failed to allocate connection"
  5412. " table entry\n");
  5413. return;
  5414. }
  5415. memcpy(&conn_entry->conn_rec, &conn_rec[i],
  5416. sizeof(struct lpfc_fcf_conn_rec));
  5417. conn_entry->conn_rec.vlan_tag =
  5418. le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
  5419. conn_entry->conn_rec.flags =
  5420. le16_to_cpu(conn_entry->conn_rec.flags);
  5421. list_add_tail(&conn_entry->list,
  5422. &phba->fcf_conn_rec_list);
  5423. }
  5424. }
  5425. /**
  5426. * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
  5427. * @phba: Pointer to hba context object.
  5428. * @buff: Buffer containing the FCoE parameter data structure.
  5429. *
  5430. * This function update driver data structure with config
  5431. * parameters read from config region 23.
  5432. */
  5433. static void
  5434. lpfc_read_fcoe_param(struct lpfc_hba *phba,
  5435. uint8_t *buff)
  5436. {
  5437. struct lpfc_fip_param_hdr *fcoe_param_hdr;
  5438. struct lpfc_fcoe_params *fcoe_param;
  5439. fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
  5440. buff;
  5441. fcoe_param = (struct lpfc_fcoe_params *)
  5442. (buff + sizeof(struct lpfc_fip_param_hdr));
  5443. if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
  5444. (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
  5445. return;
  5446. if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
  5447. phba->valid_vlan = 1;
  5448. phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
  5449. 0xFFF;
  5450. }
  5451. phba->fc_map[0] = fcoe_param->fc_map[0];
  5452. phba->fc_map[1] = fcoe_param->fc_map[1];
  5453. phba->fc_map[2] = fcoe_param->fc_map[2];
  5454. return;
  5455. }
  5456. /**
  5457. * lpfc_get_rec_conf23 - Get a record type in config region data.
  5458. * @buff: Buffer containing config region 23 data.
  5459. * @size: Size of the data buffer.
  5460. * @rec_type: Record type to be searched.
  5461. *
  5462. * This function searches config region data to find the beginning
  5463. * of the record specified by record_type. If record found, this
  5464. * function return pointer to the record else return NULL.
  5465. */
  5466. static uint8_t *
  5467. lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
  5468. {
  5469. uint32_t offset = 0, rec_length;
  5470. if ((buff[0] == LPFC_REGION23_LAST_REC) ||
  5471. (size < sizeof(uint32_t)))
  5472. return NULL;
  5473. rec_length = buff[offset + 1];
  5474. /*
  5475. * One TLV record has one word header and number of data words
  5476. * specified in the rec_length field of the record header.
  5477. */
  5478. while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
  5479. <= size) {
  5480. if (buff[offset] == rec_type)
  5481. return &buff[offset];
  5482. if (buff[offset] == LPFC_REGION23_LAST_REC)
  5483. return NULL;
  5484. offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
  5485. rec_length = buff[offset + 1];
  5486. }
  5487. return NULL;
  5488. }
  5489. /**
  5490. * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
  5491. * @phba: Pointer to lpfc_hba data structure.
  5492. * @buff: Buffer containing config region 23 data.
  5493. * @size: Size of the data buffer.
  5494. *
  5495. * This function parses the FCoE config parameters in config region 23 and
  5496. * populate driver data structure with the parameters.
  5497. */
  5498. void
  5499. lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
  5500. uint8_t *buff,
  5501. uint32_t size)
  5502. {
  5503. uint32_t offset = 0, rec_length;
  5504. uint8_t *rec_ptr;
  5505. /*
  5506. * If data size is less than 2 words signature and version cannot be
  5507. * verified.
  5508. */
  5509. if (size < 2*sizeof(uint32_t))
  5510. return;
  5511. /* Check the region signature first */
  5512. if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
  5513. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5514. "2567 Config region 23 has bad signature\n");
  5515. return;
  5516. }
  5517. offset += 4;
  5518. /* Check the data structure version */
  5519. if (buff[offset] != LPFC_REGION23_VERSION) {
  5520. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5521. "2568 Config region 23 has bad version\n");
  5522. return;
  5523. }
  5524. offset += 4;
  5525. rec_length = buff[offset + 1];
  5526. /* Read FCoE param record */
  5527. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  5528. size - offset, FCOE_PARAM_TYPE);
  5529. if (rec_ptr)
  5530. lpfc_read_fcoe_param(phba, rec_ptr);
  5531. /* Read FCF connection table */
  5532. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  5533. size - offset, FCOE_CONN_TBL_TYPE);
  5534. if (rec_ptr)
  5535. lpfc_read_fcf_conn_tbl(phba, rec_ptr);
  5536. }