lpfc_els.c 258 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2012 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. /* See Fibre Channel protocol T11 FC-LS for details */
  22. #include <linux/blkdev.h>
  23. #include <linux/pci.h>
  24. #include <linux/slab.h>
  25. #include <linux/interrupt.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include "lpfc_hw4.h"
  31. #include "lpfc_hw.h"
  32. #include "lpfc_sli.h"
  33. #include "lpfc_sli4.h"
  34. #include "lpfc_nl.h"
  35. #include "lpfc_disc.h"
  36. #include "lpfc_scsi.h"
  37. #include "lpfc.h"
  38. #include "lpfc_logmsg.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_vport.h"
  41. #include "lpfc_debugfs.h"
  42. static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
  43. struct lpfc_iocbq *);
  44. static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
  45. struct lpfc_iocbq *);
  46. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
  47. static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
  48. struct lpfc_nodelist *ndlp, uint8_t retry);
  49. static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
  50. struct lpfc_iocbq *iocb);
  51. static int lpfc_max_els_tries = 3;
  52. /**
  53. * lpfc_els_chk_latt - Check host link attention event for a vport
  54. * @vport: pointer to a host virtual N_Port data structure.
  55. *
  56. * This routine checks whether there is an outstanding host link
  57. * attention event during the discovery process with the @vport. It is done
  58. * by reading the HBA's Host Attention (HA) register. If there is any host
  59. * link attention events during this @vport's discovery process, the @vport
  60. * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
  61. * be issued if the link state is not already in host link cleared state,
  62. * and a return code shall indicate whether the host link attention event
  63. * had happened.
  64. *
  65. * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
  66. * state in LPFC_VPORT_READY, the request for checking host link attention
  67. * event will be ignored and a return code shall indicate no host link
  68. * attention event had happened.
  69. *
  70. * Return codes
  71. * 0 - no host link attention event happened
  72. * 1 - host link attention event happened
  73. **/
  74. int
  75. lpfc_els_chk_latt(struct lpfc_vport *vport)
  76. {
  77. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  78. struct lpfc_hba *phba = vport->phba;
  79. uint32_t ha_copy;
  80. if (vport->port_state >= LPFC_VPORT_READY ||
  81. phba->link_state == LPFC_LINK_DOWN ||
  82. phba->sli_rev > LPFC_SLI_REV3)
  83. return 0;
  84. /* Read the HBA Host Attention Register */
  85. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  86. return 1;
  87. if (!(ha_copy & HA_LATT))
  88. return 0;
  89. /* Pending Link Event during Discovery */
  90. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  91. "0237 Pending Link Event during "
  92. "Discovery: State x%x\n",
  93. phba->pport->port_state);
  94. /* CLEAR_LA should re-enable link attention events and
  95. * we should then immediately take a LATT event. The
  96. * LATT processing should call lpfc_linkdown() which
  97. * will cleanup any left over in-progress discovery
  98. * events.
  99. */
  100. spin_lock_irq(shost->host_lock);
  101. vport->fc_flag |= FC_ABORT_DISCOVERY;
  102. spin_unlock_irq(shost->host_lock);
  103. if (phba->link_state != LPFC_CLEAR_LA)
  104. lpfc_issue_clear_la(phba, vport);
  105. return 1;
  106. }
  107. /**
  108. * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
  109. * @vport: pointer to a host virtual N_Port data structure.
  110. * @expectRsp: flag indicating whether response is expected.
  111. * @cmdSize: size of the ELS command.
  112. * @retry: number of retries to the command IOCB when it fails.
  113. * @ndlp: pointer to a node-list data structure.
  114. * @did: destination identifier.
  115. * @elscmd: the ELS command code.
  116. *
  117. * This routine is used for allocating a lpfc-IOCB data structure from
  118. * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
  119. * passed into the routine for discovery state machine to issue an Extended
  120. * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
  121. * and preparation routine that is used by all the discovery state machine
  122. * routines and the ELS command-specific fields will be later set up by
  123. * the individual discovery machine routines after calling this routine
  124. * allocating and preparing a generic IOCB data structure. It fills in the
  125. * Buffer Descriptor Entries (BDEs), allocates buffers for both command
  126. * payload and response payload (if expected). The reference count on the
  127. * ndlp is incremented by 1 and the reference to the ndlp is put into
  128. * context1 of the IOCB data structure for this IOCB to hold the ndlp
  129. * reference for the command's callback function to access later.
  130. *
  131. * Return code
  132. * Pointer to the newly allocated/prepared els iocb data structure
  133. * NULL - when els iocb data structure allocation/preparation failed
  134. **/
  135. struct lpfc_iocbq *
  136. lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
  137. uint16_t cmdSize, uint8_t retry,
  138. struct lpfc_nodelist *ndlp, uint32_t did,
  139. uint32_t elscmd)
  140. {
  141. struct lpfc_hba *phba = vport->phba;
  142. struct lpfc_iocbq *elsiocb;
  143. struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
  144. struct ulp_bde64 *bpl;
  145. IOCB_t *icmd;
  146. if (!lpfc_is_link_up(phba))
  147. return NULL;
  148. /* Allocate buffer for command iocb */
  149. elsiocb = lpfc_sli_get_iocbq(phba);
  150. if (elsiocb == NULL)
  151. return NULL;
  152. /*
  153. * If this command is for fabric controller and HBA running
  154. * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
  155. */
  156. if ((did == Fabric_DID) &&
  157. (phba->hba_flag & HBA_FIP_SUPPORT) &&
  158. ((elscmd == ELS_CMD_FLOGI) ||
  159. (elscmd == ELS_CMD_FDISC) ||
  160. (elscmd == ELS_CMD_LOGO)))
  161. switch (elscmd) {
  162. case ELS_CMD_FLOGI:
  163. elsiocb->iocb_flag |=
  164. ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
  165. & LPFC_FIP_ELS_ID_MASK);
  166. break;
  167. case ELS_CMD_FDISC:
  168. elsiocb->iocb_flag |=
  169. ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
  170. & LPFC_FIP_ELS_ID_MASK);
  171. break;
  172. case ELS_CMD_LOGO:
  173. elsiocb->iocb_flag |=
  174. ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
  175. & LPFC_FIP_ELS_ID_MASK);
  176. break;
  177. }
  178. else
  179. elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
  180. icmd = &elsiocb->iocb;
  181. /* fill in BDEs for command */
  182. /* Allocate buffer for command payload */
  183. pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  184. if (pcmd)
  185. pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
  186. if (!pcmd || !pcmd->virt)
  187. goto els_iocb_free_pcmb_exit;
  188. INIT_LIST_HEAD(&pcmd->list);
  189. /* Allocate buffer for response payload */
  190. if (expectRsp) {
  191. prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  192. if (prsp)
  193. prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  194. &prsp->phys);
  195. if (!prsp || !prsp->virt)
  196. goto els_iocb_free_prsp_exit;
  197. INIT_LIST_HEAD(&prsp->list);
  198. } else
  199. prsp = NULL;
  200. /* Allocate buffer for Buffer ptr list */
  201. pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  202. if (pbuflist)
  203. pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  204. &pbuflist->phys);
  205. if (!pbuflist || !pbuflist->virt)
  206. goto els_iocb_free_pbuf_exit;
  207. INIT_LIST_HEAD(&pbuflist->list);
  208. if (expectRsp) {
  209. icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  210. icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  211. icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  212. icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
  213. icmd->un.elsreq64.remoteID = did; /* DID */
  214. icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
  215. icmd->ulpTimeout = phba->fc_ratov * 2;
  216. } else {
  217. icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  218. icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  219. icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  220. icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
  221. icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
  222. icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
  223. }
  224. icmd->ulpBdeCount = 1;
  225. icmd->ulpLe = 1;
  226. icmd->ulpClass = CLASS3;
  227. /*
  228. * If we have NPIV enabled, we want to send ELS traffic by VPI.
  229. * For SLI4, since the driver controls VPIs we also want to include
  230. * all ELS pt2pt protocol traffic as well.
  231. */
  232. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
  233. ((phba->sli_rev == LPFC_SLI_REV4) &&
  234. (vport->fc_flag & FC_PT2PT))) {
  235. if (expectRsp) {
  236. icmd->un.elsreq64.myID = vport->fc_myDID;
  237. /* For ELS_REQUEST64_CR, use the VPI by default */
  238. icmd->ulpContext = phba->vpi_ids[vport->vpi];
  239. }
  240. icmd->ulpCt_h = 0;
  241. /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
  242. if (elscmd == ELS_CMD_ECHO)
  243. icmd->ulpCt_l = 0; /* context = invalid RPI */
  244. else
  245. icmd->ulpCt_l = 1; /* context = VPI */
  246. }
  247. bpl = (struct ulp_bde64 *) pbuflist->virt;
  248. bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
  249. bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
  250. bpl->tus.f.bdeSize = cmdSize;
  251. bpl->tus.f.bdeFlags = 0;
  252. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  253. if (expectRsp) {
  254. bpl++;
  255. bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
  256. bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
  257. bpl->tus.f.bdeSize = FCELSSIZE;
  258. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  259. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  260. }
  261. /* prevent preparing iocb with NULL ndlp reference */
  262. elsiocb->context1 = lpfc_nlp_get(ndlp);
  263. if (!elsiocb->context1)
  264. goto els_iocb_free_pbuf_exit;
  265. elsiocb->context2 = pcmd;
  266. elsiocb->context3 = pbuflist;
  267. elsiocb->retry = retry;
  268. elsiocb->vport = vport;
  269. elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
  270. if (prsp) {
  271. list_add(&prsp->list, &pcmd->list);
  272. }
  273. if (expectRsp) {
  274. /* Xmit ELS command <elsCmd> to remote NPORT <did> */
  275. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  276. "0116 Xmit ELS command x%x to remote "
  277. "NPORT x%x I/O tag: x%x, port state: x%x\n",
  278. elscmd, did, elsiocb->iotag,
  279. vport->port_state);
  280. } else {
  281. /* Xmit ELS response <elsCmd> to remote NPORT <did> */
  282. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  283. "0117 Xmit ELS response x%x to remote "
  284. "NPORT x%x I/O tag: x%x, size: x%x\n",
  285. elscmd, ndlp->nlp_DID, elsiocb->iotag,
  286. cmdSize);
  287. }
  288. return elsiocb;
  289. els_iocb_free_pbuf_exit:
  290. if (expectRsp)
  291. lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
  292. kfree(pbuflist);
  293. els_iocb_free_prsp_exit:
  294. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  295. kfree(prsp);
  296. els_iocb_free_pcmb_exit:
  297. kfree(pcmd);
  298. lpfc_sli_release_iocbq(phba, elsiocb);
  299. return NULL;
  300. }
  301. /**
  302. * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
  303. * @vport: pointer to a host virtual N_Port data structure.
  304. *
  305. * This routine issues a fabric registration login for a @vport. An
  306. * active ndlp node with Fabric_DID must already exist for this @vport.
  307. * The routine invokes two mailbox commands to carry out fabric registration
  308. * login through the HBA firmware: the first mailbox command requests the
  309. * HBA to perform link configuration for the @vport; and the second mailbox
  310. * command requests the HBA to perform the actual fabric registration login
  311. * with the @vport.
  312. *
  313. * Return code
  314. * 0 - successfully issued fabric registration login for @vport
  315. * -ENXIO -- failed to issue fabric registration login for @vport
  316. **/
  317. int
  318. lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
  319. {
  320. struct lpfc_hba *phba = vport->phba;
  321. LPFC_MBOXQ_t *mbox;
  322. struct lpfc_dmabuf *mp;
  323. struct lpfc_nodelist *ndlp;
  324. struct serv_parm *sp;
  325. int rc;
  326. int err = 0;
  327. sp = &phba->fc_fabparam;
  328. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  329. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  330. err = 1;
  331. goto fail;
  332. }
  333. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  334. if (!mbox) {
  335. err = 2;
  336. goto fail;
  337. }
  338. vport->port_state = LPFC_FABRIC_CFG_LINK;
  339. lpfc_config_link(phba, mbox);
  340. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  341. mbox->vport = vport;
  342. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  343. if (rc == MBX_NOT_FINISHED) {
  344. err = 3;
  345. goto fail_free_mbox;
  346. }
  347. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  348. if (!mbox) {
  349. err = 4;
  350. goto fail;
  351. }
  352. rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
  353. ndlp->nlp_rpi);
  354. if (rc) {
  355. err = 5;
  356. goto fail_free_mbox;
  357. }
  358. mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
  359. mbox->vport = vport;
  360. /* increment the reference count on ndlp to hold reference
  361. * for the callback routine.
  362. */
  363. mbox->context2 = lpfc_nlp_get(ndlp);
  364. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  365. if (rc == MBX_NOT_FINISHED) {
  366. err = 6;
  367. goto fail_issue_reg_login;
  368. }
  369. return 0;
  370. fail_issue_reg_login:
  371. /* decrement the reference count on ndlp just incremented
  372. * for the failed mbox command.
  373. */
  374. lpfc_nlp_put(ndlp);
  375. mp = (struct lpfc_dmabuf *) mbox->context1;
  376. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  377. kfree(mp);
  378. fail_free_mbox:
  379. mempool_free(mbox, phba->mbox_mem_pool);
  380. fail:
  381. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  382. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  383. "0249 Cannot issue Register Fabric login: Err %d\n", err);
  384. return -ENXIO;
  385. }
  386. /**
  387. * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
  388. * @vport: pointer to a host virtual N_Port data structure.
  389. *
  390. * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
  391. * the @vport. This mailbox command is necessary for SLI4 port only.
  392. *
  393. * Return code
  394. * 0 - successfully issued REG_VFI for @vport
  395. * A failure code otherwise.
  396. **/
  397. int
  398. lpfc_issue_reg_vfi(struct lpfc_vport *vport)
  399. {
  400. struct lpfc_hba *phba = vport->phba;
  401. LPFC_MBOXQ_t *mboxq;
  402. struct lpfc_nodelist *ndlp;
  403. struct serv_parm *sp;
  404. struct lpfc_dmabuf *dmabuf;
  405. int rc = 0;
  406. sp = &phba->fc_fabparam;
  407. /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
  408. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  409. !(phba->link_flag & LS_LOOPBACK_MODE) &&
  410. !(vport->fc_flag & FC_PT2PT)) {
  411. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  412. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  413. rc = -ENODEV;
  414. goto fail;
  415. }
  416. }
  417. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  418. if (!dmabuf) {
  419. rc = -ENOMEM;
  420. goto fail;
  421. }
  422. dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
  423. if (!dmabuf->virt) {
  424. rc = -ENOMEM;
  425. goto fail_free_dmabuf;
  426. }
  427. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  428. if (!mboxq) {
  429. rc = -ENOMEM;
  430. goto fail_free_coherent;
  431. }
  432. vport->port_state = LPFC_FABRIC_CFG_LINK;
  433. memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
  434. lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
  435. mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
  436. mboxq->vport = vport;
  437. mboxq->context1 = dmabuf;
  438. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  439. if (rc == MBX_NOT_FINISHED) {
  440. rc = -ENXIO;
  441. goto fail_free_mbox;
  442. }
  443. return 0;
  444. fail_free_mbox:
  445. mempool_free(mboxq, phba->mbox_mem_pool);
  446. fail_free_coherent:
  447. lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
  448. fail_free_dmabuf:
  449. kfree(dmabuf);
  450. fail:
  451. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  452. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  453. "0289 Issue Register VFI failed: Err %d\n", rc);
  454. return rc;
  455. }
  456. /**
  457. * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
  458. * @vport: pointer to a host virtual N_Port data structure.
  459. *
  460. * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
  461. * the @vport. This mailbox command is necessary for SLI4 port only.
  462. *
  463. * Return code
  464. * 0 - successfully issued REG_VFI for @vport
  465. * A failure code otherwise.
  466. **/
  467. int
  468. lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
  469. {
  470. struct lpfc_hba *phba = vport->phba;
  471. struct Scsi_Host *shost;
  472. LPFC_MBOXQ_t *mboxq;
  473. int rc;
  474. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  475. if (!mboxq) {
  476. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  477. "2556 UNREG_VFI mbox allocation failed"
  478. "HBA state x%x\n", phba->pport->port_state);
  479. return -ENOMEM;
  480. }
  481. lpfc_unreg_vfi(mboxq, vport);
  482. mboxq->vport = vport;
  483. mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
  484. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  485. if (rc == MBX_NOT_FINISHED) {
  486. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  487. "2557 UNREG_VFI issue mbox failed rc x%x "
  488. "HBA state x%x\n",
  489. rc, phba->pport->port_state);
  490. mempool_free(mboxq, phba->mbox_mem_pool);
  491. return -EIO;
  492. }
  493. shost = lpfc_shost_from_vport(vport);
  494. spin_lock_irq(shost->host_lock);
  495. vport->fc_flag &= ~FC_VFI_REGISTERED;
  496. spin_unlock_irq(shost->host_lock);
  497. return 0;
  498. }
  499. /**
  500. * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
  501. * @vport: pointer to a host virtual N_Port data structure.
  502. * @sp: pointer to service parameter data structure.
  503. *
  504. * This routine is called from FLOGI/FDISC completion handler functions.
  505. * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
  506. * node nodename is changed in the completion service parameter else return
  507. * 0. This function also set flag in the vport data structure to delay
  508. * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
  509. * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
  510. * node nodename is changed in the completion service parameter.
  511. *
  512. * Return code
  513. * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
  514. * 1 - FCID or Fabric Nodename or Fabric portname is changed.
  515. *
  516. **/
  517. static uint8_t
  518. lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
  519. struct serv_parm *sp)
  520. {
  521. uint8_t fabric_param_changed = 0;
  522. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  523. if ((vport->fc_prevDID != vport->fc_myDID) ||
  524. memcmp(&vport->fabric_portname, &sp->portName,
  525. sizeof(struct lpfc_name)) ||
  526. memcmp(&vport->fabric_nodename, &sp->nodeName,
  527. sizeof(struct lpfc_name)))
  528. fabric_param_changed = 1;
  529. /*
  530. * Word 1 Bit 31 in common service parameter is overloaded.
  531. * Word 1 Bit 31 in FLOGI request is multiple NPort request
  532. * Word 1 Bit 31 in FLOGI response is clean address bit
  533. *
  534. * If fabric parameter is changed and clean address bit is
  535. * cleared delay nport discovery if
  536. * - vport->fc_prevDID != 0 (not initial discovery) OR
  537. * - lpfc_delay_discovery module parameter is set.
  538. */
  539. if (fabric_param_changed && !sp->cmn.clean_address_bit &&
  540. (vport->fc_prevDID || lpfc_delay_discovery)) {
  541. spin_lock_irq(shost->host_lock);
  542. vport->fc_flag |= FC_DISC_DELAYED;
  543. spin_unlock_irq(shost->host_lock);
  544. }
  545. return fabric_param_changed;
  546. }
  547. /**
  548. * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
  549. * @vport: pointer to a host virtual N_Port data structure.
  550. * @ndlp: pointer to a node-list data structure.
  551. * @sp: pointer to service parameter data structure.
  552. * @irsp: pointer to the IOCB within the lpfc response IOCB.
  553. *
  554. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  555. * function to handle the completion of a Fabric Login (FLOGI) into a fabric
  556. * port in a fabric topology. It properly sets up the parameters to the @ndlp
  557. * from the IOCB response. It also check the newly assigned N_Port ID to the
  558. * @vport against the previously assigned N_Port ID. If it is different from
  559. * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
  560. * is invoked on all the remaining nodes with the @vport to unregister the
  561. * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
  562. * is invoked to register login to the fabric.
  563. *
  564. * Return code
  565. * 0 - Success (currently, always return 0)
  566. **/
  567. static int
  568. lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  569. struct serv_parm *sp, IOCB_t *irsp)
  570. {
  571. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  572. struct lpfc_hba *phba = vport->phba;
  573. struct lpfc_nodelist *np;
  574. struct lpfc_nodelist *next_np;
  575. uint8_t fabric_param_changed;
  576. spin_lock_irq(shost->host_lock);
  577. vport->fc_flag |= FC_FABRIC;
  578. spin_unlock_irq(shost->host_lock);
  579. phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
  580. if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
  581. phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
  582. phba->fc_edtovResol = sp->cmn.edtovResolution;
  583. phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
  584. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  585. spin_lock_irq(shost->host_lock);
  586. vport->fc_flag |= FC_PUBLIC_LOOP;
  587. spin_unlock_irq(shost->host_lock);
  588. }
  589. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  590. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
  591. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
  592. ndlp->nlp_class_sup = 0;
  593. if (sp->cls1.classValid)
  594. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  595. if (sp->cls2.classValid)
  596. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  597. if (sp->cls3.classValid)
  598. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  599. if (sp->cls4.classValid)
  600. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  601. ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  602. sp->cmn.bbRcvSizeLsb;
  603. fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
  604. memcpy(&vport->fabric_portname, &sp->portName,
  605. sizeof(struct lpfc_name));
  606. memcpy(&vport->fabric_nodename, &sp->nodeName,
  607. sizeof(struct lpfc_name));
  608. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  609. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  610. if (sp->cmn.response_multiple_NPort) {
  611. lpfc_printf_vlog(vport, KERN_WARNING,
  612. LOG_ELS | LOG_VPORT,
  613. "1816 FLOGI NPIV supported, "
  614. "response data 0x%x\n",
  615. sp->cmn.response_multiple_NPort);
  616. spin_lock_irq(&phba->hbalock);
  617. phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
  618. spin_unlock_irq(&phba->hbalock);
  619. } else {
  620. /* Because we asked f/w for NPIV it still expects us
  621. to call reg_vnpid atleast for the physcial host */
  622. lpfc_printf_vlog(vport, KERN_WARNING,
  623. LOG_ELS | LOG_VPORT,
  624. "1817 Fabric does not support NPIV "
  625. "- configuring single port mode.\n");
  626. spin_lock_irq(&phba->hbalock);
  627. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  628. spin_unlock_irq(&phba->hbalock);
  629. }
  630. }
  631. /*
  632. * For FC we need to do some special processing because of the SLI
  633. * Port's default settings of the Common Service Parameters.
  634. */
  635. if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) {
  636. /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
  637. if ((phba->sli_rev == LPFC_SLI_REV4) && fabric_param_changed)
  638. lpfc_unregister_fcf_prep(phba);
  639. /* This should just update the VFI CSPs*/
  640. if (vport->fc_flag & FC_VFI_REGISTERED)
  641. lpfc_issue_reg_vfi(vport);
  642. }
  643. if (fabric_param_changed &&
  644. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  645. /* If our NportID changed, we need to ensure all
  646. * remaining NPORTs get unreg_login'ed.
  647. */
  648. list_for_each_entry_safe(np, next_np,
  649. &vport->fc_nodes, nlp_listp) {
  650. if (!NLP_CHK_NODE_ACT(np))
  651. continue;
  652. if ((np->nlp_state != NLP_STE_NPR_NODE) ||
  653. !(np->nlp_flag & NLP_NPR_ADISC))
  654. continue;
  655. spin_lock_irq(shost->host_lock);
  656. np->nlp_flag &= ~NLP_NPR_ADISC;
  657. spin_unlock_irq(shost->host_lock);
  658. lpfc_unreg_rpi(vport, np);
  659. }
  660. lpfc_cleanup_pending_mbox(vport);
  661. if (phba->sli_rev == LPFC_SLI_REV4) {
  662. lpfc_sli4_unreg_all_rpis(vport);
  663. lpfc_mbx_unreg_vpi(vport);
  664. spin_lock_irq(shost->host_lock);
  665. vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  666. spin_unlock_irq(shost->host_lock);
  667. }
  668. /*
  669. * For SLI3 and SLI4, the VPI needs to be reregistered in
  670. * response to this fabric parameter change event.
  671. */
  672. spin_lock_irq(shost->host_lock);
  673. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  674. spin_unlock_irq(shost->host_lock);
  675. } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
  676. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  677. /*
  678. * Driver needs to re-reg VPI in order for f/w
  679. * to update the MAC address.
  680. */
  681. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  682. lpfc_register_new_vport(phba, vport, ndlp);
  683. return 0;
  684. }
  685. if (phba->sli_rev < LPFC_SLI_REV4) {
  686. lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
  687. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
  688. vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  689. lpfc_register_new_vport(phba, vport, ndlp);
  690. else
  691. lpfc_issue_fabric_reglogin(vport);
  692. } else {
  693. ndlp->nlp_type |= NLP_FABRIC;
  694. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  695. if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
  696. (vport->vpi_state & LPFC_VPI_REGISTERED)) {
  697. lpfc_start_fdiscs(phba);
  698. lpfc_do_scr_ns_plogi(phba, vport);
  699. } else if (vport->fc_flag & FC_VFI_REGISTERED)
  700. lpfc_issue_init_vpi(vport);
  701. else {
  702. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  703. "3135 Need register VFI: (x%x/%x)\n",
  704. vport->fc_prevDID, vport->fc_myDID);
  705. lpfc_issue_reg_vfi(vport);
  706. }
  707. }
  708. return 0;
  709. }
  710. /**
  711. * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
  712. * @vport: pointer to a host virtual N_Port data structure.
  713. * @ndlp: pointer to a node-list data structure.
  714. * @sp: pointer to service parameter data structure.
  715. *
  716. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  717. * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
  718. * in a point-to-point topology. First, the @vport's N_Port Name is compared
  719. * with the received N_Port Name: if the @vport's N_Port Name is greater than
  720. * the received N_Port Name lexicographically, this node shall assign local
  721. * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
  722. * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
  723. * this node shall just wait for the remote node to issue PLOGI and assign
  724. * N_Port IDs.
  725. *
  726. * Return code
  727. * 0 - Success
  728. * -ENXIO - Fail
  729. **/
  730. static int
  731. lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  732. struct serv_parm *sp)
  733. {
  734. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  735. struct lpfc_hba *phba = vport->phba;
  736. LPFC_MBOXQ_t *mbox;
  737. int rc;
  738. spin_lock_irq(shost->host_lock);
  739. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  740. spin_unlock_irq(shost->host_lock);
  741. phba->fc_edtov = FF_DEF_EDTOV;
  742. phba->fc_ratov = FF_DEF_RATOV;
  743. rc = memcmp(&vport->fc_portname, &sp->portName,
  744. sizeof(vport->fc_portname));
  745. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  746. if (rc >= 0) {
  747. /* This side will initiate the PLOGI */
  748. spin_lock_irq(shost->host_lock);
  749. vport->fc_flag |= FC_PT2PT_PLOGI;
  750. spin_unlock_irq(shost->host_lock);
  751. /*
  752. * N_Port ID cannot be 0, set our to LocalID the other
  753. * side will be RemoteID.
  754. */
  755. /* not equal */
  756. if (rc)
  757. vport->fc_myDID = PT2PT_LocalID;
  758. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  759. if (!mbox)
  760. goto fail;
  761. lpfc_config_link(phba, mbox);
  762. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  763. mbox->vport = vport;
  764. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  765. if (rc == MBX_NOT_FINISHED) {
  766. mempool_free(mbox, phba->mbox_mem_pool);
  767. goto fail;
  768. }
  769. /*
  770. * For SLI4, the VFI/VPI are registered AFTER the
  771. * Nport with the higher WWPN sends the PLOGI with
  772. * an assigned NPortId.
  773. */
  774. /* not equal */
  775. if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
  776. lpfc_issue_reg_vfi(vport);
  777. /* Decrement ndlp reference count indicating that ndlp can be
  778. * safely released when other references to it are done.
  779. */
  780. lpfc_nlp_put(ndlp);
  781. ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
  782. if (!ndlp) {
  783. /*
  784. * Cannot find existing Fabric ndlp, so allocate a
  785. * new one
  786. */
  787. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  788. if (!ndlp)
  789. goto fail;
  790. lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
  791. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  792. ndlp = lpfc_enable_node(vport, ndlp,
  793. NLP_STE_UNUSED_NODE);
  794. if(!ndlp)
  795. goto fail;
  796. }
  797. memcpy(&ndlp->nlp_portname, &sp->portName,
  798. sizeof(struct lpfc_name));
  799. memcpy(&ndlp->nlp_nodename, &sp->nodeName,
  800. sizeof(struct lpfc_name));
  801. /* Set state will put ndlp onto node list if not already done */
  802. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  803. spin_lock_irq(shost->host_lock);
  804. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  805. spin_unlock_irq(shost->host_lock);
  806. } else
  807. /* This side will wait for the PLOGI, decrement ndlp reference
  808. * count indicating that ndlp can be released when other
  809. * references to it are done.
  810. */
  811. lpfc_nlp_put(ndlp);
  812. /* If we are pt2pt with another NPort, force NPIV off! */
  813. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  814. spin_lock_irq(shost->host_lock);
  815. vport->fc_flag |= FC_PT2PT;
  816. spin_unlock_irq(shost->host_lock);
  817. /* Start discovery - this should just do CLEAR_LA */
  818. lpfc_disc_start(vport);
  819. return 0;
  820. fail:
  821. return -ENXIO;
  822. }
  823. /**
  824. * lpfc_cmpl_els_flogi - Completion callback function for flogi
  825. * @phba: pointer to lpfc hba data structure.
  826. * @cmdiocb: pointer to lpfc command iocb data structure.
  827. * @rspiocb: pointer to lpfc response iocb data structure.
  828. *
  829. * This routine is the top-level completion callback function for issuing
  830. * a Fabric Login (FLOGI) command. If the response IOCB reported error,
  831. * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
  832. * retry has been made (either immediately or delayed with lpfc_els_retry()
  833. * returning 1), the command IOCB will be released and function returned.
  834. * If the retry attempt has been given up (possibly reach the maximum
  835. * number of retries), one additional decrement of ndlp reference shall be
  836. * invoked before going out after releasing the command IOCB. This will
  837. * actually release the remote node (Note, lpfc_els_free_iocb() will also
  838. * invoke one decrement of ndlp reference count). If no error reported in
  839. * the IOCB status, the command Port ID field is used to determine whether
  840. * this is a point-to-point topology or a fabric topology: if the Port ID
  841. * field is assigned, it is a fabric topology; otherwise, it is a
  842. * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
  843. * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
  844. * specific topology completion conditions.
  845. **/
  846. static void
  847. lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  848. struct lpfc_iocbq *rspiocb)
  849. {
  850. struct lpfc_vport *vport = cmdiocb->vport;
  851. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  852. IOCB_t *irsp = &rspiocb->iocb;
  853. struct lpfc_nodelist *ndlp = cmdiocb->context1;
  854. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  855. struct serv_parm *sp;
  856. uint16_t fcf_index;
  857. int rc;
  858. /* Check to see if link went down during discovery */
  859. if (lpfc_els_chk_latt(vport)) {
  860. /* One additional decrement on node reference count to
  861. * trigger the release of the node
  862. */
  863. lpfc_nlp_put(ndlp);
  864. goto out;
  865. }
  866. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  867. "FLOGI cmpl: status:x%x/x%x state:x%x",
  868. irsp->ulpStatus, irsp->un.ulpWord[4],
  869. vport->port_state);
  870. if (irsp->ulpStatus) {
  871. /*
  872. * In case of FIP mode, perform roundrobin FCF failover
  873. * due to new FCF discovery
  874. */
  875. if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
  876. (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
  877. if (phba->link_state < LPFC_LINK_UP)
  878. goto stop_rr_fcf_flogi;
  879. if ((phba->fcoe_cvl_eventtag_attn ==
  880. phba->fcoe_cvl_eventtag) &&
  881. (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  882. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  883. IOERR_SLI_ABORTED))
  884. goto stop_rr_fcf_flogi;
  885. else
  886. phba->fcoe_cvl_eventtag_attn =
  887. phba->fcoe_cvl_eventtag;
  888. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
  889. "2611 FLOGI failed on FCF (x%x), "
  890. "status:x%x/x%x, tmo:x%x, perform "
  891. "roundrobin FCF failover\n",
  892. phba->fcf.current_rec.fcf_indx,
  893. irsp->ulpStatus, irsp->un.ulpWord[4],
  894. irsp->ulpTimeout);
  895. lpfc_sli4_set_fcf_flogi_fail(phba,
  896. phba->fcf.current_rec.fcf_indx);
  897. fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
  898. rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
  899. if (rc)
  900. goto out;
  901. }
  902. stop_rr_fcf_flogi:
  903. /* FLOGI failure */
  904. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  905. "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
  906. irsp->ulpStatus, irsp->un.ulpWord[4],
  907. irsp->ulpTimeout);
  908. /* Check for retry */
  909. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  910. goto out;
  911. /* FLOGI failure */
  912. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  913. "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
  914. irsp->ulpStatus, irsp->un.ulpWord[4],
  915. irsp->ulpTimeout);
  916. /* FLOGI failed, so there is no fabric */
  917. spin_lock_irq(shost->host_lock);
  918. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  919. spin_unlock_irq(shost->host_lock);
  920. /* If private loop, then allow max outstanding els to be
  921. * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
  922. * alpa map would take too long otherwise.
  923. */
  924. if (phba->alpa_map[0] == 0)
  925. vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
  926. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  927. (!(vport->fc_flag & FC_VFI_REGISTERED) ||
  928. (vport->fc_prevDID != vport->fc_myDID))) {
  929. if (vport->fc_flag & FC_VFI_REGISTERED)
  930. lpfc_sli4_unreg_all_rpis(vport);
  931. lpfc_issue_reg_vfi(vport);
  932. lpfc_nlp_put(ndlp);
  933. goto out;
  934. }
  935. goto flogifail;
  936. }
  937. spin_lock_irq(shost->host_lock);
  938. vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
  939. vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
  940. spin_unlock_irq(shost->host_lock);
  941. /*
  942. * The FLogI succeeded. Sync the data for the CPU before
  943. * accessing it.
  944. */
  945. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  946. sp = prsp->virt + sizeof(uint32_t);
  947. /* FLOGI completes successfully */
  948. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  949. "0101 FLOGI completes successfully "
  950. "Data: x%x x%x x%x x%x\n",
  951. irsp->un.ulpWord[4], sp->cmn.e_d_tov,
  952. sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
  953. if (vport->port_state == LPFC_FLOGI) {
  954. /*
  955. * If Common Service Parameters indicate Nport
  956. * we are point to point, if Fport we are Fabric.
  957. */
  958. if (sp->cmn.fPort)
  959. rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
  960. else if (!(phba->hba_flag & HBA_FCOE_MODE))
  961. rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
  962. else {
  963. lpfc_printf_vlog(vport, KERN_ERR,
  964. LOG_FIP | LOG_ELS,
  965. "2831 FLOGI response with cleared Fabric "
  966. "bit fcf_index 0x%x "
  967. "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
  968. "Fabric Name "
  969. "%02x%02x%02x%02x%02x%02x%02x%02x\n",
  970. phba->fcf.current_rec.fcf_indx,
  971. phba->fcf.current_rec.switch_name[0],
  972. phba->fcf.current_rec.switch_name[1],
  973. phba->fcf.current_rec.switch_name[2],
  974. phba->fcf.current_rec.switch_name[3],
  975. phba->fcf.current_rec.switch_name[4],
  976. phba->fcf.current_rec.switch_name[5],
  977. phba->fcf.current_rec.switch_name[6],
  978. phba->fcf.current_rec.switch_name[7],
  979. phba->fcf.current_rec.fabric_name[0],
  980. phba->fcf.current_rec.fabric_name[1],
  981. phba->fcf.current_rec.fabric_name[2],
  982. phba->fcf.current_rec.fabric_name[3],
  983. phba->fcf.current_rec.fabric_name[4],
  984. phba->fcf.current_rec.fabric_name[5],
  985. phba->fcf.current_rec.fabric_name[6],
  986. phba->fcf.current_rec.fabric_name[7]);
  987. lpfc_nlp_put(ndlp);
  988. spin_lock_irq(&phba->hbalock);
  989. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  990. phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
  991. spin_unlock_irq(&phba->hbalock);
  992. goto out;
  993. }
  994. if (!rc) {
  995. /* Mark the FCF discovery process done */
  996. if (phba->hba_flag & HBA_FIP_SUPPORT)
  997. lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
  998. LOG_ELS,
  999. "2769 FLOGI to FCF (x%x) "
  1000. "completed successfully\n",
  1001. phba->fcf.current_rec.fcf_indx);
  1002. spin_lock_irq(&phba->hbalock);
  1003. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  1004. phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
  1005. spin_unlock_irq(&phba->hbalock);
  1006. goto out;
  1007. }
  1008. }
  1009. flogifail:
  1010. lpfc_nlp_put(ndlp);
  1011. if (!lpfc_error_lost_link(irsp)) {
  1012. /* FLOGI failed, so just use loop map to make discovery list */
  1013. lpfc_disc_list_loopmap(vport);
  1014. /* Start discovery */
  1015. lpfc_disc_start(vport);
  1016. } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  1017. (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  1018. IOERR_SLI_ABORTED) &&
  1019. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  1020. IOERR_SLI_DOWN))) &&
  1021. (phba->link_state != LPFC_CLEAR_LA)) {
  1022. /* If FLOGI failed enable link interrupt. */
  1023. lpfc_issue_clear_la(phba, vport);
  1024. }
  1025. out:
  1026. lpfc_els_free_iocb(phba, cmdiocb);
  1027. }
  1028. /**
  1029. * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
  1030. * @vport: pointer to a host virtual N_Port data structure.
  1031. * @ndlp: pointer to a node-list data structure.
  1032. * @retry: number of retries to the command IOCB.
  1033. *
  1034. * This routine issues a Fabric Login (FLOGI) Request ELS command
  1035. * for a @vport. The initiator service parameters are put into the payload
  1036. * of the FLOGI Request IOCB and the top-level callback function pointer
  1037. * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
  1038. * function field. The lpfc_issue_fabric_iocb routine is invoked to send
  1039. * out FLOGI ELS command with one outstanding fabric IOCB at a time.
  1040. *
  1041. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1042. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1043. * will be stored into the context1 field of the IOCB for the completion
  1044. * callback function to the FLOGI ELS command.
  1045. *
  1046. * Return code
  1047. * 0 - successfully issued flogi iocb for @vport
  1048. * 1 - failed to issue flogi iocb for @vport
  1049. **/
  1050. static int
  1051. lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1052. uint8_t retry)
  1053. {
  1054. struct lpfc_hba *phba = vport->phba;
  1055. struct serv_parm *sp;
  1056. IOCB_t *icmd;
  1057. struct lpfc_iocbq *elsiocb;
  1058. struct lpfc_sli_ring *pring;
  1059. uint8_t *pcmd;
  1060. uint16_t cmdsize;
  1061. uint32_t tmo;
  1062. int rc;
  1063. pring = &phba->sli.ring[LPFC_ELS_RING];
  1064. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  1065. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1066. ndlp->nlp_DID, ELS_CMD_FLOGI);
  1067. if (!elsiocb)
  1068. return 1;
  1069. icmd = &elsiocb->iocb;
  1070. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1071. /* For FLOGI request, remainder of payload is service parameters */
  1072. *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
  1073. pcmd += sizeof(uint32_t);
  1074. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1075. sp = (struct serv_parm *) pcmd;
  1076. /* Setup CSPs accordingly for Fabric */
  1077. sp->cmn.e_d_tov = 0;
  1078. sp->cmn.w2.r_a_tov = 0;
  1079. sp->cmn.virtual_fabric_support = 0;
  1080. sp->cls1.classValid = 0;
  1081. if (sp->cmn.fcphLow < FC_PH3)
  1082. sp->cmn.fcphLow = FC_PH3;
  1083. if (sp->cmn.fcphHigh < FC_PH3)
  1084. sp->cmn.fcphHigh = FC_PH3;
  1085. if (phba->sli_rev == LPFC_SLI_REV4) {
  1086. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  1087. LPFC_SLI_INTF_IF_TYPE_0) {
  1088. elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
  1089. elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
  1090. /* FLOGI needs to be 3 for WQE FCFI */
  1091. /* Set the fcfi to the fcfi we registered with */
  1092. elsiocb->iocb.ulpContext = phba->fcf.fcfi;
  1093. }
  1094. /* Can't do SLI4 class2 without support sequence coalescing */
  1095. sp->cls2.classValid = 0;
  1096. sp->cls2.seqDelivery = 0;
  1097. } else {
  1098. /* Historical, setting sequential-delivery bit for SLI3 */
  1099. sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
  1100. sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
  1101. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  1102. sp->cmn.request_multiple_Nport = 1;
  1103. /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
  1104. icmd->ulpCt_h = 1;
  1105. icmd->ulpCt_l = 0;
  1106. } else
  1107. sp->cmn.request_multiple_Nport = 0;
  1108. }
  1109. if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
  1110. icmd->un.elsreq64.myID = 0;
  1111. icmd->un.elsreq64.fl = 1;
  1112. }
  1113. tmo = phba->fc_ratov;
  1114. phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
  1115. lpfc_set_disctmo(vport);
  1116. phba->fc_ratov = tmo;
  1117. phba->fc_stat.elsXmitFLOGI++;
  1118. elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
  1119. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1120. "Issue FLOGI: opt:x%x",
  1121. phba->sli3_options, 0, 0);
  1122. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  1123. if (rc == IOCB_ERROR) {
  1124. lpfc_els_free_iocb(phba, elsiocb);
  1125. return 1;
  1126. }
  1127. return 0;
  1128. }
  1129. /**
  1130. * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
  1131. * @phba: pointer to lpfc hba data structure.
  1132. *
  1133. * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
  1134. * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
  1135. * list and issues an abort IOCB commond on each outstanding IOCB that
  1136. * contains a active Fabric_DID ndlp. Note that this function is to issue
  1137. * the abort IOCB command on all the outstanding IOCBs, thus when this
  1138. * function returns, it does not guarantee all the IOCBs are actually aborted.
  1139. *
  1140. * Return code
  1141. * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
  1142. **/
  1143. int
  1144. lpfc_els_abort_flogi(struct lpfc_hba *phba)
  1145. {
  1146. struct lpfc_sli_ring *pring;
  1147. struct lpfc_iocbq *iocb, *next_iocb;
  1148. struct lpfc_nodelist *ndlp;
  1149. IOCB_t *icmd;
  1150. /* Abort outstanding I/O on NPort <nlp_DID> */
  1151. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1152. "0201 Abort outstanding I/O on NPort x%x\n",
  1153. Fabric_DID);
  1154. pring = &phba->sli.ring[LPFC_ELS_RING];
  1155. /*
  1156. * Check the txcmplq for an iocb that matches the nport the driver is
  1157. * searching for.
  1158. */
  1159. spin_lock_irq(&phba->hbalock);
  1160. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  1161. icmd = &iocb->iocb;
  1162. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
  1163. ndlp = (struct lpfc_nodelist *)(iocb->context1);
  1164. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  1165. (ndlp->nlp_DID == Fabric_DID))
  1166. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  1167. }
  1168. }
  1169. spin_unlock_irq(&phba->hbalock);
  1170. return 0;
  1171. }
  1172. /**
  1173. * lpfc_initial_flogi - Issue an initial fabric login for a vport
  1174. * @vport: pointer to a host virtual N_Port data structure.
  1175. *
  1176. * This routine issues an initial Fabric Login (FLOGI) for the @vport
  1177. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  1178. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  1179. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  1180. * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
  1181. * is then invoked with the @vport and the ndlp to perform the FLOGI for the
  1182. * @vport.
  1183. *
  1184. * Return code
  1185. * 0 - failed to issue initial flogi for @vport
  1186. * 1 - successfully issued initial flogi for @vport
  1187. **/
  1188. int
  1189. lpfc_initial_flogi(struct lpfc_vport *vport)
  1190. {
  1191. struct lpfc_hba *phba = vport->phba;
  1192. struct lpfc_nodelist *ndlp;
  1193. vport->port_state = LPFC_FLOGI;
  1194. lpfc_set_disctmo(vport);
  1195. /* First look for the Fabric ndlp */
  1196. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  1197. if (!ndlp) {
  1198. /* Cannot find existing Fabric ndlp, so allocate a new one */
  1199. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1200. if (!ndlp)
  1201. return 0;
  1202. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  1203. /* Set the node type */
  1204. ndlp->nlp_type |= NLP_FABRIC;
  1205. /* Put ndlp onto node list */
  1206. lpfc_enqueue_node(vport, ndlp);
  1207. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1208. /* re-setup ndlp without removing from node list */
  1209. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1210. if (!ndlp)
  1211. return 0;
  1212. }
  1213. if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
  1214. /* This decrement of reference count to node shall kick off
  1215. * the release of the node.
  1216. */
  1217. lpfc_nlp_put(ndlp);
  1218. return 0;
  1219. }
  1220. return 1;
  1221. }
  1222. /**
  1223. * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
  1224. * @vport: pointer to a host virtual N_Port data structure.
  1225. *
  1226. * This routine issues an initial Fabric Discover (FDISC) for the @vport
  1227. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  1228. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  1229. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  1230. * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
  1231. * is then invoked with the @vport and the ndlp to perform the FDISC for the
  1232. * @vport.
  1233. *
  1234. * Return code
  1235. * 0 - failed to issue initial fdisc for @vport
  1236. * 1 - successfully issued initial fdisc for @vport
  1237. **/
  1238. int
  1239. lpfc_initial_fdisc(struct lpfc_vport *vport)
  1240. {
  1241. struct lpfc_hba *phba = vport->phba;
  1242. struct lpfc_nodelist *ndlp;
  1243. /* First look for the Fabric ndlp */
  1244. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  1245. if (!ndlp) {
  1246. /* Cannot find existing Fabric ndlp, so allocate a new one */
  1247. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1248. if (!ndlp)
  1249. return 0;
  1250. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  1251. /* Put ndlp onto node list */
  1252. lpfc_enqueue_node(vport, ndlp);
  1253. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1254. /* re-setup ndlp without removing from node list */
  1255. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1256. if (!ndlp)
  1257. return 0;
  1258. }
  1259. if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
  1260. /* decrement node reference count to trigger the release of
  1261. * the node.
  1262. */
  1263. lpfc_nlp_put(ndlp);
  1264. return 0;
  1265. }
  1266. return 1;
  1267. }
  1268. /**
  1269. * lpfc_more_plogi - Check and issue remaining plogis for a vport
  1270. * @vport: pointer to a host virtual N_Port data structure.
  1271. *
  1272. * This routine checks whether there are more remaining Port Logins
  1273. * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
  1274. * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
  1275. * to issue ELS PLOGIs up to the configured discover threads with the
  1276. * @vport (@vport->cfg_discovery_threads). The function also decrement
  1277. * the @vport's num_disc_node by 1 if it is not already 0.
  1278. **/
  1279. void
  1280. lpfc_more_plogi(struct lpfc_vport *vport)
  1281. {
  1282. int sentplogi;
  1283. if (vport->num_disc_nodes)
  1284. vport->num_disc_nodes--;
  1285. /* Continue discovery with <num_disc_nodes> PLOGIs to go */
  1286. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1287. "0232 Continue discovery with %d PLOGIs to go "
  1288. "Data: x%x x%x x%x\n",
  1289. vport->num_disc_nodes, vport->fc_plogi_cnt,
  1290. vport->fc_flag, vport->port_state);
  1291. /* Check to see if there are more PLOGIs to be sent */
  1292. if (vport->fc_flag & FC_NLP_MORE)
  1293. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  1294. sentplogi = lpfc_els_disc_plogi(vport);
  1295. return;
  1296. }
  1297. /**
  1298. * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
  1299. * @phba: pointer to lpfc hba data structure.
  1300. * @prsp: pointer to response IOCB payload.
  1301. * @ndlp: pointer to a node-list data structure.
  1302. *
  1303. * This routine checks and indicates whether the WWPN of an N_Port, retrieved
  1304. * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
  1305. * The following cases are considered N_Port confirmed:
  1306. * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
  1307. * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
  1308. * it does not have WWPN assigned either. If the WWPN is confirmed, the
  1309. * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
  1310. * 1) if there is a node on vport list other than the @ndlp with the same
  1311. * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
  1312. * on that node to release the RPI associated with the node; 2) if there is
  1313. * no node found on vport list with the same WWPN of the N_Port PLOGI logged
  1314. * into, a new node shall be allocated (or activated). In either case, the
  1315. * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
  1316. * be released and the new_ndlp shall be put on to the vport node list and
  1317. * its pointer returned as the confirmed node.
  1318. *
  1319. * Note that before the @ndlp got "released", the keepDID from not-matching
  1320. * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
  1321. * of the @ndlp. This is because the release of @ndlp is actually to put it
  1322. * into an inactive state on the vport node list and the vport node list
  1323. * management algorithm does not allow two node with a same DID.
  1324. *
  1325. * Return code
  1326. * pointer to the PLOGI N_Port @ndlp
  1327. **/
  1328. static struct lpfc_nodelist *
  1329. lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
  1330. struct lpfc_nodelist *ndlp)
  1331. {
  1332. struct lpfc_vport *vport = ndlp->vport;
  1333. struct lpfc_nodelist *new_ndlp;
  1334. struct lpfc_rport_data *rdata;
  1335. struct fc_rport *rport;
  1336. struct serv_parm *sp;
  1337. uint8_t name[sizeof(struct lpfc_name)];
  1338. uint32_t rc, keepDID = 0;
  1339. int put_node;
  1340. int put_rport;
  1341. struct lpfc_node_rrqs rrq;
  1342. /* Fabric nodes can have the same WWPN so we don't bother searching
  1343. * by WWPN. Just return the ndlp that was given to us.
  1344. */
  1345. if (ndlp->nlp_type & NLP_FABRIC)
  1346. return ndlp;
  1347. sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
  1348. memset(name, 0, sizeof(struct lpfc_name));
  1349. /* Now we find out if the NPort we are logging into, matches the WWPN
  1350. * we have for that ndlp. If not, we have some work to do.
  1351. */
  1352. new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
  1353. if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
  1354. return ndlp;
  1355. memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
  1356. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1357. "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
  1358. ndlp, ndlp->nlp_DID, new_ndlp);
  1359. if (!new_ndlp) {
  1360. rc = memcmp(&ndlp->nlp_portname, name,
  1361. sizeof(struct lpfc_name));
  1362. if (!rc)
  1363. return ndlp;
  1364. new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
  1365. if (!new_ndlp)
  1366. return ndlp;
  1367. lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
  1368. } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
  1369. rc = memcmp(&ndlp->nlp_portname, name,
  1370. sizeof(struct lpfc_name));
  1371. if (!rc)
  1372. return ndlp;
  1373. new_ndlp = lpfc_enable_node(vport, new_ndlp,
  1374. NLP_STE_UNUSED_NODE);
  1375. if (!new_ndlp)
  1376. return ndlp;
  1377. keepDID = new_ndlp->nlp_DID;
  1378. if (phba->sli_rev == LPFC_SLI_REV4)
  1379. memcpy(&rrq.xri_bitmap,
  1380. &new_ndlp->active_rrqs.xri_bitmap,
  1381. sizeof(new_ndlp->active_rrqs.xri_bitmap));
  1382. } else {
  1383. keepDID = new_ndlp->nlp_DID;
  1384. if (phba->sli_rev == LPFC_SLI_REV4)
  1385. memcpy(&rrq.xri_bitmap,
  1386. &new_ndlp->active_rrqs.xri_bitmap,
  1387. sizeof(new_ndlp->active_rrqs.xri_bitmap));
  1388. }
  1389. lpfc_unreg_rpi(vport, new_ndlp);
  1390. new_ndlp->nlp_DID = ndlp->nlp_DID;
  1391. new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
  1392. if (phba->sli_rev == LPFC_SLI_REV4)
  1393. memcpy(new_ndlp->active_rrqs.xri_bitmap,
  1394. &ndlp->active_rrqs.xri_bitmap,
  1395. sizeof(ndlp->active_rrqs.xri_bitmap));
  1396. if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
  1397. new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1398. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1399. /* Set state will put new_ndlp on to node list if not already done */
  1400. lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
  1401. /* Move this back to NPR state */
  1402. if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
  1403. /* The new_ndlp is replacing ndlp totally, so we need
  1404. * to put ndlp on UNUSED list and try to free it.
  1405. */
  1406. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1407. "3179 PLOGI confirm NEW: %x %x\n",
  1408. new_ndlp->nlp_DID, keepDID);
  1409. /* Fix up the rport accordingly */
  1410. rport = ndlp->rport;
  1411. if (rport) {
  1412. rdata = rport->dd_data;
  1413. if (rdata->pnode == ndlp) {
  1414. lpfc_nlp_put(ndlp);
  1415. ndlp->rport = NULL;
  1416. rdata->pnode = lpfc_nlp_get(new_ndlp);
  1417. new_ndlp->rport = rport;
  1418. }
  1419. new_ndlp->nlp_type = ndlp->nlp_type;
  1420. }
  1421. /* We shall actually free the ndlp with both nlp_DID and
  1422. * nlp_portname fields equals 0 to avoid any ndlp on the
  1423. * nodelist never to be used.
  1424. */
  1425. if (ndlp->nlp_DID == 0) {
  1426. spin_lock_irq(&phba->ndlp_lock);
  1427. NLP_SET_FREE_REQ(ndlp);
  1428. spin_unlock_irq(&phba->ndlp_lock);
  1429. }
  1430. /* Two ndlps cannot have the same did on the nodelist */
  1431. ndlp->nlp_DID = keepDID;
  1432. if (phba->sli_rev == LPFC_SLI_REV4)
  1433. memcpy(&ndlp->active_rrqs.xri_bitmap,
  1434. &rrq.xri_bitmap,
  1435. sizeof(ndlp->active_rrqs.xri_bitmap));
  1436. lpfc_drop_node(vport, ndlp);
  1437. }
  1438. else {
  1439. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1440. "3180 PLOGI confirm SWAP: %x %x\n",
  1441. new_ndlp->nlp_DID, keepDID);
  1442. lpfc_unreg_rpi(vport, ndlp);
  1443. /* Two ndlps cannot have the same did */
  1444. ndlp->nlp_DID = keepDID;
  1445. if (phba->sli_rev == LPFC_SLI_REV4)
  1446. memcpy(&ndlp->active_rrqs.xri_bitmap,
  1447. &rrq.xri_bitmap,
  1448. sizeof(ndlp->active_rrqs.xri_bitmap));
  1449. /* Since we are swapping the ndlp passed in with the new one
  1450. * and the did has already been swapped, copy over state.
  1451. * The new WWNs are already in new_ndlp since thats what
  1452. * we looked it up by in the begining of this routine.
  1453. */
  1454. new_ndlp->nlp_state = ndlp->nlp_state;
  1455. /* Since we are switching over to the new_ndlp, the old
  1456. * ndlp should be put in the NPR state, unless we have
  1457. * already started re-discovery on it.
  1458. */
  1459. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  1460. (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
  1461. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1462. /* Fix up the rport accordingly */
  1463. rport = ndlp->rport;
  1464. if (rport) {
  1465. rdata = rport->dd_data;
  1466. put_node = rdata->pnode != NULL;
  1467. put_rport = ndlp->rport != NULL;
  1468. rdata->pnode = NULL;
  1469. ndlp->rport = NULL;
  1470. if (put_node)
  1471. lpfc_nlp_put(ndlp);
  1472. if (put_rport)
  1473. put_device(&rport->dev);
  1474. }
  1475. }
  1476. return new_ndlp;
  1477. }
  1478. /**
  1479. * lpfc_end_rscn - Check and handle more rscn for a vport
  1480. * @vport: pointer to a host virtual N_Port data structure.
  1481. *
  1482. * This routine checks whether more Registration State Change
  1483. * Notifications (RSCNs) came in while the discovery state machine was in
  1484. * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
  1485. * invoked to handle the additional RSCNs for the @vport. Otherwise, the
  1486. * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
  1487. * handling the RSCNs.
  1488. **/
  1489. void
  1490. lpfc_end_rscn(struct lpfc_vport *vport)
  1491. {
  1492. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1493. if (vport->fc_flag & FC_RSCN_MODE) {
  1494. /*
  1495. * Check to see if more RSCNs came in while we were
  1496. * processing this one.
  1497. */
  1498. if (vport->fc_rscn_id_cnt ||
  1499. (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
  1500. lpfc_els_handle_rscn(vport);
  1501. else {
  1502. spin_lock_irq(shost->host_lock);
  1503. vport->fc_flag &= ~FC_RSCN_MODE;
  1504. spin_unlock_irq(shost->host_lock);
  1505. }
  1506. }
  1507. }
  1508. /**
  1509. * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
  1510. * @phba: pointer to lpfc hba data structure.
  1511. * @cmdiocb: pointer to lpfc command iocb data structure.
  1512. * @rspiocb: pointer to lpfc response iocb data structure.
  1513. *
  1514. * This routine will call the clear rrq function to free the rrq and
  1515. * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
  1516. * exist then the clear_rrq is still called because the rrq needs to
  1517. * be freed.
  1518. **/
  1519. static void
  1520. lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1521. struct lpfc_iocbq *rspiocb)
  1522. {
  1523. struct lpfc_vport *vport = cmdiocb->vport;
  1524. IOCB_t *irsp;
  1525. struct lpfc_nodelist *ndlp;
  1526. struct lpfc_node_rrq *rrq;
  1527. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1528. rrq = cmdiocb->context_un.rrq;
  1529. cmdiocb->context_un.rsp_iocb = rspiocb;
  1530. irsp = &rspiocb->iocb;
  1531. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1532. "RRQ cmpl: status:x%x/x%x did:x%x",
  1533. irsp->ulpStatus, irsp->un.ulpWord[4],
  1534. irsp->un.elsreq64.remoteID);
  1535. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  1536. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
  1537. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1538. "2882 RRQ completes to NPort x%x "
  1539. "with no ndlp. Data: x%x x%x x%x\n",
  1540. irsp->un.elsreq64.remoteID,
  1541. irsp->ulpStatus, irsp->un.ulpWord[4],
  1542. irsp->ulpIoTag);
  1543. goto out;
  1544. }
  1545. /* rrq completes to NPort <nlp_DID> */
  1546. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1547. "2880 RRQ completes to NPort x%x "
  1548. "Data: x%x x%x x%x x%x x%x\n",
  1549. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1550. irsp->ulpTimeout, rrq->xritag, rrq->rxid);
  1551. if (irsp->ulpStatus) {
  1552. /* Check for retry */
  1553. /* RRQ failed Don't print the vport to vport rjts */
  1554. if (irsp->ulpStatus != IOSTAT_LS_RJT ||
  1555. (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
  1556. ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
  1557. (phba)->pport->cfg_log_verbose & LOG_ELS)
  1558. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1559. "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
  1560. ndlp->nlp_DID, irsp->ulpStatus,
  1561. irsp->un.ulpWord[4]);
  1562. }
  1563. out:
  1564. if (rrq)
  1565. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  1566. lpfc_els_free_iocb(phba, cmdiocb);
  1567. return;
  1568. }
  1569. /**
  1570. * lpfc_cmpl_els_plogi - Completion callback function for plogi
  1571. * @phba: pointer to lpfc hba data structure.
  1572. * @cmdiocb: pointer to lpfc command iocb data structure.
  1573. * @rspiocb: pointer to lpfc response iocb data structure.
  1574. *
  1575. * This routine is the completion callback function for issuing the Port
  1576. * Login (PLOGI) command. For PLOGI completion, there must be an active
  1577. * ndlp on the vport node list that matches the remote node ID from the
  1578. * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
  1579. * ignored and command IOCB released. The PLOGI response IOCB status is
  1580. * checked for error conditons. If there is error status reported, PLOGI
  1581. * retry shall be attempted by invoking the lpfc_els_retry() routine.
  1582. * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
  1583. * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
  1584. * (DSM) is set for this PLOGI completion. Finally, it checks whether
  1585. * there are additional N_Port nodes with the vport that need to perform
  1586. * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
  1587. * PLOGIs.
  1588. **/
  1589. static void
  1590. lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1591. struct lpfc_iocbq *rspiocb)
  1592. {
  1593. struct lpfc_vport *vport = cmdiocb->vport;
  1594. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1595. IOCB_t *irsp;
  1596. struct lpfc_nodelist *ndlp;
  1597. struct lpfc_dmabuf *prsp;
  1598. int disc, rc, did, type;
  1599. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1600. cmdiocb->context_un.rsp_iocb = rspiocb;
  1601. irsp = &rspiocb->iocb;
  1602. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1603. "PLOGI cmpl: status:x%x/x%x did:x%x",
  1604. irsp->ulpStatus, irsp->un.ulpWord[4],
  1605. irsp->un.elsreq64.remoteID);
  1606. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  1607. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  1608. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1609. "0136 PLOGI completes to NPort x%x "
  1610. "with no ndlp. Data: x%x x%x x%x\n",
  1611. irsp->un.elsreq64.remoteID,
  1612. irsp->ulpStatus, irsp->un.ulpWord[4],
  1613. irsp->ulpIoTag);
  1614. goto out;
  1615. }
  1616. /* Since ndlp can be freed in the disc state machine, note if this node
  1617. * is being used during discovery.
  1618. */
  1619. spin_lock_irq(shost->host_lock);
  1620. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  1621. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1622. spin_unlock_irq(shost->host_lock);
  1623. rc = 0;
  1624. /* PLOGI completes to NPort <nlp_DID> */
  1625. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1626. "0102 PLOGI completes to NPort x%x "
  1627. "Data: x%x x%x x%x x%x x%x\n",
  1628. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1629. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  1630. /* Check to see if link went down during discovery */
  1631. if (lpfc_els_chk_latt(vport)) {
  1632. spin_lock_irq(shost->host_lock);
  1633. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1634. spin_unlock_irq(shost->host_lock);
  1635. goto out;
  1636. }
  1637. /* ndlp could be freed in DSM, save these values now */
  1638. type = ndlp->nlp_type;
  1639. did = ndlp->nlp_DID;
  1640. if (irsp->ulpStatus) {
  1641. /* Check for retry */
  1642. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1643. /* ELS command is being retried */
  1644. if (disc) {
  1645. spin_lock_irq(shost->host_lock);
  1646. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1647. spin_unlock_irq(shost->host_lock);
  1648. }
  1649. goto out;
  1650. }
  1651. /* PLOGI failed Don't print the vport to vport rjts */
  1652. if (irsp->ulpStatus != IOSTAT_LS_RJT ||
  1653. (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
  1654. ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
  1655. (phba)->pport->cfg_log_verbose & LOG_ELS)
  1656. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1657. "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
  1658. ndlp->nlp_DID, irsp->ulpStatus,
  1659. irsp->un.ulpWord[4]);
  1660. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1661. if (lpfc_error_lost_link(irsp))
  1662. rc = NLP_STE_FREED_NODE;
  1663. else
  1664. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1665. NLP_EVT_CMPL_PLOGI);
  1666. } else {
  1667. /* Good status, call state machine */
  1668. prsp = list_entry(((struct lpfc_dmabuf *)
  1669. cmdiocb->context2)->list.next,
  1670. struct lpfc_dmabuf, list);
  1671. ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
  1672. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1673. NLP_EVT_CMPL_PLOGI);
  1674. }
  1675. if (disc && vport->num_disc_nodes) {
  1676. /* Check to see if there are more PLOGIs to be sent */
  1677. lpfc_more_plogi(vport);
  1678. if (vport->num_disc_nodes == 0) {
  1679. spin_lock_irq(shost->host_lock);
  1680. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1681. spin_unlock_irq(shost->host_lock);
  1682. lpfc_can_disctmo(vport);
  1683. lpfc_end_rscn(vport);
  1684. }
  1685. }
  1686. out:
  1687. lpfc_els_free_iocb(phba, cmdiocb);
  1688. return;
  1689. }
  1690. /**
  1691. * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
  1692. * @vport: pointer to a host virtual N_Port data structure.
  1693. * @did: destination port identifier.
  1694. * @retry: number of retries to the command IOCB.
  1695. *
  1696. * This routine issues a Port Login (PLOGI) command to a remote N_Port
  1697. * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
  1698. * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
  1699. * This routine constructs the proper feilds of the PLOGI IOCB and invokes
  1700. * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
  1701. *
  1702. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1703. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1704. * will be stored into the context1 field of the IOCB for the completion
  1705. * callback function to the PLOGI ELS command.
  1706. *
  1707. * Return code
  1708. * 0 - Successfully issued a plogi for @vport
  1709. * 1 - failed to issue a plogi for @vport
  1710. **/
  1711. int
  1712. lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
  1713. {
  1714. struct lpfc_hba *phba = vport->phba;
  1715. struct serv_parm *sp;
  1716. IOCB_t *icmd;
  1717. struct lpfc_nodelist *ndlp;
  1718. struct lpfc_iocbq *elsiocb;
  1719. struct lpfc_sli *psli;
  1720. uint8_t *pcmd;
  1721. uint16_t cmdsize;
  1722. int ret;
  1723. psli = &phba->sli;
  1724. ndlp = lpfc_findnode_did(vport, did);
  1725. if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
  1726. ndlp = NULL;
  1727. /* If ndlp is not NULL, we will bump the reference count on it */
  1728. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  1729. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  1730. ELS_CMD_PLOGI);
  1731. if (!elsiocb)
  1732. return 1;
  1733. icmd = &elsiocb->iocb;
  1734. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1735. /* For PLOGI request, remainder of payload is service parameters */
  1736. *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
  1737. pcmd += sizeof(uint32_t);
  1738. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1739. sp = (struct serv_parm *) pcmd;
  1740. /*
  1741. * If we are a N-port connected to a Fabric, fix-up paramm's so logins
  1742. * to device on remote loops work.
  1743. */
  1744. if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
  1745. sp->cmn.altBbCredit = 1;
  1746. if (sp->cmn.fcphLow < FC_PH_4_3)
  1747. sp->cmn.fcphLow = FC_PH_4_3;
  1748. if (sp->cmn.fcphHigh < FC_PH3)
  1749. sp->cmn.fcphHigh = FC_PH3;
  1750. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1751. "Issue PLOGI: did:x%x",
  1752. did, 0, 0);
  1753. phba->fc_stat.elsXmitPLOGI++;
  1754. elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
  1755. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  1756. if (ret == IOCB_ERROR) {
  1757. lpfc_els_free_iocb(phba, elsiocb);
  1758. return 1;
  1759. }
  1760. return 0;
  1761. }
  1762. /**
  1763. * lpfc_cmpl_els_prli - Completion callback function for prli
  1764. * @phba: pointer to lpfc hba data structure.
  1765. * @cmdiocb: pointer to lpfc command iocb data structure.
  1766. * @rspiocb: pointer to lpfc response iocb data structure.
  1767. *
  1768. * This routine is the completion callback function for a Process Login
  1769. * (PRLI) ELS command. The PRLI response IOCB status is checked for error
  1770. * status. If there is error status reported, PRLI retry shall be attempted
  1771. * by invoking the lpfc_els_retry() routine. Otherwise, the state
  1772. * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
  1773. * ndlp to mark the PRLI completion.
  1774. **/
  1775. static void
  1776. lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1777. struct lpfc_iocbq *rspiocb)
  1778. {
  1779. struct lpfc_vport *vport = cmdiocb->vport;
  1780. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1781. IOCB_t *irsp;
  1782. struct lpfc_sli *psli;
  1783. struct lpfc_nodelist *ndlp;
  1784. psli = &phba->sli;
  1785. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1786. cmdiocb->context_un.rsp_iocb = rspiocb;
  1787. irsp = &(rspiocb->iocb);
  1788. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1789. spin_lock_irq(shost->host_lock);
  1790. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  1791. spin_unlock_irq(shost->host_lock);
  1792. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1793. "PRLI cmpl: status:x%x/x%x did:x%x",
  1794. irsp->ulpStatus, irsp->un.ulpWord[4],
  1795. ndlp->nlp_DID);
  1796. /* PRLI completes to NPort <nlp_DID> */
  1797. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1798. "0103 PRLI completes to NPort x%x "
  1799. "Data: x%x x%x x%x x%x\n",
  1800. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1801. irsp->ulpTimeout, vport->num_disc_nodes);
  1802. vport->fc_prli_sent--;
  1803. /* Check to see if link went down during discovery */
  1804. if (lpfc_els_chk_latt(vport))
  1805. goto out;
  1806. if (irsp->ulpStatus) {
  1807. /* Check for retry */
  1808. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1809. /* ELS command is being retried */
  1810. goto out;
  1811. }
  1812. /* PRLI failed */
  1813. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1814. "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
  1815. ndlp->nlp_DID, irsp->ulpStatus,
  1816. irsp->un.ulpWord[4]);
  1817. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1818. if (lpfc_error_lost_link(irsp))
  1819. goto out;
  1820. else
  1821. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1822. NLP_EVT_CMPL_PRLI);
  1823. } else
  1824. /* Good status, call state machine */
  1825. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1826. NLP_EVT_CMPL_PRLI);
  1827. out:
  1828. lpfc_els_free_iocb(phba, cmdiocb);
  1829. return;
  1830. }
  1831. /**
  1832. * lpfc_issue_els_prli - Issue a prli iocb command for a vport
  1833. * @vport: pointer to a host virtual N_Port data structure.
  1834. * @ndlp: pointer to a node-list data structure.
  1835. * @retry: number of retries to the command IOCB.
  1836. *
  1837. * This routine issues a Process Login (PRLI) ELS command for the
  1838. * @vport. The PRLI service parameters are set up in the payload of the
  1839. * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
  1840. * is put to the IOCB completion callback func field before invoking the
  1841. * routine lpfc_sli_issue_iocb() to send out PRLI command.
  1842. *
  1843. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1844. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1845. * will be stored into the context1 field of the IOCB for the completion
  1846. * callback function to the PRLI ELS command.
  1847. *
  1848. * Return code
  1849. * 0 - successfully issued prli iocb command for @vport
  1850. * 1 - failed to issue prli iocb command for @vport
  1851. **/
  1852. int
  1853. lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1854. uint8_t retry)
  1855. {
  1856. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1857. struct lpfc_hba *phba = vport->phba;
  1858. PRLI *npr;
  1859. IOCB_t *icmd;
  1860. struct lpfc_iocbq *elsiocb;
  1861. uint8_t *pcmd;
  1862. uint16_t cmdsize;
  1863. cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
  1864. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1865. ndlp->nlp_DID, ELS_CMD_PRLI);
  1866. if (!elsiocb)
  1867. return 1;
  1868. icmd = &elsiocb->iocb;
  1869. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1870. /* For PRLI request, remainder of payload is service parameters */
  1871. memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
  1872. *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
  1873. pcmd += sizeof(uint32_t);
  1874. /* For PRLI, remainder of payload is PRLI parameter page */
  1875. npr = (PRLI *) pcmd;
  1876. /*
  1877. * If our firmware version is 3.20 or later,
  1878. * set the following bits for FC-TAPE support.
  1879. */
  1880. if (phba->vpd.rev.feaLevelHigh >= 0x02) {
  1881. npr->ConfmComplAllowed = 1;
  1882. npr->Retry = 1;
  1883. npr->TaskRetryIdReq = 1;
  1884. }
  1885. npr->estabImagePair = 1;
  1886. npr->readXferRdyDis = 1;
  1887. /* For FCP support */
  1888. npr->prliType = PRLI_FCP_TYPE;
  1889. npr->initiatorFunc = 1;
  1890. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1891. "Issue PRLI: did:x%x",
  1892. ndlp->nlp_DID, 0, 0);
  1893. phba->fc_stat.elsXmitPRLI++;
  1894. elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
  1895. spin_lock_irq(shost->host_lock);
  1896. ndlp->nlp_flag |= NLP_PRLI_SND;
  1897. spin_unlock_irq(shost->host_lock);
  1898. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  1899. IOCB_ERROR) {
  1900. spin_lock_irq(shost->host_lock);
  1901. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  1902. spin_unlock_irq(shost->host_lock);
  1903. lpfc_els_free_iocb(phba, elsiocb);
  1904. return 1;
  1905. }
  1906. vport->fc_prli_sent++;
  1907. return 0;
  1908. }
  1909. /**
  1910. * lpfc_rscn_disc - Perform rscn discovery for a vport
  1911. * @vport: pointer to a host virtual N_Port data structure.
  1912. *
  1913. * This routine performs Registration State Change Notification (RSCN)
  1914. * discovery for a @vport. If the @vport's node port recovery count is not
  1915. * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
  1916. * the nodes that need recovery. If none of the PLOGI were needed through
  1917. * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
  1918. * invoked to check and handle possible more RSCN came in during the period
  1919. * of processing the current ones.
  1920. **/
  1921. static void
  1922. lpfc_rscn_disc(struct lpfc_vport *vport)
  1923. {
  1924. lpfc_can_disctmo(vport);
  1925. /* RSCN discovery */
  1926. /* go thru NPR nodes and issue ELS PLOGIs */
  1927. if (vport->fc_npr_cnt)
  1928. if (lpfc_els_disc_plogi(vport))
  1929. return;
  1930. lpfc_end_rscn(vport);
  1931. }
  1932. /**
  1933. * lpfc_adisc_done - Complete the adisc phase of discovery
  1934. * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
  1935. *
  1936. * This function is called when the final ADISC is completed during discovery.
  1937. * This function handles clearing link attention or issuing reg_vpi depending
  1938. * on whether npiv is enabled. This function also kicks off the PLOGI phase of
  1939. * discovery.
  1940. * This function is called with no locks held.
  1941. **/
  1942. static void
  1943. lpfc_adisc_done(struct lpfc_vport *vport)
  1944. {
  1945. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1946. struct lpfc_hba *phba = vport->phba;
  1947. /*
  1948. * For NPIV, cmpl_reg_vpi will set port_state to READY,
  1949. * and continue discovery.
  1950. */
  1951. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1952. !(vport->fc_flag & FC_RSCN_MODE) &&
  1953. (phba->sli_rev < LPFC_SLI_REV4)) {
  1954. lpfc_issue_reg_vpi(phba, vport);
  1955. return;
  1956. }
  1957. /*
  1958. * For SLI2, we need to set port_state to READY
  1959. * and continue discovery.
  1960. */
  1961. if (vport->port_state < LPFC_VPORT_READY) {
  1962. /* If we get here, there is nothing to ADISC */
  1963. if (vport->port_type == LPFC_PHYSICAL_PORT)
  1964. lpfc_issue_clear_la(phba, vport);
  1965. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  1966. vport->num_disc_nodes = 0;
  1967. /* go thru NPR list, issue ELS PLOGIs */
  1968. if (vport->fc_npr_cnt)
  1969. lpfc_els_disc_plogi(vport);
  1970. if (!vport->num_disc_nodes) {
  1971. spin_lock_irq(shost->host_lock);
  1972. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1973. spin_unlock_irq(shost->host_lock);
  1974. lpfc_can_disctmo(vport);
  1975. lpfc_end_rscn(vport);
  1976. }
  1977. }
  1978. vport->port_state = LPFC_VPORT_READY;
  1979. } else
  1980. lpfc_rscn_disc(vport);
  1981. }
  1982. /**
  1983. * lpfc_more_adisc - Issue more adisc as needed
  1984. * @vport: pointer to a host virtual N_Port data structure.
  1985. *
  1986. * This routine determines whether there are more ndlps on a @vport
  1987. * node list need to have Address Discover (ADISC) issued. If so, it will
  1988. * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
  1989. * remaining nodes which need to have ADISC sent.
  1990. **/
  1991. void
  1992. lpfc_more_adisc(struct lpfc_vport *vport)
  1993. {
  1994. int sentadisc;
  1995. if (vport->num_disc_nodes)
  1996. vport->num_disc_nodes--;
  1997. /* Continue discovery with <num_disc_nodes> ADISCs to go */
  1998. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1999. "0210 Continue discovery with %d ADISCs to go "
  2000. "Data: x%x x%x x%x\n",
  2001. vport->num_disc_nodes, vport->fc_adisc_cnt,
  2002. vport->fc_flag, vport->port_state);
  2003. /* Check to see if there are more ADISCs to be sent */
  2004. if (vport->fc_flag & FC_NLP_MORE) {
  2005. lpfc_set_disctmo(vport);
  2006. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  2007. sentadisc = lpfc_els_disc_adisc(vport);
  2008. }
  2009. if (!vport->num_disc_nodes)
  2010. lpfc_adisc_done(vport);
  2011. return;
  2012. }
  2013. /**
  2014. * lpfc_cmpl_els_adisc - Completion callback function for adisc
  2015. * @phba: pointer to lpfc hba data structure.
  2016. * @cmdiocb: pointer to lpfc command iocb data structure.
  2017. * @rspiocb: pointer to lpfc response iocb data structure.
  2018. *
  2019. * This routine is the completion function for issuing the Address Discover
  2020. * (ADISC) command. It first checks to see whether link went down during
  2021. * the discovery process. If so, the node will be marked as node port
  2022. * recovery for issuing discover IOCB by the link attention handler and
  2023. * exit. Otherwise, the response status is checked. If error was reported
  2024. * in the response status, the ADISC command shall be retried by invoking
  2025. * the lpfc_els_retry() routine. Otherwise, if no error was reported in
  2026. * the response status, the state machine is invoked to set transition
  2027. * with respect to NLP_EVT_CMPL_ADISC event.
  2028. **/
  2029. static void
  2030. lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2031. struct lpfc_iocbq *rspiocb)
  2032. {
  2033. struct lpfc_vport *vport = cmdiocb->vport;
  2034. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2035. IOCB_t *irsp;
  2036. struct lpfc_nodelist *ndlp;
  2037. int disc;
  2038. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2039. cmdiocb->context_un.rsp_iocb = rspiocb;
  2040. irsp = &(rspiocb->iocb);
  2041. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2042. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2043. "ADISC cmpl: status:x%x/x%x did:x%x",
  2044. irsp->ulpStatus, irsp->un.ulpWord[4],
  2045. ndlp->nlp_DID);
  2046. /* Since ndlp can be freed in the disc state machine, note if this node
  2047. * is being used during discovery.
  2048. */
  2049. spin_lock_irq(shost->host_lock);
  2050. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  2051. ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
  2052. spin_unlock_irq(shost->host_lock);
  2053. /* ADISC completes to NPort <nlp_DID> */
  2054. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2055. "0104 ADISC completes to NPort x%x "
  2056. "Data: x%x x%x x%x x%x x%x\n",
  2057. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  2058. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  2059. /* Check to see if link went down during discovery */
  2060. if (lpfc_els_chk_latt(vport)) {
  2061. spin_lock_irq(shost->host_lock);
  2062. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2063. spin_unlock_irq(shost->host_lock);
  2064. goto out;
  2065. }
  2066. if (irsp->ulpStatus) {
  2067. /* Check for retry */
  2068. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  2069. /* ELS command is being retried */
  2070. if (disc) {
  2071. spin_lock_irq(shost->host_lock);
  2072. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2073. spin_unlock_irq(shost->host_lock);
  2074. lpfc_set_disctmo(vport);
  2075. }
  2076. goto out;
  2077. }
  2078. /* ADISC failed */
  2079. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2080. "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
  2081. ndlp->nlp_DID, irsp->ulpStatus,
  2082. irsp->un.ulpWord[4]);
  2083. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  2084. if (!lpfc_error_lost_link(irsp))
  2085. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2086. NLP_EVT_CMPL_ADISC);
  2087. } else
  2088. /* Good status, call state machine */
  2089. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2090. NLP_EVT_CMPL_ADISC);
  2091. /* Check to see if there are more ADISCs to be sent */
  2092. if (disc && vport->num_disc_nodes)
  2093. lpfc_more_adisc(vport);
  2094. out:
  2095. lpfc_els_free_iocb(phba, cmdiocb);
  2096. return;
  2097. }
  2098. /**
  2099. * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
  2100. * @vport: pointer to a virtual N_Port data structure.
  2101. * @ndlp: pointer to a node-list data structure.
  2102. * @retry: number of retries to the command IOCB.
  2103. *
  2104. * This routine issues an Address Discover (ADISC) for an @ndlp on a
  2105. * @vport. It prepares the payload of the ADISC ELS command, updates the
  2106. * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
  2107. * to issue the ADISC ELS command.
  2108. *
  2109. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2110. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2111. * will be stored into the context1 field of the IOCB for the completion
  2112. * callback function to the ADISC ELS command.
  2113. *
  2114. * Return code
  2115. * 0 - successfully issued adisc
  2116. * 1 - failed to issue adisc
  2117. **/
  2118. int
  2119. lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2120. uint8_t retry)
  2121. {
  2122. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2123. struct lpfc_hba *phba = vport->phba;
  2124. ADISC *ap;
  2125. IOCB_t *icmd;
  2126. struct lpfc_iocbq *elsiocb;
  2127. uint8_t *pcmd;
  2128. uint16_t cmdsize;
  2129. cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
  2130. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2131. ndlp->nlp_DID, ELS_CMD_ADISC);
  2132. if (!elsiocb)
  2133. return 1;
  2134. icmd = &elsiocb->iocb;
  2135. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2136. /* For ADISC request, remainder of payload is service parameters */
  2137. *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
  2138. pcmd += sizeof(uint32_t);
  2139. /* Fill in ADISC payload */
  2140. ap = (ADISC *) pcmd;
  2141. ap->hardAL_PA = phba->fc_pref_ALPA;
  2142. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2143. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2144. ap->DID = be32_to_cpu(vport->fc_myDID);
  2145. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2146. "Issue ADISC: did:x%x",
  2147. ndlp->nlp_DID, 0, 0);
  2148. phba->fc_stat.elsXmitADISC++;
  2149. elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
  2150. spin_lock_irq(shost->host_lock);
  2151. ndlp->nlp_flag |= NLP_ADISC_SND;
  2152. spin_unlock_irq(shost->host_lock);
  2153. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2154. IOCB_ERROR) {
  2155. spin_lock_irq(shost->host_lock);
  2156. ndlp->nlp_flag &= ~NLP_ADISC_SND;
  2157. spin_unlock_irq(shost->host_lock);
  2158. lpfc_els_free_iocb(phba, elsiocb);
  2159. return 1;
  2160. }
  2161. return 0;
  2162. }
  2163. /**
  2164. * lpfc_cmpl_els_logo - Completion callback function for logo
  2165. * @phba: pointer to lpfc hba data structure.
  2166. * @cmdiocb: pointer to lpfc command iocb data structure.
  2167. * @rspiocb: pointer to lpfc response iocb data structure.
  2168. *
  2169. * This routine is the completion function for issuing the ELS Logout (LOGO)
  2170. * command. If no error status was reported from the LOGO response, the
  2171. * state machine of the associated ndlp shall be invoked for transition with
  2172. * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
  2173. * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
  2174. **/
  2175. static void
  2176. lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2177. struct lpfc_iocbq *rspiocb)
  2178. {
  2179. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2180. struct lpfc_vport *vport = ndlp->vport;
  2181. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2182. IOCB_t *irsp;
  2183. struct lpfc_sli *psli;
  2184. struct lpfcMboxq *mbox;
  2185. unsigned long flags;
  2186. uint32_t skip_recovery = 0;
  2187. psli = &phba->sli;
  2188. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2189. cmdiocb->context_un.rsp_iocb = rspiocb;
  2190. irsp = &(rspiocb->iocb);
  2191. spin_lock_irq(shost->host_lock);
  2192. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  2193. spin_unlock_irq(shost->host_lock);
  2194. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2195. "LOGO cmpl: status:x%x/x%x did:x%x",
  2196. irsp->ulpStatus, irsp->un.ulpWord[4],
  2197. ndlp->nlp_DID);
  2198. /* LOGO completes to NPort <nlp_DID> */
  2199. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2200. "0105 LOGO completes to NPort x%x "
  2201. "Data: x%x x%x x%x x%x\n",
  2202. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  2203. irsp->ulpTimeout, vport->num_disc_nodes);
  2204. if (lpfc_els_chk_latt(vport)) {
  2205. skip_recovery = 1;
  2206. goto out;
  2207. }
  2208. /* Check to see if link went down during discovery */
  2209. if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
  2210. /* NLP_EVT_DEVICE_RM should unregister the RPI
  2211. * which should abort all outstanding IOs.
  2212. */
  2213. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2214. NLP_EVT_DEVICE_RM);
  2215. skip_recovery = 1;
  2216. goto out;
  2217. }
  2218. if (irsp->ulpStatus) {
  2219. /* Check for retry */
  2220. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  2221. /* ELS command is being retried */
  2222. skip_recovery = 1;
  2223. goto out;
  2224. }
  2225. /* LOGO failed */
  2226. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2227. "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
  2228. ndlp->nlp_DID, irsp->ulpStatus,
  2229. irsp->un.ulpWord[4]);
  2230. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  2231. if (lpfc_error_lost_link(irsp)) {
  2232. skip_recovery = 1;
  2233. goto out;
  2234. }
  2235. }
  2236. /* Call state machine. This will unregister the rpi if needed. */
  2237. lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
  2238. out:
  2239. lpfc_els_free_iocb(phba, cmdiocb);
  2240. /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
  2241. if ((vport->fc_flag & FC_PT2PT) &&
  2242. !(vport->fc_flag & FC_PT2PT_PLOGI)) {
  2243. phba->pport->fc_myDID = 0;
  2244. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2245. if (mbox) {
  2246. lpfc_config_link(phba, mbox);
  2247. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2248. mbox->vport = vport;
  2249. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
  2250. MBX_NOT_FINISHED) {
  2251. mempool_free(mbox, phba->mbox_mem_pool);
  2252. skip_recovery = 1;
  2253. }
  2254. }
  2255. }
  2256. /*
  2257. * If the node is a target, the handling attempts to recover the port.
  2258. * For any other port type, the rpi is unregistered as an implicit
  2259. * LOGO.
  2260. */
  2261. if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
  2262. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2263. spin_lock_irqsave(shost->host_lock, flags);
  2264. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2265. spin_unlock_irqrestore(shost->host_lock, flags);
  2266. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2267. "3187 LOGO completes to NPort x%x: Start "
  2268. "Recovery Data: x%x x%x x%x x%x\n",
  2269. ndlp->nlp_DID, irsp->ulpStatus,
  2270. irsp->un.ulpWord[4], irsp->ulpTimeout,
  2271. vport->num_disc_nodes);
  2272. lpfc_disc_start(vport);
  2273. }
  2274. return;
  2275. }
  2276. /**
  2277. * lpfc_issue_els_logo - Issue a logo to an node on a vport
  2278. * @vport: pointer to a virtual N_Port data structure.
  2279. * @ndlp: pointer to a node-list data structure.
  2280. * @retry: number of retries to the command IOCB.
  2281. *
  2282. * This routine constructs and issues an ELS Logout (LOGO) iocb command
  2283. * to a remote node, referred by an @ndlp on a @vport. It constructs the
  2284. * payload of the IOCB, properly sets up the @ndlp state, and invokes the
  2285. * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
  2286. *
  2287. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2288. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2289. * will be stored into the context1 field of the IOCB for the completion
  2290. * callback function to the LOGO ELS command.
  2291. *
  2292. * Return code
  2293. * 0 - successfully issued logo
  2294. * 1 - failed to issue logo
  2295. **/
  2296. int
  2297. lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2298. uint8_t retry)
  2299. {
  2300. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2301. struct lpfc_hba *phba = vport->phba;
  2302. IOCB_t *icmd;
  2303. struct lpfc_iocbq *elsiocb;
  2304. uint8_t *pcmd;
  2305. uint16_t cmdsize;
  2306. int rc;
  2307. spin_lock_irq(shost->host_lock);
  2308. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  2309. spin_unlock_irq(shost->host_lock);
  2310. return 0;
  2311. }
  2312. spin_unlock_irq(shost->host_lock);
  2313. cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
  2314. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2315. ndlp->nlp_DID, ELS_CMD_LOGO);
  2316. if (!elsiocb)
  2317. return 1;
  2318. icmd = &elsiocb->iocb;
  2319. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2320. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  2321. pcmd += sizeof(uint32_t);
  2322. /* Fill in LOGO payload */
  2323. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  2324. pcmd += sizeof(uint32_t);
  2325. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  2326. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2327. "Issue LOGO: did:x%x",
  2328. ndlp->nlp_DID, 0, 0);
  2329. /*
  2330. * If we are issuing a LOGO, we may try to recover the remote NPort
  2331. * by issuing a PLOGI later. Even though we issue ELS cmds by the
  2332. * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
  2333. * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
  2334. * for that ELS cmd. To avoid this situation, lets get rid of the
  2335. * RPI right now, before any ELS cmds are sent.
  2336. */
  2337. spin_lock_irq(shost->host_lock);
  2338. ndlp->nlp_flag |= NLP_ISSUE_LOGO;
  2339. spin_unlock_irq(shost->host_lock);
  2340. if (lpfc_unreg_rpi(vport, ndlp)) {
  2341. lpfc_els_free_iocb(phba, elsiocb);
  2342. return 0;
  2343. }
  2344. phba->fc_stat.elsXmitLOGO++;
  2345. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
  2346. spin_lock_irq(shost->host_lock);
  2347. ndlp->nlp_flag |= NLP_LOGO_SND;
  2348. ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
  2349. spin_unlock_irq(shost->host_lock);
  2350. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  2351. if (rc == IOCB_ERROR) {
  2352. spin_lock_irq(shost->host_lock);
  2353. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  2354. spin_unlock_irq(shost->host_lock);
  2355. lpfc_els_free_iocb(phba, elsiocb);
  2356. return 1;
  2357. }
  2358. return 0;
  2359. }
  2360. /**
  2361. * lpfc_cmpl_els_cmd - Completion callback function for generic els command
  2362. * @phba: pointer to lpfc hba data structure.
  2363. * @cmdiocb: pointer to lpfc command iocb data structure.
  2364. * @rspiocb: pointer to lpfc response iocb data structure.
  2365. *
  2366. * This routine is a generic completion callback function for ELS commands.
  2367. * Specifically, it is the callback function which does not need to perform
  2368. * any command specific operations. It is currently used by the ELS command
  2369. * issuing routines for the ELS State Change Request (SCR),
  2370. * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
  2371. * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
  2372. * certain debug loggings, this callback function simply invokes the
  2373. * lpfc_els_chk_latt() routine to check whether link went down during the
  2374. * discovery process.
  2375. **/
  2376. static void
  2377. lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2378. struct lpfc_iocbq *rspiocb)
  2379. {
  2380. struct lpfc_vport *vport = cmdiocb->vport;
  2381. IOCB_t *irsp;
  2382. irsp = &rspiocb->iocb;
  2383. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2384. "ELS cmd cmpl: status:x%x/x%x did:x%x",
  2385. irsp->ulpStatus, irsp->un.ulpWord[4],
  2386. irsp->un.elsreq64.remoteID);
  2387. /* ELS cmd tag <ulpIoTag> completes */
  2388. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2389. "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
  2390. irsp->ulpIoTag, irsp->ulpStatus,
  2391. irsp->un.ulpWord[4], irsp->ulpTimeout);
  2392. /* Check to see if link went down during discovery */
  2393. lpfc_els_chk_latt(vport);
  2394. lpfc_els_free_iocb(phba, cmdiocb);
  2395. return;
  2396. }
  2397. /**
  2398. * lpfc_issue_els_scr - Issue a scr to an node on a vport
  2399. * @vport: pointer to a host virtual N_Port data structure.
  2400. * @nportid: N_Port identifier to the remote node.
  2401. * @retry: number of retries to the command IOCB.
  2402. *
  2403. * This routine issues a State Change Request (SCR) to a fabric node
  2404. * on a @vport. The remote node @nportid is passed into the function. It
  2405. * first search the @vport node list to find the matching ndlp. If no such
  2406. * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
  2407. * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
  2408. * routine is invoked to send the SCR IOCB.
  2409. *
  2410. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2411. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2412. * will be stored into the context1 field of the IOCB for the completion
  2413. * callback function to the SCR ELS command.
  2414. *
  2415. * Return code
  2416. * 0 - Successfully issued scr command
  2417. * 1 - Failed to issue scr command
  2418. **/
  2419. int
  2420. lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  2421. {
  2422. struct lpfc_hba *phba = vport->phba;
  2423. IOCB_t *icmd;
  2424. struct lpfc_iocbq *elsiocb;
  2425. struct lpfc_sli *psli;
  2426. uint8_t *pcmd;
  2427. uint16_t cmdsize;
  2428. struct lpfc_nodelist *ndlp;
  2429. psli = &phba->sli;
  2430. cmdsize = (sizeof(uint32_t) + sizeof(SCR));
  2431. ndlp = lpfc_findnode_did(vport, nportid);
  2432. if (!ndlp) {
  2433. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2434. if (!ndlp)
  2435. return 1;
  2436. lpfc_nlp_init(vport, ndlp, nportid);
  2437. lpfc_enqueue_node(vport, ndlp);
  2438. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  2439. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  2440. if (!ndlp)
  2441. return 1;
  2442. }
  2443. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2444. ndlp->nlp_DID, ELS_CMD_SCR);
  2445. if (!elsiocb) {
  2446. /* This will trigger the release of the node just
  2447. * allocated
  2448. */
  2449. lpfc_nlp_put(ndlp);
  2450. return 1;
  2451. }
  2452. icmd = &elsiocb->iocb;
  2453. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2454. *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
  2455. pcmd += sizeof(uint32_t);
  2456. /* For SCR, remainder of payload is SCR parameter page */
  2457. memset(pcmd, 0, sizeof(SCR));
  2458. ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
  2459. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2460. "Issue SCR: did:x%x",
  2461. ndlp->nlp_DID, 0, 0);
  2462. phba->fc_stat.elsXmitSCR++;
  2463. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  2464. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2465. IOCB_ERROR) {
  2466. /* The additional lpfc_nlp_put will cause the following
  2467. * lpfc_els_free_iocb routine to trigger the rlease of
  2468. * the node.
  2469. */
  2470. lpfc_nlp_put(ndlp);
  2471. lpfc_els_free_iocb(phba, elsiocb);
  2472. return 1;
  2473. }
  2474. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  2475. * trigger the release of node.
  2476. */
  2477. lpfc_nlp_put(ndlp);
  2478. return 0;
  2479. }
  2480. /**
  2481. * lpfc_issue_els_farpr - Issue a farp to an node on a vport
  2482. * @vport: pointer to a host virtual N_Port data structure.
  2483. * @nportid: N_Port identifier to the remote node.
  2484. * @retry: number of retries to the command IOCB.
  2485. *
  2486. * This routine issues a Fibre Channel Address Resolution Response
  2487. * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
  2488. * is passed into the function. It first search the @vport node list to find
  2489. * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
  2490. * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
  2491. * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
  2492. *
  2493. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2494. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2495. * will be stored into the context1 field of the IOCB for the completion
  2496. * callback function to the PARPR ELS command.
  2497. *
  2498. * Return code
  2499. * 0 - Successfully issued farpr command
  2500. * 1 - Failed to issue farpr command
  2501. **/
  2502. static int
  2503. lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  2504. {
  2505. struct lpfc_hba *phba = vport->phba;
  2506. IOCB_t *icmd;
  2507. struct lpfc_iocbq *elsiocb;
  2508. struct lpfc_sli *psli;
  2509. FARP *fp;
  2510. uint8_t *pcmd;
  2511. uint32_t *lp;
  2512. uint16_t cmdsize;
  2513. struct lpfc_nodelist *ondlp;
  2514. struct lpfc_nodelist *ndlp;
  2515. psli = &phba->sli;
  2516. cmdsize = (sizeof(uint32_t) + sizeof(FARP));
  2517. ndlp = lpfc_findnode_did(vport, nportid);
  2518. if (!ndlp) {
  2519. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2520. if (!ndlp)
  2521. return 1;
  2522. lpfc_nlp_init(vport, ndlp, nportid);
  2523. lpfc_enqueue_node(vport, ndlp);
  2524. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  2525. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  2526. if (!ndlp)
  2527. return 1;
  2528. }
  2529. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2530. ndlp->nlp_DID, ELS_CMD_RNID);
  2531. if (!elsiocb) {
  2532. /* This will trigger the release of the node just
  2533. * allocated
  2534. */
  2535. lpfc_nlp_put(ndlp);
  2536. return 1;
  2537. }
  2538. icmd = &elsiocb->iocb;
  2539. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2540. *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
  2541. pcmd += sizeof(uint32_t);
  2542. /* Fill in FARPR payload */
  2543. fp = (FARP *) (pcmd);
  2544. memset(fp, 0, sizeof(FARP));
  2545. lp = (uint32_t *) pcmd;
  2546. *lp++ = be32_to_cpu(nportid);
  2547. *lp++ = be32_to_cpu(vport->fc_myDID);
  2548. fp->Rflags = 0;
  2549. fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
  2550. memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
  2551. memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2552. ondlp = lpfc_findnode_did(vport, nportid);
  2553. if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
  2554. memcpy(&fp->OportName, &ondlp->nlp_portname,
  2555. sizeof(struct lpfc_name));
  2556. memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
  2557. sizeof(struct lpfc_name));
  2558. }
  2559. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2560. "Issue FARPR: did:x%x",
  2561. ndlp->nlp_DID, 0, 0);
  2562. phba->fc_stat.elsXmitFARPR++;
  2563. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  2564. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2565. IOCB_ERROR) {
  2566. /* The additional lpfc_nlp_put will cause the following
  2567. * lpfc_els_free_iocb routine to trigger the release of
  2568. * the node.
  2569. */
  2570. lpfc_nlp_put(ndlp);
  2571. lpfc_els_free_iocb(phba, elsiocb);
  2572. return 1;
  2573. }
  2574. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  2575. * trigger the release of the node.
  2576. */
  2577. lpfc_nlp_put(ndlp);
  2578. return 0;
  2579. }
  2580. /**
  2581. * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
  2582. * @vport: pointer to a host virtual N_Port data structure.
  2583. * @nlp: pointer to a node-list data structure.
  2584. *
  2585. * This routine cancels the timer with a delayed IOCB-command retry for
  2586. * a @vport's @ndlp. It stops the timer for the delayed function retrial and
  2587. * removes the ELS retry event if it presents. In addition, if the
  2588. * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
  2589. * commands are sent for the @vport's nodes that require issuing discovery
  2590. * ADISC.
  2591. **/
  2592. void
  2593. lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
  2594. {
  2595. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2596. struct lpfc_work_evt *evtp;
  2597. if (!(nlp->nlp_flag & NLP_DELAY_TMO))
  2598. return;
  2599. spin_lock_irq(shost->host_lock);
  2600. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  2601. spin_unlock_irq(shost->host_lock);
  2602. del_timer_sync(&nlp->nlp_delayfunc);
  2603. nlp->nlp_last_elscmd = 0;
  2604. if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
  2605. list_del_init(&nlp->els_retry_evt.evt_listp);
  2606. /* Decrement nlp reference count held for the delayed retry */
  2607. evtp = &nlp->els_retry_evt;
  2608. lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
  2609. }
  2610. if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
  2611. spin_lock_irq(shost->host_lock);
  2612. nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  2613. spin_unlock_irq(shost->host_lock);
  2614. if (vport->num_disc_nodes) {
  2615. if (vport->port_state < LPFC_VPORT_READY) {
  2616. /* Check if there are more ADISCs to be sent */
  2617. lpfc_more_adisc(vport);
  2618. } else {
  2619. /* Check if there are more PLOGIs to be sent */
  2620. lpfc_more_plogi(vport);
  2621. if (vport->num_disc_nodes == 0) {
  2622. spin_lock_irq(shost->host_lock);
  2623. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2624. spin_unlock_irq(shost->host_lock);
  2625. lpfc_can_disctmo(vport);
  2626. lpfc_end_rscn(vport);
  2627. }
  2628. }
  2629. }
  2630. }
  2631. return;
  2632. }
  2633. /**
  2634. * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
  2635. * @ptr: holder for the pointer to the timer function associated data (ndlp).
  2636. *
  2637. * This routine is invoked by the ndlp delayed-function timer to check
  2638. * whether there is any pending ELS retry event(s) with the node. If not, it
  2639. * simply returns. Otherwise, if there is at least one ELS delayed event, it
  2640. * adds the delayed events to the HBA work list and invokes the
  2641. * lpfc_worker_wake_up() routine to wake up worker thread to process the
  2642. * event. Note that lpfc_nlp_get() is called before posting the event to
  2643. * the work list to hold reference count of ndlp so that it guarantees the
  2644. * reference to ndlp will still be available when the worker thread gets
  2645. * to the event associated with the ndlp.
  2646. **/
  2647. void
  2648. lpfc_els_retry_delay(unsigned long ptr)
  2649. {
  2650. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
  2651. struct lpfc_vport *vport = ndlp->vport;
  2652. struct lpfc_hba *phba = vport->phba;
  2653. unsigned long flags;
  2654. struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
  2655. spin_lock_irqsave(&phba->hbalock, flags);
  2656. if (!list_empty(&evtp->evt_listp)) {
  2657. spin_unlock_irqrestore(&phba->hbalock, flags);
  2658. return;
  2659. }
  2660. /* We need to hold the node by incrementing the reference
  2661. * count until the queued work is done
  2662. */
  2663. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  2664. if (evtp->evt_arg1) {
  2665. evtp->evt = LPFC_EVT_ELS_RETRY;
  2666. list_add_tail(&evtp->evt_listp, &phba->work_list);
  2667. lpfc_worker_wake_up(phba);
  2668. }
  2669. spin_unlock_irqrestore(&phba->hbalock, flags);
  2670. return;
  2671. }
  2672. /**
  2673. * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
  2674. * @ndlp: pointer to a node-list data structure.
  2675. *
  2676. * This routine is the worker-thread handler for processing the @ndlp delayed
  2677. * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
  2678. * the last ELS command from the associated ndlp and invokes the proper ELS
  2679. * function according to the delayed ELS command to retry the command.
  2680. **/
  2681. void
  2682. lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
  2683. {
  2684. struct lpfc_vport *vport = ndlp->vport;
  2685. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2686. uint32_t cmd, did, retry;
  2687. spin_lock_irq(shost->host_lock);
  2688. did = ndlp->nlp_DID;
  2689. cmd = ndlp->nlp_last_elscmd;
  2690. ndlp->nlp_last_elscmd = 0;
  2691. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  2692. spin_unlock_irq(shost->host_lock);
  2693. return;
  2694. }
  2695. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  2696. spin_unlock_irq(shost->host_lock);
  2697. /*
  2698. * If a discovery event readded nlp_delayfunc after timer
  2699. * firing and before processing the timer, cancel the
  2700. * nlp_delayfunc.
  2701. */
  2702. del_timer_sync(&ndlp->nlp_delayfunc);
  2703. retry = ndlp->nlp_retry;
  2704. ndlp->nlp_retry = 0;
  2705. switch (cmd) {
  2706. case ELS_CMD_FLOGI:
  2707. lpfc_issue_els_flogi(vport, ndlp, retry);
  2708. break;
  2709. case ELS_CMD_PLOGI:
  2710. if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
  2711. ndlp->nlp_prev_state = ndlp->nlp_state;
  2712. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2713. }
  2714. break;
  2715. case ELS_CMD_ADISC:
  2716. if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
  2717. ndlp->nlp_prev_state = ndlp->nlp_state;
  2718. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2719. }
  2720. break;
  2721. case ELS_CMD_PRLI:
  2722. if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
  2723. ndlp->nlp_prev_state = ndlp->nlp_state;
  2724. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  2725. }
  2726. break;
  2727. case ELS_CMD_LOGO:
  2728. if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
  2729. ndlp->nlp_prev_state = ndlp->nlp_state;
  2730. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  2731. }
  2732. break;
  2733. case ELS_CMD_FDISC:
  2734. if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
  2735. lpfc_issue_els_fdisc(vport, ndlp, retry);
  2736. break;
  2737. }
  2738. return;
  2739. }
  2740. /**
  2741. * lpfc_els_retry - Make retry decision on an els command iocb
  2742. * @phba: pointer to lpfc hba data structure.
  2743. * @cmdiocb: pointer to lpfc command iocb data structure.
  2744. * @rspiocb: pointer to lpfc response iocb data structure.
  2745. *
  2746. * This routine makes a retry decision on an ELS command IOCB, which has
  2747. * failed. The following ELS IOCBs use this function for retrying the command
  2748. * when previously issued command responsed with error status: FLOGI, PLOGI,
  2749. * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
  2750. * returned error status, it makes the decision whether a retry shall be
  2751. * issued for the command, and whether a retry shall be made immediately or
  2752. * delayed. In the former case, the corresponding ELS command issuing-function
  2753. * is called to retry the command. In the later case, the ELS command shall
  2754. * be posted to the ndlp delayed event and delayed function timer set to the
  2755. * ndlp for the delayed command issusing.
  2756. *
  2757. * Return code
  2758. * 0 - No retry of els command is made
  2759. * 1 - Immediate or delayed retry of els command is made
  2760. **/
  2761. static int
  2762. lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2763. struct lpfc_iocbq *rspiocb)
  2764. {
  2765. struct lpfc_vport *vport = cmdiocb->vport;
  2766. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2767. IOCB_t *irsp = &rspiocb->iocb;
  2768. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2769. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2770. uint32_t *elscmd;
  2771. struct ls_rjt stat;
  2772. int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
  2773. int logerr = 0;
  2774. uint32_t cmd = 0;
  2775. uint32_t did;
  2776. /* Note: context2 may be 0 for internal driver abort
  2777. * of delays ELS command.
  2778. */
  2779. if (pcmd && pcmd->virt) {
  2780. elscmd = (uint32_t *) (pcmd->virt);
  2781. cmd = *elscmd++;
  2782. }
  2783. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  2784. did = ndlp->nlp_DID;
  2785. else {
  2786. /* We should only hit this case for retrying PLOGI */
  2787. did = irsp->un.elsreq64.remoteID;
  2788. ndlp = lpfc_findnode_did(vport, did);
  2789. if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  2790. && (cmd != ELS_CMD_PLOGI))
  2791. return 1;
  2792. }
  2793. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2794. "Retry ELS: wd7:x%x wd4:x%x did:x%x",
  2795. *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
  2796. switch (irsp->ulpStatus) {
  2797. case IOSTAT_FCP_RSP_ERROR:
  2798. break;
  2799. case IOSTAT_REMOTE_STOP:
  2800. if (phba->sli_rev == LPFC_SLI_REV4) {
  2801. /* This IO was aborted by the target, we don't
  2802. * know the rxid and because we did not send the
  2803. * ABTS we cannot generate and RRQ.
  2804. */
  2805. lpfc_set_rrq_active(phba, ndlp,
  2806. cmdiocb->sli4_lxritag, 0, 0);
  2807. }
  2808. break;
  2809. case IOSTAT_LOCAL_REJECT:
  2810. switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
  2811. case IOERR_LOOP_OPEN_FAILURE:
  2812. if (cmd == ELS_CMD_FLOGI) {
  2813. if (PCI_DEVICE_ID_HORNET ==
  2814. phba->pcidev->device) {
  2815. phba->fc_topology = LPFC_TOPOLOGY_LOOP;
  2816. phba->pport->fc_myDID = 0;
  2817. phba->alpa_map[0] = 0;
  2818. phba->alpa_map[1] = 0;
  2819. }
  2820. }
  2821. if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
  2822. delay = 1000;
  2823. retry = 1;
  2824. break;
  2825. case IOERR_ILLEGAL_COMMAND:
  2826. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2827. "0124 Retry illegal cmd x%x "
  2828. "retry:x%x delay:x%x\n",
  2829. cmd, cmdiocb->retry, delay);
  2830. retry = 1;
  2831. /* All command's retry policy */
  2832. maxretry = 8;
  2833. if (cmdiocb->retry > 2)
  2834. delay = 1000;
  2835. break;
  2836. case IOERR_NO_RESOURCES:
  2837. logerr = 1; /* HBA out of resources */
  2838. retry = 1;
  2839. if (cmdiocb->retry > 100)
  2840. delay = 100;
  2841. maxretry = 250;
  2842. break;
  2843. case IOERR_ILLEGAL_FRAME:
  2844. delay = 100;
  2845. retry = 1;
  2846. break;
  2847. case IOERR_SEQUENCE_TIMEOUT:
  2848. case IOERR_INVALID_RPI:
  2849. if (cmd == ELS_CMD_PLOGI &&
  2850. did == NameServer_DID) {
  2851. /* Continue forever if plogi to */
  2852. /* the nameserver fails */
  2853. maxretry = 0;
  2854. delay = 100;
  2855. }
  2856. retry = 1;
  2857. break;
  2858. }
  2859. break;
  2860. case IOSTAT_NPORT_RJT:
  2861. case IOSTAT_FABRIC_RJT:
  2862. if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  2863. retry = 1;
  2864. break;
  2865. }
  2866. break;
  2867. case IOSTAT_NPORT_BSY:
  2868. case IOSTAT_FABRIC_BSY:
  2869. logerr = 1; /* Fabric / Remote NPort out of resources */
  2870. retry = 1;
  2871. break;
  2872. case IOSTAT_LS_RJT:
  2873. stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
  2874. /* Added for Vendor specifc support
  2875. * Just keep retrying for these Rsn / Exp codes
  2876. */
  2877. switch (stat.un.b.lsRjtRsnCode) {
  2878. case LSRJT_UNABLE_TPC:
  2879. if (stat.un.b.lsRjtRsnCodeExp ==
  2880. LSEXP_CMD_IN_PROGRESS) {
  2881. if (cmd == ELS_CMD_PLOGI) {
  2882. delay = 1000;
  2883. maxretry = 48;
  2884. }
  2885. retry = 1;
  2886. break;
  2887. }
  2888. if (stat.un.b.lsRjtRsnCodeExp ==
  2889. LSEXP_CANT_GIVE_DATA) {
  2890. if (cmd == ELS_CMD_PLOGI) {
  2891. delay = 1000;
  2892. maxretry = 48;
  2893. }
  2894. retry = 1;
  2895. break;
  2896. }
  2897. if ((cmd == ELS_CMD_PLOGI) ||
  2898. (cmd == ELS_CMD_PRLI)) {
  2899. delay = 1000;
  2900. maxretry = lpfc_max_els_tries + 1;
  2901. retry = 1;
  2902. break;
  2903. }
  2904. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2905. (cmd == ELS_CMD_FDISC) &&
  2906. (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
  2907. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2908. "0125 FDISC Failed (x%x). "
  2909. "Fabric out of resources\n",
  2910. stat.un.lsRjtError);
  2911. lpfc_vport_set_state(vport,
  2912. FC_VPORT_NO_FABRIC_RSCS);
  2913. }
  2914. break;
  2915. case LSRJT_LOGICAL_BSY:
  2916. if ((cmd == ELS_CMD_PLOGI) ||
  2917. (cmd == ELS_CMD_PRLI)) {
  2918. delay = 1000;
  2919. maxretry = 48;
  2920. } else if (cmd == ELS_CMD_FDISC) {
  2921. /* FDISC retry policy */
  2922. maxretry = 48;
  2923. if (cmdiocb->retry >= 32)
  2924. delay = 1000;
  2925. }
  2926. retry = 1;
  2927. break;
  2928. case LSRJT_LOGICAL_ERR:
  2929. /* There are some cases where switches return this
  2930. * error when they are not ready and should be returning
  2931. * Logical Busy. We should delay every time.
  2932. */
  2933. if (cmd == ELS_CMD_FDISC &&
  2934. stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
  2935. maxretry = 3;
  2936. delay = 1000;
  2937. retry = 1;
  2938. break;
  2939. }
  2940. case LSRJT_PROTOCOL_ERR:
  2941. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2942. (cmd == ELS_CMD_FDISC) &&
  2943. ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
  2944. (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
  2945. ) {
  2946. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2947. "0122 FDISC Failed (x%x). "
  2948. "Fabric Detected Bad WWN\n",
  2949. stat.un.lsRjtError);
  2950. lpfc_vport_set_state(vport,
  2951. FC_VPORT_FABRIC_REJ_WWN);
  2952. }
  2953. break;
  2954. }
  2955. break;
  2956. case IOSTAT_INTERMED_RSP:
  2957. case IOSTAT_BA_RJT:
  2958. break;
  2959. default:
  2960. break;
  2961. }
  2962. if (did == FDMI_DID)
  2963. retry = 1;
  2964. if ((cmd == ELS_CMD_FLOGI) &&
  2965. (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
  2966. !lpfc_error_lost_link(irsp)) {
  2967. /* FLOGI retry policy */
  2968. retry = 1;
  2969. /* retry FLOGI forever */
  2970. maxretry = 0;
  2971. if (cmdiocb->retry >= 100)
  2972. delay = 5000;
  2973. else if (cmdiocb->retry >= 32)
  2974. delay = 1000;
  2975. } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
  2976. /* retry FDISCs every second up to devloss */
  2977. retry = 1;
  2978. maxretry = vport->cfg_devloss_tmo;
  2979. delay = 1000;
  2980. }
  2981. cmdiocb->retry++;
  2982. if (maxretry && (cmdiocb->retry >= maxretry)) {
  2983. phba->fc_stat.elsRetryExceeded++;
  2984. retry = 0;
  2985. }
  2986. if ((vport->load_flag & FC_UNLOADING) != 0)
  2987. retry = 0;
  2988. if (retry) {
  2989. if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
  2990. /* Stop retrying PLOGI and FDISC if in FCF discovery */
  2991. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  2992. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2993. "2849 Stop retry ELS command "
  2994. "x%x to remote NPORT x%x, "
  2995. "Data: x%x x%x\n", cmd, did,
  2996. cmdiocb->retry, delay);
  2997. return 0;
  2998. }
  2999. }
  3000. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  3001. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3002. "0107 Retry ELS command x%x to remote "
  3003. "NPORT x%x Data: x%x x%x\n",
  3004. cmd, did, cmdiocb->retry, delay);
  3005. if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
  3006. ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  3007. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  3008. IOERR_NO_RESOURCES))) {
  3009. /* Don't reset timer for no resources */
  3010. /* If discovery / RSCN timer is running, reset it */
  3011. if (timer_pending(&vport->fc_disctmo) ||
  3012. (vport->fc_flag & FC_RSCN_MODE))
  3013. lpfc_set_disctmo(vport);
  3014. }
  3015. phba->fc_stat.elsXmitRetry++;
  3016. if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
  3017. phba->fc_stat.elsDelayRetry++;
  3018. ndlp->nlp_retry = cmdiocb->retry;
  3019. /* delay is specified in milliseconds */
  3020. mod_timer(&ndlp->nlp_delayfunc,
  3021. jiffies + msecs_to_jiffies(delay));
  3022. spin_lock_irq(shost->host_lock);
  3023. ndlp->nlp_flag |= NLP_DELAY_TMO;
  3024. spin_unlock_irq(shost->host_lock);
  3025. ndlp->nlp_prev_state = ndlp->nlp_state;
  3026. if (cmd == ELS_CMD_PRLI)
  3027. lpfc_nlp_set_state(vport, ndlp,
  3028. NLP_STE_PRLI_ISSUE);
  3029. else
  3030. lpfc_nlp_set_state(vport, ndlp,
  3031. NLP_STE_NPR_NODE);
  3032. ndlp->nlp_last_elscmd = cmd;
  3033. return 1;
  3034. }
  3035. switch (cmd) {
  3036. case ELS_CMD_FLOGI:
  3037. lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
  3038. return 1;
  3039. case ELS_CMD_FDISC:
  3040. lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
  3041. return 1;
  3042. case ELS_CMD_PLOGI:
  3043. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  3044. ndlp->nlp_prev_state = ndlp->nlp_state;
  3045. lpfc_nlp_set_state(vport, ndlp,
  3046. NLP_STE_PLOGI_ISSUE);
  3047. }
  3048. lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
  3049. return 1;
  3050. case ELS_CMD_ADISC:
  3051. ndlp->nlp_prev_state = ndlp->nlp_state;
  3052. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  3053. lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
  3054. return 1;
  3055. case ELS_CMD_PRLI:
  3056. ndlp->nlp_prev_state = ndlp->nlp_state;
  3057. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  3058. lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
  3059. return 1;
  3060. case ELS_CMD_LOGO:
  3061. ndlp->nlp_prev_state = ndlp->nlp_state;
  3062. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  3063. lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
  3064. return 1;
  3065. }
  3066. }
  3067. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  3068. if (logerr) {
  3069. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3070. "0137 No retry ELS command x%x to remote "
  3071. "NPORT x%x: Out of Resources: Error:x%x/%x\n",
  3072. cmd, did, irsp->ulpStatus,
  3073. irsp->un.ulpWord[4]);
  3074. }
  3075. else {
  3076. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3077. "0108 No retry ELS command x%x to remote "
  3078. "NPORT x%x Retried:%d Error:x%x/%x\n",
  3079. cmd, did, cmdiocb->retry, irsp->ulpStatus,
  3080. irsp->un.ulpWord[4]);
  3081. }
  3082. return 0;
  3083. }
  3084. /**
  3085. * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
  3086. * @phba: pointer to lpfc hba data structure.
  3087. * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
  3088. *
  3089. * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
  3090. * associated with a command IOCB back to the lpfc DMA buffer pool. It first
  3091. * checks to see whether there is a lpfc DMA buffer associated with the
  3092. * response of the command IOCB. If so, it will be released before releasing
  3093. * the lpfc DMA buffer associated with the IOCB itself.
  3094. *
  3095. * Return code
  3096. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  3097. **/
  3098. static int
  3099. lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
  3100. {
  3101. struct lpfc_dmabuf *buf_ptr;
  3102. /* Free the response before processing the command. */
  3103. if (!list_empty(&buf_ptr1->list)) {
  3104. list_remove_head(&buf_ptr1->list, buf_ptr,
  3105. struct lpfc_dmabuf,
  3106. list);
  3107. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  3108. kfree(buf_ptr);
  3109. }
  3110. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  3111. kfree(buf_ptr1);
  3112. return 0;
  3113. }
  3114. /**
  3115. * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
  3116. * @phba: pointer to lpfc hba data structure.
  3117. * @buf_ptr: pointer to the lpfc dma buffer data structure.
  3118. *
  3119. * This routine releases the lpfc Direct Memory Access (DMA) buffer
  3120. * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
  3121. * pool.
  3122. *
  3123. * Return code
  3124. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  3125. **/
  3126. static int
  3127. lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
  3128. {
  3129. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  3130. kfree(buf_ptr);
  3131. return 0;
  3132. }
  3133. /**
  3134. * lpfc_els_free_iocb - Free a command iocb and its associated resources
  3135. * @phba: pointer to lpfc hba data structure.
  3136. * @elsiocb: pointer to lpfc els command iocb data structure.
  3137. *
  3138. * This routine frees a command IOCB and its associated resources. The
  3139. * command IOCB data structure contains the reference to various associated
  3140. * resources, these fields must be set to NULL if the associated reference
  3141. * not present:
  3142. * context1 - reference to ndlp
  3143. * context2 - reference to cmd
  3144. * context2->next - reference to rsp
  3145. * context3 - reference to bpl
  3146. *
  3147. * It first properly decrements the reference count held on ndlp for the
  3148. * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
  3149. * set, it invokes the lpfc_els_free_data() routine to release the Direct
  3150. * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
  3151. * adds the DMA buffer the @phba data structure for the delayed release.
  3152. * If reference to the Buffer Pointer List (BPL) is present, the
  3153. * lpfc_els_free_bpl() routine is invoked to release the DMA memory
  3154. * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
  3155. * invoked to release the IOCB data structure back to @phba IOCBQ list.
  3156. *
  3157. * Return code
  3158. * 0 - Success (currently, always return 0)
  3159. **/
  3160. int
  3161. lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
  3162. {
  3163. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  3164. struct lpfc_nodelist *ndlp;
  3165. ndlp = (struct lpfc_nodelist *)elsiocb->context1;
  3166. if (ndlp) {
  3167. if (ndlp->nlp_flag & NLP_DEFER_RM) {
  3168. lpfc_nlp_put(ndlp);
  3169. /* If the ndlp is not being used by another discovery
  3170. * thread, free it.
  3171. */
  3172. if (!lpfc_nlp_not_used(ndlp)) {
  3173. /* If ndlp is being used by another discovery
  3174. * thread, just clear NLP_DEFER_RM
  3175. */
  3176. ndlp->nlp_flag &= ~NLP_DEFER_RM;
  3177. }
  3178. }
  3179. else
  3180. lpfc_nlp_put(ndlp);
  3181. elsiocb->context1 = NULL;
  3182. }
  3183. /* context2 = cmd, context2->next = rsp, context3 = bpl */
  3184. if (elsiocb->context2) {
  3185. if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
  3186. /* Firmware could still be in progress of DMAing
  3187. * payload, so don't free data buffer till after
  3188. * a hbeat.
  3189. */
  3190. elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
  3191. buf_ptr = elsiocb->context2;
  3192. elsiocb->context2 = NULL;
  3193. if (buf_ptr) {
  3194. buf_ptr1 = NULL;
  3195. spin_lock_irq(&phba->hbalock);
  3196. if (!list_empty(&buf_ptr->list)) {
  3197. list_remove_head(&buf_ptr->list,
  3198. buf_ptr1, struct lpfc_dmabuf,
  3199. list);
  3200. INIT_LIST_HEAD(&buf_ptr1->list);
  3201. list_add_tail(&buf_ptr1->list,
  3202. &phba->elsbuf);
  3203. phba->elsbuf_cnt++;
  3204. }
  3205. INIT_LIST_HEAD(&buf_ptr->list);
  3206. list_add_tail(&buf_ptr->list, &phba->elsbuf);
  3207. phba->elsbuf_cnt++;
  3208. spin_unlock_irq(&phba->hbalock);
  3209. }
  3210. } else {
  3211. buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
  3212. lpfc_els_free_data(phba, buf_ptr1);
  3213. }
  3214. }
  3215. if (elsiocb->context3) {
  3216. buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
  3217. lpfc_els_free_bpl(phba, buf_ptr);
  3218. }
  3219. lpfc_sli_release_iocbq(phba, elsiocb);
  3220. return 0;
  3221. }
  3222. /**
  3223. * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
  3224. * @phba: pointer to lpfc hba data structure.
  3225. * @cmdiocb: pointer to lpfc command iocb data structure.
  3226. * @rspiocb: pointer to lpfc response iocb data structure.
  3227. *
  3228. * This routine is the completion callback function to the Logout (LOGO)
  3229. * Accept (ACC) Response ELS command. This routine is invoked to indicate
  3230. * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
  3231. * release the ndlp if it has the last reference remaining (reference count
  3232. * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
  3233. * field to NULL to inform the following lpfc_els_free_iocb() routine no
  3234. * ndlp reference count needs to be decremented. Otherwise, the ndlp
  3235. * reference use-count shall be decremented by the lpfc_els_free_iocb()
  3236. * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
  3237. * IOCB data structure.
  3238. **/
  3239. static void
  3240. lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3241. struct lpfc_iocbq *rspiocb)
  3242. {
  3243. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  3244. struct lpfc_vport *vport = cmdiocb->vport;
  3245. IOCB_t *irsp;
  3246. irsp = &rspiocb->iocb;
  3247. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3248. "ACC LOGO cmpl: status:x%x/x%x did:x%x",
  3249. irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
  3250. /* ACC to LOGO completes to NPort <nlp_DID> */
  3251. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3252. "0109 ACC to LOGO completes to NPort x%x "
  3253. "Data: x%x x%x x%x\n",
  3254. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3255. ndlp->nlp_rpi);
  3256. if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
  3257. /* NPort Recovery mode or node is just allocated */
  3258. if (!lpfc_nlp_not_used(ndlp)) {
  3259. /* If the ndlp is being used by another discovery
  3260. * thread, just unregister the RPI.
  3261. */
  3262. lpfc_unreg_rpi(vport, ndlp);
  3263. } else {
  3264. /* Indicate the node has already released, should
  3265. * not reference to it from within lpfc_els_free_iocb.
  3266. */
  3267. cmdiocb->context1 = NULL;
  3268. }
  3269. }
  3270. /*
  3271. * The driver received a LOGO from the rport and has ACK'd it.
  3272. * At this point, the driver is done so release the IOCB
  3273. */
  3274. lpfc_els_free_iocb(phba, cmdiocb);
  3275. /*
  3276. * Remove the ndlp reference if it's a fabric node that has
  3277. * sent us an unsolicted LOGO.
  3278. */
  3279. if (ndlp->nlp_type & NLP_FABRIC)
  3280. lpfc_nlp_put(ndlp);
  3281. return;
  3282. }
  3283. /**
  3284. * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
  3285. * @phba: pointer to lpfc hba data structure.
  3286. * @pmb: pointer to the driver internal queue element for mailbox command.
  3287. *
  3288. * This routine is the completion callback function for unregister default
  3289. * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
  3290. * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
  3291. * decrements the ndlp reference count held for this completion callback
  3292. * function. After that, it invokes the lpfc_nlp_not_used() to check
  3293. * whether there is only one reference left on the ndlp. If so, it will
  3294. * perform one more decrement and trigger the release of the ndlp.
  3295. **/
  3296. void
  3297. lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3298. {
  3299. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3300. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3301. pmb->context1 = NULL;
  3302. pmb->context2 = NULL;
  3303. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3304. kfree(mp);
  3305. mempool_free(pmb, phba->mbox_mem_pool);
  3306. if (ndlp) {
  3307. if (NLP_CHK_NODE_ACT(ndlp)) {
  3308. lpfc_nlp_put(ndlp);
  3309. /* This is the end of the default RPI cleanup logic for
  3310. * this ndlp. If no other discovery threads are using
  3311. * this ndlp, free all resources associated with it.
  3312. */
  3313. lpfc_nlp_not_used(ndlp);
  3314. } else {
  3315. lpfc_drop_node(ndlp->vport, ndlp);
  3316. }
  3317. }
  3318. return;
  3319. }
  3320. /**
  3321. * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
  3322. * @phba: pointer to lpfc hba data structure.
  3323. * @cmdiocb: pointer to lpfc command iocb data structure.
  3324. * @rspiocb: pointer to lpfc response iocb data structure.
  3325. *
  3326. * This routine is the completion callback function for ELS Response IOCB
  3327. * command. In normal case, this callback function just properly sets the
  3328. * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
  3329. * field in the command IOCB is not NULL, the referred mailbox command will
  3330. * be send out, and then invokes the lpfc_els_free_iocb() routine to release
  3331. * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
  3332. * link down event occurred during the discovery, the lpfc_nlp_not_used()
  3333. * routine shall be invoked trying to release the ndlp if no other threads
  3334. * are currently referring it.
  3335. **/
  3336. static void
  3337. lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3338. struct lpfc_iocbq *rspiocb)
  3339. {
  3340. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  3341. struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
  3342. struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
  3343. IOCB_t *irsp;
  3344. uint8_t *pcmd;
  3345. LPFC_MBOXQ_t *mbox = NULL;
  3346. struct lpfc_dmabuf *mp = NULL;
  3347. uint32_t ls_rjt = 0;
  3348. irsp = &rspiocb->iocb;
  3349. if (cmdiocb->context_un.mbox)
  3350. mbox = cmdiocb->context_un.mbox;
  3351. /* First determine if this is a LS_RJT cmpl. Note, this callback
  3352. * function can have cmdiocb->contest1 (ndlp) field set to NULL.
  3353. */
  3354. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  3355. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  3356. (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
  3357. /* A LS_RJT associated with Default RPI cleanup has its own
  3358. * separate code path.
  3359. */
  3360. if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  3361. ls_rjt = 1;
  3362. }
  3363. /* Check to see if link went down during discovery */
  3364. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
  3365. if (mbox) {
  3366. mp = (struct lpfc_dmabuf *) mbox->context1;
  3367. if (mp) {
  3368. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3369. kfree(mp);
  3370. }
  3371. mempool_free(mbox, phba->mbox_mem_pool);
  3372. }
  3373. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  3374. (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  3375. if (lpfc_nlp_not_used(ndlp)) {
  3376. ndlp = NULL;
  3377. /* Indicate the node has already released,
  3378. * should not reference to it from within
  3379. * the routine lpfc_els_free_iocb.
  3380. */
  3381. cmdiocb->context1 = NULL;
  3382. }
  3383. goto out;
  3384. }
  3385. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3386. "ELS rsp cmpl: status:x%x/x%x did:x%x",
  3387. irsp->ulpStatus, irsp->un.ulpWord[4],
  3388. cmdiocb->iocb.un.elsreq64.remoteID);
  3389. /* ELS response tag <ulpIoTag> completes */
  3390. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3391. "0110 ELS response tag x%x completes "
  3392. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  3393. cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
  3394. rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
  3395. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3396. ndlp->nlp_rpi);
  3397. if (mbox) {
  3398. if ((rspiocb->iocb.ulpStatus == 0)
  3399. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  3400. lpfc_unreg_rpi(vport, ndlp);
  3401. /* Increment reference count to ndlp to hold the
  3402. * reference to ndlp for the callback function.
  3403. */
  3404. mbox->context2 = lpfc_nlp_get(ndlp);
  3405. mbox->vport = vport;
  3406. if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
  3407. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  3408. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  3409. }
  3410. else {
  3411. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  3412. ndlp->nlp_prev_state = ndlp->nlp_state;
  3413. lpfc_nlp_set_state(vport, ndlp,
  3414. NLP_STE_REG_LOGIN_ISSUE);
  3415. }
  3416. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  3417. != MBX_NOT_FINISHED)
  3418. goto out;
  3419. else
  3420. /* Decrement the ndlp reference count we
  3421. * set for this failed mailbox command.
  3422. */
  3423. lpfc_nlp_put(ndlp);
  3424. /* ELS rsp: Cannot issue reg_login for <NPortid> */
  3425. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3426. "0138 ELS rsp: Cannot issue reg_login for x%x "
  3427. "Data: x%x x%x x%x\n",
  3428. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3429. ndlp->nlp_rpi);
  3430. if (lpfc_nlp_not_used(ndlp)) {
  3431. ndlp = NULL;
  3432. /* Indicate node has already been released,
  3433. * should not reference to it from within
  3434. * the routine lpfc_els_free_iocb.
  3435. */
  3436. cmdiocb->context1 = NULL;
  3437. }
  3438. } else {
  3439. /* Do not drop node for lpfc_els_abort'ed ELS cmds */
  3440. if (!lpfc_error_lost_link(irsp) &&
  3441. ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  3442. if (lpfc_nlp_not_used(ndlp)) {
  3443. ndlp = NULL;
  3444. /* Indicate node has already been
  3445. * released, should not reference
  3446. * to it from within the routine
  3447. * lpfc_els_free_iocb.
  3448. */
  3449. cmdiocb->context1 = NULL;
  3450. }
  3451. }
  3452. }
  3453. mp = (struct lpfc_dmabuf *) mbox->context1;
  3454. if (mp) {
  3455. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3456. kfree(mp);
  3457. }
  3458. mempool_free(mbox, phba->mbox_mem_pool);
  3459. }
  3460. out:
  3461. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  3462. spin_lock_irq(shost->host_lock);
  3463. ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
  3464. spin_unlock_irq(shost->host_lock);
  3465. /* If the node is not being used by another discovery thread,
  3466. * and we are sending a reject, we are done with it.
  3467. * Release driver reference count here and free associated
  3468. * resources.
  3469. */
  3470. if (ls_rjt)
  3471. if (lpfc_nlp_not_used(ndlp))
  3472. /* Indicate node has already been released,
  3473. * should not reference to it from within
  3474. * the routine lpfc_els_free_iocb.
  3475. */
  3476. cmdiocb->context1 = NULL;
  3477. }
  3478. lpfc_els_free_iocb(phba, cmdiocb);
  3479. return;
  3480. }
  3481. /**
  3482. * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
  3483. * @vport: pointer to a host virtual N_Port data structure.
  3484. * @flag: the els command code to be accepted.
  3485. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3486. * @ndlp: pointer to a node-list data structure.
  3487. * @mbox: pointer to the driver internal queue element for mailbox command.
  3488. *
  3489. * This routine prepares and issues an Accept (ACC) response IOCB
  3490. * command. It uses the @flag to properly set up the IOCB field for the
  3491. * specific ACC response command to be issued and invokes the
  3492. * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
  3493. * @mbox pointer is passed in, it will be put into the context_un.mbox
  3494. * field of the IOCB for the completion callback function to issue the
  3495. * mailbox command to the HBA later when callback is invoked.
  3496. *
  3497. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3498. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3499. * will be stored into the context1 field of the IOCB for the completion
  3500. * callback function to the corresponding response ELS IOCB command.
  3501. *
  3502. * Return code
  3503. * 0 - Successfully issued acc response
  3504. * 1 - Failed to issue acc response
  3505. **/
  3506. int
  3507. lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
  3508. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  3509. LPFC_MBOXQ_t *mbox)
  3510. {
  3511. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3512. struct lpfc_hba *phba = vport->phba;
  3513. IOCB_t *icmd;
  3514. IOCB_t *oldcmd;
  3515. struct lpfc_iocbq *elsiocb;
  3516. struct lpfc_sli *psli;
  3517. uint8_t *pcmd;
  3518. uint16_t cmdsize;
  3519. int rc;
  3520. ELS_PKT *els_pkt_ptr;
  3521. psli = &phba->sli;
  3522. oldcmd = &oldiocb->iocb;
  3523. switch (flag) {
  3524. case ELS_CMD_ACC:
  3525. cmdsize = sizeof(uint32_t);
  3526. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  3527. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  3528. if (!elsiocb) {
  3529. spin_lock_irq(shost->host_lock);
  3530. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  3531. spin_unlock_irq(shost->host_lock);
  3532. return 1;
  3533. }
  3534. icmd = &elsiocb->iocb;
  3535. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3536. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3537. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3538. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3539. pcmd += sizeof(uint32_t);
  3540. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3541. "Issue ACC: did:x%x flg:x%x",
  3542. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3543. break;
  3544. case ELS_CMD_PLOGI:
  3545. cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
  3546. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  3547. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  3548. if (!elsiocb)
  3549. return 1;
  3550. icmd = &elsiocb->iocb;
  3551. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3552. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3553. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3554. if (mbox)
  3555. elsiocb->context_un.mbox = mbox;
  3556. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3557. pcmd += sizeof(uint32_t);
  3558. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  3559. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3560. "Issue ACC PLOGI: did:x%x flg:x%x",
  3561. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3562. break;
  3563. case ELS_CMD_PRLO:
  3564. cmdsize = sizeof(uint32_t) + sizeof(PRLO);
  3565. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  3566. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  3567. if (!elsiocb)
  3568. return 1;
  3569. icmd = &elsiocb->iocb;
  3570. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3571. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3572. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3573. memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
  3574. sizeof(uint32_t) + sizeof(PRLO));
  3575. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  3576. els_pkt_ptr = (ELS_PKT *) pcmd;
  3577. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  3578. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3579. "Issue ACC PRLO: did:x%x flg:x%x",
  3580. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3581. break;
  3582. default:
  3583. return 1;
  3584. }
  3585. /* Xmit ELS ACC response tag <ulpIoTag> */
  3586. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3587. "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
  3588. "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
  3589. "fc_flag x%x\n",
  3590. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3591. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3592. ndlp->nlp_rpi, vport->fc_flag);
  3593. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  3594. spin_lock_irq(shost->host_lock);
  3595. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  3596. spin_unlock_irq(shost->host_lock);
  3597. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
  3598. } else {
  3599. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3600. }
  3601. phba->fc_stat.elsXmitACC++;
  3602. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3603. if (rc == IOCB_ERROR) {
  3604. lpfc_els_free_iocb(phba, elsiocb);
  3605. return 1;
  3606. }
  3607. return 0;
  3608. }
  3609. /**
  3610. * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
  3611. * @vport: pointer to a virtual N_Port data structure.
  3612. * @rejectError:
  3613. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3614. * @ndlp: pointer to a node-list data structure.
  3615. * @mbox: pointer to the driver internal queue element for mailbox command.
  3616. *
  3617. * This routine prepares and issue an Reject (RJT) response IOCB
  3618. * command. If a @mbox pointer is passed in, it will be put into the
  3619. * context_un.mbox field of the IOCB for the completion callback function
  3620. * to issue to the HBA later.
  3621. *
  3622. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3623. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3624. * will be stored into the context1 field of the IOCB for the completion
  3625. * callback function to the reject response ELS IOCB command.
  3626. *
  3627. * Return code
  3628. * 0 - Successfully issued reject response
  3629. * 1 - Failed to issue reject response
  3630. **/
  3631. int
  3632. lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
  3633. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  3634. LPFC_MBOXQ_t *mbox)
  3635. {
  3636. struct lpfc_hba *phba = vport->phba;
  3637. IOCB_t *icmd;
  3638. IOCB_t *oldcmd;
  3639. struct lpfc_iocbq *elsiocb;
  3640. struct lpfc_sli *psli;
  3641. uint8_t *pcmd;
  3642. uint16_t cmdsize;
  3643. int rc;
  3644. psli = &phba->sli;
  3645. cmdsize = 2 * sizeof(uint32_t);
  3646. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3647. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  3648. if (!elsiocb)
  3649. return 1;
  3650. icmd = &elsiocb->iocb;
  3651. oldcmd = &oldiocb->iocb;
  3652. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3653. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3654. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3655. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  3656. pcmd += sizeof(uint32_t);
  3657. *((uint32_t *) (pcmd)) = rejectError;
  3658. if (mbox)
  3659. elsiocb->context_un.mbox = mbox;
  3660. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  3661. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3662. "0129 Xmit ELS RJT x%x response tag x%x "
  3663. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  3664. "rpi x%x\n",
  3665. rejectError, elsiocb->iotag,
  3666. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  3667. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  3668. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3669. "Issue LS_RJT: did:x%x flg:x%x err:x%x",
  3670. ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
  3671. phba->fc_stat.elsXmitLSRJT++;
  3672. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3673. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3674. if (rc == IOCB_ERROR) {
  3675. lpfc_els_free_iocb(phba, elsiocb);
  3676. return 1;
  3677. }
  3678. return 0;
  3679. }
  3680. /**
  3681. * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
  3682. * @vport: pointer to a virtual N_Port data structure.
  3683. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3684. * @ndlp: pointer to a node-list data structure.
  3685. *
  3686. * This routine prepares and issues an Accept (ACC) response to Address
  3687. * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
  3688. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  3689. *
  3690. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3691. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3692. * will be stored into the context1 field of the IOCB for the completion
  3693. * callback function to the ADISC Accept response ELS IOCB command.
  3694. *
  3695. * Return code
  3696. * 0 - Successfully issued acc adisc response
  3697. * 1 - Failed to issue adisc acc response
  3698. **/
  3699. int
  3700. lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  3701. struct lpfc_nodelist *ndlp)
  3702. {
  3703. struct lpfc_hba *phba = vport->phba;
  3704. ADISC *ap;
  3705. IOCB_t *icmd, *oldcmd;
  3706. struct lpfc_iocbq *elsiocb;
  3707. uint8_t *pcmd;
  3708. uint16_t cmdsize;
  3709. int rc;
  3710. cmdsize = sizeof(uint32_t) + sizeof(ADISC);
  3711. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3712. ndlp->nlp_DID, ELS_CMD_ACC);
  3713. if (!elsiocb)
  3714. return 1;
  3715. icmd = &elsiocb->iocb;
  3716. oldcmd = &oldiocb->iocb;
  3717. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3718. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3719. /* Xmit ADISC ACC response tag <ulpIoTag> */
  3720. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3721. "0130 Xmit ADISC ACC response iotag x%x xri: "
  3722. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  3723. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3724. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3725. ndlp->nlp_rpi);
  3726. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3727. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3728. pcmd += sizeof(uint32_t);
  3729. ap = (ADISC *) (pcmd);
  3730. ap->hardAL_PA = phba->fc_pref_ALPA;
  3731. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  3732. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  3733. ap->DID = be32_to_cpu(vport->fc_myDID);
  3734. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3735. "Issue ACC ADISC: did:x%x flg:x%x",
  3736. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3737. phba->fc_stat.elsXmitACC++;
  3738. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3739. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3740. if (rc == IOCB_ERROR) {
  3741. lpfc_els_free_iocb(phba, elsiocb);
  3742. return 1;
  3743. }
  3744. return 0;
  3745. }
  3746. /**
  3747. * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
  3748. * @vport: pointer to a virtual N_Port data structure.
  3749. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3750. * @ndlp: pointer to a node-list data structure.
  3751. *
  3752. * This routine prepares and issues an Accept (ACC) response to Process
  3753. * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
  3754. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  3755. *
  3756. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3757. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3758. * will be stored into the context1 field of the IOCB for the completion
  3759. * callback function to the PRLI Accept response ELS IOCB command.
  3760. *
  3761. * Return code
  3762. * 0 - Successfully issued acc prli response
  3763. * 1 - Failed to issue acc prli response
  3764. **/
  3765. int
  3766. lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  3767. struct lpfc_nodelist *ndlp)
  3768. {
  3769. struct lpfc_hba *phba = vport->phba;
  3770. PRLI *npr;
  3771. lpfc_vpd_t *vpd;
  3772. IOCB_t *icmd;
  3773. IOCB_t *oldcmd;
  3774. struct lpfc_iocbq *elsiocb;
  3775. struct lpfc_sli *psli;
  3776. uint8_t *pcmd;
  3777. uint16_t cmdsize;
  3778. int rc;
  3779. psli = &phba->sli;
  3780. cmdsize = sizeof(uint32_t) + sizeof(PRLI);
  3781. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3782. ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
  3783. if (!elsiocb)
  3784. return 1;
  3785. icmd = &elsiocb->iocb;
  3786. oldcmd = &oldiocb->iocb;
  3787. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3788. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3789. /* Xmit PRLI ACC response tag <ulpIoTag> */
  3790. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3791. "0131 Xmit PRLI ACC response tag x%x xri x%x, "
  3792. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  3793. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3794. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3795. ndlp->nlp_rpi);
  3796. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3797. *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  3798. pcmd += sizeof(uint32_t);
  3799. /* For PRLI, remainder of payload is PRLI parameter page */
  3800. memset(pcmd, 0, sizeof(PRLI));
  3801. npr = (PRLI *) pcmd;
  3802. vpd = &phba->vpd;
  3803. /*
  3804. * If the remote port is a target and our firmware version is 3.20 or
  3805. * later, set the following bits for FC-TAPE support.
  3806. */
  3807. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  3808. (vpd->rev.feaLevelHigh >= 0x02)) {
  3809. npr->ConfmComplAllowed = 1;
  3810. npr->Retry = 1;
  3811. npr->TaskRetryIdReq = 1;
  3812. }
  3813. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  3814. npr->estabImagePair = 1;
  3815. npr->readXferRdyDis = 1;
  3816. npr->ConfmComplAllowed = 1;
  3817. npr->prliType = PRLI_FCP_TYPE;
  3818. npr->initiatorFunc = 1;
  3819. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3820. "Issue ACC PRLI: did:x%x flg:x%x",
  3821. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3822. phba->fc_stat.elsXmitACC++;
  3823. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3824. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3825. if (rc == IOCB_ERROR) {
  3826. lpfc_els_free_iocb(phba, elsiocb);
  3827. return 1;
  3828. }
  3829. return 0;
  3830. }
  3831. /**
  3832. * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
  3833. * @vport: pointer to a virtual N_Port data structure.
  3834. * @format: rnid command format.
  3835. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3836. * @ndlp: pointer to a node-list data structure.
  3837. *
  3838. * This routine issues a Request Node Identification Data (RNID) Accept
  3839. * (ACC) response. It constructs the RNID ACC response command according to
  3840. * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
  3841. * issue the response. Note that this command does not need to hold the ndlp
  3842. * reference count for the callback. So, the ndlp reference count taken by
  3843. * the lpfc_prep_els_iocb() routine is put back and the context1 field of
  3844. * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
  3845. * there is no ndlp reference available.
  3846. *
  3847. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3848. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3849. * will be stored into the context1 field of the IOCB for the completion
  3850. * callback function. However, for the RNID Accept Response ELS command,
  3851. * this is undone later by this routine after the IOCB is allocated.
  3852. *
  3853. * Return code
  3854. * 0 - Successfully issued acc rnid response
  3855. * 1 - Failed to issue acc rnid response
  3856. **/
  3857. static int
  3858. lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
  3859. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  3860. {
  3861. struct lpfc_hba *phba = vport->phba;
  3862. RNID *rn;
  3863. IOCB_t *icmd, *oldcmd;
  3864. struct lpfc_iocbq *elsiocb;
  3865. struct lpfc_sli *psli;
  3866. uint8_t *pcmd;
  3867. uint16_t cmdsize;
  3868. int rc;
  3869. psli = &phba->sli;
  3870. cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
  3871. + (2 * sizeof(struct lpfc_name));
  3872. if (format)
  3873. cmdsize += sizeof(RNID_TOP_DISC);
  3874. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3875. ndlp->nlp_DID, ELS_CMD_ACC);
  3876. if (!elsiocb)
  3877. return 1;
  3878. icmd = &elsiocb->iocb;
  3879. oldcmd = &oldiocb->iocb;
  3880. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3881. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3882. /* Xmit RNID ACC response tag <ulpIoTag> */
  3883. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3884. "0132 Xmit RNID ACC response tag x%x xri x%x\n",
  3885. elsiocb->iotag, elsiocb->iocb.ulpContext);
  3886. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3887. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3888. pcmd += sizeof(uint32_t);
  3889. memset(pcmd, 0, sizeof(RNID));
  3890. rn = (RNID *) (pcmd);
  3891. rn->Format = format;
  3892. rn->CommonLen = (2 * sizeof(struct lpfc_name));
  3893. memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  3894. memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  3895. switch (format) {
  3896. case 0:
  3897. rn->SpecificLen = 0;
  3898. break;
  3899. case RNID_TOPOLOGY_DISC:
  3900. rn->SpecificLen = sizeof(RNID_TOP_DISC);
  3901. memcpy(&rn->un.topologyDisc.portName,
  3902. &vport->fc_portname, sizeof(struct lpfc_name));
  3903. rn->un.topologyDisc.unitType = RNID_HBA;
  3904. rn->un.topologyDisc.physPort = 0;
  3905. rn->un.topologyDisc.attachedNodes = 0;
  3906. break;
  3907. default:
  3908. rn->CommonLen = 0;
  3909. rn->SpecificLen = 0;
  3910. break;
  3911. }
  3912. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3913. "Issue ACC RNID: did:x%x flg:x%x",
  3914. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3915. phba->fc_stat.elsXmitACC++;
  3916. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3917. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3918. if (rc == IOCB_ERROR) {
  3919. lpfc_els_free_iocb(phba, elsiocb);
  3920. return 1;
  3921. }
  3922. return 0;
  3923. }
  3924. /**
  3925. * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
  3926. * @vport: pointer to a virtual N_Port data structure.
  3927. * @iocb: pointer to the lpfc command iocb data structure.
  3928. * @ndlp: pointer to a node-list data structure.
  3929. *
  3930. * Return
  3931. **/
  3932. static void
  3933. lpfc_els_clear_rrq(struct lpfc_vport *vport,
  3934. struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
  3935. {
  3936. struct lpfc_hba *phba = vport->phba;
  3937. uint8_t *pcmd;
  3938. struct RRQ *rrq;
  3939. uint16_t rxid;
  3940. uint16_t xri;
  3941. struct lpfc_node_rrq *prrq;
  3942. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
  3943. pcmd += sizeof(uint32_t);
  3944. rrq = (struct RRQ *)pcmd;
  3945. rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
  3946. rxid = bf_get(rrq_rxid, rrq);
  3947. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3948. "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
  3949. " x%x x%x\n",
  3950. be32_to_cpu(bf_get(rrq_did, rrq)),
  3951. bf_get(rrq_oxid, rrq),
  3952. rxid,
  3953. iocb->iotag, iocb->iocb.ulpContext);
  3954. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3955. "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
  3956. ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
  3957. if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
  3958. xri = bf_get(rrq_oxid, rrq);
  3959. else
  3960. xri = rxid;
  3961. prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
  3962. if (prrq)
  3963. lpfc_clr_rrq_active(phba, xri, prrq);
  3964. return;
  3965. }
  3966. /**
  3967. * lpfc_els_rsp_echo_acc - Issue echo acc response
  3968. * @vport: pointer to a virtual N_Port data structure.
  3969. * @data: pointer to echo data to return in the accept.
  3970. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3971. * @ndlp: pointer to a node-list data structure.
  3972. *
  3973. * Return code
  3974. * 0 - Successfully issued acc echo response
  3975. * 1 - Failed to issue acc echo response
  3976. **/
  3977. static int
  3978. lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
  3979. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  3980. {
  3981. struct lpfc_hba *phba = vport->phba;
  3982. struct lpfc_iocbq *elsiocb;
  3983. struct lpfc_sli *psli;
  3984. uint8_t *pcmd;
  3985. uint16_t cmdsize;
  3986. int rc;
  3987. psli = &phba->sli;
  3988. cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
  3989. /* The accumulated length can exceed the BPL_SIZE. For
  3990. * now, use this as the limit
  3991. */
  3992. if (cmdsize > LPFC_BPL_SIZE)
  3993. cmdsize = LPFC_BPL_SIZE;
  3994. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3995. ndlp->nlp_DID, ELS_CMD_ACC);
  3996. if (!elsiocb)
  3997. return 1;
  3998. elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
  3999. elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
  4000. /* Xmit ECHO ACC response tag <ulpIoTag> */
  4001. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4002. "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
  4003. elsiocb->iotag, elsiocb->iocb.ulpContext);
  4004. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4005. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4006. pcmd += sizeof(uint32_t);
  4007. memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
  4008. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4009. "Issue ACC ECHO: did:x%x flg:x%x",
  4010. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4011. phba->fc_stat.elsXmitACC++;
  4012. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4013. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  4014. if (rc == IOCB_ERROR) {
  4015. lpfc_els_free_iocb(phba, elsiocb);
  4016. return 1;
  4017. }
  4018. return 0;
  4019. }
  4020. /**
  4021. * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
  4022. * @vport: pointer to a host virtual N_Port data structure.
  4023. *
  4024. * This routine issues Address Discover (ADISC) ELS commands to those
  4025. * N_Ports which are in node port recovery state and ADISC has not been issued
  4026. * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
  4027. * lpfc_issue_els_adisc() routine, the per @vport number of discover count
  4028. * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
  4029. * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
  4030. * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
  4031. * IOCBs quit for later pick up. On the other hand, after walking through
  4032. * all the ndlps with the @vport and there is none ADISC IOCB issued, the
  4033. * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
  4034. * no more ADISC need to be sent.
  4035. *
  4036. * Return code
  4037. * The number of N_Ports with adisc issued.
  4038. **/
  4039. int
  4040. lpfc_els_disc_adisc(struct lpfc_vport *vport)
  4041. {
  4042. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4043. struct lpfc_nodelist *ndlp, *next_ndlp;
  4044. int sentadisc = 0;
  4045. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  4046. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  4047. if (!NLP_CHK_NODE_ACT(ndlp))
  4048. continue;
  4049. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  4050. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  4051. (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
  4052. spin_lock_irq(shost->host_lock);
  4053. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  4054. spin_unlock_irq(shost->host_lock);
  4055. ndlp->nlp_prev_state = ndlp->nlp_state;
  4056. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  4057. lpfc_issue_els_adisc(vport, ndlp, 0);
  4058. sentadisc++;
  4059. vport->num_disc_nodes++;
  4060. if (vport->num_disc_nodes >=
  4061. vport->cfg_discovery_threads) {
  4062. spin_lock_irq(shost->host_lock);
  4063. vport->fc_flag |= FC_NLP_MORE;
  4064. spin_unlock_irq(shost->host_lock);
  4065. break;
  4066. }
  4067. }
  4068. }
  4069. if (sentadisc == 0) {
  4070. spin_lock_irq(shost->host_lock);
  4071. vport->fc_flag &= ~FC_NLP_MORE;
  4072. spin_unlock_irq(shost->host_lock);
  4073. }
  4074. return sentadisc;
  4075. }
  4076. /**
  4077. * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
  4078. * @vport: pointer to a host virtual N_Port data structure.
  4079. *
  4080. * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
  4081. * which are in node port recovery state, with a @vport. Each time an ELS
  4082. * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
  4083. * the per @vport number of discover count (num_disc_nodes) shall be
  4084. * incremented. If the num_disc_nodes reaches a pre-configured threshold
  4085. * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
  4086. * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
  4087. * later pick up. On the other hand, after walking through all the ndlps with
  4088. * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
  4089. * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
  4090. * PLOGI need to be sent.
  4091. *
  4092. * Return code
  4093. * The number of N_Ports with plogi issued.
  4094. **/
  4095. int
  4096. lpfc_els_disc_plogi(struct lpfc_vport *vport)
  4097. {
  4098. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4099. struct lpfc_nodelist *ndlp, *next_ndlp;
  4100. int sentplogi = 0;
  4101. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  4102. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  4103. if (!NLP_CHK_NODE_ACT(ndlp))
  4104. continue;
  4105. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  4106. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  4107. (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
  4108. (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
  4109. ndlp->nlp_prev_state = ndlp->nlp_state;
  4110. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  4111. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  4112. sentplogi++;
  4113. vport->num_disc_nodes++;
  4114. if (vport->num_disc_nodes >=
  4115. vport->cfg_discovery_threads) {
  4116. spin_lock_irq(shost->host_lock);
  4117. vport->fc_flag |= FC_NLP_MORE;
  4118. spin_unlock_irq(shost->host_lock);
  4119. break;
  4120. }
  4121. }
  4122. }
  4123. if (sentplogi) {
  4124. lpfc_set_disctmo(vport);
  4125. }
  4126. else {
  4127. spin_lock_irq(shost->host_lock);
  4128. vport->fc_flag &= ~FC_NLP_MORE;
  4129. spin_unlock_irq(shost->host_lock);
  4130. }
  4131. return sentplogi;
  4132. }
  4133. /**
  4134. * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
  4135. * @vport: pointer to a host virtual N_Port data structure.
  4136. *
  4137. * This routine cleans up any Registration State Change Notification
  4138. * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
  4139. * @vport together with the host_lock is used to prevent multiple thread
  4140. * trying to access the RSCN array on a same @vport at the same time.
  4141. **/
  4142. void
  4143. lpfc_els_flush_rscn(struct lpfc_vport *vport)
  4144. {
  4145. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4146. struct lpfc_hba *phba = vport->phba;
  4147. int i;
  4148. spin_lock_irq(shost->host_lock);
  4149. if (vport->fc_rscn_flush) {
  4150. /* Another thread is walking fc_rscn_id_list on this vport */
  4151. spin_unlock_irq(shost->host_lock);
  4152. return;
  4153. }
  4154. /* Indicate we are walking lpfc_els_flush_rscn on this vport */
  4155. vport->fc_rscn_flush = 1;
  4156. spin_unlock_irq(shost->host_lock);
  4157. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  4158. lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
  4159. vport->fc_rscn_id_list[i] = NULL;
  4160. }
  4161. spin_lock_irq(shost->host_lock);
  4162. vport->fc_rscn_id_cnt = 0;
  4163. vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  4164. spin_unlock_irq(shost->host_lock);
  4165. lpfc_can_disctmo(vport);
  4166. /* Indicate we are done walking this fc_rscn_id_list */
  4167. vport->fc_rscn_flush = 0;
  4168. }
  4169. /**
  4170. * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
  4171. * @vport: pointer to a host virtual N_Port data structure.
  4172. * @did: remote destination port identifier.
  4173. *
  4174. * This routine checks whether there is any pending Registration State
  4175. * Configuration Notification (RSCN) to a @did on @vport.
  4176. *
  4177. * Return code
  4178. * None zero - The @did matched with a pending rscn
  4179. * 0 - not able to match @did with a pending rscn
  4180. **/
  4181. int
  4182. lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
  4183. {
  4184. D_ID ns_did;
  4185. D_ID rscn_did;
  4186. uint32_t *lp;
  4187. uint32_t payload_len, i;
  4188. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4189. ns_did.un.word = did;
  4190. /* Never match fabric nodes for RSCNs */
  4191. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  4192. return 0;
  4193. /* If we are doing a FULL RSCN rediscovery, match everything */
  4194. if (vport->fc_flag & FC_RSCN_DISCOVERY)
  4195. return did;
  4196. spin_lock_irq(shost->host_lock);
  4197. if (vport->fc_rscn_flush) {
  4198. /* Another thread is walking fc_rscn_id_list on this vport */
  4199. spin_unlock_irq(shost->host_lock);
  4200. return 0;
  4201. }
  4202. /* Indicate we are walking fc_rscn_id_list on this vport */
  4203. vport->fc_rscn_flush = 1;
  4204. spin_unlock_irq(shost->host_lock);
  4205. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  4206. lp = vport->fc_rscn_id_list[i]->virt;
  4207. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  4208. payload_len -= sizeof(uint32_t); /* take off word 0 */
  4209. while (payload_len) {
  4210. rscn_did.un.word = be32_to_cpu(*lp++);
  4211. payload_len -= sizeof(uint32_t);
  4212. switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
  4213. case RSCN_ADDRESS_FORMAT_PORT:
  4214. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  4215. && (ns_did.un.b.area == rscn_did.un.b.area)
  4216. && (ns_did.un.b.id == rscn_did.un.b.id))
  4217. goto return_did_out;
  4218. break;
  4219. case RSCN_ADDRESS_FORMAT_AREA:
  4220. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  4221. && (ns_did.un.b.area == rscn_did.un.b.area))
  4222. goto return_did_out;
  4223. break;
  4224. case RSCN_ADDRESS_FORMAT_DOMAIN:
  4225. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  4226. goto return_did_out;
  4227. break;
  4228. case RSCN_ADDRESS_FORMAT_FABRIC:
  4229. goto return_did_out;
  4230. }
  4231. }
  4232. }
  4233. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  4234. vport->fc_rscn_flush = 0;
  4235. return 0;
  4236. return_did_out:
  4237. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  4238. vport->fc_rscn_flush = 0;
  4239. return did;
  4240. }
  4241. /**
  4242. * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
  4243. * @vport: pointer to a host virtual N_Port data structure.
  4244. *
  4245. * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
  4246. * state machine for a @vport's nodes that are with pending RSCN (Registration
  4247. * State Change Notification).
  4248. *
  4249. * Return code
  4250. * 0 - Successful (currently alway return 0)
  4251. **/
  4252. static int
  4253. lpfc_rscn_recovery_check(struct lpfc_vport *vport)
  4254. {
  4255. struct lpfc_nodelist *ndlp = NULL;
  4256. /* Move all affected nodes by pending RSCNs to NPR state. */
  4257. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  4258. if (!NLP_CHK_NODE_ACT(ndlp) ||
  4259. (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
  4260. !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
  4261. continue;
  4262. lpfc_disc_state_machine(vport, ndlp, NULL,
  4263. NLP_EVT_DEVICE_RECOVERY);
  4264. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  4265. }
  4266. return 0;
  4267. }
  4268. /**
  4269. * lpfc_send_rscn_event - Send an RSCN event to management application
  4270. * @vport: pointer to a host virtual N_Port data structure.
  4271. * @cmdiocb: pointer to lpfc command iocb data structure.
  4272. *
  4273. * lpfc_send_rscn_event sends an RSCN netlink event to management
  4274. * applications.
  4275. */
  4276. static void
  4277. lpfc_send_rscn_event(struct lpfc_vport *vport,
  4278. struct lpfc_iocbq *cmdiocb)
  4279. {
  4280. struct lpfc_dmabuf *pcmd;
  4281. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4282. uint32_t *payload_ptr;
  4283. uint32_t payload_len;
  4284. struct lpfc_rscn_event_header *rscn_event_data;
  4285. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4286. payload_ptr = (uint32_t *) pcmd->virt;
  4287. payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
  4288. rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
  4289. payload_len, GFP_KERNEL);
  4290. if (!rscn_event_data) {
  4291. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4292. "0147 Failed to allocate memory for RSCN event\n");
  4293. return;
  4294. }
  4295. rscn_event_data->event_type = FC_REG_RSCN_EVENT;
  4296. rscn_event_data->payload_length = payload_len;
  4297. memcpy(rscn_event_data->rscn_payload, payload_ptr,
  4298. payload_len);
  4299. fc_host_post_vendor_event(shost,
  4300. fc_get_event_number(),
  4301. sizeof(struct lpfc_els_event_header) + payload_len,
  4302. (char *)rscn_event_data,
  4303. LPFC_NL_VENDOR_ID);
  4304. kfree(rscn_event_data);
  4305. }
  4306. /**
  4307. * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
  4308. * @vport: pointer to a host virtual N_Port data structure.
  4309. * @cmdiocb: pointer to lpfc command iocb data structure.
  4310. * @ndlp: pointer to a node-list data structure.
  4311. *
  4312. * This routine processes an unsolicited RSCN (Registration State Change
  4313. * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
  4314. * to invoke fc_host_post_event() routine to the FC transport layer. If the
  4315. * discover state machine is about to begin discovery, it just accepts the
  4316. * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
  4317. * contains N_Port IDs for other vports on this HBA, it just accepts the
  4318. * RSCN and ignore processing it. If the state machine is in the recovery
  4319. * state, the fc_rscn_id_list of this @vport is walked and the
  4320. * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
  4321. * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
  4322. * routine is invoked to handle the RSCN event.
  4323. *
  4324. * Return code
  4325. * 0 - Just sent the acc response
  4326. * 1 - Sent the acc response and waited for name server completion
  4327. **/
  4328. static int
  4329. lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4330. struct lpfc_nodelist *ndlp)
  4331. {
  4332. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4333. struct lpfc_hba *phba = vport->phba;
  4334. struct lpfc_dmabuf *pcmd;
  4335. uint32_t *lp, *datap;
  4336. IOCB_t *icmd;
  4337. uint32_t payload_len, length, nportid, *cmd;
  4338. int rscn_cnt;
  4339. int rscn_id = 0, hba_id = 0;
  4340. int i;
  4341. icmd = &cmdiocb->iocb;
  4342. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4343. lp = (uint32_t *) pcmd->virt;
  4344. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  4345. payload_len -= sizeof(uint32_t); /* take off word 0 */
  4346. /* RSCN received */
  4347. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4348. "0214 RSCN received Data: x%x x%x x%x x%x\n",
  4349. vport->fc_flag, payload_len, *lp,
  4350. vport->fc_rscn_id_cnt);
  4351. /* Send an RSCN event to the management application */
  4352. lpfc_send_rscn_event(vport, cmdiocb);
  4353. for (i = 0; i < payload_len/sizeof(uint32_t); i++)
  4354. fc_host_post_event(shost, fc_get_event_number(),
  4355. FCH_EVT_RSCN, lp[i]);
  4356. /* If we are about to begin discovery, just ACC the RSCN.
  4357. * Discovery processing will satisfy it.
  4358. */
  4359. if (vport->port_state <= LPFC_NS_QRY) {
  4360. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4361. "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
  4362. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  4363. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4364. return 0;
  4365. }
  4366. /* If this RSCN just contains NPortIDs for other vports on this HBA,
  4367. * just ACC and ignore it.
  4368. */
  4369. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  4370. !(vport->cfg_peer_port_login)) {
  4371. i = payload_len;
  4372. datap = lp;
  4373. while (i > 0) {
  4374. nportid = *datap++;
  4375. nportid = ((be32_to_cpu(nportid)) & Mask_DID);
  4376. i -= sizeof(uint32_t);
  4377. rscn_id++;
  4378. if (lpfc_find_vport_by_did(phba, nportid))
  4379. hba_id++;
  4380. }
  4381. if (rscn_id == hba_id) {
  4382. /* ALL NPortIDs in RSCN are on HBA */
  4383. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4384. "0219 Ignore RSCN "
  4385. "Data: x%x x%x x%x x%x\n",
  4386. vport->fc_flag, payload_len,
  4387. *lp, vport->fc_rscn_id_cnt);
  4388. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4389. "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
  4390. ndlp->nlp_DID, vport->port_state,
  4391. ndlp->nlp_flag);
  4392. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
  4393. ndlp, NULL);
  4394. return 0;
  4395. }
  4396. }
  4397. spin_lock_irq(shost->host_lock);
  4398. if (vport->fc_rscn_flush) {
  4399. /* Another thread is walking fc_rscn_id_list on this vport */
  4400. vport->fc_flag |= FC_RSCN_DISCOVERY;
  4401. spin_unlock_irq(shost->host_lock);
  4402. /* Send back ACC */
  4403. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4404. return 0;
  4405. }
  4406. /* Indicate we are walking fc_rscn_id_list on this vport */
  4407. vport->fc_rscn_flush = 1;
  4408. spin_unlock_irq(shost->host_lock);
  4409. /* Get the array count after successfully have the token */
  4410. rscn_cnt = vport->fc_rscn_id_cnt;
  4411. /* If we are already processing an RSCN, save the received
  4412. * RSCN payload buffer, cmdiocb->context2 to process later.
  4413. */
  4414. if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
  4415. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4416. "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
  4417. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  4418. spin_lock_irq(shost->host_lock);
  4419. vport->fc_flag |= FC_RSCN_DEFERRED;
  4420. if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
  4421. !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
  4422. vport->fc_flag |= FC_RSCN_MODE;
  4423. spin_unlock_irq(shost->host_lock);
  4424. if (rscn_cnt) {
  4425. cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
  4426. length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
  4427. }
  4428. if ((rscn_cnt) &&
  4429. (payload_len + length <= LPFC_BPL_SIZE)) {
  4430. *cmd &= ELS_CMD_MASK;
  4431. *cmd |= cpu_to_be32(payload_len + length);
  4432. memcpy(((uint8_t *)cmd) + length, lp,
  4433. payload_len);
  4434. } else {
  4435. vport->fc_rscn_id_list[rscn_cnt] = pcmd;
  4436. vport->fc_rscn_id_cnt++;
  4437. /* If we zero, cmdiocb->context2, the calling
  4438. * routine will not try to free it.
  4439. */
  4440. cmdiocb->context2 = NULL;
  4441. }
  4442. /* Deferred RSCN */
  4443. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4444. "0235 Deferred RSCN "
  4445. "Data: x%x x%x x%x\n",
  4446. vport->fc_rscn_id_cnt, vport->fc_flag,
  4447. vport->port_state);
  4448. } else {
  4449. vport->fc_flag |= FC_RSCN_DISCOVERY;
  4450. spin_unlock_irq(shost->host_lock);
  4451. /* ReDiscovery RSCN */
  4452. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4453. "0234 ReDiscovery RSCN "
  4454. "Data: x%x x%x x%x\n",
  4455. vport->fc_rscn_id_cnt, vport->fc_flag,
  4456. vport->port_state);
  4457. }
  4458. /* Indicate we are done walking fc_rscn_id_list on this vport */
  4459. vport->fc_rscn_flush = 0;
  4460. /* Send back ACC */
  4461. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4462. /* send RECOVERY event for ALL nodes that match RSCN payload */
  4463. lpfc_rscn_recovery_check(vport);
  4464. spin_lock_irq(shost->host_lock);
  4465. vport->fc_flag &= ~FC_RSCN_DEFERRED;
  4466. spin_unlock_irq(shost->host_lock);
  4467. return 0;
  4468. }
  4469. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4470. "RCV RSCN: did:x%x/ste:x%x flg:x%x",
  4471. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  4472. spin_lock_irq(shost->host_lock);
  4473. vport->fc_flag |= FC_RSCN_MODE;
  4474. spin_unlock_irq(shost->host_lock);
  4475. vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
  4476. /* Indicate we are done walking fc_rscn_id_list on this vport */
  4477. vport->fc_rscn_flush = 0;
  4478. /*
  4479. * If we zero, cmdiocb->context2, the calling routine will
  4480. * not try to free it.
  4481. */
  4482. cmdiocb->context2 = NULL;
  4483. lpfc_set_disctmo(vport);
  4484. /* Send back ACC */
  4485. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4486. /* send RECOVERY event for ALL nodes that match RSCN payload */
  4487. lpfc_rscn_recovery_check(vport);
  4488. return lpfc_els_handle_rscn(vport);
  4489. }
  4490. /**
  4491. * lpfc_els_handle_rscn - Handle rscn for a vport
  4492. * @vport: pointer to a host virtual N_Port data structure.
  4493. *
  4494. * This routine handles the Registration State Configuration Notification
  4495. * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
  4496. * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
  4497. * if the ndlp to NameServer exists, a Common Transport (CT) command to the
  4498. * NameServer shall be issued. If CT command to the NameServer fails to be
  4499. * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
  4500. * RSCN activities with the @vport.
  4501. *
  4502. * Return code
  4503. * 0 - Cleaned up rscn on the @vport
  4504. * 1 - Wait for plogi to name server before proceed
  4505. **/
  4506. int
  4507. lpfc_els_handle_rscn(struct lpfc_vport *vport)
  4508. {
  4509. struct lpfc_nodelist *ndlp;
  4510. struct lpfc_hba *phba = vport->phba;
  4511. /* Ignore RSCN if the port is being torn down. */
  4512. if (vport->load_flag & FC_UNLOADING) {
  4513. lpfc_els_flush_rscn(vport);
  4514. return 0;
  4515. }
  4516. /* Start timer for RSCN processing */
  4517. lpfc_set_disctmo(vport);
  4518. /* RSCN processed */
  4519. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4520. "0215 RSCN processed Data: x%x x%x x%x x%x\n",
  4521. vport->fc_flag, 0, vport->fc_rscn_id_cnt,
  4522. vport->port_state);
  4523. /* To process RSCN, first compare RSCN data with NameServer */
  4524. vport->fc_ns_retry = 0;
  4525. vport->num_disc_nodes = 0;
  4526. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  4527. if (ndlp && NLP_CHK_NODE_ACT(ndlp)
  4528. && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  4529. /* Good ndlp, issue CT Request to NameServer */
  4530. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
  4531. /* Wait for NameServer query cmpl before we can
  4532. continue */
  4533. return 1;
  4534. } else {
  4535. /* If login to NameServer does not exist, issue one */
  4536. /* Good status, issue PLOGI to NameServer */
  4537. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  4538. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  4539. /* Wait for NameServer login cmpl before we can
  4540. continue */
  4541. return 1;
  4542. if (ndlp) {
  4543. ndlp = lpfc_enable_node(vport, ndlp,
  4544. NLP_STE_PLOGI_ISSUE);
  4545. if (!ndlp) {
  4546. lpfc_els_flush_rscn(vport);
  4547. return 0;
  4548. }
  4549. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  4550. } else {
  4551. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  4552. if (!ndlp) {
  4553. lpfc_els_flush_rscn(vport);
  4554. return 0;
  4555. }
  4556. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  4557. ndlp->nlp_prev_state = ndlp->nlp_state;
  4558. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  4559. }
  4560. ndlp->nlp_type |= NLP_FABRIC;
  4561. lpfc_issue_els_plogi(vport, NameServer_DID, 0);
  4562. /* Wait for NameServer login cmpl before we can
  4563. * continue
  4564. */
  4565. return 1;
  4566. }
  4567. lpfc_els_flush_rscn(vport);
  4568. return 0;
  4569. }
  4570. /**
  4571. * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
  4572. * @vport: pointer to a host virtual N_Port data structure.
  4573. * @cmdiocb: pointer to lpfc command iocb data structure.
  4574. * @ndlp: pointer to a node-list data structure.
  4575. *
  4576. * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
  4577. * unsolicited event. An unsolicited FLOGI can be received in a point-to-
  4578. * point topology. As an unsolicited FLOGI should not be received in a loop
  4579. * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
  4580. * lpfc_check_sparm() routine is invoked to check the parameters in the
  4581. * unsolicited FLOGI. If parameters validation failed, the routine
  4582. * lpfc_els_rsp_reject() shall be called with reject reason code set to
  4583. * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
  4584. * FLOGI shall be compared with the Port WWN of the @vport to determine who
  4585. * will initiate PLOGI. The higher lexicographical value party shall has
  4586. * higher priority (as the winning port) and will initiate PLOGI and
  4587. * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
  4588. * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
  4589. * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
  4590. *
  4591. * Return code
  4592. * 0 - Successfully processed the unsolicited flogi
  4593. * 1 - Failed to process the unsolicited flogi
  4594. **/
  4595. static int
  4596. lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4597. struct lpfc_nodelist *ndlp)
  4598. {
  4599. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4600. struct lpfc_hba *phba = vport->phba;
  4601. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4602. uint32_t *lp = (uint32_t *) pcmd->virt;
  4603. IOCB_t *icmd = &cmdiocb->iocb;
  4604. struct serv_parm *sp;
  4605. LPFC_MBOXQ_t *mbox;
  4606. struct ls_rjt stat;
  4607. uint32_t cmd, did;
  4608. int rc;
  4609. cmd = *lp++;
  4610. sp = (struct serv_parm *) lp;
  4611. /* FLOGI received */
  4612. lpfc_set_disctmo(vport);
  4613. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  4614. /* We should never receive a FLOGI in loop mode, ignore it */
  4615. did = icmd->un.elsreq64.remoteID;
  4616. /* An FLOGI ELS command <elsCmd> was received from DID <did> in
  4617. Loop Mode */
  4618. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4619. "0113 An FLOGI ELS command x%x was "
  4620. "received from DID x%x in Loop Mode\n",
  4621. cmd, did);
  4622. return 1;
  4623. }
  4624. if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
  4625. /* For a FLOGI we accept, then if our portname is greater
  4626. * then the remote portname we initiate Nport login.
  4627. */
  4628. rc = memcmp(&vport->fc_portname, &sp->portName,
  4629. sizeof(struct lpfc_name));
  4630. if (!rc) {
  4631. if (phba->sli_rev < LPFC_SLI_REV4) {
  4632. mbox = mempool_alloc(phba->mbox_mem_pool,
  4633. GFP_KERNEL);
  4634. if (!mbox)
  4635. return 1;
  4636. lpfc_linkdown(phba);
  4637. lpfc_init_link(phba, mbox,
  4638. phba->cfg_topology,
  4639. phba->cfg_link_speed);
  4640. mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  4641. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4642. mbox->vport = vport;
  4643. rc = lpfc_sli_issue_mbox(phba, mbox,
  4644. MBX_NOWAIT);
  4645. lpfc_set_loopback_flag(phba);
  4646. if (rc == MBX_NOT_FINISHED)
  4647. mempool_free(mbox, phba->mbox_mem_pool);
  4648. return 1;
  4649. } else {
  4650. /* abort the flogi coming back to ourselves
  4651. * due to external loopback on the port.
  4652. */
  4653. lpfc_els_abort_flogi(phba);
  4654. return 0;
  4655. }
  4656. } else if (rc > 0) { /* greater than */
  4657. spin_lock_irq(shost->host_lock);
  4658. vport->fc_flag |= FC_PT2PT_PLOGI;
  4659. spin_unlock_irq(shost->host_lock);
  4660. /* If we have the high WWPN we can assign our own
  4661. * myDID; otherwise, we have to WAIT for a PLOGI
  4662. * from the remote NPort to find out what it
  4663. * will be.
  4664. */
  4665. vport->fc_myDID = PT2PT_LocalID;
  4666. }
  4667. /*
  4668. * The vport state should go to LPFC_FLOGI only
  4669. * AFTER we issue a FLOGI, not receive one.
  4670. */
  4671. spin_lock_irq(shost->host_lock);
  4672. vport->fc_flag |= FC_PT2PT;
  4673. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  4674. spin_unlock_irq(shost->host_lock);
  4675. /*
  4676. * We temporarily set fc_myDID to make it look like we are
  4677. * a Fabric. This is done just so we end up with the right
  4678. * did / sid on the FLOGI ACC rsp.
  4679. */
  4680. did = vport->fc_myDID;
  4681. vport->fc_myDID = Fabric_DID;
  4682. } else {
  4683. /* Reject this request because invalid parameters */
  4684. stat.un.b.lsRjtRsvd0 = 0;
  4685. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4686. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  4687. stat.un.b.vendorUnique = 0;
  4688. /*
  4689. * We temporarily set fc_myDID to make it look like we are
  4690. * a Fabric. This is done just so we end up with the right
  4691. * did / sid on the FLOGI LS_RJT rsp.
  4692. */
  4693. did = vport->fc_myDID;
  4694. vport->fc_myDID = Fabric_DID;
  4695. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  4696. NULL);
  4697. /* Now lets put fc_myDID back to what its supposed to be */
  4698. vport->fc_myDID = did;
  4699. return 1;
  4700. }
  4701. /* Send back ACC */
  4702. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
  4703. /* Now lets put fc_myDID back to what its supposed to be */
  4704. vport->fc_myDID = did;
  4705. if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
  4706. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4707. if (!mbox)
  4708. goto fail;
  4709. lpfc_config_link(phba, mbox);
  4710. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4711. mbox->vport = vport;
  4712. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4713. if (rc == MBX_NOT_FINISHED) {
  4714. mempool_free(mbox, phba->mbox_mem_pool);
  4715. goto fail;
  4716. }
  4717. }
  4718. return 0;
  4719. fail:
  4720. return 1;
  4721. }
  4722. /**
  4723. * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
  4724. * @vport: pointer to a host virtual N_Port data structure.
  4725. * @cmdiocb: pointer to lpfc command iocb data structure.
  4726. * @ndlp: pointer to a node-list data structure.
  4727. *
  4728. * This routine processes Request Node Identification Data (RNID) IOCB
  4729. * received as an ELS unsolicited event. Only when the RNID specified format
  4730. * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
  4731. * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
  4732. * Accept (ACC) the RNID ELS command. All the other RNID formats are
  4733. * rejected by invoking the lpfc_els_rsp_reject() routine.
  4734. *
  4735. * Return code
  4736. * 0 - Successfully processed rnid iocb (currently always return 0)
  4737. **/
  4738. static int
  4739. lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4740. struct lpfc_nodelist *ndlp)
  4741. {
  4742. struct lpfc_dmabuf *pcmd;
  4743. uint32_t *lp;
  4744. IOCB_t *icmd;
  4745. RNID *rn;
  4746. struct ls_rjt stat;
  4747. uint32_t cmd, did;
  4748. icmd = &cmdiocb->iocb;
  4749. did = icmd->un.elsreq64.remoteID;
  4750. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4751. lp = (uint32_t *) pcmd->virt;
  4752. cmd = *lp++;
  4753. rn = (RNID *) lp;
  4754. /* RNID received */
  4755. switch (rn->Format) {
  4756. case 0:
  4757. case RNID_TOPOLOGY_DISC:
  4758. /* Send back ACC */
  4759. lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
  4760. break;
  4761. default:
  4762. /* Reject this request because format not supported */
  4763. stat.un.b.lsRjtRsvd0 = 0;
  4764. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4765. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  4766. stat.un.b.vendorUnique = 0;
  4767. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  4768. NULL);
  4769. }
  4770. return 0;
  4771. }
  4772. /**
  4773. * lpfc_els_rcv_echo - Process an unsolicited echo iocb
  4774. * @vport: pointer to a host virtual N_Port data structure.
  4775. * @cmdiocb: pointer to lpfc command iocb data structure.
  4776. * @ndlp: pointer to a node-list data structure.
  4777. *
  4778. * Return code
  4779. * 0 - Successfully processed echo iocb (currently always return 0)
  4780. **/
  4781. static int
  4782. lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4783. struct lpfc_nodelist *ndlp)
  4784. {
  4785. uint8_t *pcmd;
  4786. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  4787. /* skip over first word of echo command to find echo data */
  4788. pcmd += sizeof(uint32_t);
  4789. lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
  4790. return 0;
  4791. }
  4792. /**
  4793. * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
  4794. * @vport: pointer to a host virtual N_Port data structure.
  4795. * @cmdiocb: pointer to lpfc command iocb data structure.
  4796. * @ndlp: pointer to a node-list data structure.
  4797. *
  4798. * This routine processes a Link Incident Report Registration(LIRR) IOCB
  4799. * received as an ELS unsolicited event. Currently, this function just invokes
  4800. * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
  4801. *
  4802. * Return code
  4803. * 0 - Successfully processed lirr iocb (currently always return 0)
  4804. **/
  4805. static int
  4806. lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4807. struct lpfc_nodelist *ndlp)
  4808. {
  4809. struct ls_rjt stat;
  4810. /* For now, unconditionally reject this command */
  4811. stat.un.b.lsRjtRsvd0 = 0;
  4812. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4813. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  4814. stat.un.b.vendorUnique = 0;
  4815. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  4816. return 0;
  4817. }
  4818. /**
  4819. * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
  4820. * @vport: pointer to a host virtual N_Port data structure.
  4821. * @cmdiocb: pointer to lpfc command iocb data structure.
  4822. * @ndlp: pointer to a node-list data structure.
  4823. *
  4824. * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
  4825. * received as an ELS unsolicited event. A request to RRQ shall only
  4826. * be accepted if the Originator Nx_Port N_Port_ID or the Responder
  4827. * Nx_Port N_Port_ID of the target Exchange is the same as the
  4828. * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
  4829. * not accepted, an LS_RJT with reason code "Unable to perform
  4830. * command request" and reason code explanation "Invalid Originator
  4831. * S_ID" shall be returned. For now, we just unconditionally accept
  4832. * RRQ from the target.
  4833. **/
  4834. static void
  4835. lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4836. struct lpfc_nodelist *ndlp)
  4837. {
  4838. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4839. if (vport->phba->sli_rev == LPFC_SLI_REV4)
  4840. lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
  4841. }
  4842. /**
  4843. * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
  4844. * @phba: pointer to lpfc hba data structure.
  4845. * @pmb: pointer to the driver internal queue element for mailbox command.
  4846. *
  4847. * This routine is the completion callback function for the MBX_READ_LNK_STAT
  4848. * mailbox command. This callback function is to actually send the Accept
  4849. * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
  4850. * collects the link statistics from the completion of the MBX_READ_LNK_STAT
  4851. * mailbox command, constructs the RPS response with the link statistics
  4852. * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
  4853. * response to the RPS.
  4854. *
  4855. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4856. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4857. * will be stored into the context1 field of the IOCB for the completion
  4858. * callback function to the RPS Accept Response ELS IOCB command.
  4859. *
  4860. **/
  4861. static void
  4862. lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4863. {
  4864. MAILBOX_t *mb;
  4865. IOCB_t *icmd;
  4866. struct RLS_RSP *rls_rsp;
  4867. uint8_t *pcmd;
  4868. struct lpfc_iocbq *elsiocb;
  4869. struct lpfc_nodelist *ndlp;
  4870. uint16_t oxid;
  4871. uint16_t rxid;
  4872. uint32_t cmdsize;
  4873. mb = &pmb->u.mb;
  4874. ndlp = (struct lpfc_nodelist *) pmb->context2;
  4875. rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
  4876. oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
  4877. pmb->context1 = NULL;
  4878. pmb->context2 = NULL;
  4879. if (mb->mbxStatus) {
  4880. mempool_free(pmb, phba->mbox_mem_pool);
  4881. return;
  4882. }
  4883. cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
  4884. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  4885. lpfc_max_els_tries, ndlp,
  4886. ndlp->nlp_DID, ELS_CMD_ACC);
  4887. /* Decrement the ndlp reference count from previous mbox command */
  4888. lpfc_nlp_put(ndlp);
  4889. if (!elsiocb) {
  4890. mempool_free(pmb, phba->mbox_mem_pool);
  4891. return;
  4892. }
  4893. icmd = &elsiocb->iocb;
  4894. icmd->ulpContext = rxid;
  4895. icmd->unsli3.rcvsli3.ox_id = oxid;
  4896. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4897. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4898. pcmd += sizeof(uint32_t); /* Skip past command */
  4899. rls_rsp = (struct RLS_RSP *)pcmd;
  4900. rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
  4901. rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
  4902. rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
  4903. rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
  4904. rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
  4905. rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
  4906. mempool_free(pmb, phba->mbox_mem_pool);
  4907. /* Xmit ELS RLS ACC response tag <ulpIoTag> */
  4908. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  4909. "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
  4910. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  4911. elsiocb->iotag, elsiocb->iocb.ulpContext,
  4912. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4913. ndlp->nlp_rpi);
  4914. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4915. phba->fc_stat.elsXmitACC++;
  4916. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
  4917. lpfc_els_free_iocb(phba, elsiocb);
  4918. }
  4919. /**
  4920. * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
  4921. * @phba: pointer to lpfc hba data structure.
  4922. * @pmb: pointer to the driver internal queue element for mailbox command.
  4923. *
  4924. * This routine is the completion callback function for the MBX_READ_LNK_STAT
  4925. * mailbox command. This callback function is to actually send the Accept
  4926. * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
  4927. * collects the link statistics from the completion of the MBX_READ_LNK_STAT
  4928. * mailbox command, constructs the RPS response with the link statistics
  4929. * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
  4930. * response to the RPS.
  4931. *
  4932. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4933. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4934. * will be stored into the context1 field of the IOCB for the completion
  4935. * callback function to the RPS Accept Response ELS IOCB command.
  4936. *
  4937. **/
  4938. static void
  4939. lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4940. {
  4941. MAILBOX_t *mb;
  4942. IOCB_t *icmd;
  4943. RPS_RSP *rps_rsp;
  4944. uint8_t *pcmd;
  4945. struct lpfc_iocbq *elsiocb;
  4946. struct lpfc_nodelist *ndlp;
  4947. uint16_t status;
  4948. uint16_t oxid;
  4949. uint16_t rxid;
  4950. uint32_t cmdsize;
  4951. mb = &pmb->u.mb;
  4952. ndlp = (struct lpfc_nodelist *) pmb->context2;
  4953. rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
  4954. oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
  4955. pmb->context1 = NULL;
  4956. pmb->context2 = NULL;
  4957. if (mb->mbxStatus) {
  4958. mempool_free(pmb, phba->mbox_mem_pool);
  4959. return;
  4960. }
  4961. cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
  4962. mempool_free(pmb, phba->mbox_mem_pool);
  4963. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  4964. lpfc_max_els_tries, ndlp,
  4965. ndlp->nlp_DID, ELS_CMD_ACC);
  4966. /* Decrement the ndlp reference count from previous mbox command */
  4967. lpfc_nlp_put(ndlp);
  4968. if (!elsiocb)
  4969. return;
  4970. icmd = &elsiocb->iocb;
  4971. icmd->ulpContext = rxid;
  4972. icmd->unsli3.rcvsli3.ox_id = oxid;
  4973. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4974. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4975. pcmd += sizeof(uint32_t); /* Skip past command */
  4976. rps_rsp = (RPS_RSP *)pcmd;
  4977. if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
  4978. status = 0x10;
  4979. else
  4980. status = 0x8;
  4981. if (phba->pport->fc_flag & FC_FABRIC)
  4982. status |= 0x4;
  4983. rps_rsp->rsvd1 = 0;
  4984. rps_rsp->portStatus = cpu_to_be16(status);
  4985. rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
  4986. rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
  4987. rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
  4988. rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
  4989. rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
  4990. rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
  4991. /* Xmit ELS RPS ACC response tag <ulpIoTag> */
  4992. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  4993. "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
  4994. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  4995. elsiocb->iotag, elsiocb->iocb.ulpContext,
  4996. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4997. ndlp->nlp_rpi);
  4998. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4999. phba->fc_stat.elsXmitACC++;
  5000. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
  5001. lpfc_els_free_iocb(phba, elsiocb);
  5002. return;
  5003. }
  5004. /**
  5005. * lpfc_els_rcv_rls - Process an unsolicited rls iocb
  5006. * @vport: pointer to a host virtual N_Port data structure.
  5007. * @cmdiocb: pointer to lpfc command iocb data structure.
  5008. * @ndlp: pointer to a node-list data structure.
  5009. *
  5010. * This routine processes Read Port Status (RPL) IOCB received as an
  5011. * ELS unsolicited event. It first checks the remote port state. If the
  5012. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  5013. * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
  5014. * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
  5015. * for reading the HBA link statistics. It is for the callback function,
  5016. * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
  5017. * to actually sending out RPL Accept (ACC) response.
  5018. *
  5019. * Return codes
  5020. * 0 - Successfully processed rls iocb (currently always return 0)
  5021. **/
  5022. static int
  5023. lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5024. struct lpfc_nodelist *ndlp)
  5025. {
  5026. struct lpfc_hba *phba = vport->phba;
  5027. LPFC_MBOXQ_t *mbox;
  5028. struct lpfc_dmabuf *pcmd;
  5029. struct ls_rjt stat;
  5030. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  5031. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  5032. /* reject the unsolicited RPS request and done with it */
  5033. goto reject_out;
  5034. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5035. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  5036. if (mbox) {
  5037. lpfc_read_lnk_stat(phba, mbox);
  5038. mbox->context1 = (void *)((unsigned long)
  5039. ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
  5040. cmdiocb->iocb.ulpContext)); /* rx_id */
  5041. mbox->context2 = lpfc_nlp_get(ndlp);
  5042. mbox->vport = vport;
  5043. mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
  5044. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  5045. != MBX_NOT_FINISHED)
  5046. /* Mbox completion will send ELS Response */
  5047. return 0;
  5048. /* Decrement reference count used for the failed mbox
  5049. * command.
  5050. */
  5051. lpfc_nlp_put(ndlp);
  5052. mempool_free(mbox, phba->mbox_mem_pool);
  5053. }
  5054. reject_out:
  5055. /* issue rejection response */
  5056. stat.un.b.lsRjtRsvd0 = 0;
  5057. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5058. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  5059. stat.un.b.vendorUnique = 0;
  5060. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  5061. return 0;
  5062. }
  5063. /**
  5064. * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
  5065. * @vport: pointer to a host virtual N_Port data structure.
  5066. * @cmdiocb: pointer to lpfc command iocb data structure.
  5067. * @ndlp: pointer to a node-list data structure.
  5068. *
  5069. * This routine processes Read Timout Value (RTV) IOCB received as an
  5070. * ELS unsolicited event. It first checks the remote port state. If the
  5071. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  5072. * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
  5073. * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
  5074. * Value (RTV) unsolicited IOCB event.
  5075. *
  5076. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  5077. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  5078. * will be stored into the context1 field of the IOCB for the completion
  5079. * callback function to the RPS Accept Response ELS IOCB command.
  5080. *
  5081. * Return codes
  5082. * 0 - Successfully processed rtv iocb (currently always return 0)
  5083. **/
  5084. static int
  5085. lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5086. struct lpfc_nodelist *ndlp)
  5087. {
  5088. struct lpfc_hba *phba = vport->phba;
  5089. struct ls_rjt stat;
  5090. struct RTV_RSP *rtv_rsp;
  5091. uint8_t *pcmd;
  5092. struct lpfc_iocbq *elsiocb;
  5093. uint32_t cmdsize;
  5094. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  5095. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  5096. /* reject the unsolicited RPS request and done with it */
  5097. goto reject_out;
  5098. cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
  5099. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  5100. lpfc_max_els_tries, ndlp,
  5101. ndlp->nlp_DID, ELS_CMD_ACC);
  5102. if (!elsiocb)
  5103. return 1;
  5104. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5105. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  5106. pcmd += sizeof(uint32_t); /* Skip past command */
  5107. /* use the command's xri in the response */
  5108. elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
  5109. elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
  5110. rtv_rsp = (struct RTV_RSP *)pcmd;
  5111. /* populate RTV payload */
  5112. rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
  5113. rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
  5114. bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
  5115. bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
  5116. rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
  5117. /* Xmit ELS RLS ACC response tag <ulpIoTag> */
  5118. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  5119. "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
  5120. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
  5121. "Data: x%x x%x x%x\n",
  5122. elsiocb->iotag, elsiocb->iocb.ulpContext,
  5123. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  5124. ndlp->nlp_rpi,
  5125. rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
  5126. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  5127. phba->fc_stat.elsXmitACC++;
  5128. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
  5129. lpfc_els_free_iocb(phba, elsiocb);
  5130. return 0;
  5131. reject_out:
  5132. /* issue rejection response */
  5133. stat.un.b.lsRjtRsvd0 = 0;
  5134. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5135. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  5136. stat.un.b.vendorUnique = 0;
  5137. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  5138. return 0;
  5139. }
  5140. /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
  5141. * @vport: pointer to a host virtual N_Port data structure.
  5142. * @cmdiocb: pointer to lpfc command iocb data structure.
  5143. * @ndlp: pointer to a node-list data structure.
  5144. *
  5145. * This routine processes Read Port Status (RPS) IOCB received as an
  5146. * ELS unsolicited event. It first checks the remote port state. If the
  5147. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  5148. * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
  5149. * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
  5150. * for reading the HBA link statistics. It is for the callback function,
  5151. * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
  5152. * to actually sending out RPS Accept (ACC) response.
  5153. *
  5154. * Return codes
  5155. * 0 - Successfully processed rps iocb (currently always return 0)
  5156. **/
  5157. static int
  5158. lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5159. struct lpfc_nodelist *ndlp)
  5160. {
  5161. struct lpfc_hba *phba = vport->phba;
  5162. uint32_t *lp;
  5163. uint8_t flag;
  5164. LPFC_MBOXQ_t *mbox;
  5165. struct lpfc_dmabuf *pcmd;
  5166. RPS *rps;
  5167. struct ls_rjt stat;
  5168. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  5169. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  5170. /* reject the unsolicited RPS request and done with it */
  5171. goto reject_out;
  5172. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5173. lp = (uint32_t *) pcmd->virt;
  5174. flag = (be32_to_cpu(*lp++) & 0xf);
  5175. rps = (RPS *) lp;
  5176. if ((flag == 0) ||
  5177. ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
  5178. ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
  5179. sizeof(struct lpfc_name)) == 0))) {
  5180. printk("Fix me....\n");
  5181. dump_stack();
  5182. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  5183. if (mbox) {
  5184. lpfc_read_lnk_stat(phba, mbox);
  5185. mbox->context1 = (void *)((unsigned long)
  5186. ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
  5187. cmdiocb->iocb.ulpContext)); /* rx_id */
  5188. mbox->context2 = lpfc_nlp_get(ndlp);
  5189. mbox->vport = vport;
  5190. mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
  5191. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  5192. != MBX_NOT_FINISHED)
  5193. /* Mbox completion will send ELS Response */
  5194. return 0;
  5195. /* Decrement reference count used for the failed mbox
  5196. * command.
  5197. */
  5198. lpfc_nlp_put(ndlp);
  5199. mempool_free(mbox, phba->mbox_mem_pool);
  5200. }
  5201. }
  5202. reject_out:
  5203. /* issue rejection response */
  5204. stat.un.b.lsRjtRsvd0 = 0;
  5205. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5206. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  5207. stat.un.b.vendorUnique = 0;
  5208. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  5209. return 0;
  5210. }
  5211. /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
  5212. * @vport: pointer to a host virtual N_Port data structure.
  5213. * @ndlp: pointer to a node-list data structure.
  5214. * @did: DID of the target.
  5215. * @rrq: Pointer to the rrq struct.
  5216. *
  5217. * Build a ELS RRQ command and send it to the target. If the issue_iocb is
  5218. * Successful the the completion handler will clear the RRQ.
  5219. *
  5220. * Return codes
  5221. * 0 - Successfully sent rrq els iocb.
  5222. * 1 - Failed to send rrq els iocb.
  5223. **/
  5224. static int
  5225. lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  5226. uint32_t did, struct lpfc_node_rrq *rrq)
  5227. {
  5228. struct lpfc_hba *phba = vport->phba;
  5229. struct RRQ *els_rrq;
  5230. IOCB_t *icmd;
  5231. struct lpfc_iocbq *elsiocb;
  5232. uint8_t *pcmd;
  5233. uint16_t cmdsize;
  5234. int ret;
  5235. if (ndlp != rrq->ndlp)
  5236. ndlp = rrq->ndlp;
  5237. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  5238. return 1;
  5239. /* If ndlp is not NULL, we will bump the reference count on it */
  5240. cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
  5241. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
  5242. ELS_CMD_RRQ);
  5243. if (!elsiocb)
  5244. return 1;
  5245. icmd = &elsiocb->iocb;
  5246. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5247. /* For RRQ request, remainder of payload is Exchange IDs */
  5248. *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
  5249. pcmd += sizeof(uint32_t);
  5250. els_rrq = (struct RRQ *) pcmd;
  5251. bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
  5252. bf_set(rrq_rxid, els_rrq, rrq->rxid);
  5253. bf_set(rrq_did, els_rrq, vport->fc_myDID);
  5254. els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
  5255. els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
  5256. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  5257. "Issue RRQ: did:x%x",
  5258. did, rrq->xritag, rrq->rxid);
  5259. elsiocb->context_un.rrq = rrq;
  5260. elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
  5261. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5262. if (ret == IOCB_ERROR) {
  5263. lpfc_els_free_iocb(phba, elsiocb);
  5264. return 1;
  5265. }
  5266. return 0;
  5267. }
  5268. /**
  5269. * lpfc_send_rrq - Sends ELS RRQ if needed.
  5270. * @phba: pointer to lpfc hba data structure.
  5271. * @rrq: pointer to the active rrq.
  5272. *
  5273. * This routine will call the lpfc_issue_els_rrq if the rrq is
  5274. * still active for the xri. If this function returns a failure then
  5275. * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
  5276. *
  5277. * Returns 0 Success.
  5278. * 1 Failure.
  5279. **/
  5280. int
  5281. lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
  5282. {
  5283. struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
  5284. rrq->nlp_DID);
  5285. if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
  5286. return lpfc_issue_els_rrq(rrq->vport, ndlp,
  5287. rrq->nlp_DID, rrq);
  5288. else
  5289. return 1;
  5290. }
  5291. /**
  5292. * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
  5293. * @vport: pointer to a host virtual N_Port data structure.
  5294. * @cmdsize: size of the ELS command.
  5295. * @oldiocb: pointer to the original lpfc command iocb data structure.
  5296. * @ndlp: pointer to a node-list data structure.
  5297. *
  5298. * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
  5299. * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
  5300. *
  5301. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  5302. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  5303. * will be stored into the context1 field of the IOCB for the completion
  5304. * callback function to the RPL Accept Response ELS command.
  5305. *
  5306. * Return code
  5307. * 0 - Successfully issued ACC RPL ELS command
  5308. * 1 - Failed to issue ACC RPL ELS command
  5309. **/
  5310. static int
  5311. lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
  5312. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  5313. {
  5314. struct lpfc_hba *phba = vport->phba;
  5315. IOCB_t *icmd, *oldcmd;
  5316. RPL_RSP rpl_rsp;
  5317. struct lpfc_iocbq *elsiocb;
  5318. uint8_t *pcmd;
  5319. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  5320. ndlp->nlp_DID, ELS_CMD_ACC);
  5321. if (!elsiocb)
  5322. return 1;
  5323. icmd = &elsiocb->iocb;
  5324. oldcmd = &oldiocb->iocb;
  5325. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  5326. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  5327. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5328. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  5329. pcmd += sizeof(uint16_t);
  5330. *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
  5331. pcmd += sizeof(uint16_t);
  5332. /* Setup the RPL ACC payload */
  5333. rpl_rsp.listLen = be32_to_cpu(1);
  5334. rpl_rsp.index = 0;
  5335. rpl_rsp.port_num_blk.portNum = 0;
  5336. rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
  5337. memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
  5338. sizeof(struct lpfc_name));
  5339. memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
  5340. /* Xmit ELS RPL ACC response tag <ulpIoTag> */
  5341. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5342. "0120 Xmit ELS RPL ACC response tag x%x "
  5343. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  5344. "rpi x%x\n",
  5345. elsiocb->iotag, elsiocb->iocb.ulpContext,
  5346. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  5347. ndlp->nlp_rpi);
  5348. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  5349. phba->fc_stat.elsXmitACC++;
  5350. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  5351. IOCB_ERROR) {
  5352. lpfc_els_free_iocb(phba, elsiocb);
  5353. return 1;
  5354. }
  5355. return 0;
  5356. }
  5357. /**
  5358. * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
  5359. * @vport: pointer to a host virtual N_Port data structure.
  5360. * @cmdiocb: pointer to lpfc command iocb data structure.
  5361. * @ndlp: pointer to a node-list data structure.
  5362. *
  5363. * This routine processes Read Port List (RPL) IOCB received as an ELS
  5364. * unsolicited event. It first checks the remote port state. If the remote
  5365. * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
  5366. * invokes the lpfc_els_rsp_reject() routine to send reject response.
  5367. * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
  5368. * to accept the RPL.
  5369. *
  5370. * Return code
  5371. * 0 - Successfully processed rpl iocb (currently always return 0)
  5372. **/
  5373. static int
  5374. lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5375. struct lpfc_nodelist *ndlp)
  5376. {
  5377. struct lpfc_dmabuf *pcmd;
  5378. uint32_t *lp;
  5379. uint32_t maxsize;
  5380. uint16_t cmdsize;
  5381. RPL *rpl;
  5382. struct ls_rjt stat;
  5383. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  5384. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  5385. /* issue rejection response */
  5386. stat.un.b.lsRjtRsvd0 = 0;
  5387. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5388. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  5389. stat.un.b.vendorUnique = 0;
  5390. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  5391. NULL);
  5392. /* rejected the unsolicited RPL request and done with it */
  5393. return 0;
  5394. }
  5395. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5396. lp = (uint32_t *) pcmd->virt;
  5397. rpl = (RPL *) (lp + 1);
  5398. maxsize = be32_to_cpu(rpl->maxsize);
  5399. /* We support only one port */
  5400. if ((rpl->index == 0) &&
  5401. ((maxsize == 0) ||
  5402. ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
  5403. cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
  5404. } else {
  5405. cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
  5406. }
  5407. lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
  5408. return 0;
  5409. }
  5410. /**
  5411. * lpfc_els_rcv_farp - Process an unsolicited farp request els command
  5412. * @vport: pointer to a virtual N_Port data structure.
  5413. * @cmdiocb: pointer to lpfc command iocb data structure.
  5414. * @ndlp: pointer to a node-list data structure.
  5415. *
  5416. * This routine processes Fibre Channel Address Resolution Protocol
  5417. * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
  5418. * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
  5419. * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
  5420. * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
  5421. * remote PortName is compared against the FC PortName stored in the @vport
  5422. * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
  5423. * compared against the FC NodeName stored in the @vport data structure.
  5424. * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
  5425. * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
  5426. * invoked to send out FARP Response to the remote node. Before sending the
  5427. * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
  5428. * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
  5429. * routine is invoked to log into the remote port first.
  5430. *
  5431. * Return code
  5432. * 0 - Either the FARP Match Mode not supported or successfully processed
  5433. **/
  5434. static int
  5435. lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5436. struct lpfc_nodelist *ndlp)
  5437. {
  5438. struct lpfc_dmabuf *pcmd;
  5439. uint32_t *lp;
  5440. IOCB_t *icmd;
  5441. FARP *fp;
  5442. uint32_t cmd, cnt, did;
  5443. icmd = &cmdiocb->iocb;
  5444. did = icmd->un.elsreq64.remoteID;
  5445. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5446. lp = (uint32_t *) pcmd->virt;
  5447. cmd = *lp++;
  5448. fp = (FARP *) lp;
  5449. /* FARP-REQ received from DID <did> */
  5450. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5451. "0601 FARP-REQ received from DID x%x\n", did);
  5452. /* We will only support match on WWPN or WWNN */
  5453. if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
  5454. return 0;
  5455. }
  5456. cnt = 0;
  5457. /* If this FARP command is searching for my portname */
  5458. if (fp->Mflags & FARP_MATCH_PORT) {
  5459. if (memcmp(&fp->RportName, &vport->fc_portname,
  5460. sizeof(struct lpfc_name)) == 0)
  5461. cnt = 1;
  5462. }
  5463. /* If this FARP command is searching for my nodename */
  5464. if (fp->Mflags & FARP_MATCH_NODE) {
  5465. if (memcmp(&fp->RnodeName, &vport->fc_nodename,
  5466. sizeof(struct lpfc_name)) == 0)
  5467. cnt = 1;
  5468. }
  5469. if (cnt) {
  5470. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  5471. (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
  5472. /* Log back into the node before sending the FARP. */
  5473. if (fp->Rflags & FARP_REQUEST_PLOGI) {
  5474. ndlp->nlp_prev_state = ndlp->nlp_state;
  5475. lpfc_nlp_set_state(vport, ndlp,
  5476. NLP_STE_PLOGI_ISSUE);
  5477. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  5478. }
  5479. /* Send a FARP response to that node */
  5480. if (fp->Rflags & FARP_REQUEST_FARPR)
  5481. lpfc_issue_els_farpr(vport, did, 0);
  5482. }
  5483. }
  5484. return 0;
  5485. }
  5486. /**
  5487. * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
  5488. * @vport: pointer to a host virtual N_Port data structure.
  5489. * @cmdiocb: pointer to lpfc command iocb data structure.
  5490. * @ndlp: pointer to a node-list data structure.
  5491. *
  5492. * This routine processes Fibre Channel Address Resolution Protocol
  5493. * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
  5494. * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
  5495. * the FARP response request.
  5496. *
  5497. * Return code
  5498. * 0 - Successfully processed FARPR IOCB (currently always return 0)
  5499. **/
  5500. static int
  5501. lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5502. struct lpfc_nodelist *ndlp)
  5503. {
  5504. struct lpfc_dmabuf *pcmd;
  5505. uint32_t *lp;
  5506. IOCB_t *icmd;
  5507. uint32_t cmd, did;
  5508. icmd = &cmdiocb->iocb;
  5509. did = icmd->un.elsreq64.remoteID;
  5510. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5511. lp = (uint32_t *) pcmd->virt;
  5512. cmd = *lp++;
  5513. /* FARP-RSP received from DID <did> */
  5514. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5515. "0600 FARP-RSP received from DID x%x\n", did);
  5516. /* ACCEPT the Farp resp request */
  5517. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  5518. return 0;
  5519. }
  5520. /**
  5521. * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
  5522. * @vport: pointer to a host virtual N_Port data structure.
  5523. * @cmdiocb: pointer to lpfc command iocb data structure.
  5524. * @fan_ndlp: pointer to a node-list data structure.
  5525. *
  5526. * This routine processes a Fabric Address Notification (FAN) IOCB
  5527. * command received as an ELS unsolicited event. The FAN ELS command will
  5528. * only be processed on a physical port (i.e., the @vport represents the
  5529. * physical port). The fabric NodeName and PortName from the FAN IOCB are
  5530. * compared against those in the phba data structure. If any of those is
  5531. * different, the lpfc_initial_flogi() routine is invoked to initialize
  5532. * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
  5533. * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
  5534. * is invoked to register login to the fabric.
  5535. *
  5536. * Return code
  5537. * 0 - Successfully processed fan iocb (currently always return 0).
  5538. **/
  5539. static int
  5540. lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5541. struct lpfc_nodelist *fan_ndlp)
  5542. {
  5543. struct lpfc_hba *phba = vport->phba;
  5544. uint32_t *lp;
  5545. FAN *fp;
  5546. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
  5547. lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
  5548. fp = (FAN *) ++lp;
  5549. /* FAN received; Fan does not have a reply sequence */
  5550. if ((vport == phba->pport) &&
  5551. (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
  5552. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  5553. sizeof(struct lpfc_name))) ||
  5554. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  5555. sizeof(struct lpfc_name)))) {
  5556. /* This port has switched fabrics. FLOGI is required */
  5557. lpfc_issue_init_vfi(vport);
  5558. } else {
  5559. /* FAN verified - skip FLOGI */
  5560. vport->fc_myDID = vport->fc_prevDID;
  5561. if (phba->sli_rev < LPFC_SLI_REV4)
  5562. lpfc_issue_fabric_reglogin(vport);
  5563. else {
  5564. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5565. "3138 Need register VFI: (x%x/%x)\n",
  5566. vport->fc_prevDID, vport->fc_myDID);
  5567. lpfc_issue_reg_vfi(vport);
  5568. }
  5569. }
  5570. }
  5571. return 0;
  5572. }
  5573. /**
  5574. * lpfc_els_timeout - Handler funciton to the els timer
  5575. * @ptr: holder for the timer function associated data.
  5576. *
  5577. * This routine is invoked by the ELS timer after timeout. It posts the ELS
  5578. * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
  5579. * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
  5580. * up the worker thread. It is for the worker thread to invoke the routine
  5581. * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
  5582. **/
  5583. void
  5584. lpfc_els_timeout(unsigned long ptr)
  5585. {
  5586. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  5587. struct lpfc_hba *phba = vport->phba;
  5588. uint32_t tmo_posted;
  5589. unsigned long iflag;
  5590. spin_lock_irqsave(&vport->work_port_lock, iflag);
  5591. tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
  5592. if (!tmo_posted)
  5593. vport->work_port_events |= WORKER_ELS_TMO;
  5594. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  5595. if (!tmo_posted)
  5596. lpfc_worker_wake_up(phba);
  5597. return;
  5598. }
  5599. /**
  5600. * lpfc_els_timeout_handler - Process an els timeout event
  5601. * @vport: pointer to a virtual N_Port data structure.
  5602. *
  5603. * This routine is the actual handler function that processes an ELS timeout
  5604. * event. It walks the ELS ring to get and abort all the IOCBs (except the
  5605. * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
  5606. * invoking the lpfc_sli_issue_abort_iotag() routine.
  5607. **/
  5608. void
  5609. lpfc_els_timeout_handler(struct lpfc_vport *vport)
  5610. {
  5611. struct lpfc_hba *phba = vport->phba;
  5612. struct lpfc_sli_ring *pring;
  5613. struct lpfc_iocbq *tmp_iocb, *piocb;
  5614. IOCB_t *cmd = NULL;
  5615. struct lpfc_dmabuf *pcmd;
  5616. uint32_t els_command = 0;
  5617. uint32_t timeout;
  5618. uint32_t remote_ID = 0xffffffff;
  5619. LIST_HEAD(txcmplq_completions);
  5620. LIST_HEAD(abort_list);
  5621. timeout = (uint32_t)(phba->fc_ratov << 1);
  5622. pring = &phba->sli.ring[LPFC_ELS_RING];
  5623. spin_lock_irq(&phba->hbalock);
  5624. list_splice_init(&pring->txcmplq, &txcmplq_completions);
  5625. spin_unlock_irq(&phba->hbalock);
  5626. list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
  5627. cmd = &piocb->iocb;
  5628. if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
  5629. piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5630. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5631. continue;
  5632. if (piocb->vport != vport)
  5633. continue;
  5634. pcmd = (struct lpfc_dmabuf *) piocb->context2;
  5635. if (pcmd)
  5636. els_command = *(uint32_t *) (pcmd->virt);
  5637. if (els_command == ELS_CMD_FARP ||
  5638. els_command == ELS_CMD_FARPR ||
  5639. els_command == ELS_CMD_FDISC)
  5640. continue;
  5641. if (piocb->drvrTimeout > 0) {
  5642. if (piocb->drvrTimeout >= timeout)
  5643. piocb->drvrTimeout -= timeout;
  5644. else
  5645. piocb->drvrTimeout = 0;
  5646. continue;
  5647. }
  5648. remote_ID = 0xffffffff;
  5649. if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
  5650. remote_ID = cmd->un.elsreq64.remoteID;
  5651. else {
  5652. struct lpfc_nodelist *ndlp;
  5653. ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
  5654. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  5655. remote_ID = ndlp->nlp_DID;
  5656. }
  5657. list_add_tail(&piocb->dlist, &abort_list);
  5658. }
  5659. spin_lock_irq(&phba->hbalock);
  5660. list_splice(&txcmplq_completions, &pring->txcmplq);
  5661. spin_unlock_irq(&phba->hbalock);
  5662. list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
  5663. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  5664. "0127 ELS timeout Data: x%x x%x x%x "
  5665. "x%x\n", els_command,
  5666. remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
  5667. spin_lock_irq(&phba->hbalock);
  5668. list_del_init(&piocb->dlist);
  5669. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  5670. spin_unlock_irq(&phba->hbalock);
  5671. }
  5672. if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq))
  5673. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  5674. }
  5675. /**
  5676. * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
  5677. * @vport: pointer to a host virtual N_Port data structure.
  5678. *
  5679. * This routine is used to clean up all the outstanding ELS commands on a
  5680. * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
  5681. * routine. After that, it walks the ELS transmit queue to remove all the
  5682. * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
  5683. * the IOCBs with a non-NULL completion callback function, the callback
  5684. * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
  5685. * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
  5686. * callback function, the IOCB will simply be released. Finally, it walks
  5687. * the ELS transmit completion queue to issue an abort IOCB to any transmit
  5688. * completion queue IOCB that is associated with the @vport and is not
  5689. * an IOCB from libdfc (i.e., the management plane IOCBs that are not
  5690. * part of the discovery state machine) out to HBA by invoking the
  5691. * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
  5692. * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
  5693. * the IOCBs are aborted when this function returns.
  5694. **/
  5695. void
  5696. lpfc_els_flush_cmd(struct lpfc_vport *vport)
  5697. {
  5698. LIST_HEAD(completions);
  5699. struct lpfc_hba *phba = vport->phba;
  5700. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  5701. struct lpfc_iocbq *tmp_iocb, *piocb;
  5702. IOCB_t *cmd = NULL;
  5703. lpfc_fabric_abort_vport(vport);
  5704. spin_lock_irq(&phba->hbalock);
  5705. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  5706. cmd = &piocb->iocb;
  5707. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  5708. continue;
  5709. }
  5710. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  5711. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  5712. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  5713. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  5714. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  5715. continue;
  5716. if (piocb->vport != vport)
  5717. continue;
  5718. list_move_tail(&piocb->list, &completions);
  5719. }
  5720. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  5721. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  5722. continue;
  5723. }
  5724. if (piocb->vport != vport)
  5725. continue;
  5726. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  5727. }
  5728. spin_unlock_irq(&phba->hbalock);
  5729. /* Cancell all the IOCBs from the completions list */
  5730. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  5731. IOERR_SLI_ABORTED);
  5732. return;
  5733. }
  5734. /**
  5735. * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
  5736. * @phba: pointer to lpfc hba data structure.
  5737. *
  5738. * This routine is used to clean up all the outstanding ELS commands on a
  5739. * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
  5740. * routine. After that, it walks the ELS transmit queue to remove all the
  5741. * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
  5742. * the IOCBs with the completion callback function associated, the callback
  5743. * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
  5744. * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
  5745. * callback function associated, the IOCB will simply be released. Finally,
  5746. * it walks the ELS transmit completion queue to issue an abort IOCB to any
  5747. * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
  5748. * management plane IOCBs that are not part of the discovery state machine)
  5749. * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
  5750. **/
  5751. void
  5752. lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
  5753. {
  5754. LIST_HEAD(completions);
  5755. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  5756. struct lpfc_iocbq *tmp_iocb, *piocb;
  5757. IOCB_t *cmd = NULL;
  5758. lpfc_fabric_abort_hba(phba);
  5759. spin_lock_irq(&phba->hbalock);
  5760. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  5761. cmd = &piocb->iocb;
  5762. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  5763. continue;
  5764. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  5765. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  5766. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  5767. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  5768. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  5769. continue;
  5770. list_move_tail(&piocb->list, &completions);
  5771. }
  5772. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  5773. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  5774. continue;
  5775. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  5776. }
  5777. spin_unlock_irq(&phba->hbalock);
  5778. /* Cancel all the IOCBs from the completions list */
  5779. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  5780. IOERR_SLI_ABORTED);
  5781. return;
  5782. }
  5783. /**
  5784. * lpfc_send_els_failure_event - Posts an ELS command failure event
  5785. * @phba: Pointer to hba context object.
  5786. * @cmdiocbp: Pointer to command iocb which reported error.
  5787. * @rspiocbp: Pointer to response iocb which reported error.
  5788. *
  5789. * This function sends an event when there is an ELS command
  5790. * failure.
  5791. **/
  5792. void
  5793. lpfc_send_els_failure_event(struct lpfc_hba *phba,
  5794. struct lpfc_iocbq *cmdiocbp,
  5795. struct lpfc_iocbq *rspiocbp)
  5796. {
  5797. struct lpfc_vport *vport = cmdiocbp->vport;
  5798. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5799. struct lpfc_lsrjt_event lsrjt_event;
  5800. struct lpfc_fabric_event_header fabric_event;
  5801. struct ls_rjt stat;
  5802. struct lpfc_nodelist *ndlp;
  5803. uint32_t *pcmd;
  5804. ndlp = cmdiocbp->context1;
  5805. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  5806. return;
  5807. if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
  5808. lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
  5809. lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
  5810. memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
  5811. sizeof(struct lpfc_name));
  5812. memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
  5813. sizeof(struct lpfc_name));
  5814. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  5815. cmdiocbp->context2)->virt);
  5816. lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
  5817. stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
  5818. lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
  5819. lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
  5820. fc_host_post_vendor_event(shost,
  5821. fc_get_event_number(),
  5822. sizeof(lsrjt_event),
  5823. (char *)&lsrjt_event,
  5824. LPFC_NL_VENDOR_ID);
  5825. return;
  5826. }
  5827. if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
  5828. (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
  5829. fabric_event.event_type = FC_REG_FABRIC_EVENT;
  5830. if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
  5831. fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
  5832. else
  5833. fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
  5834. memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
  5835. sizeof(struct lpfc_name));
  5836. memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
  5837. sizeof(struct lpfc_name));
  5838. fc_host_post_vendor_event(shost,
  5839. fc_get_event_number(),
  5840. sizeof(fabric_event),
  5841. (char *)&fabric_event,
  5842. LPFC_NL_VENDOR_ID);
  5843. return;
  5844. }
  5845. }
  5846. /**
  5847. * lpfc_send_els_event - Posts unsolicited els event
  5848. * @vport: Pointer to vport object.
  5849. * @ndlp: Pointer FC node object.
  5850. * @cmd: ELS command code.
  5851. *
  5852. * This function posts an event when there is an incoming
  5853. * unsolicited ELS command.
  5854. **/
  5855. static void
  5856. lpfc_send_els_event(struct lpfc_vport *vport,
  5857. struct lpfc_nodelist *ndlp,
  5858. uint32_t *payload)
  5859. {
  5860. struct lpfc_els_event_header *els_data = NULL;
  5861. struct lpfc_logo_event *logo_data = NULL;
  5862. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5863. if (*payload == ELS_CMD_LOGO) {
  5864. logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
  5865. if (!logo_data) {
  5866. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  5867. "0148 Failed to allocate memory "
  5868. "for LOGO event\n");
  5869. return;
  5870. }
  5871. els_data = &logo_data->header;
  5872. } else {
  5873. els_data = kmalloc(sizeof(struct lpfc_els_event_header),
  5874. GFP_KERNEL);
  5875. if (!els_data) {
  5876. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  5877. "0149 Failed to allocate memory "
  5878. "for ELS event\n");
  5879. return;
  5880. }
  5881. }
  5882. els_data->event_type = FC_REG_ELS_EVENT;
  5883. switch (*payload) {
  5884. case ELS_CMD_PLOGI:
  5885. els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
  5886. break;
  5887. case ELS_CMD_PRLO:
  5888. els_data->subcategory = LPFC_EVENT_PRLO_RCV;
  5889. break;
  5890. case ELS_CMD_ADISC:
  5891. els_data->subcategory = LPFC_EVENT_ADISC_RCV;
  5892. break;
  5893. case ELS_CMD_LOGO:
  5894. els_data->subcategory = LPFC_EVENT_LOGO_RCV;
  5895. /* Copy the WWPN in the LOGO payload */
  5896. memcpy(logo_data->logo_wwpn, &payload[2],
  5897. sizeof(struct lpfc_name));
  5898. break;
  5899. default:
  5900. kfree(els_data);
  5901. return;
  5902. }
  5903. memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
  5904. memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
  5905. if (*payload == ELS_CMD_LOGO) {
  5906. fc_host_post_vendor_event(shost,
  5907. fc_get_event_number(),
  5908. sizeof(struct lpfc_logo_event),
  5909. (char *)logo_data,
  5910. LPFC_NL_VENDOR_ID);
  5911. kfree(logo_data);
  5912. } else {
  5913. fc_host_post_vendor_event(shost,
  5914. fc_get_event_number(),
  5915. sizeof(struct lpfc_els_event_header),
  5916. (char *)els_data,
  5917. LPFC_NL_VENDOR_ID);
  5918. kfree(els_data);
  5919. }
  5920. return;
  5921. }
  5922. /**
  5923. * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
  5924. * @phba: pointer to lpfc hba data structure.
  5925. * @pring: pointer to a SLI ring.
  5926. * @vport: pointer to a host virtual N_Port data structure.
  5927. * @elsiocb: pointer to lpfc els command iocb data structure.
  5928. *
  5929. * This routine is used for processing the IOCB associated with a unsolicited
  5930. * event. It first determines whether there is an existing ndlp that matches
  5931. * the DID from the unsolicited IOCB. If not, it will create a new one with
  5932. * the DID from the unsolicited IOCB. The ELS command from the unsolicited
  5933. * IOCB is then used to invoke the proper routine and to set up proper state
  5934. * of the discovery state machine.
  5935. **/
  5936. static void
  5937. lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5938. struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
  5939. {
  5940. struct Scsi_Host *shost;
  5941. struct lpfc_nodelist *ndlp;
  5942. struct ls_rjt stat;
  5943. uint32_t *payload;
  5944. uint32_t cmd, did, newnode;
  5945. uint8_t rjt_exp, rjt_err = 0;
  5946. IOCB_t *icmd = &elsiocb->iocb;
  5947. if (!vport || !(elsiocb->context2))
  5948. goto dropit;
  5949. newnode = 0;
  5950. payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
  5951. cmd = *payload;
  5952. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
  5953. lpfc_post_buffer(phba, pring, 1);
  5954. did = icmd->un.rcvels.remoteID;
  5955. if (icmd->ulpStatus) {
  5956. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  5957. "RCV Unsol ELS: status:x%x/x%x did:x%x",
  5958. icmd->ulpStatus, icmd->un.ulpWord[4], did);
  5959. goto dropit;
  5960. }
  5961. /* Check to see if link went down during discovery */
  5962. if (lpfc_els_chk_latt(vport))
  5963. goto dropit;
  5964. /* Ignore traffic received during vport shutdown. */
  5965. if (vport->load_flag & FC_UNLOADING)
  5966. goto dropit;
  5967. /* If NPort discovery is delayed drop incoming ELS */
  5968. if ((vport->fc_flag & FC_DISC_DELAYED) &&
  5969. (cmd != ELS_CMD_PLOGI))
  5970. goto dropit;
  5971. ndlp = lpfc_findnode_did(vport, did);
  5972. if (!ndlp) {
  5973. /* Cannot find existing Fabric ndlp, so allocate a new one */
  5974. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  5975. if (!ndlp)
  5976. goto dropit;
  5977. lpfc_nlp_init(vport, ndlp, did);
  5978. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  5979. newnode = 1;
  5980. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  5981. ndlp->nlp_type |= NLP_FABRIC;
  5982. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  5983. ndlp = lpfc_enable_node(vport, ndlp,
  5984. NLP_STE_UNUSED_NODE);
  5985. if (!ndlp)
  5986. goto dropit;
  5987. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  5988. newnode = 1;
  5989. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  5990. ndlp->nlp_type |= NLP_FABRIC;
  5991. } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  5992. /* This is similar to the new node path */
  5993. ndlp = lpfc_nlp_get(ndlp);
  5994. if (!ndlp)
  5995. goto dropit;
  5996. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  5997. newnode = 1;
  5998. }
  5999. phba->fc_stat.elsRcvFrame++;
  6000. elsiocb->context1 = lpfc_nlp_get(ndlp);
  6001. elsiocb->vport = vport;
  6002. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  6003. cmd &= ELS_CMD_MASK;
  6004. }
  6005. /* ELS command <elsCmd> received from NPORT <did> */
  6006. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6007. "0112 ELS command x%x received from NPORT x%x "
  6008. "Data: x%x\n", cmd, did, vport->port_state);
  6009. switch (cmd) {
  6010. case ELS_CMD_PLOGI:
  6011. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6012. "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
  6013. did, vport->port_state, ndlp->nlp_flag);
  6014. phba->fc_stat.elsRcvPLOGI++;
  6015. ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
  6016. lpfc_send_els_event(vport, ndlp, payload);
  6017. /* If Nport discovery is delayed, reject PLOGIs */
  6018. if (vport->fc_flag & FC_DISC_DELAYED) {
  6019. rjt_err = LSRJT_UNABLE_TPC;
  6020. rjt_exp = LSEXP_NOTHING_MORE;
  6021. break;
  6022. }
  6023. if (vport->port_state < LPFC_DISC_AUTH) {
  6024. if (!(phba->pport->fc_flag & FC_PT2PT) ||
  6025. (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
  6026. rjt_err = LSRJT_UNABLE_TPC;
  6027. rjt_exp = LSEXP_NOTHING_MORE;
  6028. break;
  6029. }
  6030. /* We get here, and drop thru, if we are PT2PT with
  6031. * another NPort and the other side has initiated
  6032. * the PLOGI before responding to our FLOGI.
  6033. */
  6034. }
  6035. shost = lpfc_shost_from_vport(vport);
  6036. spin_lock_irq(shost->host_lock);
  6037. ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
  6038. spin_unlock_irq(shost->host_lock);
  6039. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  6040. NLP_EVT_RCV_PLOGI);
  6041. break;
  6042. case ELS_CMD_FLOGI:
  6043. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6044. "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
  6045. did, vport->port_state, ndlp->nlp_flag);
  6046. phba->fc_stat.elsRcvFLOGI++;
  6047. lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
  6048. if (newnode)
  6049. lpfc_nlp_put(ndlp);
  6050. break;
  6051. case ELS_CMD_LOGO:
  6052. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6053. "RCV LOGO: did:x%x/ste:x%x flg:x%x",
  6054. did, vport->port_state, ndlp->nlp_flag);
  6055. phba->fc_stat.elsRcvLOGO++;
  6056. lpfc_send_els_event(vport, ndlp, payload);
  6057. if (vport->port_state < LPFC_DISC_AUTH) {
  6058. rjt_err = LSRJT_UNABLE_TPC;
  6059. rjt_exp = LSEXP_NOTHING_MORE;
  6060. break;
  6061. }
  6062. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  6063. break;
  6064. case ELS_CMD_PRLO:
  6065. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6066. "RCV PRLO: did:x%x/ste:x%x flg:x%x",
  6067. did, vport->port_state, ndlp->nlp_flag);
  6068. phba->fc_stat.elsRcvPRLO++;
  6069. lpfc_send_els_event(vport, ndlp, payload);
  6070. if (vport->port_state < LPFC_DISC_AUTH) {
  6071. rjt_err = LSRJT_UNABLE_TPC;
  6072. rjt_exp = LSEXP_NOTHING_MORE;
  6073. break;
  6074. }
  6075. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  6076. break;
  6077. case ELS_CMD_RSCN:
  6078. phba->fc_stat.elsRcvRSCN++;
  6079. lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
  6080. if (newnode)
  6081. lpfc_nlp_put(ndlp);
  6082. break;
  6083. case ELS_CMD_ADISC:
  6084. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6085. "RCV ADISC: did:x%x/ste:x%x flg:x%x",
  6086. did, vport->port_state, ndlp->nlp_flag);
  6087. lpfc_send_els_event(vport, ndlp, payload);
  6088. phba->fc_stat.elsRcvADISC++;
  6089. if (vport->port_state < LPFC_DISC_AUTH) {
  6090. rjt_err = LSRJT_UNABLE_TPC;
  6091. rjt_exp = LSEXP_NOTHING_MORE;
  6092. break;
  6093. }
  6094. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  6095. NLP_EVT_RCV_ADISC);
  6096. break;
  6097. case ELS_CMD_PDISC:
  6098. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6099. "RCV PDISC: did:x%x/ste:x%x flg:x%x",
  6100. did, vport->port_state, ndlp->nlp_flag);
  6101. phba->fc_stat.elsRcvPDISC++;
  6102. if (vport->port_state < LPFC_DISC_AUTH) {
  6103. rjt_err = LSRJT_UNABLE_TPC;
  6104. rjt_exp = LSEXP_NOTHING_MORE;
  6105. break;
  6106. }
  6107. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  6108. NLP_EVT_RCV_PDISC);
  6109. break;
  6110. case ELS_CMD_FARPR:
  6111. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6112. "RCV FARPR: did:x%x/ste:x%x flg:x%x",
  6113. did, vport->port_state, ndlp->nlp_flag);
  6114. phba->fc_stat.elsRcvFARPR++;
  6115. lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
  6116. break;
  6117. case ELS_CMD_FARP:
  6118. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6119. "RCV FARP: did:x%x/ste:x%x flg:x%x",
  6120. did, vport->port_state, ndlp->nlp_flag);
  6121. phba->fc_stat.elsRcvFARP++;
  6122. lpfc_els_rcv_farp(vport, elsiocb, ndlp);
  6123. break;
  6124. case ELS_CMD_FAN:
  6125. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6126. "RCV FAN: did:x%x/ste:x%x flg:x%x",
  6127. did, vport->port_state, ndlp->nlp_flag);
  6128. phba->fc_stat.elsRcvFAN++;
  6129. lpfc_els_rcv_fan(vport, elsiocb, ndlp);
  6130. break;
  6131. case ELS_CMD_PRLI:
  6132. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6133. "RCV PRLI: did:x%x/ste:x%x flg:x%x",
  6134. did, vport->port_state, ndlp->nlp_flag);
  6135. phba->fc_stat.elsRcvPRLI++;
  6136. if (vport->port_state < LPFC_DISC_AUTH) {
  6137. rjt_err = LSRJT_UNABLE_TPC;
  6138. rjt_exp = LSEXP_NOTHING_MORE;
  6139. break;
  6140. }
  6141. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  6142. break;
  6143. case ELS_CMD_LIRR:
  6144. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6145. "RCV LIRR: did:x%x/ste:x%x flg:x%x",
  6146. did, vport->port_state, ndlp->nlp_flag);
  6147. phba->fc_stat.elsRcvLIRR++;
  6148. lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
  6149. if (newnode)
  6150. lpfc_nlp_put(ndlp);
  6151. break;
  6152. case ELS_CMD_RLS:
  6153. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6154. "RCV RLS: did:x%x/ste:x%x flg:x%x",
  6155. did, vport->port_state, ndlp->nlp_flag);
  6156. phba->fc_stat.elsRcvRLS++;
  6157. lpfc_els_rcv_rls(vport, elsiocb, ndlp);
  6158. if (newnode)
  6159. lpfc_nlp_put(ndlp);
  6160. break;
  6161. case ELS_CMD_RPS:
  6162. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6163. "RCV RPS: did:x%x/ste:x%x flg:x%x",
  6164. did, vport->port_state, ndlp->nlp_flag);
  6165. phba->fc_stat.elsRcvRPS++;
  6166. lpfc_els_rcv_rps(vport, elsiocb, ndlp);
  6167. if (newnode)
  6168. lpfc_nlp_put(ndlp);
  6169. break;
  6170. case ELS_CMD_RPL:
  6171. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6172. "RCV RPL: did:x%x/ste:x%x flg:x%x",
  6173. did, vport->port_state, ndlp->nlp_flag);
  6174. phba->fc_stat.elsRcvRPL++;
  6175. lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
  6176. if (newnode)
  6177. lpfc_nlp_put(ndlp);
  6178. break;
  6179. case ELS_CMD_RNID:
  6180. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6181. "RCV RNID: did:x%x/ste:x%x flg:x%x",
  6182. did, vport->port_state, ndlp->nlp_flag);
  6183. phba->fc_stat.elsRcvRNID++;
  6184. lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
  6185. if (newnode)
  6186. lpfc_nlp_put(ndlp);
  6187. break;
  6188. case ELS_CMD_RTV:
  6189. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6190. "RCV RTV: did:x%x/ste:x%x flg:x%x",
  6191. did, vport->port_state, ndlp->nlp_flag);
  6192. phba->fc_stat.elsRcvRTV++;
  6193. lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
  6194. if (newnode)
  6195. lpfc_nlp_put(ndlp);
  6196. break;
  6197. case ELS_CMD_RRQ:
  6198. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6199. "RCV RRQ: did:x%x/ste:x%x flg:x%x",
  6200. did, vport->port_state, ndlp->nlp_flag);
  6201. phba->fc_stat.elsRcvRRQ++;
  6202. lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
  6203. if (newnode)
  6204. lpfc_nlp_put(ndlp);
  6205. break;
  6206. case ELS_CMD_ECHO:
  6207. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6208. "RCV ECHO: did:x%x/ste:x%x flg:x%x",
  6209. did, vport->port_state, ndlp->nlp_flag);
  6210. phba->fc_stat.elsRcvECHO++;
  6211. lpfc_els_rcv_echo(vport, elsiocb, ndlp);
  6212. if (newnode)
  6213. lpfc_nlp_put(ndlp);
  6214. break;
  6215. case ELS_CMD_REC:
  6216. /* receive this due to exchange closed */
  6217. rjt_err = LSRJT_UNABLE_TPC;
  6218. rjt_exp = LSEXP_INVALID_OX_RX;
  6219. break;
  6220. default:
  6221. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6222. "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
  6223. cmd, did, vport->port_state);
  6224. /* Unsupported ELS command, reject */
  6225. rjt_err = LSRJT_CMD_UNSUPPORTED;
  6226. rjt_exp = LSEXP_NOTHING_MORE;
  6227. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  6228. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6229. "0115 Unknown ELS command x%x "
  6230. "received from NPORT x%x\n", cmd, did);
  6231. if (newnode)
  6232. lpfc_nlp_put(ndlp);
  6233. break;
  6234. }
  6235. /* check if need to LS_RJT received ELS cmd */
  6236. if (rjt_err) {
  6237. memset(&stat, 0, sizeof(stat));
  6238. stat.un.b.lsRjtRsnCode = rjt_err;
  6239. stat.un.b.lsRjtRsnCodeExp = rjt_exp;
  6240. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
  6241. NULL);
  6242. }
  6243. lpfc_nlp_put(elsiocb->context1);
  6244. elsiocb->context1 = NULL;
  6245. return;
  6246. dropit:
  6247. if (vport && !(vport->load_flag & FC_UNLOADING))
  6248. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6249. "0111 Dropping received ELS cmd "
  6250. "Data: x%x x%x x%x\n",
  6251. icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
  6252. phba->fc_stat.elsRcvDrop++;
  6253. }
  6254. /**
  6255. * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
  6256. * @phba: pointer to lpfc hba data structure.
  6257. * @pring: pointer to a SLI ring.
  6258. * @elsiocb: pointer to lpfc els iocb data structure.
  6259. *
  6260. * This routine is used to process an unsolicited event received from a SLI
  6261. * (Service Level Interface) ring. The actual processing of the data buffer
  6262. * associated with the unsolicited event is done by invoking the routine
  6263. * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
  6264. * SLI ring on which the unsolicited event was received.
  6265. **/
  6266. void
  6267. lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6268. struct lpfc_iocbq *elsiocb)
  6269. {
  6270. struct lpfc_vport *vport = phba->pport;
  6271. IOCB_t *icmd = &elsiocb->iocb;
  6272. dma_addr_t paddr;
  6273. struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
  6274. struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
  6275. elsiocb->context1 = NULL;
  6276. elsiocb->context2 = NULL;
  6277. elsiocb->context3 = NULL;
  6278. if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
  6279. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  6280. } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
  6281. (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  6282. IOERR_RCV_BUFFER_WAITING) {
  6283. phba->fc_stat.NoRcvBuf++;
  6284. /* Not enough posted buffers; Try posting more buffers */
  6285. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  6286. lpfc_post_buffer(phba, pring, 0);
  6287. return;
  6288. }
  6289. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  6290. (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
  6291. icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  6292. if (icmd->unsli3.rcvsli3.vpi == 0xffff)
  6293. vport = phba->pport;
  6294. else
  6295. vport = lpfc_find_vport_by_vpid(phba,
  6296. icmd->unsli3.rcvsli3.vpi);
  6297. }
  6298. /* If there are no BDEs associated
  6299. * with this IOCB, there is nothing to do.
  6300. */
  6301. if (icmd->ulpBdeCount == 0)
  6302. return;
  6303. /* type of ELS cmd is first 32bit word
  6304. * in packet
  6305. */
  6306. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  6307. elsiocb->context2 = bdeBuf1;
  6308. } else {
  6309. paddr = getPaddr(icmd->un.cont64[0].addrHigh,
  6310. icmd->un.cont64[0].addrLow);
  6311. elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
  6312. paddr);
  6313. }
  6314. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  6315. /*
  6316. * The different unsolicited event handlers would tell us
  6317. * if they are done with "mp" by setting context2 to NULL.
  6318. */
  6319. if (elsiocb->context2) {
  6320. lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
  6321. elsiocb->context2 = NULL;
  6322. }
  6323. /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
  6324. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
  6325. icmd->ulpBdeCount == 2) {
  6326. elsiocb->context2 = bdeBuf2;
  6327. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  6328. /* free mp if we are done with it */
  6329. if (elsiocb->context2) {
  6330. lpfc_in_buf_free(phba, elsiocb->context2);
  6331. elsiocb->context2 = NULL;
  6332. }
  6333. }
  6334. }
  6335. /**
  6336. * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
  6337. * @phba: pointer to lpfc hba data structure.
  6338. * @vport: pointer to a virtual N_Port data structure.
  6339. *
  6340. * This routine issues a Port Login (PLOGI) to the Name Server with
  6341. * State Change Request (SCR) for a @vport. This routine will create an
  6342. * ndlp for the Name Server associated to the @vport if such node does
  6343. * not already exist. The PLOGI to Name Server is issued by invoking the
  6344. * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
  6345. * (FDMI) is configured to the @vport, a FDMI node will be created and
  6346. * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
  6347. **/
  6348. void
  6349. lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  6350. {
  6351. struct lpfc_nodelist *ndlp, *ndlp_fdmi;
  6352. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6353. /*
  6354. * If lpfc_delay_discovery parameter is set and the clean address
  6355. * bit is cleared and fc fabric parameters chenged, delay FC NPort
  6356. * discovery.
  6357. */
  6358. spin_lock_irq(shost->host_lock);
  6359. if (vport->fc_flag & FC_DISC_DELAYED) {
  6360. spin_unlock_irq(shost->host_lock);
  6361. mod_timer(&vport->delayed_disc_tmo,
  6362. jiffies + HZ * phba->fc_ratov);
  6363. return;
  6364. }
  6365. spin_unlock_irq(shost->host_lock);
  6366. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  6367. if (!ndlp) {
  6368. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  6369. if (!ndlp) {
  6370. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  6371. lpfc_disc_start(vport);
  6372. return;
  6373. }
  6374. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6375. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6376. "0251 NameServer login: no memory\n");
  6377. return;
  6378. }
  6379. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  6380. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  6381. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  6382. if (!ndlp) {
  6383. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  6384. lpfc_disc_start(vport);
  6385. return;
  6386. }
  6387. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6388. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6389. "0348 NameServer login: node freed\n");
  6390. return;
  6391. }
  6392. }
  6393. ndlp->nlp_type |= NLP_FABRIC;
  6394. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  6395. if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
  6396. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6397. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6398. "0252 Cannot issue NameServer login\n");
  6399. return;
  6400. }
  6401. if (vport->cfg_fdmi_on) {
  6402. /* If this is the first time, allocate an ndlp and initialize
  6403. * it. Otherwise, make sure the node is enabled and then do the
  6404. * login.
  6405. */
  6406. ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
  6407. if (!ndlp_fdmi) {
  6408. ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
  6409. GFP_KERNEL);
  6410. if (ndlp_fdmi) {
  6411. lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
  6412. ndlp_fdmi->nlp_type |= NLP_FABRIC;
  6413. } else
  6414. return;
  6415. }
  6416. if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
  6417. ndlp_fdmi = lpfc_enable_node(vport,
  6418. ndlp_fdmi,
  6419. NLP_STE_NPR_NODE);
  6420. if (ndlp_fdmi) {
  6421. lpfc_nlp_set_state(vport, ndlp_fdmi,
  6422. NLP_STE_PLOGI_ISSUE);
  6423. lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
  6424. }
  6425. }
  6426. }
  6427. /**
  6428. * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
  6429. * @phba: pointer to lpfc hba data structure.
  6430. * @pmb: pointer to the driver internal queue element for mailbox command.
  6431. *
  6432. * This routine is the completion callback function to register new vport
  6433. * mailbox command. If the new vport mailbox command completes successfully,
  6434. * the fabric registration login shall be performed on physical port (the
  6435. * new vport created is actually a physical port, with VPI 0) or the port
  6436. * login to Name Server for State Change Request (SCR) will be performed
  6437. * on virtual port (real virtual port, with VPI greater than 0).
  6438. **/
  6439. static void
  6440. lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  6441. {
  6442. struct lpfc_vport *vport = pmb->vport;
  6443. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6444. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  6445. MAILBOX_t *mb = &pmb->u.mb;
  6446. int rc;
  6447. spin_lock_irq(shost->host_lock);
  6448. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  6449. spin_unlock_irq(shost->host_lock);
  6450. if (mb->mbxStatus) {
  6451. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  6452. "0915 Register VPI failed : Status: x%x"
  6453. " upd bit: x%x \n", mb->mbxStatus,
  6454. mb->un.varRegVpi.upd);
  6455. if (phba->sli_rev == LPFC_SLI_REV4 &&
  6456. mb->un.varRegVpi.upd)
  6457. goto mbox_err_exit ;
  6458. switch (mb->mbxStatus) {
  6459. case 0x11: /* unsupported feature */
  6460. case 0x9603: /* max_vpi exceeded */
  6461. case 0x9602: /* Link event since CLEAR_LA */
  6462. /* giving up on vport registration */
  6463. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6464. spin_lock_irq(shost->host_lock);
  6465. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  6466. spin_unlock_irq(shost->host_lock);
  6467. lpfc_can_disctmo(vport);
  6468. break;
  6469. /* If reg_vpi fail with invalid VPI status, re-init VPI */
  6470. case 0x20:
  6471. spin_lock_irq(shost->host_lock);
  6472. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  6473. spin_unlock_irq(shost->host_lock);
  6474. lpfc_init_vpi(phba, pmb, vport->vpi);
  6475. pmb->vport = vport;
  6476. pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
  6477. rc = lpfc_sli_issue_mbox(phba, pmb,
  6478. MBX_NOWAIT);
  6479. if (rc == MBX_NOT_FINISHED) {
  6480. lpfc_printf_vlog(vport,
  6481. KERN_ERR, LOG_MBOX,
  6482. "2732 Failed to issue INIT_VPI"
  6483. " mailbox command\n");
  6484. } else {
  6485. lpfc_nlp_put(ndlp);
  6486. return;
  6487. }
  6488. default:
  6489. /* Try to recover from this error */
  6490. if (phba->sli_rev == LPFC_SLI_REV4)
  6491. lpfc_sli4_unreg_all_rpis(vport);
  6492. lpfc_mbx_unreg_vpi(vport);
  6493. spin_lock_irq(shost->host_lock);
  6494. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  6495. spin_unlock_irq(shost->host_lock);
  6496. if (vport->port_type == LPFC_PHYSICAL_PORT
  6497. && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
  6498. lpfc_issue_init_vfi(vport);
  6499. else
  6500. lpfc_initial_fdisc(vport);
  6501. break;
  6502. }
  6503. } else {
  6504. spin_lock_irq(shost->host_lock);
  6505. vport->vpi_state |= LPFC_VPI_REGISTERED;
  6506. spin_unlock_irq(shost->host_lock);
  6507. if (vport == phba->pport) {
  6508. if (phba->sli_rev < LPFC_SLI_REV4)
  6509. lpfc_issue_fabric_reglogin(vport);
  6510. else {
  6511. /*
  6512. * If the physical port is instantiated using
  6513. * FDISC, do not start vport discovery.
  6514. */
  6515. if (vport->port_state != LPFC_FDISC)
  6516. lpfc_start_fdiscs(phba);
  6517. lpfc_do_scr_ns_plogi(phba, vport);
  6518. }
  6519. } else
  6520. lpfc_do_scr_ns_plogi(phba, vport);
  6521. }
  6522. mbox_err_exit:
  6523. /* Now, we decrement the ndlp reference count held for this
  6524. * callback function
  6525. */
  6526. lpfc_nlp_put(ndlp);
  6527. mempool_free(pmb, phba->mbox_mem_pool);
  6528. return;
  6529. }
  6530. /**
  6531. * lpfc_register_new_vport - Register a new vport with a HBA
  6532. * @phba: pointer to lpfc hba data structure.
  6533. * @vport: pointer to a host virtual N_Port data structure.
  6534. * @ndlp: pointer to a node-list data structure.
  6535. *
  6536. * This routine registers the @vport as a new virtual port with a HBA.
  6537. * It is done through a registering vpi mailbox command.
  6538. **/
  6539. void
  6540. lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
  6541. struct lpfc_nodelist *ndlp)
  6542. {
  6543. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6544. LPFC_MBOXQ_t *mbox;
  6545. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6546. if (mbox) {
  6547. lpfc_reg_vpi(vport, mbox);
  6548. mbox->vport = vport;
  6549. mbox->context2 = lpfc_nlp_get(ndlp);
  6550. mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
  6551. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  6552. == MBX_NOT_FINISHED) {
  6553. /* mailbox command not success, decrement ndlp
  6554. * reference count for this command
  6555. */
  6556. lpfc_nlp_put(ndlp);
  6557. mempool_free(mbox, phba->mbox_mem_pool);
  6558. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  6559. "0253 Register VPI: Can't send mbox\n");
  6560. goto mbox_err_exit;
  6561. }
  6562. } else {
  6563. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  6564. "0254 Register VPI: no memory\n");
  6565. goto mbox_err_exit;
  6566. }
  6567. return;
  6568. mbox_err_exit:
  6569. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6570. spin_lock_irq(shost->host_lock);
  6571. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  6572. spin_unlock_irq(shost->host_lock);
  6573. return;
  6574. }
  6575. /**
  6576. * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
  6577. * @phba: pointer to lpfc hba data structure.
  6578. *
  6579. * This routine cancels the retry delay timers to all the vports.
  6580. **/
  6581. void
  6582. lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
  6583. {
  6584. struct lpfc_vport **vports;
  6585. struct lpfc_nodelist *ndlp;
  6586. uint32_t link_state;
  6587. int i;
  6588. /* Treat this failure as linkdown for all vports */
  6589. link_state = phba->link_state;
  6590. lpfc_linkdown(phba);
  6591. phba->link_state = link_state;
  6592. vports = lpfc_create_vport_work_array(phba);
  6593. if (vports) {
  6594. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  6595. ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
  6596. if (ndlp)
  6597. lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
  6598. lpfc_els_flush_cmd(vports[i]);
  6599. }
  6600. lpfc_destroy_vport_work_array(phba, vports);
  6601. }
  6602. }
  6603. /**
  6604. * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
  6605. * @phba: pointer to lpfc hba data structure.
  6606. *
  6607. * This routine abort all pending discovery commands and
  6608. * start a timer to retry FLOGI for the physical port
  6609. * discovery.
  6610. **/
  6611. void
  6612. lpfc_retry_pport_discovery(struct lpfc_hba *phba)
  6613. {
  6614. struct lpfc_nodelist *ndlp;
  6615. struct Scsi_Host *shost;
  6616. /* Cancel the all vports retry delay retry timers */
  6617. lpfc_cancel_all_vport_retry_delay_timer(phba);
  6618. /* If fabric require FLOGI, then re-instantiate physical login */
  6619. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  6620. if (!ndlp)
  6621. return;
  6622. shost = lpfc_shost_from_vport(phba->pport);
  6623. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  6624. spin_lock_irq(shost->host_lock);
  6625. ndlp->nlp_flag |= NLP_DELAY_TMO;
  6626. spin_unlock_irq(shost->host_lock);
  6627. ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
  6628. phba->pport->port_state = LPFC_FLOGI;
  6629. return;
  6630. }
  6631. /**
  6632. * lpfc_fabric_login_reqd - Check if FLOGI required.
  6633. * @phba: pointer to lpfc hba data structure.
  6634. * @cmdiocb: pointer to FDISC command iocb.
  6635. * @rspiocb: pointer to FDISC response iocb.
  6636. *
  6637. * This routine checks if a FLOGI is reguired for FDISC
  6638. * to succeed.
  6639. **/
  6640. static int
  6641. lpfc_fabric_login_reqd(struct lpfc_hba *phba,
  6642. struct lpfc_iocbq *cmdiocb,
  6643. struct lpfc_iocbq *rspiocb)
  6644. {
  6645. if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
  6646. (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
  6647. return 0;
  6648. else
  6649. return 1;
  6650. }
  6651. /**
  6652. * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
  6653. * @phba: pointer to lpfc hba data structure.
  6654. * @cmdiocb: pointer to lpfc command iocb data structure.
  6655. * @rspiocb: pointer to lpfc response iocb data structure.
  6656. *
  6657. * This routine is the completion callback function to a Fabric Discover
  6658. * (FDISC) ELS command. Since all the FDISC ELS commands are issued
  6659. * single threaded, each FDISC completion callback function will reset
  6660. * the discovery timer for all vports such that the timers will not get
  6661. * unnecessary timeout. The function checks the FDISC IOCB status. If error
  6662. * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
  6663. * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
  6664. * assigned to the vport has been changed with the completion of the FDISC
  6665. * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
  6666. * are unregistered from the HBA, and then the lpfc_register_new_vport()
  6667. * routine is invoked to register new vport with the HBA. Otherwise, the
  6668. * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
  6669. * Server for State Change Request (SCR).
  6670. **/
  6671. static void
  6672. lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6673. struct lpfc_iocbq *rspiocb)
  6674. {
  6675. struct lpfc_vport *vport = cmdiocb->vport;
  6676. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6677. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  6678. struct lpfc_nodelist *np;
  6679. struct lpfc_nodelist *next_np;
  6680. IOCB_t *irsp = &rspiocb->iocb;
  6681. struct lpfc_iocbq *piocb;
  6682. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  6683. struct serv_parm *sp;
  6684. uint8_t fabric_param_changed;
  6685. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6686. "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
  6687. irsp->ulpStatus, irsp->un.ulpWord[4],
  6688. vport->fc_prevDID);
  6689. /* Since all FDISCs are being single threaded, we
  6690. * must reset the discovery timer for ALL vports
  6691. * waiting to send FDISC when one completes.
  6692. */
  6693. list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
  6694. lpfc_set_disctmo(piocb->vport);
  6695. }
  6696. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6697. "FDISC cmpl: status:x%x/x%x prevdid:x%x",
  6698. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
  6699. if (irsp->ulpStatus) {
  6700. if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
  6701. lpfc_retry_pport_discovery(phba);
  6702. goto out;
  6703. }
  6704. /* Check for retry */
  6705. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  6706. goto out;
  6707. /* FDISC failed */
  6708. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6709. "0126 FDISC failed. (x%x/x%x)\n",
  6710. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6711. goto fdisc_failed;
  6712. }
  6713. spin_lock_irq(shost->host_lock);
  6714. vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
  6715. vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
  6716. vport->fc_flag |= FC_FABRIC;
  6717. if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
  6718. vport->fc_flag |= FC_PUBLIC_LOOP;
  6719. spin_unlock_irq(shost->host_lock);
  6720. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  6721. lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
  6722. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  6723. sp = prsp->virt + sizeof(uint32_t);
  6724. fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
  6725. memcpy(&vport->fabric_portname, &sp->portName,
  6726. sizeof(struct lpfc_name));
  6727. memcpy(&vport->fabric_nodename, &sp->nodeName,
  6728. sizeof(struct lpfc_name));
  6729. if (fabric_param_changed &&
  6730. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  6731. /* If our NportID changed, we need to ensure all
  6732. * remaining NPORTs get unreg_login'ed so we can
  6733. * issue unreg_vpi.
  6734. */
  6735. list_for_each_entry_safe(np, next_np,
  6736. &vport->fc_nodes, nlp_listp) {
  6737. if (!NLP_CHK_NODE_ACT(ndlp) ||
  6738. (np->nlp_state != NLP_STE_NPR_NODE) ||
  6739. !(np->nlp_flag & NLP_NPR_ADISC))
  6740. continue;
  6741. spin_lock_irq(shost->host_lock);
  6742. np->nlp_flag &= ~NLP_NPR_ADISC;
  6743. spin_unlock_irq(shost->host_lock);
  6744. lpfc_unreg_rpi(vport, np);
  6745. }
  6746. lpfc_cleanup_pending_mbox(vport);
  6747. if (phba->sli_rev == LPFC_SLI_REV4)
  6748. lpfc_sli4_unreg_all_rpis(vport);
  6749. lpfc_mbx_unreg_vpi(vport);
  6750. spin_lock_irq(shost->host_lock);
  6751. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  6752. if (phba->sli_rev == LPFC_SLI_REV4)
  6753. vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  6754. else
  6755. vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
  6756. spin_unlock_irq(shost->host_lock);
  6757. } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
  6758. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  6759. /*
  6760. * Driver needs to re-reg VPI in order for f/w
  6761. * to update the MAC address.
  6762. */
  6763. lpfc_register_new_vport(phba, vport, ndlp);
  6764. goto out;
  6765. }
  6766. if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
  6767. lpfc_issue_init_vpi(vport);
  6768. else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  6769. lpfc_register_new_vport(phba, vport, ndlp);
  6770. else
  6771. lpfc_do_scr_ns_plogi(phba, vport);
  6772. goto out;
  6773. fdisc_failed:
  6774. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6775. /* Cancel discovery timer */
  6776. lpfc_can_disctmo(vport);
  6777. lpfc_nlp_put(ndlp);
  6778. out:
  6779. lpfc_els_free_iocb(phba, cmdiocb);
  6780. }
  6781. /**
  6782. * lpfc_issue_els_fdisc - Issue a fdisc iocb command
  6783. * @vport: pointer to a virtual N_Port data structure.
  6784. * @ndlp: pointer to a node-list data structure.
  6785. * @retry: number of retries to the command IOCB.
  6786. *
  6787. * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
  6788. * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
  6789. * routine to issue the IOCB, which makes sure only one outstanding fabric
  6790. * IOCB will be sent off HBA at any given time.
  6791. *
  6792. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  6793. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  6794. * will be stored into the context1 field of the IOCB for the completion
  6795. * callback function to the FDISC ELS command.
  6796. *
  6797. * Return code
  6798. * 0 - Successfully issued fdisc iocb command
  6799. * 1 - Failed to issue fdisc iocb command
  6800. **/
  6801. static int
  6802. lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  6803. uint8_t retry)
  6804. {
  6805. struct lpfc_hba *phba = vport->phba;
  6806. IOCB_t *icmd;
  6807. struct lpfc_iocbq *elsiocb;
  6808. struct serv_parm *sp;
  6809. uint8_t *pcmd;
  6810. uint16_t cmdsize;
  6811. int did = ndlp->nlp_DID;
  6812. int rc;
  6813. vport->port_state = LPFC_FDISC;
  6814. vport->fc_myDID = 0;
  6815. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  6816. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  6817. ELS_CMD_FDISC);
  6818. if (!elsiocb) {
  6819. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6820. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6821. "0255 Issue FDISC: no IOCB\n");
  6822. return 1;
  6823. }
  6824. icmd = &elsiocb->iocb;
  6825. icmd->un.elsreq64.myID = 0;
  6826. icmd->un.elsreq64.fl = 1;
  6827. /*
  6828. * SLI3 ports require a different context type value than SLI4.
  6829. * Catch SLI3 ports here and override the prep.
  6830. */
  6831. if (phba->sli_rev == LPFC_SLI_REV3) {
  6832. icmd->ulpCt_h = 1;
  6833. icmd->ulpCt_l = 0;
  6834. }
  6835. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  6836. *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
  6837. pcmd += sizeof(uint32_t); /* CSP Word 1 */
  6838. memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
  6839. sp = (struct serv_parm *) pcmd;
  6840. /* Setup CSPs accordingly for Fabric */
  6841. sp->cmn.e_d_tov = 0;
  6842. sp->cmn.w2.r_a_tov = 0;
  6843. sp->cmn.virtual_fabric_support = 0;
  6844. sp->cls1.classValid = 0;
  6845. sp->cls2.seqDelivery = 1;
  6846. sp->cls3.seqDelivery = 1;
  6847. pcmd += sizeof(uint32_t); /* CSP Word 2 */
  6848. pcmd += sizeof(uint32_t); /* CSP Word 3 */
  6849. pcmd += sizeof(uint32_t); /* CSP Word 4 */
  6850. pcmd += sizeof(uint32_t); /* Port Name */
  6851. memcpy(pcmd, &vport->fc_portname, 8);
  6852. pcmd += sizeof(uint32_t); /* Node Name */
  6853. pcmd += sizeof(uint32_t); /* Node Name */
  6854. memcpy(pcmd, &vport->fc_nodename, 8);
  6855. lpfc_set_disctmo(vport);
  6856. phba->fc_stat.elsXmitFDISC++;
  6857. elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
  6858. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6859. "Issue FDISC: did:x%x",
  6860. did, 0, 0);
  6861. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  6862. if (rc == IOCB_ERROR) {
  6863. lpfc_els_free_iocb(phba, elsiocb);
  6864. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6865. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6866. "0256 Issue FDISC: Cannot send IOCB\n");
  6867. return 1;
  6868. }
  6869. lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
  6870. return 0;
  6871. }
  6872. /**
  6873. * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
  6874. * @phba: pointer to lpfc hba data structure.
  6875. * @cmdiocb: pointer to lpfc command iocb data structure.
  6876. * @rspiocb: pointer to lpfc response iocb data structure.
  6877. *
  6878. * This routine is the completion callback function to the issuing of a LOGO
  6879. * ELS command off a vport. It frees the command IOCB and then decrement the
  6880. * reference count held on ndlp for this completion function, indicating that
  6881. * the reference to the ndlp is no long needed. Note that the
  6882. * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
  6883. * callback function and an additional explicit ndlp reference decrementation
  6884. * will trigger the actual release of the ndlp.
  6885. **/
  6886. static void
  6887. lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6888. struct lpfc_iocbq *rspiocb)
  6889. {
  6890. struct lpfc_vport *vport = cmdiocb->vport;
  6891. IOCB_t *irsp;
  6892. struct lpfc_nodelist *ndlp;
  6893. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6894. ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
  6895. irsp = &rspiocb->iocb;
  6896. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6897. "LOGO npiv cmpl: status:x%x/x%x did:x%x",
  6898. irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
  6899. lpfc_els_free_iocb(phba, cmdiocb);
  6900. vport->unreg_vpi_cmpl = VPORT_ERROR;
  6901. /* Trigger the release of the ndlp after logo */
  6902. lpfc_nlp_put(ndlp);
  6903. /* NPIV LOGO completes to NPort <nlp_DID> */
  6904. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6905. "2928 NPIV LOGO completes to NPort x%x "
  6906. "Data: x%x x%x x%x x%x\n",
  6907. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  6908. irsp->ulpTimeout, vport->num_disc_nodes);
  6909. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  6910. spin_lock_irq(shost->host_lock);
  6911. vport->fc_flag &= ~FC_FABRIC;
  6912. spin_unlock_irq(shost->host_lock);
  6913. }
  6914. }
  6915. /**
  6916. * lpfc_issue_els_npiv_logo - Issue a logo off a vport
  6917. * @vport: pointer to a virtual N_Port data structure.
  6918. * @ndlp: pointer to a node-list data structure.
  6919. *
  6920. * This routine issues a LOGO ELS command to an @ndlp off a @vport.
  6921. *
  6922. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  6923. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  6924. * will be stored into the context1 field of the IOCB for the completion
  6925. * callback function to the LOGO ELS command.
  6926. *
  6927. * Return codes
  6928. * 0 - Successfully issued logo off the @vport
  6929. * 1 - Failed to issue logo off the @vport
  6930. **/
  6931. int
  6932. lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  6933. {
  6934. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6935. struct lpfc_hba *phba = vport->phba;
  6936. IOCB_t *icmd;
  6937. struct lpfc_iocbq *elsiocb;
  6938. uint8_t *pcmd;
  6939. uint16_t cmdsize;
  6940. cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
  6941. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
  6942. ELS_CMD_LOGO);
  6943. if (!elsiocb)
  6944. return 1;
  6945. icmd = &elsiocb->iocb;
  6946. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  6947. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  6948. pcmd += sizeof(uint32_t);
  6949. /* Fill in LOGO payload */
  6950. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  6951. pcmd += sizeof(uint32_t);
  6952. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  6953. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6954. "Issue LOGO npiv did:x%x flg:x%x",
  6955. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  6956. elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
  6957. spin_lock_irq(shost->host_lock);
  6958. ndlp->nlp_flag |= NLP_LOGO_SND;
  6959. spin_unlock_irq(shost->host_lock);
  6960. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  6961. IOCB_ERROR) {
  6962. spin_lock_irq(shost->host_lock);
  6963. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  6964. spin_unlock_irq(shost->host_lock);
  6965. lpfc_els_free_iocb(phba, elsiocb);
  6966. return 1;
  6967. }
  6968. return 0;
  6969. }
  6970. /**
  6971. * lpfc_fabric_block_timeout - Handler function to the fabric block timer
  6972. * @ptr: holder for the timer function associated data.
  6973. *
  6974. * This routine is invoked by the fabric iocb block timer after
  6975. * timeout. It posts the fabric iocb block timeout event by setting the
  6976. * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
  6977. * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
  6978. * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
  6979. * posted event WORKER_FABRIC_BLOCK_TMO.
  6980. **/
  6981. void
  6982. lpfc_fabric_block_timeout(unsigned long ptr)
  6983. {
  6984. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  6985. unsigned long iflags;
  6986. uint32_t tmo_posted;
  6987. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  6988. tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
  6989. if (!tmo_posted)
  6990. phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
  6991. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  6992. if (!tmo_posted)
  6993. lpfc_worker_wake_up(phba);
  6994. return;
  6995. }
  6996. /**
  6997. * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
  6998. * @phba: pointer to lpfc hba data structure.
  6999. *
  7000. * This routine issues one fabric iocb from the driver internal list to
  7001. * the HBA. It first checks whether it's ready to issue one fabric iocb to
  7002. * the HBA (whether there is no outstanding fabric iocb). If so, it shall
  7003. * remove one pending fabric iocb from the driver internal list and invokes
  7004. * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
  7005. **/
  7006. static void
  7007. lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
  7008. {
  7009. struct lpfc_iocbq *iocb;
  7010. unsigned long iflags;
  7011. int ret;
  7012. IOCB_t *cmd;
  7013. repeat:
  7014. iocb = NULL;
  7015. spin_lock_irqsave(&phba->hbalock, iflags);
  7016. /* Post any pending iocb to the SLI layer */
  7017. if (atomic_read(&phba->fabric_iocb_count) == 0) {
  7018. list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
  7019. list);
  7020. if (iocb)
  7021. /* Increment fabric iocb count to hold the position */
  7022. atomic_inc(&phba->fabric_iocb_count);
  7023. }
  7024. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7025. if (iocb) {
  7026. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  7027. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  7028. iocb->iocb_flag |= LPFC_IO_FABRIC;
  7029. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  7030. "Fabric sched1: ste:x%x",
  7031. iocb->vport->port_state, 0, 0);
  7032. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
  7033. if (ret == IOCB_ERROR) {
  7034. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  7035. iocb->fabric_iocb_cmpl = NULL;
  7036. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  7037. cmd = &iocb->iocb;
  7038. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  7039. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  7040. iocb->iocb_cmpl(phba, iocb, iocb);
  7041. atomic_dec(&phba->fabric_iocb_count);
  7042. goto repeat;
  7043. }
  7044. }
  7045. return;
  7046. }
  7047. /**
  7048. * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
  7049. * @phba: pointer to lpfc hba data structure.
  7050. *
  7051. * This routine unblocks the issuing fabric iocb command. The function
  7052. * will clear the fabric iocb block bit and then invoke the routine
  7053. * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
  7054. * from the driver internal fabric iocb list.
  7055. **/
  7056. void
  7057. lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
  7058. {
  7059. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  7060. lpfc_resume_fabric_iocbs(phba);
  7061. return;
  7062. }
  7063. /**
  7064. * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
  7065. * @phba: pointer to lpfc hba data structure.
  7066. *
  7067. * This routine blocks the issuing fabric iocb for a specified amount of
  7068. * time (currently 100 ms). This is done by set the fabric iocb block bit
  7069. * and set up a timeout timer for 100ms. When the block bit is set, no more
  7070. * fabric iocb will be issued out of the HBA.
  7071. **/
  7072. static void
  7073. lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
  7074. {
  7075. int blocked;
  7076. blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  7077. /* Start a timer to unblock fabric iocbs after 100ms */
  7078. if (!blocked)
  7079. mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
  7080. return;
  7081. }
  7082. /**
  7083. * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
  7084. * @phba: pointer to lpfc hba data structure.
  7085. * @cmdiocb: pointer to lpfc command iocb data structure.
  7086. * @rspiocb: pointer to lpfc response iocb data structure.
  7087. *
  7088. * This routine is the callback function that is put to the fabric iocb's
  7089. * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
  7090. * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
  7091. * function first restores and invokes the original iocb's callback function
  7092. * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
  7093. * fabric bound iocb from the driver internal fabric iocb list onto the wire.
  7094. **/
  7095. static void
  7096. lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7097. struct lpfc_iocbq *rspiocb)
  7098. {
  7099. struct ls_rjt stat;
  7100. if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
  7101. BUG();
  7102. switch (rspiocb->iocb.ulpStatus) {
  7103. case IOSTAT_NPORT_RJT:
  7104. case IOSTAT_FABRIC_RJT:
  7105. if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  7106. lpfc_block_fabric_iocbs(phba);
  7107. }
  7108. break;
  7109. case IOSTAT_NPORT_BSY:
  7110. case IOSTAT_FABRIC_BSY:
  7111. lpfc_block_fabric_iocbs(phba);
  7112. break;
  7113. case IOSTAT_LS_RJT:
  7114. stat.un.lsRjtError =
  7115. be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
  7116. if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
  7117. (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
  7118. lpfc_block_fabric_iocbs(phba);
  7119. break;
  7120. }
  7121. if (atomic_read(&phba->fabric_iocb_count) == 0)
  7122. BUG();
  7123. cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
  7124. cmdiocb->fabric_iocb_cmpl = NULL;
  7125. cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
  7126. cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
  7127. atomic_dec(&phba->fabric_iocb_count);
  7128. if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
  7129. /* Post any pending iocbs to HBA */
  7130. lpfc_resume_fabric_iocbs(phba);
  7131. }
  7132. }
  7133. /**
  7134. * lpfc_issue_fabric_iocb - Issue a fabric iocb command
  7135. * @phba: pointer to lpfc hba data structure.
  7136. * @iocb: pointer to lpfc command iocb data structure.
  7137. *
  7138. * This routine is used as the top-level API for issuing a fabric iocb command
  7139. * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
  7140. * function makes sure that only one fabric bound iocb will be outstanding at
  7141. * any given time. As such, this function will first check to see whether there
  7142. * is already an outstanding fabric iocb on the wire. If so, it will put the
  7143. * newly issued iocb onto the driver internal fabric iocb list, waiting to be
  7144. * issued later. Otherwise, it will issue the iocb on the wire and update the
  7145. * fabric iocb count it indicate that there is one fabric iocb on the wire.
  7146. *
  7147. * Note, this implementation has a potential sending out fabric IOCBs out of
  7148. * order. The problem is caused by the construction of the "ready" boolen does
  7149. * not include the condition that the internal fabric IOCB list is empty. As
  7150. * such, it is possible a fabric IOCB issued by this routine might be "jump"
  7151. * ahead of the fabric IOCBs in the internal list.
  7152. *
  7153. * Return code
  7154. * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
  7155. * IOCB_ERROR - failed to issue fabric iocb
  7156. **/
  7157. static int
  7158. lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
  7159. {
  7160. unsigned long iflags;
  7161. int ready;
  7162. int ret;
  7163. if (atomic_read(&phba->fabric_iocb_count) > 1)
  7164. BUG();
  7165. spin_lock_irqsave(&phba->hbalock, iflags);
  7166. ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
  7167. !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  7168. if (ready)
  7169. /* Increment fabric iocb count to hold the position */
  7170. atomic_inc(&phba->fabric_iocb_count);
  7171. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7172. if (ready) {
  7173. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  7174. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  7175. iocb->iocb_flag |= LPFC_IO_FABRIC;
  7176. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  7177. "Fabric sched2: ste:x%x",
  7178. iocb->vport->port_state, 0, 0);
  7179. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
  7180. if (ret == IOCB_ERROR) {
  7181. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  7182. iocb->fabric_iocb_cmpl = NULL;
  7183. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  7184. atomic_dec(&phba->fabric_iocb_count);
  7185. }
  7186. } else {
  7187. spin_lock_irqsave(&phba->hbalock, iflags);
  7188. list_add_tail(&iocb->list, &phba->fabric_iocb_list);
  7189. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7190. ret = IOCB_SUCCESS;
  7191. }
  7192. return ret;
  7193. }
  7194. /**
  7195. * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
  7196. * @vport: pointer to a virtual N_Port data structure.
  7197. *
  7198. * This routine aborts all the IOCBs associated with a @vport from the
  7199. * driver internal fabric IOCB list. The list contains fabric IOCBs to be
  7200. * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
  7201. * list, removes each IOCB associated with the @vport off the list, set the
  7202. * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
  7203. * associated with the IOCB.
  7204. **/
  7205. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
  7206. {
  7207. LIST_HEAD(completions);
  7208. struct lpfc_hba *phba = vport->phba;
  7209. struct lpfc_iocbq *tmp_iocb, *piocb;
  7210. spin_lock_irq(&phba->hbalock);
  7211. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  7212. list) {
  7213. if (piocb->vport != vport)
  7214. continue;
  7215. list_move_tail(&piocb->list, &completions);
  7216. }
  7217. spin_unlock_irq(&phba->hbalock);
  7218. /* Cancel all the IOCBs from the completions list */
  7219. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7220. IOERR_SLI_ABORTED);
  7221. }
  7222. /**
  7223. * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
  7224. * @ndlp: pointer to a node-list data structure.
  7225. *
  7226. * This routine aborts all the IOCBs associated with an @ndlp from the
  7227. * driver internal fabric IOCB list. The list contains fabric IOCBs to be
  7228. * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
  7229. * list, removes each IOCB associated with the @ndlp off the list, set the
  7230. * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
  7231. * associated with the IOCB.
  7232. **/
  7233. void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
  7234. {
  7235. LIST_HEAD(completions);
  7236. struct lpfc_hba *phba = ndlp->phba;
  7237. struct lpfc_iocbq *tmp_iocb, *piocb;
  7238. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7239. spin_lock_irq(&phba->hbalock);
  7240. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  7241. list) {
  7242. if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
  7243. list_move_tail(&piocb->list, &completions);
  7244. }
  7245. }
  7246. spin_unlock_irq(&phba->hbalock);
  7247. /* Cancel all the IOCBs from the completions list */
  7248. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7249. IOERR_SLI_ABORTED);
  7250. }
  7251. /**
  7252. * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
  7253. * @phba: pointer to lpfc hba data structure.
  7254. *
  7255. * This routine aborts all the IOCBs currently on the driver internal
  7256. * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
  7257. * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
  7258. * list, removes IOCBs off the list, set the status feild to
  7259. * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
  7260. * the IOCB.
  7261. **/
  7262. void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
  7263. {
  7264. LIST_HEAD(completions);
  7265. spin_lock_irq(&phba->hbalock);
  7266. list_splice_init(&phba->fabric_iocb_list, &completions);
  7267. spin_unlock_irq(&phba->hbalock);
  7268. /* Cancel all the IOCBs from the completions list */
  7269. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7270. IOERR_SLI_ABORTED);
  7271. }
  7272. /**
  7273. * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
  7274. * @vport: pointer to lpfc vport data structure.
  7275. *
  7276. * This routine is invoked by the vport cleanup for deletions and the cleanup
  7277. * for an ndlp on removal.
  7278. **/
  7279. void
  7280. lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
  7281. {
  7282. struct lpfc_hba *phba = vport->phba;
  7283. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  7284. unsigned long iflag = 0;
  7285. spin_lock_irqsave(&phba->hbalock, iflag);
  7286. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  7287. list_for_each_entry_safe(sglq_entry, sglq_next,
  7288. &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
  7289. if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
  7290. sglq_entry->ndlp = NULL;
  7291. }
  7292. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  7293. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7294. return;
  7295. }
  7296. /**
  7297. * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
  7298. * @phba: pointer to lpfc hba data structure.
  7299. * @axri: pointer to the els xri abort wcqe structure.
  7300. *
  7301. * This routine is invoked by the worker thread to process a SLI4 slow-path
  7302. * ELS aborted xri.
  7303. **/
  7304. void
  7305. lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
  7306. struct sli4_wcqe_xri_aborted *axri)
  7307. {
  7308. uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
  7309. uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
  7310. uint16_t lxri = 0;
  7311. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  7312. unsigned long iflag = 0;
  7313. struct lpfc_nodelist *ndlp;
  7314. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7315. spin_lock_irqsave(&phba->hbalock, iflag);
  7316. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  7317. list_for_each_entry_safe(sglq_entry, sglq_next,
  7318. &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
  7319. if (sglq_entry->sli4_xritag == xri) {
  7320. list_del(&sglq_entry->list);
  7321. ndlp = sglq_entry->ndlp;
  7322. sglq_entry->ndlp = NULL;
  7323. list_add_tail(&sglq_entry->list,
  7324. &phba->sli4_hba.lpfc_sgl_list);
  7325. sglq_entry->state = SGL_FREED;
  7326. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  7327. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7328. lpfc_set_rrq_active(phba, ndlp,
  7329. sglq_entry->sli4_lxritag,
  7330. rxid, 1);
  7331. /* Check if TXQ queue needs to be serviced */
  7332. if (!(list_empty(&pring->txq)))
  7333. lpfc_worker_wake_up(phba);
  7334. return;
  7335. }
  7336. }
  7337. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  7338. lxri = lpfc_sli4_xri_inrange(phba, xri);
  7339. if (lxri == NO_XRI) {
  7340. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7341. return;
  7342. }
  7343. sglq_entry = __lpfc_get_active_sglq(phba, lxri);
  7344. if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
  7345. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7346. return;
  7347. }
  7348. sglq_entry->state = SGL_XRI_ABORTED;
  7349. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7350. return;
  7351. }
  7352. /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
  7353. * @vport: pointer to virtual port object.
  7354. * @ndlp: nodelist pointer for the impacted node.
  7355. *
  7356. * The driver calls this routine in response to an SLI4 XRI ABORT CQE
  7357. * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
  7358. * the driver is required to send a LOGO to the remote node before it
  7359. * attempts to recover its login to the remote node.
  7360. */
  7361. void
  7362. lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
  7363. struct lpfc_nodelist *ndlp)
  7364. {
  7365. struct Scsi_Host *shost;
  7366. struct lpfc_hba *phba;
  7367. unsigned long flags = 0;
  7368. shost = lpfc_shost_from_vport(vport);
  7369. phba = vport->phba;
  7370. if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
  7371. lpfc_printf_log(phba, KERN_INFO,
  7372. LOG_SLI, "3093 No rport recovery needed. "
  7373. "rport in state 0x%x\n", ndlp->nlp_state);
  7374. return;
  7375. }
  7376. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7377. "3094 Start rport recovery on shost id 0x%x "
  7378. "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
  7379. "flags 0x%x\n",
  7380. shost->host_no, ndlp->nlp_DID,
  7381. vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
  7382. ndlp->nlp_flag);
  7383. /*
  7384. * The rport is not responding. Remove the FCP-2 flag to prevent
  7385. * an ADISC in the follow-up recovery code.
  7386. */
  7387. spin_lock_irqsave(shost->host_lock, flags);
  7388. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  7389. spin_unlock_irqrestore(shost->host_lock, flags);
  7390. lpfc_issue_els_logo(vport, ndlp, 0);
  7391. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  7392. }