lpfc_els.c 242 KB

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