lpfc_els.c 206 KB

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