lpfc_hbadisc.c 166 KB

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