lpfc_els.c 248 KB

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