lpfc_els.c 223 KB

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