lpfc_hbadisc.c 183 KB

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