lpfc_hbadisc.c 188 KB

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