bfa_svc.c 164 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  4. * Copyright (c) 2014- QLogic Corporation.
  5. * All rights reserved
  6. * www.qlogic.com
  7. *
  8. * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
  9. */
  10. #include "bfad_drv.h"
  11. #include "bfad_im.h"
  12. #include "bfa_plog.h"
  13. #include "bfa_cs.h"
  14. #include "bfa_modules.h"
  15. BFA_TRC_FILE(HAL, FCXP);
  16. /*
  17. * LPS related definitions
  18. */
  19. #define BFA_LPS_MIN_LPORTS (1)
  20. #define BFA_LPS_MAX_LPORTS (256)
  21. /*
  22. * Maximum Vports supported per physical port or vf.
  23. */
  24. #define BFA_LPS_MAX_VPORTS_SUPP_CB 255
  25. #define BFA_LPS_MAX_VPORTS_SUPP_CT 190
  26. /*
  27. * FC PORT related definitions
  28. */
  29. /*
  30. * The port is considered disabled if corresponding physical port or IOC are
  31. * disabled explicitly
  32. */
  33. #define BFA_PORT_IS_DISABLED(bfa) \
  34. ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
  35. (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
  36. /*
  37. * BFA port state machine events
  38. */
  39. enum bfa_fcport_sm_event {
  40. BFA_FCPORT_SM_START = 1, /* start port state machine */
  41. BFA_FCPORT_SM_STOP = 2, /* stop port state machine */
  42. BFA_FCPORT_SM_ENABLE = 3, /* enable port */
  43. BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */
  44. BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */
  45. BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */
  46. BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */
  47. BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */
  48. BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
  49. BFA_FCPORT_SM_DPORTENABLE = 10, /* enable dport */
  50. BFA_FCPORT_SM_DPORTDISABLE = 11,/* disable dport */
  51. BFA_FCPORT_SM_FAA_MISCONFIG = 12, /* FAA misconfiguratin */
  52. BFA_FCPORT_SM_DDPORTENABLE = 13, /* enable ddport */
  53. BFA_FCPORT_SM_DDPORTDISABLE = 14, /* disable ddport */
  54. };
  55. /*
  56. * BFA port link notification state machine events
  57. */
  58. enum bfa_fcport_ln_sm_event {
  59. BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
  60. BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
  61. BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
  62. };
  63. /*
  64. * RPORT related definitions
  65. */
  66. #define bfa_rport_offline_cb(__rp) do { \
  67. if ((__rp)->bfa->fcs) \
  68. bfa_cb_rport_offline((__rp)->rport_drv); \
  69. else { \
  70. bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
  71. __bfa_cb_rport_offline, (__rp)); \
  72. } \
  73. } while (0)
  74. #define bfa_rport_online_cb(__rp) do { \
  75. if ((__rp)->bfa->fcs) \
  76. bfa_cb_rport_online((__rp)->rport_drv); \
  77. else { \
  78. bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
  79. __bfa_cb_rport_online, (__rp)); \
  80. } \
  81. } while (0)
  82. /*
  83. * forward declarations FCXP related functions
  84. */
  85. static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete);
  86. static void hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
  87. struct bfi_fcxp_send_rsp_s *fcxp_rsp);
  88. static void hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen,
  89. struct bfa_fcxp_s *fcxp, struct fchs_s *fchs);
  90. static void bfa_fcxp_qresume(void *cbarg);
  91. static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp,
  92. struct bfi_fcxp_send_req_s *send_req);
  93. /*
  94. * forward declarations for LPS functions
  95. */
  96. static void bfa_lps_login_rsp(struct bfa_s *bfa,
  97. struct bfi_lps_login_rsp_s *rsp);
  98. static void bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count);
  99. static void bfa_lps_logout_rsp(struct bfa_s *bfa,
  100. struct bfi_lps_logout_rsp_s *rsp);
  101. static void bfa_lps_reqq_resume(void *lps_arg);
  102. static void bfa_lps_free(struct bfa_lps_s *lps);
  103. static void bfa_lps_send_login(struct bfa_lps_s *lps);
  104. static void bfa_lps_send_logout(struct bfa_lps_s *lps);
  105. static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps);
  106. static void bfa_lps_login_comp(struct bfa_lps_s *lps);
  107. static void bfa_lps_logout_comp(struct bfa_lps_s *lps);
  108. static void bfa_lps_cvl_event(struct bfa_lps_s *lps);
  109. /*
  110. * forward declaration for LPS state machine
  111. */
  112. static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event);
  113. static void bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event);
  114. static void bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event
  115. event);
  116. static void bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event);
  117. static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps,
  118. enum bfa_lps_event event);
  119. static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event);
  120. static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event
  121. event);
  122. /*
  123. * forward declaration for FC Port functions
  124. */
  125. static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
  126. static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport);
  127. static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport);
  128. static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport);
  129. static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport);
  130. static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete);
  131. static void bfa_fcport_scn(struct bfa_fcport_s *fcport,
  132. enum bfa_port_linkstate event, bfa_boolean_t trunk);
  133. static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln,
  134. enum bfa_port_linkstate event);
  135. static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete);
  136. static void bfa_fcport_stats_get_timeout(void *cbarg);
  137. static void bfa_fcport_stats_clr_timeout(void *cbarg);
  138. static void bfa_trunk_iocdisable(struct bfa_s *bfa);
  139. /*
  140. * forward declaration for FC PORT state machine
  141. */
  142. static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
  143. enum bfa_fcport_sm_event event);
  144. static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
  145. enum bfa_fcport_sm_event event);
  146. static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
  147. enum bfa_fcport_sm_event event);
  148. static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
  149. enum bfa_fcport_sm_event event);
  150. static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
  151. enum bfa_fcport_sm_event event);
  152. static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
  153. enum bfa_fcport_sm_event event);
  154. static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
  155. enum bfa_fcport_sm_event event);
  156. static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
  157. enum bfa_fcport_sm_event event);
  158. static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
  159. enum bfa_fcport_sm_event event);
  160. static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
  161. enum bfa_fcport_sm_event event);
  162. static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
  163. enum bfa_fcport_sm_event event);
  164. static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
  165. enum bfa_fcport_sm_event event);
  166. static void bfa_fcport_sm_dport(struct bfa_fcport_s *fcport,
  167. enum bfa_fcport_sm_event event);
  168. static void bfa_fcport_sm_ddport(struct bfa_fcport_s *fcport,
  169. enum bfa_fcport_sm_event event);
  170. static void bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s *fcport,
  171. enum bfa_fcport_sm_event event);
  172. static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
  173. enum bfa_fcport_ln_sm_event event);
  174. static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
  175. enum bfa_fcport_ln_sm_event event);
  176. static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
  177. enum bfa_fcport_ln_sm_event event);
  178. static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
  179. enum bfa_fcport_ln_sm_event event);
  180. static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
  181. enum bfa_fcport_ln_sm_event event);
  182. static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
  183. enum bfa_fcport_ln_sm_event event);
  184. static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
  185. enum bfa_fcport_ln_sm_event event);
  186. static struct bfa_sm_table_s hal_port_sm_table[] = {
  187. {BFA_SM(bfa_fcport_sm_uninit), BFA_PORT_ST_UNINIT},
  188. {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PORT_ST_ENABLING_QWAIT},
  189. {BFA_SM(bfa_fcport_sm_enabling), BFA_PORT_ST_ENABLING},
  190. {BFA_SM(bfa_fcport_sm_linkdown), BFA_PORT_ST_LINKDOWN},
  191. {BFA_SM(bfa_fcport_sm_linkup), BFA_PORT_ST_LINKUP},
  192. {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PORT_ST_DISABLING_QWAIT},
  193. {BFA_SM(bfa_fcport_sm_toggling_qwait), BFA_PORT_ST_TOGGLING_QWAIT},
  194. {BFA_SM(bfa_fcport_sm_disabling), BFA_PORT_ST_DISABLING},
  195. {BFA_SM(bfa_fcport_sm_disabled), BFA_PORT_ST_DISABLED},
  196. {BFA_SM(bfa_fcport_sm_stopped), BFA_PORT_ST_STOPPED},
  197. {BFA_SM(bfa_fcport_sm_iocdown), BFA_PORT_ST_IOCDOWN},
  198. {BFA_SM(bfa_fcport_sm_iocfail), BFA_PORT_ST_IOCDOWN},
  199. {BFA_SM(bfa_fcport_sm_dport), BFA_PORT_ST_DPORT},
  200. {BFA_SM(bfa_fcport_sm_ddport), BFA_PORT_ST_DDPORT},
  201. {BFA_SM(bfa_fcport_sm_faa_misconfig), BFA_PORT_ST_FAA_MISCONFIG},
  202. };
  203. /*
  204. * forward declaration for RPORT related functions
  205. */
  206. static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod);
  207. static void bfa_rport_free(struct bfa_rport_s *rport);
  208. static bfa_boolean_t bfa_rport_send_fwcreate(struct bfa_rport_s *rp);
  209. static bfa_boolean_t bfa_rport_send_fwdelete(struct bfa_rport_s *rp);
  210. static bfa_boolean_t bfa_rport_send_fwspeed(struct bfa_rport_s *rp);
  211. static void __bfa_cb_rport_online(void *cbarg,
  212. bfa_boolean_t complete);
  213. static void __bfa_cb_rport_offline(void *cbarg,
  214. bfa_boolean_t complete);
  215. /*
  216. * forward declaration for RPORT state machine
  217. */
  218. static void bfa_rport_sm_uninit(struct bfa_rport_s *rp,
  219. enum bfa_rport_event event);
  220. static void bfa_rport_sm_created(struct bfa_rport_s *rp,
  221. enum bfa_rport_event event);
  222. static void bfa_rport_sm_fwcreate(struct bfa_rport_s *rp,
  223. enum bfa_rport_event event);
  224. static void bfa_rport_sm_online(struct bfa_rport_s *rp,
  225. enum bfa_rport_event event);
  226. static void bfa_rport_sm_fwdelete(struct bfa_rport_s *rp,
  227. enum bfa_rport_event event);
  228. static void bfa_rport_sm_offline(struct bfa_rport_s *rp,
  229. enum bfa_rport_event event);
  230. static void bfa_rport_sm_deleting(struct bfa_rport_s *rp,
  231. enum bfa_rport_event event);
  232. static void bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
  233. enum bfa_rport_event event);
  234. static void bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
  235. enum bfa_rport_event event);
  236. static void bfa_rport_sm_iocdisable(struct bfa_rport_s *rp,
  237. enum bfa_rport_event event);
  238. static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp,
  239. enum bfa_rport_event event);
  240. static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp,
  241. enum bfa_rport_event event);
  242. static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp,
  243. enum bfa_rport_event event);
  244. /*
  245. * PLOG related definitions
  246. */
  247. static int
  248. plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec)
  249. {
  250. if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
  251. (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING))
  252. return 1;
  253. if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
  254. (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ))
  255. return 1;
  256. return 0;
  257. }
  258. static void
  259. bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
  260. {
  261. u16 tail;
  262. struct bfa_plog_rec_s *pl_recp;
  263. if (plog->plog_enabled == 0)
  264. return;
  265. if (plkd_validate_logrec(pl_rec)) {
  266. WARN_ON(1);
  267. return;
  268. }
  269. tail = plog->tail;
  270. pl_recp = &(plog->plog_recs[tail]);
  271. memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
  272. pl_recp->tv = ktime_get_real_seconds();
  273. BFA_PL_LOG_REC_INCR(plog->tail);
  274. if (plog->head == plog->tail)
  275. BFA_PL_LOG_REC_INCR(plog->head);
  276. }
  277. void
  278. bfa_plog_init(struct bfa_plog_s *plog)
  279. {
  280. memset((char *)plog, 0, sizeof(struct bfa_plog_s));
  281. memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN);
  282. plog->head = plog->tail = 0;
  283. plog->plog_enabled = 1;
  284. }
  285. void
  286. bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  287. enum bfa_plog_eid event,
  288. u16 misc, char *log_str)
  289. {
  290. struct bfa_plog_rec_s lp;
  291. if (plog->plog_enabled) {
  292. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  293. lp.mid = mid;
  294. lp.eid = event;
  295. lp.log_type = BFA_PL_LOG_TYPE_STRING;
  296. lp.misc = misc;
  297. strlcpy(lp.log_entry.string_log, log_str,
  298. BFA_PL_STRING_LOG_SZ);
  299. lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0';
  300. bfa_plog_add(plog, &lp);
  301. }
  302. }
  303. void
  304. bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  305. enum bfa_plog_eid event,
  306. u16 misc, u32 *intarr, u32 num_ints)
  307. {
  308. struct bfa_plog_rec_s lp;
  309. u32 i;
  310. if (num_ints > BFA_PL_INT_LOG_SZ)
  311. num_ints = BFA_PL_INT_LOG_SZ;
  312. if (plog->plog_enabled) {
  313. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  314. lp.mid = mid;
  315. lp.eid = event;
  316. lp.log_type = BFA_PL_LOG_TYPE_INT;
  317. lp.misc = misc;
  318. for (i = 0; i < num_ints; i++)
  319. lp.log_entry.int_log[i] = intarr[i];
  320. lp.log_num_ints = (u8) num_ints;
  321. bfa_plog_add(plog, &lp);
  322. }
  323. }
  324. void
  325. bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  326. enum bfa_plog_eid event,
  327. u16 misc, struct fchs_s *fchdr)
  328. {
  329. u32 *tmp_int = (u32 *) fchdr;
  330. u32 ints[BFA_PL_INT_LOG_SZ];
  331. if (plog->plog_enabled) {
  332. ints[0] = tmp_int[0];
  333. ints[1] = tmp_int[1];
  334. ints[2] = tmp_int[4];
  335. bfa_plog_intarr(plog, mid, event, misc, ints, 3);
  336. }
  337. }
  338. void
  339. bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  340. enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
  341. u32 pld_w0)
  342. {
  343. u32 *tmp_int = (u32 *) fchdr;
  344. u32 ints[BFA_PL_INT_LOG_SZ];
  345. if (plog->plog_enabled) {
  346. ints[0] = tmp_int[0];
  347. ints[1] = tmp_int[1];
  348. ints[2] = tmp_int[4];
  349. ints[3] = pld_w0;
  350. bfa_plog_intarr(plog, mid, event, misc, ints, 4);
  351. }
  352. }
  353. /*
  354. * fcxp_pvt BFA FCXP private functions
  355. */
  356. static void
  357. claim_fcxps_mem(struct bfa_fcxp_mod_s *mod)
  358. {
  359. u16 i;
  360. struct bfa_fcxp_s *fcxp;
  361. fcxp = (struct bfa_fcxp_s *) bfa_mem_kva_curp(mod);
  362. memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps);
  363. INIT_LIST_HEAD(&mod->fcxp_req_free_q);
  364. INIT_LIST_HEAD(&mod->fcxp_rsp_free_q);
  365. INIT_LIST_HEAD(&mod->fcxp_active_q);
  366. INIT_LIST_HEAD(&mod->fcxp_req_unused_q);
  367. INIT_LIST_HEAD(&mod->fcxp_rsp_unused_q);
  368. mod->fcxp_list = fcxp;
  369. for (i = 0; i < mod->num_fcxps; i++) {
  370. fcxp->fcxp_mod = mod;
  371. fcxp->fcxp_tag = i;
  372. if (i < (mod->num_fcxps / 2)) {
  373. list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q);
  374. fcxp->req_rsp = BFA_TRUE;
  375. } else {
  376. list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q);
  377. fcxp->req_rsp = BFA_FALSE;
  378. }
  379. bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp);
  380. fcxp->reqq_waiting = BFA_FALSE;
  381. fcxp = fcxp + 1;
  382. }
  383. bfa_mem_kva_curp(mod) = (void *)fcxp;
  384. }
  385. void
  386. bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  387. struct bfa_s *bfa)
  388. {
  389. struct bfa_fcxp_mod_s *fcxp_mod = BFA_FCXP_MOD(bfa);
  390. struct bfa_mem_kva_s *fcxp_kva = BFA_MEM_FCXP_KVA(bfa);
  391. struct bfa_mem_dma_s *seg_ptr;
  392. u16 nsegs, idx, per_seg_fcxp;
  393. u16 num_fcxps = cfg->fwcfg.num_fcxp_reqs;
  394. u32 per_fcxp_sz;
  395. if (num_fcxps == 0)
  396. return;
  397. if (cfg->drvcfg.min_cfg)
  398. per_fcxp_sz = 2 * BFA_FCXP_MAX_IBUF_SZ;
  399. else
  400. per_fcxp_sz = BFA_FCXP_MAX_IBUF_SZ + BFA_FCXP_MAX_LBUF_SZ;
  401. /* dma memory */
  402. nsegs = BFI_MEM_DMA_NSEGS(num_fcxps, per_fcxp_sz);
  403. per_seg_fcxp = BFI_MEM_NREQS_SEG(per_fcxp_sz);
  404. bfa_mem_dma_seg_iter(fcxp_mod, seg_ptr, nsegs, idx) {
  405. if (num_fcxps >= per_seg_fcxp) {
  406. num_fcxps -= per_seg_fcxp;
  407. bfa_mem_dma_setup(minfo, seg_ptr,
  408. per_seg_fcxp * per_fcxp_sz);
  409. } else
  410. bfa_mem_dma_setup(minfo, seg_ptr,
  411. num_fcxps * per_fcxp_sz);
  412. }
  413. /* kva memory */
  414. bfa_mem_kva_setup(minfo, fcxp_kva,
  415. cfg->fwcfg.num_fcxp_reqs * sizeof(struct bfa_fcxp_s));
  416. }
  417. void
  418. bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  419. struct bfa_pcidev_s *pcidev)
  420. {
  421. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  422. mod->bfa = bfa;
  423. mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs;
  424. /*
  425. * Initialize FCXP request and response payload sizes.
  426. */
  427. mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ;
  428. if (!cfg->drvcfg.min_cfg)
  429. mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ;
  430. INIT_LIST_HEAD(&mod->req_wait_q);
  431. INIT_LIST_HEAD(&mod->rsp_wait_q);
  432. claim_fcxps_mem(mod);
  433. }
  434. void
  435. bfa_fcxp_iocdisable(struct bfa_s *bfa)
  436. {
  437. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  438. struct bfa_fcxp_s *fcxp;
  439. struct list_head *qe, *qen;
  440. /* Enqueue unused fcxp resources to free_q */
  441. list_splice_tail_init(&mod->fcxp_req_unused_q, &mod->fcxp_req_free_q);
  442. list_splice_tail_init(&mod->fcxp_rsp_unused_q, &mod->fcxp_rsp_free_q);
  443. list_for_each_safe(qe, qen, &mod->fcxp_active_q) {
  444. fcxp = (struct bfa_fcxp_s *) qe;
  445. if (fcxp->caller == NULL) {
  446. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  447. BFA_STATUS_IOC_FAILURE, 0, 0, NULL);
  448. bfa_fcxp_free(fcxp);
  449. } else {
  450. fcxp->rsp_status = BFA_STATUS_IOC_FAILURE;
  451. bfa_cb_queue(bfa, &fcxp->hcb_qe,
  452. __bfa_fcxp_send_cbfn, fcxp);
  453. }
  454. }
  455. }
  456. static struct bfa_fcxp_s *
  457. bfa_fcxp_get(struct bfa_fcxp_mod_s *fm, bfa_boolean_t req)
  458. {
  459. struct bfa_fcxp_s *fcxp;
  460. if (req)
  461. bfa_q_deq(&fm->fcxp_req_free_q, &fcxp);
  462. else
  463. bfa_q_deq(&fm->fcxp_rsp_free_q, &fcxp);
  464. if (fcxp)
  465. list_add_tail(&fcxp->qe, &fm->fcxp_active_q);
  466. return fcxp;
  467. }
  468. static void
  469. bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp,
  470. struct bfa_s *bfa,
  471. u8 *use_ibuf,
  472. u32 *nr_sgles,
  473. bfa_fcxp_get_sgaddr_t *r_sga_cbfn,
  474. bfa_fcxp_get_sglen_t *r_sglen_cbfn,
  475. struct list_head *r_sgpg_q,
  476. int n_sgles,
  477. bfa_fcxp_get_sgaddr_t sga_cbfn,
  478. bfa_fcxp_get_sglen_t sglen_cbfn)
  479. {
  480. WARN_ON(bfa == NULL);
  481. bfa_trc(bfa, fcxp->fcxp_tag);
  482. if (n_sgles == 0) {
  483. *use_ibuf = 1;
  484. } else {
  485. WARN_ON(*sga_cbfn == NULL);
  486. WARN_ON(*sglen_cbfn == NULL);
  487. *use_ibuf = 0;
  488. *r_sga_cbfn = sga_cbfn;
  489. *r_sglen_cbfn = sglen_cbfn;
  490. *nr_sgles = n_sgles;
  491. /*
  492. * alloc required sgpgs
  493. */
  494. if (n_sgles > BFI_SGE_INLINE)
  495. WARN_ON(1);
  496. }
  497. }
  498. static void
  499. bfa_fcxp_init(struct bfa_fcxp_s *fcxp,
  500. void *caller, struct bfa_s *bfa, int nreq_sgles,
  501. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  502. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  503. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  504. bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
  505. {
  506. WARN_ON(bfa == NULL);
  507. bfa_trc(bfa, fcxp->fcxp_tag);
  508. fcxp->caller = caller;
  509. bfa_fcxp_init_reqrsp(fcxp, bfa,
  510. &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn,
  511. &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q,
  512. nreq_sgles, req_sga_cbfn, req_sglen_cbfn);
  513. bfa_fcxp_init_reqrsp(fcxp, bfa,
  514. &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn,
  515. &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q,
  516. nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn);
  517. }
  518. static void
  519. bfa_fcxp_put(struct bfa_fcxp_s *fcxp)
  520. {
  521. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  522. struct bfa_fcxp_wqe_s *wqe;
  523. if (fcxp->req_rsp)
  524. bfa_q_deq(&mod->req_wait_q, &wqe);
  525. else
  526. bfa_q_deq(&mod->rsp_wait_q, &wqe);
  527. if (wqe) {
  528. bfa_trc(mod->bfa, fcxp->fcxp_tag);
  529. bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles,
  530. wqe->nrsp_sgles, wqe->req_sga_cbfn,
  531. wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn,
  532. wqe->rsp_sglen_cbfn);
  533. wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp);
  534. return;
  535. }
  536. WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp));
  537. list_del(&fcxp->qe);
  538. if (fcxp->req_rsp)
  539. list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q);
  540. else
  541. list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q);
  542. }
  543. static void
  544. bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
  545. bfa_status_t req_status, u32 rsp_len,
  546. u32 resid_len, struct fchs_s *rsp_fchs)
  547. {
  548. /* discarded fcxp completion */
  549. }
  550. static void
  551. __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete)
  552. {
  553. struct bfa_fcxp_s *fcxp = cbarg;
  554. if (complete) {
  555. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  556. fcxp->rsp_status, fcxp->rsp_len,
  557. fcxp->residue_len, &fcxp->rsp_fchs);
  558. } else {
  559. bfa_fcxp_free(fcxp);
  560. }
  561. }
  562. static void
  563. hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp)
  564. {
  565. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  566. struct bfa_fcxp_s *fcxp;
  567. u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag);
  568. bfa_trc(bfa, fcxp_tag);
  569. fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len);
  570. /*
  571. * @todo f/w should not set residue to non-0 when everything
  572. * is received.
  573. */
  574. if (fcxp_rsp->req_status == BFA_STATUS_OK)
  575. fcxp_rsp->residue_len = 0;
  576. else
  577. fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len);
  578. fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag);
  579. WARN_ON(fcxp->send_cbfn == NULL);
  580. hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp);
  581. if (fcxp->send_cbfn != NULL) {
  582. bfa_trc(mod->bfa, (NULL == fcxp->caller));
  583. if (fcxp->caller == NULL) {
  584. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  585. fcxp_rsp->req_status, fcxp_rsp->rsp_len,
  586. fcxp_rsp->residue_len, &fcxp_rsp->fchs);
  587. /*
  588. * fcxp automatically freed on return from the callback
  589. */
  590. bfa_fcxp_free(fcxp);
  591. } else {
  592. fcxp->rsp_status = fcxp_rsp->req_status;
  593. fcxp->rsp_len = fcxp_rsp->rsp_len;
  594. fcxp->residue_len = fcxp_rsp->residue_len;
  595. fcxp->rsp_fchs = fcxp_rsp->fchs;
  596. bfa_cb_queue(bfa, &fcxp->hcb_qe,
  597. __bfa_fcxp_send_cbfn, fcxp);
  598. }
  599. } else {
  600. bfa_trc(bfa, (NULL == fcxp->send_cbfn));
  601. }
  602. }
  603. static void
  604. hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp,
  605. struct fchs_s *fchs)
  606. {
  607. /*
  608. * TODO: TX ox_id
  609. */
  610. if (reqlen > 0) {
  611. if (fcxp->use_ireqbuf) {
  612. u32 pld_w0 =
  613. *((u32 *) BFA_FCXP_REQ_PLD(fcxp));
  614. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
  615. BFA_PL_EID_TX,
  616. reqlen + sizeof(struct fchs_s), fchs,
  617. pld_w0);
  618. } else {
  619. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
  620. BFA_PL_EID_TX,
  621. reqlen + sizeof(struct fchs_s),
  622. fchs);
  623. }
  624. } else {
  625. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX,
  626. reqlen + sizeof(struct fchs_s), fchs);
  627. }
  628. }
  629. static void
  630. hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
  631. struct bfi_fcxp_send_rsp_s *fcxp_rsp)
  632. {
  633. if (fcxp_rsp->rsp_len > 0) {
  634. if (fcxp->use_irspbuf) {
  635. u32 pld_w0 =
  636. *((u32 *) BFA_FCXP_RSP_PLD(fcxp));
  637. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
  638. BFA_PL_EID_RX,
  639. (u16) fcxp_rsp->rsp_len,
  640. &fcxp_rsp->fchs, pld_w0);
  641. } else {
  642. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
  643. BFA_PL_EID_RX,
  644. (u16) fcxp_rsp->rsp_len,
  645. &fcxp_rsp->fchs);
  646. }
  647. } else {
  648. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX,
  649. (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs);
  650. }
  651. }
  652. /*
  653. * Handler to resume sending fcxp when space in available in cpe queue.
  654. */
  655. static void
  656. bfa_fcxp_qresume(void *cbarg)
  657. {
  658. struct bfa_fcxp_s *fcxp = cbarg;
  659. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  660. struct bfi_fcxp_send_req_s *send_req;
  661. fcxp->reqq_waiting = BFA_FALSE;
  662. send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
  663. bfa_fcxp_queue(fcxp, send_req);
  664. }
  665. /*
  666. * Queue fcxp send request to foimrware.
  667. */
  668. static void
  669. bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
  670. {
  671. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  672. struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
  673. struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
  674. struct bfa_rport_s *rport = reqi->bfa_rport;
  675. bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ,
  676. bfa_fn_lpu(bfa));
  677. send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag);
  678. if (rport) {
  679. send_req->rport_fw_hndl = rport->fw_handle;
  680. send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz);
  681. if (send_req->max_frmsz == 0)
  682. send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
  683. } else {
  684. send_req->rport_fw_hndl = 0;
  685. send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
  686. }
  687. send_req->vf_id = cpu_to_be16(reqi->vf_id);
  688. send_req->lp_fwtag = bfa_lps_get_fwtag(bfa, reqi->lp_tag);
  689. send_req->class = reqi->class;
  690. send_req->rsp_timeout = rspi->rsp_timeout;
  691. send_req->cts = reqi->cts;
  692. send_req->fchs = reqi->fchs;
  693. send_req->req_len = cpu_to_be32(reqi->req_tot_len);
  694. send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen);
  695. /*
  696. * setup req sgles
  697. */
  698. if (fcxp->use_ireqbuf == 1) {
  699. bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
  700. BFA_FCXP_REQ_PLD_PA(fcxp));
  701. } else {
  702. if (fcxp->nreq_sgles > 0) {
  703. WARN_ON(fcxp->nreq_sgles != 1);
  704. bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
  705. fcxp->req_sga_cbfn(fcxp->caller, 0));
  706. } else {
  707. WARN_ON(reqi->req_tot_len != 0);
  708. bfa_alen_set(&send_req->rsp_alen, 0, 0);
  709. }
  710. }
  711. /*
  712. * setup rsp sgles
  713. */
  714. if (fcxp->use_irspbuf == 1) {
  715. WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ);
  716. bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
  717. BFA_FCXP_RSP_PLD_PA(fcxp));
  718. } else {
  719. if (fcxp->nrsp_sgles > 0) {
  720. WARN_ON(fcxp->nrsp_sgles != 1);
  721. bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
  722. fcxp->rsp_sga_cbfn(fcxp->caller, 0));
  723. } else {
  724. WARN_ON(rspi->rsp_maxlen != 0);
  725. bfa_alen_set(&send_req->rsp_alen, 0, 0);
  726. }
  727. }
  728. hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs);
  729. bfa_reqq_produce(bfa, BFA_REQQ_FCXP, send_req->mh);
  730. bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP));
  731. bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP));
  732. }
  733. /*
  734. * Allocate an FCXP instance to send a response or to send a request
  735. * that has a response. Request/response buffers are allocated by caller.
  736. *
  737. * @param[in] bfa BFA bfa instance
  738. * @param[in] nreq_sgles Number of SG elements required for request
  739. * buffer. 0, if fcxp internal buffers are used.
  740. * Use bfa_fcxp_get_reqbuf() to get the
  741. * internal req buffer.
  742. * @param[in] req_sgles SG elements describing request buffer. Will be
  743. * copied in by BFA and hence can be freed on
  744. * return from this function.
  745. * @param[in] get_req_sga function ptr to be called to get a request SG
  746. * Address (given the sge index).
  747. * @param[in] get_req_sglen function ptr to be called to get a request SG
  748. * len (given the sge index).
  749. * @param[in] get_rsp_sga function ptr to be called to get a response SG
  750. * Address (given the sge index).
  751. * @param[in] get_rsp_sglen function ptr to be called to get a response SG
  752. * len (given the sge index).
  753. * @param[in] req Allocated FCXP is used to send req or rsp?
  754. * request - BFA_TRUE, response - BFA_FALSE
  755. *
  756. * @return FCXP instance. NULL on failure.
  757. */
  758. struct bfa_fcxp_s *
  759. bfa_fcxp_req_rsp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles,
  760. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  761. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  762. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  763. bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req)
  764. {
  765. struct bfa_fcxp_s *fcxp = NULL;
  766. WARN_ON(bfa == NULL);
  767. fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa), req);
  768. if (fcxp == NULL)
  769. return NULL;
  770. bfa_trc(bfa, fcxp->fcxp_tag);
  771. bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn,
  772. req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn);
  773. return fcxp;
  774. }
  775. /*
  776. * Get the internal request buffer pointer
  777. *
  778. * @param[in] fcxp BFA fcxp pointer
  779. *
  780. * @return pointer to the internal request buffer
  781. */
  782. void *
  783. bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp)
  784. {
  785. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  786. void *reqbuf;
  787. WARN_ON(fcxp->use_ireqbuf != 1);
  788. reqbuf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
  789. mod->req_pld_sz + mod->rsp_pld_sz);
  790. return reqbuf;
  791. }
  792. u32
  793. bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp)
  794. {
  795. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  796. return mod->req_pld_sz;
  797. }
  798. /*
  799. * Get the internal response buffer pointer
  800. *
  801. * @param[in] fcxp BFA fcxp pointer
  802. *
  803. * @return pointer to the internal request buffer
  804. */
  805. void *
  806. bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp)
  807. {
  808. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  809. void *fcxp_buf;
  810. WARN_ON(fcxp->use_irspbuf != 1);
  811. fcxp_buf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag,
  812. mod->req_pld_sz + mod->rsp_pld_sz);
  813. /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */
  814. return ((u8 *) fcxp_buf) + mod->req_pld_sz;
  815. }
  816. /*
  817. * Free the BFA FCXP
  818. *
  819. * @param[in] fcxp BFA fcxp pointer
  820. *
  821. * @return void
  822. */
  823. void
  824. bfa_fcxp_free(struct bfa_fcxp_s *fcxp)
  825. {
  826. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  827. WARN_ON(fcxp == NULL);
  828. bfa_trc(mod->bfa, fcxp->fcxp_tag);
  829. bfa_fcxp_put(fcxp);
  830. }
  831. /*
  832. * Send a FCXP request
  833. *
  834. * @param[in] fcxp BFA fcxp pointer
  835. * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
  836. * @param[in] vf_id virtual Fabric ID
  837. * @param[in] lp_tag lport tag
  838. * @param[in] cts use Continuous sequence
  839. * @param[in] cos fc Class of Service
  840. * @param[in] reqlen request length, does not include FCHS length
  841. * @param[in] fchs fc Header Pointer. The header content will be copied
  842. * in by BFA.
  843. *
  844. * @param[in] cbfn call back function to be called on receiving
  845. * the response
  846. * @param[in] cbarg arg for cbfn
  847. * @param[in] rsp_timeout
  848. * response timeout
  849. *
  850. * @return bfa_status_t
  851. */
  852. void
  853. bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
  854. u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos,
  855. u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn,
  856. void *cbarg, u32 rsp_maxlen, u8 rsp_timeout)
  857. {
  858. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  859. struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
  860. struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
  861. struct bfi_fcxp_send_req_s *send_req;
  862. bfa_trc(bfa, fcxp->fcxp_tag);
  863. /*
  864. * setup request/response info
  865. */
  866. reqi->bfa_rport = rport;
  867. reqi->vf_id = vf_id;
  868. reqi->lp_tag = lp_tag;
  869. reqi->class = cos;
  870. rspi->rsp_timeout = rsp_timeout;
  871. reqi->cts = cts;
  872. reqi->fchs = *fchs;
  873. reqi->req_tot_len = reqlen;
  874. rspi->rsp_maxlen = rsp_maxlen;
  875. fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp;
  876. fcxp->send_cbarg = cbarg;
  877. /*
  878. * If no room in CPE queue, wait for space in request queue
  879. */
  880. send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
  881. if (!send_req) {
  882. bfa_trc(bfa, fcxp->fcxp_tag);
  883. fcxp->reqq_waiting = BFA_TRUE;
  884. bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe);
  885. return;
  886. }
  887. bfa_fcxp_queue(fcxp, send_req);
  888. }
  889. /*
  890. * Abort a BFA FCXP
  891. *
  892. * @param[in] fcxp BFA fcxp pointer
  893. *
  894. * @return void
  895. */
  896. bfa_status_t
  897. bfa_fcxp_abort(struct bfa_fcxp_s *fcxp)
  898. {
  899. bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag);
  900. WARN_ON(1);
  901. return BFA_STATUS_OK;
  902. }
  903. void
  904. bfa_fcxp_req_rsp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
  905. bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg,
  906. void *caller, int nreq_sgles,
  907. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  908. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  909. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  910. bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req)
  911. {
  912. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  913. if (req)
  914. WARN_ON(!list_empty(&mod->fcxp_req_free_q));
  915. else
  916. WARN_ON(!list_empty(&mod->fcxp_rsp_free_q));
  917. wqe->alloc_cbfn = alloc_cbfn;
  918. wqe->alloc_cbarg = alloc_cbarg;
  919. wqe->caller = caller;
  920. wqe->bfa = bfa;
  921. wqe->nreq_sgles = nreq_sgles;
  922. wqe->nrsp_sgles = nrsp_sgles;
  923. wqe->req_sga_cbfn = req_sga_cbfn;
  924. wqe->req_sglen_cbfn = req_sglen_cbfn;
  925. wqe->rsp_sga_cbfn = rsp_sga_cbfn;
  926. wqe->rsp_sglen_cbfn = rsp_sglen_cbfn;
  927. if (req)
  928. list_add_tail(&wqe->qe, &mod->req_wait_q);
  929. else
  930. list_add_tail(&wqe->qe, &mod->rsp_wait_q);
  931. }
  932. void
  933. bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe)
  934. {
  935. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  936. WARN_ON(!bfa_q_is_on_q(&mod->req_wait_q, wqe) ||
  937. !bfa_q_is_on_q(&mod->rsp_wait_q, wqe));
  938. list_del(&wqe->qe);
  939. }
  940. void
  941. bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
  942. {
  943. /*
  944. * If waiting for room in request queue, cancel reqq wait
  945. * and free fcxp.
  946. */
  947. if (fcxp->reqq_waiting) {
  948. fcxp->reqq_waiting = BFA_FALSE;
  949. bfa_reqq_wcancel(&fcxp->reqq_wqe);
  950. bfa_fcxp_free(fcxp);
  951. return;
  952. }
  953. fcxp->send_cbfn = bfa_fcxp_null_comp;
  954. }
  955. void
  956. bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  957. {
  958. switch (msg->mhdr.msg_id) {
  959. case BFI_FCXP_I2H_SEND_RSP:
  960. hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg);
  961. break;
  962. default:
  963. bfa_trc(bfa, msg->mhdr.msg_id);
  964. WARN_ON(1);
  965. }
  966. }
  967. u32
  968. bfa_fcxp_get_maxrsp(struct bfa_s *bfa)
  969. {
  970. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  971. return mod->rsp_pld_sz;
  972. }
  973. void
  974. bfa_fcxp_res_recfg(struct bfa_s *bfa, u16 num_fcxp_fw)
  975. {
  976. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  977. struct list_head *qe;
  978. int i;
  979. for (i = 0; i < (mod->num_fcxps - num_fcxp_fw); i++) {
  980. if (i < ((mod->num_fcxps - num_fcxp_fw) / 2)) {
  981. bfa_q_deq_tail(&mod->fcxp_req_free_q, &qe);
  982. list_add_tail(qe, &mod->fcxp_req_unused_q);
  983. } else {
  984. bfa_q_deq_tail(&mod->fcxp_rsp_free_q, &qe);
  985. list_add_tail(qe, &mod->fcxp_rsp_unused_q);
  986. }
  987. }
  988. }
  989. /*
  990. * BFA LPS state machine functions
  991. */
  992. /*
  993. * Init state -- no login
  994. */
  995. static void
  996. bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event)
  997. {
  998. bfa_trc(lps->bfa, lps->bfa_tag);
  999. bfa_trc(lps->bfa, event);
  1000. switch (event) {
  1001. case BFA_LPS_SM_LOGIN:
  1002. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1003. bfa_sm_set_state(lps, bfa_lps_sm_loginwait);
  1004. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1005. } else {
  1006. bfa_sm_set_state(lps, bfa_lps_sm_login);
  1007. bfa_lps_send_login(lps);
  1008. }
  1009. if (lps->fdisc)
  1010. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1011. BFA_PL_EID_LOGIN, 0, "FDISC Request");
  1012. else
  1013. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1014. BFA_PL_EID_LOGIN, 0, "FLOGI Request");
  1015. break;
  1016. case BFA_LPS_SM_LOGOUT:
  1017. bfa_lps_logout_comp(lps);
  1018. break;
  1019. case BFA_LPS_SM_DELETE:
  1020. bfa_lps_free(lps);
  1021. break;
  1022. case BFA_LPS_SM_RX_CVL:
  1023. case BFA_LPS_SM_OFFLINE:
  1024. break;
  1025. case BFA_LPS_SM_FWRSP:
  1026. /*
  1027. * Could happen when fabric detects loopback and discards
  1028. * the lps request. Fw will eventually sent out the timeout
  1029. * Just ignore
  1030. */
  1031. break;
  1032. case BFA_LPS_SM_SET_N2N_PID:
  1033. /*
  1034. * When topology is set to loop, bfa_lps_set_n2n_pid() sends
  1035. * this event. Ignore this event.
  1036. */
  1037. break;
  1038. default:
  1039. bfa_sm_fault(lps->bfa, event);
  1040. }
  1041. }
  1042. /*
  1043. * login is in progress -- awaiting response from firmware
  1044. */
  1045. static void
  1046. bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1047. {
  1048. bfa_trc(lps->bfa, lps->bfa_tag);
  1049. bfa_trc(lps->bfa, event);
  1050. switch (event) {
  1051. case BFA_LPS_SM_FWRSP:
  1052. if (lps->status == BFA_STATUS_OK) {
  1053. bfa_sm_set_state(lps, bfa_lps_sm_online);
  1054. if (lps->fdisc)
  1055. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1056. BFA_PL_EID_LOGIN, 0, "FDISC Accept");
  1057. else
  1058. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1059. BFA_PL_EID_LOGIN, 0, "FLOGI Accept");
  1060. /* If N2N, send the assigned PID to FW */
  1061. bfa_trc(lps->bfa, lps->fport);
  1062. bfa_trc(lps->bfa, lps->lp_pid);
  1063. if (!lps->fport && lps->lp_pid)
  1064. bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
  1065. } else {
  1066. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1067. if (lps->fdisc)
  1068. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1069. BFA_PL_EID_LOGIN, 0,
  1070. "FDISC Fail (RJT or timeout)");
  1071. else
  1072. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1073. BFA_PL_EID_LOGIN, 0,
  1074. "FLOGI Fail (RJT or timeout)");
  1075. }
  1076. bfa_lps_login_comp(lps);
  1077. break;
  1078. case BFA_LPS_SM_OFFLINE:
  1079. case BFA_LPS_SM_DELETE:
  1080. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1081. break;
  1082. case BFA_LPS_SM_SET_N2N_PID:
  1083. bfa_trc(lps->bfa, lps->fport);
  1084. bfa_trc(lps->bfa, lps->lp_pid);
  1085. break;
  1086. default:
  1087. bfa_sm_fault(lps->bfa, event);
  1088. }
  1089. }
  1090. /*
  1091. * login pending - awaiting space in request queue
  1092. */
  1093. static void
  1094. bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1095. {
  1096. bfa_trc(lps->bfa, lps->bfa_tag);
  1097. bfa_trc(lps->bfa, event);
  1098. switch (event) {
  1099. case BFA_LPS_SM_RESUME:
  1100. bfa_sm_set_state(lps, bfa_lps_sm_login);
  1101. bfa_lps_send_login(lps);
  1102. break;
  1103. case BFA_LPS_SM_OFFLINE:
  1104. case BFA_LPS_SM_DELETE:
  1105. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1106. bfa_reqq_wcancel(&lps->wqe);
  1107. break;
  1108. case BFA_LPS_SM_RX_CVL:
  1109. /*
  1110. * Login was not even sent out; so when getting out
  1111. * of this state, it will appear like a login retry
  1112. * after Clear virtual link
  1113. */
  1114. break;
  1115. default:
  1116. bfa_sm_fault(lps->bfa, event);
  1117. }
  1118. }
  1119. /*
  1120. * login complete
  1121. */
  1122. static void
  1123. bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1124. {
  1125. bfa_trc(lps->bfa, lps->bfa_tag);
  1126. bfa_trc(lps->bfa, event);
  1127. switch (event) {
  1128. case BFA_LPS_SM_LOGOUT:
  1129. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1130. bfa_sm_set_state(lps, bfa_lps_sm_logowait);
  1131. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1132. } else {
  1133. bfa_sm_set_state(lps, bfa_lps_sm_logout);
  1134. bfa_lps_send_logout(lps);
  1135. }
  1136. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1137. BFA_PL_EID_LOGO, 0, "Logout");
  1138. break;
  1139. case BFA_LPS_SM_RX_CVL:
  1140. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1141. /* Let the vport module know about this event */
  1142. bfa_lps_cvl_event(lps);
  1143. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1144. BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
  1145. break;
  1146. case BFA_LPS_SM_SET_N2N_PID:
  1147. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1148. bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
  1149. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1150. } else
  1151. bfa_lps_send_set_n2n_pid(lps);
  1152. break;
  1153. case BFA_LPS_SM_OFFLINE:
  1154. case BFA_LPS_SM_DELETE:
  1155. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1156. break;
  1157. default:
  1158. bfa_sm_fault(lps->bfa, event);
  1159. }
  1160. }
  1161. /*
  1162. * login complete
  1163. */
  1164. static void
  1165. bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1166. {
  1167. bfa_trc(lps->bfa, lps->bfa_tag);
  1168. bfa_trc(lps->bfa, event);
  1169. switch (event) {
  1170. case BFA_LPS_SM_RESUME:
  1171. bfa_sm_set_state(lps, bfa_lps_sm_online);
  1172. bfa_lps_send_set_n2n_pid(lps);
  1173. break;
  1174. case BFA_LPS_SM_LOGOUT:
  1175. bfa_sm_set_state(lps, bfa_lps_sm_logowait);
  1176. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1177. BFA_PL_EID_LOGO, 0, "Logout");
  1178. break;
  1179. case BFA_LPS_SM_RX_CVL:
  1180. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1181. bfa_reqq_wcancel(&lps->wqe);
  1182. /* Let the vport module know about this event */
  1183. bfa_lps_cvl_event(lps);
  1184. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1185. BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
  1186. break;
  1187. case BFA_LPS_SM_OFFLINE:
  1188. case BFA_LPS_SM_DELETE:
  1189. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1190. bfa_reqq_wcancel(&lps->wqe);
  1191. break;
  1192. default:
  1193. bfa_sm_fault(lps->bfa, event);
  1194. }
  1195. }
  1196. /*
  1197. * logout in progress - awaiting firmware response
  1198. */
  1199. static void
  1200. bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1201. {
  1202. bfa_trc(lps->bfa, lps->bfa_tag);
  1203. bfa_trc(lps->bfa, event);
  1204. switch (event) {
  1205. case BFA_LPS_SM_FWRSP:
  1206. case BFA_LPS_SM_OFFLINE:
  1207. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1208. bfa_lps_logout_comp(lps);
  1209. break;
  1210. case BFA_LPS_SM_DELETE:
  1211. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1212. break;
  1213. default:
  1214. bfa_sm_fault(lps->bfa, event);
  1215. }
  1216. }
  1217. /*
  1218. * logout pending -- awaiting space in request queue
  1219. */
  1220. static void
  1221. bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1222. {
  1223. bfa_trc(lps->bfa, lps->bfa_tag);
  1224. bfa_trc(lps->bfa, event);
  1225. switch (event) {
  1226. case BFA_LPS_SM_RESUME:
  1227. bfa_sm_set_state(lps, bfa_lps_sm_logout);
  1228. bfa_lps_send_logout(lps);
  1229. break;
  1230. case BFA_LPS_SM_OFFLINE:
  1231. case BFA_LPS_SM_DELETE:
  1232. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1233. bfa_reqq_wcancel(&lps->wqe);
  1234. break;
  1235. default:
  1236. bfa_sm_fault(lps->bfa, event);
  1237. }
  1238. }
  1239. /*
  1240. * lps_pvt BFA LPS private functions
  1241. */
  1242. /*
  1243. * return memory requirement
  1244. */
  1245. void
  1246. bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  1247. struct bfa_s *bfa)
  1248. {
  1249. struct bfa_mem_kva_s *lps_kva = BFA_MEM_LPS_KVA(bfa);
  1250. if (cfg->drvcfg.min_cfg)
  1251. bfa_mem_kva_setup(minfo, lps_kva,
  1252. sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS);
  1253. else
  1254. bfa_mem_kva_setup(minfo, lps_kva,
  1255. sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS);
  1256. }
  1257. /*
  1258. * bfa module attach at initialization time
  1259. */
  1260. void
  1261. bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  1262. struct bfa_pcidev_s *pcidev)
  1263. {
  1264. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1265. struct bfa_lps_s *lps;
  1266. int i;
  1267. mod->num_lps = BFA_LPS_MAX_LPORTS;
  1268. if (cfg->drvcfg.min_cfg)
  1269. mod->num_lps = BFA_LPS_MIN_LPORTS;
  1270. else
  1271. mod->num_lps = BFA_LPS_MAX_LPORTS;
  1272. mod->lps_arr = lps = (struct bfa_lps_s *) bfa_mem_kva_curp(mod);
  1273. bfa_mem_kva_curp(mod) += mod->num_lps * sizeof(struct bfa_lps_s);
  1274. INIT_LIST_HEAD(&mod->lps_free_q);
  1275. INIT_LIST_HEAD(&mod->lps_active_q);
  1276. INIT_LIST_HEAD(&mod->lps_login_q);
  1277. for (i = 0; i < mod->num_lps; i++, lps++) {
  1278. lps->bfa = bfa;
  1279. lps->bfa_tag = (u8) i;
  1280. lps->reqq = BFA_REQQ_LPS;
  1281. bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
  1282. list_add_tail(&lps->qe, &mod->lps_free_q);
  1283. }
  1284. }
  1285. /*
  1286. * IOC in disabled state -- consider all lps offline
  1287. */
  1288. void
  1289. bfa_lps_iocdisable(struct bfa_s *bfa)
  1290. {
  1291. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1292. struct bfa_lps_s *lps;
  1293. struct list_head *qe, *qen;
  1294. list_for_each_safe(qe, qen, &mod->lps_active_q) {
  1295. lps = (struct bfa_lps_s *) qe;
  1296. bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
  1297. }
  1298. list_for_each_safe(qe, qen, &mod->lps_login_q) {
  1299. lps = (struct bfa_lps_s *) qe;
  1300. bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
  1301. }
  1302. list_splice_tail_init(&mod->lps_login_q, &mod->lps_active_q);
  1303. }
  1304. /*
  1305. * Firmware login response
  1306. */
  1307. static void
  1308. bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
  1309. {
  1310. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1311. struct bfa_lps_s *lps;
  1312. WARN_ON(rsp->bfa_tag >= mod->num_lps);
  1313. lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
  1314. lps->status = rsp->status;
  1315. switch (rsp->status) {
  1316. case BFA_STATUS_OK:
  1317. lps->fw_tag = rsp->fw_tag;
  1318. lps->fport = rsp->f_port;
  1319. if (lps->fport)
  1320. lps->lp_pid = rsp->lp_pid;
  1321. lps->npiv_en = rsp->npiv_en;
  1322. lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
  1323. lps->pr_pwwn = rsp->port_name;
  1324. lps->pr_nwwn = rsp->node_name;
  1325. lps->auth_req = rsp->auth_req;
  1326. lps->lp_mac = rsp->lp_mac;
  1327. lps->brcd_switch = rsp->brcd_switch;
  1328. lps->fcf_mac = rsp->fcf_mac;
  1329. break;
  1330. case BFA_STATUS_FABRIC_RJT:
  1331. lps->lsrjt_rsn = rsp->lsrjt_rsn;
  1332. lps->lsrjt_expl = rsp->lsrjt_expl;
  1333. break;
  1334. case BFA_STATUS_EPROTOCOL:
  1335. lps->ext_status = rsp->ext_status;
  1336. break;
  1337. case BFA_STATUS_VPORT_MAX:
  1338. if (rsp->ext_status)
  1339. bfa_lps_no_res(lps, rsp->ext_status);
  1340. break;
  1341. default:
  1342. /* Nothing to do with other status */
  1343. break;
  1344. }
  1345. list_del(&lps->qe);
  1346. list_add_tail(&lps->qe, &mod->lps_active_q);
  1347. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1348. }
  1349. static void
  1350. bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count)
  1351. {
  1352. struct bfa_s *bfa = first_lps->bfa;
  1353. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1354. struct list_head *qe, *qe_next;
  1355. struct bfa_lps_s *lps;
  1356. bfa_trc(bfa, count);
  1357. qe = bfa_q_next(first_lps);
  1358. while (count && qe) {
  1359. qe_next = bfa_q_next(qe);
  1360. lps = (struct bfa_lps_s *)qe;
  1361. bfa_trc(bfa, lps->bfa_tag);
  1362. lps->status = first_lps->status;
  1363. list_del(&lps->qe);
  1364. list_add_tail(&lps->qe, &mod->lps_active_q);
  1365. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1366. qe = qe_next;
  1367. count--;
  1368. }
  1369. }
  1370. /*
  1371. * Firmware logout response
  1372. */
  1373. static void
  1374. bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
  1375. {
  1376. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1377. struct bfa_lps_s *lps;
  1378. WARN_ON(rsp->bfa_tag >= mod->num_lps);
  1379. lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
  1380. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1381. }
  1382. /*
  1383. * Firmware received a Clear virtual link request (for FCoE)
  1384. */
  1385. static void
  1386. bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
  1387. {
  1388. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1389. struct bfa_lps_s *lps;
  1390. lps = BFA_LPS_FROM_TAG(mod, cvl->bfa_tag);
  1391. bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
  1392. }
  1393. /*
  1394. * Space is available in request queue, resume queueing request to firmware.
  1395. */
  1396. static void
  1397. bfa_lps_reqq_resume(void *lps_arg)
  1398. {
  1399. struct bfa_lps_s *lps = lps_arg;
  1400. bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
  1401. }
  1402. /*
  1403. * lps is freed -- triggered by vport delete
  1404. */
  1405. static void
  1406. bfa_lps_free(struct bfa_lps_s *lps)
  1407. {
  1408. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
  1409. lps->lp_pid = 0;
  1410. list_del(&lps->qe);
  1411. list_add_tail(&lps->qe, &mod->lps_free_q);
  1412. }
  1413. /*
  1414. * send login request to firmware
  1415. */
  1416. static void
  1417. bfa_lps_send_login(struct bfa_lps_s *lps)
  1418. {
  1419. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
  1420. struct bfi_lps_login_req_s *m;
  1421. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1422. WARN_ON(!m);
  1423. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
  1424. bfa_fn_lpu(lps->bfa));
  1425. m->bfa_tag = lps->bfa_tag;
  1426. m->alpa = lps->alpa;
  1427. m->pdu_size = cpu_to_be16(lps->pdusz);
  1428. m->pwwn = lps->pwwn;
  1429. m->nwwn = lps->nwwn;
  1430. m->fdisc = lps->fdisc;
  1431. m->auth_en = lps->auth_en;
  1432. bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
  1433. list_del(&lps->qe);
  1434. list_add_tail(&lps->qe, &mod->lps_login_q);
  1435. }
  1436. /*
  1437. * send logout request to firmware
  1438. */
  1439. static void
  1440. bfa_lps_send_logout(struct bfa_lps_s *lps)
  1441. {
  1442. struct bfi_lps_logout_req_s *m;
  1443. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1444. WARN_ON(!m);
  1445. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
  1446. bfa_fn_lpu(lps->bfa));
  1447. m->fw_tag = lps->fw_tag;
  1448. m->port_name = lps->pwwn;
  1449. bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
  1450. }
  1451. /*
  1452. * send n2n pid set request to firmware
  1453. */
  1454. static void
  1455. bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
  1456. {
  1457. struct bfi_lps_n2n_pid_req_s *m;
  1458. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1459. WARN_ON(!m);
  1460. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
  1461. bfa_fn_lpu(lps->bfa));
  1462. m->fw_tag = lps->fw_tag;
  1463. m->lp_pid = lps->lp_pid;
  1464. bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
  1465. }
  1466. /*
  1467. * Indirect login completion handler for non-fcs
  1468. */
  1469. static void
  1470. bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
  1471. {
  1472. struct bfa_lps_s *lps = arg;
  1473. if (!complete)
  1474. return;
  1475. if (lps->fdisc)
  1476. bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1477. else
  1478. bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1479. }
  1480. /*
  1481. * Login completion handler -- direct call for fcs, queue for others
  1482. */
  1483. static void
  1484. bfa_lps_login_comp(struct bfa_lps_s *lps)
  1485. {
  1486. if (!lps->bfa->fcs) {
  1487. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
  1488. lps);
  1489. return;
  1490. }
  1491. if (lps->fdisc)
  1492. bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1493. else
  1494. bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1495. }
  1496. /*
  1497. * Indirect logout completion handler for non-fcs
  1498. */
  1499. static void
  1500. bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
  1501. {
  1502. struct bfa_lps_s *lps = arg;
  1503. if (!complete)
  1504. return;
  1505. if (lps->fdisc)
  1506. bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
  1507. else
  1508. bfa_cb_lps_flogo_comp(lps->bfa->bfad, lps->uarg);
  1509. }
  1510. /*
  1511. * Logout completion handler -- direct call for fcs, queue for others
  1512. */
  1513. static void
  1514. bfa_lps_logout_comp(struct bfa_lps_s *lps)
  1515. {
  1516. if (!lps->bfa->fcs) {
  1517. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
  1518. lps);
  1519. return;
  1520. }
  1521. if (lps->fdisc)
  1522. bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
  1523. }
  1524. /*
  1525. * Clear virtual link completion handler for non-fcs
  1526. */
  1527. static void
  1528. bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
  1529. {
  1530. struct bfa_lps_s *lps = arg;
  1531. if (!complete)
  1532. return;
  1533. /* Clear virtual link to base port will result in link down */
  1534. if (lps->fdisc)
  1535. bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
  1536. }
  1537. /*
  1538. * Received Clear virtual link event --direct call for fcs,
  1539. * queue for others
  1540. */
  1541. static void
  1542. bfa_lps_cvl_event(struct bfa_lps_s *lps)
  1543. {
  1544. if (!lps->bfa->fcs) {
  1545. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
  1546. lps);
  1547. return;
  1548. }
  1549. /* Clear virtual link to base port will result in link down */
  1550. if (lps->fdisc)
  1551. bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
  1552. }
  1553. /*
  1554. * lps_public BFA LPS public functions
  1555. */
  1556. u32
  1557. bfa_lps_get_max_vport(struct bfa_s *bfa)
  1558. {
  1559. if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
  1560. return BFA_LPS_MAX_VPORTS_SUPP_CT;
  1561. else
  1562. return BFA_LPS_MAX_VPORTS_SUPP_CB;
  1563. }
  1564. /*
  1565. * Allocate a lport srvice tag.
  1566. */
  1567. struct bfa_lps_s *
  1568. bfa_lps_alloc(struct bfa_s *bfa)
  1569. {
  1570. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1571. struct bfa_lps_s *lps = NULL;
  1572. bfa_q_deq(&mod->lps_free_q, &lps);
  1573. if (lps == NULL)
  1574. return NULL;
  1575. list_add_tail(&lps->qe, &mod->lps_active_q);
  1576. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1577. return lps;
  1578. }
  1579. /*
  1580. * Free lport service tag. This can be called anytime after an alloc.
  1581. * No need to wait for any pending login/logout completions.
  1582. */
  1583. void
  1584. bfa_lps_delete(struct bfa_lps_s *lps)
  1585. {
  1586. bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
  1587. }
  1588. /*
  1589. * Initiate a lport login.
  1590. */
  1591. void
  1592. bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
  1593. wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en)
  1594. {
  1595. lps->uarg = uarg;
  1596. lps->alpa = alpa;
  1597. lps->pdusz = pdusz;
  1598. lps->pwwn = pwwn;
  1599. lps->nwwn = nwwn;
  1600. lps->fdisc = BFA_FALSE;
  1601. lps->auth_en = auth_en;
  1602. bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
  1603. }
  1604. /*
  1605. * Initiate a lport fdisc login.
  1606. */
  1607. void
  1608. bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
  1609. wwn_t nwwn)
  1610. {
  1611. lps->uarg = uarg;
  1612. lps->alpa = 0;
  1613. lps->pdusz = pdusz;
  1614. lps->pwwn = pwwn;
  1615. lps->nwwn = nwwn;
  1616. lps->fdisc = BFA_TRUE;
  1617. lps->auth_en = BFA_FALSE;
  1618. bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
  1619. }
  1620. /*
  1621. * Initiate a lport FDSIC logout.
  1622. */
  1623. void
  1624. bfa_lps_fdisclogo(struct bfa_lps_s *lps)
  1625. {
  1626. bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
  1627. }
  1628. u8
  1629. bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag)
  1630. {
  1631. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1632. return BFA_LPS_FROM_TAG(mod, lp_tag)->fw_tag;
  1633. }
  1634. /*
  1635. * Return lport services tag given the pid
  1636. */
  1637. u8
  1638. bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
  1639. {
  1640. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1641. struct bfa_lps_s *lps;
  1642. int i;
  1643. for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
  1644. if (lps->lp_pid == pid)
  1645. return lps->bfa_tag;
  1646. }
  1647. /* Return base port tag anyway */
  1648. return 0;
  1649. }
  1650. /*
  1651. * return port id assigned to the base lport
  1652. */
  1653. u32
  1654. bfa_lps_get_base_pid(struct bfa_s *bfa)
  1655. {
  1656. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1657. return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
  1658. }
  1659. /*
  1660. * Set PID in case of n2n (which is assigned during PLOGI)
  1661. */
  1662. void
  1663. bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
  1664. {
  1665. bfa_trc(lps->bfa, lps->bfa_tag);
  1666. bfa_trc(lps->bfa, n2n_pid);
  1667. lps->lp_pid = n2n_pid;
  1668. bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
  1669. }
  1670. /*
  1671. * LPS firmware message class handler.
  1672. */
  1673. void
  1674. bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
  1675. {
  1676. union bfi_lps_i2h_msg_u msg;
  1677. bfa_trc(bfa, m->mhdr.msg_id);
  1678. msg.msg = m;
  1679. switch (m->mhdr.msg_id) {
  1680. case BFI_LPS_I2H_LOGIN_RSP:
  1681. bfa_lps_login_rsp(bfa, msg.login_rsp);
  1682. break;
  1683. case BFI_LPS_I2H_LOGOUT_RSP:
  1684. bfa_lps_logout_rsp(bfa, msg.logout_rsp);
  1685. break;
  1686. case BFI_LPS_I2H_CVL_EVENT:
  1687. bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
  1688. break;
  1689. default:
  1690. bfa_trc(bfa, m->mhdr.msg_id);
  1691. WARN_ON(1);
  1692. }
  1693. }
  1694. static void
  1695. bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event)
  1696. {
  1697. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1698. struct bfa_aen_entry_s *aen_entry;
  1699. bfad_get_aen_entry(bfad, aen_entry);
  1700. if (!aen_entry)
  1701. return;
  1702. aen_entry->aen_data.port.ioc_type = bfa_get_type(fcport->bfa);
  1703. aen_entry->aen_data.port.pwwn = fcport->pwwn;
  1704. /* Send the AEN notification */
  1705. bfad_im_post_vendor_event(aen_entry, bfad, ++fcport->bfa->bfa_aen_seq,
  1706. BFA_AEN_CAT_PORT, event);
  1707. }
  1708. /*
  1709. * FC PORT state machine functions
  1710. */
  1711. static void
  1712. bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
  1713. enum bfa_fcport_sm_event event)
  1714. {
  1715. bfa_trc(fcport->bfa, event);
  1716. switch (event) {
  1717. case BFA_FCPORT_SM_START:
  1718. /*
  1719. * Start event after IOC is configured and BFA is started.
  1720. */
  1721. fcport->use_flash_cfg = BFA_TRUE;
  1722. if (bfa_fcport_send_enable(fcport)) {
  1723. bfa_trc(fcport->bfa, BFA_TRUE);
  1724. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1725. } else {
  1726. bfa_trc(fcport->bfa, BFA_FALSE);
  1727. bfa_sm_set_state(fcport,
  1728. bfa_fcport_sm_enabling_qwait);
  1729. }
  1730. break;
  1731. case BFA_FCPORT_SM_ENABLE:
  1732. /*
  1733. * Port is persistently configured to be in enabled state. Do
  1734. * not change state. Port enabling is done when START event is
  1735. * received.
  1736. */
  1737. break;
  1738. case BFA_FCPORT_SM_DISABLE:
  1739. /*
  1740. * If a port is persistently configured to be disabled, the
  1741. * first event will a port disable request.
  1742. */
  1743. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  1744. break;
  1745. case BFA_FCPORT_SM_HWFAIL:
  1746. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1747. break;
  1748. default:
  1749. bfa_sm_fault(fcport->bfa, event);
  1750. }
  1751. }
  1752. static void
  1753. bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
  1754. enum bfa_fcport_sm_event event)
  1755. {
  1756. char pwwn_buf[BFA_STRING_32];
  1757. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1758. bfa_trc(fcport->bfa, event);
  1759. switch (event) {
  1760. case BFA_FCPORT_SM_QRESUME:
  1761. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1762. bfa_fcport_send_enable(fcport);
  1763. break;
  1764. case BFA_FCPORT_SM_STOP:
  1765. bfa_reqq_wcancel(&fcport->reqq_wait);
  1766. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1767. break;
  1768. case BFA_FCPORT_SM_ENABLE:
  1769. /*
  1770. * Already enable is in progress.
  1771. */
  1772. break;
  1773. case BFA_FCPORT_SM_DISABLE:
  1774. /*
  1775. * Just send disable request to firmware when room becomes
  1776. * available in request queue.
  1777. */
  1778. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  1779. bfa_reqq_wcancel(&fcport->reqq_wait);
  1780. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1781. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1782. wwn2str(pwwn_buf, fcport->pwwn);
  1783. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1784. "Base port disabled: WWN = %s\n", pwwn_buf);
  1785. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  1786. break;
  1787. case BFA_FCPORT_SM_LINKUP:
  1788. case BFA_FCPORT_SM_LINKDOWN:
  1789. /*
  1790. * Possible to get link events when doing back-to-back
  1791. * enable/disables.
  1792. */
  1793. break;
  1794. case BFA_FCPORT_SM_HWFAIL:
  1795. bfa_reqq_wcancel(&fcport->reqq_wait);
  1796. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1797. break;
  1798. case BFA_FCPORT_SM_FAA_MISCONFIG:
  1799. bfa_fcport_reset_linkinfo(fcport);
  1800. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  1801. bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
  1802. break;
  1803. default:
  1804. bfa_sm_fault(fcport->bfa, event);
  1805. }
  1806. }
  1807. static void
  1808. bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
  1809. enum bfa_fcport_sm_event event)
  1810. {
  1811. char pwwn_buf[BFA_STRING_32];
  1812. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1813. bfa_trc(fcport->bfa, event);
  1814. switch (event) {
  1815. case BFA_FCPORT_SM_FWRSP:
  1816. case BFA_FCPORT_SM_LINKDOWN:
  1817. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  1818. break;
  1819. case BFA_FCPORT_SM_LINKUP:
  1820. bfa_fcport_update_linkinfo(fcport);
  1821. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  1822. WARN_ON(!fcport->event_cbfn);
  1823. bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
  1824. break;
  1825. case BFA_FCPORT_SM_ENABLE:
  1826. /*
  1827. * Already being enabled.
  1828. */
  1829. break;
  1830. case BFA_FCPORT_SM_DISABLE:
  1831. if (bfa_fcport_send_disable(fcport))
  1832. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1833. else
  1834. bfa_sm_set_state(fcport,
  1835. bfa_fcport_sm_disabling_qwait);
  1836. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1837. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1838. wwn2str(pwwn_buf, fcport->pwwn);
  1839. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1840. "Base port disabled: WWN = %s\n", pwwn_buf);
  1841. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  1842. break;
  1843. case BFA_FCPORT_SM_STOP:
  1844. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1845. break;
  1846. case BFA_FCPORT_SM_HWFAIL:
  1847. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1848. break;
  1849. case BFA_FCPORT_SM_FAA_MISCONFIG:
  1850. bfa_fcport_reset_linkinfo(fcport);
  1851. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  1852. bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
  1853. break;
  1854. default:
  1855. bfa_sm_fault(fcport->bfa, event);
  1856. }
  1857. }
  1858. static void
  1859. bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
  1860. enum bfa_fcport_sm_event event)
  1861. {
  1862. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  1863. char pwwn_buf[BFA_STRING_32];
  1864. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1865. bfa_trc(fcport->bfa, event);
  1866. switch (event) {
  1867. case BFA_FCPORT_SM_LINKUP:
  1868. bfa_fcport_update_linkinfo(fcport);
  1869. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  1870. WARN_ON(!fcport->event_cbfn);
  1871. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1872. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
  1873. if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
  1874. bfa_trc(fcport->bfa,
  1875. pevent->link_state.attr.vc_fcf.fcf.fipenabled);
  1876. bfa_trc(fcport->bfa,
  1877. pevent->link_state.attr.vc_fcf.fcf.fipfailed);
  1878. if (pevent->link_state.attr.vc_fcf.fcf.fipfailed)
  1879. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1880. BFA_PL_EID_FIP_FCF_DISC, 0,
  1881. "FIP FCF Discovery Failed");
  1882. else
  1883. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1884. BFA_PL_EID_FIP_FCF_DISC, 0,
  1885. "FIP FCF Discovered");
  1886. }
  1887. bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
  1888. wwn2str(pwwn_buf, fcport->pwwn);
  1889. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1890. "Base port online: WWN = %s\n", pwwn_buf);
  1891. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE);
  1892. /* If QoS is enabled and it is not online, send AEN */
  1893. if (fcport->cfg.qos_enabled &&
  1894. fcport->qos_attr.state != BFA_QOS_ONLINE)
  1895. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_QOS_NEG);
  1896. break;
  1897. case BFA_FCPORT_SM_LINKDOWN:
  1898. /*
  1899. * Possible to get link down event.
  1900. */
  1901. break;
  1902. case BFA_FCPORT_SM_ENABLE:
  1903. /*
  1904. * Already enabled.
  1905. */
  1906. break;
  1907. case BFA_FCPORT_SM_DISABLE:
  1908. if (bfa_fcport_send_disable(fcport))
  1909. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1910. else
  1911. bfa_sm_set_state(fcport,
  1912. bfa_fcport_sm_disabling_qwait);
  1913. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1914. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1915. wwn2str(pwwn_buf, fcport->pwwn);
  1916. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1917. "Base port disabled: WWN = %s\n", pwwn_buf);
  1918. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  1919. break;
  1920. case BFA_FCPORT_SM_STOP:
  1921. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1922. break;
  1923. case BFA_FCPORT_SM_HWFAIL:
  1924. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1925. break;
  1926. case BFA_FCPORT_SM_FAA_MISCONFIG:
  1927. bfa_fcport_reset_linkinfo(fcport);
  1928. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  1929. bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
  1930. break;
  1931. default:
  1932. bfa_sm_fault(fcport->bfa, event);
  1933. }
  1934. }
  1935. static void
  1936. bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
  1937. enum bfa_fcport_sm_event event)
  1938. {
  1939. char pwwn_buf[BFA_STRING_32];
  1940. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1941. bfa_trc(fcport->bfa, event);
  1942. switch (event) {
  1943. case BFA_FCPORT_SM_ENABLE:
  1944. /*
  1945. * Already enabled.
  1946. */
  1947. break;
  1948. case BFA_FCPORT_SM_DISABLE:
  1949. if (bfa_fcport_send_disable(fcport))
  1950. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1951. else
  1952. bfa_sm_set_state(fcport,
  1953. bfa_fcport_sm_disabling_qwait);
  1954. bfa_fcport_reset_linkinfo(fcport);
  1955. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1956. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1957. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1958. wwn2str(pwwn_buf, fcport->pwwn);
  1959. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1960. "Base port offline: WWN = %s\n", pwwn_buf);
  1961. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  1962. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1963. "Base port disabled: WWN = %s\n", pwwn_buf);
  1964. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  1965. break;
  1966. case BFA_FCPORT_SM_LINKDOWN:
  1967. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  1968. bfa_fcport_reset_linkinfo(fcport);
  1969. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1970. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1971. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
  1972. wwn2str(pwwn_buf, fcport->pwwn);
  1973. if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
  1974. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1975. "Base port offline: WWN = %s\n", pwwn_buf);
  1976. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  1977. } else {
  1978. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  1979. "Base port (WWN = %s) "
  1980. "lost fabric connectivity\n", pwwn_buf);
  1981. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  1982. }
  1983. break;
  1984. case BFA_FCPORT_SM_STOP:
  1985. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1986. bfa_fcport_reset_linkinfo(fcport);
  1987. wwn2str(pwwn_buf, fcport->pwwn);
  1988. if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
  1989. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1990. "Base port offline: WWN = %s\n", pwwn_buf);
  1991. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  1992. } else {
  1993. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  1994. "Base port (WWN = %s) "
  1995. "lost fabric connectivity\n", pwwn_buf);
  1996. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  1997. }
  1998. break;
  1999. case BFA_FCPORT_SM_HWFAIL:
  2000. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  2001. bfa_fcport_reset_linkinfo(fcport);
  2002. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  2003. wwn2str(pwwn_buf, fcport->pwwn);
  2004. if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
  2005. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2006. "Base port offline: WWN = %s\n", pwwn_buf);
  2007. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  2008. } else {
  2009. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  2010. "Base port (WWN = %s) "
  2011. "lost fabric connectivity\n", pwwn_buf);
  2012. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  2013. }
  2014. break;
  2015. case BFA_FCPORT_SM_FAA_MISCONFIG:
  2016. bfa_fcport_reset_linkinfo(fcport);
  2017. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  2018. bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
  2019. break;
  2020. default:
  2021. bfa_sm_fault(fcport->bfa, event);
  2022. }
  2023. }
  2024. static void
  2025. bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
  2026. enum bfa_fcport_sm_event event)
  2027. {
  2028. bfa_trc(fcport->bfa, event);
  2029. switch (event) {
  2030. case BFA_FCPORT_SM_QRESUME:
  2031. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  2032. bfa_fcport_send_disable(fcport);
  2033. break;
  2034. case BFA_FCPORT_SM_STOP:
  2035. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2036. bfa_reqq_wcancel(&fcport->reqq_wait);
  2037. break;
  2038. case BFA_FCPORT_SM_ENABLE:
  2039. bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
  2040. break;
  2041. case BFA_FCPORT_SM_DISABLE:
  2042. /*
  2043. * Already being disabled.
  2044. */
  2045. break;
  2046. case BFA_FCPORT_SM_LINKUP:
  2047. case BFA_FCPORT_SM_LINKDOWN:
  2048. /*
  2049. * Possible to get link events when doing back-to-back
  2050. * enable/disables.
  2051. */
  2052. break;
  2053. case BFA_FCPORT_SM_HWFAIL:
  2054. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2055. bfa_reqq_wcancel(&fcport->reqq_wait);
  2056. break;
  2057. case BFA_FCPORT_SM_FAA_MISCONFIG:
  2058. bfa_fcport_reset_linkinfo(fcport);
  2059. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  2060. bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig);
  2061. break;
  2062. default:
  2063. bfa_sm_fault(fcport->bfa, event);
  2064. }
  2065. }
  2066. static void
  2067. bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
  2068. enum bfa_fcport_sm_event event)
  2069. {
  2070. bfa_trc(fcport->bfa, event);
  2071. switch (event) {
  2072. case BFA_FCPORT_SM_QRESUME:
  2073. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  2074. bfa_fcport_send_disable(fcport);
  2075. if (bfa_fcport_send_enable(fcport))
  2076. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2077. else
  2078. bfa_sm_set_state(fcport,
  2079. bfa_fcport_sm_enabling_qwait);
  2080. break;
  2081. case BFA_FCPORT_SM_STOP:
  2082. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2083. bfa_reqq_wcancel(&fcport->reqq_wait);
  2084. break;
  2085. case BFA_FCPORT_SM_ENABLE:
  2086. break;
  2087. case BFA_FCPORT_SM_DISABLE:
  2088. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
  2089. break;
  2090. case BFA_FCPORT_SM_LINKUP:
  2091. case BFA_FCPORT_SM_LINKDOWN:
  2092. /*
  2093. * Possible to get link events when doing back-to-back
  2094. * enable/disables.
  2095. */
  2096. break;
  2097. case BFA_FCPORT_SM_HWFAIL:
  2098. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2099. bfa_reqq_wcancel(&fcport->reqq_wait);
  2100. break;
  2101. default:
  2102. bfa_sm_fault(fcport->bfa, event);
  2103. }
  2104. }
  2105. static void
  2106. bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
  2107. enum bfa_fcport_sm_event event)
  2108. {
  2109. char pwwn_buf[BFA_STRING_32];
  2110. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  2111. bfa_trc(fcport->bfa, event);
  2112. switch (event) {
  2113. case BFA_FCPORT_SM_FWRSP:
  2114. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2115. break;
  2116. case BFA_FCPORT_SM_DISABLE:
  2117. /*
  2118. * Already being disabled.
  2119. */
  2120. break;
  2121. case BFA_FCPORT_SM_ENABLE:
  2122. if (bfa_fcport_send_enable(fcport))
  2123. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2124. else
  2125. bfa_sm_set_state(fcport,
  2126. bfa_fcport_sm_enabling_qwait);
  2127. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2128. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  2129. wwn2str(pwwn_buf, fcport->pwwn);
  2130. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2131. "Base port enabled: WWN = %s\n", pwwn_buf);
  2132. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
  2133. break;
  2134. case BFA_FCPORT_SM_STOP:
  2135. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2136. break;
  2137. case BFA_FCPORT_SM_LINKUP:
  2138. case BFA_FCPORT_SM_LINKDOWN:
  2139. /*
  2140. * Possible to get link events when doing back-to-back
  2141. * enable/disables.
  2142. */
  2143. break;
  2144. case BFA_FCPORT_SM_HWFAIL:
  2145. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2146. break;
  2147. default:
  2148. bfa_sm_fault(fcport->bfa, event);
  2149. }
  2150. }
  2151. static void
  2152. bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
  2153. enum bfa_fcport_sm_event event)
  2154. {
  2155. char pwwn_buf[BFA_STRING_32];
  2156. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  2157. bfa_trc(fcport->bfa, event);
  2158. switch (event) {
  2159. case BFA_FCPORT_SM_START:
  2160. /*
  2161. * Ignore start event for a port that is disabled.
  2162. */
  2163. break;
  2164. case BFA_FCPORT_SM_STOP:
  2165. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2166. break;
  2167. case BFA_FCPORT_SM_ENABLE:
  2168. if (bfa_fcport_send_enable(fcport))
  2169. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2170. else
  2171. bfa_sm_set_state(fcport,
  2172. bfa_fcport_sm_enabling_qwait);
  2173. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2174. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  2175. wwn2str(pwwn_buf, fcport->pwwn);
  2176. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2177. "Base port enabled: WWN = %s\n", pwwn_buf);
  2178. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
  2179. break;
  2180. case BFA_FCPORT_SM_DISABLE:
  2181. /*
  2182. * Already disabled.
  2183. */
  2184. break;
  2185. case BFA_FCPORT_SM_HWFAIL:
  2186. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2187. break;
  2188. case BFA_FCPORT_SM_DPORTENABLE:
  2189. bfa_sm_set_state(fcport, bfa_fcport_sm_dport);
  2190. break;
  2191. case BFA_FCPORT_SM_DDPORTENABLE:
  2192. bfa_sm_set_state(fcport, bfa_fcport_sm_ddport);
  2193. break;
  2194. default:
  2195. bfa_sm_fault(fcport->bfa, event);
  2196. }
  2197. }
  2198. static void
  2199. bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
  2200. enum bfa_fcport_sm_event event)
  2201. {
  2202. bfa_trc(fcport->bfa, event);
  2203. switch (event) {
  2204. case BFA_FCPORT_SM_START:
  2205. if (bfa_fcport_send_enable(fcport))
  2206. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2207. else
  2208. bfa_sm_set_state(fcport,
  2209. bfa_fcport_sm_enabling_qwait);
  2210. break;
  2211. default:
  2212. /*
  2213. * Ignore all other events.
  2214. */
  2215. ;
  2216. }
  2217. }
  2218. /*
  2219. * Port is enabled. IOC is down/failed.
  2220. */
  2221. static void
  2222. bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
  2223. enum bfa_fcport_sm_event event)
  2224. {
  2225. bfa_trc(fcport->bfa, event);
  2226. switch (event) {
  2227. case BFA_FCPORT_SM_START:
  2228. if (bfa_fcport_send_enable(fcport))
  2229. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2230. else
  2231. bfa_sm_set_state(fcport,
  2232. bfa_fcport_sm_enabling_qwait);
  2233. break;
  2234. default:
  2235. /*
  2236. * Ignore all events.
  2237. */
  2238. ;
  2239. }
  2240. }
  2241. /*
  2242. * Port is disabled. IOC is down/failed.
  2243. */
  2244. static void
  2245. bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
  2246. enum bfa_fcport_sm_event event)
  2247. {
  2248. bfa_trc(fcport->bfa, event);
  2249. switch (event) {
  2250. case BFA_FCPORT_SM_START:
  2251. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2252. break;
  2253. case BFA_FCPORT_SM_ENABLE:
  2254. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  2255. break;
  2256. default:
  2257. /*
  2258. * Ignore all events.
  2259. */
  2260. ;
  2261. }
  2262. }
  2263. static void
  2264. bfa_fcport_sm_dport(struct bfa_fcport_s *fcport, enum bfa_fcport_sm_event event)
  2265. {
  2266. bfa_trc(fcport->bfa, event);
  2267. switch (event) {
  2268. case BFA_FCPORT_SM_DPORTENABLE:
  2269. case BFA_FCPORT_SM_DISABLE:
  2270. case BFA_FCPORT_SM_ENABLE:
  2271. case BFA_FCPORT_SM_START:
  2272. /*
  2273. * Ignore event for a port that is dport
  2274. */
  2275. break;
  2276. case BFA_FCPORT_SM_STOP:
  2277. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2278. break;
  2279. case BFA_FCPORT_SM_HWFAIL:
  2280. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2281. break;
  2282. case BFA_FCPORT_SM_DPORTDISABLE:
  2283. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2284. break;
  2285. default:
  2286. bfa_sm_fault(fcport->bfa, event);
  2287. }
  2288. }
  2289. static void
  2290. bfa_fcport_sm_ddport(struct bfa_fcport_s *fcport,
  2291. enum bfa_fcport_sm_event event)
  2292. {
  2293. bfa_trc(fcport->bfa, event);
  2294. switch (event) {
  2295. case BFA_FCPORT_SM_DISABLE:
  2296. case BFA_FCPORT_SM_DDPORTDISABLE:
  2297. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2298. break;
  2299. case BFA_FCPORT_SM_DPORTENABLE:
  2300. case BFA_FCPORT_SM_DPORTDISABLE:
  2301. case BFA_FCPORT_SM_ENABLE:
  2302. case BFA_FCPORT_SM_START:
  2303. /*
  2304. * Ignore event for a port that is ddport
  2305. */
  2306. break;
  2307. case BFA_FCPORT_SM_STOP:
  2308. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2309. break;
  2310. case BFA_FCPORT_SM_HWFAIL:
  2311. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2312. break;
  2313. default:
  2314. bfa_sm_fault(fcport->bfa, event);
  2315. }
  2316. }
  2317. static void
  2318. bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s *fcport,
  2319. enum bfa_fcport_sm_event event)
  2320. {
  2321. bfa_trc(fcport->bfa, event);
  2322. switch (event) {
  2323. case BFA_FCPORT_SM_DPORTENABLE:
  2324. case BFA_FCPORT_SM_ENABLE:
  2325. case BFA_FCPORT_SM_START:
  2326. /*
  2327. * Ignore event for a port as there is FAA misconfig
  2328. */
  2329. break;
  2330. case BFA_FCPORT_SM_DISABLE:
  2331. if (bfa_fcport_send_disable(fcport))
  2332. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  2333. else
  2334. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
  2335. bfa_fcport_reset_linkinfo(fcport);
  2336. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  2337. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2338. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  2339. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  2340. break;
  2341. case BFA_FCPORT_SM_STOP:
  2342. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2343. break;
  2344. case BFA_FCPORT_SM_HWFAIL:
  2345. bfa_fcport_reset_linkinfo(fcport);
  2346. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  2347. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  2348. break;
  2349. default:
  2350. bfa_sm_fault(fcport->bfa, event);
  2351. }
  2352. }
  2353. /*
  2354. * Link state is down
  2355. */
  2356. static void
  2357. bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
  2358. enum bfa_fcport_ln_sm_event event)
  2359. {
  2360. bfa_trc(ln->fcport->bfa, event);
  2361. switch (event) {
  2362. case BFA_FCPORT_LN_SM_LINKUP:
  2363. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  2364. bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
  2365. break;
  2366. default:
  2367. bfa_sm_fault(ln->fcport->bfa, event);
  2368. }
  2369. }
  2370. /*
  2371. * Link state is waiting for down notification
  2372. */
  2373. static void
  2374. bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
  2375. enum bfa_fcport_ln_sm_event event)
  2376. {
  2377. bfa_trc(ln->fcport->bfa, event);
  2378. switch (event) {
  2379. case BFA_FCPORT_LN_SM_LINKUP:
  2380. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  2381. break;
  2382. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2383. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  2384. break;
  2385. default:
  2386. bfa_sm_fault(ln->fcport->bfa, event);
  2387. }
  2388. }
  2389. /*
  2390. * Link state is waiting for down notification and there is a pending up
  2391. */
  2392. static void
  2393. bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
  2394. enum bfa_fcport_ln_sm_event event)
  2395. {
  2396. bfa_trc(ln->fcport->bfa, event);
  2397. switch (event) {
  2398. case BFA_FCPORT_LN_SM_LINKDOWN:
  2399. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2400. break;
  2401. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2402. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  2403. bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
  2404. break;
  2405. default:
  2406. bfa_sm_fault(ln->fcport->bfa, event);
  2407. }
  2408. }
  2409. /*
  2410. * Link state is up
  2411. */
  2412. static void
  2413. bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
  2414. enum bfa_fcport_ln_sm_event event)
  2415. {
  2416. bfa_trc(ln->fcport->bfa, event);
  2417. switch (event) {
  2418. case BFA_FCPORT_LN_SM_LINKDOWN:
  2419. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2420. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2421. break;
  2422. default:
  2423. bfa_sm_fault(ln->fcport->bfa, event);
  2424. }
  2425. }
  2426. /*
  2427. * Link state is waiting for up notification
  2428. */
  2429. static void
  2430. bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
  2431. enum bfa_fcport_ln_sm_event event)
  2432. {
  2433. bfa_trc(ln->fcport->bfa, event);
  2434. switch (event) {
  2435. case BFA_FCPORT_LN_SM_LINKDOWN:
  2436. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  2437. break;
  2438. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2439. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
  2440. break;
  2441. default:
  2442. bfa_sm_fault(ln->fcport->bfa, event);
  2443. }
  2444. }
  2445. /*
  2446. * Link state is waiting for up notification and there is a pending down
  2447. */
  2448. static void
  2449. bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
  2450. enum bfa_fcport_ln_sm_event event)
  2451. {
  2452. bfa_trc(ln->fcport->bfa, event);
  2453. switch (event) {
  2454. case BFA_FCPORT_LN_SM_LINKUP:
  2455. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
  2456. break;
  2457. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2458. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2459. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2460. break;
  2461. default:
  2462. bfa_sm_fault(ln->fcport->bfa, event);
  2463. }
  2464. }
  2465. /*
  2466. * Link state is waiting for up notification and there are pending down and up
  2467. */
  2468. static void
  2469. bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
  2470. enum bfa_fcport_ln_sm_event event)
  2471. {
  2472. bfa_trc(ln->fcport->bfa, event);
  2473. switch (event) {
  2474. case BFA_FCPORT_LN_SM_LINKDOWN:
  2475. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  2476. break;
  2477. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2478. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  2479. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2480. break;
  2481. default:
  2482. bfa_sm_fault(ln->fcport->bfa, event);
  2483. }
  2484. }
  2485. static void
  2486. __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
  2487. {
  2488. struct bfa_fcport_ln_s *ln = cbarg;
  2489. if (complete)
  2490. ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
  2491. else
  2492. bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
  2493. }
  2494. /*
  2495. * Send SCN notification to upper layers.
  2496. * trunk - false if caller is fcport to ignore fcport event in trunked mode
  2497. */
  2498. static void
  2499. bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
  2500. bfa_boolean_t trunk)
  2501. {
  2502. if (fcport->cfg.trunked && !trunk)
  2503. return;
  2504. switch (event) {
  2505. case BFA_PORT_LINKUP:
  2506. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
  2507. break;
  2508. case BFA_PORT_LINKDOWN:
  2509. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
  2510. break;
  2511. default:
  2512. WARN_ON(1);
  2513. }
  2514. }
  2515. static void
  2516. bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
  2517. {
  2518. struct bfa_fcport_s *fcport = ln->fcport;
  2519. if (fcport->bfa->fcs) {
  2520. fcport->event_cbfn(fcport->event_cbarg, event);
  2521. bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
  2522. } else {
  2523. ln->ln_event = event;
  2524. bfa_cb_queue(fcport->bfa, &ln->ln_qe,
  2525. __bfa_cb_fcport_event, ln);
  2526. }
  2527. }
  2528. #define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
  2529. BFA_CACHELINE_SZ))
  2530. void
  2531. bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  2532. struct bfa_s *bfa)
  2533. {
  2534. struct bfa_mem_dma_s *fcport_dma = BFA_MEM_FCPORT_DMA(bfa);
  2535. bfa_mem_dma_setup(minfo, fcport_dma, FCPORT_STATS_DMA_SZ);
  2536. }
  2537. static void
  2538. bfa_fcport_qresume(void *cbarg)
  2539. {
  2540. struct bfa_fcport_s *fcport = cbarg;
  2541. bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
  2542. }
  2543. static void
  2544. bfa_fcport_mem_claim(struct bfa_fcport_s *fcport)
  2545. {
  2546. struct bfa_mem_dma_s *fcport_dma = &fcport->fcport_dma;
  2547. fcport->stats_kva = bfa_mem_dma_virt(fcport_dma);
  2548. fcport->stats_pa = bfa_mem_dma_phys(fcport_dma);
  2549. fcport->stats = (union bfa_fcport_stats_u *)
  2550. bfa_mem_dma_virt(fcport_dma);
  2551. }
  2552. /*
  2553. * Memory initialization.
  2554. */
  2555. void
  2556. bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  2557. struct bfa_pcidev_s *pcidev)
  2558. {
  2559. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2560. struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
  2561. struct bfa_fcport_ln_s *ln = &fcport->ln;
  2562. fcport->bfa = bfa;
  2563. ln->fcport = fcport;
  2564. bfa_fcport_mem_claim(fcport);
  2565. bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
  2566. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  2567. /*
  2568. * initialize time stamp for stats reset
  2569. */
  2570. fcport->stats_reset_time = ktime_get_seconds();
  2571. fcport->stats_dma_ready = BFA_FALSE;
  2572. /*
  2573. * initialize and set default configuration
  2574. */
  2575. port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
  2576. port_cfg->speed = BFA_PORT_SPEED_AUTO;
  2577. port_cfg->trunked = BFA_FALSE;
  2578. port_cfg->maxfrsize = 0;
  2579. port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
  2580. port_cfg->qos_bw.high = BFA_QOS_BW_HIGH;
  2581. port_cfg->qos_bw.med = BFA_QOS_BW_MED;
  2582. port_cfg->qos_bw.low = BFA_QOS_BW_LOW;
  2583. fcport->fec_state = BFA_FEC_OFFLINE;
  2584. INIT_LIST_HEAD(&fcport->stats_pending_q);
  2585. INIT_LIST_HEAD(&fcport->statsclr_pending_q);
  2586. bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
  2587. }
  2588. void
  2589. bfa_fcport_start(struct bfa_s *bfa)
  2590. {
  2591. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
  2592. }
  2593. /*
  2594. * Called when IOC failure is detected.
  2595. */
  2596. void
  2597. bfa_fcport_iocdisable(struct bfa_s *bfa)
  2598. {
  2599. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2600. bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
  2601. bfa_trunk_iocdisable(bfa);
  2602. }
  2603. /*
  2604. * Update loop info in fcport for SCN online
  2605. */
  2606. static void
  2607. bfa_fcport_update_loop_info(struct bfa_fcport_s *fcport,
  2608. struct bfa_fcport_loop_info_s *loop_info)
  2609. {
  2610. fcport->myalpa = loop_info->myalpa;
  2611. fcport->alpabm_valid =
  2612. loop_info->alpabm_val;
  2613. memcpy(fcport->alpabm.alpa_bm,
  2614. loop_info->alpabm.alpa_bm,
  2615. sizeof(struct fc_alpabm_s));
  2616. }
  2617. static void
  2618. bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
  2619. {
  2620. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  2621. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2622. fcport->speed = pevent->link_state.speed;
  2623. fcport->topology = pevent->link_state.topology;
  2624. if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP) {
  2625. bfa_fcport_update_loop_info(fcport,
  2626. &pevent->link_state.attr.loop_info);
  2627. return;
  2628. }
  2629. /* QoS Details */
  2630. fcport->qos_attr = pevent->link_state.qos_attr;
  2631. fcport->qos_vc_attr = pevent->link_state.attr.vc_fcf.qos_vc_attr;
  2632. if (fcport->cfg.bb_cr_enabled)
  2633. fcport->bbcr_attr = pevent->link_state.attr.bbcr_attr;
  2634. fcport->fec_state = pevent->link_state.fec_state;
  2635. /*
  2636. * update trunk state if applicable
  2637. */
  2638. if (!fcport->cfg.trunked)
  2639. trunk->attr.state = BFA_TRUNK_DISABLED;
  2640. /* update FCoE specific */
  2641. fcport->fcoe_vlan =
  2642. be16_to_cpu(pevent->link_state.attr.vc_fcf.fcf.vlan);
  2643. bfa_trc(fcport->bfa, fcport->speed);
  2644. bfa_trc(fcport->bfa, fcport->topology);
  2645. }
  2646. static void
  2647. bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
  2648. {
  2649. fcport->speed = BFA_PORT_SPEED_UNKNOWN;
  2650. fcport->topology = BFA_PORT_TOPOLOGY_NONE;
  2651. fcport->fec_state = BFA_FEC_OFFLINE;
  2652. }
  2653. /*
  2654. * Send port enable message to firmware.
  2655. */
  2656. static bfa_boolean_t
  2657. bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
  2658. {
  2659. struct bfi_fcport_enable_req_s *m;
  2660. /*
  2661. * Increment message tag before queue check, so that responses to old
  2662. * requests are discarded.
  2663. */
  2664. fcport->msgtag++;
  2665. /*
  2666. * check for room in queue to send request now
  2667. */
  2668. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2669. if (!m) {
  2670. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2671. &fcport->reqq_wait);
  2672. return BFA_FALSE;
  2673. }
  2674. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
  2675. bfa_fn_lpu(fcport->bfa));
  2676. m->nwwn = fcport->nwwn;
  2677. m->pwwn = fcport->pwwn;
  2678. m->port_cfg = fcport->cfg;
  2679. m->msgtag = fcport->msgtag;
  2680. m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
  2681. m->use_flash_cfg = fcport->use_flash_cfg;
  2682. bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
  2683. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
  2684. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
  2685. /*
  2686. * queue I/O message to firmware
  2687. */
  2688. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
  2689. return BFA_TRUE;
  2690. }
  2691. /*
  2692. * Send port disable message to firmware.
  2693. */
  2694. static bfa_boolean_t
  2695. bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
  2696. {
  2697. struct bfi_fcport_req_s *m;
  2698. /*
  2699. * Increment message tag before queue check, so that responses to old
  2700. * requests are discarded.
  2701. */
  2702. fcport->msgtag++;
  2703. /*
  2704. * check for room in queue to send request now
  2705. */
  2706. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2707. if (!m) {
  2708. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2709. &fcport->reqq_wait);
  2710. return BFA_FALSE;
  2711. }
  2712. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
  2713. bfa_fn_lpu(fcport->bfa));
  2714. m->msgtag = fcport->msgtag;
  2715. /*
  2716. * queue I/O message to firmware
  2717. */
  2718. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
  2719. return BFA_TRUE;
  2720. }
  2721. static void
  2722. bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
  2723. {
  2724. fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
  2725. fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
  2726. bfa_trc(fcport->bfa, fcport->pwwn);
  2727. bfa_trc(fcport->bfa, fcport->nwwn);
  2728. }
  2729. static void
  2730. bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
  2731. struct bfa_qos_stats_s *s)
  2732. {
  2733. u32 *dip = (u32 *) d;
  2734. __be32 *sip = (__be32 *) s;
  2735. int i;
  2736. /* Now swap the 32 bit fields */
  2737. for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
  2738. dip[i] = be32_to_cpu(sip[i]);
  2739. }
  2740. static void
  2741. bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
  2742. struct bfa_fcoe_stats_s *s)
  2743. {
  2744. u32 *dip = (u32 *) d;
  2745. __be32 *sip = (__be32 *) s;
  2746. int i;
  2747. for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
  2748. i = i + 2) {
  2749. #ifdef __BIG_ENDIAN
  2750. dip[i] = be32_to_cpu(sip[i]);
  2751. dip[i + 1] = be32_to_cpu(sip[i + 1]);
  2752. #else
  2753. dip[i] = be32_to_cpu(sip[i + 1]);
  2754. dip[i + 1] = be32_to_cpu(sip[i]);
  2755. #endif
  2756. }
  2757. }
  2758. static void
  2759. __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
  2760. {
  2761. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *)cbarg;
  2762. struct bfa_cb_pending_q_s *cb;
  2763. struct list_head *qe, *qen;
  2764. union bfa_fcport_stats_u *ret;
  2765. if (complete) {
  2766. time64_t time = ktime_get_seconds();
  2767. list_for_each_safe(qe, qen, &fcport->stats_pending_q) {
  2768. bfa_q_deq(&fcport->stats_pending_q, &qe);
  2769. cb = (struct bfa_cb_pending_q_s *)qe;
  2770. if (fcport->stats_status == BFA_STATUS_OK) {
  2771. ret = (union bfa_fcport_stats_u *)cb->data;
  2772. /* Swap FC QoS or FCoE stats */
  2773. if (bfa_ioc_get_fcmode(&fcport->bfa->ioc))
  2774. bfa_fcport_qos_stats_swap(&ret->fcqos,
  2775. &fcport->stats->fcqos);
  2776. else {
  2777. bfa_fcport_fcoe_stats_swap(&ret->fcoe,
  2778. &fcport->stats->fcoe);
  2779. ret->fcoe.secs_reset =
  2780. time - fcport->stats_reset_time;
  2781. }
  2782. }
  2783. bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
  2784. fcport->stats_status);
  2785. }
  2786. fcport->stats_status = BFA_STATUS_OK;
  2787. } else {
  2788. INIT_LIST_HEAD(&fcport->stats_pending_q);
  2789. fcport->stats_status = BFA_STATUS_OK;
  2790. }
  2791. }
  2792. static void
  2793. bfa_fcport_stats_get_timeout(void *cbarg)
  2794. {
  2795. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2796. bfa_trc(fcport->bfa, fcport->stats_qfull);
  2797. if (fcport->stats_qfull) {
  2798. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  2799. fcport->stats_qfull = BFA_FALSE;
  2800. }
  2801. fcport->stats_status = BFA_STATUS_ETIMER;
  2802. __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
  2803. }
  2804. static void
  2805. bfa_fcport_send_stats_get(void *cbarg)
  2806. {
  2807. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2808. struct bfi_fcport_req_s *msg;
  2809. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2810. if (!msg) {
  2811. fcport->stats_qfull = BFA_TRUE;
  2812. bfa_reqq_winit(&fcport->stats_reqq_wait,
  2813. bfa_fcport_send_stats_get, fcport);
  2814. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2815. &fcport->stats_reqq_wait);
  2816. return;
  2817. }
  2818. fcport->stats_qfull = BFA_FALSE;
  2819. memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  2820. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
  2821. bfa_fn_lpu(fcport->bfa));
  2822. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
  2823. }
  2824. static void
  2825. __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
  2826. {
  2827. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2828. struct bfa_cb_pending_q_s *cb;
  2829. struct list_head *qe, *qen;
  2830. if (complete) {
  2831. /*
  2832. * re-initialize time stamp for stats reset
  2833. */
  2834. fcport->stats_reset_time = ktime_get_seconds();
  2835. list_for_each_safe(qe, qen, &fcport->statsclr_pending_q) {
  2836. bfa_q_deq(&fcport->statsclr_pending_q, &qe);
  2837. cb = (struct bfa_cb_pending_q_s *)qe;
  2838. bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
  2839. fcport->stats_status);
  2840. }
  2841. fcport->stats_status = BFA_STATUS_OK;
  2842. } else {
  2843. INIT_LIST_HEAD(&fcport->statsclr_pending_q);
  2844. fcport->stats_status = BFA_STATUS_OK;
  2845. }
  2846. }
  2847. static void
  2848. bfa_fcport_stats_clr_timeout(void *cbarg)
  2849. {
  2850. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2851. bfa_trc(fcport->bfa, fcport->stats_qfull);
  2852. if (fcport->stats_qfull) {
  2853. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  2854. fcport->stats_qfull = BFA_FALSE;
  2855. }
  2856. fcport->stats_status = BFA_STATUS_ETIMER;
  2857. __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
  2858. }
  2859. static void
  2860. bfa_fcport_send_stats_clear(void *cbarg)
  2861. {
  2862. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2863. struct bfi_fcport_req_s *msg;
  2864. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2865. if (!msg) {
  2866. fcport->stats_qfull = BFA_TRUE;
  2867. bfa_reqq_winit(&fcport->stats_reqq_wait,
  2868. bfa_fcport_send_stats_clear, fcport);
  2869. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2870. &fcport->stats_reqq_wait);
  2871. return;
  2872. }
  2873. fcport->stats_qfull = BFA_FALSE;
  2874. memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  2875. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
  2876. bfa_fn_lpu(fcport->bfa));
  2877. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
  2878. }
  2879. /*
  2880. * Handle trunk SCN event from firmware.
  2881. */
  2882. static void
  2883. bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
  2884. {
  2885. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2886. struct bfi_fcport_trunk_link_s *tlink;
  2887. struct bfa_trunk_link_attr_s *lattr;
  2888. enum bfa_trunk_state state_prev;
  2889. int i;
  2890. int link_bm = 0;
  2891. bfa_trc(fcport->bfa, fcport->cfg.trunked);
  2892. WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
  2893. scn->trunk_state != BFA_TRUNK_OFFLINE);
  2894. bfa_trc(fcport->bfa, trunk->attr.state);
  2895. bfa_trc(fcport->bfa, scn->trunk_state);
  2896. bfa_trc(fcport->bfa, scn->trunk_speed);
  2897. /*
  2898. * Save off new state for trunk attribute query
  2899. */
  2900. state_prev = trunk->attr.state;
  2901. if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
  2902. trunk->attr.state = scn->trunk_state;
  2903. trunk->attr.speed = scn->trunk_speed;
  2904. for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
  2905. lattr = &trunk->attr.link_attr[i];
  2906. tlink = &scn->tlink[i];
  2907. lattr->link_state = tlink->state;
  2908. lattr->trunk_wwn = tlink->trunk_wwn;
  2909. lattr->fctl = tlink->fctl;
  2910. lattr->speed = tlink->speed;
  2911. lattr->deskew = be32_to_cpu(tlink->deskew);
  2912. if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
  2913. fcport->speed = tlink->speed;
  2914. fcport->topology = BFA_PORT_TOPOLOGY_P2P;
  2915. link_bm |= 1 << i;
  2916. }
  2917. bfa_trc(fcport->bfa, lattr->link_state);
  2918. bfa_trc(fcport->bfa, lattr->trunk_wwn);
  2919. bfa_trc(fcport->bfa, lattr->fctl);
  2920. bfa_trc(fcport->bfa, lattr->speed);
  2921. bfa_trc(fcport->bfa, lattr->deskew);
  2922. }
  2923. switch (link_bm) {
  2924. case 3:
  2925. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2926. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
  2927. break;
  2928. case 2:
  2929. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2930. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
  2931. break;
  2932. case 1:
  2933. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2934. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
  2935. break;
  2936. default:
  2937. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2938. BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
  2939. }
  2940. /*
  2941. * Notify upper layers if trunk state changed.
  2942. */
  2943. if ((state_prev != trunk->attr.state) ||
  2944. (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
  2945. bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
  2946. BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
  2947. }
  2948. }
  2949. static void
  2950. bfa_trunk_iocdisable(struct bfa_s *bfa)
  2951. {
  2952. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2953. int i = 0;
  2954. /*
  2955. * In trunked mode, notify upper layers that link is down
  2956. */
  2957. if (fcport->cfg.trunked) {
  2958. if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
  2959. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
  2960. fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
  2961. fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
  2962. for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
  2963. fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
  2964. fcport->trunk.attr.link_attr[i].fctl =
  2965. BFA_TRUNK_LINK_FCTL_NORMAL;
  2966. fcport->trunk.attr.link_attr[i].link_state =
  2967. BFA_TRUNK_LINK_STATE_DN_LINKDN;
  2968. fcport->trunk.attr.link_attr[i].speed =
  2969. BFA_PORT_SPEED_UNKNOWN;
  2970. fcport->trunk.attr.link_attr[i].deskew = 0;
  2971. }
  2972. }
  2973. }
  2974. /*
  2975. * Called to initialize port attributes
  2976. */
  2977. void
  2978. bfa_fcport_init(struct bfa_s *bfa)
  2979. {
  2980. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2981. /*
  2982. * Initialize port attributes from IOC hardware data.
  2983. */
  2984. bfa_fcport_set_wwns(fcport);
  2985. if (fcport->cfg.maxfrsize == 0)
  2986. fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
  2987. fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
  2988. fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
  2989. if (bfa_fcport_is_pbcdisabled(bfa))
  2990. bfa->modules.port.pbc_disabled = BFA_TRUE;
  2991. WARN_ON(!fcport->cfg.maxfrsize);
  2992. WARN_ON(!fcport->cfg.rx_bbcredit);
  2993. WARN_ON(!fcport->speed_sup);
  2994. }
  2995. /*
  2996. * Firmware message handler.
  2997. */
  2998. void
  2999. bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  3000. {
  3001. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3002. union bfi_fcport_i2h_msg_u i2hmsg;
  3003. i2hmsg.msg = msg;
  3004. fcport->event_arg.i2hmsg = i2hmsg;
  3005. bfa_trc(bfa, msg->mhdr.msg_id);
  3006. bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
  3007. switch (msg->mhdr.msg_id) {
  3008. case BFI_FCPORT_I2H_ENABLE_RSP:
  3009. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
  3010. fcport->stats_dma_ready = BFA_TRUE;
  3011. if (fcport->use_flash_cfg) {
  3012. fcport->cfg = i2hmsg.penable_rsp->port_cfg;
  3013. fcport->cfg.maxfrsize =
  3014. cpu_to_be16(fcport->cfg.maxfrsize);
  3015. fcport->cfg.path_tov =
  3016. cpu_to_be16(fcport->cfg.path_tov);
  3017. fcport->cfg.q_depth =
  3018. cpu_to_be16(fcport->cfg.q_depth);
  3019. if (fcport->cfg.trunked)
  3020. fcport->trunk.attr.state =
  3021. BFA_TRUNK_OFFLINE;
  3022. else
  3023. fcport->trunk.attr.state =
  3024. BFA_TRUNK_DISABLED;
  3025. fcport->qos_attr.qos_bw =
  3026. i2hmsg.penable_rsp->port_cfg.qos_bw;
  3027. fcport->use_flash_cfg = BFA_FALSE;
  3028. }
  3029. if (fcport->cfg.qos_enabled)
  3030. fcport->qos_attr.state = BFA_QOS_OFFLINE;
  3031. else
  3032. fcport->qos_attr.state = BFA_QOS_DISABLED;
  3033. fcport->qos_attr.qos_bw_op =
  3034. i2hmsg.penable_rsp->port_cfg.qos_bw;
  3035. if (fcport->cfg.bb_cr_enabled)
  3036. fcport->bbcr_attr.state = BFA_BBCR_OFFLINE;
  3037. else
  3038. fcport->bbcr_attr.state = BFA_BBCR_DISABLED;
  3039. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  3040. }
  3041. break;
  3042. case BFI_FCPORT_I2H_DISABLE_RSP:
  3043. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
  3044. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  3045. break;
  3046. case BFI_FCPORT_I2H_EVENT:
  3047. if (fcport->cfg.bb_cr_enabled)
  3048. fcport->bbcr_attr.state = BFA_BBCR_OFFLINE;
  3049. else
  3050. fcport->bbcr_attr.state = BFA_BBCR_DISABLED;
  3051. if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
  3052. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
  3053. else {
  3054. if (i2hmsg.event->link_state.linkstate_rsn ==
  3055. BFA_PORT_LINKSTATE_RSN_FAA_MISCONFIG)
  3056. bfa_sm_send_event(fcport,
  3057. BFA_FCPORT_SM_FAA_MISCONFIG);
  3058. else
  3059. bfa_sm_send_event(fcport,
  3060. BFA_FCPORT_SM_LINKDOWN);
  3061. }
  3062. fcport->qos_attr.qos_bw_op =
  3063. i2hmsg.event->link_state.qos_attr.qos_bw_op;
  3064. break;
  3065. case BFI_FCPORT_I2H_TRUNK_SCN:
  3066. bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
  3067. break;
  3068. case BFI_FCPORT_I2H_STATS_GET_RSP:
  3069. /*
  3070. * check for timer pop before processing the rsp
  3071. */
  3072. if (list_empty(&fcport->stats_pending_q) ||
  3073. (fcport->stats_status == BFA_STATUS_ETIMER))
  3074. break;
  3075. bfa_timer_stop(&fcport->timer);
  3076. fcport->stats_status = i2hmsg.pstatsget_rsp->status;
  3077. __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
  3078. break;
  3079. case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
  3080. /*
  3081. * check for timer pop before processing the rsp
  3082. */
  3083. if (list_empty(&fcport->statsclr_pending_q) ||
  3084. (fcport->stats_status == BFA_STATUS_ETIMER))
  3085. break;
  3086. bfa_timer_stop(&fcport->timer);
  3087. fcport->stats_status = BFA_STATUS_OK;
  3088. __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
  3089. break;
  3090. case BFI_FCPORT_I2H_ENABLE_AEN:
  3091. bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
  3092. break;
  3093. case BFI_FCPORT_I2H_DISABLE_AEN:
  3094. bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
  3095. break;
  3096. default:
  3097. WARN_ON(1);
  3098. break;
  3099. }
  3100. }
  3101. /*
  3102. * Registered callback for port events.
  3103. */
  3104. void
  3105. bfa_fcport_event_register(struct bfa_s *bfa,
  3106. void (*cbfn) (void *cbarg,
  3107. enum bfa_port_linkstate event),
  3108. void *cbarg)
  3109. {
  3110. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3111. fcport->event_cbfn = cbfn;
  3112. fcport->event_cbarg = cbarg;
  3113. }
  3114. bfa_status_t
  3115. bfa_fcport_enable(struct bfa_s *bfa)
  3116. {
  3117. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3118. if (bfa_fcport_is_pbcdisabled(bfa))
  3119. return BFA_STATUS_PBC;
  3120. if (bfa_ioc_is_disabled(&bfa->ioc))
  3121. return BFA_STATUS_IOC_DISABLED;
  3122. if (fcport->diag_busy)
  3123. return BFA_STATUS_DIAG_BUSY;
  3124. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
  3125. return BFA_STATUS_OK;
  3126. }
  3127. bfa_status_t
  3128. bfa_fcport_disable(struct bfa_s *bfa)
  3129. {
  3130. if (bfa_fcport_is_pbcdisabled(bfa))
  3131. return BFA_STATUS_PBC;
  3132. if (bfa_ioc_is_disabled(&bfa->ioc))
  3133. return BFA_STATUS_IOC_DISABLED;
  3134. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
  3135. return BFA_STATUS_OK;
  3136. }
  3137. /* If PBC is disabled on port, return error */
  3138. bfa_status_t
  3139. bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
  3140. {
  3141. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3142. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  3143. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  3144. if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
  3145. bfa_trc(bfa, fcport->pwwn);
  3146. return BFA_STATUS_PBC;
  3147. }
  3148. return BFA_STATUS_OK;
  3149. }
  3150. /*
  3151. * Configure port speed.
  3152. */
  3153. bfa_status_t
  3154. bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
  3155. {
  3156. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3157. bfa_trc(bfa, speed);
  3158. if (fcport->cfg.trunked == BFA_TRUE)
  3159. return BFA_STATUS_TRUNK_ENABLED;
  3160. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  3161. (speed == BFA_PORT_SPEED_16GBPS))
  3162. return BFA_STATUS_UNSUPP_SPEED;
  3163. if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
  3164. bfa_trc(bfa, fcport->speed_sup);
  3165. return BFA_STATUS_UNSUPP_SPEED;
  3166. }
  3167. /* Port speed entered needs to be checked */
  3168. if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
  3169. /* For CT2, 1G is not supported */
  3170. if ((speed == BFA_PORT_SPEED_1GBPS) &&
  3171. (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
  3172. return BFA_STATUS_UNSUPP_SPEED;
  3173. /* Already checked for Auto Speed and Max Speed supp */
  3174. if (!(speed == BFA_PORT_SPEED_1GBPS ||
  3175. speed == BFA_PORT_SPEED_2GBPS ||
  3176. speed == BFA_PORT_SPEED_4GBPS ||
  3177. speed == BFA_PORT_SPEED_8GBPS ||
  3178. speed == BFA_PORT_SPEED_16GBPS ||
  3179. speed == BFA_PORT_SPEED_AUTO))
  3180. return BFA_STATUS_UNSUPP_SPEED;
  3181. } else {
  3182. if (speed != BFA_PORT_SPEED_10GBPS)
  3183. return BFA_STATUS_UNSUPP_SPEED;
  3184. }
  3185. fcport->cfg.speed = speed;
  3186. return BFA_STATUS_OK;
  3187. }
  3188. /*
  3189. * Get current speed.
  3190. */
  3191. enum bfa_port_speed
  3192. bfa_fcport_get_speed(struct bfa_s *bfa)
  3193. {
  3194. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3195. return fcport->speed;
  3196. }
  3197. /*
  3198. * Configure port topology.
  3199. */
  3200. bfa_status_t
  3201. bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
  3202. {
  3203. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3204. bfa_trc(bfa, topology);
  3205. bfa_trc(bfa, fcport->cfg.topology);
  3206. switch (topology) {
  3207. case BFA_PORT_TOPOLOGY_P2P:
  3208. break;
  3209. case BFA_PORT_TOPOLOGY_LOOP:
  3210. if ((bfa_fcport_is_qos_enabled(bfa) != BFA_FALSE) ||
  3211. (fcport->qos_attr.state != BFA_QOS_DISABLED))
  3212. return BFA_STATUS_ERROR_QOS_ENABLED;
  3213. if (fcport->cfg.ratelimit != BFA_FALSE)
  3214. return BFA_STATUS_ERROR_TRL_ENABLED;
  3215. if ((bfa_fcport_is_trunk_enabled(bfa) != BFA_FALSE) ||
  3216. (fcport->trunk.attr.state != BFA_TRUNK_DISABLED))
  3217. return BFA_STATUS_ERROR_TRUNK_ENABLED;
  3218. if ((bfa_fcport_get_speed(bfa) == BFA_PORT_SPEED_16GBPS) ||
  3219. (fcport->cfg.speed == BFA_PORT_SPEED_16GBPS))
  3220. return BFA_STATUS_UNSUPP_SPEED;
  3221. if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type))
  3222. return BFA_STATUS_LOOP_UNSUPP_MEZZ;
  3223. if (bfa_fcport_is_dport(bfa) != BFA_FALSE)
  3224. return BFA_STATUS_DPORT_ERR;
  3225. if (bfa_fcport_is_ddport(bfa) != BFA_FALSE)
  3226. return BFA_STATUS_DPORT_ERR;
  3227. break;
  3228. case BFA_PORT_TOPOLOGY_AUTO:
  3229. break;
  3230. default:
  3231. return BFA_STATUS_EINVAL;
  3232. }
  3233. fcport->cfg.topology = topology;
  3234. return BFA_STATUS_OK;
  3235. }
  3236. /*
  3237. * Get current topology.
  3238. */
  3239. enum bfa_port_topology
  3240. bfa_fcport_get_topology(struct bfa_s *bfa)
  3241. {
  3242. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3243. return fcport->topology;
  3244. }
  3245. /*
  3246. * Get config topology.
  3247. */
  3248. enum bfa_port_topology
  3249. bfa_fcport_get_cfg_topology(struct bfa_s *bfa)
  3250. {
  3251. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3252. return fcport->cfg.topology;
  3253. }
  3254. bfa_status_t
  3255. bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
  3256. {
  3257. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3258. bfa_trc(bfa, alpa);
  3259. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  3260. bfa_trc(bfa, fcport->cfg.hardalpa);
  3261. fcport->cfg.cfg_hardalpa = BFA_TRUE;
  3262. fcport->cfg.hardalpa = alpa;
  3263. return BFA_STATUS_OK;
  3264. }
  3265. bfa_status_t
  3266. bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
  3267. {
  3268. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3269. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  3270. bfa_trc(bfa, fcport->cfg.hardalpa);
  3271. fcport->cfg.cfg_hardalpa = BFA_FALSE;
  3272. return BFA_STATUS_OK;
  3273. }
  3274. bfa_boolean_t
  3275. bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
  3276. {
  3277. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3278. *alpa = fcport->cfg.hardalpa;
  3279. return fcport->cfg.cfg_hardalpa;
  3280. }
  3281. u8
  3282. bfa_fcport_get_myalpa(struct bfa_s *bfa)
  3283. {
  3284. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3285. return fcport->myalpa;
  3286. }
  3287. bfa_status_t
  3288. bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
  3289. {
  3290. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3291. bfa_trc(bfa, maxfrsize);
  3292. bfa_trc(bfa, fcport->cfg.maxfrsize);
  3293. /* with in range */
  3294. if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
  3295. return BFA_STATUS_INVLD_DFSZ;
  3296. /* power of 2, if not the max frame size of 2112 */
  3297. if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
  3298. return BFA_STATUS_INVLD_DFSZ;
  3299. fcport->cfg.maxfrsize = maxfrsize;
  3300. return BFA_STATUS_OK;
  3301. }
  3302. u16
  3303. bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
  3304. {
  3305. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3306. return fcport->cfg.maxfrsize;
  3307. }
  3308. u8
  3309. bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
  3310. {
  3311. if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP)
  3312. return (BFA_FCPORT_MOD(bfa))->cfg.rx_bbcredit;
  3313. else
  3314. return 0;
  3315. }
  3316. void
  3317. bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit)
  3318. {
  3319. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3320. fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
  3321. }
  3322. /*
  3323. * Get port attributes.
  3324. */
  3325. wwn_t
  3326. bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
  3327. {
  3328. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3329. if (node)
  3330. return fcport->nwwn;
  3331. else
  3332. return fcport->pwwn;
  3333. }
  3334. void
  3335. bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
  3336. {
  3337. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3338. memset(attr, 0, sizeof(struct bfa_port_attr_s));
  3339. attr->nwwn = fcport->nwwn;
  3340. attr->pwwn = fcport->pwwn;
  3341. attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
  3342. attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
  3343. memcpy(&attr->pport_cfg, &fcport->cfg,
  3344. sizeof(struct bfa_port_cfg_s));
  3345. /* speed attributes */
  3346. attr->pport_cfg.speed = fcport->cfg.speed;
  3347. attr->speed_supported = fcport->speed_sup;
  3348. attr->speed = fcport->speed;
  3349. attr->cos_supported = FC_CLASS_3;
  3350. /* topology attributes */
  3351. attr->pport_cfg.topology = fcport->cfg.topology;
  3352. attr->topology = fcport->topology;
  3353. attr->pport_cfg.trunked = fcport->cfg.trunked;
  3354. /* beacon attributes */
  3355. attr->beacon = fcport->beacon;
  3356. attr->link_e2e_beacon = fcport->link_e2e_beacon;
  3357. attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
  3358. attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
  3359. attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
  3360. attr->fec_state = fcport->fec_state;
  3361. /* PBC Disabled State */
  3362. if (bfa_fcport_is_pbcdisabled(bfa))
  3363. attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
  3364. else {
  3365. if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
  3366. attr->port_state = BFA_PORT_ST_IOCDIS;
  3367. else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
  3368. attr->port_state = BFA_PORT_ST_FWMISMATCH;
  3369. }
  3370. /* FCoE vlan */
  3371. attr->fcoe_vlan = fcport->fcoe_vlan;
  3372. }
  3373. #define BFA_FCPORT_STATS_TOV 1000
  3374. /*
  3375. * Fetch port statistics (FCQoS or FCoE).
  3376. */
  3377. bfa_status_t
  3378. bfa_fcport_get_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
  3379. {
  3380. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3381. if (!bfa_iocfc_is_operational(bfa) ||
  3382. !fcport->stats_dma_ready)
  3383. return BFA_STATUS_IOC_NON_OP;
  3384. if (!list_empty(&fcport->statsclr_pending_q))
  3385. return BFA_STATUS_DEVBUSY;
  3386. if (list_empty(&fcport->stats_pending_q)) {
  3387. list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
  3388. bfa_fcport_send_stats_get(fcport);
  3389. bfa_timer_start(bfa, &fcport->timer,
  3390. bfa_fcport_stats_get_timeout,
  3391. fcport, BFA_FCPORT_STATS_TOV);
  3392. } else
  3393. list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
  3394. return BFA_STATUS_OK;
  3395. }
  3396. /*
  3397. * Reset port statistics (FCQoS or FCoE).
  3398. */
  3399. bfa_status_t
  3400. bfa_fcport_clear_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
  3401. {
  3402. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3403. if (!bfa_iocfc_is_operational(bfa) ||
  3404. !fcport->stats_dma_ready)
  3405. return BFA_STATUS_IOC_NON_OP;
  3406. if (!list_empty(&fcport->stats_pending_q))
  3407. return BFA_STATUS_DEVBUSY;
  3408. if (list_empty(&fcport->statsclr_pending_q)) {
  3409. list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
  3410. bfa_fcport_send_stats_clear(fcport);
  3411. bfa_timer_start(bfa, &fcport->timer,
  3412. bfa_fcport_stats_clr_timeout,
  3413. fcport, BFA_FCPORT_STATS_TOV);
  3414. } else
  3415. list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
  3416. return BFA_STATUS_OK;
  3417. }
  3418. /*
  3419. * Fetch port attributes.
  3420. */
  3421. bfa_boolean_t
  3422. bfa_fcport_is_disabled(struct bfa_s *bfa)
  3423. {
  3424. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3425. return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
  3426. BFA_PORT_ST_DISABLED;
  3427. }
  3428. bfa_boolean_t
  3429. bfa_fcport_is_dport(struct bfa_s *bfa)
  3430. {
  3431. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3432. return (bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
  3433. BFA_PORT_ST_DPORT);
  3434. }
  3435. bfa_boolean_t
  3436. bfa_fcport_is_ddport(struct bfa_s *bfa)
  3437. {
  3438. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3439. return (bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
  3440. BFA_PORT_ST_DDPORT);
  3441. }
  3442. bfa_status_t
  3443. bfa_fcport_set_qos_bw(struct bfa_s *bfa, struct bfa_qos_bw_s *qos_bw)
  3444. {
  3445. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3446. enum bfa_ioc_type_e ioc_type = bfa_get_type(bfa);
  3447. bfa_trc(bfa, ioc_type);
  3448. if ((qos_bw->high == 0) || (qos_bw->med == 0) || (qos_bw->low == 0))
  3449. return BFA_STATUS_QOS_BW_INVALID;
  3450. if ((qos_bw->high + qos_bw->med + qos_bw->low) != 100)
  3451. return BFA_STATUS_QOS_BW_INVALID;
  3452. if ((qos_bw->med > qos_bw->high) || (qos_bw->low > qos_bw->med) ||
  3453. (qos_bw->low > qos_bw->high))
  3454. return BFA_STATUS_QOS_BW_INVALID;
  3455. if ((ioc_type == BFA_IOC_TYPE_FC) &&
  3456. (fcport->cfg.topology != BFA_PORT_TOPOLOGY_LOOP))
  3457. fcport->cfg.qos_bw = *qos_bw;
  3458. return BFA_STATUS_OK;
  3459. }
  3460. bfa_boolean_t
  3461. bfa_fcport_is_ratelim(struct bfa_s *bfa)
  3462. {
  3463. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3464. return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
  3465. }
  3466. /*
  3467. * Enable/Disable FAA feature in port config
  3468. */
  3469. void
  3470. bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state)
  3471. {
  3472. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3473. bfa_trc(bfa, state);
  3474. fcport->cfg.faa_state = state;
  3475. }
  3476. /*
  3477. * Get default minimum ratelim speed
  3478. */
  3479. enum bfa_port_speed
  3480. bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
  3481. {
  3482. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3483. bfa_trc(bfa, fcport->cfg.trl_def_speed);
  3484. return fcport->cfg.trl_def_speed;
  3485. }
  3486. void
  3487. bfa_fcport_beacon(void *dev, bfa_boolean_t beacon,
  3488. bfa_boolean_t link_e2e_beacon)
  3489. {
  3490. struct bfa_s *bfa = dev;
  3491. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3492. bfa_trc(bfa, beacon);
  3493. bfa_trc(bfa, link_e2e_beacon);
  3494. bfa_trc(bfa, fcport->beacon);
  3495. bfa_trc(bfa, fcport->link_e2e_beacon);
  3496. fcport->beacon = beacon;
  3497. fcport->link_e2e_beacon = link_e2e_beacon;
  3498. }
  3499. bfa_boolean_t
  3500. bfa_fcport_is_linkup(struct bfa_s *bfa)
  3501. {
  3502. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3503. return (!fcport->cfg.trunked &&
  3504. bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
  3505. (fcport->cfg.trunked &&
  3506. fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
  3507. }
  3508. bfa_boolean_t
  3509. bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
  3510. {
  3511. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3512. return fcport->cfg.qos_enabled;
  3513. }
  3514. bfa_boolean_t
  3515. bfa_fcport_is_trunk_enabled(struct bfa_s *bfa)
  3516. {
  3517. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3518. return fcport->cfg.trunked;
  3519. }
  3520. bfa_status_t
  3521. bfa_fcport_cfg_bbcr(struct bfa_s *bfa, bfa_boolean_t on_off, u8 bb_scn)
  3522. {
  3523. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3524. bfa_trc(bfa, on_off);
  3525. if (bfa_ioc_get_type(&fcport->bfa->ioc) != BFA_IOC_TYPE_FC)
  3526. return BFA_STATUS_BBCR_FC_ONLY;
  3527. if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type) &&
  3528. (bfa->ioc.attr->card_type != BFA_MFG_TYPE_CHINOOK))
  3529. return BFA_STATUS_CMD_NOTSUPP_MEZZ;
  3530. if (on_off) {
  3531. if (fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP)
  3532. return BFA_STATUS_TOPOLOGY_LOOP;
  3533. if (fcport->cfg.qos_enabled)
  3534. return BFA_STATUS_ERROR_QOS_ENABLED;
  3535. if (fcport->cfg.trunked)
  3536. return BFA_STATUS_TRUNK_ENABLED;
  3537. if ((fcport->cfg.speed != BFA_PORT_SPEED_AUTO) &&
  3538. (fcport->cfg.speed < bfa_ioc_speed_sup(&bfa->ioc)))
  3539. return BFA_STATUS_ERR_BBCR_SPEED_UNSUPPORT;
  3540. if (bfa_ioc_speed_sup(&bfa->ioc) < BFA_PORT_SPEED_8GBPS)
  3541. return BFA_STATUS_FEATURE_NOT_SUPPORTED;
  3542. if (fcport->cfg.bb_cr_enabled) {
  3543. if (bb_scn != fcport->cfg.bb_scn)
  3544. return BFA_STATUS_BBCR_CFG_NO_CHANGE;
  3545. else
  3546. return BFA_STATUS_NO_CHANGE;
  3547. }
  3548. if ((bb_scn == 0) || (bb_scn > BFA_BB_SCN_MAX))
  3549. bb_scn = BFA_BB_SCN_DEF;
  3550. fcport->cfg.bb_cr_enabled = on_off;
  3551. fcport->cfg.bb_scn = bb_scn;
  3552. } else {
  3553. if (!fcport->cfg.bb_cr_enabled)
  3554. return BFA_STATUS_NO_CHANGE;
  3555. fcport->cfg.bb_cr_enabled = on_off;
  3556. fcport->cfg.bb_scn = 0;
  3557. }
  3558. return BFA_STATUS_OK;
  3559. }
  3560. bfa_status_t
  3561. bfa_fcport_get_bbcr_attr(struct bfa_s *bfa,
  3562. struct bfa_bbcr_attr_s *bbcr_attr)
  3563. {
  3564. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3565. if (bfa_ioc_get_type(&fcport->bfa->ioc) != BFA_IOC_TYPE_FC)
  3566. return BFA_STATUS_BBCR_FC_ONLY;
  3567. if (fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP)
  3568. return BFA_STATUS_TOPOLOGY_LOOP;
  3569. *bbcr_attr = fcport->bbcr_attr;
  3570. return BFA_STATUS_OK;
  3571. }
  3572. void
  3573. bfa_fcport_dportenable(struct bfa_s *bfa)
  3574. {
  3575. /*
  3576. * Assume caller check for port is in disable state
  3577. */
  3578. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DPORTENABLE);
  3579. bfa_port_set_dportenabled(&bfa->modules.port, BFA_TRUE);
  3580. }
  3581. void
  3582. bfa_fcport_dportdisable(struct bfa_s *bfa)
  3583. {
  3584. /*
  3585. * Assume caller check for port is in disable state
  3586. */
  3587. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DPORTDISABLE);
  3588. bfa_port_set_dportenabled(&bfa->modules.port, BFA_FALSE);
  3589. }
  3590. static void
  3591. bfa_fcport_ddportenable(struct bfa_s *bfa)
  3592. {
  3593. /*
  3594. * Assume caller check for port is in disable state
  3595. */
  3596. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DDPORTENABLE);
  3597. }
  3598. static void
  3599. bfa_fcport_ddportdisable(struct bfa_s *bfa)
  3600. {
  3601. /*
  3602. * Assume caller check for port is in disable state
  3603. */
  3604. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DDPORTDISABLE);
  3605. }
  3606. /*
  3607. * Rport State machine functions
  3608. */
  3609. /*
  3610. * Beginning state, only online event expected.
  3611. */
  3612. static void
  3613. bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3614. {
  3615. bfa_trc(rp->bfa, rp->rport_tag);
  3616. bfa_trc(rp->bfa, event);
  3617. switch (event) {
  3618. case BFA_RPORT_SM_CREATE:
  3619. bfa_stats(rp, sm_un_cr);
  3620. bfa_sm_set_state(rp, bfa_rport_sm_created);
  3621. break;
  3622. default:
  3623. bfa_stats(rp, sm_un_unexp);
  3624. bfa_sm_fault(rp->bfa, event);
  3625. }
  3626. }
  3627. static void
  3628. bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3629. {
  3630. bfa_trc(rp->bfa, rp->rport_tag);
  3631. bfa_trc(rp->bfa, event);
  3632. switch (event) {
  3633. case BFA_RPORT_SM_ONLINE:
  3634. bfa_stats(rp, sm_cr_on);
  3635. if (bfa_rport_send_fwcreate(rp))
  3636. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3637. else
  3638. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3639. break;
  3640. case BFA_RPORT_SM_DELETE:
  3641. bfa_stats(rp, sm_cr_del);
  3642. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3643. bfa_rport_free(rp);
  3644. break;
  3645. case BFA_RPORT_SM_HWFAIL:
  3646. bfa_stats(rp, sm_cr_hwf);
  3647. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3648. break;
  3649. default:
  3650. bfa_stats(rp, sm_cr_unexp);
  3651. bfa_sm_fault(rp->bfa, event);
  3652. }
  3653. }
  3654. /*
  3655. * Waiting for rport create response from firmware.
  3656. */
  3657. static void
  3658. bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3659. {
  3660. bfa_trc(rp->bfa, rp->rport_tag);
  3661. bfa_trc(rp->bfa, event);
  3662. switch (event) {
  3663. case BFA_RPORT_SM_FWRSP:
  3664. bfa_stats(rp, sm_fwc_rsp);
  3665. bfa_sm_set_state(rp, bfa_rport_sm_online);
  3666. bfa_rport_online_cb(rp);
  3667. break;
  3668. case BFA_RPORT_SM_DELETE:
  3669. bfa_stats(rp, sm_fwc_del);
  3670. bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
  3671. break;
  3672. case BFA_RPORT_SM_OFFLINE:
  3673. bfa_stats(rp, sm_fwc_off);
  3674. bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
  3675. break;
  3676. case BFA_RPORT_SM_HWFAIL:
  3677. bfa_stats(rp, sm_fwc_hwf);
  3678. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3679. break;
  3680. default:
  3681. bfa_stats(rp, sm_fwc_unexp);
  3682. bfa_sm_fault(rp->bfa, event);
  3683. }
  3684. }
  3685. /*
  3686. * Request queue is full, awaiting queue resume to send create request.
  3687. */
  3688. static void
  3689. bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3690. {
  3691. bfa_trc(rp->bfa, rp->rport_tag);
  3692. bfa_trc(rp->bfa, event);
  3693. switch (event) {
  3694. case BFA_RPORT_SM_QRESUME:
  3695. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3696. bfa_rport_send_fwcreate(rp);
  3697. break;
  3698. case BFA_RPORT_SM_DELETE:
  3699. bfa_stats(rp, sm_fwc_del);
  3700. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3701. bfa_reqq_wcancel(&rp->reqq_wait);
  3702. bfa_rport_free(rp);
  3703. break;
  3704. case BFA_RPORT_SM_OFFLINE:
  3705. bfa_stats(rp, sm_fwc_off);
  3706. bfa_sm_set_state(rp, bfa_rport_sm_offline);
  3707. bfa_reqq_wcancel(&rp->reqq_wait);
  3708. bfa_rport_offline_cb(rp);
  3709. break;
  3710. case BFA_RPORT_SM_HWFAIL:
  3711. bfa_stats(rp, sm_fwc_hwf);
  3712. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3713. bfa_reqq_wcancel(&rp->reqq_wait);
  3714. break;
  3715. default:
  3716. bfa_stats(rp, sm_fwc_unexp);
  3717. bfa_sm_fault(rp->bfa, event);
  3718. }
  3719. }
  3720. /*
  3721. * Online state - normal parking state.
  3722. */
  3723. static void
  3724. bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3725. {
  3726. struct bfi_rport_qos_scn_s *qos_scn;
  3727. bfa_trc(rp->bfa, rp->rport_tag);
  3728. bfa_trc(rp->bfa, event);
  3729. switch (event) {
  3730. case BFA_RPORT_SM_OFFLINE:
  3731. bfa_stats(rp, sm_on_off);
  3732. if (bfa_rport_send_fwdelete(rp))
  3733. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3734. else
  3735. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
  3736. break;
  3737. case BFA_RPORT_SM_DELETE:
  3738. bfa_stats(rp, sm_on_del);
  3739. if (bfa_rport_send_fwdelete(rp))
  3740. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3741. else
  3742. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3743. break;
  3744. case BFA_RPORT_SM_HWFAIL:
  3745. bfa_stats(rp, sm_on_hwf);
  3746. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3747. break;
  3748. case BFA_RPORT_SM_SET_SPEED:
  3749. bfa_rport_send_fwspeed(rp);
  3750. break;
  3751. case BFA_RPORT_SM_QOS_SCN:
  3752. qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
  3753. rp->qos_attr = qos_scn->new_qos_attr;
  3754. bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
  3755. bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
  3756. bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
  3757. bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
  3758. qos_scn->old_qos_attr.qos_flow_id =
  3759. be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
  3760. qos_scn->new_qos_attr.qos_flow_id =
  3761. be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
  3762. if (qos_scn->old_qos_attr.qos_flow_id !=
  3763. qos_scn->new_qos_attr.qos_flow_id)
  3764. bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
  3765. qos_scn->old_qos_attr,
  3766. qos_scn->new_qos_attr);
  3767. if (qos_scn->old_qos_attr.qos_priority !=
  3768. qos_scn->new_qos_attr.qos_priority)
  3769. bfa_cb_rport_qos_scn_prio(rp->rport_drv,
  3770. qos_scn->old_qos_attr,
  3771. qos_scn->new_qos_attr);
  3772. break;
  3773. default:
  3774. bfa_stats(rp, sm_on_unexp);
  3775. bfa_sm_fault(rp->bfa, event);
  3776. }
  3777. }
  3778. /*
  3779. * Firmware rport is being deleted - awaiting f/w response.
  3780. */
  3781. static void
  3782. bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3783. {
  3784. bfa_trc(rp->bfa, rp->rport_tag);
  3785. bfa_trc(rp->bfa, event);
  3786. switch (event) {
  3787. case BFA_RPORT_SM_FWRSP:
  3788. bfa_stats(rp, sm_fwd_rsp);
  3789. bfa_sm_set_state(rp, bfa_rport_sm_offline);
  3790. bfa_rport_offline_cb(rp);
  3791. break;
  3792. case BFA_RPORT_SM_DELETE:
  3793. bfa_stats(rp, sm_fwd_del);
  3794. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3795. break;
  3796. case BFA_RPORT_SM_HWFAIL:
  3797. bfa_stats(rp, sm_fwd_hwf);
  3798. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3799. bfa_rport_offline_cb(rp);
  3800. break;
  3801. default:
  3802. bfa_stats(rp, sm_fwd_unexp);
  3803. bfa_sm_fault(rp->bfa, event);
  3804. }
  3805. }
  3806. static void
  3807. bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3808. {
  3809. bfa_trc(rp->bfa, rp->rport_tag);
  3810. bfa_trc(rp->bfa, event);
  3811. switch (event) {
  3812. case BFA_RPORT_SM_QRESUME:
  3813. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3814. bfa_rport_send_fwdelete(rp);
  3815. break;
  3816. case BFA_RPORT_SM_DELETE:
  3817. bfa_stats(rp, sm_fwd_del);
  3818. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3819. break;
  3820. case BFA_RPORT_SM_HWFAIL:
  3821. bfa_stats(rp, sm_fwd_hwf);
  3822. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3823. bfa_reqq_wcancel(&rp->reqq_wait);
  3824. bfa_rport_offline_cb(rp);
  3825. break;
  3826. default:
  3827. bfa_stats(rp, sm_fwd_unexp);
  3828. bfa_sm_fault(rp->bfa, event);
  3829. }
  3830. }
  3831. /*
  3832. * Offline state.
  3833. */
  3834. static void
  3835. bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3836. {
  3837. bfa_trc(rp->bfa, rp->rport_tag);
  3838. bfa_trc(rp->bfa, event);
  3839. switch (event) {
  3840. case BFA_RPORT_SM_DELETE:
  3841. bfa_stats(rp, sm_off_del);
  3842. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3843. bfa_rport_free(rp);
  3844. break;
  3845. case BFA_RPORT_SM_ONLINE:
  3846. bfa_stats(rp, sm_off_on);
  3847. if (bfa_rport_send_fwcreate(rp))
  3848. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3849. else
  3850. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3851. break;
  3852. case BFA_RPORT_SM_HWFAIL:
  3853. bfa_stats(rp, sm_off_hwf);
  3854. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3855. break;
  3856. case BFA_RPORT_SM_OFFLINE:
  3857. bfa_rport_offline_cb(rp);
  3858. break;
  3859. default:
  3860. bfa_stats(rp, sm_off_unexp);
  3861. bfa_sm_fault(rp->bfa, event);
  3862. }
  3863. }
  3864. /*
  3865. * Rport is deleted, waiting for firmware response to delete.
  3866. */
  3867. static void
  3868. bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3869. {
  3870. bfa_trc(rp->bfa, rp->rport_tag);
  3871. bfa_trc(rp->bfa, event);
  3872. switch (event) {
  3873. case BFA_RPORT_SM_FWRSP:
  3874. bfa_stats(rp, sm_del_fwrsp);
  3875. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3876. bfa_rport_free(rp);
  3877. break;
  3878. case BFA_RPORT_SM_HWFAIL:
  3879. bfa_stats(rp, sm_del_hwf);
  3880. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3881. bfa_rport_free(rp);
  3882. break;
  3883. default:
  3884. bfa_sm_fault(rp->bfa, event);
  3885. }
  3886. }
  3887. static void
  3888. bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3889. {
  3890. bfa_trc(rp->bfa, rp->rport_tag);
  3891. bfa_trc(rp->bfa, event);
  3892. switch (event) {
  3893. case BFA_RPORT_SM_QRESUME:
  3894. bfa_stats(rp, sm_del_fwrsp);
  3895. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3896. bfa_rport_send_fwdelete(rp);
  3897. break;
  3898. case BFA_RPORT_SM_HWFAIL:
  3899. bfa_stats(rp, sm_del_hwf);
  3900. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3901. bfa_reqq_wcancel(&rp->reqq_wait);
  3902. bfa_rport_free(rp);
  3903. break;
  3904. default:
  3905. bfa_sm_fault(rp->bfa, event);
  3906. }
  3907. }
  3908. /*
  3909. * Waiting for rport create response from firmware. A delete is pending.
  3910. */
  3911. static void
  3912. bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
  3913. enum bfa_rport_event event)
  3914. {
  3915. bfa_trc(rp->bfa, rp->rport_tag);
  3916. bfa_trc(rp->bfa, event);
  3917. switch (event) {
  3918. case BFA_RPORT_SM_FWRSP:
  3919. bfa_stats(rp, sm_delp_fwrsp);
  3920. if (bfa_rport_send_fwdelete(rp))
  3921. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3922. else
  3923. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3924. break;
  3925. case BFA_RPORT_SM_HWFAIL:
  3926. bfa_stats(rp, sm_delp_hwf);
  3927. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3928. bfa_rport_free(rp);
  3929. break;
  3930. default:
  3931. bfa_stats(rp, sm_delp_unexp);
  3932. bfa_sm_fault(rp->bfa, event);
  3933. }
  3934. }
  3935. /*
  3936. * Waiting for rport create response from firmware. Rport offline is pending.
  3937. */
  3938. static void
  3939. bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
  3940. enum bfa_rport_event event)
  3941. {
  3942. bfa_trc(rp->bfa, rp->rport_tag);
  3943. bfa_trc(rp->bfa, event);
  3944. switch (event) {
  3945. case BFA_RPORT_SM_FWRSP:
  3946. bfa_stats(rp, sm_offp_fwrsp);
  3947. if (bfa_rport_send_fwdelete(rp))
  3948. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3949. else
  3950. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
  3951. break;
  3952. case BFA_RPORT_SM_DELETE:
  3953. bfa_stats(rp, sm_offp_del);
  3954. bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
  3955. break;
  3956. case BFA_RPORT_SM_HWFAIL:
  3957. bfa_stats(rp, sm_offp_hwf);
  3958. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3959. bfa_rport_offline_cb(rp);
  3960. break;
  3961. default:
  3962. bfa_stats(rp, sm_offp_unexp);
  3963. bfa_sm_fault(rp->bfa, event);
  3964. }
  3965. }
  3966. /*
  3967. * IOC h/w failed.
  3968. */
  3969. static void
  3970. bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3971. {
  3972. bfa_trc(rp->bfa, rp->rport_tag);
  3973. bfa_trc(rp->bfa, event);
  3974. switch (event) {
  3975. case BFA_RPORT_SM_OFFLINE:
  3976. bfa_stats(rp, sm_iocd_off);
  3977. bfa_rport_offline_cb(rp);
  3978. break;
  3979. case BFA_RPORT_SM_DELETE:
  3980. bfa_stats(rp, sm_iocd_del);
  3981. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3982. bfa_rport_free(rp);
  3983. break;
  3984. case BFA_RPORT_SM_ONLINE:
  3985. bfa_stats(rp, sm_iocd_on);
  3986. if (bfa_rport_send_fwcreate(rp))
  3987. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3988. else
  3989. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3990. break;
  3991. case BFA_RPORT_SM_HWFAIL:
  3992. break;
  3993. default:
  3994. bfa_stats(rp, sm_iocd_unexp);
  3995. bfa_sm_fault(rp->bfa, event);
  3996. }
  3997. }
  3998. /*
  3999. * bfa_rport_private BFA rport private functions
  4000. */
  4001. static void
  4002. __bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
  4003. {
  4004. struct bfa_rport_s *rp = cbarg;
  4005. if (complete)
  4006. bfa_cb_rport_online(rp->rport_drv);
  4007. }
  4008. static void
  4009. __bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
  4010. {
  4011. struct bfa_rport_s *rp = cbarg;
  4012. if (complete)
  4013. bfa_cb_rport_offline(rp->rport_drv);
  4014. }
  4015. static void
  4016. bfa_rport_qresume(void *cbarg)
  4017. {
  4018. struct bfa_rport_s *rp = cbarg;
  4019. bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
  4020. }
  4021. void
  4022. bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  4023. struct bfa_s *bfa)
  4024. {
  4025. struct bfa_mem_kva_s *rport_kva = BFA_MEM_RPORT_KVA(bfa);
  4026. if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
  4027. cfg->fwcfg.num_rports = BFA_RPORT_MIN;
  4028. /* kva memory */
  4029. bfa_mem_kva_setup(minfo, rport_kva,
  4030. cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s));
  4031. }
  4032. void
  4033. bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4034. struct bfa_pcidev_s *pcidev)
  4035. {
  4036. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  4037. struct bfa_rport_s *rp;
  4038. u16 i;
  4039. INIT_LIST_HEAD(&mod->rp_free_q);
  4040. INIT_LIST_HEAD(&mod->rp_active_q);
  4041. INIT_LIST_HEAD(&mod->rp_unused_q);
  4042. rp = (struct bfa_rport_s *) bfa_mem_kva_curp(mod);
  4043. mod->rps_list = rp;
  4044. mod->num_rports = cfg->fwcfg.num_rports;
  4045. WARN_ON(!mod->num_rports ||
  4046. (mod->num_rports & (mod->num_rports - 1)));
  4047. for (i = 0; i < mod->num_rports; i++, rp++) {
  4048. memset(rp, 0, sizeof(struct bfa_rport_s));
  4049. rp->bfa = bfa;
  4050. rp->rport_tag = i;
  4051. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  4052. /*
  4053. * - is unused
  4054. */
  4055. if (i)
  4056. list_add_tail(&rp->qe, &mod->rp_free_q);
  4057. bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
  4058. }
  4059. /*
  4060. * consume memory
  4061. */
  4062. bfa_mem_kva_curp(mod) = (u8 *) rp;
  4063. }
  4064. void
  4065. bfa_rport_iocdisable(struct bfa_s *bfa)
  4066. {
  4067. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  4068. struct bfa_rport_s *rport;
  4069. struct list_head *qe, *qen;
  4070. /* Enqueue unused rport resources to free_q */
  4071. list_splice_tail_init(&mod->rp_unused_q, &mod->rp_free_q);
  4072. list_for_each_safe(qe, qen, &mod->rp_active_q) {
  4073. rport = (struct bfa_rport_s *) qe;
  4074. bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
  4075. }
  4076. }
  4077. static struct bfa_rport_s *
  4078. bfa_rport_alloc(struct bfa_rport_mod_s *mod)
  4079. {
  4080. struct bfa_rport_s *rport;
  4081. bfa_q_deq(&mod->rp_free_q, &rport);
  4082. if (rport)
  4083. list_add_tail(&rport->qe, &mod->rp_active_q);
  4084. return rport;
  4085. }
  4086. static void
  4087. bfa_rport_free(struct bfa_rport_s *rport)
  4088. {
  4089. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
  4090. WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
  4091. list_del(&rport->qe);
  4092. list_add_tail(&rport->qe, &mod->rp_free_q);
  4093. }
  4094. static bfa_boolean_t
  4095. bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
  4096. {
  4097. struct bfi_rport_create_req_s *m;
  4098. /*
  4099. * check for room in queue to send request now
  4100. */
  4101. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  4102. if (!m) {
  4103. bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
  4104. return BFA_FALSE;
  4105. }
  4106. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
  4107. bfa_fn_lpu(rp->bfa));
  4108. m->bfa_handle = rp->rport_tag;
  4109. m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
  4110. m->pid = rp->rport_info.pid;
  4111. m->lp_fwtag = bfa_lps_get_fwtag(rp->bfa, (u8)rp->rport_info.lp_tag);
  4112. m->local_pid = rp->rport_info.local_pid;
  4113. m->fc_class = rp->rport_info.fc_class;
  4114. m->vf_en = rp->rport_info.vf_en;
  4115. m->vf_id = rp->rport_info.vf_id;
  4116. m->cisc = rp->rport_info.cisc;
  4117. /*
  4118. * queue I/O message to firmware
  4119. */
  4120. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
  4121. return BFA_TRUE;
  4122. }
  4123. static bfa_boolean_t
  4124. bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
  4125. {
  4126. struct bfi_rport_delete_req_s *m;
  4127. /*
  4128. * check for room in queue to send request now
  4129. */
  4130. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  4131. if (!m) {
  4132. bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
  4133. return BFA_FALSE;
  4134. }
  4135. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
  4136. bfa_fn_lpu(rp->bfa));
  4137. m->fw_handle = rp->fw_handle;
  4138. /*
  4139. * queue I/O message to firmware
  4140. */
  4141. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
  4142. return BFA_TRUE;
  4143. }
  4144. static bfa_boolean_t
  4145. bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
  4146. {
  4147. struct bfa_rport_speed_req_s *m;
  4148. /*
  4149. * check for room in queue to send request now
  4150. */
  4151. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  4152. if (!m) {
  4153. bfa_trc(rp->bfa, rp->rport_info.speed);
  4154. return BFA_FALSE;
  4155. }
  4156. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
  4157. bfa_fn_lpu(rp->bfa));
  4158. m->fw_handle = rp->fw_handle;
  4159. m->speed = (u8)rp->rport_info.speed;
  4160. /*
  4161. * queue I/O message to firmware
  4162. */
  4163. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
  4164. return BFA_TRUE;
  4165. }
  4166. /*
  4167. * bfa_rport_public
  4168. */
  4169. /*
  4170. * Rport interrupt processing.
  4171. */
  4172. void
  4173. bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
  4174. {
  4175. union bfi_rport_i2h_msg_u msg;
  4176. struct bfa_rport_s *rp;
  4177. bfa_trc(bfa, m->mhdr.msg_id);
  4178. msg.msg = m;
  4179. switch (m->mhdr.msg_id) {
  4180. case BFI_RPORT_I2H_CREATE_RSP:
  4181. rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
  4182. rp->fw_handle = msg.create_rsp->fw_handle;
  4183. rp->qos_attr = msg.create_rsp->qos_attr;
  4184. bfa_rport_set_lunmask(bfa, rp);
  4185. WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
  4186. bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
  4187. break;
  4188. case BFI_RPORT_I2H_DELETE_RSP:
  4189. rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
  4190. WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
  4191. bfa_rport_unset_lunmask(bfa, rp);
  4192. bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
  4193. break;
  4194. case BFI_RPORT_I2H_QOS_SCN:
  4195. rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
  4196. rp->event_arg.fw_msg = msg.qos_scn_evt;
  4197. bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
  4198. break;
  4199. case BFI_RPORT_I2H_LIP_SCN_ONLINE:
  4200. bfa_fcport_update_loop_info(BFA_FCPORT_MOD(bfa),
  4201. &msg.lip_scn->loop_info);
  4202. bfa_cb_rport_scn_online(bfa);
  4203. break;
  4204. case BFI_RPORT_I2H_LIP_SCN_OFFLINE:
  4205. bfa_cb_rport_scn_offline(bfa);
  4206. break;
  4207. case BFI_RPORT_I2H_NO_DEV:
  4208. rp = BFA_RPORT_FROM_TAG(bfa, msg.lip_scn->bfa_handle);
  4209. bfa_cb_rport_scn_no_dev(rp->rport_drv);
  4210. break;
  4211. default:
  4212. bfa_trc(bfa, m->mhdr.msg_id);
  4213. WARN_ON(1);
  4214. }
  4215. }
  4216. void
  4217. bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw)
  4218. {
  4219. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  4220. struct list_head *qe;
  4221. int i;
  4222. for (i = 0; i < (mod->num_rports - num_rport_fw); i++) {
  4223. bfa_q_deq_tail(&mod->rp_free_q, &qe);
  4224. list_add_tail(qe, &mod->rp_unused_q);
  4225. }
  4226. }
  4227. /*
  4228. * bfa_rport_api
  4229. */
  4230. struct bfa_rport_s *
  4231. bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
  4232. {
  4233. struct bfa_rport_s *rp;
  4234. rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
  4235. if (rp == NULL)
  4236. return NULL;
  4237. rp->bfa = bfa;
  4238. rp->rport_drv = rport_drv;
  4239. memset(&rp->stats, 0, sizeof(rp->stats));
  4240. WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
  4241. bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
  4242. return rp;
  4243. }
  4244. void
  4245. bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
  4246. {
  4247. WARN_ON(rport_info->max_frmsz == 0);
  4248. /*
  4249. * Some JBODs are seen to be not setting PDU size correctly in PLOGI
  4250. * responses. Default to minimum size.
  4251. */
  4252. if (rport_info->max_frmsz == 0) {
  4253. bfa_trc(rport->bfa, rport->rport_tag);
  4254. rport_info->max_frmsz = FC_MIN_PDUSZ;
  4255. }
  4256. rport->rport_info = *rport_info;
  4257. bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
  4258. }
  4259. void
  4260. bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
  4261. {
  4262. WARN_ON(speed == 0);
  4263. WARN_ON(speed == BFA_PORT_SPEED_AUTO);
  4264. if (rport) {
  4265. rport->rport_info.speed = speed;
  4266. bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
  4267. }
  4268. }
  4269. /* Set Rport LUN Mask */
  4270. void
  4271. bfa_rport_set_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
  4272. {
  4273. struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
  4274. wwn_t lp_wwn, rp_wwn;
  4275. u8 lp_tag = (u8)rp->rport_info.lp_tag;
  4276. rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
  4277. lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
  4278. BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
  4279. rp->lun_mask = BFA_TRUE;
  4280. bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn, rp->rport_tag, lp_tag);
  4281. }
  4282. /* Unset Rport LUN mask */
  4283. void
  4284. bfa_rport_unset_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
  4285. {
  4286. struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
  4287. wwn_t lp_wwn, rp_wwn;
  4288. rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
  4289. lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
  4290. BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
  4291. rp->lun_mask = BFA_FALSE;
  4292. bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn,
  4293. BFA_RPORT_TAG_INVALID, BFA_LP_TAG_INVALID);
  4294. }
  4295. /*
  4296. * SGPG related functions
  4297. */
  4298. /*
  4299. * Compute and return memory needed by FCP(im) module.
  4300. */
  4301. void
  4302. bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  4303. struct bfa_s *bfa)
  4304. {
  4305. struct bfa_sgpg_mod_s *sgpg_mod = BFA_SGPG_MOD(bfa);
  4306. struct bfa_mem_kva_s *sgpg_kva = BFA_MEM_SGPG_KVA(bfa);
  4307. struct bfa_mem_dma_s *seg_ptr;
  4308. u16 nsegs, idx, per_seg_sgpg, num_sgpg;
  4309. u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
  4310. if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
  4311. cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
  4312. else if (cfg->drvcfg.num_sgpgs > BFA_SGPG_MAX)
  4313. cfg->drvcfg.num_sgpgs = BFA_SGPG_MAX;
  4314. num_sgpg = cfg->drvcfg.num_sgpgs;
  4315. nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
  4316. per_seg_sgpg = BFI_MEM_NREQS_SEG(sgpg_sz);
  4317. bfa_mem_dma_seg_iter(sgpg_mod, seg_ptr, nsegs, idx) {
  4318. if (num_sgpg >= per_seg_sgpg) {
  4319. num_sgpg -= per_seg_sgpg;
  4320. bfa_mem_dma_setup(minfo, seg_ptr,
  4321. per_seg_sgpg * sgpg_sz);
  4322. } else
  4323. bfa_mem_dma_setup(minfo, seg_ptr,
  4324. num_sgpg * sgpg_sz);
  4325. }
  4326. /* kva memory */
  4327. bfa_mem_kva_setup(minfo, sgpg_kva,
  4328. cfg->drvcfg.num_sgpgs * sizeof(struct bfa_sgpg_s));
  4329. }
  4330. void
  4331. bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4332. struct bfa_pcidev_s *pcidev)
  4333. {
  4334. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4335. struct bfa_sgpg_s *hsgpg;
  4336. struct bfi_sgpg_s *sgpg;
  4337. u64 align_len;
  4338. struct bfa_mem_dma_s *seg_ptr;
  4339. u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
  4340. u16 i, idx, nsegs, per_seg_sgpg, num_sgpg;
  4341. union {
  4342. u64 pa;
  4343. union bfi_addr_u addr;
  4344. } sgpg_pa, sgpg_pa_tmp;
  4345. INIT_LIST_HEAD(&mod->sgpg_q);
  4346. INIT_LIST_HEAD(&mod->sgpg_wait_q);
  4347. bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
  4348. mod->free_sgpgs = mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
  4349. num_sgpg = cfg->drvcfg.num_sgpgs;
  4350. nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
  4351. /* dma/kva mem claim */
  4352. hsgpg = (struct bfa_sgpg_s *) bfa_mem_kva_curp(mod);
  4353. bfa_mem_dma_seg_iter(mod, seg_ptr, nsegs, idx) {
  4354. if (!bfa_mem_dma_virt(seg_ptr))
  4355. break;
  4356. align_len = BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr)) -
  4357. bfa_mem_dma_phys(seg_ptr);
  4358. sgpg = (struct bfi_sgpg_s *)
  4359. (((u8 *) bfa_mem_dma_virt(seg_ptr)) + align_len);
  4360. sgpg_pa.pa = bfa_mem_dma_phys(seg_ptr) + align_len;
  4361. WARN_ON(sgpg_pa.pa & (sgpg_sz - 1));
  4362. per_seg_sgpg = (seg_ptr->mem_len - (u32)align_len) / sgpg_sz;
  4363. for (i = 0; num_sgpg > 0 && i < per_seg_sgpg; i++, num_sgpg--) {
  4364. memset(hsgpg, 0, sizeof(*hsgpg));
  4365. memset(sgpg, 0, sizeof(*sgpg));
  4366. hsgpg->sgpg = sgpg;
  4367. sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
  4368. hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
  4369. list_add_tail(&hsgpg->qe, &mod->sgpg_q);
  4370. sgpg++;
  4371. hsgpg++;
  4372. sgpg_pa.pa += sgpg_sz;
  4373. }
  4374. }
  4375. bfa_mem_kva_curp(mod) = (u8 *) hsgpg;
  4376. }
  4377. bfa_status_t
  4378. bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
  4379. {
  4380. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4381. struct bfa_sgpg_s *hsgpg;
  4382. int i;
  4383. if (mod->free_sgpgs < nsgpgs)
  4384. return BFA_STATUS_ENOMEM;
  4385. for (i = 0; i < nsgpgs; i++) {
  4386. bfa_q_deq(&mod->sgpg_q, &hsgpg);
  4387. WARN_ON(!hsgpg);
  4388. list_add_tail(&hsgpg->qe, sgpg_q);
  4389. }
  4390. mod->free_sgpgs -= nsgpgs;
  4391. return BFA_STATUS_OK;
  4392. }
  4393. void
  4394. bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
  4395. {
  4396. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4397. struct bfa_sgpg_wqe_s *wqe;
  4398. mod->free_sgpgs += nsgpg;
  4399. WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
  4400. list_splice_tail_init(sgpg_q, &mod->sgpg_q);
  4401. if (list_empty(&mod->sgpg_wait_q))
  4402. return;
  4403. /*
  4404. * satisfy as many waiting requests as possible
  4405. */
  4406. do {
  4407. wqe = bfa_q_first(&mod->sgpg_wait_q);
  4408. if (mod->free_sgpgs < wqe->nsgpg)
  4409. nsgpg = mod->free_sgpgs;
  4410. else
  4411. nsgpg = wqe->nsgpg;
  4412. bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
  4413. wqe->nsgpg -= nsgpg;
  4414. if (wqe->nsgpg == 0) {
  4415. list_del(&wqe->qe);
  4416. wqe->cbfn(wqe->cbarg);
  4417. }
  4418. } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
  4419. }
  4420. void
  4421. bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
  4422. {
  4423. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4424. WARN_ON(nsgpg <= 0);
  4425. WARN_ON(nsgpg <= mod->free_sgpgs);
  4426. wqe->nsgpg_total = wqe->nsgpg = nsgpg;
  4427. /*
  4428. * allocate any left to this one first
  4429. */
  4430. if (mod->free_sgpgs) {
  4431. /*
  4432. * no one else is waiting for SGPG
  4433. */
  4434. WARN_ON(!list_empty(&mod->sgpg_wait_q));
  4435. list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
  4436. wqe->nsgpg -= mod->free_sgpgs;
  4437. mod->free_sgpgs = 0;
  4438. }
  4439. list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
  4440. }
  4441. void
  4442. bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
  4443. {
  4444. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4445. WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
  4446. list_del(&wqe->qe);
  4447. if (wqe->nsgpg_total != wqe->nsgpg)
  4448. bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
  4449. wqe->nsgpg_total - wqe->nsgpg);
  4450. }
  4451. void
  4452. bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
  4453. void *cbarg)
  4454. {
  4455. INIT_LIST_HEAD(&wqe->sgpg_q);
  4456. wqe->cbfn = cbfn;
  4457. wqe->cbarg = cbarg;
  4458. }
  4459. /*
  4460. * UF related functions
  4461. */
  4462. /*
  4463. *****************************************************************************
  4464. * Internal functions
  4465. *****************************************************************************
  4466. */
  4467. static void
  4468. __bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
  4469. {
  4470. struct bfa_uf_s *uf = cbarg;
  4471. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
  4472. if (complete)
  4473. ufm->ufrecv(ufm->cbarg, uf);
  4474. }
  4475. static void
  4476. claim_uf_post_msgs(struct bfa_uf_mod_s *ufm)
  4477. {
  4478. struct bfi_uf_buf_post_s *uf_bp_msg;
  4479. u16 i;
  4480. u16 buf_len;
  4481. ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_mem_kva_curp(ufm);
  4482. uf_bp_msg = ufm->uf_buf_posts;
  4483. for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
  4484. i++, uf_bp_msg++) {
  4485. memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
  4486. uf_bp_msg->buf_tag = i;
  4487. buf_len = sizeof(struct bfa_uf_buf_s);
  4488. uf_bp_msg->buf_len = cpu_to_be16(buf_len);
  4489. bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
  4490. bfa_fn_lpu(ufm->bfa));
  4491. bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
  4492. }
  4493. /*
  4494. * advance pointer beyond consumed memory
  4495. */
  4496. bfa_mem_kva_curp(ufm) = (u8 *) uf_bp_msg;
  4497. }
  4498. static void
  4499. claim_ufs(struct bfa_uf_mod_s *ufm)
  4500. {
  4501. u16 i;
  4502. struct bfa_uf_s *uf;
  4503. /*
  4504. * Claim block of memory for UF list
  4505. */
  4506. ufm->uf_list = (struct bfa_uf_s *) bfa_mem_kva_curp(ufm);
  4507. /*
  4508. * Initialize UFs and queue it in UF free queue
  4509. */
  4510. for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
  4511. memset(uf, 0, sizeof(struct bfa_uf_s));
  4512. uf->bfa = ufm->bfa;
  4513. uf->uf_tag = i;
  4514. uf->pb_len = BFA_PER_UF_DMA_SZ;
  4515. uf->buf_kva = bfa_mem_get_dmabuf_kva(ufm, i, BFA_PER_UF_DMA_SZ);
  4516. uf->buf_pa = ufm_pbs_pa(ufm, i);
  4517. list_add_tail(&uf->qe, &ufm->uf_free_q);
  4518. }
  4519. /*
  4520. * advance memory pointer
  4521. */
  4522. bfa_mem_kva_curp(ufm) = (u8 *) uf;
  4523. }
  4524. static void
  4525. uf_mem_claim(struct bfa_uf_mod_s *ufm)
  4526. {
  4527. claim_ufs(ufm);
  4528. claim_uf_post_msgs(ufm);
  4529. }
  4530. void
  4531. bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  4532. struct bfa_s *bfa)
  4533. {
  4534. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4535. struct bfa_mem_kva_s *uf_kva = BFA_MEM_UF_KVA(bfa);
  4536. u32 num_ufs = cfg->fwcfg.num_uf_bufs;
  4537. struct bfa_mem_dma_s *seg_ptr;
  4538. u16 nsegs, idx, per_seg_uf = 0;
  4539. nsegs = BFI_MEM_DMA_NSEGS(num_ufs, BFA_PER_UF_DMA_SZ);
  4540. per_seg_uf = BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ);
  4541. bfa_mem_dma_seg_iter(ufm, seg_ptr, nsegs, idx) {
  4542. if (num_ufs >= per_seg_uf) {
  4543. num_ufs -= per_seg_uf;
  4544. bfa_mem_dma_setup(minfo, seg_ptr,
  4545. per_seg_uf * BFA_PER_UF_DMA_SZ);
  4546. } else
  4547. bfa_mem_dma_setup(minfo, seg_ptr,
  4548. num_ufs * BFA_PER_UF_DMA_SZ);
  4549. }
  4550. /* kva memory */
  4551. bfa_mem_kva_setup(minfo, uf_kva, cfg->fwcfg.num_uf_bufs *
  4552. (sizeof(struct bfa_uf_s) + sizeof(struct bfi_uf_buf_post_s)));
  4553. }
  4554. void
  4555. bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4556. struct bfa_pcidev_s *pcidev)
  4557. {
  4558. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4559. ufm->bfa = bfa;
  4560. ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
  4561. INIT_LIST_HEAD(&ufm->uf_free_q);
  4562. INIT_LIST_HEAD(&ufm->uf_posted_q);
  4563. INIT_LIST_HEAD(&ufm->uf_unused_q);
  4564. uf_mem_claim(ufm);
  4565. }
  4566. static struct bfa_uf_s *
  4567. bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
  4568. {
  4569. struct bfa_uf_s *uf;
  4570. bfa_q_deq(&uf_mod->uf_free_q, &uf);
  4571. return uf;
  4572. }
  4573. static void
  4574. bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
  4575. {
  4576. list_add_tail(&uf->qe, &uf_mod->uf_free_q);
  4577. }
  4578. static bfa_status_t
  4579. bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
  4580. {
  4581. struct bfi_uf_buf_post_s *uf_post_msg;
  4582. uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
  4583. if (!uf_post_msg)
  4584. return BFA_STATUS_FAILED;
  4585. memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
  4586. sizeof(struct bfi_uf_buf_post_s));
  4587. bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP, uf_post_msg->mh);
  4588. bfa_trc(ufm->bfa, uf->uf_tag);
  4589. list_add_tail(&uf->qe, &ufm->uf_posted_q);
  4590. return BFA_STATUS_OK;
  4591. }
  4592. static void
  4593. bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
  4594. {
  4595. struct bfa_uf_s *uf;
  4596. while ((uf = bfa_uf_get(uf_mod)) != NULL) {
  4597. if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
  4598. break;
  4599. }
  4600. }
  4601. static void
  4602. uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
  4603. {
  4604. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4605. u16 uf_tag = m->buf_tag;
  4606. struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
  4607. struct bfa_uf_buf_s *uf_buf;
  4608. uint8_t *buf;
  4609. uf_buf = (struct bfa_uf_buf_s *)
  4610. bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len);
  4611. buf = &uf_buf->d[0];
  4612. m->frm_len = be16_to_cpu(m->frm_len);
  4613. m->xfr_len = be16_to_cpu(m->xfr_len);
  4614. list_del(&uf->qe); /* dequeue from posted queue */
  4615. uf->data_ptr = buf;
  4616. uf->data_len = m->xfr_len;
  4617. WARN_ON(uf->data_len < sizeof(struct fchs_s));
  4618. if (uf->data_len == sizeof(struct fchs_s)) {
  4619. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
  4620. uf->data_len, (struct fchs_s *)buf);
  4621. } else {
  4622. u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
  4623. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
  4624. BFA_PL_EID_RX, uf->data_len,
  4625. (struct fchs_s *)buf, pld_w0);
  4626. }
  4627. if (bfa->fcs)
  4628. __bfa_cb_uf_recv(uf, BFA_TRUE);
  4629. else
  4630. bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
  4631. }
  4632. void
  4633. bfa_uf_iocdisable(struct bfa_s *bfa)
  4634. {
  4635. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4636. struct bfa_uf_s *uf;
  4637. struct list_head *qe, *qen;
  4638. /* Enqueue unused uf resources to free_q */
  4639. list_splice_tail_init(&ufm->uf_unused_q, &ufm->uf_free_q);
  4640. list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
  4641. uf = (struct bfa_uf_s *) qe;
  4642. list_del(&uf->qe);
  4643. bfa_uf_put(ufm, uf);
  4644. }
  4645. }
  4646. void
  4647. bfa_uf_start(struct bfa_s *bfa)
  4648. {
  4649. bfa_uf_post_all(BFA_UF_MOD(bfa));
  4650. }
  4651. /*
  4652. * Register handler for all unsolicted receive frames.
  4653. *
  4654. * @param[in] bfa BFA instance
  4655. * @param[in] ufrecv receive handler function
  4656. * @param[in] cbarg receive handler arg
  4657. */
  4658. void
  4659. bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
  4660. {
  4661. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4662. ufm->ufrecv = ufrecv;
  4663. ufm->cbarg = cbarg;
  4664. }
  4665. /*
  4666. * Free an unsolicited frame back to BFA.
  4667. *
  4668. * @param[in] uf unsolicited frame to be freed
  4669. *
  4670. * @return None
  4671. */
  4672. void
  4673. bfa_uf_free(struct bfa_uf_s *uf)
  4674. {
  4675. bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
  4676. bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
  4677. }
  4678. /*
  4679. * uf_pub BFA uf module public functions
  4680. */
  4681. void
  4682. bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  4683. {
  4684. bfa_trc(bfa, msg->mhdr.msg_id);
  4685. switch (msg->mhdr.msg_id) {
  4686. case BFI_UF_I2H_FRM_RCVD:
  4687. uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
  4688. break;
  4689. default:
  4690. bfa_trc(bfa, msg->mhdr.msg_id);
  4691. WARN_ON(1);
  4692. }
  4693. }
  4694. void
  4695. bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw)
  4696. {
  4697. struct bfa_uf_mod_s *mod = BFA_UF_MOD(bfa);
  4698. struct list_head *qe;
  4699. int i;
  4700. for (i = 0; i < (mod->num_ufs - num_uf_fw); i++) {
  4701. bfa_q_deq_tail(&mod->uf_free_q, &qe);
  4702. list_add_tail(qe, &mod->uf_unused_q);
  4703. }
  4704. }
  4705. /*
  4706. * Dport forward declaration
  4707. */
  4708. enum bfa_dport_test_state_e {
  4709. BFA_DPORT_ST_DISABLED = 0, /*!< dport is disabled */
  4710. BFA_DPORT_ST_INP = 1, /*!< test in progress */
  4711. BFA_DPORT_ST_COMP = 2, /*!< test complete successfully */
  4712. BFA_DPORT_ST_NO_SFP = 3, /*!< sfp is not present */
  4713. BFA_DPORT_ST_NOTSTART = 4, /*!< test not start dport is enabled */
  4714. };
  4715. /*
  4716. * BFA DPORT state machine events
  4717. */
  4718. enum bfa_dport_sm_event {
  4719. BFA_DPORT_SM_ENABLE = 1, /* dport enable event */
  4720. BFA_DPORT_SM_DISABLE = 2, /* dport disable event */
  4721. BFA_DPORT_SM_FWRSP = 3, /* fw enable/disable rsp */
  4722. BFA_DPORT_SM_QRESUME = 4, /* CQ space available */
  4723. BFA_DPORT_SM_HWFAIL = 5, /* IOC h/w failure */
  4724. BFA_DPORT_SM_START = 6, /* re-start dport test */
  4725. BFA_DPORT_SM_REQFAIL = 7, /* request failure */
  4726. BFA_DPORT_SM_SCN = 8, /* state change notify frm fw */
  4727. };
  4728. static void bfa_dport_sm_disabled(struct bfa_dport_s *dport,
  4729. enum bfa_dport_sm_event event);
  4730. static void bfa_dport_sm_enabling_qwait(struct bfa_dport_s *dport,
  4731. enum bfa_dport_sm_event event);
  4732. static void bfa_dport_sm_enabling(struct bfa_dport_s *dport,
  4733. enum bfa_dport_sm_event event);
  4734. static void bfa_dport_sm_enabled(struct bfa_dport_s *dport,
  4735. enum bfa_dport_sm_event event);
  4736. static void bfa_dport_sm_disabling_qwait(struct bfa_dport_s *dport,
  4737. enum bfa_dport_sm_event event);
  4738. static void bfa_dport_sm_disabling(struct bfa_dport_s *dport,
  4739. enum bfa_dport_sm_event event);
  4740. static void bfa_dport_sm_starting_qwait(struct bfa_dport_s *dport,
  4741. enum bfa_dport_sm_event event);
  4742. static void bfa_dport_sm_starting(struct bfa_dport_s *dport,
  4743. enum bfa_dport_sm_event event);
  4744. static void bfa_dport_sm_dynamic_disabling(struct bfa_dport_s *dport,
  4745. enum bfa_dport_sm_event event);
  4746. static void bfa_dport_sm_dynamic_disabling_qwait(struct bfa_dport_s *dport,
  4747. enum bfa_dport_sm_event event);
  4748. static void bfa_dport_qresume(void *cbarg);
  4749. static void bfa_dport_req_comp(struct bfa_dport_s *dport,
  4750. struct bfi_diag_dport_rsp_s *msg);
  4751. static void bfa_dport_scn(struct bfa_dport_s *dport,
  4752. struct bfi_diag_dport_scn_s *msg);
  4753. /*
  4754. * BFA fcdiag module
  4755. */
  4756. #define BFA_DIAG_QTEST_TOV 1000 /* msec */
  4757. /*
  4758. * Set port status to busy
  4759. */
  4760. static void
  4761. bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s *fcdiag)
  4762. {
  4763. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fcdiag->bfa);
  4764. if (fcdiag->lb.lock)
  4765. fcport->diag_busy = BFA_TRUE;
  4766. else
  4767. fcport->diag_busy = BFA_FALSE;
  4768. }
  4769. void
  4770. bfa_fcdiag_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4771. struct bfa_pcidev_s *pcidev)
  4772. {
  4773. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4774. struct bfa_dport_s *dport = &fcdiag->dport;
  4775. fcdiag->bfa = bfa;
  4776. fcdiag->trcmod = bfa->trcmod;
  4777. /* The common DIAG attach bfa_diag_attach() will do all memory claim */
  4778. dport->bfa = bfa;
  4779. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  4780. bfa_reqq_winit(&dport->reqq_wait, bfa_dport_qresume, dport);
  4781. dport->cbfn = NULL;
  4782. dport->cbarg = NULL;
  4783. dport->test_state = BFA_DPORT_ST_DISABLED;
  4784. memset(&dport->result, 0, sizeof(struct bfa_diag_dport_result_s));
  4785. }
  4786. void
  4787. bfa_fcdiag_iocdisable(struct bfa_s *bfa)
  4788. {
  4789. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4790. struct bfa_dport_s *dport = &fcdiag->dport;
  4791. bfa_trc(fcdiag, fcdiag->lb.lock);
  4792. if (fcdiag->lb.lock) {
  4793. fcdiag->lb.status = BFA_STATUS_IOC_FAILURE;
  4794. fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
  4795. fcdiag->lb.lock = 0;
  4796. bfa_fcdiag_set_busy_status(fcdiag);
  4797. }
  4798. bfa_sm_send_event(dport, BFA_DPORT_SM_HWFAIL);
  4799. }
  4800. static void
  4801. bfa_fcdiag_queuetest_timeout(void *cbarg)
  4802. {
  4803. struct bfa_fcdiag_s *fcdiag = cbarg;
  4804. struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
  4805. bfa_trc(fcdiag, fcdiag->qtest.all);
  4806. bfa_trc(fcdiag, fcdiag->qtest.count);
  4807. fcdiag->qtest.timer_active = 0;
  4808. res->status = BFA_STATUS_ETIMER;
  4809. res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
  4810. if (fcdiag->qtest.all)
  4811. res->queue = fcdiag->qtest.all;
  4812. bfa_trc(fcdiag, BFA_STATUS_ETIMER);
  4813. fcdiag->qtest.status = BFA_STATUS_ETIMER;
  4814. fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
  4815. fcdiag->qtest.lock = 0;
  4816. }
  4817. static bfa_status_t
  4818. bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s *fcdiag)
  4819. {
  4820. u32 i;
  4821. struct bfi_diag_qtest_req_s *req;
  4822. req = bfa_reqq_next(fcdiag->bfa, fcdiag->qtest.queue);
  4823. if (!req)
  4824. return BFA_STATUS_DEVBUSY;
  4825. /* build host command */
  4826. bfi_h2i_set(req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_QTEST,
  4827. bfa_fn_lpu(fcdiag->bfa));
  4828. for (i = 0; i < BFI_LMSG_PL_WSZ; i++)
  4829. req->data[i] = QTEST_PAT_DEFAULT;
  4830. bfa_trc(fcdiag, fcdiag->qtest.queue);
  4831. /* ring door bell */
  4832. bfa_reqq_produce(fcdiag->bfa, fcdiag->qtest.queue, req->mh);
  4833. return BFA_STATUS_OK;
  4834. }
  4835. static void
  4836. bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s *fcdiag,
  4837. bfi_diag_qtest_rsp_t *rsp)
  4838. {
  4839. struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
  4840. bfa_status_t status = BFA_STATUS_OK;
  4841. int i;
  4842. /* Check timer, should still be active */
  4843. if (!fcdiag->qtest.timer_active) {
  4844. bfa_trc(fcdiag, fcdiag->qtest.timer_active);
  4845. return;
  4846. }
  4847. /* update count */
  4848. fcdiag->qtest.count--;
  4849. /* Check result */
  4850. for (i = 0; i < BFI_LMSG_PL_WSZ; i++) {
  4851. if (rsp->data[i] != ~(QTEST_PAT_DEFAULT)) {
  4852. res->status = BFA_STATUS_DATACORRUPTED;
  4853. break;
  4854. }
  4855. }
  4856. if (res->status == BFA_STATUS_OK) {
  4857. if (fcdiag->qtest.count > 0) {
  4858. status = bfa_fcdiag_queuetest_send(fcdiag);
  4859. if (status == BFA_STATUS_OK)
  4860. return;
  4861. else
  4862. res->status = status;
  4863. } else if (fcdiag->qtest.all > 0 &&
  4864. fcdiag->qtest.queue < (BFI_IOC_MAX_CQS - 1)) {
  4865. fcdiag->qtest.count = QTEST_CNT_DEFAULT;
  4866. fcdiag->qtest.queue++;
  4867. status = bfa_fcdiag_queuetest_send(fcdiag);
  4868. if (status == BFA_STATUS_OK)
  4869. return;
  4870. else
  4871. res->status = status;
  4872. }
  4873. }
  4874. /* Stop timer when we comp all queue */
  4875. if (fcdiag->qtest.timer_active) {
  4876. bfa_timer_stop(&fcdiag->qtest.timer);
  4877. fcdiag->qtest.timer_active = 0;
  4878. }
  4879. res->queue = fcdiag->qtest.queue;
  4880. res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
  4881. bfa_trc(fcdiag, res->count);
  4882. bfa_trc(fcdiag, res->status);
  4883. fcdiag->qtest.status = res->status;
  4884. fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
  4885. fcdiag->qtest.lock = 0;
  4886. }
  4887. static void
  4888. bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s *fcdiag,
  4889. struct bfi_diag_lb_rsp_s *rsp)
  4890. {
  4891. struct bfa_diag_loopback_result_s *res = fcdiag->lb.result;
  4892. res->numtxmfrm = be32_to_cpu(rsp->res.numtxmfrm);
  4893. res->numosffrm = be32_to_cpu(rsp->res.numosffrm);
  4894. res->numrcvfrm = be32_to_cpu(rsp->res.numrcvfrm);
  4895. res->badfrminf = be32_to_cpu(rsp->res.badfrminf);
  4896. res->badfrmnum = be32_to_cpu(rsp->res.badfrmnum);
  4897. res->status = rsp->res.status;
  4898. fcdiag->lb.status = rsp->res.status;
  4899. bfa_trc(fcdiag, fcdiag->lb.status);
  4900. fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
  4901. fcdiag->lb.lock = 0;
  4902. bfa_fcdiag_set_busy_status(fcdiag);
  4903. }
  4904. static bfa_status_t
  4905. bfa_fcdiag_loopback_send(struct bfa_fcdiag_s *fcdiag,
  4906. struct bfa_diag_loopback_s *loopback)
  4907. {
  4908. struct bfi_diag_lb_req_s *lb_req;
  4909. lb_req = bfa_reqq_next(fcdiag->bfa, BFA_REQQ_DIAG);
  4910. if (!lb_req)
  4911. return BFA_STATUS_DEVBUSY;
  4912. /* build host command */
  4913. bfi_h2i_set(lb_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LOOPBACK,
  4914. bfa_fn_lpu(fcdiag->bfa));
  4915. lb_req->lb_mode = loopback->lb_mode;
  4916. lb_req->speed = loopback->speed;
  4917. lb_req->loopcnt = loopback->loopcnt;
  4918. lb_req->pattern = loopback->pattern;
  4919. /* ring door bell */
  4920. bfa_reqq_produce(fcdiag->bfa, BFA_REQQ_DIAG, lb_req->mh);
  4921. bfa_trc(fcdiag, loopback->lb_mode);
  4922. bfa_trc(fcdiag, loopback->speed);
  4923. bfa_trc(fcdiag, loopback->loopcnt);
  4924. bfa_trc(fcdiag, loopback->pattern);
  4925. return BFA_STATUS_OK;
  4926. }
  4927. /*
  4928. * cpe/rme intr handler
  4929. */
  4930. void
  4931. bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  4932. {
  4933. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4934. switch (msg->mhdr.msg_id) {
  4935. case BFI_DIAG_I2H_LOOPBACK:
  4936. bfa_fcdiag_loopback_comp(fcdiag,
  4937. (struct bfi_diag_lb_rsp_s *) msg);
  4938. break;
  4939. case BFI_DIAG_I2H_QTEST:
  4940. bfa_fcdiag_queuetest_comp(fcdiag, (bfi_diag_qtest_rsp_t *)msg);
  4941. break;
  4942. case BFI_DIAG_I2H_DPORT:
  4943. bfa_dport_req_comp(&fcdiag->dport,
  4944. (struct bfi_diag_dport_rsp_s *)msg);
  4945. break;
  4946. case BFI_DIAG_I2H_DPORT_SCN:
  4947. bfa_dport_scn(&fcdiag->dport,
  4948. (struct bfi_diag_dport_scn_s *)msg);
  4949. break;
  4950. default:
  4951. bfa_trc(fcdiag, msg->mhdr.msg_id);
  4952. WARN_ON(1);
  4953. }
  4954. }
  4955. /*
  4956. * Loopback test
  4957. *
  4958. * @param[in] *bfa - bfa data struct
  4959. * @param[in] opmode - port operation mode
  4960. * @param[in] speed - port speed
  4961. * @param[in] lpcnt - loop count
  4962. * @param[in] pat - pattern to build packet
  4963. * @param[in] *result - pt to bfa_diag_loopback_result_t data struct
  4964. * @param[in] cbfn - callback function
  4965. * @param[in] cbarg - callback functioin arg
  4966. *
  4967. * @param[out]
  4968. */
  4969. bfa_status_t
  4970. bfa_fcdiag_loopback(struct bfa_s *bfa, enum bfa_port_opmode opmode,
  4971. enum bfa_port_speed speed, u32 lpcnt, u32 pat,
  4972. struct bfa_diag_loopback_result_s *result, bfa_cb_diag_t cbfn,
  4973. void *cbarg)
  4974. {
  4975. struct bfa_diag_loopback_s loopback;
  4976. struct bfa_port_attr_s attr;
  4977. bfa_status_t status;
  4978. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4979. if (!bfa_iocfc_is_operational(bfa))
  4980. return BFA_STATUS_IOC_NON_OP;
  4981. /* if port is PBC disabled, return error */
  4982. if (bfa_fcport_is_pbcdisabled(bfa)) {
  4983. bfa_trc(fcdiag, BFA_STATUS_PBC);
  4984. return BFA_STATUS_PBC;
  4985. }
  4986. if (bfa_fcport_is_disabled(bfa) == BFA_FALSE) {
  4987. bfa_trc(fcdiag, opmode);
  4988. return BFA_STATUS_PORT_NOT_DISABLED;
  4989. }
  4990. /*
  4991. * Check if input speed is supported by the port mode
  4992. */
  4993. if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
  4994. if (!(speed == BFA_PORT_SPEED_1GBPS ||
  4995. speed == BFA_PORT_SPEED_2GBPS ||
  4996. speed == BFA_PORT_SPEED_4GBPS ||
  4997. speed == BFA_PORT_SPEED_8GBPS ||
  4998. speed == BFA_PORT_SPEED_16GBPS ||
  4999. speed == BFA_PORT_SPEED_AUTO)) {
  5000. bfa_trc(fcdiag, speed);
  5001. return BFA_STATUS_UNSUPP_SPEED;
  5002. }
  5003. bfa_fcport_get_attr(bfa, &attr);
  5004. bfa_trc(fcdiag, attr.speed_supported);
  5005. if (speed > attr.speed_supported)
  5006. return BFA_STATUS_UNSUPP_SPEED;
  5007. } else {
  5008. if (speed != BFA_PORT_SPEED_10GBPS) {
  5009. bfa_trc(fcdiag, speed);
  5010. return BFA_STATUS_UNSUPP_SPEED;
  5011. }
  5012. }
  5013. /*
  5014. * For CT2, 1G is not supported
  5015. */
  5016. if ((speed == BFA_PORT_SPEED_1GBPS) &&
  5017. (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id))) {
  5018. bfa_trc(fcdiag, speed);
  5019. return BFA_STATUS_UNSUPP_SPEED;
  5020. }
  5021. /* For Mezz card, port speed entered needs to be checked */
  5022. if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type)) {
  5023. if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
  5024. if (!(speed == BFA_PORT_SPEED_1GBPS ||
  5025. speed == BFA_PORT_SPEED_2GBPS ||
  5026. speed == BFA_PORT_SPEED_4GBPS ||
  5027. speed == BFA_PORT_SPEED_8GBPS ||
  5028. speed == BFA_PORT_SPEED_16GBPS ||
  5029. speed == BFA_PORT_SPEED_AUTO))
  5030. return BFA_STATUS_UNSUPP_SPEED;
  5031. } else {
  5032. if (speed != BFA_PORT_SPEED_10GBPS)
  5033. return BFA_STATUS_UNSUPP_SPEED;
  5034. }
  5035. }
  5036. /* check to see if fcport is dport */
  5037. if (bfa_fcport_is_dport(bfa)) {
  5038. bfa_trc(fcdiag, fcdiag->lb.lock);
  5039. return BFA_STATUS_DPORT_ENABLED;
  5040. }
  5041. /* check to see if there is another destructive diag cmd running */
  5042. if (fcdiag->lb.lock) {
  5043. bfa_trc(fcdiag, fcdiag->lb.lock);
  5044. return BFA_STATUS_DEVBUSY;
  5045. }
  5046. fcdiag->lb.lock = 1;
  5047. loopback.lb_mode = opmode;
  5048. loopback.speed = speed;
  5049. loopback.loopcnt = lpcnt;
  5050. loopback.pattern = pat;
  5051. fcdiag->lb.result = result;
  5052. fcdiag->lb.cbfn = cbfn;
  5053. fcdiag->lb.cbarg = cbarg;
  5054. memset(result, 0, sizeof(struct bfa_diag_loopback_result_s));
  5055. bfa_fcdiag_set_busy_status(fcdiag);
  5056. /* Send msg to fw */
  5057. status = bfa_fcdiag_loopback_send(fcdiag, &loopback);
  5058. return status;
  5059. }
  5060. /*
  5061. * DIAG queue test command
  5062. *
  5063. * @param[in] *bfa - bfa data struct
  5064. * @param[in] force - 1: don't do ioc op checking
  5065. * @param[in] queue - queue no. to test
  5066. * @param[in] *result - pt to bfa_diag_qtest_result_t data struct
  5067. * @param[in] cbfn - callback function
  5068. * @param[in] *cbarg - callback functioin arg
  5069. *
  5070. * @param[out]
  5071. */
  5072. bfa_status_t
  5073. bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 force, u32 queue,
  5074. struct bfa_diag_qtest_result_s *result, bfa_cb_diag_t cbfn,
  5075. void *cbarg)
  5076. {
  5077. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  5078. bfa_status_t status;
  5079. bfa_trc(fcdiag, force);
  5080. bfa_trc(fcdiag, queue);
  5081. if (!force && !bfa_iocfc_is_operational(bfa))
  5082. return BFA_STATUS_IOC_NON_OP;
  5083. /* check to see if there is another destructive diag cmd running */
  5084. if (fcdiag->qtest.lock) {
  5085. bfa_trc(fcdiag, fcdiag->qtest.lock);
  5086. return BFA_STATUS_DEVBUSY;
  5087. }
  5088. /* Initialization */
  5089. fcdiag->qtest.lock = 1;
  5090. fcdiag->qtest.cbfn = cbfn;
  5091. fcdiag->qtest.cbarg = cbarg;
  5092. fcdiag->qtest.result = result;
  5093. fcdiag->qtest.count = QTEST_CNT_DEFAULT;
  5094. /* Init test results */
  5095. fcdiag->qtest.result->status = BFA_STATUS_OK;
  5096. fcdiag->qtest.result->count = 0;
  5097. /* send */
  5098. if (queue < BFI_IOC_MAX_CQS) {
  5099. fcdiag->qtest.result->queue = (u8)queue;
  5100. fcdiag->qtest.queue = (u8)queue;
  5101. fcdiag->qtest.all = 0;
  5102. } else {
  5103. fcdiag->qtest.result->queue = 0;
  5104. fcdiag->qtest.queue = 0;
  5105. fcdiag->qtest.all = 1;
  5106. }
  5107. status = bfa_fcdiag_queuetest_send(fcdiag);
  5108. /* Start a timer */
  5109. if (status == BFA_STATUS_OK) {
  5110. bfa_timer_start(bfa, &fcdiag->qtest.timer,
  5111. bfa_fcdiag_queuetest_timeout, fcdiag,
  5112. BFA_DIAG_QTEST_TOV);
  5113. fcdiag->qtest.timer_active = 1;
  5114. }
  5115. return status;
  5116. }
  5117. /*
  5118. * DIAG PLB is running
  5119. *
  5120. * @param[in] *bfa - bfa data struct
  5121. *
  5122. * @param[out]
  5123. */
  5124. bfa_status_t
  5125. bfa_fcdiag_lb_is_running(struct bfa_s *bfa)
  5126. {
  5127. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  5128. return fcdiag->lb.lock ? BFA_STATUS_DIAG_BUSY : BFA_STATUS_OK;
  5129. }
  5130. /*
  5131. * D-port
  5132. */
  5133. #define bfa_dport_result_start(__dport, __mode) do { \
  5134. (__dport)->result.start_time = ktime_get_real_seconds(); \
  5135. (__dport)->result.status = DPORT_TEST_ST_INPRG; \
  5136. (__dport)->result.mode = (__mode); \
  5137. (__dport)->result.rp_pwwn = (__dport)->rp_pwwn; \
  5138. (__dport)->result.rp_nwwn = (__dport)->rp_nwwn; \
  5139. (__dport)->result.lpcnt = (__dport)->lpcnt; \
  5140. } while (0)
  5141. static bfa_boolean_t bfa_dport_send_req(struct bfa_dport_s *dport,
  5142. enum bfi_dport_req req);
  5143. static void
  5144. bfa_cb_fcdiag_dport(struct bfa_dport_s *dport, bfa_status_t bfa_status)
  5145. {
  5146. if (dport->cbfn != NULL) {
  5147. dport->cbfn(dport->cbarg, bfa_status);
  5148. dport->cbfn = NULL;
  5149. dport->cbarg = NULL;
  5150. }
  5151. }
  5152. static void
  5153. bfa_dport_sm_disabled(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
  5154. {
  5155. bfa_trc(dport->bfa, event);
  5156. switch (event) {
  5157. case BFA_DPORT_SM_ENABLE:
  5158. bfa_fcport_dportenable(dport->bfa);
  5159. if (bfa_dport_send_req(dport, BFI_DPORT_ENABLE))
  5160. bfa_sm_set_state(dport, bfa_dport_sm_enabling);
  5161. else
  5162. bfa_sm_set_state(dport, bfa_dport_sm_enabling_qwait);
  5163. break;
  5164. case BFA_DPORT_SM_DISABLE:
  5165. /* Already disabled */
  5166. break;
  5167. case BFA_DPORT_SM_HWFAIL:
  5168. /* ignore */
  5169. break;
  5170. case BFA_DPORT_SM_SCN:
  5171. if (dport->i2hmsg.scn.state == BFI_DPORT_SCN_DDPORT_ENABLE) {
  5172. bfa_fcport_ddportenable(dport->bfa);
  5173. dport->dynamic = BFA_TRUE;
  5174. dport->test_state = BFA_DPORT_ST_NOTSTART;
  5175. bfa_sm_set_state(dport, bfa_dport_sm_enabled);
  5176. } else {
  5177. bfa_trc(dport->bfa, dport->i2hmsg.scn.state);
  5178. WARN_ON(1);
  5179. }
  5180. break;
  5181. default:
  5182. bfa_sm_fault(dport->bfa, event);
  5183. }
  5184. }
  5185. static void
  5186. bfa_dport_sm_enabling_qwait(struct bfa_dport_s *dport,
  5187. enum bfa_dport_sm_event event)
  5188. {
  5189. bfa_trc(dport->bfa, event);
  5190. switch (event) {
  5191. case BFA_DPORT_SM_QRESUME:
  5192. bfa_sm_set_state(dport, bfa_dport_sm_enabling);
  5193. bfa_dport_send_req(dport, BFI_DPORT_ENABLE);
  5194. break;
  5195. case BFA_DPORT_SM_HWFAIL:
  5196. bfa_reqq_wcancel(&dport->reqq_wait);
  5197. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5198. bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
  5199. break;
  5200. default:
  5201. bfa_sm_fault(dport->bfa, event);
  5202. }
  5203. }
  5204. static void
  5205. bfa_dport_sm_enabling(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
  5206. {
  5207. bfa_trc(dport->bfa, event);
  5208. switch (event) {
  5209. case BFA_DPORT_SM_FWRSP:
  5210. memset(&dport->result, 0,
  5211. sizeof(struct bfa_diag_dport_result_s));
  5212. if (dport->i2hmsg.rsp.status == BFA_STATUS_DPORT_INV_SFP) {
  5213. dport->test_state = BFA_DPORT_ST_NO_SFP;
  5214. } else {
  5215. dport->test_state = BFA_DPORT_ST_INP;
  5216. bfa_dport_result_start(dport, BFA_DPORT_OPMODE_AUTO);
  5217. }
  5218. bfa_sm_set_state(dport, bfa_dport_sm_enabled);
  5219. break;
  5220. case BFA_DPORT_SM_REQFAIL:
  5221. dport->test_state = BFA_DPORT_ST_DISABLED;
  5222. bfa_fcport_dportdisable(dport->bfa);
  5223. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5224. break;
  5225. case BFA_DPORT_SM_HWFAIL:
  5226. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5227. bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
  5228. break;
  5229. default:
  5230. bfa_sm_fault(dport->bfa, event);
  5231. }
  5232. }
  5233. static void
  5234. bfa_dport_sm_enabled(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
  5235. {
  5236. bfa_trc(dport->bfa, event);
  5237. switch (event) {
  5238. case BFA_DPORT_SM_START:
  5239. if (bfa_dport_send_req(dport, BFI_DPORT_START))
  5240. bfa_sm_set_state(dport, bfa_dport_sm_starting);
  5241. else
  5242. bfa_sm_set_state(dport, bfa_dport_sm_starting_qwait);
  5243. break;
  5244. case BFA_DPORT_SM_DISABLE:
  5245. bfa_fcport_dportdisable(dport->bfa);
  5246. if (bfa_dport_send_req(dport, BFI_DPORT_DISABLE))
  5247. bfa_sm_set_state(dport, bfa_dport_sm_disabling);
  5248. else
  5249. bfa_sm_set_state(dport, bfa_dport_sm_disabling_qwait);
  5250. break;
  5251. case BFA_DPORT_SM_HWFAIL:
  5252. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5253. break;
  5254. case BFA_DPORT_SM_SCN:
  5255. switch (dport->i2hmsg.scn.state) {
  5256. case BFI_DPORT_SCN_TESTCOMP:
  5257. dport->test_state = BFA_DPORT_ST_COMP;
  5258. break;
  5259. case BFI_DPORT_SCN_TESTSTART:
  5260. dport->test_state = BFA_DPORT_ST_INP;
  5261. break;
  5262. case BFI_DPORT_SCN_TESTSKIP:
  5263. case BFI_DPORT_SCN_SUBTESTSTART:
  5264. /* no state change */
  5265. break;
  5266. case BFI_DPORT_SCN_SFP_REMOVED:
  5267. dport->test_state = BFA_DPORT_ST_NO_SFP;
  5268. break;
  5269. case BFI_DPORT_SCN_DDPORT_DISABLE:
  5270. bfa_fcport_ddportdisable(dport->bfa);
  5271. if (bfa_dport_send_req(dport, BFI_DPORT_DYN_DISABLE))
  5272. bfa_sm_set_state(dport,
  5273. bfa_dport_sm_dynamic_disabling);
  5274. else
  5275. bfa_sm_set_state(dport,
  5276. bfa_dport_sm_dynamic_disabling_qwait);
  5277. break;
  5278. case BFI_DPORT_SCN_FCPORT_DISABLE:
  5279. bfa_fcport_ddportdisable(dport->bfa);
  5280. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5281. dport->dynamic = BFA_FALSE;
  5282. break;
  5283. default:
  5284. bfa_trc(dport->bfa, dport->i2hmsg.scn.state);
  5285. bfa_sm_fault(dport->bfa, event);
  5286. }
  5287. break;
  5288. default:
  5289. bfa_sm_fault(dport->bfa, event);
  5290. }
  5291. }
  5292. static void
  5293. bfa_dport_sm_disabling_qwait(struct bfa_dport_s *dport,
  5294. enum bfa_dport_sm_event event)
  5295. {
  5296. bfa_trc(dport->bfa, event);
  5297. switch (event) {
  5298. case BFA_DPORT_SM_QRESUME:
  5299. bfa_sm_set_state(dport, bfa_dport_sm_disabling);
  5300. bfa_dport_send_req(dport, BFI_DPORT_DISABLE);
  5301. break;
  5302. case BFA_DPORT_SM_HWFAIL:
  5303. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5304. bfa_reqq_wcancel(&dport->reqq_wait);
  5305. bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
  5306. break;
  5307. case BFA_DPORT_SM_SCN:
  5308. /* ignore */
  5309. break;
  5310. default:
  5311. bfa_sm_fault(dport->bfa, event);
  5312. }
  5313. }
  5314. static void
  5315. bfa_dport_sm_disabling(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
  5316. {
  5317. bfa_trc(dport->bfa, event);
  5318. switch (event) {
  5319. case BFA_DPORT_SM_FWRSP:
  5320. dport->test_state = BFA_DPORT_ST_DISABLED;
  5321. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5322. break;
  5323. case BFA_DPORT_SM_HWFAIL:
  5324. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5325. bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
  5326. break;
  5327. case BFA_DPORT_SM_SCN:
  5328. /* no state change */
  5329. break;
  5330. default:
  5331. bfa_sm_fault(dport->bfa, event);
  5332. }
  5333. }
  5334. static void
  5335. bfa_dport_sm_starting_qwait(struct bfa_dport_s *dport,
  5336. enum bfa_dport_sm_event event)
  5337. {
  5338. bfa_trc(dport->bfa, event);
  5339. switch (event) {
  5340. case BFA_DPORT_SM_QRESUME:
  5341. bfa_sm_set_state(dport, bfa_dport_sm_starting);
  5342. bfa_dport_send_req(dport, BFI_DPORT_START);
  5343. break;
  5344. case BFA_DPORT_SM_HWFAIL:
  5345. bfa_reqq_wcancel(&dport->reqq_wait);
  5346. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5347. bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
  5348. break;
  5349. default:
  5350. bfa_sm_fault(dport->bfa, event);
  5351. }
  5352. }
  5353. static void
  5354. bfa_dport_sm_starting(struct bfa_dport_s *dport, enum bfa_dport_sm_event event)
  5355. {
  5356. bfa_trc(dport->bfa, event);
  5357. switch (event) {
  5358. case BFA_DPORT_SM_FWRSP:
  5359. memset(&dport->result, 0,
  5360. sizeof(struct bfa_diag_dport_result_s));
  5361. if (dport->i2hmsg.rsp.status == BFA_STATUS_DPORT_INV_SFP) {
  5362. dport->test_state = BFA_DPORT_ST_NO_SFP;
  5363. } else {
  5364. dport->test_state = BFA_DPORT_ST_INP;
  5365. bfa_dport_result_start(dport, BFA_DPORT_OPMODE_MANU);
  5366. }
  5367. fallthrough;
  5368. case BFA_DPORT_SM_REQFAIL:
  5369. bfa_sm_set_state(dport, bfa_dport_sm_enabled);
  5370. break;
  5371. case BFA_DPORT_SM_HWFAIL:
  5372. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5373. bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED);
  5374. break;
  5375. default:
  5376. bfa_sm_fault(dport->bfa, event);
  5377. }
  5378. }
  5379. static void
  5380. bfa_dport_sm_dynamic_disabling(struct bfa_dport_s *dport,
  5381. enum bfa_dport_sm_event event)
  5382. {
  5383. bfa_trc(dport->bfa, event);
  5384. switch (event) {
  5385. case BFA_DPORT_SM_SCN:
  5386. switch (dport->i2hmsg.scn.state) {
  5387. case BFI_DPORT_SCN_DDPORT_DISABLED:
  5388. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5389. dport->dynamic = BFA_FALSE;
  5390. bfa_fcport_enable(dport->bfa);
  5391. break;
  5392. default:
  5393. bfa_trc(dport->bfa, dport->i2hmsg.scn.state);
  5394. bfa_sm_fault(dport->bfa, event);
  5395. }
  5396. break;
  5397. case BFA_DPORT_SM_HWFAIL:
  5398. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5399. bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
  5400. break;
  5401. default:
  5402. bfa_sm_fault(dport->bfa, event);
  5403. }
  5404. }
  5405. static void
  5406. bfa_dport_sm_dynamic_disabling_qwait(struct bfa_dport_s *dport,
  5407. enum bfa_dport_sm_event event)
  5408. {
  5409. bfa_trc(dport->bfa, event);
  5410. switch (event) {
  5411. case BFA_DPORT_SM_QRESUME:
  5412. bfa_sm_set_state(dport, bfa_dport_sm_dynamic_disabling);
  5413. bfa_dport_send_req(dport, BFI_DPORT_DYN_DISABLE);
  5414. break;
  5415. case BFA_DPORT_SM_HWFAIL:
  5416. bfa_sm_set_state(dport, bfa_dport_sm_disabled);
  5417. bfa_reqq_wcancel(&dport->reqq_wait);
  5418. bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK);
  5419. break;
  5420. case BFA_DPORT_SM_SCN:
  5421. /* ignore */
  5422. break;
  5423. default:
  5424. bfa_sm_fault(dport->bfa, event);
  5425. }
  5426. }
  5427. static bfa_boolean_t
  5428. bfa_dport_send_req(struct bfa_dport_s *dport, enum bfi_dport_req req)
  5429. {
  5430. struct bfi_diag_dport_req_s *m;
  5431. /*
  5432. * check for room in queue to send request now
  5433. */
  5434. m = bfa_reqq_next(dport->bfa, BFA_REQQ_DIAG);
  5435. if (!m) {
  5436. bfa_reqq_wait(dport->bfa, BFA_REQQ_PORT, &dport->reqq_wait);
  5437. return BFA_FALSE;
  5438. }
  5439. bfi_h2i_set(m->mh, BFI_MC_DIAG, BFI_DIAG_H2I_DPORT,
  5440. bfa_fn_lpu(dport->bfa));
  5441. m->req = req;
  5442. if ((req == BFI_DPORT_ENABLE) || (req == BFI_DPORT_START)) {
  5443. m->lpcnt = cpu_to_be32(dport->lpcnt);
  5444. m->payload = cpu_to_be32(dport->payload);
  5445. }
  5446. /*
  5447. * queue I/O message to firmware
  5448. */
  5449. bfa_reqq_produce(dport->bfa, BFA_REQQ_DIAG, m->mh);
  5450. return BFA_TRUE;
  5451. }
  5452. static void
  5453. bfa_dport_qresume(void *cbarg)
  5454. {
  5455. struct bfa_dport_s *dport = cbarg;
  5456. bfa_sm_send_event(dport, BFA_DPORT_SM_QRESUME);
  5457. }
  5458. static void
  5459. bfa_dport_req_comp(struct bfa_dport_s *dport, struct bfi_diag_dport_rsp_s *msg)
  5460. {
  5461. msg->status = cpu_to_be32(msg->status);
  5462. dport->i2hmsg.rsp.status = msg->status;
  5463. dport->rp_pwwn = msg->pwwn;
  5464. dport->rp_nwwn = msg->nwwn;
  5465. if ((msg->status == BFA_STATUS_OK) ||
  5466. (msg->status == BFA_STATUS_DPORT_NO_SFP)) {
  5467. bfa_trc(dport->bfa, msg->status);
  5468. bfa_trc(dport->bfa, dport->rp_pwwn);
  5469. bfa_trc(dport->bfa, dport->rp_nwwn);
  5470. bfa_sm_send_event(dport, BFA_DPORT_SM_FWRSP);
  5471. } else {
  5472. bfa_trc(dport->bfa, msg->status);
  5473. bfa_sm_send_event(dport, BFA_DPORT_SM_REQFAIL);
  5474. }
  5475. bfa_cb_fcdiag_dport(dport, msg->status);
  5476. }
  5477. static bfa_boolean_t
  5478. bfa_dport_is_sending_req(struct bfa_dport_s *dport)
  5479. {
  5480. if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabling) ||
  5481. bfa_sm_cmp_state(dport, bfa_dport_sm_enabling_qwait) ||
  5482. bfa_sm_cmp_state(dport, bfa_dport_sm_disabling) ||
  5483. bfa_sm_cmp_state(dport, bfa_dport_sm_disabling_qwait) ||
  5484. bfa_sm_cmp_state(dport, bfa_dport_sm_starting) ||
  5485. bfa_sm_cmp_state(dport, bfa_dport_sm_starting_qwait)) {
  5486. return BFA_TRUE;
  5487. } else {
  5488. return BFA_FALSE;
  5489. }
  5490. }
  5491. static void
  5492. bfa_dport_scn(struct bfa_dport_s *dport, struct bfi_diag_dport_scn_s *msg)
  5493. {
  5494. int i;
  5495. uint8_t subtesttype;
  5496. bfa_trc(dport->bfa, msg->state);
  5497. dport->i2hmsg.scn.state = msg->state;
  5498. switch (dport->i2hmsg.scn.state) {
  5499. case BFI_DPORT_SCN_TESTCOMP:
  5500. dport->result.end_time = ktime_get_real_seconds();
  5501. bfa_trc(dport->bfa, dport->result.end_time);
  5502. dport->result.status = msg->info.testcomp.status;
  5503. bfa_trc(dport->bfa, dport->result.status);
  5504. dport->result.roundtrip_latency =
  5505. cpu_to_be32(msg->info.testcomp.latency);
  5506. dport->result.est_cable_distance =
  5507. cpu_to_be32(msg->info.testcomp.distance);
  5508. dport->result.buffer_required =
  5509. be16_to_cpu(msg->info.testcomp.numbuffer);
  5510. dport->result.frmsz = be16_to_cpu(msg->info.testcomp.frm_sz);
  5511. dport->result.speed = msg->info.testcomp.speed;
  5512. bfa_trc(dport->bfa, dport->result.roundtrip_latency);
  5513. bfa_trc(dport->bfa, dport->result.est_cable_distance);
  5514. bfa_trc(dport->bfa, dport->result.buffer_required);
  5515. bfa_trc(dport->bfa, dport->result.frmsz);
  5516. bfa_trc(dport->bfa, dport->result.speed);
  5517. for (i = DPORT_TEST_ELOOP; i < DPORT_TEST_MAX; i++) {
  5518. dport->result.subtest[i].status =
  5519. msg->info.testcomp.subtest_status[i];
  5520. bfa_trc(dport->bfa, dport->result.subtest[i].status);
  5521. }
  5522. break;
  5523. case BFI_DPORT_SCN_TESTSKIP:
  5524. case BFI_DPORT_SCN_DDPORT_ENABLE:
  5525. memset(&dport->result, 0,
  5526. sizeof(struct bfa_diag_dport_result_s));
  5527. break;
  5528. case BFI_DPORT_SCN_TESTSTART:
  5529. memset(&dport->result, 0,
  5530. sizeof(struct bfa_diag_dport_result_s));
  5531. dport->rp_pwwn = msg->info.teststart.pwwn;
  5532. dport->rp_nwwn = msg->info.teststart.nwwn;
  5533. dport->lpcnt = cpu_to_be32(msg->info.teststart.numfrm);
  5534. bfa_dport_result_start(dport, msg->info.teststart.mode);
  5535. break;
  5536. case BFI_DPORT_SCN_SUBTESTSTART:
  5537. subtesttype = msg->info.teststart.type;
  5538. dport->result.subtest[subtesttype].start_time =
  5539. ktime_get_real_seconds();
  5540. dport->result.subtest[subtesttype].status =
  5541. DPORT_TEST_ST_INPRG;
  5542. bfa_trc(dport->bfa, subtesttype);
  5543. bfa_trc(dport->bfa,
  5544. dport->result.subtest[subtesttype].start_time);
  5545. break;
  5546. case BFI_DPORT_SCN_SFP_REMOVED:
  5547. case BFI_DPORT_SCN_DDPORT_DISABLED:
  5548. case BFI_DPORT_SCN_DDPORT_DISABLE:
  5549. case BFI_DPORT_SCN_FCPORT_DISABLE:
  5550. dport->result.status = DPORT_TEST_ST_IDLE;
  5551. break;
  5552. default:
  5553. bfa_sm_fault(dport->bfa, msg->state);
  5554. }
  5555. bfa_sm_send_event(dport, BFA_DPORT_SM_SCN);
  5556. }
  5557. /*
  5558. * Dport enable
  5559. *
  5560. * @param[in] *bfa - bfa data struct
  5561. */
  5562. bfa_status_t
  5563. bfa_dport_enable(struct bfa_s *bfa, u32 lpcnt, u32 pat,
  5564. bfa_cb_diag_t cbfn, void *cbarg)
  5565. {
  5566. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  5567. struct bfa_dport_s *dport = &fcdiag->dport;
  5568. /*
  5569. * Dport is not support in MEZZ card
  5570. */
  5571. if (bfa_mfg_is_mezz(dport->bfa->ioc.attr->card_type)) {
  5572. bfa_trc(dport->bfa, BFA_STATUS_PBC);
  5573. return BFA_STATUS_CMD_NOTSUPP_MEZZ;
  5574. }
  5575. /*
  5576. * Dport is supported in CT2 or above
  5577. */
  5578. if (!(bfa_asic_id_ct2(dport->bfa->ioc.pcidev.device_id))) {
  5579. bfa_trc(dport->bfa, dport->bfa->ioc.pcidev.device_id);
  5580. return BFA_STATUS_FEATURE_NOT_SUPPORTED;
  5581. }
  5582. /*
  5583. * Check to see if IOC is down
  5584. */
  5585. if (!bfa_iocfc_is_operational(bfa))
  5586. return BFA_STATUS_IOC_NON_OP;
  5587. /* if port is PBC disabled, return error */
  5588. if (bfa_fcport_is_pbcdisabled(bfa)) {
  5589. bfa_trc(dport->bfa, BFA_STATUS_PBC);
  5590. return BFA_STATUS_PBC;
  5591. }
  5592. /*
  5593. * Check if port mode is FC port
  5594. */
  5595. if (bfa_ioc_get_type(&bfa->ioc) != BFA_IOC_TYPE_FC) {
  5596. bfa_trc(dport->bfa, bfa_ioc_get_type(&bfa->ioc));
  5597. return BFA_STATUS_CMD_NOTSUPP_CNA;
  5598. }
  5599. /*
  5600. * Check if port is in LOOP mode
  5601. */
  5602. if ((bfa_fcport_get_cfg_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) ||
  5603. (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)) {
  5604. bfa_trc(dport->bfa, 0);
  5605. return BFA_STATUS_TOPOLOGY_LOOP;
  5606. }
  5607. /*
  5608. * Check if port is TRUNK mode
  5609. */
  5610. if (bfa_fcport_is_trunk_enabled(bfa)) {
  5611. bfa_trc(dport->bfa, 0);
  5612. return BFA_STATUS_ERROR_TRUNK_ENABLED;
  5613. }
  5614. /*
  5615. * Check if diag loopback is running
  5616. */
  5617. if (bfa_fcdiag_lb_is_running(bfa)) {
  5618. bfa_trc(dport->bfa, 0);
  5619. return BFA_STATUS_DIAG_BUSY;
  5620. }
  5621. /*
  5622. * Check to see if port is disable or in dport state
  5623. */
  5624. if ((bfa_fcport_is_disabled(bfa) == BFA_FALSE) &&
  5625. (bfa_fcport_is_dport(bfa) == BFA_FALSE)) {
  5626. bfa_trc(dport->bfa, 0);
  5627. return BFA_STATUS_PORT_NOT_DISABLED;
  5628. }
  5629. /*
  5630. * Check if dport is in dynamic mode
  5631. */
  5632. if (dport->dynamic)
  5633. return BFA_STATUS_DDPORT_ERR;
  5634. /*
  5635. * Check if dport is busy
  5636. */
  5637. if (bfa_dport_is_sending_req(dport))
  5638. return BFA_STATUS_DEVBUSY;
  5639. /*
  5640. * Check if dport is already enabled
  5641. */
  5642. if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabled)) {
  5643. bfa_trc(dport->bfa, 0);
  5644. return BFA_STATUS_DPORT_ENABLED;
  5645. }
  5646. bfa_trc(dport->bfa, lpcnt);
  5647. bfa_trc(dport->bfa, pat);
  5648. dport->lpcnt = (lpcnt) ? lpcnt : DPORT_ENABLE_LOOPCNT_DEFAULT;
  5649. dport->payload = (pat) ? pat : LB_PATTERN_DEFAULT;
  5650. dport->cbfn = cbfn;
  5651. dport->cbarg = cbarg;
  5652. bfa_sm_send_event(dport, BFA_DPORT_SM_ENABLE);
  5653. return BFA_STATUS_OK;
  5654. }
  5655. /*
  5656. * Dport disable
  5657. *
  5658. * @param[in] *bfa - bfa data struct
  5659. */
  5660. bfa_status_t
  5661. bfa_dport_disable(struct bfa_s *bfa, bfa_cb_diag_t cbfn, void *cbarg)
  5662. {
  5663. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  5664. struct bfa_dport_s *dport = &fcdiag->dport;
  5665. if (bfa_ioc_is_disabled(&bfa->ioc))
  5666. return BFA_STATUS_IOC_DISABLED;
  5667. /* if port is PBC disabled, return error */
  5668. if (bfa_fcport_is_pbcdisabled(bfa)) {
  5669. bfa_trc(dport->bfa, BFA_STATUS_PBC);
  5670. return BFA_STATUS_PBC;
  5671. }
  5672. /*
  5673. * Check if dport is in dynamic mode
  5674. */
  5675. if (dport->dynamic) {
  5676. return BFA_STATUS_DDPORT_ERR;
  5677. }
  5678. /*
  5679. * Check to see if port is disable or in dport state
  5680. */
  5681. if ((bfa_fcport_is_disabled(bfa) == BFA_FALSE) &&
  5682. (bfa_fcport_is_dport(bfa) == BFA_FALSE)) {
  5683. bfa_trc(dport->bfa, 0);
  5684. return BFA_STATUS_PORT_NOT_DISABLED;
  5685. }
  5686. /*
  5687. * Check if dport is busy
  5688. */
  5689. if (bfa_dport_is_sending_req(dport))
  5690. return BFA_STATUS_DEVBUSY;
  5691. /*
  5692. * Check if dport is already disabled
  5693. */
  5694. if (bfa_sm_cmp_state(dport, bfa_dport_sm_disabled)) {
  5695. bfa_trc(dport->bfa, 0);
  5696. return BFA_STATUS_DPORT_DISABLED;
  5697. }
  5698. dport->cbfn = cbfn;
  5699. dport->cbarg = cbarg;
  5700. bfa_sm_send_event(dport, BFA_DPORT_SM_DISABLE);
  5701. return BFA_STATUS_OK;
  5702. }
  5703. /*
  5704. * Dport start -- restart dport test
  5705. *
  5706. * @param[in] *bfa - bfa data struct
  5707. */
  5708. bfa_status_t
  5709. bfa_dport_start(struct bfa_s *bfa, u32 lpcnt, u32 pat,
  5710. bfa_cb_diag_t cbfn, void *cbarg)
  5711. {
  5712. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  5713. struct bfa_dport_s *dport = &fcdiag->dport;
  5714. /*
  5715. * Check to see if IOC is down
  5716. */
  5717. if (!bfa_iocfc_is_operational(bfa))
  5718. return BFA_STATUS_IOC_NON_OP;
  5719. /*
  5720. * Check if dport is in dynamic mode
  5721. */
  5722. if (dport->dynamic)
  5723. return BFA_STATUS_DDPORT_ERR;
  5724. /*
  5725. * Check if dport is busy
  5726. */
  5727. if (bfa_dport_is_sending_req(dport))
  5728. return BFA_STATUS_DEVBUSY;
  5729. /*
  5730. * Check if dport is in enabled state.
  5731. * Test can only be restart when previous test has completed
  5732. */
  5733. if (!bfa_sm_cmp_state(dport, bfa_dport_sm_enabled)) {
  5734. bfa_trc(dport->bfa, 0);
  5735. return BFA_STATUS_DPORT_DISABLED;
  5736. } else {
  5737. if (dport->test_state == BFA_DPORT_ST_NO_SFP)
  5738. return BFA_STATUS_DPORT_INV_SFP;
  5739. if (dport->test_state == BFA_DPORT_ST_INP)
  5740. return BFA_STATUS_DEVBUSY;
  5741. WARN_ON(dport->test_state != BFA_DPORT_ST_COMP);
  5742. }
  5743. bfa_trc(dport->bfa, lpcnt);
  5744. bfa_trc(dport->bfa, pat);
  5745. dport->lpcnt = (lpcnt) ? lpcnt : DPORT_ENABLE_LOOPCNT_DEFAULT;
  5746. dport->payload = (pat) ? pat : LB_PATTERN_DEFAULT;
  5747. dport->cbfn = cbfn;
  5748. dport->cbarg = cbarg;
  5749. bfa_sm_send_event(dport, BFA_DPORT_SM_START);
  5750. return BFA_STATUS_OK;
  5751. }
  5752. /*
  5753. * Dport show -- return dport test result
  5754. *
  5755. * @param[in] *bfa - bfa data struct
  5756. */
  5757. bfa_status_t
  5758. bfa_dport_show(struct bfa_s *bfa, struct bfa_diag_dport_result_s *result)
  5759. {
  5760. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  5761. struct bfa_dport_s *dport = &fcdiag->dport;
  5762. /*
  5763. * Check to see if IOC is down
  5764. */
  5765. if (!bfa_iocfc_is_operational(bfa))
  5766. return BFA_STATUS_IOC_NON_OP;
  5767. /*
  5768. * Check if dport is busy
  5769. */
  5770. if (bfa_dport_is_sending_req(dport))
  5771. return BFA_STATUS_DEVBUSY;
  5772. /*
  5773. * Check if dport is in enabled state.
  5774. */
  5775. if (!bfa_sm_cmp_state(dport, bfa_dport_sm_enabled)) {
  5776. bfa_trc(dport->bfa, 0);
  5777. return BFA_STATUS_DPORT_DISABLED;
  5778. }
  5779. /*
  5780. * Check if there is SFP
  5781. */
  5782. if (dport->test_state == BFA_DPORT_ST_NO_SFP)
  5783. return BFA_STATUS_DPORT_INV_SFP;
  5784. memcpy(result, &dport->result, sizeof(struct bfa_diag_dport_result_s));
  5785. return BFA_STATUS_OK;
  5786. }