lpfc_hbadisc.c 181 KB

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