lpfc_hbadisc.c 176 KB

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