lpfc_els.c 247 KB

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