lpfc_hbadisc.c 169 KB

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