12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989 |
- /*
- * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
- * All rights reserved
- * www.brocade.com
- *
- * Linux driver for Brocade Fibre Channel Host Bus Adapter.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License (GPL) Version 2 as
- * published by the Free Software Foundation
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- */
- #include "bfad_drv.h"
- #include "bfad_im.h"
- #include "bfa_fcs.h"
- #include "bfa_fcbuild.h"
- #include "bfa_fc.h"
- BFA_TRC_FILE(FCS, PORT);
- /*
- * ALPA to LIXA bitmap mapping
- *
- * ALPA 0x00 (Word 0, Bit 30) is invalid for N_Ports. Also Word 0 Bit 31
- * is for L_bit (login required) and is filled as ALPA 0x00 here.
- */
- static const u8 loop_alpa_map[] = {
- 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x0F, 0x10, /* Word 0 Bits 31..24 */
- 0x17, 0x18, 0x1B, 0x1D, 0x1E, 0x1F, 0x23, 0x25, /* Word 0 Bits 23..16 */
- 0x26, 0x27, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, /* Word 0 Bits 15..08 */
- 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x39, 0x3A, /* Word 0 Bits 07..00 */
- 0x3C, 0x43, 0x45, 0x46, 0x47, 0x49, 0x4A, 0x4B, /* Word 1 Bits 31..24 */
- 0x4C, 0x4D, 0x4E, 0x51, 0x52, 0x53, 0x54, 0x55, /* Word 1 Bits 23..16 */
- 0x56, 0x59, 0x5A, 0x5C, 0x63, 0x65, 0x66, 0x67, /* Word 1 Bits 15..08 */
- 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x71, 0x72, /* Word 1 Bits 07..00 */
- 0x73, 0x74, 0x75, 0x76, 0x79, 0x7A, 0x7C, 0x80, /* Word 2 Bits 31..24 */
- 0x81, 0x82, 0x84, 0x88, 0x8F, 0x90, 0x97, 0x98, /* Word 2 Bits 23..16 */
- 0x9B, 0x9D, 0x9E, 0x9F, 0xA3, 0xA5, 0xA6, 0xA7, /* Word 2 Bits 15..08 */
- 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xB1, 0xB2, /* Word 2 Bits 07..00 */
- 0xB3, 0xB4, 0xB5, 0xB6, 0xB9, 0xBA, 0xBC, 0xC3, /* Word 3 Bits 31..24 */
- 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, /* Word 3 Bits 23..16 */
- 0xCE, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD9, /* Word 3 Bits 15..08 */
- 0xDA, 0xDC, 0xE0, 0xE1, 0xE2, 0xE4, 0xE8, 0xEF, /* Word 3 Bits 07..00 */
- };
- static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port,
- struct fchs_s *rx_fchs, u8 reason_code,
- u8 reason_code_expl);
- static void bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
- struct fchs_s *rx_fchs, struct fc_logi_s *plogi);
- static void bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port,
- struct fchs_s *rx_fchs,
- struct fc_echo_s *echo, u16 len);
- static void bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port,
- struct fchs_s *rx_fchs,
- struct fc_rnid_cmd_s *rnid, u16 len);
- static void bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
- struct fc_rnid_general_topology_data_s *gen_topo_data);
- static void bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port);
- static void bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port);
- static struct {
- void (*init) (struct bfa_fcs_lport_s *port);
- void (*online) (struct bfa_fcs_lport_s *port);
- void (*offline) (struct bfa_fcs_lport_s *port);
- } __port_action[] = {
- {
- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
- bfa_fcs_lport_unknown_offline}, {
- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
- bfa_fcs_lport_fab_offline}, {
- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
- bfa_fcs_lport_n2n_offline}, {
- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
- bfa_fcs_lport_loop_offline},
- };
- /*
- * fcs_port_sm FCS logical port state machine
- */
- enum bfa_fcs_lport_event {
- BFA_FCS_PORT_SM_CREATE = 1,
- BFA_FCS_PORT_SM_ONLINE = 2,
- BFA_FCS_PORT_SM_OFFLINE = 3,
- BFA_FCS_PORT_SM_DELETE = 4,
- BFA_FCS_PORT_SM_DELRPORT = 5,
- BFA_FCS_PORT_SM_STOP = 6,
- };
- static void bfa_fcs_lport_sm_uninit(struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event);
- static void bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event);
- static void bfa_fcs_lport_sm_online(struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event);
- static void bfa_fcs_lport_sm_offline(struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event);
- static void bfa_fcs_lport_sm_deleting(struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event);
- static void bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event);
- static void
- bfa_fcs_lport_sm_uninit(
- struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event)
- {
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case BFA_FCS_PORT_SM_CREATE:
- bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event)
- {
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case BFA_FCS_PORT_SM_ONLINE:
- bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
- bfa_fcs_lport_online_actions(port);
- break;
- case BFA_FCS_PORT_SM_DELETE:
- bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
- bfa_fcs_lport_deleted(port);
- break;
- case BFA_FCS_PORT_SM_STOP:
- /* If vport - send completion call back */
- if (port->vport)
- bfa_fcs_vport_stop_comp(port->vport);
- else
- bfa_wc_down(&(port->fabric->stop_wc));
- break;
- case BFA_FCS_PORT_SM_OFFLINE:
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_sm_online(
- struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event)
- {
- struct bfa_fcs_rport_s *rport;
- struct list_head *qe, *qen;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case BFA_FCS_PORT_SM_OFFLINE:
- bfa_sm_set_state(port, bfa_fcs_lport_sm_offline);
- bfa_fcs_lport_offline_actions(port);
- break;
- case BFA_FCS_PORT_SM_STOP:
- __port_action[port->fabric->fab_type].offline(port);
- if (port->num_rports == 0) {
- bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
- /* If vport - send completion call back */
- if (port->vport)
- bfa_fcs_vport_stop_comp(port->vport);
- else
- bfa_wc_down(&(port->fabric->stop_wc));
- } else {
- bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
- list_for_each_safe(qe, qen, &port->rport_q) {
- rport = (struct bfa_fcs_rport_s *) qe;
- bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
- }
- }
- break;
- case BFA_FCS_PORT_SM_DELETE:
- __port_action[port->fabric->fab_type].offline(port);
- if (port->num_rports == 0) {
- bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
- bfa_fcs_lport_deleted(port);
- } else {
- bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
- list_for_each_safe(qe, qen, &port->rport_q) {
- rport = (struct bfa_fcs_rport_s *) qe;
- bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
- }
- }
- break;
- case BFA_FCS_PORT_SM_DELRPORT:
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_sm_offline(
- struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event)
- {
- struct bfa_fcs_rport_s *rport;
- struct list_head *qe, *qen;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case BFA_FCS_PORT_SM_ONLINE:
- bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
- bfa_fcs_lport_online_actions(port);
- break;
- case BFA_FCS_PORT_SM_STOP:
- if (port->num_rports == 0) {
- bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
- /* If vport - send completion call back */
- if (port->vport)
- bfa_fcs_vport_stop_comp(port->vport);
- else
- bfa_wc_down(&(port->fabric->stop_wc));
- } else {
- bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
- list_for_each_safe(qe, qen, &port->rport_q) {
- rport = (struct bfa_fcs_rport_s *) qe;
- bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
- }
- }
- break;
- case BFA_FCS_PORT_SM_DELETE:
- if (port->num_rports == 0) {
- bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
- bfa_fcs_lport_deleted(port);
- } else {
- bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
- list_for_each_safe(qe, qen, &port->rport_q) {
- rport = (struct bfa_fcs_rport_s *) qe;
- bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
- }
- }
- break;
- case BFA_FCS_PORT_SM_DELRPORT:
- case BFA_FCS_PORT_SM_OFFLINE:
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event)
- {
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case BFA_FCS_PORT_SM_DELRPORT:
- if (port->num_rports == 0) {
- bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
- /* If vport - send completion call back */
- if (port->vport)
- bfa_fcs_vport_stop_comp(port->vport);
- else
- bfa_wc_down(&(port->fabric->stop_wc));
- }
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_sm_deleting(
- struct bfa_fcs_lport_s *port,
- enum bfa_fcs_lport_event event)
- {
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case BFA_FCS_PORT_SM_DELRPORT:
- if (port->num_rports == 0) {
- bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
- bfa_fcs_lport_deleted(port);
- }
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- /*
- * fcs_port_pvt
- */
- /*
- * Send AEN notification
- */
- static void
- bfa_fcs_lport_aen_post(struct bfa_fcs_lport_s *port,
- enum bfa_lport_aen_event event)
- {
- struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
- struct bfa_aen_entry_s *aen_entry;
- bfad_get_aen_entry(bfad, aen_entry);
- if (!aen_entry)
- return;
- aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
- aen_entry->aen_data.lport.roles = port->port_cfg.roles;
- aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
- bfa_fcs_get_base_port(port->fcs));
- aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
- /* Send the AEN notification */
- bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
- BFA_AEN_CAT_LPORT, event);
- }
- /*
- * Send a LS reject
- */
- static void
- bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
- u8 reason_code, u8 reason_code_expl)
- {
- struct fchs_s fchs;
- struct bfa_fcxp_s *fcxp;
- struct bfa_rport_s *bfa_rport = NULL;
- int len;
- bfa_trc(port->fcs, rx_fchs->d_id);
- bfa_trc(port->fcs, rx_fchs->s_id);
- fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
- if (!fcxp)
- return;
- len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
- rx_fchs->ox_id, reason_code, reason_code_expl);
- bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
- BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
- FC_MAX_PDUSZ, 0);
- }
- /*
- * Send a FCCT Reject
- */
- static void
- bfa_fcs_lport_send_fcgs_rjt(struct bfa_fcs_lport_s *port,
- struct fchs_s *rx_fchs, u8 reason_code, u8 reason_code_expl)
- {
- struct fchs_s fchs;
- struct bfa_fcxp_s *fcxp;
- struct bfa_rport_s *bfa_rport = NULL;
- int len;
- struct ct_hdr_s *rx_cthdr = (struct ct_hdr_s *)(rx_fchs + 1);
- struct ct_hdr_s *ct_hdr;
- bfa_trc(port->fcs, rx_fchs->d_id);
- bfa_trc(port->fcs, rx_fchs->s_id);
- fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
- if (!fcxp)
- return;
- ct_hdr = bfa_fcxp_get_reqbuf(fcxp);
- ct_hdr->gs_type = rx_cthdr->gs_type;
- ct_hdr->gs_sub_type = rx_cthdr->gs_sub_type;
- len = fc_gs_rjt_build(&fchs, ct_hdr, rx_fchs->s_id,
- bfa_fcs_lport_get_fcid(port),
- rx_fchs->ox_id, reason_code, reason_code_expl);
- bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
- BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
- FC_MAX_PDUSZ, 0);
- }
- /*
- * Process incoming plogi from a remote port.
- */
- static void
- bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
- struct fchs_s *rx_fchs, struct fc_logi_s *plogi)
- {
- struct bfa_fcs_rport_s *rport;
- bfa_trc(port->fcs, rx_fchs->d_id);
- bfa_trc(port->fcs, rx_fchs->s_id);
- /*
- * If min cfg mode is enabled, drop any incoming PLOGIs
- */
- if (__fcs_min_cfg(port->fcs)) {
- bfa_trc(port->fcs, rx_fchs->s_id);
- return;
- }
- if (fc_plogi_parse(rx_fchs) != FC_PARSE_OK) {
- bfa_trc(port->fcs, rx_fchs->s_id);
- /*
- * send a LS reject
- */
- bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
- FC_LS_RJT_RSN_PROTOCOL_ERROR,
- FC_LS_RJT_EXP_SPARMS_ERR_OPTIONS);
- return;
- }
- /*
- * Direct Attach P2P mode : verify address assigned by the r-port.
- */
- if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
- (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
- (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
- if (BFA_FCS_PID_IS_WKA(rx_fchs->d_id)) {
- /* Address assigned to us cannot be a WKA */
- bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
- FC_LS_RJT_RSN_PROTOCOL_ERROR,
- FC_LS_RJT_EXP_INVALID_NPORT_ID);
- return;
- }
- port->pid = rx_fchs->d_id;
- bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
- }
- /*
- * First, check if we know the device by pwwn.
- */
- rport = bfa_fcs_lport_get_rport_by_pwwn(port, plogi->port_name);
- if (rport) {
- /*
- * Direct Attach P2P mode : handle address assigned by r-port.
- */
- if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
- (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
- (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
- port->pid = rx_fchs->d_id;
- bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
- rport->pid = rx_fchs->s_id;
- }
- bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
- return;
- }
- /*
- * Next, lookup rport by PID.
- */
- rport = bfa_fcs_lport_get_rport_by_pid(port, rx_fchs->s_id);
- if (!rport) {
- /*
- * Inbound PLOGI from a new device.
- */
- bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
- return;
- }
- /*
- * Rport is known only by PID.
- */
- if (rport->pwwn) {
- /*
- * This is a different device with the same pid. Old device
- * disappeared. Send implicit LOGO to old device.
- */
- WARN_ON(rport->pwwn == plogi->port_name);
- bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
- /*
- * Inbound PLOGI from a new device (with old PID).
- */
- bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
- return;
- }
- /*
- * PLOGI crossing each other.
- */
- WARN_ON(rport->pwwn != WWN_NULL);
- bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
- }
- /*
- * Process incoming ECHO.
- * Since it does not require a login, it is processed here.
- */
- static void
- bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
- struct fc_echo_s *echo, u16 rx_len)
- {
- struct fchs_s fchs;
- struct bfa_fcxp_s *fcxp;
- struct bfa_rport_s *bfa_rport = NULL;
- int len, pyld_len;
- bfa_trc(port->fcs, rx_fchs->s_id);
- bfa_trc(port->fcs, rx_fchs->d_id);
- fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
- if (!fcxp)
- return;
- len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
- rx_fchs->ox_id);
- /*
- * Copy the payload (if any) from the echo frame
- */
- pyld_len = rx_len - sizeof(struct fchs_s);
- bfa_trc(port->fcs, rx_len);
- bfa_trc(port->fcs, pyld_len);
- if (pyld_len > len)
- memcpy(((u8 *) bfa_fcxp_get_reqbuf(fcxp)) +
- sizeof(struct fc_echo_s), (echo + 1),
- (pyld_len - sizeof(struct fc_echo_s)));
- bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
- BFA_FALSE, FC_CLASS_3, pyld_len, &fchs, NULL, NULL,
- FC_MAX_PDUSZ, 0);
- }
- /*
- * Process incoming RNID.
- * Since it does not require a login, it is processed here.
- */
- static void
- bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
- struct fc_rnid_cmd_s *rnid, u16 rx_len)
- {
- struct fc_rnid_common_id_data_s common_id_data;
- struct fc_rnid_general_topology_data_s gen_topo_data;
- struct fchs_s fchs;
- struct bfa_fcxp_s *fcxp;
- struct bfa_rport_s *bfa_rport = NULL;
- u16 len;
- u32 data_format;
- bfa_trc(port->fcs, rx_fchs->s_id);
- bfa_trc(port->fcs, rx_fchs->d_id);
- bfa_trc(port->fcs, rx_len);
- fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
- if (!fcxp)
- return;
- /*
- * Check Node Indentification Data Format
- * We only support General Topology Discovery Format.
- * For any other requested Data Formats, we return Common Node Id Data
- * only, as per FC-LS.
- */
- bfa_trc(port->fcs, rnid->node_id_data_format);
- if (rnid->node_id_data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
- data_format = RNID_NODEID_DATA_FORMAT_DISCOVERY;
- /*
- * Get General topology data for this port
- */
- bfa_fs_port_get_gen_topo_data(port, &gen_topo_data);
- } else {
- data_format = RNID_NODEID_DATA_FORMAT_COMMON;
- }
- /*
- * Copy the Node Id Info
- */
- common_id_data.port_name = bfa_fcs_lport_get_pwwn(port);
- common_id_data.node_name = bfa_fcs_lport_get_nwwn(port);
- len = fc_rnid_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
- rx_fchs->ox_id, data_format, &common_id_data,
- &gen_topo_data);
- bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
- BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
- FC_MAX_PDUSZ, 0);
- }
- /*
- * Fill out General Topolpgy Discovery Data for RNID ELS.
- */
- static void
- bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
- struct fc_rnid_general_topology_data_s *gen_topo_data)
- {
- memset(gen_topo_data, 0,
- sizeof(struct fc_rnid_general_topology_data_s));
- gen_topo_data->asso_type = cpu_to_be32(RNID_ASSOCIATED_TYPE_HOST);
- gen_topo_data->phy_port_num = 0; /* @todo */
- gen_topo_data->num_attached_nodes = cpu_to_be32(1);
- }
- static void
- bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port)
- {
- struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
- char lpwwn_buf[BFA_STRING_32];
- bfa_trc(port->fcs, port->fabric->oper_type);
- __port_action[port->fabric->fab_type].init(port);
- __port_action[port->fabric->fab_type].online(port);
- wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
- BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
- "Logical port online: WWN = %s Role = %s\n",
- lpwwn_buf, "Initiator");
- bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_ONLINE);
- bfad->bfad_flags |= BFAD_PORT_ONLINE;
- }
- static void
- bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port)
- {
- struct list_head *qe, *qen;
- struct bfa_fcs_rport_s *rport;
- struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
- char lpwwn_buf[BFA_STRING_32];
- bfa_trc(port->fcs, port->fabric->oper_type);
- __port_action[port->fabric->fab_type].offline(port);
- wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
- if (bfa_sm_cmp_state(port->fabric,
- bfa_fcs_fabric_sm_online) == BFA_TRUE) {
- BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
- "Logical port lost fabric connectivity: WWN = %s Role = %s\n",
- lpwwn_buf, "Initiator");
- bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DISCONNECT);
- } else {
- BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
- "Logical port taken offline: WWN = %s Role = %s\n",
- lpwwn_buf, "Initiator");
- bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_OFFLINE);
- }
- list_for_each_safe(qe, qen, &port->rport_q) {
- rport = (struct bfa_fcs_rport_s *) qe;
- bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
- }
- }
- static void
- bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port)
- {
- WARN_ON(1);
- }
- static void
- bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port)
- {
- WARN_ON(1);
- }
- static void
- bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port)
- {
- WARN_ON(1);
- }
- static void
- bfa_fcs_lport_abts_acc(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs)
- {
- struct fchs_s fchs;
- struct bfa_fcxp_s *fcxp;
- int len;
- bfa_trc(port->fcs, rx_fchs->d_id);
- bfa_trc(port->fcs, rx_fchs->s_id);
- fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
- if (!fcxp)
- return;
- len = fc_ba_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
- rx_fchs->ox_id, 0);
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
- BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
- FC_MAX_PDUSZ, 0);
- }
- static void
- bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port)
- {
- struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
- char lpwwn_buf[BFA_STRING_32];
- wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
- BFA_LOG(KERN_INFO, bfad, bfa_log_level,
- "Logical port deleted: WWN = %s Role = %s\n",
- lpwwn_buf, "Initiator");
- bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DELETE);
- /* Base port will be deleted by the OS driver */
- if (port->vport)
- bfa_fcs_vport_delete_comp(port->vport);
- else
- bfa_wc_down(&port->fabric->wc);
- }
- /*
- * Unsolicited frame receive handling.
- */
- void
- bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
- struct fchs_s *fchs, u16 len)
- {
- u32 pid = fchs->s_id;
- struct bfa_fcs_rport_s *rport = NULL;
- struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
- bfa_stats(lport, uf_recvs);
- bfa_trc(lport->fcs, fchs->type);
- if (!bfa_fcs_lport_is_online(lport)) {
- /*
- * In direct attach topology, it is possible to get a PLOGI
- * before the lport is online due to port feature
- * (QoS/Trunk/FEC/CR), so send a rjt
- */
- if ((fchs->type == FC_TYPE_ELS) &&
- (els_cmd->els_code == FC_ELS_PLOGI)) {
- bfa_fcs_lport_send_ls_rjt(lport, fchs,
- FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
- FC_LS_RJT_EXP_NO_ADDL_INFO);
- bfa_stats(lport, plogi_rcvd);
- } else
- bfa_stats(lport, uf_recv_drops);
- return;
- }
- /*
- * First, handle ELSs that donot require a login.
- */
- /*
- * Handle PLOGI first
- */
- if ((fchs->type == FC_TYPE_ELS) &&
- (els_cmd->els_code == FC_ELS_PLOGI)) {
- bfa_fcs_lport_plogi(lport, fchs, (struct fc_logi_s *) els_cmd);
- return;
- }
- /*
- * Handle ECHO separately.
- */
- if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_ECHO)) {
- bfa_fcs_lport_echo(lport, fchs,
- (struct fc_echo_s *)els_cmd, len);
- return;
- }
- /*
- * Handle RNID separately.
- */
- if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_RNID)) {
- bfa_fcs_lport_rnid(lport, fchs,
- (struct fc_rnid_cmd_s *) els_cmd, len);
- return;
- }
- if (fchs->type == FC_TYPE_BLS) {
- if ((fchs->routing == FC_RTG_BASIC_LINK) &&
- (fchs->cat_info == FC_CAT_ABTS))
- bfa_fcs_lport_abts_acc(lport, fchs);
- return;
- }
- if (fchs->type == FC_TYPE_SERVICES) {
- /*
- * Unhandled FC-GS frames. Send a FC-CT Reject
- */
- bfa_fcs_lport_send_fcgs_rjt(lport, fchs, CT_RSN_NOT_SUPP,
- CT_NS_EXP_NOADDITIONAL);
- return;
- }
- /*
- * look for a matching remote port ID
- */
- rport = bfa_fcs_lport_get_rport_by_pid(lport, pid);
- if (rport) {
- bfa_trc(rport->fcs, fchs->s_id);
- bfa_trc(rport->fcs, fchs->d_id);
- bfa_trc(rport->fcs, fchs->type);
- bfa_fcs_rport_uf_recv(rport, fchs, len);
- return;
- }
- /*
- * Only handles ELS frames for now.
- */
- if (fchs->type != FC_TYPE_ELS) {
- bfa_trc(lport->fcs, fchs->s_id);
- bfa_trc(lport->fcs, fchs->d_id);
- /* ignore type FC_TYPE_FC_FSS */
- if (fchs->type != FC_TYPE_FC_FSS)
- bfa_sm_fault(lport->fcs, fchs->type);
- return;
- }
- bfa_trc(lport->fcs, els_cmd->els_code);
- if (els_cmd->els_code == FC_ELS_RSCN) {
- bfa_fcs_lport_scn_process_rscn(lport, fchs, len);
- return;
- }
- if (els_cmd->els_code == FC_ELS_LOGO) {
- /*
- * @todo Handle LOGO frames received.
- */
- return;
- }
- if (els_cmd->els_code == FC_ELS_PRLI) {
- /*
- * @todo Handle PRLI frames received.
- */
- return;
- }
- /*
- * Unhandled ELS frames. Send a LS_RJT.
- */
- bfa_fcs_lport_send_ls_rjt(lport, fchs, FC_LS_RJT_RSN_CMD_NOT_SUPP,
- FC_LS_RJT_EXP_NO_ADDL_INFO);
- }
- /*
- * PID based Lookup for a R-Port in the Port R-Port Queue
- */
- struct bfa_fcs_rport_s *
- bfa_fcs_lport_get_rport_by_pid(struct bfa_fcs_lport_s *port, u32 pid)
- {
- struct bfa_fcs_rport_s *rport;
- struct list_head *qe;
- list_for_each(qe, &port->rport_q) {
- rport = (struct bfa_fcs_rport_s *) qe;
- if (rport->pid == pid)
- return rport;
- }
- bfa_trc(port->fcs, pid);
- return NULL;
- }
- /*
- * OLD_PID based Lookup for a R-Port in the Port R-Port Queue
- */
- struct bfa_fcs_rport_s *
- bfa_fcs_lport_get_rport_by_old_pid(struct bfa_fcs_lport_s *port, u32 pid)
- {
- struct bfa_fcs_rport_s *rport;
- struct list_head *qe;
- list_for_each(qe, &port->rport_q) {
- rport = (struct bfa_fcs_rport_s *) qe;
- if (rport->old_pid == pid)
- return rport;
- }
- bfa_trc(port->fcs, pid);
- return NULL;
- }
- /*
- * PWWN based Lookup for a R-Port in the Port R-Port Queue
- */
- struct bfa_fcs_rport_s *
- bfa_fcs_lport_get_rport_by_pwwn(struct bfa_fcs_lport_s *port, wwn_t pwwn)
- {
- struct bfa_fcs_rport_s *rport;
- struct list_head *qe;
- list_for_each(qe, &port->rport_q) {
- rport = (struct bfa_fcs_rport_s *) qe;
- if (wwn_is_equal(rport->pwwn, pwwn))
- return rport;
- }
- bfa_trc(port->fcs, pwwn);
- return NULL;
- }
- /*
- * NWWN based Lookup for a R-Port in the Port R-Port Queue
- */
- struct bfa_fcs_rport_s *
- bfa_fcs_lport_get_rport_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t nwwn)
- {
- struct bfa_fcs_rport_s *rport;
- struct list_head *qe;
- list_for_each(qe, &port->rport_q) {
- rport = (struct bfa_fcs_rport_s *) qe;
- if (wwn_is_equal(rport->nwwn, nwwn))
- return rport;
- }
- bfa_trc(port->fcs, nwwn);
- return NULL;
- }
- /*
- * PWWN & PID based Lookup for a R-Port in the Port R-Port Queue
- */
- struct bfa_fcs_rport_s *
- bfa_fcs_lport_get_rport_by_qualifier(struct bfa_fcs_lport_s *port,
- wwn_t pwwn, u32 pid)
- {
- struct bfa_fcs_rport_s *rport;
- struct list_head *qe;
- list_for_each(qe, &port->rport_q) {
- rport = (struct bfa_fcs_rport_s *) qe;
- if (wwn_is_equal(rport->pwwn, pwwn) && rport->pid == pid)
- return rport;
- }
- bfa_trc(port->fcs, pwwn);
- return NULL;
- }
- /*
- * Called by rport module when new rports are discovered.
- */
- void
- bfa_fcs_lport_add_rport(
- struct bfa_fcs_lport_s *port,
- struct bfa_fcs_rport_s *rport)
- {
- list_add_tail(&rport->qe, &port->rport_q);
- port->num_rports++;
- }
- /*
- * Called by rport module to when rports are deleted.
- */
- void
- bfa_fcs_lport_del_rport(
- struct bfa_fcs_lport_s *port,
- struct bfa_fcs_rport_s *rport)
- {
- WARN_ON(!bfa_q_is_on_q(&port->rport_q, rport));
- list_del(&rport->qe);
- port->num_rports--;
- bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELRPORT);
- }
- /*
- * Called by fabric for base port when fabric login is complete.
- * Called by vport for virtual ports when FDISC is complete.
- */
- void
- bfa_fcs_lport_online(struct bfa_fcs_lport_s *port)
- {
- bfa_sm_send_event(port, BFA_FCS_PORT_SM_ONLINE);
- }
- /*
- * Called by fabric for base port when fabric goes offline.
- * Called by vport for virtual ports when virtual port becomes offline.
- */
- void
- bfa_fcs_lport_offline(struct bfa_fcs_lport_s *port)
- {
- bfa_sm_send_event(port, BFA_FCS_PORT_SM_OFFLINE);
- }
- /*
- * Called by fabric for base port and by vport for virtual ports
- * when target mode driver is unloaded.
- */
- void
- bfa_fcs_lport_stop(struct bfa_fcs_lport_s *port)
- {
- bfa_sm_send_event(port, BFA_FCS_PORT_SM_STOP);
- }
- /*
- * Called by fabric to delete base lport and associated resources.
- *
- * Called by vport to delete lport and associated resources. Should call
- * bfa_fcs_vport_delete_comp() for vports on completion.
- */
- void
- bfa_fcs_lport_delete(struct bfa_fcs_lport_s *port)
- {
- bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELETE);
- }
- /*
- * Return TRUE if port is online, else return FALSE
- */
- bfa_boolean_t
- bfa_fcs_lport_is_online(struct bfa_fcs_lport_s *port)
- {
- return bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online);
- }
- /*
- * Attach time initialization of logical ports.
- */
- void
- bfa_fcs_lport_attach(struct bfa_fcs_lport_s *lport, struct bfa_fcs_s *fcs,
- u16 vf_id, struct bfa_fcs_vport_s *vport)
- {
- lport->fcs = fcs;
- lport->fabric = bfa_fcs_vf_lookup(fcs, vf_id);
- lport->vport = vport;
- lport->lp_tag = (vport) ? vport->lps->bfa_tag :
- lport->fabric->lps->bfa_tag;
- INIT_LIST_HEAD(&lport->rport_q);
- lport->num_rports = 0;
- }
- /*
- * Logical port initialization of base or virtual port.
- * Called by fabric for base port or by vport for virtual ports.
- */
- void
- bfa_fcs_lport_init(struct bfa_fcs_lport_s *lport,
- struct bfa_lport_cfg_s *port_cfg)
- {
- struct bfa_fcs_vport_s *vport = lport->vport;
- struct bfad_s *bfad = (struct bfad_s *)lport->fcs->bfad;
- char lpwwn_buf[BFA_STRING_32];
- lport->port_cfg = *port_cfg;
- lport->bfad_port = bfa_fcb_lport_new(lport->fcs->bfad, lport,
- lport->port_cfg.roles,
- lport->fabric->vf_drv,
- vport ? vport->vport_drv : NULL);
- wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(lport));
- BFA_LOG(KERN_INFO, bfad, bfa_log_level,
- "New logical port created: WWN = %s Role = %s\n",
- lpwwn_buf, "Initiator");
- bfa_fcs_lport_aen_post(lport, BFA_LPORT_AEN_NEW);
- bfa_sm_set_state(lport, bfa_fcs_lport_sm_uninit);
- bfa_sm_send_event(lport, BFA_FCS_PORT_SM_CREATE);
- }
- void
- bfa_fcs_lport_set_symname(struct bfa_fcs_lport_s *port,
- char *symname)
- {
- strcpy(port->port_cfg.sym_name.symname, symname);
- if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
- bfa_fcs_lport_ns_util_send_rspn_id(
- BFA_FCS_GET_NS_FROM_PORT(port), NULL);
- }
- /*
- * fcs_lport_api
- */
- void
- bfa_fcs_lport_get_attr(
- struct bfa_fcs_lport_s *port,
- struct bfa_lport_attr_s *port_attr)
- {
- if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
- port_attr->pid = port->pid;
- else
- port_attr->pid = 0;
- port_attr->port_cfg = port->port_cfg;
- if (port->fabric) {
- port_attr->port_type = port->fabric->oper_type;
- port_attr->loopback = bfa_sm_cmp_state(port->fabric,
- bfa_fcs_fabric_sm_loopback);
- port_attr->authfail =
- bfa_sm_cmp_state(port->fabric,
- bfa_fcs_fabric_sm_auth_failed);
- port_attr->fabric_name = bfa_fcs_lport_get_fabric_name(port);
- memcpy(port_attr->fabric_ip_addr,
- bfa_fcs_lport_get_fabric_ipaddr(port),
- BFA_FCS_FABRIC_IPADDR_SZ);
- if (port->vport != NULL) {
- port_attr->port_type = BFA_PORT_TYPE_VPORT;
- port_attr->fpma_mac =
- port->vport->lps->lp_mac;
- } else {
- port_attr->fpma_mac =
- port->fabric->lps->lp_mac;
- }
- } else {
- port_attr->port_type = BFA_PORT_TYPE_UNKNOWN;
- port_attr->state = BFA_LPORT_UNINIT;
- }
- }
- /*
- * bfa_fcs_lport_fab port fab functions
- */
- /*
- * Called by port to initialize fabric services of the base port.
- */
- static void
- bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port)
- {
- bfa_fcs_lport_ns_init(port);
- bfa_fcs_lport_scn_init(port);
- bfa_fcs_lport_ms_init(port);
- }
- /*
- * Called by port to notify transition to online state.
- */
- static void
- bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port)
- {
- bfa_fcs_lport_ns_online(port);
- bfa_fcs_lport_fab_scn_online(port);
- }
- /*
- * Called by port to notify transition to offline state.
- */
- static void
- bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port)
- {
- bfa_fcs_lport_ns_offline(port);
- bfa_fcs_lport_scn_offline(port);
- bfa_fcs_lport_ms_offline(port);
- }
- /*
- * bfa_fcs_lport_n2n functions
- */
- /*
- * Called by fcs/port to initialize N2N topology.
- */
- static void
- bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port)
- {
- }
- /*
- * Called by fcs/port to notify transition to online state.
- */
- static void
- bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
- struct bfa_lport_cfg_s *pcfg = &port->port_cfg;
- struct bfa_fcs_rport_s *rport;
- bfa_trc(port->fcs, pcfg->pwwn);
- /*
- * If our PWWN is > than that of the r-port, we have to initiate PLOGI
- * and assign an Address. if not, we need to wait for its PLOGI.
- *
- * If our PWWN is < than that of the remote port, it will send a PLOGI
- * with the PIDs assigned. The rport state machine take care of this
- * incoming PLOGI.
- */
- if (memcmp
- ((void *)&pcfg->pwwn, (void *)&n2n_port->rem_port_wwn,
- sizeof(wwn_t)) > 0) {
- port->pid = N2N_LOCAL_PID;
- bfa_lps_set_n2n_pid(port->fabric->lps, N2N_LOCAL_PID);
- /*
- * First, check if we know the device by pwwn.
- */
- rport = bfa_fcs_lport_get_rport_by_pwwn(port,
- n2n_port->rem_port_wwn);
- if (rport) {
- bfa_trc(port->fcs, rport->pid);
- bfa_trc(port->fcs, rport->pwwn);
- rport->pid = N2N_REMOTE_PID;
- bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
- return;
- }
- /*
- * In n2n there can be only one rport. Delete the old one
- * whose pid should be zero, because it is offline.
- */
- if (port->num_rports > 0) {
- rport = bfa_fcs_lport_get_rport_by_pid(port, 0);
- WARN_ON(rport == NULL);
- if (rport) {
- bfa_trc(port->fcs, rport->pwwn);
- bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
- }
- }
- bfa_fcs_rport_create(port, N2N_REMOTE_PID);
- }
- }
- /*
- * Called by fcs/port to notify transition to offline state.
- */
- static void
- bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
- bfa_trc(port->fcs, port->pid);
- port->pid = 0;
- n2n_port->rem_port_wwn = 0;
- n2n_port->reply_oxid = 0;
- }
- void
- bfa_fcport_get_loop_attr(struct bfa_fcs_lport_s *port)
- {
- int i = 0, j = 0, bit = 0, alpa_bit = 0;
- u8 k = 0;
- struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(port->fcs->bfa);
- port->port_topo.ploop.alpabm_valid = fcport->alpabm_valid;
- port->pid = fcport->myalpa;
- port->pid = bfa_hton3b(port->pid);
- for (i = 0; i < (FC_ALPA_MAX / 8); i++) {
- for (j = 0, alpa_bit = 0; j < 8; j++, alpa_bit++) {
- bfa_trc(port->fcs->bfa, fcport->alpabm.alpa_bm[i]);
- bit = (fcport->alpabm.alpa_bm[i] & (1 << (7 - j)));
- if (bit) {
- port->port_topo.ploop.alpa_pos_map[k] =
- loop_alpa_map[(i * 8) + alpa_bit];
- k++;
- bfa_trc(port->fcs->bfa, k);
- bfa_trc(port->fcs->bfa,
- port->port_topo.ploop.alpa_pos_map[k]);
- }
- }
- }
- port->port_topo.ploop.num_alpa = k;
- }
- /*
- * Called by fcs/port to initialize Loop topology.
- */
- static void
- bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port)
- {
- }
- /*
- * Called by fcs/port to notify transition to online state.
- */
- static void
- bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port)
- {
- u8 num_alpa = 0, alpabm_valid = 0;
- struct bfa_fcs_rport_s *rport;
- u8 *alpa_map = NULL;
- int i = 0;
- u32 pid;
- bfa_fcport_get_loop_attr(port);
- num_alpa = port->port_topo.ploop.num_alpa;
- alpabm_valid = port->port_topo.ploop.alpabm_valid;
- alpa_map = port->port_topo.ploop.alpa_pos_map;
- bfa_trc(port->fcs->bfa, port->pid);
- bfa_trc(port->fcs->bfa, num_alpa);
- if (alpabm_valid == 1) {
- for (i = 0; i < num_alpa; i++) {
- bfa_trc(port->fcs->bfa, alpa_map[i]);
- if (alpa_map[i] != bfa_hton3b(port->pid)) {
- pid = alpa_map[i];
- bfa_trc(port->fcs->bfa, pid);
- rport = bfa_fcs_lport_get_rport_by_pid(port,
- bfa_hton3b(pid));
- if (!rport)
- rport = bfa_fcs_rport_create(port,
- bfa_hton3b(pid));
- }
- }
- } else {
- for (i = 0; i < MAX_ALPA_COUNT; i++) {
- if (alpa_map[i] != port->pid) {
- pid = loop_alpa_map[i];
- bfa_trc(port->fcs->bfa, pid);
- rport = bfa_fcs_lport_get_rport_by_pid(port,
- bfa_hton3b(pid));
- if (!rport)
- rport = bfa_fcs_rport_create(port,
- bfa_hton3b(pid));
- }
- }
- }
- }
- /*
- * Called by fcs/port to notify transition to offline state.
- */
- static void
- bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port)
- {
- }
- #define BFA_FCS_FDMI_CMD_MAX_RETRIES 2
- /*
- * forward declarations
- */
- static void bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_fdmi_rhba_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_fdmi_rprt_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_fdmi_rpa_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_fdmi_timeout(void *arg);
- static u16 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
- u8 *pyld);
- static u16 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
- u8 *pyld);
- static u16 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
- u8 *pyld);
- static u16 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *
- fdmi, u8 *pyld);
- static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
- struct bfa_fcs_fdmi_hba_attr_s *hba_attr);
- static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
- struct bfa_fcs_fdmi_port_attr_s *port_attr);
- u32 bfa_fcs_fdmi_convert_speed(enum bfa_port_speed pport_speed);
- /*
- * fcs_fdmi_sm FCS FDMI state machine
- */
- /*
- * FDMI State Machine events
- */
- enum port_fdmi_event {
- FDMISM_EVENT_PORT_ONLINE = 1,
- FDMISM_EVENT_PORT_OFFLINE = 2,
- FDMISM_EVENT_RSP_OK = 4,
- FDMISM_EVENT_RSP_ERROR = 5,
- FDMISM_EVENT_TIMEOUT = 6,
- FDMISM_EVENT_RHBA_SENT = 7,
- FDMISM_EVENT_RPRT_SENT = 8,
- FDMISM_EVENT_RPA_SENT = 9,
- };
- static void bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- static void bfa_fcs_lport_fdmi_sm_sending_rhba(
- struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- static void bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- static void bfa_fcs_lport_fdmi_sm_rhba_retry(
- struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- static void bfa_fcs_lport_fdmi_sm_sending_rprt(
- struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- static void bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- static void bfa_fcs_lport_fdmi_sm_rprt_retry(
- struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- static void bfa_fcs_lport_fdmi_sm_sending_rpa(
- struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- static void bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- static void bfa_fcs_lport_fdmi_sm_rpa_retry(
- struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- static void bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- static void bfa_fcs_lport_fdmi_sm_disabled(
- struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event);
- /*
- * Start in offline state - awaiting MS to send start.
- */
- static void
- bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- fdmi->retry_cnt = 0;
- switch (event) {
- case FDMISM_EVENT_PORT_ONLINE:
- if (port->vport) {
- /*
- * For Vports, register a new port.
- */
- bfa_sm_set_state(fdmi,
- bfa_fcs_lport_fdmi_sm_sending_rprt);
- bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
- } else {
- /*
- * For a base port, we should first register the HBA
- * attribute. The HBA attribute also contains the base
- * port registration.
- */
- bfa_sm_set_state(fdmi,
- bfa_fcs_lport_fdmi_sm_sending_rhba);
- bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
- }
- break;
- case FDMISM_EVENT_PORT_OFFLINE:
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_fdmi_sm_sending_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case FDMISM_EVENT_RHBA_SENT:
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rhba);
- break;
- case FDMISM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
- &fdmi->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case FDMISM_EVENT_RSP_ERROR:
- /*
- * if max retries have not been reached, start timer for a
- * delayed retry
- */
- if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
- bfa_sm_set_state(fdmi,
- bfa_fcs_lport_fdmi_sm_rhba_retry);
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
- &fdmi->timer,
- bfa_fcs_lport_fdmi_timeout, fdmi,
- BFA_FCS_RETRY_TIMEOUT);
- } else {
- /*
- * set state to offline
- */
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- }
- break;
- case FDMISM_EVENT_RSP_OK:
- /*
- * Initiate Register Port Attributes
- */
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
- fdmi->retry_cnt = 0;
- bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
- break;
- case FDMISM_EVENT_PORT_OFFLINE:
- bfa_fcxp_discard(fdmi->fcxp);
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_fdmi_sm_rhba_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case FDMISM_EVENT_TIMEOUT:
- /*
- * Retry Timer Expired. Re-send
- */
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rhba);
- bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
- break;
- case FDMISM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- bfa_timer_stop(&fdmi->timer);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- /*
- * RPRT : Register Port
- */
- static void
- bfa_fcs_lport_fdmi_sm_sending_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case FDMISM_EVENT_RPRT_SENT:
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rprt);
- break;
- case FDMISM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
- &fdmi->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case FDMISM_EVENT_RSP_ERROR:
- /*
- * if max retries have not been reached, start timer for a
- * delayed retry
- */
- if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
- bfa_sm_set_state(fdmi,
- bfa_fcs_lport_fdmi_sm_rprt_retry);
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
- &fdmi->timer,
- bfa_fcs_lport_fdmi_timeout, fdmi,
- BFA_FCS_RETRY_TIMEOUT);
- } else {
- /*
- * set state to offline
- */
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- fdmi->retry_cnt = 0;
- }
- break;
- case FDMISM_EVENT_RSP_OK:
- fdmi->retry_cnt = 0;
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
- break;
- case FDMISM_EVENT_PORT_OFFLINE:
- bfa_fcxp_discard(fdmi->fcxp);
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_fdmi_sm_rprt_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case FDMISM_EVENT_TIMEOUT:
- /*
- * Retry Timer Expired. Re-send
- */
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rprt);
- bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
- break;
- case FDMISM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- bfa_timer_stop(&fdmi->timer);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- /*
- * Register Port Attributes
- */
- static void
- bfa_fcs_lport_fdmi_sm_sending_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case FDMISM_EVENT_RPA_SENT:
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa);
- break;
- case FDMISM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
- &fdmi->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case FDMISM_EVENT_RSP_ERROR:
- /*
- * if max retries have not been reached, start timer for a
- * delayed retry
- */
- if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa_retry);
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
- &fdmi->timer,
- bfa_fcs_lport_fdmi_timeout, fdmi,
- BFA_FCS_RETRY_TIMEOUT);
- } else {
- /*
- * set state to offline
- */
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- fdmi->retry_cnt = 0;
- }
- break;
- case FDMISM_EVENT_RSP_OK:
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
- fdmi->retry_cnt = 0;
- break;
- case FDMISM_EVENT_PORT_OFFLINE:
- bfa_fcxp_discard(fdmi->fcxp);
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_fdmi_sm_rpa_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case FDMISM_EVENT_TIMEOUT:
- /*
- * Retry Timer Expired. Re-send
- */
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
- bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
- break;
- case FDMISM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- bfa_timer_stop(&fdmi->timer);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- switch (event) {
- case FDMISM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- /*
- * FDMI is disabled state.
- */
- static void
- bfa_fcs_lport_fdmi_sm_disabled(struct bfa_fcs_lport_fdmi_s *fdmi,
- enum port_fdmi_event event)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- bfa_trc(port->fcs, event);
- /* No op State. It can only be enabled at Driver Init. */
- }
- /*
- * RHBA : Register HBA Attributes.
- */
- static void
- bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- struct fchs_s fchs;
- int len, attr_len;
- struct bfa_fcxp_s *fcxp;
- u8 *pyld;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
- bfa_fcs_lport_fdmi_send_rhba, fdmi, BFA_TRUE);
- return;
- }
- fdmi->fcxp = fcxp;
- pyld = bfa_fcxp_get_reqbuf(fcxp);
- memset(pyld, 0, FC_MAX_PDUSZ);
- len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
- FDMI_RHBA);
- attr_len =
- bfa_fcs_lport_fdmi_build_rhba_pyld(fdmi,
- (u8 *) ((struct ct_hdr_s *) pyld
- + 1));
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, (len + attr_len), &fchs,
- bfa_fcs_lport_fdmi_rhba_response, (void *)fdmi,
- FC_MAX_PDUSZ, FC_FCCT_TOV);
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RHBA_SENT);
- }
- static u16
- bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- struct bfa_fcs_fdmi_hba_attr_s hba_attr;
- struct bfa_fcs_fdmi_hba_attr_s *fcs_hba_attr = &hba_attr;
- struct fdmi_rhba_s *rhba = (struct fdmi_rhba_s *) pyld;
- struct fdmi_attr_s *attr;
- u8 *curr_ptr;
- u16 len, count;
- u16 templen;
- /*
- * get hba attributes
- */
- bfa_fcs_fdmi_get_hbaattr(fdmi, fcs_hba_attr);
- rhba->hba_id = bfa_fcs_lport_get_pwwn(port);
- rhba->port_list.num_ports = cpu_to_be32(1);
- rhba->port_list.port_entry = bfa_fcs_lport_get_pwwn(port);
- len = sizeof(rhba->hba_id) + sizeof(rhba->port_list);
- count = 0;
- len += sizeof(rhba->hba_attr_blk.attr_count);
- /*
- * fill out the invididual entries of the HBA attrib Block
- */
- curr_ptr = (u8 *) &rhba->hba_attr_blk.hba_attr;
- /*
- * Node Name
- */
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODENAME);
- templen = sizeof(wwn_t);
- memcpy(attr->value, &bfa_fcs_lport_get_nwwn(port), templen);
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * Manufacturer
- */
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MANUFACTURER);
- templen = (u16) strlen(fcs_hba_attr->manufacturer);
- memcpy(attr->value, fcs_hba_attr->manufacturer, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * Serial Number
- */
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_SERIALNUM);
- templen = (u16) strlen(fcs_hba_attr->serial_num);
- memcpy(attr->value, fcs_hba_attr->serial_num, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * Model
- */
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL);
- templen = (u16) strlen(fcs_hba_attr->model);
- memcpy(attr->value, fcs_hba_attr->model, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * Model Desc
- */
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL_DESC);
- templen = (u16) strlen(fcs_hba_attr->model_desc);
- memcpy(attr->value, fcs_hba_attr->model_desc, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * H/W Version
- */
- if (fcs_hba_attr->hw_version[0] != '\0') {
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_HW_VERSION);
- templen = (u16) strlen(fcs_hba_attr->hw_version);
- memcpy(attr->value, fcs_hba_attr->hw_version, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- }
- /*
- * Driver Version
- */
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_DRIVER_VERSION);
- templen = (u16) strlen(fcs_hba_attr->driver_version);
- memcpy(attr->value, fcs_hba_attr->driver_version, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * Option Rom Version
- */
- if (fcs_hba_attr->option_rom_ver[0] != '\0') {
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_ROM_VERSION);
- templen = (u16) strlen(fcs_hba_attr->option_rom_ver);
- memcpy(attr->value, fcs_hba_attr->option_rom_ver, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- }
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FW_VERSION);
- templen = (u16) strlen(fcs_hba_attr->fw_version);
- memcpy(attr->value, fcs_hba_attr->fw_version, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * OS Name
- */
- if (fcs_hba_attr->os_name[0] != '\0') {
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_OS_NAME);
- templen = (u16) strlen(fcs_hba_attr->os_name);
- memcpy(attr->value, fcs_hba_attr->os_name, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- }
- /*
- * MAX_CT_PAYLOAD
- */
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MAX_CT);
- templen = sizeof(fcs_hba_attr->max_ct_pyld);
- memcpy(attr->value, &fcs_hba_attr->max_ct_pyld, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * Send extended attributes ( FOS 7.1 support )
- */
- if (fdmi->retry_cnt == 0) {
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODE_SYM_NAME);
- templen = sizeof(fcs_hba_attr->node_sym_name);
- memcpy(attr->value, &fcs_hba_attr->node_sym_name, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_VENDOR_ID);
- templen = sizeof(fcs_hba_attr->vendor_info);
- memcpy(attr->value, &fcs_hba_attr->vendor_info, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NUM_PORTS);
- templen = sizeof(fcs_hba_attr->num_ports);
- memcpy(attr->value, &fcs_hba_attr->num_ports, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FABRIC_NAME);
- templen = sizeof(fcs_hba_attr->fabric_name);
- memcpy(attr->value, &fcs_hba_attr->fabric_name, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_BIOS_VER);
- templen = sizeof(fcs_hba_attr->bios_ver);
- memcpy(attr->value, &fcs_hba_attr->bios_ver, templen);
- templen = fc_roundup(attr->len, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- count++;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- }
- /*
- * Update size of payload
- */
- len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
- rhba->hba_attr_blk.attr_count = cpu_to_be32(count);
- return len;
- }
- static void
- bfa_fcs_lport_fdmi_rhba_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len,
- struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_fdmi_s *fdmi =
- (struct bfa_fcs_lport_fdmi_s *) cbarg;
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- struct ct_hdr_s *cthdr = NULL;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
- return;
- }
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
- }
- /*
- * RPRT : Register Port
- */
- static void
- bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- struct fchs_s fchs;
- u16 len, attr_len;
- struct bfa_fcxp_s *fcxp;
- u8 *pyld;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
- bfa_fcs_lport_fdmi_send_rprt, fdmi, BFA_TRUE);
- return;
- }
- fdmi->fcxp = fcxp;
- pyld = bfa_fcxp_get_reqbuf(fcxp);
- memset(pyld, 0, FC_MAX_PDUSZ);
- len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
- FDMI_RPRT);
- attr_len =
- bfa_fcs_lport_fdmi_build_rprt_pyld(fdmi,
- (u8 *) ((struct ct_hdr_s *) pyld
- + 1));
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len + attr_len, &fchs,
- bfa_fcs_lport_fdmi_rprt_response, (void *)fdmi,
- FC_MAX_PDUSZ, FC_FCCT_TOV);
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RPRT_SENT);
- }
- /*
- * This routine builds Port Attribute Block that used in RPA, RPRT commands.
- */
- static u16
- bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
- u8 *pyld)
- {
- struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
- struct fdmi_port_attr_s *port_attrib = (struct fdmi_port_attr_s *) pyld;
- struct fdmi_attr_s *attr;
- u8 *curr_ptr;
- u16 len;
- u8 count = 0;
- u16 templen;
- /*
- * get port attributes
- */
- bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
- len = sizeof(port_attrib->attr_count);
- /*
- * fill out the invididual entries
- */
- curr_ptr = (u8 *) &port_attrib->port_attr;
- /*
- * FC4 Types
- */
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FC4_TYPES);
- templen = sizeof(fcs_port_attr.supp_fc4_types);
- memcpy(attr->value, fcs_port_attr.supp_fc4_types, templen);
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len =
- cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * Supported Speed
- */
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_SPEED);
- templen = sizeof(fcs_port_attr.supp_speed);
- memcpy(attr->value, &fcs_port_attr.supp_speed, templen);
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len =
- cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * current Port Speed
- */
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SPEED);
- templen = sizeof(fcs_port_attr.curr_speed);
- memcpy(attr->value, &fcs_port_attr.curr_speed, templen);
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * max frame size
- */
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FRAME_SIZE);
- templen = sizeof(fcs_port_attr.max_frm_size);
- memcpy(attr->value, &fcs_port_attr.max_frm_size, templen);
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- /*
- * OS Device Name
- */
- if (fcs_port_attr.os_device_name[0] != '\0') {
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_DEV_NAME);
- templen = (u16) strlen(fcs_port_attr.os_device_name);
- memcpy(attr->value, fcs_port_attr.os_device_name, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- }
- /*
- * Host Name
- */
- if (fcs_port_attr.host_name[0] != '\0') {
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_HOST_NAME);
- templen = (u16) strlen(fcs_port_attr.host_name);
- memcpy(attr->value, fcs_port_attr.host_name, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- }
- if (fdmi->retry_cnt == 0) {
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_NODE_NAME);
- templen = sizeof(fcs_port_attr.node_name);
- memcpy(attr->value, &fcs_port_attr.node_name, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NAME);
- templen = sizeof(fcs_port_attr.port_name);
- memcpy(attr->value, &fcs_port_attr.port_name, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(attr->len) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- if (fcs_port_attr.port_sym_name.symname[0] != '\0') {
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type =
- cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SYM_NAME);
- templen = sizeof(fcs_port_attr.port_sym_name);
- memcpy(attr->value,
- &fcs_port_attr.port_sym_name, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) +
- sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen +
- sizeof(attr->type) + sizeof(templen));
- }
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_TYPE);
- templen = sizeof(fcs_port_attr.port_type);
- memcpy(attr->value, &fcs_port_attr.port_type, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_COS);
- templen = sizeof(fcs_port_attr.scos);
- memcpy(attr->value, &fcs_port_attr.scos, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FAB_NAME);
- templen = sizeof(fcs_port_attr.port_fabric_name);
- memcpy(attr->value, &fcs_port_attr.port_fabric_name, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FC4_TYPE);
- templen = sizeof(fcs_port_attr.port_act_fc4_type);
- memcpy(attr->value, fcs_port_attr.port_act_fc4_type,
- templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_STATE);
- templen = sizeof(fcs_port_attr.port_state);
- memcpy(attr->value, &fcs_port_attr.port_state, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- attr = (struct fdmi_attr_s *) curr_ptr;
- attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NUM_RPRT);
- templen = sizeof(fcs_port_attr.num_ports);
- memcpy(attr->value, &fcs_port_attr.num_ports, templen);
- templen = fc_roundup(templen, sizeof(u32));
- curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
- len += templen;
- ++count;
- attr->len = cpu_to_be16(templen + sizeof(attr->type) +
- sizeof(templen));
- }
- /*
- * Update size of payload
- */
- port_attrib->attr_count = cpu_to_be32(count);
- len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
- return len;
- }
- static u16
- bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- struct fdmi_rprt_s *rprt = (struct fdmi_rprt_s *) pyld;
- u16 len;
- rprt->hba_id = bfa_fcs_lport_get_pwwn(bfa_fcs_get_base_port(port->fcs));
- rprt->port_name = bfa_fcs_lport_get_pwwn(port);
- len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
- (u8 *) &rprt->port_attr_blk);
- len += sizeof(rprt->hba_id) + sizeof(rprt->port_name);
- return len;
- }
- static void
- bfa_fcs_lport_fdmi_rprt_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len,
- struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_fdmi_s *fdmi =
- (struct bfa_fcs_lport_fdmi_s *) cbarg;
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- struct ct_hdr_s *cthdr = NULL;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
- return;
- }
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
- }
- /*
- * RPA : Register Port Attributes.
- */
- static void
- bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- struct fchs_s fchs;
- u16 len, attr_len;
- struct bfa_fcxp_s *fcxp;
- u8 *pyld;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
- bfa_fcs_lport_fdmi_send_rpa, fdmi, BFA_TRUE);
- return;
- }
- fdmi->fcxp = fcxp;
- pyld = bfa_fcxp_get_reqbuf(fcxp);
- memset(pyld, 0, FC_MAX_PDUSZ);
- len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
- FDMI_RPA);
- attr_len = bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi,
- (u8 *) ((struct ct_hdr_s *) pyld + 1));
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len + attr_len, &fchs,
- bfa_fcs_lport_fdmi_rpa_response, (void *)fdmi,
- FC_MAX_PDUSZ, FC_FCCT_TOV);
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RPA_SENT);
- }
- static u16
- bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- struct fdmi_rpa_s *rpa = (struct fdmi_rpa_s *) pyld;
- u16 len;
- rpa->port_name = bfa_fcs_lport_get_pwwn(port);
- len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
- (u8 *) &rpa->port_attr_blk);
- len += sizeof(rpa->port_name);
- return len;
- }
- static void
- bfa_fcs_lport_fdmi_rpa_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status, u32 rsp_len,
- u32 resid_len, struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_fdmi_s *fdmi =
- (struct bfa_fcs_lport_fdmi_s *) cbarg;
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- struct ct_hdr_s *cthdr = NULL;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
- return;
- }
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
- }
- static void
- bfa_fcs_lport_fdmi_timeout(void *arg)
- {
- struct bfa_fcs_lport_fdmi_s *fdmi = (struct bfa_fcs_lport_fdmi_s *) arg;
- bfa_sm_send_event(fdmi, FDMISM_EVENT_TIMEOUT);
- }
- static void
- bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
- struct bfa_fcs_fdmi_hba_attr_s *hba_attr)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
- struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
- memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s));
- bfa_ioc_get_adapter_manufacturer(&port->fcs->bfa->ioc,
- hba_attr->manufacturer);
- bfa_ioc_get_adapter_serial_num(&port->fcs->bfa->ioc,
- hba_attr->serial_num);
- bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
- hba_attr->model);
- bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
- hba_attr->model_desc);
- bfa_ioc_get_pci_chip_rev(&port->fcs->bfa->ioc,
- hba_attr->hw_version);
- bfa_ioc_get_adapter_optrom_ver(&port->fcs->bfa->ioc,
- hba_attr->option_rom_ver);
- bfa_ioc_get_adapter_fw_ver(&port->fcs->bfa->ioc,
- hba_attr->fw_version);
- strncpy(hba_attr->driver_version, (char *)driver_info->version,
- sizeof(hba_attr->driver_version));
- strncpy(hba_attr->os_name, driver_info->host_os_name,
- sizeof(hba_attr->os_name));
- /*
- * If there is a patch level, append it
- * to the os name along with a separator
- */
- if (driver_info->host_os_patch[0] != '\0') {
- strncat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
- sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
- strncat(hba_attr->os_name, driver_info->host_os_patch,
- sizeof(driver_info->host_os_patch));
- }
- /* Retrieve the max frame size from the port attr */
- bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
- hba_attr->max_ct_pyld = fcs_port_attr.max_frm_size;
- strncpy(hba_attr->node_sym_name.symname,
- port->port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
- strcpy(hba_attr->vendor_info, "BROCADE");
- hba_attr->num_ports =
- cpu_to_be32(bfa_ioc_get_nports(&port->fcs->bfa->ioc));
- hba_attr->fabric_name = port->fabric->lps->pr_nwwn;
- strncpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
- }
- static void
- bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
- struct bfa_fcs_fdmi_port_attr_s *port_attr)
- {
- struct bfa_fcs_lport_s *port = fdmi->ms->port;
- struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
- struct bfa_port_attr_s pport_attr;
- struct bfa_lport_attr_s lport_attr;
- memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s));
- /*
- * get pport attributes from hal
- */
- bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
- /*
- * get FC4 type Bitmask
- */
- fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->supp_fc4_types);
- /*
- * Supported Speeds
- */
- switch (pport_attr.speed_supported) {
- case BFA_PORT_SPEED_16GBPS:
- port_attr->supp_speed =
- cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_16G);
- break;
- case BFA_PORT_SPEED_10GBPS:
- port_attr->supp_speed =
- cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_10G);
- break;
- case BFA_PORT_SPEED_8GBPS:
- port_attr->supp_speed =
- cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_8G);
- break;
- case BFA_PORT_SPEED_4GBPS:
- port_attr->supp_speed =
- cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_4G);
- break;
- default:
- bfa_sm_fault(port->fcs, pport_attr.speed_supported);
- }
- /*
- * Current Speed
- */
- port_attr->curr_speed = cpu_to_be32(
- bfa_fcs_fdmi_convert_speed(pport_attr.speed));
- /*
- * Max PDU Size.
- */
- port_attr->max_frm_size = cpu_to_be32(pport_attr.pport_cfg.maxfrsize);
- /*
- * OS device Name
- */
- strncpy(port_attr->os_device_name, (char *)driver_info->os_device_name,
- sizeof(port_attr->os_device_name));
- /*
- * Host name
- */
- strncpy(port_attr->host_name, (char *)driver_info->host_machine_name,
- sizeof(port_attr->host_name));
- port_attr->node_name = bfa_fcs_lport_get_nwwn(port);
- port_attr->port_name = bfa_fcs_lport_get_pwwn(port);
- strncpy(port_attr->port_sym_name.symname,
- (char *)&bfa_fcs_lport_get_psym_name(port), BFA_SYMNAME_MAXLEN);
- bfa_fcs_lport_get_attr(port, &lport_attr);
- port_attr->port_type = cpu_to_be32(lport_attr.port_type);
- port_attr->scos = pport_attr.cos_supported;
- port_attr->port_fabric_name = port->fabric->lps->pr_nwwn;
- fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->port_act_fc4_type);
- port_attr->port_state = cpu_to_be32(pport_attr.port_state);
- port_attr->num_ports = cpu_to_be32(port->num_rports);
- }
- /*
- * Convert BFA speed to FDMI format.
- */
- u32
- bfa_fcs_fdmi_convert_speed(bfa_port_speed_t pport_speed)
- {
- u32 ret;
- switch (pport_speed) {
- case BFA_PORT_SPEED_1GBPS:
- case BFA_PORT_SPEED_2GBPS:
- ret = pport_speed;
- break;
- case BFA_PORT_SPEED_4GBPS:
- ret = FDMI_TRANS_SPEED_4G;
- break;
- case BFA_PORT_SPEED_8GBPS:
- ret = FDMI_TRANS_SPEED_8G;
- break;
- case BFA_PORT_SPEED_10GBPS:
- ret = FDMI_TRANS_SPEED_10G;
- break;
- case BFA_PORT_SPEED_16GBPS:
- ret = FDMI_TRANS_SPEED_16G;
- break;
- default:
- ret = FDMI_TRANS_SPEED_UNKNOWN;
- }
- return ret;
- }
- void
- bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s *ms)
- {
- struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
- fdmi->ms = ms;
- if (ms->port->fcs->fdmi_enabled)
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
- else
- bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_disabled);
- }
- void
- bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s *ms)
- {
- struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
- fdmi->ms = ms;
- bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_OFFLINE);
- }
- void
- bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s *ms)
- {
- struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
- fdmi->ms = ms;
- bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_ONLINE);
- }
- #define BFA_FCS_MS_CMD_MAX_RETRIES 2
- /*
- * forward declarations
- */
- static void bfa_fcs_lport_ms_send_plogi(void *ms_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_ms_timeout(void *arg);
- static void bfa_fcs_lport_ms_plogi_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_ms_send_gmal(void *ms_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_ms_gmal_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_ms_send_gfn(void *ms_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_ms_gfn_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- /*
- * fcs_ms_sm FCS MS state machine
- */
- /*
- * MS State Machine events
- */
- enum port_ms_event {
- MSSM_EVENT_PORT_ONLINE = 1,
- MSSM_EVENT_PORT_OFFLINE = 2,
- MSSM_EVENT_RSP_OK = 3,
- MSSM_EVENT_RSP_ERROR = 4,
- MSSM_EVENT_TIMEOUT = 5,
- MSSM_EVENT_FCXP_SENT = 6,
- MSSM_EVENT_PORT_FABRIC_RSCN = 7
- };
- static void bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event);
- /*
- * Start in offline state - awaiting NS to send start.
- */
- static void
- bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_PORT_ONLINE:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
- bfa_fcs_lport_ms_send_plogi(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- break;
- default:
- bfa_sm_fault(ms->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_FCXP_SENT:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
- &ms->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(ms->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_RSP_ERROR:
- /*
- * Start timer for a delayed retry
- */
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_retry);
- ms->port->stats.ms_retries++;
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
- &ms->timer, bfa_fcs_lport_ms_timeout, ms,
- BFA_FCS_RETRY_TIMEOUT);
- break;
- case MSSM_EVENT_RSP_OK:
- /*
- * since plogi is done, now invoke MS related sub-modules
- */
- bfa_fcs_lport_fdmi_online(ms);
- /*
- * if this is a Vport, go to online state.
- */
- if (ms->port->vport) {
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
- break;
- }
- /*
- * For a base port we need to get the
- * switch's IP address.
- */
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
- bfa_fcs_lport_ms_send_gmal(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
- bfa_fcxp_discard(ms->fcxp);
- break;
- default:
- bfa_sm_fault(ms->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_TIMEOUT:
- /*
- * Retry Timer Expired. Re-send
- */
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
- bfa_fcs_lport_ms_send_plogi(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
- bfa_timer_stop(&ms->timer);
- break;
- default:
- bfa_sm_fault(ms->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
- break;
- case MSSM_EVENT_PORT_FABRIC_RSCN:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
- ms->retry_cnt = 0;
- bfa_fcs_lport_ms_send_gfn(ms, NULL);
- break;
- default:
- bfa_sm_fault(ms->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_FCXP_SENT:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
- &ms->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(ms->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_RSP_ERROR:
- /*
- * Start timer for a delayed retry
- */
- if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_retry);
- ms->port->stats.ms_retries++;
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
- &ms->timer, bfa_fcs_lport_ms_timeout, ms,
- BFA_FCS_RETRY_TIMEOUT);
- } else {
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
- bfa_fcs_lport_ms_send_gfn(ms, NULL);
- ms->retry_cnt = 0;
- }
- break;
- case MSSM_EVENT_RSP_OK:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
- bfa_fcs_lport_ms_send_gfn(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
- bfa_fcxp_discard(ms->fcxp);
- break;
- default:
- bfa_sm_fault(ms->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_TIMEOUT:
- /*
- * Retry Timer Expired. Re-send
- */
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
- bfa_fcs_lport_ms_send_gmal(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
- bfa_timer_stop(&ms->timer);
- break;
- default:
- bfa_sm_fault(ms->port->fcs, event);
- }
- }
- /*
- * ms_pvt MS local functions
- */
- static void
- bfa_fcs_lport_ms_send_gmal(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
- bfa_fcs_lport_t *port = ms->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- bfa_trc(port->fcs, port->pid);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
- bfa_fcs_lport_ms_send_gmal, ms, BFA_TRUE);
- return;
- }
- ms->fcxp = fcxp;
- len = fc_gmal_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_fcs_lport_get_fcid(port),
- port->fabric->lps->pr_nwwn);
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs,
- bfa_fcs_lport_ms_gmal_response, (void *)ms,
- FC_MAX_PDUSZ, FC_FCCT_TOV);
- bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
- }
- static void
- bfa_fcs_lport_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len,
- struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
- bfa_fcs_lport_t *port = ms->port;
- struct ct_hdr_s *cthdr = NULL;
- struct fcgs_gmal_resp_s *gmal_resp;
- struct fcgs_gmal_entry_s *gmal_entry;
- u32 num_entries;
- u8 *rsp_str;
- bfa_trc(port->fcs, req_status);
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1);
- num_entries = be32_to_cpu(gmal_resp->ms_len);
- if (num_entries == 0) {
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- return;
- }
- /*
- * The response could contain multiple Entries.
- * Entries for SNMP interface, etc.
- * We look for the entry with a telnet prefix.
- * First "http://" entry refers to IP addr
- */
- gmal_entry = (struct fcgs_gmal_entry_s *)gmal_resp->ms_ma;
- while (num_entries > 0) {
- if (strncmp(gmal_entry->prefix,
- CT_GMAL_RESP_PREFIX_HTTP,
- sizeof(gmal_entry->prefix)) == 0) {
- /*
- * if the IP address is terminating with a '/',
- * remove it.
- * Byte 0 consists of the length of the string.
- */
- rsp_str = &(gmal_entry->prefix[0]);
- if (rsp_str[gmal_entry->len-1] == '/')
- rsp_str[gmal_entry->len-1] = 0;
- /* copy IP Address to fabric */
- strncpy(bfa_fcs_lport_get_fabric_ipaddr(port),
- gmal_entry->ip_addr,
- BFA_FCS_FABRIC_IPADDR_SZ);
- break;
- } else {
- --num_entries;
- ++gmal_entry;
- }
- }
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
- return;
- }
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- }
- static void
- bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_FCXP_SENT:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
- &ms->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(ms->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_RSP_ERROR:
- /*
- * Start timer for a delayed retry
- */
- if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_retry);
- ms->port->stats.ms_retries++;
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
- &ms->timer, bfa_fcs_lport_ms_timeout, ms,
- BFA_FCS_RETRY_TIMEOUT);
- } else {
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
- ms->retry_cnt = 0;
- }
- break;
- case MSSM_EVENT_RSP_OK:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
- bfa_fcxp_discard(ms->fcxp);
- break;
- default:
- bfa_sm_fault(ms->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_TIMEOUT:
- /*
- * Retry Timer Expired. Re-send
- */
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
- bfa_fcs_lport_ms_send_gfn(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
- bfa_timer_stop(&ms->timer);
- break;
- default:
- bfa_sm_fault(ms->port->fcs, event);
- }
- }
- /*
- * ms_pvt MS local functions
- */
- static void
- bfa_fcs_lport_ms_send_gfn(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
- bfa_fcs_lport_t *port = ms->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- bfa_trc(port->fcs, port->pid);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
- bfa_fcs_lport_ms_send_gfn, ms, BFA_TRUE);
- return;
- }
- ms->fcxp = fcxp;
- len = fc_gfn_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_fcs_lport_get_fcid(port),
- port->fabric->lps->pr_nwwn);
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs,
- bfa_fcs_lport_ms_gfn_response, (void *)ms,
- FC_MAX_PDUSZ, FC_FCCT_TOV);
- bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
- }
- static void
- bfa_fcs_lport_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status, u32 rsp_len,
- u32 resid_len, struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
- bfa_fcs_lport_t *port = ms->port;
- struct ct_hdr_s *cthdr = NULL;
- wwn_t *gfn_resp;
- bfa_trc(port->fcs, req_status);
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- gfn_resp = (wwn_t *)(cthdr + 1);
- /* check if it has actually changed */
- if ((memcmp((void *)&bfa_fcs_lport_get_fabric_name(port),
- gfn_resp, sizeof(wwn_t)) != 0)) {
- bfa_fcs_fabric_set_fabric_name(port->fabric, *gfn_resp);
- }
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
- return;
- }
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- }
- /*
- * ms_pvt MS local functions
- */
- static void
- bfa_fcs_lport_ms_send_plogi(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
- struct bfa_fcs_lport_s *port = ms->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- bfa_trc(port->fcs, port->pid);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- port->stats.ms_plogi_alloc_wait++;
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
- bfa_fcs_lport_ms_send_plogi, ms, BFA_TRUE);
- return;
- }
- ms->fcxp = fcxp;
- len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_hton3b(FC_MGMT_SERVER),
- bfa_fcs_lport_get_fcid(port), 0,
- port->port_cfg.pwwn, port->port_cfg.nwwn,
- bfa_fcport_get_maxfrsize(port->fcs->bfa),
- bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs,
- bfa_fcs_lport_ms_plogi_response, (void *)ms,
- FC_MAX_PDUSZ, FC_ELS_TOV);
- port->stats.ms_plogi_sent++;
- bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
- }
- static void
- bfa_fcs_lport_ms_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len, struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
- struct bfa_fcs_lport_s *port = ms->port;
- struct fc_els_cmd_s *els_cmd;
- struct fc_ls_rjt_s *ls_rjt;
- bfa_trc(port->fcs, req_status);
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- port->stats.ms_plogi_rsp_err++;
- bfa_trc(port->fcs, req_status);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- return;
- }
- els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
- switch (els_cmd->els_code) {
- case FC_ELS_ACC:
- if (rsp_len < sizeof(struct fc_logi_s)) {
- bfa_trc(port->fcs, rsp_len);
- port->stats.ms_plogi_acc_err++;
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- break;
- }
- port->stats.ms_plogi_accepts++;
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
- break;
- case FC_ELS_LS_RJT:
- ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
- bfa_trc(port->fcs, ls_rjt->reason_code);
- bfa_trc(port->fcs, ls_rjt->reason_code_expl);
- port->stats.ms_rejects++;
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- break;
- default:
- port->stats.ms_plogi_unknown_rsp++;
- bfa_trc(port->fcs, els_cmd->els_code);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- }
- }
- static void
- bfa_fcs_lport_ms_timeout(void *arg)
- {
- struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) arg;
- ms->port->stats.ms_timeouts++;
- bfa_sm_send_event(ms, MSSM_EVENT_TIMEOUT);
- }
- void
- bfa_fcs_lport_ms_init(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
- ms->port = port;
- bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
- /*
- * Invoke init routines of sub modules.
- */
- bfa_fcs_lport_fdmi_init(ms);
- }
- void
- bfa_fcs_lport_ms_offline(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
- ms->port = port;
- bfa_sm_send_event(ms, MSSM_EVENT_PORT_OFFLINE);
- bfa_fcs_lport_fdmi_offline(ms);
- }
- void
- bfa_fcs_lport_ms_online(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
- ms->port = port;
- bfa_sm_send_event(ms, MSSM_EVENT_PORT_ONLINE);
- }
- void
- bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
- /* todo. Handle this only when in Online state */
- if (bfa_sm_cmp_state(ms, bfa_fcs_lport_ms_sm_online))
- bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN);
- }
- /*
- * @page ns_sm_info VPORT NS State Machine
- *
- * @section ns_sm_interactions VPORT NS State Machine Interactions
- *
- * @section ns_sm VPORT NS State Machine
- * img ns_sm.jpg
- */
- /*
- * forward declarations
- */
- static void bfa_fcs_lport_ns_send_plogi(void *ns_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_ns_timeout(void *arg);
- static void bfa_fcs_lport_ns_plogi_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_ns_rspn_id_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_ns_rft_id_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_ns_rff_id_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_ns_gid_ft_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_ns_rnn_id_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_ns_process_gidft_pids(
- struct bfa_fcs_lport_s *port,
- u32 *pid_buf, u32 n_pids);
- static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port);
- /*
- * fcs_ns_sm FCS nameserver interface state machine
- */
- /*
- * VPort NS State Machine events
- */
- enum vport_ns_event {
- NSSM_EVENT_PORT_ONLINE = 1,
- NSSM_EVENT_PORT_OFFLINE = 2,
- NSSM_EVENT_PLOGI_SENT = 3,
- NSSM_EVENT_RSP_OK = 4,
- NSSM_EVENT_RSP_ERROR = 5,
- NSSM_EVENT_TIMEOUT = 6,
- NSSM_EVENT_NS_QUERY = 7,
- NSSM_EVENT_RSPNID_SENT = 8,
- NSSM_EVENT_RFTID_SENT = 9,
- NSSM_EVENT_RFFID_SENT = 10,
- NSSM_EVENT_GIDFT_SENT = 11,
- NSSM_EVENT_RNNID_SENT = 12,
- NSSM_EVENT_RSNN_NN_SENT = 13,
- };
- static void bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_sending_rspn_id(
- struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_sending_rft_id(
- struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_sending_rff_id(
- struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_sending_gid_ft(
- struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_sending_rnn_id(
- struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_sending_rsnn_nn(
- struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- static void bfa_fcs_lport_ns_sm_rsnn_nn_retry(
- struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event);
- /*
- * Start in offline state - awaiting linkup
- */
- static void
- bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_PORT_ONLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
- bfa_fcs_lport_ns_send_plogi(ns, NULL);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_PLOGI_SENT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RSP_ERROR:
- /*
- * Start timer for a delayed retry
- */
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_retry);
- ns->port->stats.ns_retries++;
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->timer, bfa_fcs_lport_ns_timeout, ns,
- BFA_FCS_RETRY_TIMEOUT);
- break;
- case NSSM_EVENT_RSP_OK:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
- ns->num_rnnid_retries = 0;
- bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_discard(ns->fcxp);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_TIMEOUT:
- /*
- * Retry Timer Expired. Re-send
- */
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
- bfa_fcs_lport_ns_send_plogi(ns, NULL);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_timer_stop(&ns->timer);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_sending_rnn_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RNNID_SENT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RSP_OK:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
- ns->num_rnnid_retries = 0;
- ns->num_rsnn_nn_retries = 0;
- bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
- break;
- case NSSM_EVENT_RSP_ERROR:
- if (ns->num_rnnid_retries < BFA_FCS_MAX_NS_RETRIES) {
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id_retry);
- ns->port->stats.ns_retries++;
- ns->num_rnnid_retries++;
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->timer, bfa_fcs_lport_ns_timeout, ns,
- BFA_FCS_RETRY_TIMEOUT);
- } else {
- bfa_sm_set_state(ns,
- bfa_fcs_lport_ns_sm_sending_rspn_id);
- bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
- }
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_fcxp_discard(ns->fcxp);
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_TIMEOUT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
- bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_timer_stop(&ns->timer);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_sending_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RSNN_NN_SENT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RSP_OK:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
- ns->num_rsnn_nn_retries = 0;
- bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
- break;
- case NSSM_EVENT_RSP_ERROR:
- if (ns->num_rsnn_nn_retries < BFA_FCS_MAX_NS_RETRIES) {
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn_retry);
- ns->port->stats.ns_retries++;
- ns->num_rsnn_nn_retries++;
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->timer, bfa_fcs_lport_ns_timeout,
- ns, BFA_FCS_RETRY_TIMEOUT);
- } else {
- bfa_sm_set_state(ns,
- bfa_fcs_lport_ns_sm_sending_rspn_id);
- bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
- }
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_discard(ns->fcxp);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_rsnn_nn_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_TIMEOUT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
- bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_timer_stop(&ns->timer);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_sending_rspn_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RSPNID_SENT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RSP_ERROR:
- /*
- * Start timer for a delayed retry
- */
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry);
- ns->port->stats.ns_retries++;
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->timer, bfa_fcs_lport_ns_timeout, ns,
- BFA_FCS_RETRY_TIMEOUT);
- break;
- case NSSM_EVENT_RSP_OK:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
- bfa_fcs_lport_ns_send_rft_id(ns, NULL);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_fcxp_discard(ns->fcxp);
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_TIMEOUT:
- /*
- * Retry Timer Expired. Re-send
- */
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
- bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_timer_stop(&ns->timer);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_sending_rft_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RFTID_SENT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RSP_OK:
- /* Now move to register FC4 Features */
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
- bfa_fcs_lport_ns_send_rff_id(ns, NULL);
- break;
- case NSSM_EVENT_RSP_ERROR:
- /*
- * Start timer for a delayed retry
- */
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id_retry);
- ns->port->stats.ns_retries++;
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->timer, bfa_fcs_lport_ns_timeout, ns,
- BFA_FCS_RETRY_TIMEOUT);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_discard(ns->fcxp);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_TIMEOUT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
- bfa_fcs_lport_ns_send_rft_id(ns, NULL);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_timer_stop(&ns->timer);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_sending_rff_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RFFID_SENT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RSP_OK:
- /*
- * If min cfg mode is enabled, we donot initiate rport
- * discovery with the fabric. Instead, we will retrieve the
- * boot targets from HAL/FW.
- */
- if (__fcs_min_cfg(ns->port->fcs)) {
- bfa_fcs_lport_ns_boot_target_disc(ns->port);
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
- return;
- }
- /*
- * If the port role is Initiator Mode issue NS query.
- * If it is Target Mode, skip this and go to online.
- */
- if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
- bfa_sm_set_state(ns,
- bfa_fcs_lport_ns_sm_sending_gid_ft);
- bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
- }
- /*
- * kick off mgmt srvr state machine
- */
- bfa_fcs_lport_ms_online(ns->port);
- break;
- case NSSM_EVENT_RSP_ERROR:
- /*
- * Start timer for a delayed retry
- */
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id_retry);
- ns->port->stats.ns_retries++;
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->timer, bfa_fcs_lport_ns_timeout, ns,
- BFA_FCS_RETRY_TIMEOUT);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_discard(ns->fcxp);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_TIMEOUT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
- bfa_fcs_lport_ns_send_rff_id(ns, NULL);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_timer_stop(&ns->timer);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_sending_gid_ft(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_GIDFT_SENT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_RSP_OK:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
- break;
- case NSSM_EVENT_RSP_ERROR:
- /*
- * TBD: for certain reject codes, we don't need to retry
- */
- /*
- * Start timer for a delayed retry
- */
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft_retry);
- ns->port->stats.ns_retries++;
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
- &ns->timer, bfa_fcs_lport_ns_timeout, ns,
- BFA_FCS_RETRY_TIMEOUT);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_fcxp_discard(ns->fcxp);
- break;
- case NSSM_EVENT_NS_QUERY:
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_TIMEOUT:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_gid_ft);
- bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
- break;
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- bfa_timer_stop(&ns->timer);
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
- enum vport_ns_event event)
- {
- bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
- bfa_trc(ns->port->fcs, event);
- switch (event) {
- case NSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- break;
- case NSSM_EVENT_NS_QUERY:
- /*
- * If the port role is Initiator Mode issue NS query.
- * If it is Target Mode, skip this and go to online.
- */
- if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
- bfa_sm_set_state(ns,
- bfa_fcs_lport_ns_sm_sending_gid_ft);
- bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
- };
- break;
- default:
- bfa_sm_fault(ns->port->fcs, event);
- }
- }
- /*
- * ns_pvt Nameserver local functions
- */
- static void
- bfa_fcs_lport_ns_send_plogi(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- bfa_trc(port->fcs, port->pid);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- port->stats.ns_plogi_alloc_wait++;
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
- bfa_fcs_lport_ns_send_plogi, ns, BFA_TRUE);
- return;
- }
- ns->fcxp = fcxp;
- len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_hton3b(FC_NAME_SERVER),
- bfa_fcs_lport_get_fcid(port), 0,
- port->port_cfg.pwwn, port->port_cfg.nwwn,
- bfa_fcport_get_maxfrsize(port->fcs->bfa),
- bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs,
- bfa_fcs_lport_ns_plogi_response, (void *)ns,
- FC_MAX_PDUSZ, FC_ELS_TOV);
- port->stats.ns_plogi_sent++;
- bfa_sm_send_event(ns, NSSM_EVENT_PLOGI_SENT);
- }
- static void
- bfa_fcs_lport_ns_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status, u32 rsp_len,
- u32 resid_len, struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- /* struct fc_logi_s *plogi_resp; */
- struct fc_els_cmd_s *els_cmd;
- struct fc_ls_rjt_s *ls_rjt;
- bfa_trc(port->fcs, req_status);
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- port->stats.ns_plogi_rsp_err++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- return;
- }
- els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
- switch (els_cmd->els_code) {
- case FC_ELS_ACC:
- if (rsp_len < sizeof(struct fc_logi_s)) {
- bfa_trc(port->fcs, rsp_len);
- port->stats.ns_plogi_acc_err++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- break;
- }
- port->stats.ns_plogi_accepts++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
- break;
- case FC_ELS_LS_RJT:
- ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
- bfa_trc(port->fcs, ls_rjt->reason_code);
- bfa_trc(port->fcs, ls_rjt->reason_code_expl);
- port->stats.ns_rejects++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- break;
- default:
- port->stats.ns_plogi_unknown_rsp++;
- bfa_trc(port->fcs, els_cmd->els_code);
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- }
- }
- /*
- * Register node name for port_id
- */
- static void
- bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- port->stats.ns_rnnid_alloc_wait++;
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
- bfa_fcs_lport_ns_send_rnn_id, ns, BFA_TRUE);
- return;
- }
- ns->fcxp = fcxp;
- len = fc_rnnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_fcs_lport_get_fcid(port),
- bfa_fcs_lport_get_fcid(port),
- bfa_fcs_lport_get_nwwn(port));
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs,
- bfa_fcs_lport_ns_rnn_id_response, (void *)ns,
- FC_MAX_PDUSZ, FC_FCCT_TOV);
- port->stats.ns_rnnid_sent++;
- bfa_sm_send_event(ns, NSSM_EVENT_RNNID_SENT);
- }
- static void
- bfa_fcs_lport_ns_rnn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len,
- struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct ct_hdr_s *cthdr = NULL;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- port->stats.ns_rnnid_rsp_err++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- port->stats.ns_rnnid_accepts++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
- return;
- }
- port->stats.ns_rnnid_rejects++;
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- }
- /*
- * Register the symbolic node name for a given node name.
- */
- static void
- bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- u8 *nsymbl;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- port->stats.ns_rsnn_nn_alloc_wait++;
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
- bfa_fcs_lport_ns_send_rsnn_nn, ns, BFA_TRUE);
- return;
- }
- ns->fcxp = fcxp;
- nsymbl = (u8 *) &(bfa_fcs_lport_get_nsym_name(
- bfa_fcs_get_base_port(port->fcs)));
- len = fc_rsnn_nn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_fcs_lport_get_fcid(port),
- bfa_fcs_lport_get_nwwn(port), nsymbl);
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs,
- bfa_fcs_lport_ns_rsnn_nn_response, (void *)ns,
- FC_MAX_PDUSZ, FC_FCCT_TOV);
- port->stats.ns_rsnn_nn_sent++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSNN_NN_SENT);
- }
- static void
- bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len,
- struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct ct_hdr_s *cthdr = NULL;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- port->stats.ns_rsnn_nn_rsp_err++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- port->stats.ns_rsnn_nn_accepts++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
- return;
- }
- port->stats.ns_rsnn_nn_rejects++;
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- }
- /*
- * Register the symbolic port name.
- */
- static void
- bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- u8 symbl[256];
- u8 *psymbl = &symbl[0];
- memset(symbl, 0, sizeof(symbl));
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- port->stats.ns_rspnid_alloc_wait++;
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
- bfa_fcs_lport_ns_send_rspn_id, ns, BFA_TRUE);
- return;
- }
- ns->fcxp = fcxp;
- /*
- * for V-Port, form a Port Symbolic Name
- */
- if (port->vport) {
- /*
- * For Vports, we append the vport's port symbolic name
- * to that of the base port.
- */
- strncpy((char *)psymbl,
- (char *) &
- (bfa_fcs_lport_get_psym_name
- (bfa_fcs_get_base_port(port->fcs))),
- strlen((char *) &
- bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
- (port->fcs))));
- /* Ensure we have a null terminating string. */
- ((char *)psymbl)[strlen((char *) &
- bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
- (port->fcs)))] = 0;
- strncat((char *)psymbl,
- (char *) &(bfa_fcs_lport_get_psym_name(port)),
- strlen((char *) &bfa_fcs_lport_get_psym_name(port)));
- } else {
- psymbl = (u8 *) &(bfa_fcs_lport_get_psym_name(port));
- }
- len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_fcs_lport_get_fcid(port), 0, psymbl);
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs,
- bfa_fcs_lport_ns_rspn_id_response, (void *)ns,
- FC_MAX_PDUSZ, FC_FCCT_TOV);
- port->stats.ns_rspnid_sent++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSPNID_SENT);
- }
- static void
- bfa_fcs_lport_ns_rspn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len,
- struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct ct_hdr_s *cthdr = NULL;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- port->stats.ns_rspnid_rsp_err++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- port->stats.ns_rspnid_accepts++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
- return;
- }
- port->stats.ns_rspnid_rejects++;
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- }
- /*
- * Register FC4-Types
- */
- static void
- bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- port->stats.ns_rftid_alloc_wait++;
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
- bfa_fcs_lport_ns_send_rft_id, ns, BFA_TRUE);
- return;
- }
- ns->fcxp = fcxp;
- len = fc_rftid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_fcs_lport_get_fcid(port), 0, port->port_cfg.roles);
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs,
- bfa_fcs_lport_ns_rft_id_response, (void *)ns,
- FC_MAX_PDUSZ, FC_FCCT_TOV);
- port->stats.ns_rftid_sent++;
- bfa_sm_send_event(ns, NSSM_EVENT_RFTID_SENT);
- }
- static void
- bfa_fcs_lport_ns_rft_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len,
- struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct ct_hdr_s *cthdr = NULL;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- port->stats.ns_rftid_rsp_err++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- port->stats.ns_rftid_accepts++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
- return;
- }
- port->stats.ns_rftid_rejects++;
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- }
- /*
- * Register FC4-Features : Should be done after RFT_ID
- */
- static void
- bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- u8 fc4_ftrs = 0;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- port->stats.ns_rffid_alloc_wait++;
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
- bfa_fcs_lport_ns_send_rff_id, ns, BFA_TRUE);
- return;
- }
- ns->fcxp = fcxp;
- if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port))
- fc4_ftrs = FC_GS_FCP_FC4_FEATURE_INITIATOR;
- len = fc_rffid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_fcs_lport_get_fcid(port), 0,
- FC_TYPE_FCP, fc4_ftrs);
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs,
- bfa_fcs_lport_ns_rff_id_response, (void *)ns,
- FC_MAX_PDUSZ, FC_FCCT_TOV);
- port->stats.ns_rffid_sent++;
- bfa_sm_send_event(ns, NSSM_EVENT_RFFID_SENT);
- }
- static void
- bfa_fcs_lport_ns_rff_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len,
- struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct ct_hdr_s *cthdr = NULL;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- port->stats.ns_rffid_rsp_err++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- port->stats.ns_rffid_accepts++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
- return;
- }
- port->stats.ns_rffid_rejects++;
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- if (cthdr->reason_code == CT_RSN_NOT_SUPP) {
- /* if this command is not supported, we don't retry */
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
- } else
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- }
- /*
- * Query Fabric for FC4-Types Devices.
- *
- * TBD : Need to use a local (FCS private) response buffer, since the response
- * can be larger than 2K.
- */
- static void
- bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- bfa_trc(port->fcs, port->pid);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- port->stats.ns_gidft_alloc_wait++;
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
- bfa_fcs_lport_ns_send_gid_ft, ns, BFA_TRUE);
- return;
- }
- ns->fcxp = fcxp;
- /*
- * This query is only initiated for FCP initiator mode.
- */
- len = fc_gid_ft_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- ns->port->pid, FC_TYPE_FCP);
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs,
- bfa_fcs_lport_ns_gid_ft_response, (void *)ns,
- bfa_fcxp_get_maxrsp(port->fcs->bfa), FC_FCCT_TOV);
- port->stats.ns_gidft_sent++;
- bfa_sm_send_event(ns, NSSM_EVENT_GIDFT_SENT);
- }
- static void
- bfa_fcs_lport_ns_gid_ft_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len,
- struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct ct_hdr_s *cthdr = NULL;
- u32 n_pids;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- port->stats.ns_gidft_rsp_err++;
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- return;
- }
- if (resid_len != 0) {
- /*
- * TBD : we will need to allocate a larger buffer & retry the
- * command
- */
- bfa_trc(port->fcs, rsp_len);
- bfa_trc(port->fcs, resid_len);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
- switch (cthdr->cmd_rsp_code) {
- case CT_RSP_ACCEPT:
- port->stats.ns_gidft_accepts++;
- n_pids = (fc_get_ctresp_pyld_len(rsp_len) / sizeof(u32));
- bfa_trc(port->fcs, n_pids);
- bfa_fcs_lport_ns_process_gidft_pids(port,
- (u32 *) (cthdr + 1),
- n_pids);
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
- break;
- case CT_RSP_REJECT:
- /*
- * Check the reason code & explanation.
- * There may not have been any FC4 devices in the fabric
- */
- port->stats.ns_gidft_rejects++;
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- if ((cthdr->reason_code == CT_RSN_UNABLE_TO_PERF)
- && (cthdr->exp_code == CT_NS_EXP_FT_NOT_REG)) {
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
- } else {
- /*
- * for all other errors, retry
- */
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- }
- break;
- default:
- port->stats.ns_gidft_unknown_rsp++;
- bfa_trc(port->fcs, cthdr->cmd_rsp_code);
- bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
- }
- }
- /*
- * This routine will be called by bfa_timer on timer timeouts.
- *
- * param[in] port - pointer to bfa_fcs_lport_t.
- *
- * return
- * void
- *
- * Special Considerations:
- *
- * note
- */
- static void
- bfa_fcs_lport_ns_timeout(void *arg)
- {
- struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) arg;
- ns->port->stats.ns_timeouts++;
- bfa_sm_send_event(ns, NSSM_EVENT_TIMEOUT);
- }
- /*
- * Process the PID list in GID_FT response
- */
- static void
- bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s *port, u32 *pid_buf,
- u32 n_pids)
- {
- struct fcgs_gidft_resp_s *gidft_entry;
- struct bfa_fcs_rport_s *rport;
- u32 ii;
- struct bfa_fcs_fabric_s *fabric = port->fabric;
- struct bfa_fcs_vport_s *vport;
- struct list_head *qe;
- u8 found = 0;
- for (ii = 0; ii < n_pids; ii++) {
- gidft_entry = (struct fcgs_gidft_resp_s *) &pid_buf[ii];
- if (gidft_entry->pid == port->pid)
- continue;
- /*
- * Ignore PID if it is of base port
- * (Avoid vports discovering base port as remote port)
- */
- if (gidft_entry->pid == fabric->bport.pid)
- continue;
- /*
- * Ignore PID if it is of vport created on the same base port
- * (Avoid vport discovering every other vport created on the
- * same port as remote port)
- */
- list_for_each(qe, &fabric->vport_q) {
- vport = (struct bfa_fcs_vport_s *) qe;
- if (vport->lport.pid == gidft_entry->pid)
- found = 1;
- }
- if (found) {
- found = 0;
- continue;
- }
- /*
- * Check if this rport already exists
- */
- rport = bfa_fcs_lport_get_rport_by_pid(port, gidft_entry->pid);
- if (rport == NULL) {
- /*
- * this is a new device. create rport
- */
- rport = bfa_fcs_rport_create(port, gidft_entry->pid);
- } else {
- /*
- * this rport already exists
- */
- bfa_fcs_rport_scn(rport);
- }
- bfa_trc(port->fcs, gidft_entry->pid);
- /*
- * if the last entry bit is set, bail out.
- */
- if (gidft_entry->last)
- return;
- }
- }
- /*
- * fcs_ns_public FCS nameserver public interfaces
- */
- /*
- * Functions called by port/fab.
- * These will send relevant Events to the ns state machine.
- */
- void
- bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
- ns->port = port;
- bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
- }
- void
- bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
- ns->port = port;
- bfa_sm_send_event(ns, NSSM_EVENT_PORT_OFFLINE);
- }
- void
- bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
- ns->port = port;
- bfa_sm_send_event(ns, NSSM_EVENT_PORT_ONLINE);
- }
- void
- bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
- bfa_trc(port->fcs, port->pid);
- if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_online))
- bfa_sm_send_event(ns, NSSM_EVENT_NS_QUERY);
- }
- static void
- bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port)
- {
- struct bfa_fcs_rport_s *rport;
- u8 nwwns;
- wwn_t wwns[BFA_PREBOOT_BOOTLUN_MAX];
- int ii;
- bfa_iocfc_get_bootwwns(port->fcs->bfa, &nwwns, wwns);
- for (ii = 0 ; ii < nwwns; ++ii) {
- rport = bfa_fcs_rport_create_by_wwn(port, wwns[ii]);
- WARN_ON(!rport);
- }
- }
- void
- bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_ns_s *ns = cbarg;
- struct bfa_fcs_lport_s *port = ns->port;
- struct fchs_s fchs;
- struct bfa_fcxp_s *fcxp;
- u8 symbl[256];
- u8 *psymbl = &symbl[0];
- int len;
- /* Avoid sending RSPN in the following states. */
- if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_offline) ||
- bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_sending) ||
- bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi) ||
- bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_retry) ||
- bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry))
- return;
- memset(symbl, 0, sizeof(symbl));
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
- if (!fcxp) {
- port->stats.ns_rspnid_alloc_wait++;
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
- bfa_fcs_lport_ns_util_send_rspn_id, ns, BFA_FALSE);
- return;
- }
- ns->fcxp = fcxp;
- if (port->vport) {
- /*
- * For Vports, we append the vport's port symbolic name
- * to that of the base port.
- */
- strncpy((char *)psymbl, (char *)&(bfa_fcs_lport_get_psym_name
- (bfa_fcs_get_base_port(port->fcs))),
- strlen((char *)&bfa_fcs_lport_get_psym_name(
- bfa_fcs_get_base_port(port->fcs))));
- /* Ensure we have a null terminating string. */
- ((char *)psymbl)[strlen((char *)&bfa_fcs_lport_get_psym_name(
- bfa_fcs_get_base_port(port->fcs)))] = 0;
- strncat((char *)psymbl,
- (char *)&(bfa_fcs_lport_get_psym_name(port)),
- strlen((char *)&bfa_fcs_lport_get_psym_name(port)));
- }
- len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_fcs_lport_get_fcid(port), 0, psymbl);
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
- port->stats.ns_rspnid_sent++;
- }
- /*
- * FCS SCN
- */
- #define FC_QOS_RSCN_EVENT 0x0c
- #define FC_FABRIC_NAME_RSCN_EVENT 0x0d
- /*
- * forward declarations
- */
- static void bfa_fcs_lport_scn_send_scr(void *scn_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_lport_scn_scr_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
- struct fchs_s *rx_fchs);
- static void bfa_fcs_lport_scn_timeout(void *arg);
- /*
- * fcs_scm_sm FCS SCN state machine
- */
- /*
- * VPort SCN State Machine events
- */
- enum port_scn_event {
- SCNSM_EVENT_PORT_ONLINE = 1,
- SCNSM_EVENT_PORT_OFFLINE = 2,
- SCNSM_EVENT_RSP_OK = 3,
- SCNSM_EVENT_RSP_ERROR = 4,
- SCNSM_EVENT_TIMEOUT = 5,
- SCNSM_EVENT_SCR_SENT = 6,
- };
- static void bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
- enum port_scn_event event);
- static void bfa_fcs_lport_scn_sm_sending_scr(
- struct bfa_fcs_lport_scn_s *scn,
- enum port_scn_event event);
- static void bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
- enum port_scn_event event);
- static void bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
- enum port_scn_event event);
- static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
- enum port_scn_event event);
- /*
- * Starting state - awaiting link up.
- */
- static void
- bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
- enum port_scn_event event)
- {
- switch (event) {
- case SCNSM_EVENT_PORT_ONLINE:
- bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
- bfa_fcs_lport_scn_send_scr(scn, NULL);
- break;
- case SCNSM_EVENT_PORT_OFFLINE:
- break;
- default:
- bfa_sm_fault(scn->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_scn_sm_sending_scr(struct bfa_fcs_lport_scn_s *scn,
- enum port_scn_event event)
- {
- switch (event) {
- case SCNSM_EVENT_SCR_SENT:
- bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr);
- break;
- case SCNSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
- bfa_fcxp_walloc_cancel(scn->port->fcs->bfa, &scn->fcxp_wqe);
- break;
- default:
- bfa_sm_fault(scn->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
- enum port_scn_event event)
- {
- struct bfa_fcs_lport_s *port = scn->port;
- switch (event) {
- case SCNSM_EVENT_RSP_OK:
- bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_online);
- break;
- case SCNSM_EVENT_RSP_ERROR:
- bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr_retry);
- bfa_timer_start(port->fcs->bfa, &scn->timer,
- bfa_fcs_lport_scn_timeout, scn,
- BFA_FCS_RETRY_TIMEOUT);
- break;
- case SCNSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
- bfa_fcxp_discard(scn->fcxp);
- break;
- default:
- bfa_sm_fault(port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
- enum port_scn_event event)
- {
- switch (event) {
- case SCNSM_EVENT_TIMEOUT:
- bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
- bfa_fcs_lport_scn_send_scr(scn, NULL);
- break;
- case SCNSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
- bfa_timer_stop(&scn->timer);
- break;
- default:
- bfa_sm_fault(scn->port->fcs, event);
- }
- }
- static void
- bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
- enum port_scn_event event)
- {
- switch (event) {
- case SCNSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
- break;
- default:
- bfa_sm_fault(scn->port->fcs, event);
- }
- }
- /*
- * fcs_scn_private FCS SCN private functions
- */
- /*
- * This routine will be called to send a SCR command.
- */
- static void
- bfa_fcs_lport_scn_send_scr(void *scn_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_lport_scn_s *scn = scn_cbarg;
- struct bfa_fcs_lport_s *port = scn->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- bfa_trc(port->fcs, port->pid);
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- fcxp = fcxp_alloced ? fcxp_alloced :
- bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
- if (!fcxp) {
- bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &scn->fcxp_wqe,
- bfa_fcs_lport_scn_send_scr, scn, BFA_TRUE);
- return;
- }
- scn->fcxp = fcxp;
- /* Handle VU registrations for Base port only */
- if ((!port->vport) && bfa_ioc_get_fcmode(&port->fcs->bfa->ioc)) {
- len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- port->fabric->lps->brcd_switch,
- port->pid, 0);
- } else {
- len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- BFA_FALSE,
- port->pid, 0);
- }
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs,
- bfa_fcs_lport_scn_scr_response,
- (void *)scn, FC_MAX_PDUSZ, FC_ELS_TOV);
- bfa_sm_send_event(scn, SCNSM_EVENT_SCR_SENT);
- }
- static void
- bfa_fcs_lport_scn_scr_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status, u32 rsp_len,
- u32 resid_len, struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) cbarg;
- struct bfa_fcs_lport_s *port = scn->port;
- struct fc_els_cmd_s *els_cmd;
- struct fc_ls_rjt_s *ls_rjt;
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
- return;
- }
- els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
- switch (els_cmd->els_code) {
- case FC_ELS_ACC:
- bfa_sm_send_event(scn, SCNSM_EVENT_RSP_OK);
- break;
- case FC_ELS_LS_RJT:
- ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
- bfa_trc(port->fcs, ls_rjt->reason_code);
- bfa_trc(port->fcs, ls_rjt->reason_code_expl);
- bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
- break;
- default:
- bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
- }
- }
- /*
- * Send a LS Accept
- */
- static void
- bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
- struct fchs_s *rx_fchs)
- {
- struct fchs_s fchs;
- struct bfa_fcxp_s *fcxp;
- struct bfa_rport_s *bfa_rport = NULL;
- int len;
- bfa_trc(port->fcs, rx_fchs->s_id);
- fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
- if (!fcxp)
- return;
- len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
- rx_fchs->ox_id);
- bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
- BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
- FC_MAX_PDUSZ, 0);
- }
- /*
- * This routine will be called by bfa_timer on timer timeouts.
- *
- * param[in] vport - pointer to bfa_fcs_lport_t.
- * param[out] vport_status - pointer to return vport status in
- *
- * return
- * void
- *
- * Special Considerations:
- *
- * note
- */
- static void
- bfa_fcs_lport_scn_timeout(void *arg)
- {
- struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) arg;
- bfa_sm_send_event(scn, SCNSM_EVENT_TIMEOUT);
- }
- /*
- * fcs_scn_public FCS state change notification public interfaces
- */
- /*
- * Functions called by port/fab
- */
- void
- bfa_fcs_lport_scn_init(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
- scn->port = port;
- bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
- }
- void
- bfa_fcs_lport_scn_offline(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
- scn->port = port;
- bfa_sm_send_event(scn, SCNSM_EVENT_PORT_OFFLINE);
- }
- void
- bfa_fcs_lport_fab_scn_online(struct bfa_fcs_lport_s *port)
- {
- struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
- scn->port = port;
- bfa_sm_send_event(scn, SCNSM_EVENT_PORT_ONLINE);
- }
- static void
- bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s *port, u32 rpid)
- {
- struct bfa_fcs_rport_s *rport;
- struct bfa_fcs_fabric_s *fabric = port->fabric;
- struct bfa_fcs_vport_s *vport;
- struct list_head *qe;
- bfa_trc(port->fcs, rpid);
- /*
- * Ignore PID if it is of base port or of vports created on the
- * same base port. It is to avoid vports discovering base port or
- * other vports created on same base port as remote port
- */
- if (rpid == fabric->bport.pid)
- return;
- list_for_each(qe, &fabric->vport_q) {
- vport = (struct bfa_fcs_vport_s *) qe;
- if (vport->lport.pid == rpid)
- return;
- }
- /*
- * If this is an unknown device, then it just came online.
- * Otherwise let rport handle the RSCN event.
- */
- rport = bfa_fcs_lport_get_rport_by_pid(port, rpid);
- if (!rport)
- rport = bfa_fcs_lport_get_rport_by_old_pid(port, rpid);
- if (rport == NULL) {
- /*
- * If min cfg mode is enabled, we donot need to
- * discover any new rports.
- */
- if (!__fcs_min_cfg(port->fcs))
- rport = bfa_fcs_rport_create(port, rpid);
- } else
- bfa_fcs_rport_scn(rport);
- }
- /*
- * rscn format based PID comparison
- */
- #define __fc_pid_match(__c0, __c1, __fmt) \
- (((__fmt) == FC_RSCN_FORMAT_FABRIC) || \
- (((__fmt) == FC_RSCN_FORMAT_DOMAIN) && \
- ((__c0)[0] == (__c1)[0])) || \
- (((__fmt) == FC_RSCN_FORMAT_AREA) && \
- ((__c0)[0] == (__c1)[0]) && \
- ((__c0)[1] == (__c1)[1])))
- static void
- bfa_fcs_lport_scn_multiport_rscn(struct bfa_fcs_lport_s *port,
- enum fc_rscn_format format,
- u32 rscn_pid)
- {
- struct bfa_fcs_rport_s *rport;
- struct list_head *qe, *qe_next;
- u8 *c0, *c1;
- bfa_trc(port->fcs, format);
- bfa_trc(port->fcs, rscn_pid);
- c0 = (u8 *) &rscn_pid;
- list_for_each_safe(qe, qe_next, &port->rport_q) {
- rport = (struct bfa_fcs_rport_s *) qe;
- c1 = (u8 *) &rport->pid;
- if (__fc_pid_match(c0, c1, format))
- bfa_fcs_rport_scn(rport);
- }
- }
- void
- bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s *port,
- struct fchs_s *fchs, u32 len)
- {
- struct fc_rscn_pl_s *rscn = (struct fc_rscn_pl_s *) (fchs + 1);
- int num_entries;
- u32 rscn_pid;
- bfa_boolean_t nsquery = BFA_FALSE, found;
- int i = 0, j;
- num_entries =
- (be16_to_cpu(rscn->payldlen) -
- sizeof(u32)) / sizeof(rscn->event[0]);
- bfa_trc(port->fcs, num_entries);
- port->stats.num_rscn++;
- bfa_fcs_lport_scn_send_ls_acc(port, fchs);
- for (i = 0; i < num_entries; i++) {
- rscn_pid = rscn->event[i].portid;
- bfa_trc(port->fcs, rscn->event[i].format);
- bfa_trc(port->fcs, rscn_pid);
- /* check for duplicate entries in the list */
- found = BFA_FALSE;
- for (j = 0; j < i; j++) {
- if (rscn->event[j].portid == rscn_pid) {
- found = BFA_TRUE;
- break;
- }
- }
- /* if found in down the list, pid has been already processed */
- if (found) {
- bfa_trc(port->fcs, rscn_pid);
- continue;
- }
- switch (rscn->event[i].format) {
- case FC_RSCN_FORMAT_PORTID:
- if (rscn->event[i].qualifier == FC_QOS_RSCN_EVENT) {
- /*
- * Ignore this event.
- * f/w would have processed it
- */
- bfa_trc(port->fcs, rscn_pid);
- } else {
- port->stats.num_portid_rscn++;
- bfa_fcs_lport_scn_portid_rscn(port, rscn_pid);
- }
- break;
- case FC_RSCN_FORMAT_FABRIC:
- if (rscn->event[i].qualifier ==
- FC_FABRIC_NAME_RSCN_EVENT) {
- bfa_fcs_lport_ms_fabric_rscn(port);
- break;
- }
- /* !!!!!!!!! Fall Through !!!!!!!!!!!!! */
- case FC_RSCN_FORMAT_AREA:
- case FC_RSCN_FORMAT_DOMAIN:
- nsquery = BFA_TRUE;
- bfa_fcs_lport_scn_multiport_rscn(port,
- rscn->event[i].format,
- rscn_pid);
- break;
- default:
- WARN_ON(1);
- nsquery = BFA_TRUE;
- }
- }
- /*
- * If any of area, domain or fabric RSCN is received, do a fresh
- * discovery to find new devices.
- */
- if (nsquery)
- bfa_fcs_lport_ns_query(port);
- }
- /*
- * BFA FCS port
- */
- /*
- * fcs_port_api BFA FCS port API
- */
- struct bfa_fcs_lport_s *
- bfa_fcs_get_base_port(struct bfa_fcs_s *fcs)
- {
- return &fcs->fabric.bport;
- }
- wwn_t
- bfa_fcs_lport_get_rport(struct bfa_fcs_lport_s *port, wwn_t wwn, int index,
- int nrports, bfa_boolean_t bwwn)
- {
- struct list_head *qh, *qe;
- struct bfa_fcs_rport_s *rport = NULL;
- int i;
- struct bfa_fcs_s *fcs;
- if (port == NULL || nrports == 0)
- return (wwn_t) 0;
- fcs = port->fcs;
- bfa_trc(fcs, (u32) nrports);
- i = 0;
- qh = &port->rport_q;
- qe = bfa_q_first(qh);
- while ((qe != qh) && (i < nrports)) {
- rport = (struct bfa_fcs_rport_s *) qe;
- if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
- qe = bfa_q_next(qe);
- bfa_trc(fcs, (u32) rport->pwwn);
- bfa_trc(fcs, rport->pid);
- bfa_trc(fcs, i);
- continue;
- }
- if (bwwn) {
- if (!memcmp(&wwn, &rport->pwwn, 8))
- break;
- } else {
- if (i == index)
- break;
- }
- i++;
- qe = bfa_q_next(qe);
- }
- bfa_trc(fcs, i);
- if (rport)
- return rport->pwwn;
- else
- return (wwn_t) 0;
- }
- void
- bfa_fcs_lport_get_rport_quals(struct bfa_fcs_lport_s *port,
- struct bfa_rport_qualifier_s rports[], int *nrports)
- {
- struct list_head *qh, *qe;
- struct bfa_fcs_rport_s *rport = NULL;
- int i;
- struct bfa_fcs_s *fcs;
- if (port == NULL || rports == NULL || *nrports == 0)
- return;
- fcs = port->fcs;
- bfa_trc(fcs, (u32) *nrports);
- i = 0;
- qh = &port->rport_q;
- qe = bfa_q_first(qh);
- while ((qe != qh) && (i < *nrports)) {
- rport = (struct bfa_fcs_rport_s *) qe;
- if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
- qe = bfa_q_next(qe);
- bfa_trc(fcs, (u32) rport->pwwn);
- bfa_trc(fcs, rport->pid);
- bfa_trc(fcs, i);
- continue;
- }
- if (!rport->pwwn && !rport->pid) {
- qe = bfa_q_next(qe);
- continue;
- }
- rports[i].pwwn = rport->pwwn;
- rports[i].pid = rport->pid;
- i++;
- qe = bfa_q_next(qe);
- }
- bfa_trc(fcs, i);
- *nrports = i;
- }
- /*
- * Iterate's through all the rport's in the given port to
- * determine the maximum operating speed.
- *
- * !!!! To be used in TRL Functionality only !!!!
- */
- bfa_port_speed_t
- bfa_fcs_lport_get_rport_max_speed(bfa_fcs_lport_t *port)
- {
- struct list_head *qh, *qe;
- struct bfa_fcs_rport_s *rport = NULL;
- struct bfa_fcs_s *fcs;
- bfa_port_speed_t max_speed = 0;
- struct bfa_port_attr_s port_attr;
- bfa_port_speed_t port_speed, rport_speed;
- bfa_boolean_t trl_enabled = bfa_fcport_is_ratelim(port->fcs->bfa);
- if (port == NULL)
- return 0;
- fcs = port->fcs;
- /* Get Physical port's current speed */
- bfa_fcport_get_attr(port->fcs->bfa, &port_attr);
- port_speed = port_attr.speed;
- bfa_trc(fcs, port_speed);
- qh = &port->rport_q;
- qe = bfa_q_first(qh);
- while (qe != qh) {
- rport = (struct bfa_fcs_rport_s *) qe;
- if ((bfa_ntoh3b(rport->pid) > 0xFFF000) ||
- (bfa_fcs_rport_get_state(rport) == BFA_RPORT_OFFLINE) ||
- (rport->scsi_function != BFA_RPORT_TARGET)) {
- qe = bfa_q_next(qe);
- continue;
- }
- rport_speed = rport->rpf.rpsc_speed;
- if ((trl_enabled) && (rport_speed ==
- BFA_PORT_SPEED_UNKNOWN)) {
- /* Use default ratelim speed setting */
- rport_speed =
- bfa_fcport_get_ratelim_speed(port->fcs->bfa);
- }
- if (rport_speed > max_speed)
- max_speed = rport_speed;
- qe = bfa_q_next(qe);
- }
- if (max_speed > port_speed)
- max_speed = port_speed;
- bfa_trc(fcs, max_speed);
- return max_speed;
- }
- struct bfa_fcs_lport_s *
- bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
- {
- struct bfa_fcs_vport_s *vport;
- bfa_fcs_vf_t *vf;
- WARN_ON(fcs == NULL);
- vf = bfa_fcs_vf_lookup(fcs, vf_id);
- if (vf == NULL) {
- bfa_trc(fcs, vf_id);
- return NULL;
- }
- if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
- return &vf->bport;
- vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
- if (vport)
- return &vport->lport;
- return NULL;
- }
- /*
- * API corresponding to NPIV_VPORT_GETINFO.
- */
- void
- bfa_fcs_lport_get_info(struct bfa_fcs_lport_s *port,
- struct bfa_lport_info_s *port_info)
- {
- bfa_trc(port->fcs, port->fabric->fabric_name);
- if (port->vport == NULL) {
- /*
- * This is a Physical port
- */
- port_info->port_type = BFA_LPORT_TYPE_PHYSICAL;
- /*
- * @todo : need to fix the state & reason
- */
- port_info->port_state = 0;
- port_info->offline_reason = 0;
- port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
- port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
- port_info->max_vports_supp =
- bfa_lps_get_max_vport(port->fcs->bfa);
- port_info->num_vports_inuse =
- port->fabric->num_vports;
- port_info->max_rports_supp = BFA_FCS_MAX_RPORTS_SUPP;
- port_info->num_rports_inuse = port->num_rports;
- } else {
- /*
- * This is a virtual port
- */
- port_info->port_type = BFA_LPORT_TYPE_VIRTUAL;
- /*
- * @todo : need to fix the state & reason
- */
- port_info->port_state = 0;
- port_info->offline_reason = 0;
- port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
- port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
- }
- }
- void
- bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s *fcs_port,
- struct bfa_lport_stats_s *port_stats)
- {
- *port_stats = fcs_port->stats;
- }
- void
- bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s *fcs_port)
- {
- memset(&fcs_port->stats, 0, sizeof(struct bfa_lport_stats_s));
- }
- /*
- * Let new loop map create missing rports
- */
- void
- bfa_fcs_lport_lip_scn_online(struct bfa_fcs_lport_s *port)
- {
- bfa_fcs_lport_loop_online(port);
- }
- /*
- * FCS virtual port state machine
- */
- #define __vport_fcs(__vp) ((__vp)->lport.fcs)
- #define __vport_pwwn(__vp) ((__vp)->lport.port_cfg.pwwn)
- #define __vport_nwwn(__vp) ((__vp)->lport.port_cfg.nwwn)
- #define __vport_bfa(__vp) ((__vp)->lport.fcs->bfa)
- #define __vport_fcid(__vp) ((__vp)->lport.pid)
- #define __vport_fabric(__vp) ((__vp)->lport.fabric)
- #define __vport_vfid(__vp) ((__vp)->lport.fabric->vf_id)
- #define BFA_FCS_VPORT_MAX_RETRIES 5
- /*
- * Forward declarations
- */
- static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport);
- static void bfa_fcs_vport_timeout(void *vport_arg);
- static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport);
- static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport);
- /*
- * fcs_vport_sm FCS virtual port state machine
- */
- /*
- * VPort State Machine events
- */
- enum bfa_fcs_vport_event {
- BFA_FCS_VPORT_SM_CREATE = 1, /* vport create event */
- BFA_FCS_VPORT_SM_DELETE = 2, /* vport delete event */
- BFA_FCS_VPORT_SM_START = 3, /* vport start request */
- BFA_FCS_VPORT_SM_STOP = 4, /* stop: unsupported */
- BFA_FCS_VPORT_SM_ONLINE = 5, /* fabric online */
- BFA_FCS_VPORT_SM_OFFLINE = 6, /* fabric offline event */
- BFA_FCS_VPORT_SM_FRMSENT = 7, /* fdisc/logo sent events */
- BFA_FCS_VPORT_SM_RSP_OK = 8, /* good response */
- BFA_FCS_VPORT_SM_RSP_ERROR = 9, /* error/bad response */
- BFA_FCS_VPORT_SM_TIMEOUT = 10, /* delay timer event */
- BFA_FCS_VPORT_SM_DELCOMP = 11, /* lport delete completion */
- BFA_FCS_VPORT_SM_RSP_DUP_WWN = 12, /* Dup wnn error*/
- BFA_FCS_VPORT_SM_RSP_FAILED = 13, /* non-retryable failure */
- BFA_FCS_VPORT_SM_STOPCOMP = 14, /* vport delete completion */
- BFA_FCS_VPORT_SM_FABRIC_MAX = 15, /* max vports on fabric */
- };
- static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static void bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event);
- static struct bfa_sm_table_s vport_sm_table[] = {
- {BFA_SM(bfa_fcs_vport_sm_uninit), BFA_FCS_VPORT_UNINIT},
- {BFA_SM(bfa_fcs_vport_sm_created), BFA_FCS_VPORT_CREATED},
- {BFA_SM(bfa_fcs_vport_sm_offline), BFA_FCS_VPORT_OFFLINE},
- {BFA_SM(bfa_fcs_vport_sm_fdisc), BFA_FCS_VPORT_FDISC},
- {BFA_SM(bfa_fcs_vport_sm_fdisc_retry), BFA_FCS_VPORT_FDISC_RETRY},
- {BFA_SM(bfa_fcs_vport_sm_fdisc_rsp_wait), BFA_FCS_VPORT_FDISC_RSP_WAIT},
- {BFA_SM(bfa_fcs_vport_sm_online), BFA_FCS_VPORT_ONLINE},
- {BFA_SM(bfa_fcs_vport_sm_deleting), BFA_FCS_VPORT_DELETING},
- {BFA_SM(bfa_fcs_vport_sm_cleanup), BFA_FCS_VPORT_CLEANUP},
- {BFA_SM(bfa_fcs_vport_sm_logo), BFA_FCS_VPORT_LOGO},
- {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR}
- };
- /*
- * Beginning state.
- */
- static void
- bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_CREATE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
- bfa_fcs_fabric_addvport(__vport_fabric(vport), vport);
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * Created state - a start event is required to start up the state machine.
- */
- static void
- bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_START:
- if (bfa_sm_cmp_state(__vport_fabric(vport),
- bfa_fcs_fabric_sm_online)
- && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport))) {
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
- bfa_fcs_vport_do_fdisc(vport);
- } else {
- /*
- * Fabric is offline or not NPIV capable, stay in
- * offline state.
- */
- vport->vport_stats.fab_no_npiv++;
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
- }
- break;
- case BFA_FCS_VPORT_SM_DELETE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
- bfa_fcs_lport_delete(&vport->lport);
- break;
- case BFA_FCS_VPORT_SM_ONLINE:
- case BFA_FCS_VPORT_SM_OFFLINE:
- /*
- * Ignore ONLINE/OFFLINE events from fabric
- * till vport is started.
- */
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * Offline state - awaiting ONLINE event from fabric SM.
- */
- static void
- bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_DELETE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
- bfa_fcs_lport_delete(&vport->lport);
- break;
- case BFA_FCS_VPORT_SM_ONLINE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
- vport->fdisc_retries = 0;
- bfa_fcs_vport_do_fdisc(vport);
- break;
- case BFA_FCS_VPORT_SM_STOP:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
- bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
- break;
- case BFA_FCS_VPORT_SM_OFFLINE:
- /*
- * This can happen if the vport couldn't be initialzied
- * due the fact that the npiv was not enabled on the switch.
- * In that case we will put the vport in offline state.
- * However, the link can go down and cause the this event to
- * be sent when we are already offline. Ignore it.
- */
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * FDISC is sent and awaiting reply from fabric.
- */
- static void
- bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_DELETE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_rsp_wait);
- break;
- case BFA_FCS_VPORT_SM_OFFLINE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
- bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
- break;
- case BFA_FCS_VPORT_SM_RSP_OK:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_online);
- bfa_fcs_lport_online(&vport->lport);
- break;
- case BFA_FCS_VPORT_SM_RSP_ERROR:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_retry);
- bfa_timer_start(__vport_bfa(vport), &vport->timer,
- bfa_fcs_vport_timeout, vport,
- BFA_FCS_RETRY_TIMEOUT);
- break;
- case BFA_FCS_VPORT_SM_RSP_FAILED:
- case BFA_FCS_VPORT_SM_FABRIC_MAX:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
- break;
- case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_error);
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * FDISC attempt failed - a timer is active to retry FDISC.
- */
- static void
- bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_DELETE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
- bfa_timer_stop(&vport->timer);
- bfa_fcs_lport_delete(&vport->lport);
- break;
- case BFA_FCS_VPORT_SM_OFFLINE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
- bfa_timer_stop(&vport->timer);
- break;
- case BFA_FCS_VPORT_SM_TIMEOUT:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
- vport->vport_stats.fdisc_retries++;
- vport->fdisc_retries++;
- bfa_fcs_vport_do_fdisc(vport);
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * FDISC is in progress and we got a vport delete request -
- * this is a wait state while we wait for fdisc response and
- * we will transition to the appropriate state - on rsp status.
- */
- static void
- bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_RSP_OK:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
- bfa_fcs_lport_delete(&vport->lport);
- break;
- case BFA_FCS_VPORT_SM_DELETE:
- break;
- case BFA_FCS_VPORT_SM_OFFLINE:
- case BFA_FCS_VPORT_SM_RSP_ERROR:
- case BFA_FCS_VPORT_SM_RSP_FAILED:
- case BFA_FCS_VPORT_SM_FABRIC_MAX:
- case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
- bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
- bfa_fcs_lport_delete(&vport->lport);
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * Vport is online (FDISC is complete).
- */
- static void
- bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_DELETE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
- bfa_fcs_lport_delete(&vport->lport);
- break;
- case BFA_FCS_VPORT_SM_STOP:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_stopping);
- bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
- break;
- case BFA_FCS_VPORT_SM_OFFLINE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
- bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
- bfa_fcs_lport_offline(&vport->lport);
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * Vport is being stopped - awaiting lport stop completion to send
- * LOGO to fabric.
- */
- static void
- bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_STOPCOMP:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo_for_stop);
- bfa_fcs_vport_do_logo(vport);
- break;
- case BFA_FCS_VPORT_SM_OFFLINE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * Vport is being deleted - awaiting lport delete completion to send
- * LOGO to fabric.
- */
- static void
- bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_DELETE:
- break;
- case BFA_FCS_VPORT_SM_DELCOMP:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo);
- bfa_fcs_vport_do_logo(vport);
- break;
- case BFA_FCS_VPORT_SM_OFFLINE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * Error State.
- * This state will be set when the Vport Creation fails due
- * to errors like Dup WWN. In this state only operation allowed
- * is a Vport Delete.
- */
- static void
- bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_DELETE:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
- bfa_fcs_lport_delete(&vport->lport);
- break;
- default:
- bfa_trc(__vport_fcs(vport), event);
- }
- }
- /*
- * Lport cleanup is in progress since vport is being deleted. Fabric is
- * offline, so no LOGO is needed to complete vport deletion.
- */
- static void
- bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_DELCOMP:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
- bfa_fcs_vport_free(vport);
- break;
- case BFA_FCS_VPORT_SM_STOPCOMP:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
- break;
- case BFA_FCS_VPORT_SM_DELETE:
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * LOGO is sent to fabric. Vport stop is in progress. Lport stop cleanup
- * is done.
- */
- static void
- bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_OFFLINE:
- bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
- /*
- * !!! fall through !!!
- */
- case BFA_FCS_VPORT_SM_RSP_OK:
- case BFA_FCS_VPORT_SM_RSP_ERROR:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
- * is done.
- */
- static void
- bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
- enum bfa_fcs_vport_event event)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), event);
- switch (event) {
- case BFA_FCS_VPORT_SM_OFFLINE:
- bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
- /*
- * !!! fall through !!!
- */
- case BFA_FCS_VPORT_SM_RSP_OK:
- case BFA_FCS_VPORT_SM_RSP_ERROR:
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
- bfa_fcs_vport_free(vport);
- break;
- case BFA_FCS_VPORT_SM_DELETE:
- break;
- default:
- bfa_sm_fault(__vport_fcs(vport), event);
- }
- }
- /*
- * fcs_vport_private FCS virtual port private functions
- */
- /*
- * Send AEN notification
- */
- static void
- bfa_fcs_vport_aen_post(struct bfa_fcs_lport_s *port,
- enum bfa_lport_aen_event event)
- {
- struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
- struct bfa_aen_entry_s *aen_entry;
- bfad_get_aen_entry(bfad, aen_entry);
- if (!aen_entry)
- return;
- aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
- aen_entry->aen_data.lport.roles = port->port_cfg.roles;
- aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
- bfa_fcs_get_base_port(port->fcs));
- aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
- /* Send the AEN notification */
- bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
- BFA_AEN_CAT_LPORT, event);
- }
- /*
- * This routine will be called to send a FDISC command.
- */
- static void
- bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport)
- {
- bfa_lps_fdisc(vport->lps, vport,
- bfa_fcport_get_maxfrsize(__vport_bfa(vport)),
- __vport_pwwn(vport), __vport_nwwn(vport));
- vport->vport_stats.fdisc_sent++;
- }
- static void
- bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
- {
- u8 lsrjt_rsn = vport->lps->lsrjt_rsn;
- u8 lsrjt_expl = vport->lps->lsrjt_expl;
- bfa_trc(__vport_fcs(vport), lsrjt_rsn);
- bfa_trc(__vport_fcs(vport), lsrjt_expl);
- /* For certain reason codes, we don't want to retry. */
- switch (vport->lps->lsrjt_expl) {
- case FC_LS_RJT_EXP_INV_PORT_NAME: /* by brocade */
- case FC_LS_RJT_EXP_INVALID_NPORT_ID: /* by Cisco */
- if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
- else {
- bfa_fcs_vport_aen_post(&vport->lport,
- BFA_LPORT_AEN_NPIV_DUP_WWN);
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_DUP_WWN);
- }
- break;
- case FC_LS_RJT_EXP_INSUFF_RES:
- /*
- * This means max logins per port/switch setting on the
- * switch was exceeded.
- */
- if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
- else {
- bfa_fcs_vport_aen_post(&vport->lport,
- BFA_LPORT_AEN_NPIV_FABRIC_MAX);
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_FABRIC_MAX);
- }
- break;
- default:
- if (vport->fdisc_retries == 0)
- bfa_fcs_vport_aen_post(&vport->lport,
- BFA_LPORT_AEN_NPIV_UNKNOWN);
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
- }
- }
- /*
- * Called to send a logout to the fabric. Used when a V-Port is
- * deleted/stopped.
- */
- static void
- bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
- {
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- vport->vport_stats.logo_sent++;
- bfa_lps_fdisclogo(vport->lps);
- }
- /*
- * This routine will be called by bfa_timer on timer timeouts.
- *
- * param[in] vport - pointer to bfa_fcs_vport_t.
- * param[out] vport_status - pointer to return vport status in
- *
- * return
- * void
- *
- * Special Considerations:
- *
- * note
- */
- static void
- bfa_fcs_vport_timeout(void *vport_arg)
- {
- struct bfa_fcs_vport_s *vport = (struct bfa_fcs_vport_s *) vport_arg;
- vport->vport_stats.fdisc_timeouts++;
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_TIMEOUT);
- }
- static void
- bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
- {
- struct bfad_vport_s *vport_drv =
- (struct bfad_vport_s *)vport->vport_drv;
- bfa_fcs_fabric_delvport(__vport_fabric(vport), vport);
- bfa_lps_delete(vport->lps);
- if (vport_drv->comp_del) {
- complete(vport_drv->comp_del);
- return;
- }
- /*
- * We queue the vport delete work to the IM work_q from here.
- * The memory for the bfad_vport_s is freed from the FC function
- * template vport_delete entry point.
- */
- bfad_im_port_delete(vport_drv->drv_port.bfad, &vport_drv->drv_port);
- }
- /*
- * fcs_vport_public FCS virtual port public interfaces
- */
- /*
- * Online notification from fabric SM.
- */
- void
- bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
- {
- vport->vport_stats.fab_online++;
- if (bfa_fcs_fabric_npiv_capable(__vport_fabric(vport)))
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
- else
- vport->vport_stats.fab_no_npiv++;
- }
- /*
- * Offline notification from fabric SM.
- */
- void
- bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
- {
- vport->vport_stats.fab_offline++;
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
- }
- /*
- * Cleanup notification from fabric SM on link timer expiry.
- */
- void
- bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport)
- {
- vport->vport_stats.fab_cleanup++;
- }
- /*
- * Stop notification from fabric SM. To be invoked from within FCS.
- */
- void
- bfa_fcs_vport_fcs_stop(struct bfa_fcs_vport_s *vport)
- {
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
- }
- /*
- * delete notification from fabric SM. To be invoked from within FCS.
- */
- void
- bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s *vport)
- {
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
- }
- /*
- * Stop completion callback from associated lport
- */
- void
- bfa_fcs_vport_stop_comp(struct bfa_fcs_vport_s *vport)
- {
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOPCOMP);
- }
- /*
- * Delete completion callback from associated lport
- */
- void
- bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
- {
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELCOMP);
- }
- /*
- * fcs_vport_api Virtual port API
- */
- /*
- * Use this function to instantiate a new FCS vport object. This
- * function will not trigger any HW initialization process (which will be
- * done in vport_start() call)
- *
- * param[in] vport - pointer to bfa_fcs_vport_t. This space
- * needs to be allocated by the driver.
- * param[in] fcs - FCS instance
- * param[in] vport_cfg - vport configuration
- * param[in] vf_id - VF_ID if vport is created within a VF.
- * FC_VF_ID_NULL to specify base fabric.
- * param[in] vport_drv - Opaque handle back to the driver's vport
- * structure
- *
- * retval BFA_STATUS_OK - on success.
- * retval BFA_STATUS_FAILED - on failure.
- */
- bfa_status_t
- bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
- u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
- struct bfad_vport_s *vport_drv)
- {
- if (vport_cfg->pwwn == 0)
- return BFA_STATUS_INVALID_WWN;
- if (bfa_fcs_lport_get_pwwn(&fcs->fabric.bport) == vport_cfg->pwwn)
- return BFA_STATUS_VPORT_WWN_BP;
- if (bfa_fcs_vport_lookup(fcs, vf_id, vport_cfg->pwwn) != NULL)
- return BFA_STATUS_VPORT_EXISTS;
- if (fcs->fabric.num_vports ==
- bfa_lps_get_max_vport(fcs->bfa))
- return BFA_STATUS_VPORT_MAX;
- vport->lps = bfa_lps_alloc(fcs->bfa);
- if (!vport->lps)
- return BFA_STATUS_VPORT_MAX;
- vport->vport_drv = vport_drv;
- vport_cfg->preboot_vp = BFA_FALSE;
- bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
- bfa_fcs_lport_attach(&vport->lport, fcs, vf_id, vport);
- bfa_fcs_lport_init(&vport->lport, vport_cfg);
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_CREATE);
- return BFA_STATUS_OK;
- }
- /*
- * Use this function to instantiate a new FCS PBC vport object. This
- * function will not trigger any HW initialization process (which will be
- * done in vport_start() call)
- *
- * param[in] vport - pointer to bfa_fcs_vport_t. This space
- * needs to be allocated by the driver.
- * param[in] fcs - FCS instance
- * param[in] vport_cfg - vport configuration
- * param[in] vf_id - VF_ID if vport is created within a VF.
- * FC_VF_ID_NULL to specify base fabric.
- * param[in] vport_drv - Opaque handle back to the driver's vport
- * structure
- *
- * retval BFA_STATUS_OK - on success.
- * retval BFA_STATUS_FAILED - on failure.
- */
- bfa_status_t
- bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
- u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
- struct bfad_vport_s *vport_drv)
- {
- bfa_status_t rc;
- rc = bfa_fcs_vport_create(vport, fcs, vf_id, vport_cfg, vport_drv);
- vport->lport.port_cfg.preboot_vp = BFA_TRUE;
- return rc;
- }
- /*
- * Use this function to findout if this is a pbc vport or not.
- *
- * @param[in] vport - pointer to bfa_fcs_vport_t.
- *
- * @returns None
- */
- bfa_boolean_t
- bfa_fcs_is_pbc_vport(struct bfa_fcs_vport_s *vport)
- {
- if (vport && (vport->lport.port_cfg.preboot_vp == BFA_TRUE))
- return BFA_TRUE;
- else
- return BFA_FALSE;
- }
- /*
- * Use this function initialize the vport.
- *
- * @param[in] vport - pointer to bfa_fcs_vport_t.
- *
- * @returns None
- */
- bfa_status_t
- bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
- {
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_START);
- return BFA_STATUS_OK;
- }
- /*
- * Use this function quiese the vport object. This function will return
- * immediately, when the vport is actually stopped, the
- * bfa_drv_vport_stop_cb() will be called.
- *
- * param[in] vport - pointer to bfa_fcs_vport_t.
- *
- * return None
- */
- bfa_status_t
- bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
- {
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
- return BFA_STATUS_OK;
- }
- /*
- * Use this function to delete a vport object. Fabric object should
- * be stopped before this function call.
- *
- * !!!!!!! Donot invoke this from within FCS !!!!!!!
- *
- * param[in] vport - pointer to bfa_fcs_vport_t.
- *
- * return None
- */
- bfa_status_t
- bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport)
- {
- if (vport->lport.port_cfg.preboot_vp)
- return BFA_STATUS_PBC;
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
- return BFA_STATUS_OK;
- }
- /*
- * Use this function to get vport's current status info.
- *
- * param[in] vport pointer to bfa_fcs_vport_t.
- * param[out] attr pointer to return vport attributes
- *
- * return None
- */
- void
- bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
- struct bfa_vport_attr_s *attr)
- {
- if (vport == NULL || attr == NULL)
- return;
- memset(attr, 0, sizeof(struct bfa_vport_attr_s));
- bfa_fcs_lport_get_attr(&vport->lport, &attr->port_attr);
- attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm);
- }
- /*
- * Lookup a virtual port. Excludes base port from lookup.
- */
- struct bfa_fcs_vport_s *
- bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
- {
- struct bfa_fcs_vport_s *vport;
- struct bfa_fcs_fabric_s *fabric;
- bfa_trc(fcs, vf_id);
- bfa_trc(fcs, vpwwn);
- fabric = bfa_fcs_vf_lookup(fcs, vf_id);
- if (!fabric) {
- bfa_trc(fcs, vf_id);
- return NULL;
- }
- vport = bfa_fcs_fabric_vport_lookup(fabric, vpwwn);
- return vport;
- }
- /*
- * FDISC Response
- */
- void
- bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
- {
- struct bfa_fcs_vport_s *vport = uarg;
- bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
- bfa_trc(__vport_fcs(vport), status);
- switch (status) {
- case BFA_STATUS_OK:
- /*
- * Initialize the V-Port fields
- */
- __vport_fcid(vport) = vport->lps->lp_pid;
- vport->vport_stats.fdisc_accepts++;
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
- break;
- case BFA_STATUS_INVALID_MAC:
- /* Only for CNA */
- vport->vport_stats.fdisc_acc_bad++;
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
- break;
- case BFA_STATUS_EPROTOCOL:
- switch (vport->lps->ext_status) {
- case BFA_EPROTO_BAD_ACCEPT:
- vport->vport_stats.fdisc_acc_bad++;
- break;
- case BFA_EPROTO_UNKNOWN_RSP:
- vport->vport_stats.fdisc_unknown_rsp++;
- break;
- default:
- break;
- }
- if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
- else
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
- break;
- case BFA_STATUS_ETIMER:
- vport->vport_stats.fdisc_timeouts++;
- if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
- else
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
- break;
- case BFA_STATUS_FABRIC_RJT:
- vport->vport_stats.fdisc_rejects++;
- bfa_fcs_vport_fdisc_rejected(vport);
- break;
- default:
- vport->vport_stats.fdisc_rsp_err++;
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
- }
- }
- /*
- * LOGO response
- */
- void
- bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
- {
- struct bfa_fcs_vport_s *vport = uarg;
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
- }
- /*
- * Received clear virtual link
- */
- void
- bfa_cb_lps_cvl_event(void *bfad, void *uarg)
- {
- struct bfa_fcs_vport_s *vport = uarg;
- /* Send an Offline followed by an ONLINE */
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
- bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
- }
|