bfa_fcs_lport.c 177 KB

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