lpfc_els.c 211 KB

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