lpfc_els.c 262 KB

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