lpfc_els.c 301 KB

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