bfa_fcs_lport.c 177 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989
  1. /*
  2. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include "bfad_drv.h"
  18. #include "bfad_im.h"
  19. #include "bfa_fcs.h"
  20. #include "bfa_fcbuild.h"
  21. #include "bfa_fc.h"
  22. BFA_TRC_FILE(FCS, PORT);
  23. /*
  24. * ALPA to LIXA bitmap mapping
  25. *
  26. * ALPA 0x00 (Word 0, Bit 30) is invalid for N_Ports. Also Word 0 Bit 31
  27. * is for L_bit (login required) and is filled as ALPA 0x00 here.
  28. */
  29. static const u8 loop_alpa_map[] = {
  30. 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x0F, 0x10, /* Word 0 Bits 31..24 */
  31. 0x17, 0x18, 0x1B, 0x1D, 0x1E, 0x1F, 0x23, 0x25, /* Word 0 Bits 23..16 */
  32. 0x26, 0x27, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, /* Word 0 Bits 15..08 */
  33. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x39, 0x3A, /* Word 0 Bits 07..00 */
  34. 0x3C, 0x43, 0x45, 0x46, 0x47, 0x49, 0x4A, 0x4B, /* Word 1 Bits 31..24 */
  35. 0x4C, 0x4D, 0x4E, 0x51, 0x52, 0x53, 0x54, 0x55, /* Word 1 Bits 23..16 */
  36. 0x56, 0x59, 0x5A, 0x5C, 0x63, 0x65, 0x66, 0x67, /* Word 1 Bits 15..08 */
  37. 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x71, 0x72, /* Word 1 Bits 07..00 */
  38. 0x73, 0x74, 0x75, 0x76, 0x79, 0x7A, 0x7C, 0x80, /* Word 2 Bits 31..24 */
  39. 0x81, 0x82, 0x84, 0x88, 0x8F, 0x90, 0x97, 0x98, /* Word 2 Bits 23..16 */
  40. 0x9B, 0x9D, 0x9E, 0x9F, 0xA3, 0xA5, 0xA6, 0xA7, /* Word 2 Bits 15..08 */
  41. 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xB1, 0xB2, /* Word 2 Bits 07..00 */
  42. 0xB3, 0xB4, 0xB5, 0xB6, 0xB9, 0xBA, 0xBC, 0xC3, /* Word 3 Bits 31..24 */
  43. 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, /* Word 3 Bits 23..16 */
  44. 0xCE, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD9, /* Word 3 Bits 15..08 */
  45. 0xDA, 0xDC, 0xE0, 0xE1, 0xE2, 0xE4, 0xE8, 0xEF, /* Word 3 Bits 07..00 */
  46. };
  47. static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port,
  48. struct fchs_s *rx_fchs, u8 reason_code,
  49. u8 reason_code_expl);
  50. static void bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
  51. struct fchs_s *rx_fchs, struct fc_logi_s *plogi);
  52. static void bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port);
  53. static void bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port);
  54. static void bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port);
  55. static void bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port);
  56. static void bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port);
  57. static void bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port);
  58. static void bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port,
  59. struct fchs_s *rx_fchs,
  60. struct fc_echo_s *echo, u16 len);
  61. static void bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port,
  62. struct fchs_s *rx_fchs,
  63. struct fc_rnid_cmd_s *rnid, u16 len);
  64. static void bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
  65. struct fc_rnid_general_topology_data_s *gen_topo_data);
  66. static void bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port);
  67. static void bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port);
  68. static void bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port);
  69. static void bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port);
  70. static void bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port);
  71. static void bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port);
  72. static void bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port);
  73. static void bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port);
  74. static void bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port);
  75. static struct {
  76. void (*init) (struct bfa_fcs_lport_s *port);
  77. void (*online) (struct bfa_fcs_lport_s *port);
  78. void (*offline) (struct bfa_fcs_lport_s *port);
  79. } __port_action[] = {
  80. {
  81. bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
  82. bfa_fcs_lport_unknown_offline}, {
  83. bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
  84. bfa_fcs_lport_fab_offline}, {
  85. bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
  86. bfa_fcs_lport_n2n_offline}, {
  87. bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
  88. bfa_fcs_lport_loop_offline},
  89. };
  90. /*
  91. * fcs_port_sm FCS logical port state machine
  92. */
  93. enum bfa_fcs_lport_event {
  94. BFA_FCS_PORT_SM_CREATE = 1,
  95. BFA_FCS_PORT_SM_ONLINE = 2,
  96. BFA_FCS_PORT_SM_OFFLINE = 3,
  97. BFA_FCS_PORT_SM_DELETE = 4,
  98. BFA_FCS_PORT_SM_DELRPORT = 5,
  99. BFA_FCS_PORT_SM_STOP = 6,
  100. };
  101. static void bfa_fcs_lport_sm_uninit(struct bfa_fcs_lport_s *port,
  102. enum bfa_fcs_lport_event event);
  103. static void bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
  104. enum bfa_fcs_lport_event event);
  105. static void bfa_fcs_lport_sm_online(struct bfa_fcs_lport_s *port,
  106. enum bfa_fcs_lport_event event);
  107. static void bfa_fcs_lport_sm_offline(struct bfa_fcs_lport_s *port,
  108. enum bfa_fcs_lport_event event);
  109. static void bfa_fcs_lport_sm_deleting(struct bfa_fcs_lport_s *port,
  110. enum bfa_fcs_lport_event event);
  111. static void bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
  112. enum bfa_fcs_lport_event event);
  113. static void
  114. bfa_fcs_lport_sm_uninit(
  115. struct bfa_fcs_lport_s *port,
  116. enum bfa_fcs_lport_event event)
  117. {
  118. bfa_trc(port->fcs, port->port_cfg.pwwn);
  119. bfa_trc(port->fcs, event);
  120. switch (event) {
  121. case BFA_FCS_PORT_SM_CREATE:
  122. bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
  123. break;
  124. default:
  125. bfa_sm_fault(port->fcs, event);
  126. }
  127. }
  128. static void
  129. bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
  130. enum bfa_fcs_lport_event event)
  131. {
  132. bfa_trc(port->fcs, port->port_cfg.pwwn);
  133. bfa_trc(port->fcs, event);
  134. switch (event) {
  135. case BFA_FCS_PORT_SM_ONLINE:
  136. bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
  137. bfa_fcs_lport_online_actions(port);
  138. break;
  139. case BFA_FCS_PORT_SM_DELETE:
  140. bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
  141. bfa_fcs_lport_deleted(port);
  142. break;
  143. case BFA_FCS_PORT_SM_STOP:
  144. /* If vport - send completion call back */
  145. if (port->vport)
  146. bfa_fcs_vport_stop_comp(port->vport);
  147. else
  148. bfa_wc_down(&(port->fabric->stop_wc));
  149. break;
  150. case BFA_FCS_PORT_SM_OFFLINE:
  151. break;
  152. default:
  153. bfa_sm_fault(port->fcs, event);
  154. }
  155. }
  156. static void
  157. bfa_fcs_lport_sm_online(
  158. struct bfa_fcs_lport_s *port,
  159. enum bfa_fcs_lport_event event)
  160. {
  161. struct bfa_fcs_rport_s *rport;
  162. struct list_head *qe, *qen;
  163. bfa_trc(port->fcs, port->port_cfg.pwwn);
  164. bfa_trc(port->fcs, event);
  165. switch (event) {
  166. case BFA_FCS_PORT_SM_OFFLINE:
  167. bfa_sm_set_state(port, bfa_fcs_lport_sm_offline);
  168. bfa_fcs_lport_offline_actions(port);
  169. break;
  170. case BFA_FCS_PORT_SM_STOP:
  171. __port_action[port->fabric->fab_type].offline(port);
  172. if (port->num_rports == 0) {
  173. bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
  174. /* If vport - send completion call back */
  175. if (port->vport)
  176. bfa_fcs_vport_stop_comp(port->vport);
  177. else
  178. bfa_wc_down(&(port->fabric->stop_wc));
  179. } else {
  180. bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
  181. list_for_each_safe(qe, qen, &port->rport_q) {
  182. rport = (struct bfa_fcs_rport_s *) qe;
  183. bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
  184. }
  185. }
  186. break;
  187. case BFA_FCS_PORT_SM_DELETE:
  188. __port_action[port->fabric->fab_type].offline(port);
  189. if (port->num_rports == 0) {
  190. bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
  191. bfa_fcs_lport_deleted(port);
  192. } else {
  193. bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
  194. list_for_each_safe(qe, qen, &port->rport_q) {
  195. rport = (struct bfa_fcs_rport_s *) qe;
  196. bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
  197. }
  198. }
  199. break;
  200. case BFA_FCS_PORT_SM_DELRPORT:
  201. break;
  202. default:
  203. bfa_sm_fault(port->fcs, event);
  204. }
  205. }
  206. static void
  207. bfa_fcs_lport_sm_offline(
  208. struct bfa_fcs_lport_s *port,
  209. enum bfa_fcs_lport_event event)
  210. {
  211. struct bfa_fcs_rport_s *rport;
  212. struct list_head *qe, *qen;
  213. bfa_trc(port->fcs, port->port_cfg.pwwn);
  214. bfa_trc(port->fcs, event);
  215. switch (event) {
  216. case BFA_FCS_PORT_SM_ONLINE:
  217. bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
  218. bfa_fcs_lport_online_actions(port);
  219. break;
  220. case BFA_FCS_PORT_SM_STOP:
  221. if (port->num_rports == 0) {
  222. bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
  223. /* If vport - send completion call back */
  224. if (port->vport)
  225. bfa_fcs_vport_stop_comp(port->vport);
  226. else
  227. bfa_wc_down(&(port->fabric->stop_wc));
  228. } else {
  229. bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
  230. list_for_each_safe(qe, qen, &port->rport_q) {
  231. rport = (struct bfa_fcs_rport_s *) qe;
  232. bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
  233. }
  234. }
  235. break;
  236. case BFA_FCS_PORT_SM_DELETE:
  237. if (port->num_rports == 0) {
  238. bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
  239. bfa_fcs_lport_deleted(port);
  240. } else {
  241. bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
  242. list_for_each_safe(qe, qen, &port->rport_q) {
  243. rport = (struct bfa_fcs_rport_s *) qe;
  244. bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
  245. }
  246. }
  247. break;
  248. case BFA_FCS_PORT_SM_DELRPORT:
  249. case BFA_FCS_PORT_SM_OFFLINE:
  250. break;
  251. default:
  252. bfa_sm_fault(port->fcs, event);
  253. }
  254. }
  255. static void
  256. bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
  257. enum bfa_fcs_lport_event event)
  258. {
  259. bfa_trc(port->fcs, port->port_cfg.pwwn);
  260. bfa_trc(port->fcs, event);
  261. switch (event) {
  262. case BFA_FCS_PORT_SM_DELRPORT:
  263. if (port->num_rports == 0) {
  264. bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
  265. /* If vport - send completion call back */
  266. if (port->vport)
  267. bfa_fcs_vport_stop_comp(port->vport);
  268. else
  269. bfa_wc_down(&(port->fabric->stop_wc));
  270. }
  271. break;
  272. default:
  273. bfa_sm_fault(port->fcs, event);
  274. }
  275. }
  276. static void
  277. bfa_fcs_lport_sm_deleting(
  278. struct bfa_fcs_lport_s *port,
  279. enum bfa_fcs_lport_event event)
  280. {
  281. bfa_trc(port->fcs, port->port_cfg.pwwn);
  282. bfa_trc(port->fcs, event);
  283. switch (event) {
  284. case BFA_FCS_PORT_SM_DELRPORT:
  285. if (port->num_rports == 0) {
  286. bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
  287. bfa_fcs_lport_deleted(port);
  288. }
  289. break;
  290. default:
  291. bfa_sm_fault(port->fcs, event);
  292. }
  293. }
  294. /*
  295. * fcs_port_pvt
  296. */
  297. /*
  298. * Send AEN notification
  299. */
  300. static void
  301. bfa_fcs_lport_aen_post(struct bfa_fcs_lport_s *port,
  302. enum bfa_lport_aen_event event)
  303. {
  304. struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
  305. struct bfa_aen_entry_s *aen_entry;
  306. bfad_get_aen_entry(bfad, aen_entry);
  307. if (!aen_entry)
  308. return;
  309. aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
  310. aen_entry->aen_data.lport.roles = port->port_cfg.roles;
  311. aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
  312. bfa_fcs_get_base_port(port->fcs));
  313. aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
  314. /* Send the AEN notification */
  315. bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
  316. BFA_AEN_CAT_LPORT, event);
  317. }
  318. /*
  319. * Send a LS reject
  320. */
  321. static void
  322. bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
  323. u8 reason_code, u8 reason_code_expl)
  324. {
  325. struct fchs_s fchs;
  326. struct bfa_fcxp_s *fcxp;
  327. struct bfa_rport_s *bfa_rport = NULL;
  328. int len;
  329. bfa_trc(port->fcs, rx_fchs->d_id);
  330. bfa_trc(port->fcs, rx_fchs->s_id);
  331. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  332. if (!fcxp)
  333. return;
  334. len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  335. rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  336. rx_fchs->ox_id, reason_code, reason_code_expl);
  337. bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
  338. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  339. FC_MAX_PDUSZ, 0);
  340. }
  341. /*
  342. * Send a FCCT Reject
  343. */
  344. static void
  345. bfa_fcs_lport_send_fcgs_rjt(struct bfa_fcs_lport_s *port,
  346. struct fchs_s *rx_fchs, u8 reason_code, u8 reason_code_expl)
  347. {
  348. struct fchs_s fchs;
  349. struct bfa_fcxp_s *fcxp;
  350. struct bfa_rport_s *bfa_rport = NULL;
  351. int len;
  352. struct ct_hdr_s *rx_cthdr = (struct ct_hdr_s *)(rx_fchs + 1);
  353. struct ct_hdr_s *ct_hdr;
  354. bfa_trc(port->fcs, rx_fchs->d_id);
  355. bfa_trc(port->fcs, rx_fchs->s_id);
  356. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  357. if (!fcxp)
  358. return;
  359. ct_hdr = bfa_fcxp_get_reqbuf(fcxp);
  360. ct_hdr->gs_type = rx_cthdr->gs_type;
  361. ct_hdr->gs_sub_type = rx_cthdr->gs_sub_type;
  362. len = fc_gs_rjt_build(&fchs, ct_hdr, rx_fchs->s_id,
  363. bfa_fcs_lport_get_fcid(port),
  364. rx_fchs->ox_id, reason_code, reason_code_expl);
  365. bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
  366. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  367. FC_MAX_PDUSZ, 0);
  368. }
  369. /*
  370. * Process incoming plogi from a remote port.
  371. */
  372. static void
  373. bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
  374. struct fchs_s *rx_fchs, struct fc_logi_s *plogi)
  375. {
  376. struct bfa_fcs_rport_s *rport;
  377. bfa_trc(port->fcs, rx_fchs->d_id);
  378. bfa_trc(port->fcs, rx_fchs->s_id);
  379. /*
  380. * If min cfg mode is enabled, drop any incoming PLOGIs
  381. */
  382. if (__fcs_min_cfg(port->fcs)) {
  383. bfa_trc(port->fcs, rx_fchs->s_id);
  384. return;
  385. }
  386. if (fc_plogi_parse(rx_fchs) != FC_PARSE_OK) {
  387. bfa_trc(port->fcs, rx_fchs->s_id);
  388. /*
  389. * send a LS reject
  390. */
  391. bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
  392. FC_LS_RJT_RSN_PROTOCOL_ERROR,
  393. FC_LS_RJT_EXP_SPARMS_ERR_OPTIONS);
  394. return;
  395. }
  396. /*
  397. * Direct Attach P2P mode : verify address assigned by the r-port.
  398. */
  399. if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
  400. (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
  401. (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
  402. if (BFA_FCS_PID_IS_WKA(rx_fchs->d_id)) {
  403. /* Address assigned to us cannot be a WKA */
  404. bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
  405. FC_LS_RJT_RSN_PROTOCOL_ERROR,
  406. FC_LS_RJT_EXP_INVALID_NPORT_ID);
  407. return;
  408. }
  409. port->pid = rx_fchs->d_id;
  410. bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
  411. }
  412. /*
  413. * First, check if we know the device by pwwn.
  414. */
  415. rport = bfa_fcs_lport_get_rport_by_pwwn(port, plogi->port_name);
  416. if (rport) {
  417. /*
  418. * Direct Attach P2P mode : handle address assigned by r-port.
  419. */
  420. if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
  421. (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
  422. (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
  423. port->pid = rx_fchs->d_id;
  424. bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
  425. rport->pid = rx_fchs->s_id;
  426. }
  427. bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
  428. return;
  429. }
  430. /*
  431. * Next, lookup rport by PID.
  432. */
  433. rport = bfa_fcs_lport_get_rport_by_pid(port, rx_fchs->s_id);
  434. if (!rport) {
  435. /*
  436. * Inbound PLOGI from a new device.
  437. */
  438. bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
  439. return;
  440. }
  441. /*
  442. * Rport is known only by PID.
  443. */
  444. if (rport->pwwn) {
  445. /*
  446. * This is a different device with the same pid. Old device
  447. * disappeared. Send implicit LOGO to old device.
  448. */
  449. WARN_ON(rport->pwwn == plogi->port_name);
  450. bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
  451. /*
  452. * Inbound PLOGI from a new device (with old PID).
  453. */
  454. bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
  455. return;
  456. }
  457. /*
  458. * PLOGI crossing each other.
  459. */
  460. WARN_ON(rport->pwwn != WWN_NULL);
  461. bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
  462. }
  463. /*
  464. * Process incoming ECHO.
  465. * Since it does not require a login, it is processed here.
  466. */
  467. static void
  468. bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
  469. struct fc_echo_s *echo, u16 rx_len)
  470. {
  471. struct fchs_s fchs;
  472. struct bfa_fcxp_s *fcxp;
  473. struct bfa_rport_s *bfa_rport = NULL;
  474. int len, pyld_len;
  475. bfa_trc(port->fcs, rx_fchs->s_id);
  476. bfa_trc(port->fcs, rx_fchs->d_id);
  477. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  478. if (!fcxp)
  479. return;
  480. len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  481. rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  482. rx_fchs->ox_id);
  483. /*
  484. * Copy the payload (if any) from the echo frame
  485. */
  486. pyld_len = rx_len - sizeof(struct fchs_s);
  487. bfa_trc(port->fcs, rx_len);
  488. bfa_trc(port->fcs, pyld_len);
  489. if (pyld_len > len)
  490. memcpy(((u8 *) bfa_fcxp_get_reqbuf(fcxp)) +
  491. sizeof(struct fc_echo_s), (echo + 1),
  492. (pyld_len - sizeof(struct fc_echo_s)));
  493. bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
  494. BFA_FALSE, FC_CLASS_3, pyld_len, &fchs, NULL, NULL,
  495. FC_MAX_PDUSZ, 0);
  496. }
  497. /*
  498. * Process incoming RNID.
  499. * Since it does not require a login, it is processed here.
  500. */
  501. static void
  502. bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
  503. struct fc_rnid_cmd_s *rnid, u16 rx_len)
  504. {
  505. struct fc_rnid_common_id_data_s common_id_data;
  506. struct fc_rnid_general_topology_data_s gen_topo_data;
  507. struct fchs_s fchs;
  508. struct bfa_fcxp_s *fcxp;
  509. struct bfa_rport_s *bfa_rport = NULL;
  510. u16 len;
  511. u32 data_format;
  512. bfa_trc(port->fcs, rx_fchs->s_id);
  513. bfa_trc(port->fcs, rx_fchs->d_id);
  514. bfa_trc(port->fcs, rx_len);
  515. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  516. if (!fcxp)
  517. return;
  518. /*
  519. * Check Node Indentification Data Format
  520. * We only support General Topology Discovery Format.
  521. * For any other requested Data Formats, we return Common Node Id Data
  522. * only, as per FC-LS.
  523. */
  524. bfa_trc(port->fcs, rnid->node_id_data_format);
  525. if (rnid->node_id_data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
  526. data_format = RNID_NODEID_DATA_FORMAT_DISCOVERY;
  527. /*
  528. * Get General topology data for this port
  529. */
  530. bfa_fs_port_get_gen_topo_data(port, &gen_topo_data);
  531. } else {
  532. data_format = RNID_NODEID_DATA_FORMAT_COMMON;
  533. }
  534. /*
  535. * Copy the Node Id Info
  536. */
  537. common_id_data.port_name = bfa_fcs_lport_get_pwwn(port);
  538. common_id_data.node_name = bfa_fcs_lport_get_nwwn(port);
  539. len = fc_rnid_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  540. rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  541. rx_fchs->ox_id, data_format, &common_id_data,
  542. &gen_topo_data);
  543. bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
  544. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  545. FC_MAX_PDUSZ, 0);
  546. }
  547. /*
  548. * Fill out General Topolpgy Discovery Data for RNID ELS.
  549. */
  550. static void
  551. bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
  552. struct fc_rnid_general_topology_data_s *gen_topo_data)
  553. {
  554. memset(gen_topo_data, 0,
  555. sizeof(struct fc_rnid_general_topology_data_s));
  556. gen_topo_data->asso_type = cpu_to_be32(RNID_ASSOCIATED_TYPE_HOST);
  557. gen_topo_data->phy_port_num = 0; /* @todo */
  558. gen_topo_data->num_attached_nodes = cpu_to_be32(1);
  559. }
  560. static void
  561. bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port)
  562. {
  563. struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  564. char lpwwn_buf[BFA_STRING_32];
  565. bfa_trc(port->fcs, port->fabric->oper_type);
  566. __port_action[port->fabric->fab_type].init(port);
  567. __port_action[port->fabric->fab_type].online(port);
  568. wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
  569. BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
  570. "Logical port online: WWN = %s Role = %s\n",
  571. lpwwn_buf, "Initiator");
  572. bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_ONLINE);
  573. bfad->bfad_flags |= BFAD_PORT_ONLINE;
  574. }
  575. static void
  576. bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port)
  577. {
  578. struct list_head *qe, *qen;
  579. struct bfa_fcs_rport_s *rport;
  580. struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  581. char lpwwn_buf[BFA_STRING_32];
  582. bfa_trc(port->fcs, port->fabric->oper_type);
  583. __port_action[port->fabric->fab_type].offline(port);
  584. wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
  585. if (bfa_sm_cmp_state(port->fabric,
  586. bfa_fcs_fabric_sm_online) == BFA_TRUE) {
  587. BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
  588. "Logical port lost fabric connectivity: WWN = %s Role = %s\n",
  589. lpwwn_buf, "Initiator");
  590. bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DISCONNECT);
  591. } else {
  592. BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
  593. "Logical port taken offline: WWN = %s Role = %s\n",
  594. lpwwn_buf, "Initiator");
  595. bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_OFFLINE);
  596. }
  597. list_for_each_safe(qe, qen, &port->rport_q) {
  598. rport = (struct bfa_fcs_rport_s *) qe;
  599. bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
  600. }
  601. }
  602. static void
  603. bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port)
  604. {
  605. WARN_ON(1);
  606. }
  607. static void
  608. bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port)
  609. {
  610. WARN_ON(1);
  611. }
  612. static void
  613. bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port)
  614. {
  615. WARN_ON(1);
  616. }
  617. static void
  618. bfa_fcs_lport_abts_acc(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs)
  619. {
  620. struct fchs_s fchs;
  621. struct bfa_fcxp_s *fcxp;
  622. int len;
  623. bfa_trc(port->fcs, rx_fchs->d_id);
  624. bfa_trc(port->fcs, rx_fchs->s_id);
  625. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  626. if (!fcxp)
  627. return;
  628. len = fc_ba_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  629. rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  630. rx_fchs->ox_id, 0);
  631. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
  632. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  633. FC_MAX_PDUSZ, 0);
  634. }
  635. static void
  636. bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port)
  637. {
  638. struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
  639. char lpwwn_buf[BFA_STRING_32];
  640. wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
  641. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  642. "Logical port deleted: WWN = %s Role = %s\n",
  643. lpwwn_buf, "Initiator");
  644. bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DELETE);
  645. /* Base port will be deleted by the OS driver */
  646. if (port->vport)
  647. bfa_fcs_vport_delete_comp(port->vport);
  648. else
  649. bfa_wc_down(&port->fabric->wc);
  650. }
  651. /*
  652. * Unsolicited frame receive handling.
  653. */
  654. void
  655. bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
  656. struct fchs_s *fchs, u16 len)
  657. {
  658. u32 pid = fchs->s_id;
  659. struct bfa_fcs_rport_s *rport = NULL;
  660. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  661. bfa_stats(lport, uf_recvs);
  662. bfa_trc(lport->fcs, fchs->type);
  663. if (!bfa_fcs_lport_is_online(lport)) {
  664. /*
  665. * In direct attach topology, it is possible to get a PLOGI
  666. * before the lport is online due to port feature
  667. * (QoS/Trunk/FEC/CR), so send a rjt
  668. */
  669. if ((fchs->type == FC_TYPE_ELS) &&
  670. (els_cmd->els_code == FC_ELS_PLOGI)) {
  671. bfa_fcs_lport_send_ls_rjt(lport, fchs,
  672. FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
  673. FC_LS_RJT_EXP_NO_ADDL_INFO);
  674. bfa_stats(lport, plogi_rcvd);
  675. } else
  676. bfa_stats(lport, uf_recv_drops);
  677. return;
  678. }
  679. /*
  680. * First, handle ELSs that donot require a login.
  681. */
  682. /*
  683. * Handle PLOGI first
  684. */
  685. if ((fchs->type == FC_TYPE_ELS) &&
  686. (els_cmd->els_code == FC_ELS_PLOGI)) {
  687. bfa_fcs_lport_plogi(lport, fchs, (struct fc_logi_s *) els_cmd);
  688. return;
  689. }
  690. /*
  691. * Handle ECHO separately.
  692. */
  693. if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_ECHO)) {
  694. bfa_fcs_lport_echo(lport, fchs,
  695. (struct fc_echo_s *)els_cmd, len);
  696. return;
  697. }
  698. /*
  699. * Handle RNID separately.
  700. */
  701. if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_RNID)) {
  702. bfa_fcs_lport_rnid(lport, fchs,
  703. (struct fc_rnid_cmd_s *) els_cmd, len);
  704. return;
  705. }
  706. if (fchs->type == FC_TYPE_BLS) {
  707. if ((fchs->routing == FC_RTG_BASIC_LINK) &&
  708. (fchs->cat_info == FC_CAT_ABTS))
  709. bfa_fcs_lport_abts_acc(lport, fchs);
  710. return;
  711. }
  712. if (fchs->type == FC_TYPE_SERVICES) {
  713. /*
  714. * Unhandled FC-GS frames. Send a FC-CT Reject
  715. */
  716. bfa_fcs_lport_send_fcgs_rjt(lport, fchs, CT_RSN_NOT_SUPP,
  717. CT_NS_EXP_NOADDITIONAL);
  718. return;
  719. }
  720. /*
  721. * look for a matching remote port ID
  722. */
  723. rport = bfa_fcs_lport_get_rport_by_pid(lport, pid);
  724. if (rport) {
  725. bfa_trc(rport->fcs, fchs->s_id);
  726. bfa_trc(rport->fcs, fchs->d_id);
  727. bfa_trc(rport->fcs, fchs->type);
  728. bfa_fcs_rport_uf_recv(rport, fchs, len);
  729. return;
  730. }
  731. /*
  732. * Only handles ELS frames for now.
  733. */
  734. if (fchs->type != FC_TYPE_ELS) {
  735. bfa_trc(lport->fcs, fchs->s_id);
  736. bfa_trc(lport->fcs, fchs->d_id);
  737. /* ignore type FC_TYPE_FC_FSS */
  738. if (fchs->type != FC_TYPE_FC_FSS)
  739. bfa_sm_fault(lport->fcs, fchs->type);
  740. return;
  741. }
  742. bfa_trc(lport->fcs, els_cmd->els_code);
  743. if (els_cmd->els_code == FC_ELS_RSCN) {
  744. bfa_fcs_lport_scn_process_rscn(lport, fchs, len);
  745. return;
  746. }
  747. if (els_cmd->els_code == FC_ELS_LOGO) {
  748. /*
  749. * @todo Handle LOGO frames received.
  750. */
  751. return;
  752. }
  753. if (els_cmd->els_code == FC_ELS_PRLI) {
  754. /*
  755. * @todo Handle PRLI frames received.
  756. */
  757. return;
  758. }
  759. /*
  760. * Unhandled ELS frames. Send a LS_RJT.
  761. */
  762. bfa_fcs_lport_send_ls_rjt(lport, fchs, FC_LS_RJT_RSN_CMD_NOT_SUPP,
  763. FC_LS_RJT_EXP_NO_ADDL_INFO);
  764. }
  765. /*
  766. * PID based Lookup for a R-Port in the Port R-Port Queue
  767. */
  768. struct bfa_fcs_rport_s *
  769. bfa_fcs_lport_get_rport_by_pid(struct bfa_fcs_lport_s *port, u32 pid)
  770. {
  771. struct bfa_fcs_rport_s *rport;
  772. struct list_head *qe;
  773. list_for_each(qe, &port->rport_q) {
  774. rport = (struct bfa_fcs_rport_s *) qe;
  775. if (rport->pid == pid)
  776. return rport;
  777. }
  778. bfa_trc(port->fcs, pid);
  779. return NULL;
  780. }
  781. /*
  782. * OLD_PID based Lookup for a R-Port in the Port R-Port Queue
  783. */
  784. struct bfa_fcs_rport_s *
  785. bfa_fcs_lport_get_rport_by_old_pid(struct bfa_fcs_lport_s *port, u32 pid)
  786. {
  787. struct bfa_fcs_rport_s *rport;
  788. struct list_head *qe;
  789. list_for_each(qe, &port->rport_q) {
  790. rport = (struct bfa_fcs_rport_s *) qe;
  791. if (rport->old_pid == pid)
  792. return rport;
  793. }
  794. bfa_trc(port->fcs, pid);
  795. return NULL;
  796. }
  797. /*
  798. * PWWN based Lookup for a R-Port in the Port R-Port Queue
  799. */
  800. struct bfa_fcs_rport_s *
  801. bfa_fcs_lport_get_rport_by_pwwn(struct bfa_fcs_lport_s *port, wwn_t pwwn)
  802. {
  803. struct bfa_fcs_rport_s *rport;
  804. struct list_head *qe;
  805. list_for_each(qe, &port->rport_q) {
  806. rport = (struct bfa_fcs_rport_s *) qe;
  807. if (wwn_is_equal(rport->pwwn, pwwn))
  808. return rport;
  809. }
  810. bfa_trc(port->fcs, pwwn);
  811. return NULL;
  812. }
  813. /*
  814. * NWWN based Lookup for a R-Port in the Port R-Port Queue
  815. */
  816. struct bfa_fcs_rport_s *
  817. bfa_fcs_lport_get_rport_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t nwwn)
  818. {
  819. struct bfa_fcs_rport_s *rport;
  820. struct list_head *qe;
  821. list_for_each(qe, &port->rport_q) {
  822. rport = (struct bfa_fcs_rport_s *) qe;
  823. if (wwn_is_equal(rport->nwwn, nwwn))
  824. return rport;
  825. }
  826. bfa_trc(port->fcs, nwwn);
  827. return NULL;
  828. }
  829. /*
  830. * PWWN & PID based Lookup for a R-Port in the Port R-Port Queue
  831. */
  832. struct bfa_fcs_rport_s *
  833. bfa_fcs_lport_get_rport_by_qualifier(struct bfa_fcs_lport_s *port,
  834. wwn_t pwwn, u32 pid)
  835. {
  836. struct bfa_fcs_rport_s *rport;
  837. struct list_head *qe;
  838. list_for_each(qe, &port->rport_q) {
  839. rport = (struct bfa_fcs_rport_s *) qe;
  840. if (wwn_is_equal(rport->pwwn, pwwn) && rport->pid == pid)
  841. return rport;
  842. }
  843. bfa_trc(port->fcs, pwwn);
  844. return NULL;
  845. }
  846. /*
  847. * Called by rport module when new rports are discovered.
  848. */
  849. void
  850. bfa_fcs_lport_add_rport(
  851. struct bfa_fcs_lport_s *port,
  852. struct bfa_fcs_rport_s *rport)
  853. {
  854. list_add_tail(&rport->qe, &port->rport_q);
  855. port->num_rports++;
  856. }
  857. /*
  858. * Called by rport module to when rports are deleted.
  859. */
  860. void
  861. bfa_fcs_lport_del_rport(
  862. struct bfa_fcs_lport_s *port,
  863. struct bfa_fcs_rport_s *rport)
  864. {
  865. WARN_ON(!bfa_q_is_on_q(&port->rport_q, rport));
  866. list_del(&rport->qe);
  867. port->num_rports--;
  868. bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELRPORT);
  869. }
  870. /*
  871. * Called by fabric for base port when fabric login is complete.
  872. * Called by vport for virtual ports when FDISC is complete.
  873. */
  874. void
  875. bfa_fcs_lport_online(struct bfa_fcs_lport_s *port)
  876. {
  877. bfa_sm_send_event(port, BFA_FCS_PORT_SM_ONLINE);
  878. }
  879. /*
  880. * Called by fabric for base port when fabric goes offline.
  881. * Called by vport for virtual ports when virtual port becomes offline.
  882. */
  883. void
  884. bfa_fcs_lport_offline(struct bfa_fcs_lport_s *port)
  885. {
  886. bfa_sm_send_event(port, BFA_FCS_PORT_SM_OFFLINE);
  887. }
  888. /*
  889. * Called by fabric for base port and by vport for virtual ports
  890. * when target mode driver is unloaded.
  891. */
  892. void
  893. bfa_fcs_lport_stop(struct bfa_fcs_lport_s *port)
  894. {
  895. bfa_sm_send_event(port, BFA_FCS_PORT_SM_STOP);
  896. }
  897. /*
  898. * Called by fabric to delete base lport and associated resources.
  899. *
  900. * Called by vport to delete lport and associated resources. Should call
  901. * bfa_fcs_vport_delete_comp() for vports on completion.
  902. */
  903. void
  904. bfa_fcs_lport_delete(struct bfa_fcs_lport_s *port)
  905. {
  906. bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELETE);
  907. }
  908. /*
  909. * Return TRUE if port is online, else return FALSE
  910. */
  911. bfa_boolean_t
  912. bfa_fcs_lport_is_online(struct bfa_fcs_lport_s *port)
  913. {
  914. return bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online);
  915. }
  916. /*
  917. * Attach time initialization of logical ports.
  918. */
  919. void
  920. bfa_fcs_lport_attach(struct bfa_fcs_lport_s *lport, struct bfa_fcs_s *fcs,
  921. u16 vf_id, struct bfa_fcs_vport_s *vport)
  922. {
  923. lport->fcs = fcs;
  924. lport->fabric = bfa_fcs_vf_lookup(fcs, vf_id);
  925. lport->vport = vport;
  926. lport->lp_tag = (vport) ? vport->lps->bfa_tag :
  927. lport->fabric->lps->bfa_tag;
  928. INIT_LIST_HEAD(&lport->rport_q);
  929. lport->num_rports = 0;
  930. }
  931. /*
  932. * Logical port initialization of base or virtual port.
  933. * Called by fabric for base port or by vport for virtual ports.
  934. */
  935. void
  936. bfa_fcs_lport_init(struct bfa_fcs_lport_s *lport,
  937. struct bfa_lport_cfg_s *port_cfg)
  938. {
  939. struct bfa_fcs_vport_s *vport = lport->vport;
  940. struct bfad_s *bfad = (struct bfad_s *)lport->fcs->bfad;
  941. char lpwwn_buf[BFA_STRING_32];
  942. lport->port_cfg = *port_cfg;
  943. lport->bfad_port = bfa_fcb_lport_new(lport->fcs->bfad, lport,
  944. lport->port_cfg.roles,
  945. lport->fabric->vf_drv,
  946. vport ? vport->vport_drv : NULL);
  947. wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(lport));
  948. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  949. "New logical port created: WWN = %s Role = %s\n",
  950. lpwwn_buf, "Initiator");
  951. bfa_fcs_lport_aen_post(lport, BFA_LPORT_AEN_NEW);
  952. bfa_sm_set_state(lport, bfa_fcs_lport_sm_uninit);
  953. bfa_sm_send_event(lport, BFA_FCS_PORT_SM_CREATE);
  954. }
  955. void
  956. bfa_fcs_lport_set_symname(struct bfa_fcs_lport_s *port,
  957. char *symname)
  958. {
  959. strcpy(port->port_cfg.sym_name.symname, symname);
  960. if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
  961. bfa_fcs_lport_ns_util_send_rspn_id(
  962. BFA_FCS_GET_NS_FROM_PORT(port), NULL);
  963. }
  964. /*
  965. * fcs_lport_api
  966. */
  967. void
  968. bfa_fcs_lport_get_attr(
  969. struct bfa_fcs_lport_s *port,
  970. struct bfa_lport_attr_s *port_attr)
  971. {
  972. if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
  973. port_attr->pid = port->pid;
  974. else
  975. port_attr->pid = 0;
  976. port_attr->port_cfg = port->port_cfg;
  977. if (port->fabric) {
  978. port_attr->port_type = port->fabric->oper_type;
  979. port_attr->loopback = bfa_sm_cmp_state(port->fabric,
  980. bfa_fcs_fabric_sm_loopback);
  981. port_attr->authfail =
  982. bfa_sm_cmp_state(port->fabric,
  983. bfa_fcs_fabric_sm_auth_failed);
  984. port_attr->fabric_name = bfa_fcs_lport_get_fabric_name(port);
  985. memcpy(port_attr->fabric_ip_addr,
  986. bfa_fcs_lport_get_fabric_ipaddr(port),
  987. BFA_FCS_FABRIC_IPADDR_SZ);
  988. if (port->vport != NULL) {
  989. port_attr->port_type = BFA_PORT_TYPE_VPORT;
  990. port_attr->fpma_mac =
  991. port->vport->lps->lp_mac;
  992. } else {
  993. port_attr->fpma_mac =
  994. port->fabric->lps->lp_mac;
  995. }
  996. } else {
  997. port_attr->port_type = BFA_PORT_TYPE_UNKNOWN;
  998. port_attr->state = BFA_LPORT_UNINIT;
  999. }
  1000. }
  1001. /*
  1002. * bfa_fcs_lport_fab port fab functions
  1003. */
  1004. /*
  1005. * Called by port to initialize fabric services of the base port.
  1006. */
  1007. static void
  1008. bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port)
  1009. {
  1010. bfa_fcs_lport_ns_init(port);
  1011. bfa_fcs_lport_scn_init(port);
  1012. bfa_fcs_lport_ms_init(port);
  1013. }
  1014. /*
  1015. * Called by port to notify transition to online state.
  1016. */
  1017. static void
  1018. bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port)
  1019. {
  1020. bfa_fcs_lport_ns_online(port);
  1021. bfa_fcs_lport_fab_scn_online(port);
  1022. }
  1023. /*
  1024. * Called by port to notify transition to offline state.
  1025. */
  1026. static void
  1027. bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port)
  1028. {
  1029. bfa_fcs_lport_ns_offline(port);
  1030. bfa_fcs_lport_scn_offline(port);
  1031. bfa_fcs_lport_ms_offline(port);
  1032. }
  1033. /*
  1034. * bfa_fcs_lport_n2n functions
  1035. */
  1036. /*
  1037. * Called by fcs/port to initialize N2N topology.
  1038. */
  1039. static void
  1040. bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port)
  1041. {
  1042. }
  1043. /*
  1044. * Called by fcs/port to notify transition to online state.
  1045. */
  1046. static void
  1047. bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port)
  1048. {
  1049. struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
  1050. struct bfa_lport_cfg_s *pcfg = &port->port_cfg;
  1051. struct bfa_fcs_rport_s *rport;
  1052. bfa_trc(port->fcs, pcfg->pwwn);
  1053. /*
  1054. * If our PWWN is > than that of the r-port, we have to initiate PLOGI
  1055. * and assign an Address. if not, we need to wait for its PLOGI.
  1056. *
  1057. * If our PWWN is < than that of the remote port, it will send a PLOGI
  1058. * with the PIDs assigned. The rport state machine take care of this
  1059. * incoming PLOGI.
  1060. */
  1061. if (memcmp
  1062. ((void *)&pcfg->pwwn, (void *)&n2n_port->rem_port_wwn,
  1063. sizeof(wwn_t)) > 0) {
  1064. port->pid = N2N_LOCAL_PID;
  1065. bfa_lps_set_n2n_pid(port->fabric->lps, N2N_LOCAL_PID);
  1066. /*
  1067. * First, check if we know the device by pwwn.
  1068. */
  1069. rport = bfa_fcs_lport_get_rport_by_pwwn(port,
  1070. n2n_port->rem_port_wwn);
  1071. if (rport) {
  1072. bfa_trc(port->fcs, rport->pid);
  1073. bfa_trc(port->fcs, rport->pwwn);
  1074. rport->pid = N2N_REMOTE_PID;
  1075. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
  1076. return;
  1077. }
  1078. /*
  1079. * In n2n there can be only one rport. Delete the old one
  1080. * whose pid should be zero, because it is offline.
  1081. */
  1082. if (port->num_rports > 0) {
  1083. rport = bfa_fcs_lport_get_rport_by_pid(port, 0);
  1084. WARN_ON(rport == NULL);
  1085. if (rport) {
  1086. bfa_trc(port->fcs, rport->pwwn);
  1087. bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
  1088. }
  1089. }
  1090. bfa_fcs_rport_create(port, N2N_REMOTE_PID);
  1091. }
  1092. }
  1093. /*
  1094. * Called by fcs/port to notify transition to offline state.
  1095. */
  1096. static void
  1097. bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port)
  1098. {
  1099. struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
  1100. bfa_trc(port->fcs, port->pid);
  1101. port->pid = 0;
  1102. n2n_port->rem_port_wwn = 0;
  1103. n2n_port->reply_oxid = 0;
  1104. }
  1105. void
  1106. bfa_fcport_get_loop_attr(struct bfa_fcs_lport_s *port)
  1107. {
  1108. int i = 0, j = 0, bit = 0, alpa_bit = 0;
  1109. u8 k = 0;
  1110. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(port->fcs->bfa);
  1111. port->port_topo.ploop.alpabm_valid = fcport->alpabm_valid;
  1112. port->pid = fcport->myalpa;
  1113. port->pid = bfa_hton3b(port->pid);
  1114. for (i = 0; i < (FC_ALPA_MAX / 8); i++) {
  1115. for (j = 0, alpa_bit = 0; j < 8; j++, alpa_bit++) {
  1116. bfa_trc(port->fcs->bfa, fcport->alpabm.alpa_bm[i]);
  1117. bit = (fcport->alpabm.alpa_bm[i] & (1 << (7 - j)));
  1118. if (bit) {
  1119. port->port_topo.ploop.alpa_pos_map[k] =
  1120. loop_alpa_map[(i * 8) + alpa_bit];
  1121. k++;
  1122. bfa_trc(port->fcs->bfa, k);
  1123. bfa_trc(port->fcs->bfa,
  1124. port->port_topo.ploop.alpa_pos_map[k]);
  1125. }
  1126. }
  1127. }
  1128. port->port_topo.ploop.num_alpa = k;
  1129. }
  1130. /*
  1131. * Called by fcs/port to initialize Loop topology.
  1132. */
  1133. static void
  1134. bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port)
  1135. {
  1136. }
  1137. /*
  1138. * Called by fcs/port to notify transition to online state.
  1139. */
  1140. static void
  1141. bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port)
  1142. {
  1143. u8 num_alpa = 0, alpabm_valid = 0;
  1144. struct bfa_fcs_rport_s *rport;
  1145. u8 *alpa_map = NULL;
  1146. int i = 0;
  1147. u32 pid;
  1148. bfa_fcport_get_loop_attr(port);
  1149. num_alpa = port->port_topo.ploop.num_alpa;
  1150. alpabm_valid = port->port_topo.ploop.alpabm_valid;
  1151. alpa_map = port->port_topo.ploop.alpa_pos_map;
  1152. bfa_trc(port->fcs->bfa, port->pid);
  1153. bfa_trc(port->fcs->bfa, num_alpa);
  1154. if (alpabm_valid == 1) {
  1155. for (i = 0; i < num_alpa; i++) {
  1156. bfa_trc(port->fcs->bfa, alpa_map[i]);
  1157. if (alpa_map[i] != bfa_hton3b(port->pid)) {
  1158. pid = alpa_map[i];
  1159. bfa_trc(port->fcs->bfa, pid);
  1160. rport = bfa_fcs_lport_get_rport_by_pid(port,
  1161. bfa_hton3b(pid));
  1162. if (!rport)
  1163. rport = bfa_fcs_rport_create(port,
  1164. bfa_hton3b(pid));
  1165. }
  1166. }
  1167. } else {
  1168. for (i = 0; i < MAX_ALPA_COUNT; i++) {
  1169. if (alpa_map[i] != port->pid) {
  1170. pid = loop_alpa_map[i];
  1171. bfa_trc(port->fcs->bfa, pid);
  1172. rport = bfa_fcs_lport_get_rport_by_pid(port,
  1173. bfa_hton3b(pid));
  1174. if (!rport)
  1175. rport = bfa_fcs_rport_create(port,
  1176. bfa_hton3b(pid));
  1177. }
  1178. }
  1179. }
  1180. }
  1181. /*
  1182. * Called by fcs/port to notify transition to offline state.
  1183. */
  1184. static void
  1185. bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port)
  1186. {
  1187. }
  1188. #define BFA_FCS_FDMI_CMD_MAX_RETRIES 2
  1189. /*
  1190. * forward declarations
  1191. */
  1192. static void bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg,
  1193. struct bfa_fcxp_s *fcxp_alloced);
  1194. static void bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg,
  1195. struct bfa_fcxp_s *fcxp_alloced);
  1196. static void bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg,
  1197. struct bfa_fcxp_s *fcxp_alloced);
  1198. static void bfa_fcs_lport_fdmi_rhba_response(void *fcsarg,
  1199. struct bfa_fcxp_s *fcxp,
  1200. void *cbarg,
  1201. bfa_status_t req_status,
  1202. u32 rsp_len,
  1203. u32 resid_len,
  1204. struct fchs_s *rsp_fchs);
  1205. static void bfa_fcs_lport_fdmi_rprt_response(void *fcsarg,
  1206. struct bfa_fcxp_s *fcxp,
  1207. void *cbarg,
  1208. bfa_status_t req_status,
  1209. u32 rsp_len,
  1210. u32 resid_len,
  1211. struct fchs_s *rsp_fchs);
  1212. static void bfa_fcs_lport_fdmi_rpa_response(void *fcsarg,
  1213. struct bfa_fcxp_s *fcxp,
  1214. void *cbarg,
  1215. bfa_status_t req_status,
  1216. u32 rsp_len,
  1217. u32 resid_len,
  1218. struct fchs_s *rsp_fchs);
  1219. static void bfa_fcs_lport_fdmi_timeout(void *arg);
  1220. static u16 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
  1221. u8 *pyld);
  1222. static u16 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
  1223. u8 *pyld);
  1224. static u16 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
  1225. u8 *pyld);
  1226. static u16 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *
  1227. fdmi, u8 *pyld);
  1228. static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
  1229. struct bfa_fcs_fdmi_hba_attr_s *hba_attr);
  1230. static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
  1231. struct bfa_fcs_fdmi_port_attr_s *port_attr);
  1232. u32 bfa_fcs_fdmi_convert_speed(enum bfa_port_speed pport_speed);
  1233. /*
  1234. * fcs_fdmi_sm FCS FDMI state machine
  1235. */
  1236. /*
  1237. * FDMI State Machine events
  1238. */
  1239. enum port_fdmi_event {
  1240. FDMISM_EVENT_PORT_ONLINE = 1,
  1241. FDMISM_EVENT_PORT_OFFLINE = 2,
  1242. FDMISM_EVENT_RSP_OK = 4,
  1243. FDMISM_EVENT_RSP_ERROR = 5,
  1244. FDMISM_EVENT_TIMEOUT = 6,
  1245. FDMISM_EVENT_RHBA_SENT = 7,
  1246. FDMISM_EVENT_RPRT_SENT = 8,
  1247. FDMISM_EVENT_RPA_SENT = 9,
  1248. };
  1249. static void bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
  1250. enum port_fdmi_event event);
  1251. static void bfa_fcs_lport_fdmi_sm_sending_rhba(
  1252. struct bfa_fcs_lport_fdmi_s *fdmi,
  1253. enum port_fdmi_event event);
  1254. static void bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
  1255. enum port_fdmi_event event);
  1256. static void bfa_fcs_lport_fdmi_sm_rhba_retry(
  1257. struct bfa_fcs_lport_fdmi_s *fdmi,
  1258. enum port_fdmi_event event);
  1259. static void bfa_fcs_lport_fdmi_sm_sending_rprt(
  1260. struct bfa_fcs_lport_fdmi_s *fdmi,
  1261. enum port_fdmi_event event);
  1262. static void bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
  1263. enum port_fdmi_event event);
  1264. static void bfa_fcs_lport_fdmi_sm_rprt_retry(
  1265. struct bfa_fcs_lport_fdmi_s *fdmi,
  1266. enum port_fdmi_event event);
  1267. static void bfa_fcs_lport_fdmi_sm_sending_rpa(
  1268. struct bfa_fcs_lport_fdmi_s *fdmi,
  1269. enum port_fdmi_event event);
  1270. static void bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
  1271. enum port_fdmi_event event);
  1272. static void bfa_fcs_lport_fdmi_sm_rpa_retry(
  1273. struct bfa_fcs_lport_fdmi_s *fdmi,
  1274. enum port_fdmi_event event);
  1275. static void bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
  1276. enum port_fdmi_event event);
  1277. static void bfa_fcs_lport_fdmi_sm_disabled(
  1278. struct bfa_fcs_lport_fdmi_s *fdmi,
  1279. enum port_fdmi_event event);
  1280. /*
  1281. * Start in offline state - awaiting MS to send start.
  1282. */
  1283. static void
  1284. bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
  1285. enum port_fdmi_event event)
  1286. {
  1287. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1288. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1289. bfa_trc(port->fcs, event);
  1290. fdmi->retry_cnt = 0;
  1291. switch (event) {
  1292. case FDMISM_EVENT_PORT_ONLINE:
  1293. if (port->vport) {
  1294. /*
  1295. * For Vports, register a new port.
  1296. */
  1297. bfa_sm_set_state(fdmi,
  1298. bfa_fcs_lport_fdmi_sm_sending_rprt);
  1299. bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
  1300. } else {
  1301. /*
  1302. * For a base port, we should first register the HBA
  1303. * attribute. The HBA attribute also contains the base
  1304. * port registration.
  1305. */
  1306. bfa_sm_set_state(fdmi,
  1307. bfa_fcs_lport_fdmi_sm_sending_rhba);
  1308. bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
  1309. }
  1310. break;
  1311. case FDMISM_EVENT_PORT_OFFLINE:
  1312. break;
  1313. default:
  1314. bfa_sm_fault(port->fcs, event);
  1315. }
  1316. }
  1317. static void
  1318. bfa_fcs_lport_fdmi_sm_sending_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
  1319. enum port_fdmi_event event)
  1320. {
  1321. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1322. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1323. bfa_trc(port->fcs, event);
  1324. switch (event) {
  1325. case FDMISM_EVENT_RHBA_SENT:
  1326. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rhba);
  1327. break;
  1328. case FDMISM_EVENT_PORT_OFFLINE:
  1329. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1330. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
  1331. &fdmi->fcxp_wqe);
  1332. break;
  1333. default:
  1334. bfa_sm_fault(port->fcs, event);
  1335. }
  1336. }
  1337. static void
  1338. bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
  1339. enum port_fdmi_event event)
  1340. {
  1341. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1342. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1343. bfa_trc(port->fcs, event);
  1344. switch (event) {
  1345. case FDMISM_EVENT_RSP_ERROR:
  1346. /*
  1347. * if max retries have not been reached, start timer for a
  1348. * delayed retry
  1349. */
  1350. if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
  1351. bfa_sm_set_state(fdmi,
  1352. bfa_fcs_lport_fdmi_sm_rhba_retry);
  1353. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
  1354. &fdmi->timer,
  1355. bfa_fcs_lport_fdmi_timeout, fdmi,
  1356. BFA_FCS_RETRY_TIMEOUT);
  1357. } else {
  1358. /*
  1359. * set state to offline
  1360. */
  1361. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1362. }
  1363. break;
  1364. case FDMISM_EVENT_RSP_OK:
  1365. /*
  1366. * Initiate Register Port Attributes
  1367. */
  1368. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
  1369. fdmi->retry_cnt = 0;
  1370. bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
  1371. break;
  1372. case FDMISM_EVENT_PORT_OFFLINE:
  1373. bfa_fcxp_discard(fdmi->fcxp);
  1374. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1375. break;
  1376. default:
  1377. bfa_sm_fault(port->fcs, event);
  1378. }
  1379. }
  1380. static void
  1381. bfa_fcs_lport_fdmi_sm_rhba_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
  1382. enum port_fdmi_event event)
  1383. {
  1384. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1385. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1386. bfa_trc(port->fcs, event);
  1387. switch (event) {
  1388. case FDMISM_EVENT_TIMEOUT:
  1389. /*
  1390. * Retry Timer Expired. Re-send
  1391. */
  1392. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rhba);
  1393. bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
  1394. break;
  1395. case FDMISM_EVENT_PORT_OFFLINE:
  1396. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1397. bfa_timer_stop(&fdmi->timer);
  1398. break;
  1399. default:
  1400. bfa_sm_fault(port->fcs, event);
  1401. }
  1402. }
  1403. /*
  1404. * RPRT : Register Port
  1405. */
  1406. static void
  1407. bfa_fcs_lport_fdmi_sm_sending_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
  1408. enum port_fdmi_event event)
  1409. {
  1410. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1411. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1412. bfa_trc(port->fcs, event);
  1413. switch (event) {
  1414. case FDMISM_EVENT_RPRT_SENT:
  1415. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rprt);
  1416. break;
  1417. case FDMISM_EVENT_PORT_OFFLINE:
  1418. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1419. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
  1420. &fdmi->fcxp_wqe);
  1421. break;
  1422. default:
  1423. bfa_sm_fault(port->fcs, event);
  1424. }
  1425. }
  1426. static void
  1427. bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
  1428. enum port_fdmi_event event)
  1429. {
  1430. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1431. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1432. bfa_trc(port->fcs, event);
  1433. switch (event) {
  1434. case FDMISM_EVENT_RSP_ERROR:
  1435. /*
  1436. * if max retries have not been reached, start timer for a
  1437. * delayed retry
  1438. */
  1439. if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
  1440. bfa_sm_set_state(fdmi,
  1441. bfa_fcs_lport_fdmi_sm_rprt_retry);
  1442. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
  1443. &fdmi->timer,
  1444. bfa_fcs_lport_fdmi_timeout, fdmi,
  1445. BFA_FCS_RETRY_TIMEOUT);
  1446. } else {
  1447. /*
  1448. * set state to offline
  1449. */
  1450. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1451. fdmi->retry_cnt = 0;
  1452. }
  1453. break;
  1454. case FDMISM_EVENT_RSP_OK:
  1455. fdmi->retry_cnt = 0;
  1456. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
  1457. break;
  1458. case FDMISM_EVENT_PORT_OFFLINE:
  1459. bfa_fcxp_discard(fdmi->fcxp);
  1460. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1461. break;
  1462. default:
  1463. bfa_sm_fault(port->fcs, event);
  1464. }
  1465. }
  1466. static void
  1467. bfa_fcs_lport_fdmi_sm_rprt_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
  1468. enum port_fdmi_event event)
  1469. {
  1470. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1471. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1472. bfa_trc(port->fcs, event);
  1473. switch (event) {
  1474. case FDMISM_EVENT_TIMEOUT:
  1475. /*
  1476. * Retry Timer Expired. Re-send
  1477. */
  1478. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rprt);
  1479. bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
  1480. break;
  1481. case FDMISM_EVENT_PORT_OFFLINE:
  1482. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1483. bfa_timer_stop(&fdmi->timer);
  1484. break;
  1485. default:
  1486. bfa_sm_fault(port->fcs, event);
  1487. }
  1488. }
  1489. /*
  1490. * Register Port Attributes
  1491. */
  1492. static void
  1493. bfa_fcs_lport_fdmi_sm_sending_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
  1494. enum port_fdmi_event event)
  1495. {
  1496. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1497. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1498. bfa_trc(port->fcs, event);
  1499. switch (event) {
  1500. case FDMISM_EVENT_RPA_SENT:
  1501. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa);
  1502. break;
  1503. case FDMISM_EVENT_PORT_OFFLINE:
  1504. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1505. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
  1506. &fdmi->fcxp_wqe);
  1507. break;
  1508. default:
  1509. bfa_sm_fault(port->fcs, event);
  1510. }
  1511. }
  1512. static void
  1513. bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
  1514. enum port_fdmi_event event)
  1515. {
  1516. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1517. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1518. bfa_trc(port->fcs, event);
  1519. switch (event) {
  1520. case FDMISM_EVENT_RSP_ERROR:
  1521. /*
  1522. * if max retries have not been reached, start timer for a
  1523. * delayed retry
  1524. */
  1525. if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
  1526. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa_retry);
  1527. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
  1528. &fdmi->timer,
  1529. bfa_fcs_lport_fdmi_timeout, fdmi,
  1530. BFA_FCS_RETRY_TIMEOUT);
  1531. } else {
  1532. /*
  1533. * set state to offline
  1534. */
  1535. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1536. fdmi->retry_cnt = 0;
  1537. }
  1538. break;
  1539. case FDMISM_EVENT_RSP_OK:
  1540. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
  1541. fdmi->retry_cnt = 0;
  1542. break;
  1543. case FDMISM_EVENT_PORT_OFFLINE:
  1544. bfa_fcxp_discard(fdmi->fcxp);
  1545. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1546. break;
  1547. default:
  1548. bfa_sm_fault(port->fcs, event);
  1549. }
  1550. }
  1551. static void
  1552. bfa_fcs_lport_fdmi_sm_rpa_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
  1553. enum port_fdmi_event event)
  1554. {
  1555. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1556. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1557. bfa_trc(port->fcs, event);
  1558. switch (event) {
  1559. case FDMISM_EVENT_TIMEOUT:
  1560. /*
  1561. * Retry Timer Expired. Re-send
  1562. */
  1563. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
  1564. bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
  1565. break;
  1566. case FDMISM_EVENT_PORT_OFFLINE:
  1567. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1568. bfa_timer_stop(&fdmi->timer);
  1569. break;
  1570. default:
  1571. bfa_sm_fault(port->fcs, event);
  1572. }
  1573. }
  1574. static void
  1575. bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
  1576. enum port_fdmi_event event)
  1577. {
  1578. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1579. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1580. bfa_trc(port->fcs, event);
  1581. switch (event) {
  1582. case FDMISM_EVENT_PORT_OFFLINE:
  1583. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  1584. break;
  1585. default:
  1586. bfa_sm_fault(port->fcs, event);
  1587. }
  1588. }
  1589. /*
  1590. * FDMI is disabled state.
  1591. */
  1592. static void
  1593. bfa_fcs_lport_fdmi_sm_disabled(struct bfa_fcs_lport_fdmi_s *fdmi,
  1594. enum port_fdmi_event event)
  1595. {
  1596. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1597. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1598. bfa_trc(port->fcs, event);
  1599. /* No op State. It can only be enabled at Driver Init. */
  1600. }
  1601. /*
  1602. * RHBA : Register HBA Attributes.
  1603. */
  1604. static void
  1605. bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1606. {
  1607. struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
  1608. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1609. struct fchs_s fchs;
  1610. int len, attr_len;
  1611. struct bfa_fcxp_s *fcxp;
  1612. u8 *pyld;
  1613. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1614. fcxp = fcxp_alloced ? fcxp_alloced :
  1615. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  1616. if (!fcxp) {
  1617. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
  1618. bfa_fcs_lport_fdmi_send_rhba, fdmi, BFA_TRUE);
  1619. return;
  1620. }
  1621. fdmi->fcxp = fcxp;
  1622. pyld = bfa_fcxp_get_reqbuf(fcxp);
  1623. memset(pyld, 0, FC_MAX_PDUSZ);
  1624. len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
  1625. FDMI_RHBA);
  1626. attr_len =
  1627. bfa_fcs_lport_fdmi_build_rhba_pyld(fdmi,
  1628. (u8 *) ((struct ct_hdr_s *) pyld
  1629. + 1));
  1630. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1631. FC_CLASS_3, (len + attr_len), &fchs,
  1632. bfa_fcs_lport_fdmi_rhba_response, (void *)fdmi,
  1633. FC_MAX_PDUSZ, FC_FCCT_TOV);
  1634. bfa_sm_send_event(fdmi, FDMISM_EVENT_RHBA_SENT);
  1635. }
  1636. static u16
  1637. bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
  1638. {
  1639. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1640. struct bfa_fcs_fdmi_hba_attr_s hba_attr;
  1641. struct bfa_fcs_fdmi_hba_attr_s *fcs_hba_attr = &hba_attr;
  1642. struct fdmi_rhba_s *rhba = (struct fdmi_rhba_s *) pyld;
  1643. struct fdmi_attr_s *attr;
  1644. u8 *curr_ptr;
  1645. u16 len, count;
  1646. u16 templen;
  1647. /*
  1648. * get hba attributes
  1649. */
  1650. bfa_fcs_fdmi_get_hbaattr(fdmi, fcs_hba_attr);
  1651. rhba->hba_id = bfa_fcs_lport_get_pwwn(port);
  1652. rhba->port_list.num_ports = cpu_to_be32(1);
  1653. rhba->port_list.port_entry = bfa_fcs_lport_get_pwwn(port);
  1654. len = sizeof(rhba->hba_id) + sizeof(rhba->port_list);
  1655. count = 0;
  1656. len += sizeof(rhba->hba_attr_blk.attr_count);
  1657. /*
  1658. * fill out the invididual entries of the HBA attrib Block
  1659. */
  1660. curr_ptr = (u8 *) &rhba->hba_attr_blk.hba_attr;
  1661. /*
  1662. * Node Name
  1663. */
  1664. attr = (struct fdmi_attr_s *) curr_ptr;
  1665. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODENAME);
  1666. templen = sizeof(wwn_t);
  1667. memcpy(attr->value, &bfa_fcs_lport_get_nwwn(port), templen);
  1668. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1669. len += templen;
  1670. count++;
  1671. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1672. sizeof(templen));
  1673. /*
  1674. * Manufacturer
  1675. */
  1676. attr = (struct fdmi_attr_s *) curr_ptr;
  1677. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MANUFACTURER);
  1678. templen = (u16) strlen(fcs_hba_attr->manufacturer);
  1679. memcpy(attr->value, fcs_hba_attr->manufacturer, templen);
  1680. templen = fc_roundup(templen, sizeof(u32));
  1681. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1682. len += templen;
  1683. count++;
  1684. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1685. sizeof(templen));
  1686. /*
  1687. * Serial Number
  1688. */
  1689. attr = (struct fdmi_attr_s *) curr_ptr;
  1690. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_SERIALNUM);
  1691. templen = (u16) strlen(fcs_hba_attr->serial_num);
  1692. memcpy(attr->value, fcs_hba_attr->serial_num, templen);
  1693. templen = fc_roundup(templen, sizeof(u32));
  1694. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1695. len += templen;
  1696. count++;
  1697. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1698. sizeof(templen));
  1699. /*
  1700. * Model
  1701. */
  1702. attr = (struct fdmi_attr_s *) curr_ptr;
  1703. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL);
  1704. templen = (u16) strlen(fcs_hba_attr->model);
  1705. memcpy(attr->value, fcs_hba_attr->model, templen);
  1706. templen = fc_roundup(templen, sizeof(u32));
  1707. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1708. len += templen;
  1709. count++;
  1710. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1711. sizeof(templen));
  1712. /*
  1713. * Model Desc
  1714. */
  1715. attr = (struct fdmi_attr_s *) curr_ptr;
  1716. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL_DESC);
  1717. templen = (u16) strlen(fcs_hba_attr->model_desc);
  1718. memcpy(attr->value, fcs_hba_attr->model_desc, templen);
  1719. templen = fc_roundup(templen, sizeof(u32));
  1720. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1721. len += templen;
  1722. count++;
  1723. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1724. sizeof(templen));
  1725. /*
  1726. * H/W Version
  1727. */
  1728. if (fcs_hba_attr->hw_version[0] != '\0') {
  1729. attr = (struct fdmi_attr_s *) curr_ptr;
  1730. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_HW_VERSION);
  1731. templen = (u16) strlen(fcs_hba_attr->hw_version);
  1732. memcpy(attr->value, fcs_hba_attr->hw_version, templen);
  1733. templen = fc_roundup(templen, sizeof(u32));
  1734. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1735. len += templen;
  1736. count++;
  1737. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1738. sizeof(templen));
  1739. }
  1740. /*
  1741. * Driver Version
  1742. */
  1743. attr = (struct fdmi_attr_s *) curr_ptr;
  1744. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_DRIVER_VERSION);
  1745. templen = (u16) strlen(fcs_hba_attr->driver_version);
  1746. memcpy(attr->value, fcs_hba_attr->driver_version, templen);
  1747. templen = fc_roundup(templen, sizeof(u32));
  1748. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1749. len += templen;
  1750. count++;
  1751. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1752. sizeof(templen));
  1753. /*
  1754. * Option Rom Version
  1755. */
  1756. if (fcs_hba_attr->option_rom_ver[0] != '\0') {
  1757. attr = (struct fdmi_attr_s *) curr_ptr;
  1758. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_ROM_VERSION);
  1759. templen = (u16) strlen(fcs_hba_attr->option_rom_ver);
  1760. memcpy(attr->value, fcs_hba_attr->option_rom_ver, templen);
  1761. templen = fc_roundup(templen, sizeof(u32));
  1762. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1763. len += templen;
  1764. count++;
  1765. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1766. sizeof(templen));
  1767. }
  1768. attr = (struct fdmi_attr_s *) curr_ptr;
  1769. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FW_VERSION);
  1770. templen = (u16) strlen(fcs_hba_attr->fw_version);
  1771. memcpy(attr->value, fcs_hba_attr->fw_version, templen);
  1772. templen = fc_roundup(templen, sizeof(u32));
  1773. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1774. len += templen;
  1775. count++;
  1776. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1777. sizeof(templen));
  1778. /*
  1779. * OS Name
  1780. */
  1781. if (fcs_hba_attr->os_name[0] != '\0') {
  1782. attr = (struct fdmi_attr_s *) curr_ptr;
  1783. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_OS_NAME);
  1784. templen = (u16) strlen(fcs_hba_attr->os_name);
  1785. memcpy(attr->value, fcs_hba_attr->os_name, templen);
  1786. templen = fc_roundup(templen, sizeof(u32));
  1787. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1788. len += templen;
  1789. count++;
  1790. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1791. sizeof(templen));
  1792. }
  1793. /*
  1794. * MAX_CT_PAYLOAD
  1795. */
  1796. attr = (struct fdmi_attr_s *) curr_ptr;
  1797. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MAX_CT);
  1798. templen = sizeof(fcs_hba_attr->max_ct_pyld);
  1799. memcpy(attr->value, &fcs_hba_attr->max_ct_pyld, templen);
  1800. templen = fc_roundup(templen, sizeof(u32));
  1801. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1802. len += templen;
  1803. count++;
  1804. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1805. sizeof(templen));
  1806. /*
  1807. * Send extended attributes ( FOS 7.1 support )
  1808. */
  1809. if (fdmi->retry_cnt == 0) {
  1810. attr = (struct fdmi_attr_s *) curr_ptr;
  1811. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODE_SYM_NAME);
  1812. templen = sizeof(fcs_hba_attr->node_sym_name);
  1813. memcpy(attr->value, &fcs_hba_attr->node_sym_name, templen);
  1814. templen = fc_roundup(templen, sizeof(u32));
  1815. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1816. len += templen;
  1817. count++;
  1818. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1819. sizeof(templen));
  1820. attr = (struct fdmi_attr_s *) curr_ptr;
  1821. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_VENDOR_ID);
  1822. templen = sizeof(fcs_hba_attr->vendor_info);
  1823. memcpy(attr->value, &fcs_hba_attr->vendor_info, templen);
  1824. templen = fc_roundup(templen, sizeof(u32));
  1825. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1826. len += templen;
  1827. count++;
  1828. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1829. sizeof(templen));
  1830. attr = (struct fdmi_attr_s *) curr_ptr;
  1831. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NUM_PORTS);
  1832. templen = sizeof(fcs_hba_attr->num_ports);
  1833. memcpy(attr->value, &fcs_hba_attr->num_ports, templen);
  1834. templen = fc_roundup(templen, sizeof(u32));
  1835. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1836. len += templen;
  1837. count++;
  1838. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1839. sizeof(templen));
  1840. attr = (struct fdmi_attr_s *) curr_ptr;
  1841. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FABRIC_NAME);
  1842. templen = sizeof(fcs_hba_attr->fabric_name);
  1843. memcpy(attr->value, &fcs_hba_attr->fabric_name, templen);
  1844. templen = fc_roundup(templen, sizeof(u32));
  1845. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1846. len += templen;
  1847. count++;
  1848. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1849. sizeof(templen));
  1850. attr = (struct fdmi_attr_s *) curr_ptr;
  1851. attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_BIOS_VER);
  1852. templen = sizeof(fcs_hba_attr->bios_ver);
  1853. memcpy(attr->value, &fcs_hba_attr->bios_ver, templen);
  1854. templen = fc_roundup(attr->len, sizeof(u32));
  1855. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1856. len += templen;
  1857. count++;
  1858. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1859. sizeof(templen));
  1860. }
  1861. /*
  1862. * Update size of payload
  1863. */
  1864. len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
  1865. rhba->hba_attr_blk.attr_count = cpu_to_be32(count);
  1866. return len;
  1867. }
  1868. static void
  1869. bfa_fcs_lport_fdmi_rhba_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  1870. void *cbarg, bfa_status_t req_status,
  1871. u32 rsp_len, u32 resid_len,
  1872. struct fchs_s *rsp_fchs)
  1873. {
  1874. struct bfa_fcs_lport_fdmi_s *fdmi =
  1875. (struct bfa_fcs_lport_fdmi_s *) cbarg;
  1876. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1877. struct ct_hdr_s *cthdr = NULL;
  1878. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1879. /*
  1880. * Sanity Checks
  1881. */
  1882. if (req_status != BFA_STATUS_OK) {
  1883. bfa_trc(port->fcs, req_status);
  1884. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  1885. return;
  1886. }
  1887. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  1888. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  1889. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  1890. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
  1891. return;
  1892. }
  1893. bfa_trc(port->fcs, cthdr->reason_code);
  1894. bfa_trc(port->fcs, cthdr->exp_code);
  1895. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  1896. }
  1897. /*
  1898. * RPRT : Register Port
  1899. */
  1900. static void
  1901. bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1902. {
  1903. struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
  1904. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  1905. struct fchs_s fchs;
  1906. u16 len, attr_len;
  1907. struct bfa_fcxp_s *fcxp;
  1908. u8 *pyld;
  1909. bfa_trc(port->fcs, port->port_cfg.pwwn);
  1910. fcxp = fcxp_alloced ? fcxp_alloced :
  1911. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  1912. if (!fcxp) {
  1913. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
  1914. bfa_fcs_lport_fdmi_send_rprt, fdmi, BFA_TRUE);
  1915. return;
  1916. }
  1917. fdmi->fcxp = fcxp;
  1918. pyld = bfa_fcxp_get_reqbuf(fcxp);
  1919. memset(pyld, 0, FC_MAX_PDUSZ);
  1920. len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
  1921. FDMI_RPRT);
  1922. attr_len =
  1923. bfa_fcs_lport_fdmi_build_rprt_pyld(fdmi,
  1924. (u8 *) ((struct ct_hdr_s *) pyld
  1925. + 1));
  1926. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1927. FC_CLASS_3, len + attr_len, &fchs,
  1928. bfa_fcs_lport_fdmi_rprt_response, (void *)fdmi,
  1929. FC_MAX_PDUSZ, FC_FCCT_TOV);
  1930. bfa_sm_send_event(fdmi, FDMISM_EVENT_RPRT_SENT);
  1931. }
  1932. /*
  1933. * This routine builds Port Attribute Block that used in RPA, RPRT commands.
  1934. */
  1935. static u16
  1936. bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
  1937. u8 *pyld)
  1938. {
  1939. struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
  1940. struct fdmi_port_attr_s *port_attrib = (struct fdmi_port_attr_s *) pyld;
  1941. struct fdmi_attr_s *attr;
  1942. u8 *curr_ptr;
  1943. u16 len;
  1944. u8 count = 0;
  1945. u16 templen;
  1946. /*
  1947. * get port attributes
  1948. */
  1949. bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
  1950. len = sizeof(port_attrib->attr_count);
  1951. /*
  1952. * fill out the invididual entries
  1953. */
  1954. curr_ptr = (u8 *) &port_attrib->port_attr;
  1955. /*
  1956. * FC4 Types
  1957. */
  1958. attr = (struct fdmi_attr_s *) curr_ptr;
  1959. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FC4_TYPES);
  1960. templen = sizeof(fcs_port_attr.supp_fc4_types);
  1961. memcpy(attr->value, fcs_port_attr.supp_fc4_types, templen);
  1962. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1963. len += templen;
  1964. ++count;
  1965. attr->len =
  1966. cpu_to_be16(templen + sizeof(attr->type) +
  1967. sizeof(templen));
  1968. /*
  1969. * Supported Speed
  1970. */
  1971. attr = (struct fdmi_attr_s *) curr_ptr;
  1972. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_SPEED);
  1973. templen = sizeof(fcs_port_attr.supp_speed);
  1974. memcpy(attr->value, &fcs_port_attr.supp_speed, templen);
  1975. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1976. len += templen;
  1977. ++count;
  1978. attr->len =
  1979. cpu_to_be16(templen + sizeof(attr->type) +
  1980. sizeof(templen));
  1981. /*
  1982. * current Port Speed
  1983. */
  1984. attr = (struct fdmi_attr_s *) curr_ptr;
  1985. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SPEED);
  1986. templen = sizeof(fcs_port_attr.curr_speed);
  1987. memcpy(attr->value, &fcs_port_attr.curr_speed, templen);
  1988. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  1989. len += templen;
  1990. ++count;
  1991. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  1992. sizeof(templen));
  1993. /*
  1994. * max frame size
  1995. */
  1996. attr = (struct fdmi_attr_s *) curr_ptr;
  1997. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FRAME_SIZE);
  1998. templen = sizeof(fcs_port_attr.max_frm_size);
  1999. memcpy(attr->value, &fcs_port_attr.max_frm_size, templen);
  2000. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  2001. len += templen;
  2002. ++count;
  2003. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  2004. sizeof(templen));
  2005. /*
  2006. * OS Device Name
  2007. */
  2008. if (fcs_port_attr.os_device_name[0] != '\0') {
  2009. attr = (struct fdmi_attr_s *) curr_ptr;
  2010. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_DEV_NAME);
  2011. templen = (u16) strlen(fcs_port_attr.os_device_name);
  2012. memcpy(attr->value, fcs_port_attr.os_device_name, templen);
  2013. templen = fc_roundup(templen, sizeof(u32));
  2014. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  2015. len += templen;
  2016. ++count;
  2017. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  2018. sizeof(templen));
  2019. }
  2020. /*
  2021. * Host Name
  2022. */
  2023. if (fcs_port_attr.host_name[0] != '\0') {
  2024. attr = (struct fdmi_attr_s *) curr_ptr;
  2025. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_HOST_NAME);
  2026. templen = (u16) strlen(fcs_port_attr.host_name);
  2027. memcpy(attr->value, fcs_port_attr.host_name, templen);
  2028. templen = fc_roundup(templen, sizeof(u32));
  2029. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  2030. len += templen;
  2031. ++count;
  2032. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  2033. sizeof(templen));
  2034. }
  2035. if (fdmi->retry_cnt == 0) {
  2036. attr = (struct fdmi_attr_s *) curr_ptr;
  2037. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_NODE_NAME);
  2038. templen = sizeof(fcs_port_attr.node_name);
  2039. memcpy(attr->value, &fcs_port_attr.node_name, templen);
  2040. templen = fc_roundup(templen, sizeof(u32));
  2041. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  2042. len += templen;
  2043. ++count;
  2044. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  2045. sizeof(templen));
  2046. attr = (struct fdmi_attr_s *) curr_ptr;
  2047. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NAME);
  2048. templen = sizeof(fcs_port_attr.port_name);
  2049. memcpy(attr->value, &fcs_port_attr.port_name, templen);
  2050. templen = fc_roundup(templen, sizeof(u32));
  2051. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + templen;
  2052. len += templen;
  2053. ++count;
  2054. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  2055. sizeof(templen));
  2056. if (fcs_port_attr.port_sym_name.symname[0] != '\0') {
  2057. attr = (struct fdmi_attr_s *) curr_ptr;
  2058. attr->type =
  2059. cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SYM_NAME);
  2060. templen = sizeof(fcs_port_attr.port_sym_name);
  2061. memcpy(attr->value,
  2062. &fcs_port_attr.port_sym_name, templen);
  2063. templen = fc_roundup(templen, sizeof(u32));
  2064. curr_ptr += sizeof(attr->type) +
  2065. sizeof(templen) + templen;
  2066. len += templen;
  2067. ++count;
  2068. attr->len = cpu_to_be16(templen +
  2069. sizeof(attr->type) + sizeof(templen));
  2070. }
  2071. attr = (struct fdmi_attr_s *) curr_ptr;
  2072. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_TYPE);
  2073. templen = sizeof(fcs_port_attr.port_type);
  2074. memcpy(attr->value, &fcs_port_attr.port_type, templen);
  2075. templen = fc_roundup(templen, sizeof(u32));
  2076. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  2077. len += templen;
  2078. ++count;
  2079. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  2080. sizeof(templen));
  2081. attr = (struct fdmi_attr_s *) curr_ptr;
  2082. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_COS);
  2083. templen = sizeof(fcs_port_attr.scos);
  2084. memcpy(attr->value, &fcs_port_attr.scos, templen);
  2085. templen = fc_roundup(templen, sizeof(u32));
  2086. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  2087. len += templen;
  2088. ++count;
  2089. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  2090. sizeof(templen));
  2091. attr = (struct fdmi_attr_s *) curr_ptr;
  2092. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FAB_NAME);
  2093. templen = sizeof(fcs_port_attr.port_fabric_name);
  2094. memcpy(attr->value, &fcs_port_attr.port_fabric_name, templen);
  2095. templen = fc_roundup(templen, sizeof(u32));
  2096. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  2097. len += templen;
  2098. ++count;
  2099. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  2100. sizeof(templen));
  2101. attr = (struct fdmi_attr_s *) curr_ptr;
  2102. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FC4_TYPE);
  2103. templen = sizeof(fcs_port_attr.port_act_fc4_type);
  2104. memcpy(attr->value, fcs_port_attr.port_act_fc4_type,
  2105. templen);
  2106. templen = fc_roundup(templen, sizeof(u32));
  2107. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  2108. len += templen;
  2109. ++count;
  2110. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  2111. sizeof(templen));
  2112. attr = (struct fdmi_attr_s *) curr_ptr;
  2113. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_STATE);
  2114. templen = sizeof(fcs_port_attr.port_state);
  2115. memcpy(attr->value, &fcs_port_attr.port_state, templen);
  2116. templen = fc_roundup(templen, sizeof(u32));
  2117. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  2118. len += templen;
  2119. ++count;
  2120. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  2121. sizeof(templen));
  2122. attr = (struct fdmi_attr_s *) curr_ptr;
  2123. attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NUM_RPRT);
  2124. templen = sizeof(fcs_port_attr.num_ports);
  2125. memcpy(attr->value, &fcs_port_attr.num_ports, templen);
  2126. templen = fc_roundup(templen, sizeof(u32));
  2127. curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
  2128. len += templen;
  2129. ++count;
  2130. attr->len = cpu_to_be16(templen + sizeof(attr->type) +
  2131. sizeof(templen));
  2132. }
  2133. /*
  2134. * Update size of payload
  2135. */
  2136. port_attrib->attr_count = cpu_to_be32(count);
  2137. len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
  2138. return len;
  2139. }
  2140. static u16
  2141. bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
  2142. {
  2143. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  2144. struct fdmi_rprt_s *rprt = (struct fdmi_rprt_s *) pyld;
  2145. u16 len;
  2146. rprt->hba_id = bfa_fcs_lport_get_pwwn(bfa_fcs_get_base_port(port->fcs));
  2147. rprt->port_name = bfa_fcs_lport_get_pwwn(port);
  2148. len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
  2149. (u8 *) &rprt->port_attr_blk);
  2150. len += sizeof(rprt->hba_id) + sizeof(rprt->port_name);
  2151. return len;
  2152. }
  2153. static void
  2154. bfa_fcs_lport_fdmi_rprt_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  2155. void *cbarg, bfa_status_t req_status,
  2156. u32 rsp_len, u32 resid_len,
  2157. struct fchs_s *rsp_fchs)
  2158. {
  2159. struct bfa_fcs_lport_fdmi_s *fdmi =
  2160. (struct bfa_fcs_lport_fdmi_s *) cbarg;
  2161. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  2162. struct ct_hdr_s *cthdr = NULL;
  2163. bfa_trc(port->fcs, port->port_cfg.pwwn);
  2164. /*
  2165. * Sanity Checks
  2166. */
  2167. if (req_status != BFA_STATUS_OK) {
  2168. bfa_trc(port->fcs, req_status);
  2169. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  2170. return;
  2171. }
  2172. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  2173. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  2174. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  2175. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
  2176. return;
  2177. }
  2178. bfa_trc(port->fcs, cthdr->reason_code);
  2179. bfa_trc(port->fcs, cthdr->exp_code);
  2180. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  2181. }
  2182. /*
  2183. * RPA : Register Port Attributes.
  2184. */
  2185. static void
  2186. bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  2187. {
  2188. struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
  2189. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  2190. struct fchs_s fchs;
  2191. u16 len, attr_len;
  2192. struct bfa_fcxp_s *fcxp;
  2193. u8 *pyld;
  2194. bfa_trc(port->fcs, port->port_cfg.pwwn);
  2195. fcxp = fcxp_alloced ? fcxp_alloced :
  2196. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  2197. if (!fcxp) {
  2198. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
  2199. bfa_fcs_lport_fdmi_send_rpa, fdmi, BFA_TRUE);
  2200. return;
  2201. }
  2202. fdmi->fcxp = fcxp;
  2203. pyld = bfa_fcxp_get_reqbuf(fcxp);
  2204. memset(pyld, 0, FC_MAX_PDUSZ);
  2205. len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
  2206. FDMI_RPA);
  2207. attr_len = bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi,
  2208. (u8 *) ((struct ct_hdr_s *) pyld + 1));
  2209. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  2210. FC_CLASS_3, len + attr_len, &fchs,
  2211. bfa_fcs_lport_fdmi_rpa_response, (void *)fdmi,
  2212. FC_MAX_PDUSZ, FC_FCCT_TOV);
  2213. bfa_sm_send_event(fdmi, FDMISM_EVENT_RPA_SENT);
  2214. }
  2215. static u16
  2216. bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
  2217. {
  2218. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  2219. struct fdmi_rpa_s *rpa = (struct fdmi_rpa_s *) pyld;
  2220. u16 len;
  2221. rpa->port_name = bfa_fcs_lport_get_pwwn(port);
  2222. len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
  2223. (u8 *) &rpa->port_attr_blk);
  2224. len += sizeof(rpa->port_name);
  2225. return len;
  2226. }
  2227. static void
  2228. bfa_fcs_lport_fdmi_rpa_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  2229. void *cbarg, bfa_status_t req_status, u32 rsp_len,
  2230. u32 resid_len, struct fchs_s *rsp_fchs)
  2231. {
  2232. struct bfa_fcs_lport_fdmi_s *fdmi =
  2233. (struct bfa_fcs_lport_fdmi_s *) cbarg;
  2234. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  2235. struct ct_hdr_s *cthdr = NULL;
  2236. bfa_trc(port->fcs, port->port_cfg.pwwn);
  2237. /*
  2238. * Sanity Checks
  2239. */
  2240. if (req_status != BFA_STATUS_OK) {
  2241. bfa_trc(port->fcs, req_status);
  2242. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  2243. return;
  2244. }
  2245. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  2246. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  2247. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  2248. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
  2249. return;
  2250. }
  2251. bfa_trc(port->fcs, cthdr->reason_code);
  2252. bfa_trc(port->fcs, cthdr->exp_code);
  2253. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  2254. }
  2255. static void
  2256. bfa_fcs_lport_fdmi_timeout(void *arg)
  2257. {
  2258. struct bfa_fcs_lport_fdmi_s *fdmi = (struct bfa_fcs_lport_fdmi_s *) arg;
  2259. bfa_sm_send_event(fdmi, FDMISM_EVENT_TIMEOUT);
  2260. }
  2261. static void
  2262. bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
  2263. struct bfa_fcs_fdmi_hba_attr_s *hba_attr)
  2264. {
  2265. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  2266. struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
  2267. struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
  2268. memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s));
  2269. bfa_ioc_get_adapter_manufacturer(&port->fcs->bfa->ioc,
  2270. hba_attr->manufacturer);
  2271. bfa_ioc_get_adapter_serial_num(&port->fcs->bfa->ioc,
  2272. hba_attr->serial_num);
  2273. bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
  2274. hba_attr->model);
  2275. bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
  2276. hba_attr->model_desc);
  2277. bfa_ioc_get_pci_chip_rev(&port->fcs->bfa->ioc,
  2278. hba_attr->hw_version);
  2279. bfa_ioc_get_adapter_optrom_ver(&port->fcs->bfa->ioc,
  2280. hba_attr->option_rom_ver);
  2281. bfa_ioc_get_adapter_fw_ver(&port->fcs->bfa->ioc,
  2282. hba_attr->fw_version);
  2283. strncpy(hba_attr->driver_version, (char *)driver_info->version,
  2284. sizeof(hba_attr->driver_version));
  2285. strncpy(hba_attr->os_name, driver_info->host_os_name,
  2286. sizeof(hba_attr->os_name));
  2287. /*
  2288. * If there is a patch level, append it
  2289. * to the os name along with a separator
  2290. */
  2291. if (driver_info->host_os_patch[0] != '\0') {
  2292. strncat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  2293. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  2294. strncat(hba_attr->os_name, driver_info->host_os_patch,
  2295. sizeof(driver_info->host_os_patch));
  2296. }
  2297. /* Retrieve the max frame size from the port attr */
  2298. bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
  2299. hba_attr->max_ct_pyld = fcs_port_attr.max_frm_size;
  2300. strncpy(hba_attr->node_sym_name.symname,
  2301. port->port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
  2302. strcpy(hba_attr->vendor_info, "BROCADE");
  2303. hba_attr->num_ports =
  2304. cpu_to_be32(bfa_ioc_get_nports(&port->fcs->bfa->ioc));
  2305. hba_attr->fabric_name = port->fabric->lps->pr_nwwn;
  2306. strncpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
  2307. }
  2308. static void
  2309. bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
  2310. struct bfa_fcs_fdmi_port_attr_s *port_attr)
  2311. {
  2312. struct bfa_fcs_lport_s *port = fdmi->ms->port;
  2313. struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
  2314. struct bfa_port_attr_s pport_attr;
  2315. struct bfa_lport_attr_s lport_attr;
  2316. memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s));
  2317. /*
  2318. * get pport attributes from hal
  2319. */
  2320. bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
  2321. /*
  2322. * get FC4 type Bitmask
  2323. */
  2324. fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->supp_fc4_types);
  2325. /*
  2326. * Supported Speeds
  2327. */
  2328. switch (pport_attr.speed_supported) {
  2329. case BFA_PORT_SPEED_16GBPS:
  2330. port_attr->supp_speed =
  2331. cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_16G);
  2332. break;
  2333. case BFA_PORT_SPEED_10GBPS:
  2334. port_attr->supp_speed =
  2335. cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_10G);
  2336. break;
  2337. case BFA_PORT_SPEED_8GBPS:
  2338. port_attr->supp_speed =
  2339. cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_8G);
  2340. break;
  2341. case BFA_PORT_SPEED_4GBPS:
  2342. port_attr->supp_speed =
  2343. cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_4G);
  2344. break;
  2345. default:
  2346. bfa_sm_fault(port->fcs, pport_attr.speed_supported);
  2347. }
  2348. /*
  2349. * Current Speed
  2350. */
  2351. port_attr->curr_speed = cpu_to_be32(
  2352. bfa_fcs_fdmi_convert_speed(pport_attr.speed));
  2353. /*
  2354. * Max PDU Size.
  2355. */
  2356. port_attr->max_frm_size = cpu_to_be32(pport_attr.pport_cfg.maxfrsize);
  2357. /*
  2358. * OS device Name
  2359. */
  2360. strncpy(port_attr->os_device_name, (char *)driver_info->os_device_name,
  2361. sizeof(port_attr->os_device_name));
  2362. /*
  2363. * Host name
  2364. */
  2365. strncpy(port_attr->host_name, (char *)driver_info->host_machine_name,
  2366. sizeof(port_attr->host_name));
  2367. port_attr->node_name = bfa_fcs_lport_get_nwwn(port);
  2368. port_attr->port_name = bfa_fcs_lport_get_pwwn(port);
  2369. strncpy(port_attr->port_sym_name.symname,
  2370. (char *)&bfa_fcs_lport_get_psym_name(port), BFA_SYMNAME_MAXLEN);
  2371. bfa_fcs_lport_get_attr(port, &lport_attr);
  2372. port_attr->port_type = cpu_to_be32(lport_attr.port_type);
  2373. port_attr->scos = pport_attr.cos_supported;
  2374. port_attr->port_fabric_name = port->fabric->lps->pr_nwwn;
  2375. fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->port_act_fc4_type);
  2376. port_attr->port_state = cpu_to_be32(pport_attr.port_state);
  2377. port_attr->num_ports = cpu_to_be32(port->num_rports);
  2378. }
  2379. /*
  2380. * Convert BFA speed to FDMI format.
  2381. */
  2382. u32
  2383. bfa_fcs_fdmi_convert_speed(bfa_port_speed_t pport_speed)
  2384. {
  2385. u32 ret;
  2386. switch (pport_speed) {
  2387. case BFA_PORT_SPEED_1GBPS:
  2388. case BFA_PORT_SPEED_2GBPS:
  2389. ret = pport_speed;
  2390. break;
  2391. case BFA_PORT_SPEED_4GBPS:
  2392. ret = FDMI_TRANS_SPEED_4G;
  2393. break;
  2394. case BFA_PORT_SPEED_8GBPS:
  2395. ret = FDMI_TRANS_SPEED_8G;
  2396. break;
  2397. case BFA_PORT_SPEED_10GBPS:
  2398. ret = FDMI_TRANS_SPEED_10G;
  2399. break;
  2400. case BFA_PORT_SPEED_16GBPS:
  2401. ret = FDMI_TRANS_SPEED_16G;
  2402. break;
  2403. default:
  2404. ret = FDMI_TRANS_SPEED_UNKNOWN;
  2405. }
  2406. return ret;
  2407. }
  2408. void
  2409. bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s *ms)
  2410. {
  2411. struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
  2412. fdmi->ms = ms;
  2413. if (ms->port->fcs->fdmi_enabled)
  2414. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
  2415. else
  2416. bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_disabled);
  2417. }
  2418. void
  2419. bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s *ms)
  2420. {
  2421. struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
  2422. fdmi->ms = ms;
  2423. bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_OFFLINE);
  2424. }
  2425. void
  2426. bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s *ms)
  2427. {
  2428. struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
  2429. fdmi->ms = ms;
  2430. bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_ONLINE);
  2431. }
  2432. #define BFA_FCS_MS_CMD_MAX_RETRIES 2
  2433. /*
  2434. * forward declarations
  2435. */
  2436. static void bfa_fcs_lport_ms_send_plogi(void *ms_cbarg,
  2437. struct bfa_fcxp_s *fcxp_alloced);
  2438. static void bfa_fcs_lport_ms_timeout(void *arg);
  2439. static void bfa_fcs_lport_ms_plogi_response(void *fcsarg,
  2440. struct bfa_fcxp_s *fcxp,
  2441. void *cbarg,
  2442. bfa_status_t req_status,
  2443. u32 rsp_len,
  2444. u32 resid_len,
  2445. struct fchs_s *rsp_fchs);
  2446. static void bfa_fcs_lport_ms_send_gmal(void *ms_cbarg,
  2447. struct bfa_fcxp_s *fcxp_alloced);
  2448. static void bfa_fcs_lport_ms_gmal_response(void *fcsarg,
  2449. struct bfa_fcxp_s *fcxp,
  2450. void *cbarg,
  2451. bfa_status_t req_status,
  2452. u32 rsp_len,
  2453. u32 resid_len,
  2454. struct fchs_s *rsp_fchs);
  2455. static void bfa_fcs_lport_ms_send_gfn(void *ms_cbarg,
  2456. struct bfa_fcxp_s *fcxp_alloced);
  2457. static void bfa_fcs_lport_ms_gfn_response(void *fcsarg,
  2458. struct bfa_fcxp_s *fcxp,
  2459. void *cbarg,
  2460. bfa_status_t req_status,
  2461. u32 rsp_len,
  2462. u32 resid_len,
  2463. struct fchs_s *rsp_fchs);
  2464. /*
  2465. * fcs_ms_sm FCS MS state machine
  2466. */
  2467. /*
  2468. * MS State Machine events
  2469. */
  2470. enum port_ms_event {
  2471. MSSM_EVENT_PORT_ONLINE = 1,
  2472. MSSM_EVENT_PORT_OFFLINE = 2,
  2473. MSSM_EVENT_RSP_OK = 3,
  2474. MSSM_EVENT_RSP_ERROR = 4,
  2475. MSSM_EVENT_TIMEOUT = 5,
  2476. MSSM_EVENT_FCXP_SENT = 6,
  2477. MSSM_EVENT_PORT_FABRIC_RSCN = 7
  2478. };
  2479. static void bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
  2480. enum port_ms_event event);
  2481. static void bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
  2482. enum port_ms_event event);
  2483. static void bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
  2484. enum port_ms_event event);
  2485. static void bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
  2486. enum port_ms_event event);
  2487. static void bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
  2488. enum port_ms_event event);
  2489. static void bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
  2490. enum port_ms_event event);
  2491. static void bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
  2492. enum port_ms_event event);
  2493. static void bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
  2494. enum port_ms_event event);
  2495. static void bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
  2496. enum port_ms_event event);
  2497. static void bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
  2498. enum port_ms_event event);
  2499. static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
  2500. enum port_ms_event event);
  2501. /*
  2502. * Start in offline state - awaiting NS to send start.
  2503. */
  2504. static void
  2505. bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
  2506. enum port_ms_event event)
  2507. {
  2508. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  2509. bfa_trc(ms->port->fcs, event);
  2510. switch (event) {
  2511. case MSSM_EVENT_PORT_ONLINE:
  2512. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
  2513. bfa_fcs_lport_ms_send_plogi(ms, NULL);
  2514. break;
  2515. case MSSM_EVENT_PORT_OFFLINE:
  2516. break;
  2517. default:
  2518. bfa_sm_fault(ms->port->fcs, event);
  2519. }
  2520. }
  2521. static void
  2522. bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
  2523. enum port_ms_event event)
  2524. {
  2525. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  2526. bfa_trc(ms->port->fcs, event);
  2527. switch (event) {
  2528. case MSSM_EVENT_FCXP_SENT:
  2529. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi);
  2530. break;
  2531. case MSSM_EVENT_PORT_OFFLINE:
  2532. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
  2533. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
  2534. &ms->fcxp_wqe);
  2535. break;
  2536. default:
  2537. bfa_sm_fault(ms->port->fcs, event);
  2538. }
  2539. }
  2540. static void
  2541. bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
  2542. enum port_ms_event event)
  2543. {
  2544. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  2545. bfa_trc(ms->port->fcs, event);
  2546. switch (event) {
  2547. case MSSM_EVENT_RSP_ERROR:
  2548. /*
  2549. * Start timer for a delayed retry
  2550. */
  2551. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_retry);
  2552. ms->port->stats.ms_retries++;
  2553. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
  2554. &ms->timer, bfa_fcs_lport_ms_timeout, ms,
  2555. BFA_FCS_RETRY_TIMEOUT);
  2556. break;
  2557. case MSSM_EVENT_RSP_OK:
  2558. /*
  2559. * since plogi is done, now invoke MS related sub-modules
  2560. */
  2561. bfa_fcs_lport_fdmi_online(ms);
  2562. /*
  2563. * if this is a Vport, go to online state.
  2564. */
  2565. if (ms->port->vport) {
  2566. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
  2567. break;
  2568. }
  2569. /*
  2570. * For a base port we need to get the
  2571. * switch's IP address.
  2572. */
  2573. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
  2574. bfa_fcs_lport_ms_send_gmal(ms, NULL);
  2575. break;
  2576. case MSSM_EVENT_PORT_OFFLINE:
  2577. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
  2578. bfa_fcxp_discard(ms->fcxp);
  2579. break;
  2580. default:
  2581. bfa_sm_fault(ms->port->fcs, event);
  2582. }
  2583. }
  2584. static void
  2585. bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
  2586. enum port_ms_event event)
  2587. {
  2588. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  2589. bfa_trc(ms->port->fcs, event);
  2590. switch (event) {
  2591. case MSSM_EVENT_TIMEOUT:
  2592. /*
  2593. * Retry Timer Expired. Re-send
  2594. */
  2595. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
  2596. bfa_fcs_lport_ms_send_plogi(ms, NULL);
  2597. break;
  2598. case MSSM_EVENT_PORT_OFFLINE:
  2599. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
  2600. bfa_timer_stop(&ms->timer);
  2601. break;
  2602. default:
  2603. bfa_sm_fault(ms->port->fcs, event);
  2604. }
  2605. }
  2606. static void
  2607. bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
  2608. enum port_ms_event event)
  2609. {
  2610. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  2611. bfa_trc(ms->port->fcs, event);
  2612. switch (event) {
  2613. case MSSM_EVENT_PORT_OFFLINE:
  2614. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
  2615. break;
  2616. case MSSM_EVENT_PORT_FABRIC_RSCN:
  2617. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
  2618. ms->retry_cnt = 0;
  2619. bfa_fcs_lport_ms_send_gfn(ms, NULL);
  2620. break;
  2621. default:
  2622. bfa_sm_fault(ms->port->fcs, event);
  2623. }
  2624. }
  2625. static void
  2626. bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
  2627. enum port_ms_event event)
  2628. {
  2629. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  2630. bfa_trc(ms->port->fcs, event);
  2631. switch (event) {
  2632. case MSSM_EVENT_FCXP_SENT:
  2633. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal);
  2634. break;
  2635. case MSSM_EVENT_PORT_OFFLINE:
  2636. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
  2637. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
  2638. &ms->fcxp_wqe);
  2639. break;
  2640. default:
  2641. bfa_sm_fault(ms->port->fcs, event);
  2642. }
  2643. }
  2644. static void
  2645. bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
  2646. enum port_ms_event event)
  2647. {
  2648. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  2649. bfa_trc(ms->port->fcs, event);
  2650. switch (event) {
  2651. case MSSM_EVENT_RSP_ERROR:
  2652. /*
  2653. * Start timer for a delayed retry
  2654. */
  2655. if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
  2656. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_retry);
  2657. ms->port->stats.ms_retries++;
  2658. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
  2659. &ms->timer, bfa_fcs_lport_ms_timeout, ms,
  2660. BFA_FCS_RETRY_TIMEOUT);
  2661. } else {
  2662. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
  2663. bfa_fcs_lport_ms_send_gfn(ms, NULL);
  2664. ms->retry_cnt = 0;
  2665. }
  2666. break;
  2667. case MSSM_EVENT_RSP_OK:
  2668. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
  2669. bfa_fcs_lport_ms_send_gfn(ms, NULL);
  2670. break;
  2671. case MSSM_EVENT_PORT_OFFLINE:
  2672. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
  2673. bfa_fcxp_discard(ms->fcxp);
  2674. break;
  2675. default:
  2676. bfa_sm_fault(ms->port->fcs, event);
  2677. }
  2678. }
  2679. static void
  2680. bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
  2681. enum port_ms_event event)
  2682. {
  2683. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  2684. bfa_trc(ms->port->fcs, event);
  2685. switch (event) {
  2686. case MSSM_EVENT_TIMEOUT:
  2687. /*
  2688. * Retry Timer Expired. Re-send
  2689. */
  2690. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
  2691. bfa_fcs_lport_ms_send_gmal(ms, NULL);
  2692. break;
  2693. case MSSM_EVENT_PORT_OFFLINE:
  2694. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
  2695. bfa_timer_stop(&ms->timer);
  2696. break;
  2697. default:
  2698. bfa_sm_fault(ms->port->fcs, event);
  2699. }
  2700. }
  2701. /*
  2702. * ms_pvt MS local functions
  2703. */
  2704. static void
  2705. bfa_fcs_lport_ms_send_gmal(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  2706. {
  2707. struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
  2708. bfa_fcs_lport_t *port = ms->port;
  2709. struct fchs_s fchs;
  2710. int len;
  2711. struct bfa_fcxp_s *fcxp;
  2712. bfa_trc(port->fcs, port->pid);
  2713. fcxp = fcxp_alloced ? fcxp_alloced :
  2714. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  2715. if (!fcxp) {
  2716. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
  2717. bfa_fcs_lport_ms_send_gmal, ms, BFA_TRUE);
  2718. return;
  2719. }
  2720. ms->fcxp = fcxp;
  2721. len = fc_gmal_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  2722. bfa_fcs_lport_get_fcid(port),
  2723. port->fabric->lps->pr_nwwn);
  2724. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  2725. FC_CLASS_3, len, &fchs,
  2726. bfa_fcs_lport_ms_gmal_response, (void *)ms,
  2727. FC_MAX_PDUSZ, FC_FCCT_TOV);
  2728. bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
  2729. }
  2730. static void
  2731. bfa_fcs_lport_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  2732. void *cbarg, bfa_status_t req_status,
  2733. u32 rsp_len, u32 resid_len,
  2734. struct fchs_s *rsp_fchs)
  2735. {
  2736. struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
  2737. bfa_fcs_lport_t *port = ms->port;
  2738. struct ct_hdr_s *cthdr = NULL;
  2739. struct fcgs_gmal_resp_s *gmal_resp;
  2740. struct fcgs_gmal_entry_s *gmal_entry;
  2741. u32 num_entries;
  2742. u8 *rsp_str;
  2743. bfa_trc(port->fcs, req_status);
  2744. bfa_trc(port->fcs, port->port_cfg.pwwn);
  2745. /*
  2746. * Sanity Checks
  2747. */
  2748. if (req_status != BFA_STATUS_OK) {
  2749. bfa_trc(port->fcs, req_status);
  2750. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  2751. return;
  2752. }
  2753. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  2754. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  2755. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  2756. gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1);
  2757. num_entries = be32_to_cpu(gmal_resp->ms_len);
  2758. if (num_entries == 0) {
  2759. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  2760. return;
  2761. }
  2762. /*
  2763. * The response could contain multiple Entries.
  2764. * Entries for SNMP interface, etc.
  2765. * We look for the entry with a telnet prefix.
  2766. * First "http://" entry refers to IP addr
  2767. */
  2768. gmal_entry = (struct fcgs_gmal_entry_s *)gmal_resp->ms_ma;
  2769. while (num_entries > 0) {
  2770. if (strncmp(gmal_entry->prefix,
  2771. CT_GMAL_RESP_PREFIX_HTTP,
  2772. sizeof(gmal_entry->prefix)) == 0) {
  2773. /*
  2774. * if the IP address is terminating with a '/',
  2775. * remove it.
  2776. * Byte 0 consists of the length of the string.
  2777. */
  2778. rsp_str = &(gmal_entry->prefix[0]);
  2779. if (rsp_str[gmal_entry->len-1] == '/')
  2780. rsp_str[gmal_entry->len-1] = 0;
  2781. /* copy IP Address to fabric */
  2782. strncpy(bfa_fcs_lport_get_fabric_ipaddr(port),
  2783. gmal_entry->ip_addr,
  2784. BFA_FCS_FABRIC_IPADDR_SZ);
  2785. break;
  2786. } else {
  2787. --num_entries;
  2788. ++gmal_entry;
  2789. }
  2790. }
  2791. bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
  2792. return;
  2793. }
  2794. bfa_trc(port->fcs, cthdr->reason_code);
  2795. bfa_trc(port->fcs, cthdr->exp_code);
  2796. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  2797. }
  2798. static void
  2799. bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
  2800. enum port_ms_event event)
  2801. {
  2802. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  2803. bfa_trc(ms->port->fcs, event);
  2804. switch (event) {
  2805. case MSSM_EVENT_FCXP_SENT:
  2806. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn);
  2807. break;
  2808. case MSSM_EVENT_PORT_OFFLINE:
  2809. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
  2810. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
  2811. &ms->fcxp_wqe);
  2812. break;
  2813. default:
  2814. bfa_sm_fault(ms->port->fcs, event);
  2815. }
  2816. }
  2817. static void
  2818. bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
  2819. enum port_ms_event event)
  2820. {
  2821. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  2822. bfa_trc(ms->port->fcs, event);
  2823. switch (event) {
  2824. case MSSM_EVENT_RSP_ERROR:
  2825. /*
  2826. * Start timer for a delayed retry
  2827. */
  2828. if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
  2829. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_retry);
  2830. ms->port->stats.ms_retries++;
  2831. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
  2832. &ms->timer, bfa_fcs_lport_ms_timeout, ms,
  2833. BFA_FCS_RETRY_TIMEOUT);
  2834. } else {
  2835. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
  2836. ms->retry_cnt = 0;
  2837. }
  2838. break;
  2839. case MSSM_EVENT_RSP_OK:
  2840. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
  2841. break;
  2842. case MSSM_EVENT_PORT_OFFLINE:
  2843. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
  2844. bfa_fcxp_discard(ms->fcxp);
  2845. break;
  2846. default:
  2847. bfa_sm_fault(ms->port->fcs, event);
  2848. }
  2849. }
  2850. static void
  2851. bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
  2852. enum port_ms_event event)
  2853. {
  2854. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  2855. bfa_trc(ms->port->fcs, event);
  2856. switch (event) {
  2857. case MSSM_EVENT_TIMEOUT:
  2858. /*
  2859. * Retry Timer Expired. Re-send
  2860. */
  2861. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
  2862. bfa_fcs_lport_ms_send_gfn(ms, NULL);
  2863. break;
  2864. case MSSM_EVENT_PORT_OFFLINE:
  2865. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
  2866. bfa_timer_stop(&ms->timer);
  2867. break;
  2868. default:
  2869. bfa_sm_fault(ms->port->fcs, event);
  2870. }
  2871. }
  2872. /*
  2873. * ms_pvt MS local functions
  2874. */
  2875. static void
  2876. bfa_fcs_lport_ms_send_gfn(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  2877. {
  2878. struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
  2879. bfa_fcs_lport_t *port = ms->port;
  2880. struct fchs_s fchs;
  2881. int len;
  2882. struct bfa_fcxp_s *fcxp;
  2883. bfa_trc(port->fcs, port->pid);
  2884. fcxp = fcxp_alloced ? fcxp_alloced :
  2885. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  2886. if (!fcxp) {
  2887. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
  2888. bfa_fcs_lport_ms_send_gfn, ms, BFA_TRUE);
  2889. return;
  2890. }
  2891. ms->fcxp = fcxp;
  2892. len = fc_gfn_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  2893. bfa_fcs_lport_get_fcid(port),
  2894. port->fabric->lps->pr_nwwn);
  2895. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  2896. FC_CLASS_3, len, &fchs,
  2897. bfa_fcs_lport_ms_gfn_response, (void *)ms,
  2898. FC_MAX_PDUSZ, FC_FCCT_TOV);
  2899. bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
  2900. }
  2901. static void
  2902. bfa_fcs_lport_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  2903. void *cbarg, bfa_status_t req_status, u32 rsp_len,
  2904. u32 resid_len, struct fchs_s *rsp_fchs)
  2905. {
  2906. struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
  2907. bfa_fcs_lport_t *port = ms->port;
  2908. struct ct_hdr_s *cthdr = NULL;
  2909. wwn_t *gfn_resp;
  2910. bfa_trc(port->fcs, req_status);
  2911. bfa_trc(port->fcs, port->port_cfg.pwwn);
  2912. /*
  2913. * Sanity Checks
  2914. */
  2915. if (req_status != BFA_STATUS_OK) {
  2916. bfa_trc(port->fcs, req_status);
  2917. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  2918. return;
  2919. }
  2920. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  2921. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  2922. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  2923. gfn_resp = (wwn_t *)(cthdr + 1);
  2924. /* check if it has actually changed */
  2925. if ((memcmp((void *)&bfa_fcs_lport_get_fabric_name(port),
  2926. gfn_resp, sizeof(wwn_t)) != 0)) {
  2927. bfa_fcs_fabric_set_fabric_name(port->fabric, *gfn_resp);
  2928. }
  2929. bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
  2930. return;
  2931. }
  2932. bfa_trc(port->fcs, cthdr->reason_code);
  2933. bfa_trc(port->fcs, cthdr->exp_code);
  2934. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  2935. }
  2936. /*
  2937. * ms_pvt MS local functions
  2938. */
  2939. static void
  2940. bfa_fcs_lport_ms_send_plogi(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  2941. {
  2942. struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
  2943. struct bfa_fcs_lport_s *port = ms->port;
  2944. struct fchs_s fchs;
  2945. int len;
  2946. struct bfa_fcxp_s *fcxp;
  2947. bfa_trc(port->fcs, port->pid);
  2948. fcxp = fcxp_alloced ? fcxp_alloced :
  2949. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  2950. if (!fcxp) {
  2951. port->stats.ms_plogi_alloc_wait++;
  2952. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
  2953. bfa_fcs_lport_ms_send_plogi, ms, BFA_TRUE);
  2954. return;
  2955. }
  2956. ms->fcxp = fcxp;
  2957. len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  2958. bfa_hton3b(FC_MGMT_SERVER),
  2959. bfa_fcs_lport_get_fcid(port), 0,
  2960. port->port_cfg.pwwn, port->port_cfg.nwwn,
  2961. bfa_fcport_get_maxfrsize(port->fcs->bfa),
  2962. bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
  2963. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  2964. FC_CLASS_3, len, &fchs,
  2965. bfa_fcs_lport_ms_plogi_response, (void *)ms,
  2966. FC_MAX_PDUSZ, FC_ELS_TOV);
  2967. port->stats.ms_plogi_sent++;
  2968. bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
  2969. }
  2970. static void
  2971. bfa_fcs_lport_ms_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  2972. void *cbarg, bfa_status_t req_status,
  2973. u32 rsp_len, u32 resid_len, struct fchs_s *rsp_fchs)
  2974. {
  2975. struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
  2976. struct bfa_fcs_lport_s *port = ms->port;
  2977. struct fc_els_cmd_s *els_cmd;
  2978. struct fc_ls_rjt_s *ls_rjt;
  2979. bfa_trc(port->fcs, req_status);
  2980. bfa_trc(port->fcs, port->port_cfg.pwwn);
  2981. /*
  2982. * Sanity Checks
  2983. */
  2984. if (req_status != BFA_STATUS_OK) {
  2985. port->stats.ms_plogi_rsp_err++;
  2986. bfa_trc(port->fcs, req_status);
  2987. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  2988. return;
  2989. }
  2990. els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
  2991. switch (els_cmd->els_code) {
  2992. case FC_ELS_ACC:
  2993. if (rsp_len < sizeof(struct fc_logi_s)) {
  2994. bfa_trc(port->fcs, rsp_len);
  2995. port->stats.ms_plogi_acc_err++;
  2996. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  2997. break;
  2998. }
  2999. port->stats.ms_plogi_accepts++;
  3000. bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
  3001. break;
  3002. case FC_ELS_LS_RJT:
  3003. ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  3004. bfa_trc(port->fcs, ls_rjt->reason_code);
  3005. bfa_trc(port->fcs, ls_rjt->reason_code_expl);
  3006. port->stats.ms_rejects++;
  3007. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  3008. break;
  3009. default:
  3010. port->stats.ms_plogi_unknown_rsp++;
  3011. bfa_trc(port->fcs, els_cmd->els_code);
  3012. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  3013. }
  3014. }
  3015. static void
  3016. bfa_fcs_lport_ms_timeout(void *arg)
  3017. {
  3018. struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) arg;
  3019. ms->port->stats.ms_timeouts++;
  3020. bfa_sm_send_event(ms, MSSM_EVENT_TIMEOUT);
  3021. }
  3022. void
  3023. bfa_fcs_lport_ms_init(struct bfa_fcs_lport_s *port)
  3024. {
  3025. struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
  3026. ms->port = port;
  3027. bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
  3028. /*
  3029. * Invoke init routines of sub modules.
  3030. */
  3031. bfa_fcs_lport_fdmi_init(ms);
  3032. }
  3033. void
  3034. bfa_fcs_lport_ms_offline(struct bfa_fcs_lport_s *port)
  3035. {
  3036. struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
  3037. ms->port = port;
  3038. bfa_sm_send_event(ms, MSSM_EVENT_PORT_OFFLINE);
  3039. bfa_fcs_lport_fdmi_offline(ms);
  3040. }
  3041. void
  3042. bfa_fcs_lport_ms_online(struct bfa_fcs_lport_s *port)
  3043. {
  3044. struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
  3045. ms->port = port;
  3046. bfa_sm_send_event(ms, MSSM_EVENT_PORT_ONLINE);
  3047. }
  3048. void
  3049. bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s *port)
  3050. {
  3051. struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
  3052. /* todo. Handle this only when in Online state */
  3053. if (bfa_sm_cmp_state(ms, bfa_fcs_lport_ms_sm_online))
  3054. bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN);
  3055. }
  3056. /*
  3057. * @page ns_sm_info VPORT NS State Machine
  3058. *
  3059. * @section ns_sm_interactions VPORT NS State Machine Interactions
  3060. *
  3061. * @section ns_sm VPORT NS State Machine
  3062. * img ns_sm.jpg
  3063. */
  3064. /*
  3065. * forward declarations
  3066. */
  3067. static void bfa_fcs_lport_ns_send_plogi(void *ns_cbarg,
  3068. struct bfa_fcxp_s *fcxp_alloced);
  3069. static void bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg,
  3070. struct bfa_fcxp_s *fcxp_alloced);
  3071. static void bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg,
  3072. struct bfa_fcxp_s *fcxp_alloced);
  3073. static void bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg,
  3074. struct bfa_fcxp_s *fcxp_alloced);
  3075. static void bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg,
  3076. struct bfa_fcxp_s *fcxp_alloced);
  3077. static void bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg,
  3078. struct bfa_fcxp_s *fcxp_alloced);
  3079. static void bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg,
  3080. struct bfa_fcxp_s *fcxp_alloced);
  3081. static void bfa_fcs_lport_ns_timeout(void *arg);
  3082. static void bfa_fcs_lport_ns_plogi_response(void *fcsarg,
  3083. struct bfa_fcxp_s *fcxp,
  3084. void *cbarg,
  3085. bfa_status_t req_status,
  3086. u32 rsp_len,
  3087. u32 resid_len,
  3088. struct fchs_s *rsp_fchs);
  3089. static void bfa_fcs_lport_ns_rspn_id_response(void *fcsarg,
  3090. struct bfa_fcxp_s *fcxp,
  3091. void *cbarg,
  3092. bfa_status_t req_status,
  3093. u32 rsp_len,
  3094. u32 resid_len,
  3095. struct fchs_s *rsp_fchs);
  3096. static void bfa_fcs_lport_ns_rft_id_response(void *fcsarg,
  3097. struct bfa_fcxp_s *fcxp,
  3098. void *cbarg,
  3099. bfa_status_t req_status,
  3100. u32 rsp_len,
  3101. u32 resid_len,
  3102. struct fchs_s *rsp_fchs);
  3103. static void bfa_fcs_lport_ns_rff_id_response(void *fcsarg,
  3104. struct bfa_fcxp_s *fcxp,
  3105. void *cbarg,
  3106. bfa_status_t req_status,
  3107. u32 rsp_len,
  3108. u32 resid_len,
  3109. struct fchs_s *rsp_fchs);
  3110. static void bfa_fcs_lport_ns_gid_ft_response(void *fcsarg,
  3111. struct bfa_fcxp_s *fcxp,
  3112. void *cbarg,
  3113. bfa_status_t req_status,
  3114. u32 rsp_len,
  3115. u32 resid_len,
  3116. struct fchs_s *rsp_fchs);
  3117. static void bfa_fcs_lport_ns_rnn_id_response(void *fcsarg,
  3118. struct bfa_fcxp_s *fcxp,
  3119. void *cbarg,
  3120. bfa_status_t req_status,
  3121. u32 rsp_len,
  3122. u32 resid_len,
  3123. struct fchs_s *rsp_fchs);
  3124. static void bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg,
  3125. struct bfa_fcxp_s *fcxp,
  3126. void *cbarg,
  3127. bfa_status_t req_status,
  3128. u32 rsp_len,
  3129. u32 resid_len,
  3130. struct fchs_s *rsp_fchs);
  3131. static void bfa_fcs_lport_ns_process_gidft_pids(
  3132. struct bfa_fcs_lport_s *port,
  3133. u32 *pid_buf, u32 n_pids);
  3134. static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port);
  3135. /*
  3136. * fcs_ns_sm FCS nameserver interface state machine
  3137. */
  3138. /*
  3139. * VPort NS State Machine events
  3140. */
  3141. enum vport_ns_event {
  3142. NSSM_EVENT_PORT_ONLINE = 1,
  3143. NSSM_EVENT_PORT_OFFLINE = 2,
  3144. NSSM_EVENT_PLOGI_SENT = 3,
  3145. NSSM_EVENT_RSP_OK = 4,
  3146. NSSM_EVENT_RSP_ERROR = 5,
  3147. NSSM_EVENT_TIMEOUT = 6,
  3148. NSSM_EVENT_NS_QUERY = 7,
  3149. NSSM_EVENT_RSPNID_SENT = 8,
  3150. NSSM_EVENT_RFTID_SENT = 9,
  3151. NSSM_EVENT_RFFID_SENT = 10,
  3152. NSSM_EVENT_GIDFT_SENT = 11,
  3153. NSSM_EVENT_RNNID_SENT = 12,
  3154. NSSM_EVENT_RSNN_NN_SENT = 13,
  3155. };
  3156. static void bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
  3157. enum vport_ns_event event);
  3158. static void bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
  3159. enum vport_ns_event event);
  3160. static void bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
  3161. enum vport_ns_event event);
  3162. static void bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
  3163. enum vport_ns_event event);
  3164. static void bfa_fcs_lport_ns_sm_sending_rspn_id(
  3165. struct bfa_fcs_lport_ns_s *ns,
  3166. enum vport_ns_event event);
  3167. static void bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
  3168. enum vport_ns_event event);
  3169. static void bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
  3170. enum vport_ns_event event);
  3171. static void bfa_fcs_lport_ns_sm_sending_rft_id(
  3172. struct bfa_fcs_lport_ns_s *ns,
  3173. enum vport_ns_event event);
  3174. static void bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
  3175. enum vport_ns_event event);
  3176. static void bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
  3177. enum vport_ns_event event);
  3178. static void bfa_fcs_lport_ns_sm_sending_rff_id(
  3179. struct bfa_fcs_lport_ns_s *ns,
  3180. enum vport_ns_event event);
  3181. static void bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
  3182. enum vport_ns_event event);
  3183. static void bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
  3184. enum vport_ns_event event);
  3185. static void bfa_fcs_lport_ns_sm_sending_gid_ft(
  3186. struct bfa_fcs_lport_ns_s *ns,
  3187. enum vport_ns_event event);
  3188. static void bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
  3189. enum vport_ns_event event);
  3190. static void bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
  3191. enum vport_ns_event event);
  3192. static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
  3193. enum vport_ns_event event);
  3194. static void bfa_fcs_lport_ns_sm_sending_rnn_id(
  3195. struct bfa_fcs_lport_ns_s *ns,
  3196. enum vport_ns_event event);
  3197. static void bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
  3198. enum vport_ns_event event);
  3199. static void bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
  3200. enum vport_ns_event event);
  3201. static void bfa_fcs_lport_ns_sm_sending_rsnn_nn(
  3202. struct bfa_fcs_lport_ns_s *ns,
  3203. enum vport_ns_event event);
  3204. static void bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
  3205. enum vport_ns_event event);
  3206. static void bfa_fcs_lport_ns_sm_rsnn_nn_retry(
  3207. struct bfa_fcs_lport_ns_s *ns,
  3208. enum vport_ns_event event);
  3209. /*
  3210. * Start in offline state - awaiting linkup
  3211. */
  3212. static void
  3213. bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
  3214. enum vport_ns_event event)
  3215. {
  3216. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3217. bfa_trc(ns->port->fcs, event);
  3218. switch (event) {
  3219. case NSSM_EVENT_PORT_ONLINE:
  3220. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
  3221. bfa_fcs_lport_ns_send_plogi(ns, NULL);
  3222. break;
  3223. case NSSM_EVENT_PORT_OFFLINE:
  3224. break;
  3225. default:
  3226. bfa_sm_fault(ns->port->fcs, event);
  3227. }
  3228. }
  3229. static void
  3230. bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
  3231. enum vport_ns_event event)
  3232. {
  3233. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3234. bfa_trc(ns->port->fcs, event);
  3235. switch (event) {
  3236. case NSSM_EVENT_PLOGI_SENT:
  3237. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi);
  3238. break;
  3239. case NSSM_EVENT_PORT_OFFLINE:
  3240. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3241. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3242. &ns->fcxp_wqe);
  3243. break;
  3244. default:
  3245. bfa_sm_fault(ns->port->fcs, event);
  3246. }
  3247. }
  3248. static void
  3249. bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
  3250. enum vport_ns_event event)
  3251. {
  3252. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3253. bfa_trc(ns->port->fcs, event);
  3254. switch (event) {
  3255. case NSSM_EVENT_RSP_ERROR:
  3256. /*
  3257. * Start timer for a delayed retry
  3258. */
  3259. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_retry);
  3260. ns->port->stats.ns_retries++;
  3261. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3262. &ns->timer, bfa_fcs_lport_ns_timeout, ns,
  3263. BFA_FCS_RETRY_TIMEOUT);
  3264. break;
  3265. case NSSM_EVENT_RSP_OK:
  3266. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
  3267. ns->num_rnnid_retries = 0;
  3268. bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
  3269. break;
  3270. case NSSM_EVENT_PORT_OFFLINE:
  3271. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3272. bfa_fcxp_discard(ns->fcxp);
  3273. break;
  3274. default:
  3275. bfa_sm_fault(ns->port->fcs, event);
  3276. }
  3277. }
  3278. static void
  3279. bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
  3280. enum vport_ns_event event)
  3281. {
  3282. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3283. bfa_trc(ns->port->fcs, event);
  3284. switch (event) {
  3285. case NSSM_EVENT_TIMEOUT:
  3286. /*
  3287. * Retry Timer Expired. Re-send
  3288. */
  3289. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
  3290. bfa_fcs_lport_ns_send_plogi(ns, NULL);
  3291. break;
  3292. case NSSM_EVENT_PORT_OFFLINE:
  3293. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3294. bfa_timer_stop(&ns->timer);
  3295. break;
  3296. default:
  3297. bfa_sm_fault(ns->port->fcs, event);
  3298. }
  3299. }
  3300. static void
  3301. bfa_fcs_lport_ns_sm_sending_rnn_id(struct bfa_fcs_lport_ns_s *ns,
  3302. enum vport_ns_event event)
  3303. {
  3304. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3305. bfa_trc(ns->port->fcs, event);
  3306. switch (event) {
  3307. case NSSM_EVENT_RNNID_SENT:
  3308. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id);
  3309. break;
  3310. case NSSM_EVENT_PORT_OFFLINE:
  3311. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3312. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3313. &ns->fcxp_wqe);
  3314. break;
  3315. default:
  3316. bfa_sm_fault(ns->port->fcs, event);
  3317. }
  3318. }
  3319. static void
  3320. bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
  3321. enum vport_ns_event event)
  3322. {
  3323. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3324. bfa_trc(ns->port->fcs, event);
  3325. switch (event) {
  3326. case NSSM_EVENT_RSP_OK:
  3327. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
  3328. ns->num_rnnid_retries = 0;
  3329. ns->num_rsnn_nn_retries = 0;
  3330. bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
  3331. break;
  3332. case NSSM_EVENT_RSP_ERROR:
  3333. if (ns->num_rnnid_retries < BFA_FCS_MAX_NS_RETRIES) {
  3334. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id_retry);
  3335. ns->port->stats.ns_retries++;
  3336. ns->num_rnnid_retries++;
  3337. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3338. &ns->timer, bfa_fcs_lport_ns_timeout, ns,
  3339. BFA_FCS_RETRY_TIMEOUT);
  3340. } else {
  3341. bfa_sm_set_state(ns,
  3342. bfa_fcs_lport_ns_sm_sending_rspn_id);
  3343. bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
  3344. }
  3345. break;
  3346. case NSSM_EVENT_PORT_OFFLINE:
  3347. bfa_fcxp_discard(ns->fcxp);
  3348. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3349. break;
  3350. default:
  3351. bfa_sm_fault(ns->port->fcs, event);
  3352. }
  3353. }
  3354. static void
  3355. bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
  3356. enum vport_ns_event event)
  3357. {
  3358. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3359. bfa_trc(ns->port->fcs, event);
  3360. switch (event) {
  3361. case NSSM_EVENT_TIMEOUT:
  3362. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
  3363. bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
  3364. break;
  3365. case NSSM_EVENT_PORT_OFFLINE:
  3366. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3367. bfa_timer_stop(&ns->timer);
  3368. break;
  3369. default:
  3370. bfa_sm_fault(ns->port->fcs, event);
  3371. }
  3372. }
  3373. static void
  3374. bfa_fcs_lport_ns_sm_sending_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
  3375. enum vport_ns_event event)
  3376. {
  3377. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3378. bfa_trc(ns->port->fcs, event);
  3379. switch (event) {
  3380. case NSSM_EVENT_RSNN_NN_SENT:
  3381. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn);
  3382. break;
  3383. case NSSM_EVENT_PORT_OFFLINE:
  3384. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3385. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3386. &ns->fcxp_wqe);
  3387. break;
  3388. default:
  3389. bfa_sm_fault(ns->port->fcs, event);
  3390. }
  3391. }
  3392. static void
  3393. bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
  3394. enum vport_ns_event event)
  3395. {
  3396. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3397. bfa_trc(ns->port->fcs, event);
  3398. switch (event) {
  3399. case NSSM_EVENT_RSP_OK:
  3400. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
  3401. ns->num_rsnn_nn_retries = 0;
  3402. bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
  3403. break;
  3404. case NSSM_EVENT_RSP_ERROR:
  3405. if (ns->num_rsnn_nn_retries < BFA_FCS_MAX_NS_RETRIES) {
  3406. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn_retry);
  3407. ns->port->stats.ns_retries++;
  3408. ns->num_rsnn_nn_retries++;
  3409. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3410. &ns->timer, bfa_fcs_lport_ns_timeout,
  3411. ns, BFA_FCS_RETRY_TIMEOUT);
  3412. } else {
  3413. bfa_sm_set_state(ns,
  3414. bfa_fcs_lport_ns_sm_sending_rspn_id);
  3415. bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
  3416. }
  3417. break;
  3418. case NSSM_EVENT_PORT_OFFLINE:
  3419. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3420. bfa_fcxp_discard(ns->fcxp);
  3421. break;
  3422. default:
  3423. bfa_sm_fault(ns->port->fcs, event);
  3424. }
  3425. }
  3426. static void
  3427. bfa_fcs_lport_ns_sm_rsnn_nn_retry(struct bfa_fcs_lport_ns_s *ns,
  3428. enum vport_ns_event event)
  3429. {
  3430. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3431. bfa_trc(ns->port->fcs, event);
  3432. switch (event) {
  3433. case NSSM_EVENT_TIMEOUT:
  3434. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
  3435. bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
  3436. break;
  3437. case NSSM_EVENT_PORT_OFFLINE:
  3438. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3439. bfa_timer_stop(&ns->timer);
  3440. break;
  3441. default:
  3442. bfa_sm_fault(ns->port->fcs, event);
  3443. }
  3444. }
  3445. static void
  3446. bfa_fcs_lport_ns_sm_sending_rspn_id(struct bfa_fcs_lport_ns_s *ns,
  3447. enum vport_ns_event event)
  3448. {
  3449. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3450. bfa_trc(ns->port->fcs, event);
  3451. switch (event) {
  3452. case NSSM_EVENT_RSPNID_SENT:
  3453. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id);
  3454. break;
  3455. case NSSM_EVENT_PORT_OFFLINE:
  3456. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3457. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3458. &ns->fcxp_wqe);
  3459. break;
  3460. default:
  3461. bfa_sm_fault(ns->port->fcs, event);
  3462. }
  3463. }
  3464. static void
  3465. bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
  3466. enum vport_ns_event event)
  3467. {
  3468. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3469. bfa_trc(ns->port->fcs, event);
  3470. switch (event) {
  3471. case NSSM_EVENT_RSP_ERROR:
  3472. /*
  3473. * Start timer for a delayed retry
  3474. */
  3475. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry);
  3476. ns->port->stats.ns_retries++;
  3477. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3478. &ns->timer, bfa_fcs_lport_ns_timeout, ns,
  3479. BFA_FCS_RETRY_TIMEOUT);
  3480. break;
  3481. case NSSM_EVENT_RSP_OK:
  3482. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
  3483. bfa_fcs_lport_ns_send_rft_id(ns, NULL);
  3484. break;
  3485. case NSSM_EVENT_PORT_OFFLINE:
  3486. bfa_fcxp_discard(ns->fcxp);
  3487. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3488. break;
  3489. default:
  3490. bfa_sm_fault(ns->port->fcs, event);
  3491. }
  3492. }
  3493. static void
  3494. bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
  3495. enum vport_ns_event event)
  3496. {
  3497. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3498. bfa_trc(ns->port->fcs, event);
  3499. switch (event) {
  3500. case NSSM_EVENT_TIMEOUT:
  3501. /*
  3502. * Retry Timer Expired. Re-send
  3503. */
  3504. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
  3505. bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
  3506. break;
  3507. case NSSM_EVENT_PORT_OFFLINE:
  3508. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3509. bfa_timer_stop(&ns->timer);
  3510. break;
  3511. default:
  3512. bfa_sm_fault(ns->port->fcs, event);
  3513. }
  3514. }
  3515. static void
  3516. bfa_fcs_lport_ns_sm_sending_rft_id(struct bfa_fcs_lport_ns_s *ns,
  3517. enum vport_ns_event event)
  3518. {
  3519. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3520. bfa_trc(ns->port->fcs, event);
  3521. switch (event) {
  3522. case NSSM_EVENT_RFTID_SENT:
  3523. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id);
  3524. break;
  3525. case NSSM_EVENT_PORT_OFFLINE:
  3526. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3527. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3528. &ns->fcxp_wqe);
  3529. break;
  3530. default:
  3531. bfa_sm_fault(ns->port->fcs, event);
  3532. }
  3533. }
  3534. static void
  3535. bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
  3536. enum vport_ns_event event)
  3537. {
  3538. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3539. bfa_trc(ns->port->fcs, event);
  3540. switch (event) {
  3541. case NSSM_EVENT_RSP_OK:
  3542. /* Now move to register FC4 Features */
  3543. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
  3544. bfa_fcs_lport_ns_send_rff_id(ns, NULL);
  3545. break;
  3546. case NSSM_EVENT_RSP_ERROR:
  3547. /*
  3548. * Start timer for a delayed retry
  3549. */
  3550. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id_retry);
  3551. ns->port->stats.ns_retries++;
  3552. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3553. &ns->timer, bfa_fcs_lport_ns_timeout, ns,
  3554. BFA_FCS_RETRY_TIMEOUT);
  3555. break;
  3556. case NSSM_EVENT_PORT_OFFLINE:
  3557. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3558. bfa_fcxp_discard(ns->fcxp);
  3559. break;
  3560. default:
  3561. bfa_sm_fault(ns->port->fcs, event);
  3562. }
  3563. }
  3564. static void
  3565. bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
  3566. enum vport_ns_event event)
  3567. {
  3568. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3569. bfa_trc(ns->port->fcs, event);
  3570. switch (event) {
  3571. case NSSM_EVENT_TIMEOUT:
  3572. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
  3573. bfa_fcs_lport_ns_send_rft_id(ns, NULL);
  3574. break;
  3575. case NSSM_EVENT_PORT_OFFLINE:
  3576. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3577. bfa_timer_stop(&ns->timer);
  3578. break;
  3579. default:
  3580. bfa_sm_fault(ns->port->fcs, event);
  3581. }
  3582. }
  3583. static void
  3584. bfa_fcs_lport_ns_sm_sending_rff_id(struct bfa_fcs_lport_ns_s *ns,
  3585. enum vport_ns_event event)
  3586. {
  3587. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3588. bfa_trc(ns->port->fcs, event);
  3589. switch (event) {
  3590. case NSSM_EVENT_RFFID_SENT:
  3591. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id);
  3592. break;
  3593. case NSSM_EVENT_PORT_OFFLINE:
  3594. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3595. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3596. &ns->fcxp_wqe);
  3597. break;
  3598. default:
  3599. bfa_sm_fault(ns->port->fcs, event);
  3600. }
  3601. }
  3602. static void
  3603. bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
  3604. enum vport_ns_event event)
  3605. {
  3606. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3607. bfa_trc(ns->port->fcs, event);
  3608. switch (event) {
  3609. case NSSM_EVENT_RSP_OK:
  3610. /*
  3611. * If min cfg mode is enabled, we donot initiate rport
  3612. * discovery with the fabric. Instead, we will retrieve the
  3613. * boot targets from HAL/FW.
  3614. */
  3615. if (__fcs_min_cfg(ns->port->fcs)) {
  3616. bfa_fcs_lport_ns_boot_target_disc(ns->port);
  3617. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
  3618. return;
  3619. }
  3620. /*
  3621. * If the port role is Initiator Mode issue NS query.
  3622. * If it is Target Mode, skip this and go to online.
  3623. */
  3624. if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
  3625. bfa_sm_set_state(ns,
  3626. bfa_fcs_lport_ns_sm_sending_gid_ft);
  3627. bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
  3628. }
  3629. /*
  3630. * kick off mgmt srvr state machine
  3631. */
  3632. bfa_fcs_lport_ms_online(ns->port);
  3633. break;
  3634. case NSSM_EVENT_RSP_ERROR:
  3635. /*
  3636. * Start timer for a delayed retry
  3637. */
  3638. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id_retry);
  3639. ns->port->stats.ns_retries++;
  3640. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3641. &ns->timer, bfa_fcs_lport_ns_timeout, ns,
  3642. BFA_FCS_RETRY_TIMEOUT);
  3643. break;
  3644. case NSSM_EVENT_PORT_OFFLINE:
  3645. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3646. bfa_fcxp_discard(ns->fcxp);
  3647. break;
  3648. default:
  3649. bfa_sm_fault(ns->port->fcs, event);
  3650. }
  3651. }
  3652. static void
  3653. bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
  3654. enum vport_ns_event event)
  3655. {
  3656. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3657. bfa_trc(ns->port->fcs, event);
  3658. switch (event) {
  3659. case NSSM_EVENT_TIMEOUT:
  3660. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
  3661. bfa_fcs_lport_ns_send_rff_id(ns, NULL);
  3662. break;
  3663. case NSSM_EVENT_PORT_OFFLINE:
  3664. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3665. bfa_timer_stop(&ns->timer);
  3666. break;
  3667. default:
  3668. bfa_sm_fault(ns->port->fcs, event);
  3669. }
  3670. }
  3671. static void
  3672. bfa_fcs_lport_ns_sm_sending_gid_ft(struct bfa_fcs_lport_ns_s *ns,
  3673. enum vport_ns_event event)
  3674. {
  3675. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3676. bfa_trc(ns->port->fcs, event);
  3677. switch (event) {
  3678. case NSSM_EVENT_GIDFT_SENT:
  3679. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft);
  3680. break;
  3681. case NSSM_EVENT_PORT_OFFLINE:
  3682. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3683. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3684. &ns->fcxp_wqe);
  3685. break;
  3686. default:
  3687. bfa_sm_fault(ns->port->fcs, event);
  3688. }
  3689. }
  3690. static void
  3691. bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
  3692. enum vport_ns_event event)
  3693. {
  3694. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3695. bfa_trc(ns->port->fcs, event);
  3696. switch (event) {
  3697. case NSSM_EVENT_RSP_OK:
  3698. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
  3699. break;
  3700. case NSSM_EVENT_RSP_ERROR:
  3701. /*
  3702. * TBD: for certain reject codes, we don't need to retry
  3703. */
  3704. /*
  3705. * Start timer for a delayed retry
  3706. */
  3707. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft_retry);
  3708. ns->port->stats.ns_retries++;
  3709. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
  3710. &ns->timer, bfa_fcs_lport_ns_timeout, ns,
  3711. BFA_FCS_RETRY_TIMEOUT);
  3712. break;
  3713. case NSSM_EVENT_PORT_OFFLINE:
  3714. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3715. bfa_fcxp_discard(ns->fcxp);
  3716. break;
  3717. case NSSM_EVENT_NS_QUERY:
  3718. break;
  3719. default:
  3720. bfa_sm_fault(ns->port->fcs, event);
  3721. }
  3722. }
  3723. static void
  3724. bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
  3725. enum vport_ns_event event)
  3726. {
  3727. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3728. bfa_trc(ns->port->fcs, event);
  3729. switch (event) {
  3730. case NSSM_EVENT_TIMEOUT:
  3731. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_gid_ft);
  3732. bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
  3733. break;
  3734. case NSSM_EVENT_PORT_OFFLINE:
  3735. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3736. bfa_timer_stop(&ns->timer);
  3737. break;
  3738. default:
  3739. bfa_sm_fault(ns->port->fcs, event);
  3740. }
  3741. }
  3742. static void
  3743. bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
  3744. enum vport_ns_event event)
  3745. {
  3746. bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
  3747. bfa_trc(ns->port->fcs, event);
  3748. switch (event) {
  3749. case NSSM_EVENT_PORT_OFFLINE:
  3750. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  3751. break;
  3752. case NSSM_EVENT_NS_QUERY:
  3753. /*
  3754. * If the port role is Initiator Mode issue NS query.
  3755. * If it is Target Mode, skip this and go to online.
  3756. */
  3757. if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
  3758. bfa_sm_set_state(ns,
  3759. bfa_fcs_lport_ns_sm_sending_gid_ft);
  3760. bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
  3761. };
  3762. break;
  3763. default:
  3764. bfa_sm_fault(ns->port->fcs, event);
  3765. }
  3766. }
  3767. /*
  3768. * ns_pvt Nameserver local functions
  3769. */
  3770. static void
  3771. bfa_fcs_lport_ns_send_plogi(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  3772. {
  3773. struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
  3774. struct bfa_fcs_lport_s *port = ns->port;
  3775. struct fchs_s fchs;
  3776. int len;
  3777. struct bfa_fcxp_s *fcxp;
  3778. bfa_trc(port->fcs, port->pid);
  3779. fcxp = fcxp_alloced ? fcxp_alloced :
  3780. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  3781. if (!fcxp) {
  3782. port->stats.ns_plogi_alloc_wait++;
  3783. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
  3784. bfa_fcs_lport_ns_send_plogi, ns, BFA_TRUE);
  3785. return;
  3786. }
  3787. ns->fcxp = fcxp;
  3788. len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  3789. bfa_hton3b(FC_NAME_SERVER),
  3790. bfa_fcs_lport_get_fcid(port), 0,
  3791. port->port_cfg.pwwn, port->port_cfg.nwwn,
  3792. bfa_fcport_get_maxfrsize(port->fcs->bfa),
  3793. bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
  3794. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  3795. FC_CLASS_3, len, &fchs,
  3796. bfa_fcs_lport_ns_plogi_response, (void *)ns,
  3797. FC_MAX_PDUSZ, FC_ELS_TOV);
  3798. port->stats.ns_plogi_sent++;
  3799. bfa_sm_send_event(ns, NSSM_EVENT_PLOGI_SENT);
  3800. }
  3801. static void
  3802. bfa_fcs_lport_ns_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  3803. void *cbarg, bfa_status_t req_status, u32 rsp_len,
  3804. u32 resid_len, struct fchs_s *rsp_fchs)
  3805. {
  3806. struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
  3807. struct bfa_fcs_lport_s *port = ns->port;
  3808. /* struct fc_logi_s *plogi_resp; */
  3809. struct fc_els_cmd_s *els_cmd;
  3810. struct fc_ls_rjt_s *ls_rjt;
  3811. bfa_trc(port->fcs, req_status);
  3812. bfa_trc(port->fcs, port->port_cfg.pwwn);
  3813. /*
  3814. * Sanity Checks
  3815. */
  3816. if (req_status != BFA_STATUS_OK) {
  3817. bfa_trc(port->fcs, req_status);
  3818. port->stats.ns_plogi_rsp_err++;
  3819. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  3820. return;
  3821. }
  3822. els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
  3823. switch (els_cmd->els_code) {
  3824. case FC_ELS_ACC:
  3825. if (rsp_len < sizeof(struct fc_logi_s)) {
  3826. bfa_trc(port->fcs, rsp_len);
  3827. port->stats.ns_plogi_acc_err++;
  3828. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  3829. break;
  3830. }
  3831. port->stats.ns_plogi_accepts++;
  3832. bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
  3833. break;
  3834. case FC_ELS_LS_RJT:
  3835. ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  3836. bfa_trc(port->fcs, ls_rjt->reason_code);
  3837. bfa_trc(port->fcs, ls_rjt->reason_code_expl);
  3838. port->stats.ns_rejects++;
  3839. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  3840. break;
  3841. default:
  3842. port->stats.ns_plogi_unknown_rsp++;
  3843. bfa_trc(port->fcs, els_cmd->els_code);
  3844. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  3845. }
  3846. }
  3847. /*
  3848. * Register node name for port_id
  3849. */
  3850. static void
  3851. bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  3852. {
  3853. struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
  3854. struct bfa_fcs_lport_s *port = ns->port;
  3855. struct fchs_s fchs;
  3856. int len;
  3857. struct bfa_fcxp_s *fcxp;
  3858. bfa_trc(port->fcs, port->port_cfg.pwwn);
  3859. fcxp = fcxp_alloced ? fcxp_alloced :
  3860. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  3861. if (!fcxp) {
  3862. port->stats.ns_rnnid_alloc_wait++;
  3863. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
  3864. bfa_fcs_lport_ns_send_rnn_id, ns, BFA_TRUE);
  3865. return;
  3866. }
  3867. ns->fcxp = fcxp;
  3868. len = fc_rnnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  3869. bfa_fcs_lport_get_fcid(port),
  3870. bfa_fcs_lport_get_fcid(port),
  3871. bfa_fcs_lport_get_nwwn(port));
  3872. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  3873. FC_CLASS_3, len, &fchs,
  3874. bfa_fcs_lport_ns_rnn_id_response, (void *)ns,
  3875. FC_MAX_PDUSZ, FC_FCCT_TOV);
  3876. port->stats.ns_rnnid_sent++;
  3877. bfa_sm_send_event(ns, NSSM_EVENT_RNNID_SENT);
  3878. }
  3879. static void
  3880. bfa_fcs_lport_ns_rnn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  3881. void *cbarg, bfa_status_t req_status,
  3882. u32 rsp_len, u32 resid_len,
  3883. struct fchs_s *rsp_fchs)
  3884. {
  3885. struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
  3886. struct bfa_fcs_lport_s *port = ns->port;
  3887. struct ct_hdr_s *cthdr = NULL;
  3888. bfa_trc(port->fcs, port->port_cfg.pwwn);
  3889. /*
  3890. * Sanity Checks
  3891. */
  3892. if (req_status != BFA_STATUS_OK) {
  3893. bfa_trc(port->fcs, req_status);
  3894. port->stats.ns_rnnid_rsp_err++;
  3895. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  3896. return;
  3897. }
  3898. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  3899. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  3900. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  3901. port->stats.ns_rnnid_accepts++;
  3902. bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
  3903. return;
  3904. }
  3905. port->stats.ns_rnnid_rejects++;
  3906. bfa_trc(port->fcs, cthdr->reason_code);
  3907. bfa_trc(port->fcs, cthdr->exp_code);
  3908. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  3909. }
  3910. /*
  3911. * Register the symbolic node name for a given node name.
  3912. */
  3913. static void
  3914. bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  3915. {
  3916. struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
  3917. struct bfa_fcs_lport_s *port = ns->port;
  3918. struct fchs_s fchs;
  3919. int len;
  3920. struct bfa_fcxp_s *fcxp;
  3921. u8 *nsymbl;
  3922. bfa_trc(port->fcs, port->port_cfg.pwwn);
  3923. fcxp = fcxp_alloced ? fcxp_alloced :
  3924. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  3925. if (!fcxp) {
  3926. port->stats.ns_rsnn_nn_alloc_wait++;
  3927. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
  3928. bfa_fcs_lport_ns_send_rsnn_nn, ns, BFA_TRUE);
  3929. return;
  3930. }
  3931. ns->fcxp = fcxp;
  3932. nsymbl = (u8 *) &(bfa_fcs_lport_get_nsym_name(
  3933. bfa_fcs_get_base_port(port->fcs)));
  3934. len = fc_rsnn_nn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  3935. bfa_fcs_lport_get_fcid(port),
  3936. bfa_fcs_lport_get_nwwn(port), nsymbl);
  3937. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  3938. FC_CLASS_3, len, &fchs,
  3939. bfa_fcs_lport_ns_rsnn_nn_response, (void *)ns,
  3940. FC_MAX_PDUSZ, FC_FCCT_TOV);
  3941. port->stats.ns_rsnn_nn_sent++;
  3942. bfa_sm_send_event(ns, NSSM_EVENT_RSNN_NN_SENT);
  3943. }
  3944. static void
  3945. bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  3946. void *cbarg, bfa_status_t req_status,
  3947. u32 rsp_len, u32 resid_len,
  3948. struct fchs_s *rsp_fchs)
  3949. {
  3950. struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
  3951. struct bfa_fcs_lport_s *port = ns->port;
  3952. struct ct_hdr_s *cthdr = NULL;
  3953. bfa_trc(port->fcs, port->port_cfg.pwwn);
  3954. /*
  3955. * Sanity Checks
  3956. */
  3957. if (req_status != BFA_STATUS_OK) {
  3958. bfa_trc(port->fcs, req_status);
  3959. port->stats.ns_rsnn_nn_rsp_err++;
  3960. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  3961. return;
  3962. }
  3963. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  3964. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  3965. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  3966. port->stats.ns_rsnn_nn_accepts++;
  3967. bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
  3968. return;
  3969. }
  3970. port->stats.ns_rsnn_nn_rejects++;
  3971. bfa_trc(port->fcs, cthdr->reason_code);
  3972. bfa_trc(port->fcs, cthdr->exp_code);
  3973. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  3974. }
  3975. /*
  3976. * Register the symbolic port name.
  3977. */
  3978. static void
  3979. bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  3980. {
  3981. struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
  3982. struct bfa_fcs_lport_s *port = ns->port;
  3983. struct fchs_s fchs;
  3984. int len;
  3985. struct bfa_fcxp_s *fcxp;
  3986. u8 symbl[256];
  3987. u8 *psymbl = &symbl[0];
  3988. memset(symbl, 0, sizeof(symbl));
  3989. bfa_trc(port->fcs, port->port_cfg.pwwn);
  3990. fcxp = fcxp_alloced ? fcxp_alloced :
  3991. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  3992. if (!fcxp) {
  3993. port->stats.ns_rspnid_alloc_wait++;
  3994. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
  3995. bfa_fcs_lport_ns_send_rspn_id, ns, BFA_TRUE);
  3996. return;
  3997. }
  3998. ns->fcxp = fcxp;
  3999. /*
  4000. * for V-Port, form a Port Symbolic Name
  4001. */
  4002. if (port->vport) {
  4003. /*
  4004. * For Vports, we append the vport's port symbolic name
  4005. * to that of the base port.
  4006. */
  4007. strncpy((char *)psymbl,
  4008. (char *) &
  4009. (bfa_fcs_lport_get_psym_name
  4010. (bfa_fcs_get_base_port(port->fcs))),
  4011. strlen((char *) &
  4012. bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
  4013. (port->fcs))));
  4014. /* Ensure we have a null terminating string. */
  4015. ((char *)psymbl)[strlen((char *) &
  4016. bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
  4017. (port->fcs)))] = 0;
  4018. strncat((char *)psymbl,
  4019. (char *) &(bfa_fcs_lport_get_psym_name(port)),
  4020. strlen((char *) &bfa_fcs_lport_get_psym_name(port)));
  4021. } else {
  4022. psymbl = (u8 *) &(bfa_fcs_lport_get_psym_name(port));
  4023. }
  4024. len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  4025. bfa_fcs_lport_get_fcid(port), 0, psymbl);
  4026. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  4027. FC_CLASS_3, len, &fchs,
  4028. bfa_fcs_lport_ns_rspn_id_response, (void *)ns,
  4029. FC_MAX_PDUSZ, FC_FCCT_TOV);
  4030. port->stats.ns_rspnid_sent++;
  4031. bfa_sm_send_event(ns, NSSM_EVENT_RSPNID_SENT);
  4032. }
  4033. static void
  4034. bfa_fcs_lport_ns_rspn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  4035. void *cbarg, bfa_status_t req_status,
  4036. u32 rsp_len, u32 resid_len,
  4037. struct fchs_s *rsp_fchs)
  4038. {
  4039. struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
  4040. struct bfa_fcs_lport_s *port = ns->port;
  4041. struct ct_hdr_s *cthdr = NULL;
  4042. bfa_trc(port->fcs, port->port_cfg.pwwn);
  4043. /*
  4044. * Sanity Checks
  4045. */
  4046. if (req_status != BFA_STATUS_OK) {
  4047. bfa_trc(port->fcs, req_status);
  4048. port->stats.ns_rspnid_rsp_err++;
  4049. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  4050. return;
  4051. }
  4052. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  4053. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  4054. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  4055. port->stats.ns_rspnid_accepts++;
  4056. bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
  4057. return;
  4058. }
  4059. port->stats.ns_rspnid_rejects++;
  4060. bfa_trc(port->fcs, cthdr->reason_code);
  4061. bfa_trc(port->fcs, cthdr->exp_code);
  4062. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  4063. }
  4064. /*
  4065. * Register FC4-Types
  4066. */
  4067. static void
  4068. bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  4069. {
  4070. struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
  4071. struct bfa_fcs_lport_s *port = ns->port;
  4072. struct fchs_s fchs;
  4073. int len;
  4074. struct bfa_fcxp_s *fcxp;
  4075. bfa_trc(port->fcs, port->port_cfg.pwwn);
  4076. fcxp = fcxp_alloced ? fcxp_alloced :
  4077. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  4078. if (!fcxp) {
  4079. port->stats.ns_rftid_alloc_wait++;
  4080. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
  4081. bfa_fcs_lport_ns_send_rft_id, ns, BFA_TRUE);
  4082. return;
  4083. }
  4084. ns->fcxp = fcxp;
  4085. len = fc_rftid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  4086. bfa_fcs_lport_get_fcid(port), 0, port->port_cfg.roles);
  4087. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  4088. FC_CLASS_3, len, &fchs,
  4089. bfa_fcs_lport_ns_rft_id_response, (void *)ns,
  4090. FC_MAX_PDUSZ, FC_FCCT_TOV);
  4091. port->stats.ns_rftid_sent++;
  4092. bfa_sm_send_event(ns, NSSM_EVENT_RFTID_SENT);
  4093. }
  4094. static void
  4095. bfa_fcs_lport_ns_rft_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  4096. void *cbarg, bfa_status_t req_status,
  4097. u32 rsp_len, u32 resid_len,
  4098. struct fchs_s *rsp_fchs)
  4099. {
  4100. struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
  4101. struct bfa_fcs_lport_s *port = ns->port;
  4102. struct ct_hdr_s *cthdr = NULL;
  4103. bfa_trc(port->fcs, port->port_cfg.pwwn);
  4104. /*
  4105. * Sanity Checks
  4106. */
  4107. if (req_status != BFA_STATUS_OK) {
  4108. bfa_trc(port->fcs, req_status);
  4109. port->stats.ns_rftid_rsp_err++;
  4110. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  4111. return;
  4112. }
  4113. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  4114. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  4115. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  4116. port->stats.ns_rftid_accepts++;
  4117. bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
  4118. return;
  4119. }
  4120. port->stats.ns_rftid_rejects++;
  4121. bfa_trc(port->fcs, cthdr->reason_code);
  4122. bfa_trc(port->fcs, cthdr->exp_code);
  4123. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  4124. }
  4125. /*
  4126. * Register FC4-Features : Should be done after RFT_ID
  4127. */
  4128. static void
  4129. bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  4130. {
  4131. struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
  4132. struct bfa_fcs_lport_s *port = ns->port;
  4133. struct fchs_s fchs;
  4134. int len;
  4135. struct bfa_fcxp_s *fcxp;
  4136. u8 fc4_ftrs = 0;
  4137. bfa_trc(port->fcs, port->port_cfg.pwwn);
  4138. fcxp = fcxp_alloced ? fcxp_alloced :
  4139. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  4140. if (!fcxp) {
  4141. port->stats.ns_rffid_alloc_wait++;
  4142. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
  4143. bfa_fcs_lport_ns_send_rff_id, ns, BFA_TRUE);
  4144. return;
  4145. }
  4146. ns->fcxp = fcxp;
  4147. if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port))
  4148. fc4_ftrs = FC_GS_FCP_FC4_FEATURE_INITIATOR;
  4149. len = fc_rffid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  4150. bfa_fcs_lport_get_fcid(port), 0,
  4151. FC_TYPE_FCP, fc4_ftrs);
  4152. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  4153. FC_CLASS_3, len, &fchs,
  4154. bfa_fcs_lport_ns_rff_id_response, (void *)ns,
  4155. FC_MAX_PDUSZ, FC_FCCT_TOV);
  4156. port->stats.ns_rffid_sent++;
  4157. bfa_sm_send_event(ns, NSSM_EVENT_RFFID_SENT);
  4158. }
  4159. static void
  4160. bfa_fcs_lport_ns_rff_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  4161. void *cbarg, bfa_status_t req_status,
  4162. u32 rsp_len, u32 resid_len,
  4163. struct fchs_s *rsp_fchs)
  4164. {
  4165. struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
  4166. struct bfa_fcs_lport_s *port = ns->port;
  4167. struct ct_hdr_s *cthdr = NULL;
  4168. bfa_trc(port->fcs, port->port_cfg.pwwn);
  4169. /*
  4170. * Sanity Checks
  4171. */
  4172. if (req_status != BFA_STATUS_OK) {
  4173. bfa_trc(port->fcs, req_status);
  4174. port->stats.ns_rffid_rsp_err++;
  4175. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  4176. return;
  4177. }
  4178. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  4179. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  4180. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  4181. port->stats.ns_rffid_accepts++;
  4182. bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
  4183. return;
  4184. }
  4185. port->stats.ns_rffid_rejects++;
  4186. bfa_trc(port->fcs, cthdr->reason_code);
  4187. bfa_trc(port->fcs, cthdr->exp_code);
  4188. if (cthdr->reason_code == CT_RSN_NOT_SUPP) {
  4189. /* if this command is not supported, we don't retry */
  4190. bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
  4191. } else
  4192. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  4193. }
  4194. /*
  4195. * Query Fabric for FC4-Types Devices.
  4196. *
  4197. * TBD : Need to use a local (FCS private) response buffer, since the response
  4198. * can be larger than 2K.
  4199. */
  4200. static void
  4201. bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  4202. {
  4203. struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
  4204. struct bfa_fcs_lport_s *port = ns->port;
  4205. struct fchs_s fchs;
  4206. int len;
  4207. struct bfa_fcxp_s *fcxp;
  4208. bfa_trc(port->fcs, port->pid);
  4209. fcxp = fcxp_alloced ? fcxp_alloced :
  4210. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  4211. if (!fcxp) {
  4212. port->stats.ns_gidft_alloc_wait++;
  4213. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
  4214. bfa_fcs_lport_ns_send_gid_ft, ns, BFA_TRUE);
  4215. return;
  4216. }
  4217. ns->fcxp = fcxp;
  4218. /*
  4219. * This query is only initiated for FCP initiator mode.
  4220. */
  4221. len = fc_gid_ft_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  4222. ns->port->pid, FC_TYPE_FCP);
  4223. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  4224. FC_CLASS_3, len, &fchs,
  4225. bfa_fcs_lport_ns_gid_ft_response, (void *)ns,
  4226. bfa_fcxp_get_maxrsp(port->fcs->bfa), FC_FCCT_TOV);
  4227. port->stats.ns_gidft_sent++;
  4228. bfa_sm_send_event(ns, NSSM_EVENT_GIDFT_SENT);
  4229. }
  4230. static void
  4231. bfa_fcs_lport_ns_gid_ft_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  4232. void *cbarg, bfa_status_t req_status,
  4233. u32 rsp_len, u32 resid_len,
  4234. struct fchs_s *rsp_fchs)
  4235. {
  4236. struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
  4237. struct bfa_fcs_lport_s *port = ns->port;
  4238. struct ct_hdr_s *cthdr = NULL;
  4239. u32 n_pids;
  4240. bfa_trc(port->fcs, port->port_cfg.pwwn);
  4241. /*
  4242. * Sanity Checks
  4243. */
  4244. if (req_status != BFA_STATUS_OK) {
  4245. bfa_trc(port->fcs, req_status);
  4246. port->stats.ns_gidft_rsp_err++;
  4247. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  4248. return;
  4249. }
  4250. if (resid_len != 0) {
  4251. /*
  4252. * TBD : we will need to allocate a larger buffer & retry the
  4253. * command
  4254. */
  4255. bfa_trc(port->fcs, rsp_len);
  4256. bfa_trc(port->fcs, resid_len);
  4257. return;
  4258. }
  4259. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  4260. cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
  4261. switch (cthdr->cmd_rsp_code) {
  4262. case CT_RSP_ACCEPT:
  4263. port->stats.ns_gidft_accepts++;
  4264. n_pids = (fc_get_ctresp_pyld_len(rsp_len) / sizeof(u32));
  4265. bfa_trc(port->fcs, n_pids);
  4266. bfa_fcs_lport_ns_process_gidft_pids(port,
  4267. (u32 *) (cthdr + 1),
  4268. n_pids);
  4269. bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
  4270. break;
  4271. case CT_RSP_REJECT:
  4272. /*
  4273. * Check the reason code & explanation.
  4274. * There may not have been any FC4 devices in the fabric
  4275. */
  4276. port->stats.ns_gidft_rejects++;
  4277. bfa_trc(port->fcs, cthdr->reason_code);
  4278. bfa_trc(port->fcs, cthdr->exp_code);
  4279. if ((cthdr->reason_code == CT_RSN_UNABLE_TO_PERF)
  4280. && (cthdr->exp_code == CT_NS_EXP_FT_NOT_REG)) {
  4281. bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
  4282. } else {
  4283. /*
  4284. * for all other errors, retry
  4285. */
  4286. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  4287. }
  4288. break;
  4289. default:
  4290. port->stats.ns_gidft_unknown_rsp++;
  4291. bfa_trc(port->fcs, cthdr->cmd_rsp_code);
  4292. bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
  4293. }
  4294. }
  4295. /*
  4296. * This routine will be called by bfa_timer on timer timeouts.
  4297. *
  4298. * param[in] port - pointer to bfa_fcs_lport_t.
  4299. *
  4300. * return
  4301. * void
  4302. *
  4303. * Special Considerations:
  4304. *
  4305. * note
  4306. */
  4307. static void
  4308. bfa_fcs_lport_ns_timeout(void *arg)
  4309. {
  4310. struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) arg;
  4311. ns->port->stats.ns_timeouts++;
  4312. bfa_sm_send_event(ns, NSSM_EVENT_TIMEOUT);
  4313. }
  4314. /*
  4315. * Process the PID list in GID_FT response
  4316. */
  4317. static void
  4318. bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s *port, u32 *pid_buf,
  4319. u32 n_pids)
  4320. {
  4321. struct fcgs_gidft_resp_s *gidft_entry;
  4322. struct bfa_fcs_rport_s *rport;
  4323. u32 ii;
  4324. struct bfa_fcs_fabric_s *fabric = port->fabric;
  4325. struct bfa_fcs_vport_s *vport;
  4326. struct list_head *qe;
  4327. u8 found = 0;
  4328. for (ii = 0; ii < n_pids; ii++) {
  4329. gidft_entry = (struct fcgs_gidft_resp_s *) &pid_buf[ii];
  4330. if (gidft_entry->pid == port->pid)
  4331. continue;
  4332. /*
  4333. * Ignore PID if it is of base port
  4334. * (Avoid vports discovering base port as remote port)
  4335. */
  4336. if (gidft_entry->pid == fabric->bport.pid)
  4337. continue;
  4338. /*
  4339. * Ignore PID if it is of vport created on the same base port
  4340. * (Avoid vport discovering every other vport created on the
  4341. * same port as remote port)
  4342. */
  4343. list_for_each(qe, &fabric->vport_q) {
  4344. vport = (struct bfa_fcs_vport_s *) qe;
  4345. if (vport->lport.pid == gidft_entry->pid)
  4346. found = 1;
  4347. }
  4348. if (found) {
  4349. found = 0;
  4350. continue;
  4351. }
  4352. /*
  4353. * Check if this rport already exists
  4354. */
  4355. rport = bfa_fcs_lport_get_rport_by_pid(port, gidft_entry->pid);
  4356. if (rport == NULL) {
  4357. /*
  4358. * this is a new device. create rport
  4359. */
  4360. rport = bfa_fcs_rport_create(port, gidft_entry->pid);
  4361. } else {
  4362. /*
  4363. * this rport already exists
  4364. */
  4365. bfa_fcs_rport_scn(rport);
  4366. }
  4367. bfa_trc(port->fcs, gidft_entry->pid);
  4368. /*
  4369. * if the last entry bit is set, bail out.
  4370. */
  4371. if (gidft_entry->last)
  4372. return;
  4373. }
  4374. }
  4375. /*
  4376. * fcs_ns_public FCS nameserver public interfaces
  4377. */
  4378. /*
  4379. * Functions called by port/fab.
  4380. * These will send relevant Events to the ns state machine.
  4381. */
  4382. void
  4383. bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s *port)
  4384. {
  4385. struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
  4386. ns->port = port;
  4387. bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
  4388. }
  4389. void
  4390. bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s *port)
  4391. {
  4392. struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
  4393. ns->port = port;
  4394. bfa_sm_send_event(ns, NSSM_EVENT_PORT_OFFLINE);
  4395. }
  4396. void
  4397. bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s *port)
  4398. {
  4399. struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
  4400. ns->port = port;
  4401. bfa_sm_send_event(ns, NSSM_EVENT_PORT_ONLINE);
  4402. }
  4403. void
  4404. bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s *port)
  4405. {
  4406. struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
  4407. bfa_trc(port->fcs, port->pid);
  4408. if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_online))
  4409. bfa_sm_send_event(ns, NSSM_EVENT_NS_QUERY);
  4410. }
  4411. static void
  4412. bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port)
  4413. {
  4414. struct bfa_fcs_rport_s *rport;
  4415. u8 nwwns;
  4416. wwn_t wwns[BFA_PREBOOT_BOOTLUN_MAX];
  4417. int ii;
  4418. bfa_iocfc_get_bootwwns(port->fcs->bfa, &nwwns, wwns);
  4419. for (ii = 0 ; ii < nwwns; ++ii) {
  4420. rport = bfa_fcs_rport_create_by_wwn(port, wwns[ii]);
  4421. WARN_ON(!rport);
  4422. }
  4423. }
  4424. void
  4425. bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct bfa_fcxp_s *fcxp_alloced)
  4426. {
  4427. struct bfa_fcs_lport_ns_s *ns = cbarg;
  4428. struct bfa_fcs_lport_s *port = ns->port;
  4429. struct fchs_s fchs;
  4430. struct bfa_fcxp_s *fcxp;
  4431. u8 symbl[256];
  4432. u8 *psymbl = &symbl[0];
  4433. int len;
  4434. /* Avoid sending RSPN in the following states. */
  4435. if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_offline) ||
  4436. bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_sending) ||
  4437. bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi) ||
  4438. bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_retry) ||
  4439. bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry))
  4440. return;
  4441. memset(symbl, 0, sizeof(symbl));
  4442. bfa_trc(port->fcs, port->port_cfg.pwwn);
  4443. fcxp = fcxp_alloced ? fcxp_alloced :
  4444. bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  4445. if (!fcxp) {
  4446. port->stats.ns_rspnid_alloc_wait++;
  4447. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
  4448. bfa_fcs_lport_ns_util_send_rspn_id, ns, BFA_FALSE);
  4449. return;
  4450. }
  4451. ns->fcxp = fcxp;
  4452. if (port->vport) {
  4453. /*
  4454. * For Vports, we append the vport's port symbolic name
  4455. * to that of the base port.
  4456. */
  4457. strncpy((char *)psymbl, (char *)&(bfa_fcs_lport_get_psym_name
  4458. (bfa_fcs_get_base_port(port->fcs))),
  4459. strlen((char *)&bfa_fcs_lport_get_psym_name(
  4460. bfa_fcs_get_base_port(port->fcs))));
  4461. /* Ensure we have a null terminating string. */
  4462. ((char *)psymbl)[strlen((char *)&bfa_fcs_lport_get_psym_name(
  4463. bfa_fcs_get_base_port(port->fcs)))] = 0;
  4464. strncat((char *)psymbl,
  4465. (char *)&(bfa_fcs_lport_get_psym_name(port)),
  4466. strlen((char *)&bfa_fcs_lport_get_psym_name(port)));
  4467. }
  4468. len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  4469. bfa_fcs_lport_get_fcid(port), 0, psymbl);
  4470. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  4471. FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
  4472. port->stats.ns_rspnid_sent++;
  4473. }
  4474. /*
  4475. * FCS SCN
  4476. */
  4477. #define FC_QOS_RSCN_EVENT 0x0c
  4478. #define FC_FABRIC_NAME_RSCN_EVENT 0x0d
  4479. /*
  4480. * forward declarations
  4481. */
  4482. static void bfa_fcs_lport_scn_send_scr(void *scn_cbarg,
  4483. struct bfa_fcxp_s *fcxp_alloced);
  4484. static void bfa_fcs_lport_scn_scr_response(void *fcsarg,
  4485. struct bfa_fcxp_s *fcxp,
  4486. void *cbarg,
  4487. bfa_status_t req_status,
  4488. u32 rsp_len,
  4489. u32 resid_len,
  4490. struct fchs_s *rsp_fchs);
  4491. static void bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
  4492. struct fchs_s *rx_fchs);
  4493. static void bfa_fcs_lport_scn_timeout(void *arg);
  4494. /*
  4495. * fcs_scm_sm FCS SCN state machine
  4496. */
  4497. /*
  4498. * VPort SCN State Machine events
  4499. */
  4500. enum port_scn_event {
  4501. SCNSM_EVENT_PORT_ONLINE = 1,
  4502. SCNSM_EVENT_PORT_OFFLINE = 2,
  4503. SCNSM_EVENT_RSP_OK = 3,
  4504. SCNSM_EVENT_RSP_ERROR = 4,
  4505. SCNSM_EVENT_TIMEOUT = 5,
  4506. SCNSM_EVENT_SCR_SENT = 6,
  4507. };
  4508. static void bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
  4509. enum port_scn_event event);
  4510. static void bfa_fcs_lport_scn_sm_sending_scr(
  4511. struct bfa_fcs_lport_scn_s *scn,
  4512. enum port_scn_event event);
  4513. static void bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
  4514. enum port_scn_event event);
  4515. static void bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
  4516. enum port_scn_event event);
  4517. static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
  4518. enum port_scn_event event);
  4519. /*
  4520. * Starting state - awaiting link up.
  4521. */
  4522. static void
  4523. bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
  4524. enum port_scn_event event)
  4525. {
  4526. switch (event) {
  4527. case SCNSM_EVENT_PORT_ONLINE:
  4528. bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
  4529. bfa_fcs_lport_scn_send_scr(scn, NULL);
  4530. break;
  4531. case SCNSM_EVENT_PORT_OFFLINE:
  4532. break;
  4533. default:
  4534. bfa_sm_fault(scn->port->fcs, event);
  4535. }
  4536. }
  4537. static void
  4538. bfa_fcs_lport_scn_sm_sending_scr(struct bfa_fcs_lport_scn_s *scn,
  4539. enum port_scn_event event)
  4540. {
  4541. switch (event) {
  4542. case SCNSM_EVENT_SCR_SENT:
  4543. bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr);
  4544. break;
  4545. case SCNSM_EVENT_PORT_OFFLINE:
  4546. bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
  4547. bfa_fcxp_walloc_cancel(scn->port->fcs->bfa, &scn->fcxp_wqe);
  4548. break;
  4549. default:
  4550. bfa_sm_fault(scn->port->fcs, event);
  4551. }
  4552. }
  4553. static void
  4554. bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
  4555. enum port_scn_event event)
  4556. {
  4557. struct bfa_fcs_lport_s *port = scn->port;
  4558. switch (event) {
  4559. case SCNSM_EVENT_RSP_OK:
  4560. bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_online);
  4561. break;
  4562. case SCNSM_EVENT_RSP_ERROR:
  4563. bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr_retry);
  4564. bfa_timer_start(port->fcs->bfa, &scn->timer,
  4565. bfa_fcs_lport_scn_timeout, scn,
  4566. BFA_FCS_RETRY_TIMEOUT);
  4567. break;
  4568. case SCNSM_EVENT_PORT_OFFLINE:
  4569. bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
  4570. bfa_fcxp_discard(scn->fcxp);
  4571. break;
  4572. default:
  4573. bfa_sm_fault(port->fcs, event);
  4574. }
  4575. }
  4576. static void
  4577. bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
  4578. enum port_scn_event event)
  4579. {
  4580. switch (event) {
  4581. case SCNSM_EVENT_TIMEOUT:
  4582. bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
  4583. bfa_fcs_lport_scn_send_scr(scn, NULL);
  4584. break;
  4585. case SCNSM_EVENT_PORT_OFFLINE:
  4586. bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
  4587. bfa_timer_stop(&scn->timer);
  4588. break;
  4589. default:
  4590. bfa_sm_fault(scn->port->fcs, event);
  4591. }
  4592. }
  4593. static void
  4594. bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
  4595. enum port_scn_event event)
  4596. {
  4597. switch (event) {
  4598. case SCNSM_EVENT_PORT_OFFLINE:
  4599. bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
  4600. break;
  4601. default:
  4602. bfa_sm_fault(scn->port->fcs, event);
  4603. }
  4604. }
  4605. /*
  4606. * fcs_scn_private FCS SCN private functions
  4607. */
  4608. /*
  4609. * This routine will be called to send a SCR command.
  4610. */
  4611. static void
  4612. bfa_fcs_lport_scn_send_scr(void *scn_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  4613. {
  4614. struct bfa_fcs_lport_scn_s *scn = scn_cbarg;
  4615. struct bfa_fcs_lport_s *port = scn->port;
  4616. struct fchs_s fchs;
  4617. int len;
  4618. struct bfa_fcxp_s *fcxp;
  4619. bfa_trc(port->fcs, port->pid);
  4620. bfa_trc(port->fcs, port->port_cfg.pwwn);
  4621. fcxp = fcxp_alloced ? fcxp_alloced :
  4622. bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
  4623. if (!fcxp) {
  4624. bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &scn->fcxp_wqe,
  4625. bfa_fcs_lport_scn_send_scr, scn, BFA_TRUE);
  4626. return;
  4627. }
  4628. scn->fcxp = fcxp;
  4629. /* Handle VU registrations for Base port only */
  4630. if ((!port->vport) && bfa_ioc_get_fcmode(&port->fcs->bfa->ioc)) {
  4631. len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  4632. port->fabric->lps->brcd_switch,
  4633. port->pid, 0);
  4634. } else {
  4635. len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  4636. BFA_FALSE,
  4637. port->pid, 0);
  4638. }
  4639. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  4640. FC_CLASS_3, len, &fchs,
  4641. bfa_fcs_lport_scn_scr_response,
  4642. (void *)scn, FC_MAX_PDUSZ, FC_ELS_TOV);
  4643. bfa_sm_send_event(scn, SCNSM_EVENT_SCR_SENT);
  4644. }
  4645. static void
  4646. bfa_fcs_lport_scn_scr_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  4647. void *cbarg, bfa_status_t req_status, u32 rsp_len,
  4648. u32 resid_len, struct fchs_s *rsp_fchs)
  4649. {
  4650. struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) cbarg;
  4651. struct bfa_fcs_lport_s *port = scn->port;
  4652. struct fc_els_cmd_s *els_cmd;
  4653. struct fc_ls_rjt_s *ls_rjt;
  4654. bfa_trc(port->fcs, port->port_cfg.pwwn);
  4655. /*
  4656. * Sanity Checks
  4657. */
  4658. if (req_status != BFA_STATUS_OK) {
  4659. bfa_trc(port->fcs, req_status);
  4660. bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
  4661. return;
  4662. }
  4663. els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
  4664. switch (els_cmd->els_code) {
  4665. case FC_ELS_ACC:
  4666. bfa_sm_send_event(scn, SCNSM_EVENT_RSP_OK);
  4667. break;
  4668. case FC_ELS_LS_RJT:
  4669. ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  4670. bfa_trc(port->fcs, ls_rjt->reason_code);
  4671. bfa_trc(port->fcs, ls_rjt->reason_code_expl);
  4672. bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
  4673. break;
  4674. default:
  4675. bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
  4676. }
  4677. }
  4678. /*
  4679. * Send a LS Accept
  4680. */
  4681. static void
  4682. bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
  4683. struct fchs_s *rx_fchs)
  4684. {
  4685. struct fchs_s fchs;
  4686. struct bfa_fcxp_s *fcxp;
  4687. struct bfa_rport_s *bfa_rport = NULL;
  4688. int len;
  4689. bfa_trc(port->fcs, rx_fchs->s_id);
  4690. fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
  4691. if (!fcxp)
  4692. return;
  4693. len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  4694. rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
  4695. rx_fchs->ox_id);
  4696. bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
  4697. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  4698. FC_MAX_PDUSZ, 0);
  4699. }
  4700. /*
  4701. * This routine will be called by bfa_timer on timer timeouts.
  4702. *
  4703. * param[in] vport - pointer to bfa_fcs_lport_t.
  4704. * param[out] vport_status - pointer to return vport status in
  4705. *
  4706. * return
  4707. * void
  4708. *
  4709. * Special Considerations:
  4710. *
  4711. * note
  4712. */
  4713. static void
  4714. bfa_fcs_lport_scn_timeout(void *arg)
  4715. {
  4716. struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) arg;
  4717. bfa_sm_send_event(scn, SCNSM_EVENT_TIMEOUT);
  4718. }
  4719. /*
  4720. * fcs_scn_public FCS state change notification public interfaces
  4721. */
  4722. /*
  4723. * Functions called by port/fab
  4724. */
  4725. void
  4726. bfa_fcs_lport_scn_init(struct bfa_fcs_lport_s *port)
  4727. {
  4728. struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
  4729. scn->port = port;
  4730. bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
  4731. }
  4732. void
  4733. bfa_fcs_lport_scn_offline(struct bfa_fcs_lport_s *port)
  4734. {
  4735. struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
  4736. scn->port = port;
  4737. bfa_sm_send_event(scn, SCNSM_EVENT_PORT_OFFLINE);
  4738. }
  4739. void
  4740. bfa_fcs_lport_fab_scn_online(struct bfa_fcs_lport_s *port)
  4741. {
  4742. struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
  4743. scn->port = port;
  4744. bfa_sm_send_event(scn, SCNSM_EVENT_PORT_ONLINE);
  4745. }
  4746. static void
  4747. bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s *port, u32 rpid)
  4748. {
  4749. struct bfa_fcs_rport_s *rport;
  4750. struct bfa_fcs_fabric_s *fabric = port->fabric;
  4751. struct bfa_fcs_vport_s *vport;
  4752. struct list_head *qe;
  4753. bfa_trc(port->fcs, rpid);
  4754. /*
  4755. * Ignore PID if it is of base port or of vports created on the
  4756. * same base port. It is to avoid vports discovering base port or
  4757. * other vports created on same base port as remote port
  4758. */
  4759. if (rpid == fabric->bport.pid)
  4760. return;
  4761. list_for_each(qe, &fabric->vport_q) {
  4762. vport = (struct bfa_fcs_vport_s *) qe;
  4763. if (vport->lport.pid == rpid)
  4764. return;
  4765. }
  4766. /*
  4767. * If this is an unknown device, then it just came online.
  4768. * Otherwise let rport handle the RSCN event.
  4769. */
  4770. rport = bfa_fcs_lport_get_rport_by_pid(port, rpid);
  4771. if (!rport)
  4772. rport = bfa_fcs_lport_get_rport_by_old_pid(port, rpid);
  4773. if (rport == NULL) {
  4774. /*
  4775. * If min cfg mode is enabled, we donot need to
  4776. * discover any new rports.
  4777. */
  4778. if (!__fcs_min_cfg(port->fcs))
  4779. rport = bfa_fcs_rport_create(port, rpid);
  4780. } else
  4781. bfa_fcs_rport_scn(rport);
  4782. }
  4783. /*
  4784. * rscn format based PID comparison
  4785. */
  4786. #define __fc_pid_match(__c0, __c1, __fmt) \
  4787. (((__fmt) == FC_RSCN_FORMAT_FABRIC) || \
  4788. (((__fmt) == FC_RSCN_FORMAT_DOMAIN) && \
  4789. ((__c0)[0] == (__c1)[0])) || \
  4790. (((__fmt) == FC_RSCN_FORMAT_AREA) && \
  4791. ((__c0)[0] == (__c1)[0]) && \
  4792. ((__c0)[1] == (__c1)[1])))
  4793. static void
  4794. bfa_fcs_lport_scn_multiport_rscn(struct bfa_fcs_lport_s *port,
  4795. enum fc_rscn_format format,
  4796. u32 rscn_pid)
  4797. {
  4798. struct bfa_fcs_rport_s *rport;
  4799. struct list_head *qe, *qe_next;
  4800. u8 *c0, *c1;
  4801. bfa_trc(port->fcs, format);
  4802. bfa_trc(port->fcs, rscn_pid);
  4803. c0 = (u8 *) &rscn_pid;
  4804. list_for_each_safe(qe, qe_next, &port->rport_q) {
  4805. rport = (struct bfa_fcs_rport_s *) qe;
  4806. c1 = (u8 *) &rport->pid;
  4807. if (__fc_pid_match(c0, c1, format))
  4808. bfa_fcs_rport_scn(rport);
  4809. }
  4810. }
  4811. void
  4812. bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s *port,
  4813. struct fchs_s *fchs, u32 len)
  4814. {
  4815. struct fc_rscn_pl_s *rscn = (struct fc_rscn_pl_s *) (fchs + 1);
  4816. int num_entries;
  4817. u32 rscn_pid;
  4818. bfa_boolean_t nsquery = BFA_FALSE, found;
  4819. int i = 0, j;
  4820. num_entries =
  4821. (be16_to_cpu(rscn->payldlen) -
  4822. sizeof(u32)) / sizeof(rscn->event[0]);
  4823. bfa_trc(port->fcs, num_entries);
  4824. port->stats.num_rscn++;
  4825. bfa_fcs_lport_scn_send_ls_acc(port, fchs);
  4826. for (i = 0; i < num_entries; i++) {
  4827. rscn_pid = rscn->event[i].portid;
  4828. bfa_trc(port->fcs, rscn->event[i].format);
  4829. bfa_trc(port->fcs, rscn_pid);
  4830. /* check for duplicate entries in the list */
  4831. found = BFA_FALSE;
  4832. for (j = 0; j < i; j++) {
  4833. if (rscn->event[j].portid == rscn_pid) {
  4834. found = BFA_TRUE;
  4835. break;
  4836. }
  4837. }
  4838. /* if found in down the list, pid has been already processed */
  4839. if (found) {
  4840. bfa_trc(port->fcs, rscn_pid);
  4841. continue;
  4842. }
  4843. switch (rscn->event[i].format) {
  4844. case FC_RSCN_FORMAT_PORTID:
  4845. if (rscn->event[i].qualifier == FC_QOS_RSCN_EVENT) {
  4846. /*
  4847. * Ignore this event.
  4848. * f/w would have processed it
  4849. */
  4850. bfa_trc(port->fcs, rscn_pid);
  4851. } else {
  4852. port->stats.num_portid_rscn++;
  4853. bfa_fcs_lport_scn_portid_rscn(port, rscn_pid);
  4854. }
  4855. break;
  4856. case FC_RSCN_FORMAT_FABRIC:
  4857. if (rscn->event[i].qualifier ==
  4858. FC_FABRIC_NAME_RSCN_EVENT) {
  4859. bfa_fcs_lport_ms_fabric_rscn(port);
  4860. break;
  4861. }
  4862. /* !!!!!!!!! Fall Through !!!!!!!!!!!!! */
  4863. case FC_RSCN_FORMAT_AREA:
  4864. case FC_RSCN_FORMAT_DOMAIN:
  4865. nsquery = BFA_TRUE;
  4866. bfa_fcs_lport_scn_multiport_rscn(port,
  4867. rscn->event[i].format,
  4868. rscn_pid);
  4869. break;
  4870. default:
  4871. WARN_ON(1);
  4872. nsquery = BFA_TRUE;
  4873. }
  4874. }
  4875. /*
  4876. * If any of area, domain or fabric RSCN is received, do a fresh
  4877. * discovery to find new devices.
  4878. */
  4879. if (nsquery)
  4880. bfa_fcs_lport_ns_query(port);
  4881. }
  4882. /*
  4883. * BFA FCS port
  4884. */
  4885. /*
  4886. * fcs_port_api BFA FCS port API
  4887. */
  4888. struct bfa_fcs_lport_s *
  4889. bfa_fcs_get_base_port(struct bfa_fcs_s *fcs)
  4890. {
  4891. return &fcs->fabric.bport;
  4892. }
  4893. wwn_t
  4894. bfa_fcs_lport_get_rport(struct bfa_fcs_lport_s *port, wwn_t wwn, int index,
  4895. int nrports, bfa_boolean_t bwwn)
  4896. {
  4897. struct list_head *qh, *qe;
  4898. struct bfa_fcs_rport_s *rport = NULL;
  4899. int i;
  4900. struct bfa_fcs_s *fcs;
  4901. if (port == NULL || nrports == 0)
  4902. return (wwn_t) 0;
  4903. fcs = port->fcs;
  4904. bfa_trc(fcs, (u32) nrports);
  4905. i = 0;
  4906. qh = &port->rport_q;
  4907. qe = bfa_q_first(qh);
  4908. while ((qe != qh) && (i < nrports)) {
  4909. rport = (struct bfa_fcs_rport_s *) qe;
  4910. if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
  4911. qe = bfa_q_next(qe);
  4912. bfa_trc(fcs, (u32) rport->pwwn);
  4913. bfa_trc(fcs, rport->pid);
  4914. bfa_trc(fcs, i);
  4915. continue;
  4916. }
  4917. if (bwwn) {
  4918. if (!memcmp(&wwn, &rport->pwwn, 8))
  4919. break;
  4920. } else {
  4921. if (i == index)
  4922. break;
  4923. }
  4924. i++;
  4925. qe = bfa_q_next(qe);
  4926. }
  4927. bfa_trc(fcs, i);
  4928. if (rport)
  4929. return rport->pwwn;
  4930. else
  4931. return (wwn_t) 0;
  4932. }
  4933. void
  4934. bfa_fcs_lport_get_rport_quals(struct bfa_fcs_lport_s *port,
  4935. struct bfa_rport_qualifier_s rports[], int *nrports)
  4936. {
  4937. struct list_head *qh, *qe;
  4938. struct bfa_fcs_rport_s *rport = NULL;
  4939. int i;
  4940. struct bfa_fcs_s *fcs;
  4941. if (port == NULL || rports == NULL || *nrports == 0)
  4942. return;
  4943. fcs = port->fcs;
  4944. bfa_trc(fcs, (u32) *nrports);
  4945. i = 0;
  4946. qh = &port->rport_q;
  4947. qe = bfa_q_first(qh);
  4948. while ((qe != qh) && (i < *nrports)) {
  4949. rport = (struct bfa_fcs_rport_s *) qe;
  4950. if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
  4951. qe = bfa_q_next(qe);
  4952. bfa_trc(fcs, (u32) rport->pwwn);
  4953. bfa_trc(fcs, rport->pid);
  4954. bfa_trc(fcs, i);
  4955. continue;
  4956. }
  4957. if (!rport->pwwn && !rport->pid) {
  4958. qe = bfa_q_next(qe);
  4959. continue;
  4960. }
  4961. rports[i].pwwn = rport->pwwn;
  4962. rports[i].pid = rport->pid;
  4963. i++;
  4964. qe = bfa_q_next(qe);
  4965. }
  4966. bfa_trc(fcs, i);
  4967. *nrports = i;
  4968. }
  4969. /*
  4970. * Iterate's through all the rport's in the given port to
  4971. * determine the maximum operating speed.
  4972. *
  4973. * !!!! To be used in TRL Functionality only !!!!
  4974. */
  4975. bfa_port_speed_t
  4976. bfa_fcs_lport_get_rport_max_speed(bfa_fcs_lport_t *port)
  4977. {
  4978. struct list_head *qh, *qe;
  4979. struct bfa_fcs_rport_s *rport = NULL;
  4980. struct bfa_fcs_s *fcs;
  4981. bfa_port_speed_t max_speed = 0;
  4982. struct bfa_port_attr_s port_attr;
  4983. bfa_port_speed_t port_speed, rport_speed;
  4984. bfa_boolean_t trl_enabled = bfa_fcport_is_ratelim(port->fcs->bfa);
  4985. if (port == NULL)
  4986. return 0;
  4987. fcs = port->fcs;
  4988. /* Get Physical port's current speed */
  4989. bfa_fcport_get_attr(port->fcs->bfa, &port_attr);
  4990. port_speed = port_attr.speed;
  4991. bfa_trc(fcs, port_speed);
  4992. qh = &port->rport_q;
  4993. qe = bfa_q_first(qh);
  4994. while (qe != qh) {
  4995. rport = (struct bfa_fcs_rport_s *) qe;
  4996. if ((bfa_ntoh3b(rport->pid) > 0xFFF000) ||
  4997. (bfa_fcs_rport_get_state(rport) == BFA_RPORT_OFFLINE) ||
  4998. (rport->scsi_function != BFA_RPORT_TARGET)) {
  4999. qe = bfa_q_next(qe);
  5000. continue;
  5001. }
  5002. rport_speed = rport->rpf.rpsc_speed;
  5003. if ((trl_enabled) && (rport_speed ==
  5004. BFA_PORT_SPEED_UNKNOWN)) {
  5005. /* Use default ratelim speed setting */
  5006. rport_speed =
  5007. bfa_fcport_get_ratelim_speed(port->fcs->bfa);
  5008. }
  5009. if (rport_speed > max_speed)
  5010. max_speed = rport_speed;
  5011. qe = bfa_q_next(qe);
  5012. }
  5013. if (max_speed > port_speed)
  5014. max_speed = port_speed;
  5015. bfa_trc(fcs, max_speed);
  5016. return max_speed;
  5017. }
  5018. struct bfa_fcs_lport_s *
  5019. bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
  5020. {
  5021. struct bfa_fcs_vport_s *vport;
  5022. bfa_fcs_vf_t *vf;
  5023. WARN_ON(fcs == NULL);
  5024. vf = bfa_fcs_vf_lookup(fcs, vf_id);
  5025. if (vf == NULL) {
  5026. bfa_trc(fcs, vf_id);
  5027. return NULL;
  5028. }
  5029. if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
  5030. return &vf->bport;
  5031. vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
  5032. if (vport)
  5033. return &vport->lport;
  5034. return NULL;
  5035. }
  5036. /*
  5037. * API corresponding to NPIV_VPORT_GETINFO.
  5038. */
  5039. void
  5040. bfa_fcs_lport_get_info(struct bfa_fcs_lport_s *port,
  5041. struct bfa_lport_info_s *port_info)
  5042. {
  5043. bfa_trc(port->fcs, port->fabric->fabric_name);
  5044. if (port->vport == NULL) {
  5045. /*
  5046. * This is a Physical port
  5047. */
  5048. port_info->port_type = BFA_LPORT_TYPE_PHYSICAL;
  5049. /*
  5050. * @todo : need to fix the state & reason
  5051. */
  5052. port_info->port_state = 0;
  5053. port_info->offline_reason = 0;
  5054. port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
  5055. port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
  5056. port_info->max_vports_supp =
  5057. bfa_lps_get_max_vport(port->fcs->bfa);
  5058. port_info->num_vports_inuse =
  5059. port->fabric->num_vports;
  5060. port_info->max_rports_supp = BFA_FCS_MAX_RPORTS_SUPP;
  5061. port_info->num_rports_inuse = port->num_rports;
  5062. } else {
  5063. /*
  5064. * This is a virtual port
  5065. */
  5066. port_info->port_type = BFA_LPORT_TYPE_VIRTUAL;
  5067. /*
  5068. * @todo : need to fix the state & reason
  5069. */
  5070. port_info->port_state = 0;
  5071. port_info->offline_reason = 0;
  5072. port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
  5073. port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
  5074. }
  5075. }
  5076. void
  5077. bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s *fcs_port,
  5078. struct bfa_lport_stats_s *port_stats)
  5079. {
  5080. *port_stats = fcs_port->stats;
  5081. }
  5082. void
  5083. bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s *fcs_port)
  5084. {
  5085. memset(&fcs_port->stats, 0, sizeof(struct bfa_lport_stats_s));
  5086. }
  5087. /*
  5088. * Let new loop map create missing rports
  5089. */
  5090. void
  5091. bfa_fcs_lport_lip_scn_online(struct bfa_fcs_lport_s *port)
  5092. {
  5093. bfa_fcs_lport_loop_online(port);
  5094. }
  5095. /*
  5096. * FCS virtual port state machine
  5097. */
  5098. #define __vport_fcs(__vp) ((__vp)->lport.fcs)
  5099. #define __vport_pwwn(__vp) ((__vp)->lport.port_cfg.pwwn)
  5100. #define __vport_nwwn(__vp) ((__vp)->lport.port_cfg.nwwn)
  5101. #define __vport_bfa(__vp) ((__vp)->lport.fcs->bfa)
  5102. #define __vport_fcid(__vp) ((__vp)->lport.pid)
  5103. #define __vport_fabric(__vp) ((__vp)->lport.fabric)
  5104. #define __vport_vfid(__vp) ((__vp)->lport.fabric->vf_id)
  5105. #define BFA_FCS_VPORT_MAX_RETRIES 5
  5106. /*
  5107. * Forward declarations
  5108. */
  5109. static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport);
  5110. static void bfa_fcs_vport_timeout(void *vport_arg);
  5111. static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport);
  5112. static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport);
  5113. /*
  5114. * fcs_vport_sm FCS virtual port state machine
  5115. */
  5116. /*
  5117. * VPort State Machine events
  5118. */
  5119. enum bfa_fcs_vport_event {
  5120. BFA_FCS_VPORT_SM_CREATE = 1, /* vport create event */
  5121. BFA_FCS_VPORT_SM_DELETE = 2, /* vport delete event */
  5122. BFA_FCS_VPORT_SM_START = 3, /* vport start request */
  5123. BFA_FCS_VPORT_SM_STOP = 4, /* stop: unsupported */
  5124. BFA_FCS_VPORT_SM_ONLINE = 5, /* fabric online */
  5125. BFA_FCS_VPORT_SM_OFFLINE = 6, /* fabric offline event */
  5126. BFA_FCS_VPORT_SM_FRMSENT = 7, /* fdisc/logo sent events */
  5127. BFA_FCS_VPORT_SM_RSP_OK = 8, /* good response */
  5128. BFA_FCS_VPORT_SM_RSP_ERROR = 9, /* error/bad response */
  5129. BFA_FCS_VPORT_SM_TIMEOUT = 10, /* delay timer event */
  5130. BFA_FCS_VPORT_SM_DELCOMP = 11, /* lport delete completion */
  5131. BFA_FCS_VPORT_SM_RSP_DUP_WWN = 12, /* Dup wnn error*/
  5132. BFA_FCS_VPORT_SM_RSP_FAILED = 13, /* non-retryable failure */
  5133. BFA_FCS_VPORT_SM_STOPCOMP = 14, /* vport delete completion */
  5134. BFA_FCS_VPORT_SM_FABRIC_MAX = 15, /* max vports on fabric */
  5135. };
  5136. static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
  5137. enum bfa_fcs_vport_event event);
  5138. static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
  5139. enum bfa_fcs_vport_event event);
  5140. static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
  5141. enum bfa_fcs_vport_event event);
  5142. static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
  5143. enum bfa_fcs_vport_event event);
  5144. static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
  5145. enum bfa_fcs_vport_event event);
  5146. static void bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
  5147. enum bfa_fcs_vport_event event);
  5148. static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
  5149. enum bfa_fcs_vport_event event);
  5150. static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
  5151. enum bfa_fcs_vport_event event);
  5152. static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
  5153. enum bfa_fcs_vport_event event);
  5154. static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
  5155. enum bfa_fcs_vport_event event);
  5156. static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
  5157. enum bfa_fcs_vport_event event);
  5158. static void bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
  5159. enum bfa_fcs_vport_event event);
  5160. static void bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
  5161. enum bfa_fcs_vport_event event);
  5162. static struct bfa_sm_table_s vport_sm_table[] = {
  5163. {BFA_SM(bfa_fcs_vport_sm_uninit), BFA_FCS_VPORT_UNINIT},
  5164. {BFA_SM(bfa_fcs_vport_sm_created), BFA_FCS_VPORT_CREATED},
  5165. {BFA_SM(bfa_fcs_vport_sm_offline), BFA_FCS_VPORT_OFFLINE},
  5166. {BFA_SM(bfa_fcs_vport_sm_fdisc), BFA_FCS_VPORT_FDISC},
  5167. {BFA_SM(bfa_fcs_vport_sm_fdisc_retry), BFA_FCS_VPORT_FDISC_RETRY},
  5168. {BFA_SM(bfa_fcs_vport_sm_fdisc_rsp_wait), BFA_FCS_VPORT_FDISC_RSP_WAIT},
  5169. {BFA_SM(bfa_fcs_vport_sm_online), BFA_FCS_VPORT_ONLINE},
  5170. {BFA_SM(bfa_fcs_vport_sm_deleting), BFA_FCS_VPORT_DELETING},
  5171. {BFA_SM(bfa_fcs_vport_sm_cleanup), BFA_FCS_VPORT_CLEANUP},
  5172. {BFA_SM(bfa_fcs_vport_sm_logo), BFA_FCS_VPORT_LOGO},
  5173. {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR}
  5174. };
  5175. /*
  5176. * Beginning state.
  5177. */
  5178. static void
  5179. bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
  5180. enum bfa_fcs_vport_event event)
  5181. {
  5182. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5183. bfa_trc(__vport_fcs(vport), event);
  5184. switch (event) {
  5185. case BFA_FCS_VPORT_SM_CREATE:
  5186. bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
  5187. bfa_fcs_fabric_addvport(__vport_fabric(vport), vport);
  5188. break;
  5189. default:
  5190. bfa_sm_fault(__vport_fcs(vport), event);
  5191. }
  5192. }
  5193. /*
  5194. * Created state - a start event is required to start up the state machine.
  5195. */
  5196. static void
  5197. bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
  5198. enum bfa_fcs_vport_event event)
  5199. {
  5200. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5201. bfa_trc(__vport_fcs(vport), event);
  5202. switch (event) {
  5203. case BFA_FCS_VPORT_SM_START:
  5204. if (bfa_sm_cmp_state(__vport_fabric(vport),
  5205. bfa_fcs_fabric_sm_online)
  5206. && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport))) {
  5207. bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
  5208. bfa_fcs_vport_do_fdisc(vport);
  5209. } else {
  5210. /*
  5211. * Fabric is offline or not NPIV capable, stay in
  5212. * offline state.
  5213. */
  5214. vport->vport_stats.fab_no_npiv++;
  5215. bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
  5216. }
  5217. break;
  5218. case BFA_FCS_VPORT_SM_DELETE:
  5219. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  5220. bfa_fcs_lport_delete(&vport->lport);
  5221. break;
  5222. case BFA_FCS_VPORT_SM_ONLINE:
  5223. case BFA_FCS_VPORT_SM_OFFLINE:
  5224. /*
  5225. * Ignore ONLINE/OFFLINE events from fabric
  5226. * till vport is started.
  5227. */
  5228. break;
  5229. default:
  5230. bfa_sm_fault(__vport_fcs(vport), event);
  5231. }
  5232. }
  5233. /*
  5234. * Offline state - awaiting ONLINE event from fabric SM.
  5235. */
  5236. static void
  5237. bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
  5238. enum bfa_fcs_vport_event event)
  5239. {
  5240. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5241. bfa_trc(__vport_fcs(vport), event);
  5242. switch (event) {
  5243. case BFA_FCS_VPORT_SM_DELETE:
  5244. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  5245. bfa_fcs_lport_delete(&vport->lport);
  5246. break;
  5247. case BFA_FCS_VPORT_SM_ONLINE:
  5248. bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
  5249. vport->fdisc_retries = 0;
  5250. bfa_fcs_vport_do_fdisc(vport);
  5251. break;
  5252. case BFA_FCS_VPORT_SM_STOP:
  5253. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  5254. bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
  5255. break;
  5256. case BFA_FCS_VPORT_SM_OFFLINE:
  5257. /*
  5258. * This can happen if the vport couldn't be initialzied
  5259. * due the fact that the npiv was not enabled on the switch.
  5260. * In that case we will put the vport in offline state.
  5261. * However, the link can go down and cause the this event to
  5262. * be sent when we are already offline. Ignore it.
  5263. */
  5264. break;
  5265. default:
  5266. bfa_sm_fault(__vport_fcs(vport), event);
  5267. }
  5268. }
  5269. /*
  5270. * FDISC is sent and awaiting reply from fabric.
  5271. */
  5272. static void
  5273. bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
  5274. enum bfa_fcs_vport_event event)
  5275. {
  5276. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5277. bfa_trc(__vport_fcs(vport), event);
  5278. switch (event) {
  5279. case BFA_FCS_VPORT_SM_DELETE:
  5280. bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_rsp_wait);
  5281. break;
  5282. case BFA_FCS_VPORT_SM_OFFLINE:
  5283. bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
  5284. bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
  5285. break;
  5286. case BFA_FCS_VPORT_SM_RSP_OK:
  5287. bfa_sm_set_state(vport, bfa_fcs_vport_sm_online);
  5288. bfa_fcs_lport_online(&vport->lport);
  5289. break;
  5290. case BFA_FCS_VPORT_SM_RSP_ERROR:
  5291. bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_retry);
  5292. bfa_timer_start(__vport_bfa(vport), &vport->timer,
  5293. bfa_fcs_vport_timeout, vport,
  5294. BFA_FCS_RETRY_TIMEOUT);
  5295. break;
  5296. case BFA_FCS_VPORT_SM_RSP_FAILED:
  5297. case BFA_FCS_VPORT_SM_FABRIC_MAX:
  5298. bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
  5299. break;
  5300. case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
  5301. bfa_sm_set_state(vport, bfa_fcs_vport_sm_error);
  5302. break;
  5303. default:
  5304. bfa_sm_fault(__vport_fcs(vport), event);
  5305. }
  5306. }
  5307. /*
  5308. * FDISC attempt failed - a timer is active to retry FDISC.
  5309. */
  5310. static void
  5311. bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
  5312. enum bfa_fcs_vport_event event)
  5313. {
  5314. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5315. bfa_trc(__vport_fcs(vport), event);
  5316. switch (event) {
  5317. case BFA_FCS_VPORT_SM_DELETE:
  5318. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  5319. bfa_timer_stop(&vport->timer);
  5320. bfa_fcs_lport_delete(&vport->lport);
  5321. break;
  5322. case BFA_FCS_VPORT_SM_OFFLINE:
  5323. bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
  5324. bfa_timer_stop(&vport->timer);
  5325. break;
  5326. case BFA_FCS_VPORT_SM_TIMEOUT:
  5327. bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
  5328. vport->vport_stats.fdisc_retries++;
  5329. vport->fdisc_retries++;
  5330. bfa_fcs_vport_do_fdisc(vport);
  5331. break;
  5332. default:
  5333. bfa_sm_fault(__vport_fcs(vport), event);
  5334. }
  5335. }
  5336. /*
  5337. * FDISC is in progress and we got a vport delete request -
  5338. * this is a wait state while we wait for fdisc response and
  5339. * we will transition to the appropriate state - on rsp status.
  5340. */
  5341. static void
  5342. bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
  5343. enum bfa_fcs_vport_event event)
  5344. {
  5345. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5346. bfa_trc(__vport_fcs(vport), event);
  5347. switch (event) {
  5348. case BFA_FCS_VPORT_SM_RSP_OK:
  5349. bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
  5350. bfa_fcs_lport_delete(&vport->lport);
  5351. break;
  5352. case BFA_FCS_VPORT_SM_DELETE:
  5353. break;
  5354. case BFA_FCS_VPORT_SM_OFFLINE:
  5355. case BFA_FCS_VPORT_SM_RSP_ERROR:
  5356. case BFA_FCS_VPORT_SM_RSP_FAILED:
  5357. case BFA_FCS_VPORT_SM_FABRIC_MAX:
  5358. case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
  5359. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  5360. bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
  5361. bfa_fcs_lport_delete(&vport->lport);
  5362. break;
  5363. default:
  5364. bfa_sm_fault(__vport_fcs(vport), event);
  5365. }
  5366. }
  5367. /*
  5368. * Vport is online (FDISC is complete).
  5369. */
  5370. static void
  5371. bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
  5372. enum bfa_fcs_vport_event event)
  5373. {
  5374. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5375. bfa_trc(__vport_fcs(vport), event);
  5376. switch (event) {
  5377. case BFA_FCS_VPORT_SM_DELETE:
  5378. bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
  5379. bfa_fcs_lport_delete(&vport->lport);
  5380. break;
  5381. case BFA_FCS_VPORT_SM_STOP:
  5382. bfa_sm_set_state(vport, bfa_fcs_vport_sm_stopping);
  5383. bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
  5384. break;
  5385. case BFA_FCS_VPORT_SM_OFFLINE:
  5386. bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
  5387. bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
  5388. bfa_fcs_lport_offline(&vport->lport);
  5389. break;
  5390. default:
  5391. bfa_sm_fault(__vport_fcs(vport), event);
  5392. }
  5393. }
  5394. /*
  5395. * Vport is being stopped - awaiting lport stop completion to send
  5396. * LOGO to fabric.
  5397. */
  5398. static void
  5399. bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
  5400. enum bfa_fcs_vport_event event)
  5401. {
  5402. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5403. bfa_trc(__vport_fcs(vport), event);
  5404. switch (event) {
  5405. case BFA_FCS_VPORT_SM_STOPCOMP:
  5406. bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo_for_stop);
  5407. bfa_fcs_vport_do_logo(vport);
  5408. break;
  5409. case BFA_FCS_VPORT_SM_OFFLINE:
  5410. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  5411. break;
  5412. default:
  5413. bfa_sm_fault(__vport_fcs(vport), event);
  5414. }
  5415. }
  5416. /*
  5417. * Vport is being deleted - awaiting lport delete completion to send
  5418. * LOGO to fabric.
  5419. */
  5420. static void
  5421. bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
  5422. enum bfa_fcs_vport_event event)
  5423. {
  5424. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5425. bfa_trc(__vport_fcs(vport), event);
  5426. switch (event) {
  5427. case BFA_FCS_VPORT_SM_DELETE:
  5428. break;
  5429. case BFA_FCS_VPORT_SM_DELCOMP:
  5430. bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo);
  5431. bfa_fcs_vport_do_logo(vport);
  5432. break;
  5433. case BFA_FCS_VPORT_SM_OFFLINE:
  5434. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  5435. break;
  5436. default:
  5437. bfa_sm_fault(__vport_fcs(vport), event);
  5438. }
  5439. }
  5440. /*
  5441. * Error State.
  5442. * This state will be set when the Vport Creation fails due
  5443. * to errors like Dup WWN. In this state only operation allowed
  5444. * is a Vport Delete.
  5445. */
  5446. static void
  5447. bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
  5448. enum bfa_fcs_vport_event event)
  5449. {
  5450. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5451. bfa_trc(__vport_fcs(vport), event);
  5452. switch (event) {
  5453. case BFA_FCS_VPORT_SM_DELETE:
  5454. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  5455. bfa_fcs_lport_delete(&vport->lport);
  5456. break;
  5457. default:
  5458. bfa_trc(__vport_fcs(vport), event);
  5459. }
  5460. }
  5461. /*
  5462. * Lport cleanup is in progress since vport is being deleted. Fabric is
  5463. * offline, so no LOGO is needed to complete vport deletion.
  5464. */
  5465. static void
  5466. bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
  5467. enum bfa_fcs_vport_event event)
  5468. {
  5469. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5470. bfa_trc(__vport_fcs(vport), event);
  5471. switch (event) {
  5472. case BFA_FCS_VPORT_SM_DELCOMP:
  5473. bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
  5474. bfa_fcs_vport_free(vport);
  5475. break;
  5476. case BFA_FCS_VPORT_SM_STOPCOMP:
  5477. bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
  5478. break;
  5479. case BFA_FCS_VPORT_SM_DELETE:
  5480. break;
  5481. default:
  5482. bfa_sm_fault(__vport_fcs(vport), event);
  5483. }
  5484. }
  5485. /*
  5486. * LOGO is sent to fabric. Vport stop is in progress. Lport stop cleanup
  5487. * is done.
  5488. */
  5489. static void
  5490. bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
  5491. enum bfa_fcs_vport_event event)
  5492. {
  5493. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5494. bfa_trc(__vport_fcs(vport), event);
  5495. switch (event) {
  5496. case BFA_FCS_VPORT_SM_OFFLINE:
  5497. bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
  5498. /*
  5499. * !!! fall through !!!
  5500. */
  5501. case BFA_FCS_VPORT_SM_RSP_OK:
  5502. case BFA_FCS_VPORT_SM_RSP_ERROR:
  5503. bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
  5504. break;
  5505. default:
  5506. bfa_sm_fault(__vport_fcs(vport), event);
  5507. }
  5508. }
  5509. /*
  5510. * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
  5511. * is done.
  5512. */
  5513. static void
  5514. bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
  5515. enum bfa_fcs_vport_event event)
  5516. {
  5517. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5518. bfa_trc(__vport_fcs(vport), event);
  5519. switch (event) {
  5520. case BFA_FCS_VPORT_SM_OFFLINE:
  5521. bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
  5522. /*
  5523. * !!! fall through !!!
  5524. */
  5525. case BFA_FCS_VPORT_SM_RSP_OK:
  5526. case BFA_FCS_VPORT_SM_RSP_ERROR:
  5527. bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
  5528. bfa_fcs_vport_free(vport);
  5529. break;
  5530. case BFA_FCS_VPORT_SM_DELETE:
  5531. break;
  5532. default:
  5533. bfa_sm_fault(__vport_fcs(vport), event);
  5534. }
  5535. }
  5536. /*
  5537. * fcs_vport_private FCS virtual port private functions
  5538. */
  5539. /*
  5540. * Send AEN notification
  5541. */
  5542. static void
  5543. bfa_fcs_vport_aen_post(struct bfa_fcs_lport_s *port,
  5544. enum bfa_lport_aen_event event)
  5545. {
  5546. struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
  5547. struct bfa_aen_entry_s *aen_entry;
  5548. bfad_get_aen_entry(bfad, aen_entry);
  5549. if (!aen_entry)
  5550. return;
  5551. aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
  5552. aen_entry->aen_data.lport.roles = port->port_cfg.roles;
  5553. aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
  5554. bfa_fcs_get_base_port(port->fcs));
  5555. aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
  5556. /* Send the AEN notification */
  5557. bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
  5558. BFA_AEN_CAT_LPORT, event);
  5559. }
  5560. /*
  5561. * This routine will be called to send a FDISC command.
  5562. */
  5563. static void
  5564. bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport)
  5565. {
  5566. bfa_lps_fdisc(vport->lps, vport,
  5567. bfa_fcport_get_maxfrsize(__vport_bfa(vport)),
  5568. __vport_pwwn(vport), __vport_nwwn(vport));
  5569. vport->vport_stats.fdisc_sent++;
  5570. }
  5571. static void
  5572. bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
  5573. {
  5574. u8 lsrjt_rsn = vport->lps->lsrjt_rsn;
  5575. u8 lsrjt_expl = vport->lps->lsrjt_expl;
  5576. bfa_trc(__vport_fcs(vport), lsrjt_rsn);
  5577. bfa_trc(__vport_fcs(vport), lsrjt_expl);
  5578. /* For certain reason codes, we don't want to retry. */
  5579. switch (vport->lps->lsrjt_expl) {
  5580. case FC_LS_RJT_EXP_INV_PORT_NAME: /* by brocade */
  5581. case FC_LS_RJT_EXP_INVALID_NPORT_ID: /* by Cisco */
  5582. if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
  5583. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  5584. else {
  5585. bfa_fcs_vport_aen_post(&vport->lport,
  5586. BFA_LPORT_AEN_NPIV_DUP_WWN);
  5587. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_DUP_WWN);
  5588. }
  5589. break;
  5590. case FC_LS_RJT_EXP_INSUFF_RES:
  5591. /*
  5592. * This means max logins per port/switch setting on the
  5593. * switch was exceeded.
  5594. */
  5595. if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
  5596. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  5597. else {
  5598. bfa_fcs_vport_aen_post(&vport->lport,
  5599. BFA_LPORT_AEN_NPIV_FABRIC_MAX);
  5600. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_FABRIC_MAX);
  5601. }
  5602. break;
  5603. default:
  5604. if (vport->fdisc_retries == 0)
  5605. bfa_fcs_vport_aen_post(&vport->lport,
  5606. BFA_LPORT_AEN_NPIV_UNKNOWN);
  5607. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  5608. }
  5609. }
  5610. /*
  5611. * Called to send a logout to the fabric. Used when a V-Port is
  5612. * deleted/stopped.
  5613. */
  5614. static void
  5615. bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
  5616. {
  5617. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5618. vport->vport_stats.logo_sent++;
  5619. bfa_lps_fdisclogo(vport->lps);
  5620. }
  5621. /*
  5622. * This routine will be called by bfa_timer on timer timeouts.
  5623. *
  5624. * param[in] vport - pointer to bfa_fcs_vport_t.
  5625. * param[out] vport_status - pointer to return vport status in
  5626. *
  5627. * return
  5628. * void
  5629. *
  5630. * Special Considerations:
  5631. *
  5632. * note
  5633. */
  5634. static void
  5635. bfa_fcs_vport_timeout(void *vport_arg)
  5636. {
  5637. struct bfa_fcs_vport_s *vport = (struct bfa_fcs_vport_s *) vport_arg;
  5638. vport->vport_stats.fdisc_timeouts++;
  5639. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_TIMEOUT);
  5640. }
  5641. static void
  5642. bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
  5643. {
  5644. struct bfad_vport_s *vport_drv =
  5645. (struct bfad_vport_s *)vport->vport_drv;
  5646. bfa_fcs_fabric_delvport(__vport_fabric(vport), vport);
  5647. bfa_lps_delete(vport->lps);
  5648. if (vport_drv->comp_del) {
  5649. complete(vport_drv->comp_del);
  5650. return;
  5651. }
  5652. /*
  5653. * We queue the vport delete work to the IM work_q from here.
  5654. * The memory for the bfad_vport_s is freed from the FC function
  5655. * template vport_delete entry point.
  5656. */
  5657. bfad_im_port_delete(vport_drv->drv_port.bfad, &vport_drv->drv_port);
  5658. }
  5659. /*
  5660. * fcs_vport_public FCS virtual port public interfaces
  5661. */
  5662. /*
  5663. * Online notification from fabric SM.
  5664. */
  5665. void
  5666. bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
  5667. {
  5668. vport->vport_stats.fab_online++;
  5669. if (bfa_fcs_fabric_npiv_capable(__vport_fabric(vport)))
  5670. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
  5671. else
  5672. vport->vport_stats.fab_no_npiv++;
  5673. }
  5674. /*
  5675. * Offline notification from fabric SM.
  5676. */
  5677. void
  5678. bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
  5679. {
  5680. vport->vport_stats.fab_offline++;
  5681. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
  5682. }
  5683. /*
  5684. * Cleanup notification from fabric SM on link timer expiry.
  5685. */
  5686. void
  5687. bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport)
  5688. {
  5689. vport->vport_stats.fab_cleanup++;
  5690. }
  5691. /*
  5692. * Stop notification from fabric SM. To be invoked from within FCS.
  5693. */
  5694. void
  5695. bfa_fcs_vport_fcs_stop(struct bfa_fcs_vport_s *vport)
  5696. {
  5697. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
  5698. }
  5699. /*
  5700. * delete notification from fabric SM. To be invoked from within FCS.
  5701. */
  5702. void
  5703. bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s *vport)
  5704. {
  5705. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
  5706. }
  5707. /*
  5708. * Stop completion callback from associated lport
  5709. */
  5710. void
  5711. bfa_fcs_vport_stop_comp(struct bfa_fcs_vport_s *vport)
  5712. {
  5713. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOPCOMP);
  5714. }
  5715. /*
  5716. * Delete completion callback from associated lport
  5717. */
  5718. void
  5719. bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
  5720. {
  5721. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELCOMP);
  5722. }
  5723. /*
  5724. * fcs_vport_api Virtual port API
  5725. */
  5726. /*
  5727. * Use this function to instantiate a new FCS vport object. This
  5728. * function will not trigger any HW initialization process (which will be
  5729. * done in vport_start() call)
  5730. *
  5731. * param[in] vport - pointer to bfa_fcs_vport_t. This space
  5732. * needs to be allocated by the driver.
  5733. * param[in] fcs - FCS instance
  5734. * param[in] vport_cfg - vport configuration
  5735. * param[in] vf_id - VF_ID if vport is created within a VF.
  5736. * FC_VF_ID_NULL to specify base fabric.
  5737. * param[in] vport_drv - Opaque handle back to the driver's vport
  5738. * structure
  5739. *
  5740. * retval BFA_STATUS_OK - on success.
  5741. * retval BFA_STATUS_FAILED - on failure.
  5742. */
  5743. bfa_status_t
  5744. bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
  5745. u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
  5746. struct bfad_vport_s *vport_drv)
  5747. {
  5748. if (vport_cfg->pwwn == 0)
  5749. return BFA_STATUS_INVALID_WWN;
  5750. if (bfa_fcs_lport_get_pwwn(&fcs->fabric.bport) == vport_cfg->pwwn)
  5751. return BFA_STATUS_VPORT_WWN_BP;
  5752. if (bfa_fcs_vport_lookup(fcs, vf_id, vport_cfg->pwwn) != NULL)
  5753. return BFA_STATUS_VPORT_EXISTS;
  5754. if (fcs->fabric.num_vports ==
  5755. bfa_lps_get_max_vport(fcs->bfa))
  5756. return BFA_STATUS_VPORT_MAX;
  5757. vport->lps = bfa_lps_alloc(fcs->bfa);
  5758. if (!vport->lps)
  5759. return BFA_STATUS_VPORT_MAX;
  5760. vport->vport_drv = vport_drv;
  5761. vport_cfg->preboot_vp = BFA_FALSE;
  5762. bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
  5763. bfa_fcs_lport_attach(&vport->lport, fcs, vf_id, vport);
  5764. bfa_fcs_lport_init(&vport->lport, vport_cfg);
  5765. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_CREATE);
  5766. return BFA_STATUS_OK;
  5767. }
  5768. /*
  5769. * Use this function to instantiate a new FCS PBC vport object. This
  5770. * function will not trigger any HW initialization process (which will be
  5771. * done in vport_start() call)
  5772. *
  5773. * param[in] vport - pointer to bfa_fcs_vport_t. This space
  5774. * needs to be allocated by the driver.
  5775. * param[in] fcs - FCS instance
  5776. * param[in] vport_cfg - vport configuration
  5777. * param[in] vf_id - VF_ID if vport is created within a VF.
  5778. * FC_VF_ID_NULL to specify base fabric.
  5779. * param[in] vport_drv - Opaque handle back to the driver's vport
  5780. * structure
  5781. *
  5782. * retval BFA_STATUS_OK - on success.
  5783. * retval BFA_STATUS_FAILED - on failure.
  5784. */
  5785. bfa_status_t
  5786. bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
  5787. u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
  5788. struct bfad_vport_s *vport_drv)
  5789. {
  5790. bfa_status_t rc;
  5791. rc = bfa_fcs_vport_create(vport, fcs, vf_id, vport_cfg, vport_drv);
  5792. vport->lport.port_cfg.preboot_vp = BFA_TRUE;
  5793. return rc;
  5794. }
  5795. /*
  5796. * Use this function to findout if this is a pbc vport or not.
  5797. *
  5798. * @param[in] vport - pointer to bfa_fcs_vport_t.
  5799. *
  5800. * @returns None
  5801. */
  5802. bfa_boolean_t
  5803. bfa_fcs_is_pbc_vport(struct bfa_fcs_vport_s *vport)
  5804. {
  5805. if (vport && (vport->lport.port_cfg.preboot_vp == BFA_TRUE))
  5806. return BFA_TRUE;
  5807. else
  5808. return BFA_FALSE;
  5809. }
  5810. /*
  5811. * Use this function initialize the vport.
  5812. *
  5813. * @param[in] vport - pointer to bfa_fcs_vport_t.
  5814. *
  5815. * @returns None
  5816. */
  5817. bfa_status_t
  5818. bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
  5819. {
  5820. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_START);
  5821. return BFA_STATUS_OK;
  5822. }
  5823. /*
  5824. * Use this function quiese the vport object. This function will return
  5825. * immediately, when the vport is actually stopped, the
  5826. * bfa_drv_vport_stop_cb() will be called.
  5827. *
  5828. * param[in] vport - pointer to bfa_fcs_vport_t.
  5829. *
  5830. * return None
  5831. */
  5832. bfa_status_t
  5833. bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
  5834. {
  5835. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
  5836. return BFA_STATUS_OK;
  5837. }
  5838. /*
  5839. * Use this function to delete a vport object. Fabric object should
  5840. * be stopped before this function call.
  5841. *
  5842. * !!!!!!! Donot invoke this from within FCS !!!!!!!
  5843. *
  5844. * param[in] vport - pointer to bfa_fcs_vport_t.
  5845. *
  5846. * return None
  5847. */
  5848. bfa_status_t
  5849. bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport)
  5850. {
  5851. if (vport->lport.port_cfg.preboot_vp)
  5852. return BFA_STATUS_PBC;
  5853. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
  5854. return BFA_STATUS_OK;
  5855. }
  5856. /*
  5857. * Use this function to get vport's current status info.
  5858. *
  5859. * param[in] vport pointer to bfa_fcs_vport_t.
  5860. * param[out] attr pointer to return vport attributes
  5861. *
  5862. * return None
  5863. */
  5864. void
  5865. bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
  5866. struct bfa_vport_attr_s *attr)
  5867. {
  5868. if (vport == NULL || attr == NULL)
  5869. return;
  5870. memset(attr, 0, sizeof(struct bfa_vport_attr_s));
  5871. bfa_fcs_lport_get_attr(&vport->lport, &attr->port_attr);
  5872. attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm);
  5873. }
  5874. /*
  5875. * Lookup a virtual port. Excludes base port from lookup.
  5876. */
  5877. struct bfa_fcs_vport_s *
  5878. bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
  5879. {
  5880. struct bfa_fcs_vport_s *vport;
  5881. struct bfa_fcs_fabric_s *fabric;
  5882. bfa_trc(fcs, vf_id);
  5883. bfa_trc(fcs, vpwwn);
  5884. fabric = bfa_fcs_vf_lookup(fcs, vf_id);
  5885. if (!fabric) {
  5886. bfa_trc(fcs, vf_id);
  5887. return NULL;
  5888. }
  5889. vport = bfa_fcs_fabric_vport_lookup(fabric, vpwwn);
  5890. return vport;
  5891. }
  5892. /*
  5893. * FDISC Response
  5894. */
  5895. void
  5896. bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
  5897. {
  5898. struct bfa_fcs_vport_s *vport = uarg;
  5899. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  5900. bfa_trc(__vport_fcs(vport), status);
  5901. switch (status) {
  5902. case BFA_STATUS_OK:
  5903. /*
  5904. * Initialize the V-Port fields
  5905. */
  5906. __vport_fcid(vport) = vport->lps->lp_pid;
  5907. vport->vport_stats.fdisc_accepts++;
  5908. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
  5909. break;
  5910. case BFA_STATUS_INVALID_MAC:
  5911. /* Only for CNA */
  5912. vport->vport_stats.fdisc_acc_bad++;
  5913. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  5914. break;
  5915. case BFA_STATUS_EPROTOCOL:
  5916. switch (vport->lps->ext_status) {
  5917. case BFA_EPROTO_BAD_ACCEPT:
  5918. vport->vport_stats.fdisc_acc_bad++;
  5919. break;
  5920. case BFA_EPROTO_UNKNOWN_RSP:
  5921. vport->vport_stats.fdisc_unknown_rsp++;
  5922. break;
  5923. default:
  5924. break;
  5925. }
  5926. if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
  5927. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  5928. else
  5929. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
  5930. break;
  5931. case BFA_STATUS_ETIMER:
  5932. vport->vport_stats.fdisc_timeouts++;
  5933. if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
  5934. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  5935. else
  5936. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
  5937. break;
  5938. case BFA_STATUS_FABRIC_RJT:
  5939. vport->vport_stats.fdisc_rejects++;
  5940. bfa_fcs_vport_fdisc_rejected(vport);
  5941. break;
  5942. default:
  5943. vport->vport_stats.fdisc_rsp_err++;
  5944. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  5945. }
  5946. }
  5947. /*
  5948. * LOGO response
  5949. */
  5950. void
  5951. bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
  5952. {
  5953. struct bfa_fcs_vport_s *vport = uarg;
  5954. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
  5955. }
  5956. /*
  5957. * Received clear virtual link
  5958. */
  5959. void
  5960. bfa_cb_lps_cvl_event(void *bfad, void *uarg)
  5961. {
  5962. struct bfa_fcs_vport_s *vport = uarg;
  5963. /* Send an Offline followed by an ONLINE */
  5964. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
  5965. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
  5966. }