lpfc_hbadisc.c 179 KB

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