bfa_fcs_lport.c 177 KB

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