lpfc_hbadisc.c 181 KB

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