lpfc_els.c 219 KB

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