lpfc_els.c 213 KB

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