lpfc_hbadisc.c 181 KB

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