lpfc_hbadisc.c 211 KB

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