lpfc_els.c 280 KB

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