lpfc_hbadisc.c 165 KB

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