lpfc_hbadisc.c 182 KB

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