bfa_ioc.c 136 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946
  1. /*
  2. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include "bfad_drv.h"
  18. #include "bfad_im.h"
  19. #include "bfa_ioc.h"
  20. #include "bfi_reg.h"
  21. #include "bfa_defs.h"
  22. #include "bfa_defs_svc.h"
  23. BFA_TRC_FILE(CNA, IOC);
  24. /*
  25. * IOC local definitions
  26. */
  27. #define BFA_IOC_TOV 3000 /* msecs */
  28. #define BFA_IOC_HWSEM_TOV 500 /* msecs */
  29. #define BFA_IOC_HB_TOV 500 /* msecs */
  30. #define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
  31. #define BFA_IOC_POLL_TOV BFA_TIMER_FREQ
  32. #define bfa_ioc_timer_start(__ioc) \
  33. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
  34. bfa_ioc_timeout, (__ioc), BFA_IOC_TOV)
  35. #define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
  36. #define bfa_hb_timer_start(__ioc) \
  37. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->hb_timer, \
  38. bfa_ioc_hb_check, (__ioc), BFA_IOC_HB_TOV)
  39. #define bfa_hb_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->hb_timer)
  40. #define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
  41. /*
  42. * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
  43. */
  44. #define bfa_ioc_firmware_lock(__ioc) \
  45. ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
  46. #define bfa_ioc_firmware_unlock(__ioc) \
  47. ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
  48. #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
  49. #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
  50. #define bfa_ioc_notify_fail(__ioc) \
  51. ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
  52. #define bfa_ioc_sync_start(__ioc) \
  53. ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
  54. #define bfa_ioc_sync_join(__ioc) \
  55. ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
  56. #define bfa_ioc_sync_leave(__ioc) \
  57. ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
  58. #define bfa_ioc_sync_ack(__ioc) \
  59. ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
  60. #define bfa_ioc_sync_complete(__ioc) \
  61. ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
  62. #define bfa_ioc_mbox_cmd_pending(__ioc) \
  63. (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
  64. readl((__ioc)->ioc_regs.hfn_mbox_cmd))
  65. bfa_boolean_t bfa_auto_recover = BFA_TRUE;
  66. /*
  67. * forward declarations
  68. */
  69. static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
  70. static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
  71. static void bfa_ioc_timeout(void *ioc);
  72. static void bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc);
  73. static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
  74. static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
  75. static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
  76. static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
  77. static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
  78. static void bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc);
  79. static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
  80. static void bfa_ioc_event_notify(struct bfa_ioc_s *ioc ,
  81. enum bfa_ioc_event_e event);
  82. static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
  83. static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
  84. static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc);
  85. static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
  86. /*
  87. * IOC state machine definitions/declarations
  88. */
  89. enum ioc_event {
  90. IOC_E_RESET = 1, /* IOC reset request */
  91. IOC_E_ENABLE = 2, /* IOC enable request */
  92. IOC_E_DISABLE = 3, /* IOC disable request */
  93. IOC_E_DETACH = 4, /* driver detach cleanup */
  94. IOC_E_ENABLED = 5, /* f/w enabled */
  95. IOC_E_FWRSP_GETATTR = 6, /* IOC get attribute response */
  96. IOC_E_DISABLED = 7, /* f/w disabled */
  97. IOC_E_PFFAILED = 8, /* failure notice by iocpf sm */
  98. IOC_E_HBFAIL = 9, /* heartbeat failure */
  99. IOC_E_HWERROR = 10, /* hardware error interrupt */
  100. IOC_E_TIMEOUT = 11, /* timeout */
  101. IOC_E_HWFAILED = 12, /* PCI mapping failure notice */
  102. };
  103. bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event);
  104. bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
  105. bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
  106. bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
  107. bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
  108. bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc_s, enum ioc_event);
  109. bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event);
  110. bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
  111. bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
  112. bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc_s, enum ioc_event);
  113. static struct bfa_sm_table_s ioc_sm_table[] = {
  114. {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
  115. {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
  116. {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
  117. {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
  118. {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
  119. {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
  120. {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
  121. {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
  122. {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
  123. {BFA_SM(bfa_ioc_sm_hwfail), BFA_IOC_HWFAIL},
  124. };
  125. /*
  126. * IOCPF state machine definitions/declarations
  127. */
  128. #define bfa_iocpf_timer_start(__ioc) \
  129. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
  130. bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
  131. #define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
  132. #define bfa_iocpf_poll_timer_start(__ioc) \
  133. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
  134. bfa_iocpf_poll_timeout, (__ioc), BFA_IOC_POLL_TOV)
  135. #define bfa_sem_timer_start(__ioc) \
  136. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
  137. bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
  138. #define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
  139. /*
  140. * Forward declareations for iocpf state machine
  141. */
  142. static void bfa_iocpf_timeout(void *ioc_arg);
  143. static void bfa_iocpf_sem_timeout(void *ioc_arg);
  144. static void bfa_iocpf_poll_timeout(void *ioc_arg);
  145. /*
  146. * IOCPF state machine events
  147. */
  148. enum iocpf_event {
  149. IOCPF_E_ENABLE = 1, /* IOCPF enable request */
  150. IOCPF_E_DISABLE = 2, /* IOCPF disable request */
  151. IOCPF_E_STOP = 3, /* stop on driver detach */
  152. IOCPF_E_FWREADY = 4, /* f/w initialization done */
  153. IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */
  154. IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */
  155. IOCPF_E_FAIL = 7, /* failure notice by ioc sm */
  156. IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */
  157. IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */
  158. IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */
  159. IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
  160. IOCPF_E_SEM_ERROR = 12, /* h/w sem mapping error */
  161. };
  162. /*
  163. * IOCPF states
  164. */
  165. enum bfa_iocpf_state {
  166. BFA_IOCPF_RESET = 1, /* IOC is in reset state */
  167. BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
  168. BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
  169. BFA_IOCPF_READY = 4, /* IOCPF is initialized */
  170. BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
  171. BFA_IOCPF_FAIL = 6, /* IOCPF failed */
  172. BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
  173. BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
  174. BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
  175. };
  176. bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
  177. bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
  178. bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
  179. bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
  180. bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
  181. bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
  182. bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
  183. bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s,
  184. enum iocpf_event);
  185. bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
  186. bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event);
  187. bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
  188. bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
  189. bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s,
  190. enum iocpf_event);
  191. bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
  192. static struct bfa_sm_table_s iocpf_sm_table[] = {
  193. {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
  194. {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
  195. {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
  196. {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
  197. {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
  198. {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
  199. {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
  200. {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
  201. {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
  202. {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
  203. {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
  204. {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
  205. {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
  206. {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
  207. };
  208. /*
  209. * IOC State Machine
  210. */
  211. /*
  212. * Beginning state. IOC uninit state.
  213. */
  214. static void
  215. bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
  216. {
  217. }
  218. /*
  219. * IOC is in uninit state.
  220. */
  221. static void
  222. bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
  223. {
  224. bfa_trc(ioc, event);
  225. switch (event) {
  226. case IOC_E_RESET:
  227. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  228. break;
  229. default:
  230. bfa_sm_fault(ioc, event);
  231. }
  232. }
  233. /*
  234. * Reset entry actions -- initialize state machine
  235. */
  236. static void
  237. bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
  238. {
  239. bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
  240. }
  241. /*
  242. * IOC is in reset state.
  243. */
  244. static void
  245. bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
  246. {
  247. bfa_trc(ioc, event);
  248. switch (event) {
  249. case IOC_E_ENABLE:
  250. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  251. break;
  252. case IOC_E_DISABLE:
  253. bfa_ioc_disable_comp(ioc);
  254. break;
  255. case IOC_E_DETACH:
  256. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  257. break;
  258. default:
  259. bfa_sm_fault(ioc, event);
  260. }
  261. }
  262. static void
  263. bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
  264. {
  265. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
  266. }
  267. /*
  268. * Host IOC function is being enabled, awaiting response from firmware.
  269. * Semaphore is acquired.
  270. */
  271. static void
  272. bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
  273. {
  274. bfa_trc(ioc, event);
  275. switch (event) {
  276. case IOC_E_ENABLED:
  277. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  278. break;
  279. case IOC_E_PFFAILED:
  280. /* !!! fall through !!! */
  281. case IOC_E_HWERROR:
  282. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  283. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  284. if (event != IOC_E_PFFAILED)
  285. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
  286. break;
  287. case IOC_E_HWFAILED:
  288. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  289. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  290. break;
  291. case IOC_E_DISABLE:
  292. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  293. break;
  294. case IOC_E_DETACH:
  295. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  296. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  297. break;
  298. case IOC_E_ENABLE:
  299. break;
  300. default:
  301. bfa_sm_fault(ioc, event);
  302. }
  303. }
  304. static void
  305. bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
  306. {
  307. bfa_ioc_timer_start(ioc);
  308. bfa_ioc_send_getattr(ioc);
  309. }
  310. /*
  311. * IOC configuration in progress. Timer is active.
  312. */
  313. static void
  314. bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
  315. {
  316. bfa_trc(ioc, event);
  317. switch (event) {
  318. case IOC_E_FWRSP_GETATTR:
  319. bfa_ioc_timer_stop(ioc);
  320. bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
  321. break;
  322. case IOC_E_PFFAILED:
  323. case IOC_E_HWERROR:
  324. bfa_ioc_timer_stop(ioc);
  325. /* !!! fall through !!! */
  326. case IOC_E_TIMEOUT:
  327. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  328. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  329. if (event != IOC_E_PFFAILED)
  330. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
  331. break;
  332. case IOC_E_DISABLE:
  333. bfa_ioc_timer_stop(ioc);
  334. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  335. break;
  336. case IOC_E_ENABLE:
  337. break;
  338. default:
  339. bfa_sm_fault(ioc, event);
  340. }
  341. }
  342. static void
  343. bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
  344. {
  345. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  346. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
  347. bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
  348. bfa_ioc_hb_monitor(ioc);
  349. BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
  350. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_ENABLE);
  351. }
  352. static void
  353. bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
  354. {
  355. bfa_trc(ioc, event);
  356. switch (event) {
  357. case IOC_E_ENABLE:
  358. break;
  359. case IOC_E_DISABLE:
  360. bfa_hb_timer_stop(ioc);
  361. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  362. break;
  363. case IOC_E_PFFAILED:
  364. case IOC_E_HWERROR:
  365. bfa_hb_timer_stop(ioc);
  366. /* !!! fall through !!! */
  367. case IOC_E_HBFAIL:
  368. if (ioc->iocpf.auto_recover)
  369. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
  370. else
  371. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  372. bfa_ioc_fail_notify(ioc);
  373. if (event != IOC_E_PFFAILED)
  374. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
  375. break;
  376. default:
  377. bfa_sm_fault(ioc, event);
  378. }
  379. }
  380. static void
  381. bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
  382. {
  383. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  384. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
  385. BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
  386. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_DISABLE);
  387. }
  388. /*
  389. * IOC is being disabled
  390. */
  391. static void
  392. bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
  393. {
  394. bfa_trc(ioc, event);
  395. switch (event) {
  396. case IOC_E_DISABLED:
  397. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  398. break;
  399. case IOC_E_HWERROR:
  400. /*
  401. * No state change. Will move to disabled state
  402. * after iocpf sm completes failure processing and
  403. * moves to disabled state.
  404. */
  405. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
  406. break;
  407. case IOC_E_HWFAILED:
  408. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  409. bfa_ioc_disable_comp(ioc);
  410. break;
  411. default:
  412. bfa_sm_fault(ioc, event);
  413. }
  414. }
  415. /*
  416. * IOC disable completion entry.
  417. */
  418. static void
  419. bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
  420. {
  421. bfa_ioc_disable_comp(ioc);
  422. }
  423. static void
  424. bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
  425. {
  426. bfa_trc(ioc, event);
  427. switch (event) {
  428. case IOC_E_ENABLE:
  429. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  430. break;
  431. case IOC_E_DISABLE:
  432. ioc->cbfn->disable_cbfn(ioc->bfa);
  433. break;
  434. case IOC_E_DETACH:
  435. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  436. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  437. break;
  438. default:
  439. bfa_sm_fault(ioc, event);
  440. }
  441. }
  442. static void
  443. bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc)
  444. {
  445. bfa_trc(ioc, 0);
  446. }
  447. /*
  448. * Hardware initialization retry.
  449. */
  450. static void
  451. bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event)
  452. {
  453. bfa_trc(ioc, event);
  454. switch (event) {
  455. case IOC_E_ENABLED:
  456. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  457. break;
  458. case IOC_E_PFFAILED:
  459. case IOC_E_HWERROR:
  460. /*
  461. * Initialization retry failed.
  462. */
  463. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  464. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  465. if (event != IOC_E_PFFAILED)
  466. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
  467. break;
  468. case IOC_E_HWFAILED:
  469. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  470. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  471. break;
  472. case IOC_E_ENABLE:
  473. break;
  474. case IOC_E_DISABLE:
  475. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  476. break;
  477. case IOC_E_DETACH:
  478. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  479. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  480. break;
  481. default:
  482. bfa_sm_fault(ioc, event);
  483. }
  484. }
  485. static void
  486. bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
  487. {
  488. bfa_trc(ioc, 0);
  489. }
  490. /*
  491. * IOC failure.
  492. */
  493. static void
  494. bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
  495. {
  496. bfa_trc(ioc, event);
  497. switch (event) {
  498. case IOC_E_ENABLE:
  499. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  500. break;
  501. case IOC_E_DISABLE:
  502. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  503. break;
  504. case IOC_E_DETACH:
  505. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  506. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  507. break;
  508. case IOC_E_HWERROR:
  509. case IOC_E_HWFAILED:
  510. /*
  511. * HB failure / HW error notification, ignore.
  512. */
  513. break;
  514. default:
  515. bfa_sm_fault(ioc, event);
  516. }
  517. }
  518. static void
  519. bfa_ioc_sm_hwfail_entry(struct bfa_ioc_s *ioc)
  520. {
  521. bfa_trc(ioc, 0);
  522. }
  523. static void
  524. bfa_ioc_sm_hwfail(struct bfa_ioc_s *ioc, enum ioc_event event)
  525. {
  526. bfa_trc(ioc, event);
  527. switch (event) {
  528. case IOC_E_ENABLE:
  529. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  530. break;
  531. case IOC_E_DISABLE:
  532. ioc->cbfn->disable_cbfn(ioc->bfa);
  533. break;
  534. case IOC_E_DETACH:
  535. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  536. break;
  537. case IOC_E_HWERROR:
  538. /* Ignore - already in hwfail state */
  539. break;
  540. default:
  541. bfa_sm_fault(ioc, event);
  542. }
  543. }
  544. /*
  545. * IOCPF State Machine
  546. */
  547. /*
  548. * Reset entry actions -- initialize state machine
  549. */
  550. static void
  551. bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
  552. {
  553. iocpf->fw_mismatch_notified = BFA_FALSE;
  554. iocpf->auto_recover = bfa_auto_recover;
  555. }
  556. /*
  557. * Beginning state. IOC is in reset state.
  558. */
  559. static void
  560. bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  561. {
  562. struct bfa_ioc_s *ioc = iocpf->ioc;
  563. bfa_trc(ioc, event);
  564. switch (event) {
  565. case IOCPF_E_ENABLE:
  566. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
  567. break;
  568. case IOCPF_E_STOP:
  569. break;
  570. default:
  571. bfa_sm_fault(ioc, event);
  572. }
  573. }
  574. /*
  575. * Semaphore should be acquired for version check.
  576. */
  577. static void
  578. bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
  579. {
  580. struct bfi_ioc_image_hdr_s fwhdr;
  581. u32 r32, fwstate, pgnum, pgoff, loff = 0;
  582. int i;
  583. /*
  584. * Spin on init semaphore to serialize.
  585. */
  586. r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg);
  587. while (r32 & 0x1) {
  588. udelay(20);
  589. r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg);
  590. }
  591. /* h/w sem init */
  592. fwstate = readl(iocpf->ioc->ioc_regs.ioc_fwstate);
  593. if (fwstate == BFI_IOC_UNINIT) {
  594. writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
  595. goto sem_get;
  596. }
  597. bfa_ioc_fwver_get(iocpf->ioc, &fwhdr);
  598. if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL) {
  599. writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
  600. goto sem_get;
  601. }
  602. /*
  603. * Clear fwver hdr
  604. */
  605. pgnum = PSS_SMEM_PGNUM(iocpf->ioc->ioc_regs.smem_pg0, loff);
  606. pgoff = PSS_SMEM_PGOFF(loff);
  607. writel(pgnum, iocpf->ioc->ioc_regs.host_page_num_fn);
  608. for (i = 0; i < sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32); i++) {
  609. bfa_mem_write(iocpf->ioc->ioc_regs.smem_page_start, loff, 0);
  610. loff += sizeof(u32);
  611. }
  612. bfa_trc(iocpf->ioc, fwstate);
  613. bfa_trc(iocpf->ioc, swab32(fwhdr.exec));
  614. writel(BFI_IOC_UNINIT, iocpf->ioc->ioc_regs.ioc_fwstate);
  615. writel(BFI_IOC_UNINIT, iocpf->ioc->ioc_regs.alt_ioc_fwstate);
  616. /*
  617. * Unlock the hw semaphore. Should be here only once per boot.
  618. */
  619. bfa_ioc_ownership_reset(iocpf->ioc);
  620. /*
  621. * unlock init semaphore.
  622. */
  623. writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
  624. sem_get:
  625. bfa_ioc_hw_sem_get(iocpf->ioc);
  626. }
  627. /*
  628. * Awaiting h/w semaphore to continue with version check.
  629. */
  630. static void
  631. bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  632. {
  633. struct bfa_ioc_s *ioc = iocpf->ioc;
  634. bfa_trc(ioc, event);
  635. switch (event) {
  636. case IOCPF_E_SEMLOCKED:
  637. if (bfa_ioc_firmware_lock(ioc)) {
  638. if (bfa_ioc_sync_start(ioc)) {
  639. bfa_ioc_sync_join(ioc);
  640. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  641. } else {
  642. bfa_ioc_firmware_unlock(ioc);
  643. writel(1, ioc->ioc_regs.ioc_sem_reg);
  644. bfa_sem_timer_start(ioc);
  645. }
  646. } else {
  647. writel(1, ioc->ioc_regs.ioc_sem_reg);
  648. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
  649. }
  650. break;
  651. case IOCPF_E_SEM_ERROR:
  652. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  653. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  654. break;
  655. case IOCPF_E_DISABLE:
  656. bfa_sem_timer_stop(ioc);
  657. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  658. bfa_fsm_send_event(ioc, IOC_E_DISABLED);
  659. break;
  660. case IOCPF_E_STOP:
  661. bfa_sem_timer_stop(ioc);
  662. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  663. break;
  664. default:
  665. bfa_sm_fault(ioc, event);
  666. }
  667. }
  668. /*
  669. * Notify enable completion callback.
  670. */
  671. static void
  672. bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
  673. {
  674. /*
  675. * Call only the first time sm enters fwmismatch state.
  676. */
  677. if (iocpf->fw_mismatch_notified == BFA_FALSE)
  678. bfa_ioc_pf_fwmismatch(iocpf->ioc);
  679. iocpf->fw_mismatch_notified = BFA_TRUE;
  680. bfa_iocpf_timer_start(iocpf->ioc);
  681. }
  682. /*
  683. * Awaiting firmware version match.
  684. */
  685. static void
  686. bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  687. {
  688. struct bfa_ioc_s *ioc = iocpf->ioc;
  689. bfa_trc(ioc, event);
  690. switch (event) {
  691. case IOCPF_E_TIMEOUT:
  692. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
  693. break;
  694. case IOCPF_E_DISABLE:
  695. bfa_iocpf_timer_stop(ioc);
  696. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  697. bfa_fsm_send_event(ioc, IOC_E_DISABLED);
  698. break;
  699. case IOCPF_E_STOP:
  700. bfa_iocpf_timer_stop(ioc);
  701. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  702. break;
  703. default:
  704. bfa_sm_fault(ioc, event);
  705. }
  706. }
  707. /*
  708. * Request for semaphore.
  709. */
  710. static void
  711. bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
  712. {
  713. bfa_ioc_hw_sem_get(iocpf->ioc);
  714. }
  715. /*
  716. * Awaiting semaphore for h/w initialzation.
  717. */
  718. static void
  719. bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  720. {
  721. struct bfa_ioc_s *ioc = iocpf->ioc;
  722. bfa_trc(ioc, event);
  723. switch (event) {
  724. case IOCPF_E_SEMLOCKED:
  725. if (bfa_ioc_sync_complete(ioc)) {
  726. bfa_ioc_sync_join(ioc);
  727. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  728. } else {
  729. writel(1, ioc->ioc_regs.ioc_sem_reg);
  730. bfa_sem_timer_start(ioc);
  731. }
  732. break;
  733. case IOCPF_E_SEM_ERROR:
  734. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  735. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  736. break;
  737. case IOCPF_E_DISABLE:
  738. bfa_sem_timer_stop(ioc);
  739. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  740. break;
  741. default:
  742. bfa_sm_fault(ioc, event);
  743. }
  744. }
  745. static void
  746. bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
  747. {
  748. iocpf->poll_time = 0;
  749. bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE);
  750. }
  751. /*
  752. * Hardware is being initialized. Interrupts are enabled.
  753. * Holding hardware semaphore lock.
  754. */
  755. static void
  756. bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  757. {
  758. struct bfa_ioc_s *ioc = iocpf->ioc;
  759. bfa_trc(ioc, event);
  760. switch (event) {
  761. case IOCPF_E_FWREADY:
  762. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
  763. break;
  764. case IOCPF_E_TIMEOUT:
  765. writel(1, ioc->ioc_regs.ioc_sem_reg);
  766. bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
  767. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  768. break;
  769. case IOCPF_E_DISABLE:
  770. bfa_iocpf_timer_stop(ioc);
  771. bfa_ioc_sync_leave(ioc);
  772. writel(1, ioc->ioc_regs.ioc_sem_reg);
  773. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  774. break;
  775. default:
  776. bfa_sm_fault(ioc, event);
  777. }
  778. }
  779. static void
  780. bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
  781. {
  782. bfa_iocpf_timer_start(iocpf->ioc);
  783. /*
  784. * Enable Interrupts before sending fw IOC ENABLE cmd.
  785. */
  786. iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa);
  787. bfa_ioc_send_enable(iocpf->ioc);
  788. }
  789. /*
  790. * Host IOC function is being enabled, awaiting response from firmware.
  791. * Semaphore is acquired.
  792. */
  793. static void
  794. bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  795. {
  796. struct bfa_ioc_s *ioc = iocpf->ioc;
  797. bfa_trc(ioc, event);
  798. switch (event) {
  799. case IOCPF_E_FWRSP_ENABLE:
  800. bfa_iocpf_timer_stop(ioc);
  801. writel(1, ioc->ioc_regs.ioc_sem_reg);
  802. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
  803. break;
  804. case IOCPF_E_INITFAIL:
  805. bfa_iocpf_timer_stop(ioc);
  806. /*
  807. * !!! fall through !!!
  808. */
  809. case IOCPF_E_TIMEOUT:
  810. writel(1, ioc->ioc_regs.ioc_sem_reg);
  811. if (event == IOCPF_E_TIMEOUT)
  812. bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
  813. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  814. break;
  815. case IOCPF_E_DISABLE:
  816. bfa_iocpf_timer_stop(ioc);
  817. writel(1, ioc->ioc_regs.ioc_sem_reg);
  818. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
  819. break;
  820. default:
  821. bfa_sm_fault(ioc, event);
  822. }
  823. }
  824. static void
  825. bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
  826. {
  827. bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED);
  828. }
  829. static void
  830. bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  831. {
  832. struct bfa_ioc_s *ioc = iocpf->ioc;
  833. bfa_trc(ioc, event);
  834. switch (event) {
  835. case IOCPF_E_DISABLE:
  836. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
  837. break;
  838. case IOCPF_E_GETATTRFAIL:
  839. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  840. break;
  841. case IOCPF_E_FAIL:
  842. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
  843. break;
  844. default:
  845. bfa_sm_fault(ioc, event);
  846. }
  847. }
  848. static void
  849. bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
  850. {
  851. bfa_iocpf_timer_start(iocpf->ioc);
  852. bfa_ioc_send_disable(iocpf->ioc);
  853. }
  854. /*
  855. * IOC is being disabled
  856. */
  857. static void
  858. bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  859. {
  860. struct bfa_ioc_s *ioc = iocpf->ioc;
  861. bfa_trc(ioc, event);
  862. switch (event) {
  863. case IOCPF_E_FWRSP_DISABLE:
  864. bfa_iocpf_timer_stop(ioc);
  865. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  866. break;
  867. case IOCPF_E_FAIL:
  868. bfa_iocpf_timer_stop(ioc);
  869. /*
  870. * !!! fall through !!!
  871. */
  872. case IOCPF_E_TIMEOUT:
  873. writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
  874. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  875. break;
  876. case IOCPF_E_FWRSP_ENABLE:
  877. break;
  878. default:
  879. bfa_sm_fault(ioc, event);
  880. }
  881. }
  882. static void
  883. bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf)
  884. {
  885. bfa_ioc_hw_sem_get(iocpf->ioc);
  886. }
  887. /*
  888. * IOC hb ack request is being removed.
  889. */
  890. static void
  891. bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  892. {
  893. struct bfa_ioc_s *ioc = iocpf->ioc;
  894. bfa_trc(ioc, event);
  895. switch (event) {
  896. case IOCPF_E_SEMLOCKED:
  897. bfa_ioc_sync_leave(ioc);
  898. writel(1, ioc->ioc_regs.ioc_sem_reg);
  899. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  900. break;
  901. case IOCPF_E_SEM_ERROR:
  902. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  903. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  904. break;
  905. case IOCPF_E_FAIL:
  906. break;
  907. default:
  908. bfa_sm_fault(ioc, event);
  909. }
  910. }
  911. /*
  912. * IOC disable completion entry.
  913. */
  914. static void
  915. bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
  916. {
  917. bfa_ioc_mbox_flush(iocpf->ioc);
  918. bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED);
  919. }
  920. static void
  921. bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  922. {
  923. struct bfa_ioc_s *ioc = iocpf->ioc;
  924. bfa_trc(ioc, event);
  925. switch (event) {
  926. case IOCPF_E_ENABLE:
  927. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  928. break;
  929. case IOCPF_E_STOP:
  930. bfa_ioc_firmware_unlock(ioc);
  931. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  932. break;
  933. default:
  934. bfa_sm_fault(ioc, event);
  935. }
  936. }
  937. static void
  938. bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf)
  939. {
  940. bfa_ioc_debug_save_ftrc(iocpf->ioc);
  941. bfa_ioc_hw_sem_get(iocpf->ioc);
  942. }
  943. /*
  944. * Hardware initialization failed.
  945. */
  946. static void
  947. bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  948. {
  949. struct bfa_ioc_s *ioc = iocpf->ioc;
  950. bfa_trc(ioc, event);
  951. switch (event) {
  952. case IOCPF_E_SEMLOCKED:
  953. bfa_ioc_notify_fail(ioc);
  954. bfa_ioc_sync_leave(ioc);
  955. writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
  956. writel(1, ioc->ioc_regs.ioc_sem_reg);
  957. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
  958. break;
  959. case IOCPF_E_SEM_ERROR:
  960. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  961. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  962. break;
  963. case IOCPF_E_DISABLE:
  964. bfa_sem_timer_stop(ioc);
  965. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  966. break;
  967. case IOCPF_E_STOP:
  968. bfa_sem_timer_stop(ioc);
  969. bfa_ioc_firmware_unlock(ioc);
  970. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  971. break;
  972. case IOCPF_E_FAIL:
  973. break;
  974. default:
  975. bfa_sm_fault(ioc, event);
  976. }
  977. }
  978. static void
  979. bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
  980. {
  981. bfa_trc(iocpf->ioc, 0);
  982. }
  983. /*
  984. * Hardware initialization failed.
  985. */
  986. static void
  987. bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  988. {
  989. struct bfa_ioc_s *ioc = iocpf->ioc;
  990. bfa_trc(ioc, event);
  991. switch (event) {
  992. case IOCPF_E_DISABLE:
  993. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  994. break;
  995. case IOCPF_E_STOP:
  996. bfa_ioc_firmware_unlock(ioc);
  997. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  998. break;
  999. default:
  1000. bfa_sm_fault(ioc, event);
  1001. }
  1002. }
  1003. static void
  1004. bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
  1005. {
  1006. /*
  1007. * Mark IOC as failed in hardware and stop firmware.
  1008. */
  1009. bfa_ioc_lpu_stop(iocpf->ioc);
  1010. /*
  1011. * Flush any queued up mailbox requests.
  1012. */
  1013. bfa_ioc_mbox_flush(iocpf->ioc);
  1014. bfa_ioc_hw_sem_get(iocpf->ioc);
  1015. }
  1016. static void
  1017. bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  1018. {
  1019. struct bfa_ioc_s *ioc = iocpf->ioc;
  1020. bfa_trc(ioc, event);
  1021. switch (event) {
  1022. case IOCPF_E_SEMLOCKED:
  1023. bfa_ioc_sync_ack(ioc);
  1024. bfa_ioc_notify_fail(ioc);
  1025. if (!iocpf->auto_recover) {
  1026. bfa_ioc_sync_leave(ioc);
  1027. writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
  1028. writel(1, ioc->ioc_regs.ioc_sem_reg);
  1029. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  1030. } else {
  1031. if (bfa_ioc_sync_complete(ioc))
  1032. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  1033. else {
  1034. writel(1, ioc->ioc_regs.ioc_sem_reg);
  1035. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  1036. }
  1037. }
  1038. break;
  1039. case IOCPF_E_SEM_ERROR:
  1040. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  1041. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  1042. break;
  1043. case IOCPF_E_DISABLE:
  1044. bfa_sem_timer_stop(ioc);
  1045. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  1046. break;
  1047. case IOCPF_E_FAIL:
  1048. break;
  1049. default:
  1050. bfa_sm_fault(ioc, event);
  1051. }
  1052. }
  1053. static void
  1054. bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
  1055. {
  1056. bfa_trc(iocpf->ioc, 0);
  1057. }
  1058. /*
  1059. * IOC is in failed state.
  1060. */
  1061. static void
  1062. bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  1063. {
  1064. struct bfa_ioc_s *ioc = iocpf->ioc;
  1065. bfa_trc(ioc, event);
  1066. switch (event) {
  1067. case IOCPF_E_DISABLE:
  1068. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  1069. break;
  1070. default:
  1071. bfa_sm_fault(ioc, event);
  1072. }
  1073. }
  1074. /*
  1075. * BFA IOC private functions
  1076. */
  1077. /*
  1078. * Notify common modules registered for notification.
  1079. */
  1080. static void
  1081. bfa_ioc_event_notify(struct bfa_ioc_s *ioc, enum bfa_ioc_event_e event)
  1082. {
  1083. struct bfa_ioc_notify_s *notify;
  1084. struct list_head *qe;
  1085. list_for_each(qe, &ioc->notify_q) {
  1086. notify = (struct bfa_ioc_notify_s *)qe;
  1087. notify->cbfn(notify->cbarg, event);
  1088. }
  1089. }
  1090. static void
  1091. bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
  1092. {
  1093. ioc->cbfn->disable_cbfn(ioc->bfa);
  1094. bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
  1095. }
  1096. bfa_boolean_t
  1097. bfa_ioc_sem_get(void __iomem *sem_reg)
  1098. {
  1099. u32 r32;
  1100. int cnt = 0;
  1101. #define BFA_SEM_SPINCNT 3000
  1102. r32 = readl(sem_reg);
  1103. while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) {
  1104. cnt++;
  1105. udelay(2);
  1106. r32 = readl(sem_reg);
  1107. }
  1108. if (!(r32 & 1))
  1109. return BFA_TRUE;
  1110. return BFA_FALSE;
  1111. }
  1112. static void
  1113. bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
  1114. {
  1115. u32 r32;
  1116. /*
  1117. * First read to the semaphore register will return 0, subsequent reads
  1118. * will return 1. Semaphore is released by writing 1 to the register
  1119. */
  1120. r32 = readl(ioc->ioc_regs.ioc_sem_reg);
  1121. if (r32 == ~0) {
  1122. WARN_ON(r32 == ~0);
  1123. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEM_ERROR);
  1124. return;
  1125. }
  1126. if (!(r32 & 1)) {
  1127. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
  1128. return;
  1129. }
  1130. bfa_sem_timer_start(ioc);
  1131. }
  1132. /*
  1133. * Initialize LPU local memory (aka secondary memory / SRAM)
  1134. */
  1135. static void
  1136. bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
  1137. {
  1138. u32 pss_ctl;
  1139. int i;
  1140. #define PSS_LMEM_INIT_TIME 10000
  1141. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1142. pss_ctl &= ~__PSS_LMEM_RESET;
  1143. pss_ctl |= __PSS_LMEM_INIT_EN;
  1144. /*
  1145. * i2c workaround 12.5khz clock
  1146. */
  1147. pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
  1148. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1149. /*
  1150. * wait for memory initialization to be complete
  1151. */
  1152. i = 0;
  1153. do {
  1154. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1155. i++;
  1156. } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
  1157. /*
  1158. * If memory initialization is not successful, IOC timeout will catch
  1159. * such failures.
  1160. */
  1161. WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
  1162. bfa_trc(ioc, pss_ctl);
  1163. pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
  1164. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1165. }
  1166. static void
  1167. bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
  1168. {
  1169. u32 pss_ctl;
  1170. /*
  1171. * Take processor out of reset.
  1172. */
  1173. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1174. pss_ctl &= ~__PSS_LPU0_RESET;
  1175. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1176. }
  1177. static void
  1178. bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
  1179. {
  1180. u32 pss_ctl;
  1181. /*
  1182. * Put processors in reset.
  1183. */
  1184. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1185. pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
  1186. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1187. }
  1188. /*
  1189. * Get driver and firmware versions.
  1190. */
  1191. void
  1192. bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
  1193. {
  1194. u32 pgnum, pgoff;
  1195. u32 loff = 0;
  1196. int i;
  1197. u32 *fwsig = (u32 *) fwhdr;
  1198. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  1199. pgoff = PSS_SMEM_PGOFF(loff);
  1200. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1201. for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
  1202. i++) {
  1203. fwsig[i] =
  1204. bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  1205. loff += sizeof(u32);
  1206. }
  1207. }
  1208. /*
  1209. * Returns TRUE if same.
  1210. */
  1211. bfa_boolean_t
  1212. bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
  1213. {
  1214. struct bfi_ioc_image_hdr_s *drv_fwhdr;
  1215. int i;
  1216. drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
  1217. bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
  1218. for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
  1219. if (fwhdr->md5sum[i] != cpu_to_le32(drv_fwhdr->md5sum[i])) {
  1220. bfa_trc(ioc, i);
  1221. bfa_trc(ioc, fwhdr->md5sum[i]);
  1222. bfa_trc(ioc, drv_fwhdr->md5sum[i]);
  1223. return BFA_FALSE;
  1224. }
  1225. }
  1226. bfa_trc(ioc, fwhdr->md5sum[0]);
  1227. return BFA_TRUE;
  1228. }
  1229. /*
  1230. * Return true if current running version is valid. Firmware signature and
  1231. * execution context (driver/bios) must match.
  1232. */
  1233. static bfa_boolean_t
  1234. bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
  1235. {
  1236. struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
  1237. bfa_ioc_fwver_get(ioc, &fwhdr);
  1238. drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
  1239. bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
  1240. if (fwhdr.signature != cpu_to_le32(drv_fwhdr->signature)) {
  1241. bfa_trc(ioc, fwhdr.signature);
  1242. bfa_trc(ioc, drv_fwhdr->signature);
  1243. return BFA_FALSE;
  1244. }
  1245. if (swab32(fwhdr.bootenv) != boot_env) {
  1246. bfa_trc(ioc, fwhdr.bootenv);
  1247. bfa_trc(ioc, boot_env);
  1248. return BFA_FALSE;
  1249. }
  1250. return bfa_ioc_fwver_cmp(ioc, &fwhdr);
  1251. }
  1252. /*
  1253. * Conditionally flush any pending message from firmware at start.
  1254. */
  1255. static void
  1256. bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
  1257. {
  1258. u32 r32;
  1259. r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
  1260. if (r32)
  1261. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  1262. }
  1263. static void
  1264. bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
  1265. {
  1266. enum bfi_ioc_state ioc_fwstate;
  1267. bfa_boolean_t fwvalid;
  1268. u32 boot_type;
  1269. u32 boot_env;
  1270. ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
  1271. if (force)
  1272. ioc_fwstate = BFI_IOC_UNINIT;
  1273. bfa_trc(ioc, ioc_fwstate);
  1274. boot_type = BFI_FWBOOT_TYPE_NORMAL;
  1275. boot_env = BFI_FWBOOT_ENV_OS;
  1276. /*
  1277. * check if firmware is valid
  1278. */
  1279. fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
  1280. BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
  1281. if (!fwvalid) {
  1282. bfa_ioc_boot(ioc, boot_type, boot_env);
  1283. bfa_ioc_poll_fwinit(ioc);
  1284. return;
  1285. }
  1286. /*
  1287. * If hardware initialization is in progress (initialized by other IOC),
  1288. * just wait for an initialization completion interrupt.
  1289. */
  1290. if (ioc_fwstate == BFI_IOC_INITING) {
  1291. bfa_ioc_poll_fwinit(ioc);
  1292. return;
  1293. }
  1294. /*
  1295. * If IOC function is disabled and firmware version is same,
  1296. * just re-enable IOC.
  1297. *
  1298. * If option rom, IOC must not be in operational state. With
  1299. * convergence, IOC will be in operational state when 2nd driver
  1300. * is loaded.
  1301. */
  1302. if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
  1303. /*
  1304. * When using MSI-X any pending firmware ready event should
  1305. * be flushed. Otherwise MSI-X interrupts are not delivered.
  1306. */
  1307. bfa_ioc_msgflush(ioc);
  1308. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
  1309. return;
  1310. }
  1311. /*
  1312. * Initialize the h/w for any other states.
  1313. */
  1314. bfa_ioc_boot(ioc, boot_type, boot_env);
  1315. bfa_ioc_poll_fwinit(ioc);
  1316. }
  1317. static void
  1318. bfa_ioc_timeout(void *ioc_arg)
  1319. {
  1320. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  1321. bfa_trc(ioc, 0);
  1322. bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
  1323. }
  1324. void
  1325. bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
  1326. {
  1327. u32 *msgp = (u32 *) ioc_msg;
  1328. u32 i;
  1329. bfa_trc(ioc, msgp[0]);
  1330. bfa_trc(ioc, len);
  1331. WARN_ON(len > BFI_IOC_MSGLEN_MAX);
  1332. /*
  1333. * first write msg to mailbox registers
  1334. */
  1335. for (i = 0; i < len / sizeof(u32); i++)
  1336. writel(cpu_to_le32(msgp[i]),
  1337. ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1338. for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
  1339. writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1340. /*
  1341. * write 1 to mailbox CMD to trigger LPU event
  1342. */
  1343. writel(1, ioc->ioc_regs.hfn_mbox_cmd);
  1344. (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
  1345. }
  1346. static void
  1347. bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
  1348. {
  1349. struct bfi_ioc_ctrl_req_s enable_req;
  1350. struct timeval tv;
  1351. bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
  1352. bfa_ioc_portid(ioc));
  1353. enable_req.clscode = cpu_to_be16(ioc->clscode);
  1354. do_gettimeofday(&tv);
  1355. enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
  1356. bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  1357. }
  1358. static void
  1359. bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
  1360. {
  1361. struct bfi_ioc_ctrl_req_s disable_req;
  1362. bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
  1363. bfa_ioc_portid(ioc));
  1364. bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  1365. }
  1366. static void
  1367. bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
  1368. {
  1369. struct bfi_ioc_getattr_req_s attr_req;
  1370. bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
  1371. bfa_ioc_portid(ioc));
  1372. bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
  1373. bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
  1374. }
  1375. static void
  1376. bfa_ioc_hb_check(void *cbarg)
  1377. {
  1378. struct bfa_ioc_s *ioc = cbarg;
  1379. u32 hb_count;
  1380. hb_count = readl(ioc->ioc_regs.heartbeat);
  1381. if (ioc->hb_count == hb_count) {
  1382. bfa_ioc_recover(ioc);
  1383. return;
  1384. } else {
  1385. ioc->hb_count = hb_count;
  1386. }
  1387. bfa_ioc_mbox_poll(ioc);
  1388. bfa_hb_timer_start(ioc);
  1389. }
  1390. static void
  1391. bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
  1392. {
  1393. ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
  1394. bfa_hb_timer_start(ioc);
  1395. }
  1396. /*
  1397. * Initiate a full firmware download.
  1398. */
  1399. static void
  1400. bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
  1401. u32 boot_env)
  1402. {
  1403. u32 *fwimg;
  1404. u32 pgnum, pgoff;
  1405. u32 loff = 0;
  1406. u32 chunkno = 0;
  1407. u32 i;
  1408. u32 asicmode;
  1409. bfa_trc(ioc, bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)));
  1410. fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), chunkno);
  1411. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  1412. pgoff = PSS_SMEM_PGOFF(loff);
  1413. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1414. for (i = 0; i < bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)); i++) {
  1415. if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
  1416. chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
  1417. fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc),
  1418. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  1419. }
  1420. /*
  1421. * write smem
  1422. */
  1423. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
  1424. cpu_to_le32(fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]));
  1425. loff += sizeof(u32);
  1426. /*
  1427. * handle page offset wrap around
  1428. */
  1429. loff = PSS_SMEM_PGOFF(loff);
  1430. if (loff == 0) {
  1431. pgnum++;
  1432. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1433. }
  1434. }
  1435. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1436. ioc->ioc_regs.host_page_num_fn);
  1437. /*
  1438. * Set boot type and device mode at the end.
  1439. */
  1440. asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode,
  1441. ioc->port0_mode, ioc->port1_mode);
  1442. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_DEVMODE_OFF,
  1443. swab32(asicmode));
  1444. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_TYPE_OFF,
  1445. swab32(boot_type));
  1446. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_ENV_OFF,
  1447. swab32(boot_env));
  1448. }
  1449. /*
  1450. * Update BFA configuration from firmware configuration.
  1451. */
  1452. static void
  1453. bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
  1454. {
  1455. struct bfi_ioc_attr_s *attr = ioc->attr;
  1456. attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
  1457. attr->card_type = be32_to_cpu(attr->card_type);
  1458. attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
  1459. ioc->fcmode = (attr->port_mode == BFI_PORT_MODE_FC);
  1460. bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
  1461. }
  1462. /*
  1463. * Attach time initialization of mbox logic.
  1464. */
  1465. static void
  1466. bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
  1467. {
  1468. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1469. int mc;
  1470. INIT_LIST_HEAD(&mod->cmd_q);
  1471. for (mc = 0; mc < BFI_MC_MAX; mc++) {
  1472. mod->mbhdlr[mc].cbfn = NULL;
  1473. mod->mbhdlr[mc].cbarg = ioc->bfa;
  1474. }
  1475. }
  1476. /*
  1477. * Mbox poll timer -- restarts any pending mailbox requests.
  1478. */
  1479. static void
  1480. bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
  1481. {
  1482. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1483. struct bfa_mbox_cmd_s *cmd;
  1484. u32 stat;
  1485. /*
  1486. * If no command pending, do nothing
  1487. */
  1488. if (list_empty(&mod->cmd_q))
  1489. return;
  1490. /*
  1491. * If previous command is not yet fetched by firmware, do nothing
  1492. */
  1493. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  1494. if (stat)
  1495. return;
  1496. /*
  1497. * Enqueue command to firmware.
  1498. */
  1499. bfa_q_deq(&mod->cmd_q, &cmd);
  1500. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1501. }
  1502. /*
  1503. * Cleanup any pending requests.
  1504. */
  1505. static void
  1506. bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc)
  1507. {
  1508. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1509. struct bfa_mbox_cmd_s *cmd;
  1510. while (!list_empty(&mod->cmd_q))
  1511. bfa_q_deq(&mod->cmd_q, &cmd);
  1512. }
  1513. /*
  1514. * Read data from SMEM to host through PCI memmap
  1515. *
  1516. * @param[in] ioc memory for IOC
  1517. * @param[in] tbuf app memory to store data from smem
  1518. * @param[in] soff smem offset
  1519. * @param[in] sz size of smem in bytes
  1520. */
  1521. static bfa_status_t
  1522. bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
  1523. {
  1524. u32 pgnum, loff;
  1525. __be32 r32;
  1526. int i, len;
  1527. u32 *buf = tbuf;
  1528. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
  1529. loff = PSS_SMEM_PGOFF(soff);
  1530. bfa_trc(ioc, pgnum);
  1531. bfa_trc(ioc, loff);
  1532. bfa_trc(ioc, sz);
  1533. /*
  1534. * Hold semaphore to serialize pll init and fwtrc.
  1535. */
  1536. if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
  1537. bfa_trc(ioc, 0);
  1538. return BFA_STATUS_FAILED;
  1539. }
  1540. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1541. len = sz/sizeof(u32);
  1542. bfa_trc(ioc, len);
  1543. for (i = 0; i < len; i++) {
  1544. r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  1545. buf[i] = be32_to_cpu(r32);
  1546. loff += sizeof(u32);
  1547. /*
  1548. * handle page offset wrap around
  1549. */
  1550. loff = PSS_SMEM_PGOFF(loff);
  1551. if (loff == 0) {
  1552. pgnum++;
  1553. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1554. }
  1555. }
  1556. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1557. ioc->ioc_regs.host_page_num_fn);
  1558. /*
  1559. * release semaphore.
  1560. */
  1561. readl(ioc->ioc_regs.ioc_init_sem_reg);
  1562. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1563. bfa_trc(ioc, pgnum);
  1564. return BFA_STATUS_OK;
  1565. }
  1566. /*
  1567. * Clear SMEM data from host through PCI memmap
  1568. *
  1569. * @param[in] ioc memory for IOC
  1570. * @param[in] soff smem offset
  1571. * @param[in] sz size of smem in bytes
  1572. */
  1573. static bfa_status_t
  1574. bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
  1575. {
  1576. int i, len;
  1577. u32 pgnum, loff;
  1578. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
  1579. loff = PSS_SMEM_PGOFF(soff);
  1580. bfa_trc(ioc, pgnum);
  1581. bfa_trc(ioc, loff);
  1582. bfa_trc(ioc, sz);
  1583. /*
  1584. * Hold semaphore to serialize pll init and fwtrc.
  1585. */
  1586. if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
  1587. bfa_trc(ioc, 0);
  1588. return BFA_STATUS_FAILED;
  1589. }
  1590. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1591. len = sz/sizeof(u32); /* len in words */
  1592. bfa_trc(ioc, len);
  1593. for (i = 0; i < len; i++) {
  1594. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
  1595. loff += sizeof(u32);
  1596. /*
  1597. * handle page offset wrap around
  1598. */
  1599. loff = PSS_SMEM_PGOFF(loff);
  1600. if (loff == 0) {
  1601. pgnum++;
  1602. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1603. }
  1604. }
  1605. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1606. ioc->ioc_regs.host_page_num_fn);
  1607. /*
  1608. * release semaphore.
  1609. */
  1610. readl(ioc->ioc_regs.ioc_init_sem_reg);
  1611. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1612. bfa_trc(ioc, pgnum);
  1613. return BFA_STATUS_OK;
  1614. }
  1615. static void
  1616. bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
  1617. {
  1618. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  1619. /*
  1620. * Notify driver and common modules registered for notification.
  1621. */
  1622. ioc->cbfn->hbfail_cbfn(ioc->bfa);
  1623. bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
  1624. bfa_ioc_debug_save_ftrc(ioc);
  1625. BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
  1626. "Heart Beat of IOC has failed\n");
  1627. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_HBFAIL);
  1628. }
  1629. static void
  1630. bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
  1631. {
  1632. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  1633. /*
  1634. * Provide enable completion callback.
  1635. */
  1636. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  1637. BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
  1638. "Running firmware version is incompatible "
  1639. "with the driver version\n");
  1640. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_FWMISMATCH);
  1641. }
  1642. bfa_status_t
  1643. bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
  1644. {
  1645. /*
  1646. * Hold semaphore so that nobody can access the chip during init.
  1647. */
  1648. bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
  1649. bfa_ioc_pll_init_asic(ioc);
  1650. ioc->pllinit = BFA_TRUE;
  1651. /*
  1652. * Initialize LMEM
  1653. */
  1654. bfa_ioc_lmem_init(ioc);
  1655. /*
  1656. * release semaphore.
  1657. */
  1658. readl(ioc->ioc_regs.ioc_init_sem_reg);
  1659. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1660. return BFA_STATUS_OK;
  1661. }
  1662. /*
  1663. * Interface used by diag module to do firmware boot with memory test
  1664. * as the entry vector.
  1665. */
  1666. void
  1667. bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
  1668. {
  1669. bfa_ioc_stats(ioc, ioc_boots);
  1670. if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
  1671. return;
  1672. /*
  1673. * Initialize IOC state of all functions on a chip reset.
  1674. */
  1675. if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) {
  1676. writel(BFI_IOC_MEMTEST, ioc->ioc_regs.ioc_fwstate);
  1677. writel(BFI_IOC_MEMTEST, ioc->ioc_regs.alt_ioc_fwstate);
  1678. } else {
  1679. writel(BFI_IOC_INITING, ioc->ioc_regs.ioc_fwstate);
  1680. writel(BFI_IOC_INITING, ioc->ioc_regs.alt_ioc_fwstate);
  1681. }
  1682. bfa_ioc_msgflush(ioc);
  1683. bfa_ioc_download_fw(ioc, boot_type, boot_env);
  1684. bfa_ioc_lpu_start(ioc);
  1685. }
  1686. /*
  1687. * Enable/disable IOC failure auto recovery.
  1688. */
  1689. void
  1690. bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
  1691. {
  1692. bfa_auto_recover = auto_recover;
  1693. }
  1694. bfa_boolean_t
  1695. bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
  1696. {
  1697. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
  1698. }
  1699. bfa_boolean_t
  1700. bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
  1701. {
  1702. u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
  1703. return ((r32 != BFI_IOC_UNINIT) &&
  1704. (r32 != BFI_IOC_INITING) &&
  1705. (r32 != BFI_IOC_MEMTEST));
  1706. }
  1707. bfa_boolean_t
  1708. bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
  1709. {
  1710. __be32 *msgp = mbmsg;
  1711. u32 r32;
  1712. int i;
  1713. r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
  1714. if ((r32 & 1) == 0)
  1715. return BFA_FALSE;
  1716. /*
  1717. * read the MBOX msg
  1718. */
  1719. for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
  1720. i++) {
  1721. r32 = readl(ioc->ioc_regs.lpu_mbox +
  1722. i * sizeof(u32));
  1723. msgp[i] = cpu_to_be32(r32);
  1724. }
  1725. /*
  1726. * turn off mailbox interrupt by clearing mailbox status
  1727. */
  1728. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  1729. readl(ioc->ioc_regs.lpu_mbox_cmd);
  1730. return BFA_TRUE;
  1731. }
  1732. void
  1733. bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
  1734. {
  1735. union bfi_ioc_i2h_msg_u *msg;
  1736. struct bfa_iocpf_s *iocpf = &ioc->iocpf;
  1737. msg = (union bfi_ioc_i2h_msg_u *) m;
  1738. bfa_ioc_stats(ioc, ioc_isrs);
  1739. switch (msg->mh.msg_id) {
  1740. case BFI_IOC_I2H_HBEAT:
  1741. break;
  1742. case BFI_IOC_I2H_ENABLE_REPLY:
  1743. ioc->port_mode = ioc->port_mode_cfg =
  1744. (enum bfa_mode_s)msg->fw_event.port_mode;
  1745. ioc->ad_cap_bm = msg->fw_event.cap_bm;
  1746. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
  1747. break;
  1748. case BFI_IOC_I2H_DISABLE_REPLY:
  1749. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
  1750. break;
  1751. case BFI_IOC_I2H_GETATTR_REPLY:
  1752. bfa_ioc_getattr_reply(ioc);
  1753. break;
  1754. default:
  1755. bfa_trc(ioc, msg->mh.msg_id);
  1756. WARN_ON(1);
  1757. }
  1758. }
  1759. /*
  1760. * IOC attach time initialization and setup.
  1761. *
  1762. * @param[in] ioc memory for IOC
  1763. * @param[in] bfa driver instance structure
  1764. */
  1765. void
  1766. bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
  1767. struct bfa_timer_mod_s *timer_mod)
  1768. {
  1769. ioc->bfa = bfa;
  1770. ioc->cbfn = cbfn;
  1771. ioc->timer_mod = timer_mod;
  1772. ioc->fcmode = BFA_FALSE;
  1773. ioc->pllinit = BFA_FALSE;
  1774. ioc->dbg_fwsave_once = BFA_TRUE;
  1775. ioc->iocpf.ioc = ioc;
  1776. bfa_ioc_mbox_attach(ioc);
  1777. INIT_LIST_HEAD(&ioc->notify_q);
  1778. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  1779. bfa_fsm_send_event(ioc, IOC_E_RESET);
  1780. }
  1781. /*
  1782. * Driver detach time IOC cleanup.
  1783. */
  1784. void
  1785. bfa_ioc_detach(struct bfa_ioc_s *ioc)
  1786. {
  1787. bfa_fsm_send_event(ioc, IOC_E_DETACH);
  1788. INIT_LIST_HEAD(&ioc->notify_q);
  1789. }
  1790. /*
  1791. * Setup IOC PCI properties.
  1792. *
  1793. * @param[in] pcidev PCI device information for this IOC
  1794. */
  1795. void
  1796. bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  1797. enum bfi_pcifn_class clscode)
  1798. {
  1799. ioc->clscode = clscode;
  1800. ioc->pcidev = *pcidev;
  1801. /*
  1802. * Initialize IOC and device personality
  1803. */
  1804. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
  1805. ioc->asic_mode = BFI_ASIC_MODE_FC;
  1806. switch (pcidev->device_id) {
  1807. case BFA_PCI_DEVICE_ID_FC_8G1P:
  1808. case BFA_PCI_DEVICE_ID_FC_8G2P:
  1809. ioc->asic_gen = BFI_ASIC_GEN_CB;
  1810. ioc->fcmode = BFA_TRUE;
  1811. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
  1812. ioc->ad_cap_bm = BFA_CM_HBA;
  1813. break;
  1814. case BFA_PCI_DEVICE_ID_CT:
  1815. ioc->asic_gen = BFI_ASIC_GEN_CT;
  1816. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
  1817. ioc->asic_mode = BFI_ASIC_MODE_ETH;
  1818. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
  1819. ioc->ad_cap_bm = BFA_CM_CNA;
  1820. break;
  1821. case BFA_PCI_DEVICE_ID_CT_FC:
  1822. ioc->asic_gen = BFI_ASIC_GEN_CT;
  1823. ioc->fcmode = BFA_TRUE;
  1824. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
  1825. ioc->ad_cap_bm = BFA_CM_HBA;
  1826. break;
  1827. case BFA_PCI_DEVICE_ID_CT2:
  1828. ioc->asic_gen = BFI_ASIC_GEN_CT2;
  1829. if (clscode == BFI_PCIFN_CLASS_FC &&
  1830. pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
  1831. ioc->asic_mode = BFI_ASIC_MODE_FC16;
  1832. ioc->fcmode = BFA_TRUE;
  1833. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
  1834. ioc->ad_cap_bm = BFA_CM_HBA;
  1835. } else {
  1836. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
  1837. ioc->asic_mode = BFI_ASIC_MODE_ETH;
  1838. if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
  1839. ioc->port_mode =
  1840. ioc->port_mode_cfg = BFA_MODE_CNA;
  1841. ioc->ad_cap_bm = BFA_CM_CNA;
  1842. } else {
  1843. ioc->port_mode =
  1844. ioc->port_mode_cfg = BFA_MODE_NIC;
  1845. ioc->ad_cap_bm = BFA_CM_NIC;
  1846. }
  1847. }
  1848. break;
  1849. default:
  1850. WARN_ON(1);
  1851. }
  1852. /*
  1853. * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
  1854. */
  1855. if (ioc->asic_gen == BFI_ASIC_GEN_CB)
  1856. bfa_ioc_set_cb_hwif(ioc);
  1857. else if (ioc->asic_gen == BFI_ASIC_GEN_CT)
  1858. bfa_ioc_set_ct_hwif(ioc);
  1859. else {
  1860. WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2);
  1861. bfa_ioc_set_ct2_hwif(ioc);
  1862. bfa_ioc_ct2_poweron(ioc);
  1863. }
  1864. bfa_ioc_map_port(ioc);
  1865. bfa_ioc_reg_init(ioc);
  1866. }
  1867. /*
  1868. * Initialize IOC dma memory
  1869. *
  1870. * @param[in] dm_kva kernel virtual address of IOC dma memory
  1871. * @param[in] dm_pa physical address of IOC dma memory
  1872. */
  1873. void
  1874. bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
  1875. {
  1876. /*
  1877. * dma memory for firmware attribute
  1878. */
  1879. ioc->attr_dma.kva = dm_kva;
  1880. ioc->attr_dma.pa = dm_pa;
  1881. ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
  1882. }
  1883. void
  1884. bfa_ioc_enable(struct bfa_ioc_s *ioc)
  1885. {
  1886. bfa_ioc_stats(ioc, ioc_enables);
  1887. ioc->dbg_fwsave_once = BFA_TRUE;
  1888. bfa_fsm_send_event(ioc, IOC_E_ENABLE);
  1889. }
  1890. void
  1891. bfa_ioc_disable(struct bfa_ioc_s *ioc)
  1892. {
  1893. bfa_ioc_stats(ioc, ioc_disables);
  1894. bfa_fsm_send_event(ioc, IOC_E_DISABLE);
  1895. }
  1896. void
  1897. bfa_ioc_suspend(struct bfa_ioc_s *ioc)
  1898. {
  1899. ioc->dbg_fwsave_once = BFA_TRUE;
  1900. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  1901. }
  1902. /*
  1903. * Initialize memory for saving firmware trace. Driver must initialize
  1904. * trace memory before call bfa_ioc_enable().
  1905. */
  1906. void
  1907. bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
  1908. {
  1909. ioc->dbg_fwsave = dbg_fwsave;
  1910. ioc->dbg_fwsave_len = BFA_DBG_FWTRC_LEN;
  1911. }
  1912. /*
  1913. * Register mailbox message handler functions
  1914. *
  1915. * @param[in] ioc IOC instance
  1916. * @param[in] mcfuncs message class handler functions
  1917. */
  1918. void
  1919. bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
  1920. {
  1921. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1922. int mc;
  1923. for (mc = 0; mc < BFI_MC_MAX; mc++)
  1924. mod->mbhdlr[mc].cbfn = mcfuncs[mc];
  1925. }
  1926. /*
  1927. * Register mailbox message handler function, to be called by common modules
  1928. */
  1929. void
  1930. bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  1931. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
  1932. {
  1933. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1934. mod->mbhdlr[mc].cbfn = cbfn;
  1935. mod->mbhdlr[mc].cbarg = cbarg;
  1936. }
  1937. /*
  1938. * Queue a mailbox command request to firmware. Waits if mailbox is busy.
  1939. * Responsibility of caller to serialize
  1940. *
  1941. * @param[in] ioc IOC instance
  1942. * @param[i] cmd Mailbox command
  1943. */
  1944. void
  1945. bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
  1946. {
  1947. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1948. u32 stat;
  1949. /*
  1950. * If a previous command is pending, queue new command
  1951. */
  1952. if (!list_empty(&mod->cmd_q)) {
  1953. list_add_tail(&cmd->qe, &mod->cmd_q);
  1954. return;
  1955. }
  1956. /*
  1957. * If mailbox is busy, queue command for poll timer
  1958. */
  1959. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  1960. if (stat) {
  1961. list_add_tail(&cmd->qe, &mod->cmd_q);
  1962. return;
  1963. }
  1964. /*
  1965. * mailbox is free -- queue command to firmware
  1966. */
  1967. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1968. }
  1969. /*
  1970. * Handle mailbox interrupts
  1971. */
  1972. void
  1973. bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
  1974. {
  1975. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1976. struct bfi_mbmsg_s m;
  1977. int mc;
  1978. if (bfa_ioc_msgget(ioc, &m)) {
  1979. /*
  1980. * Treat IOC message class as special.
  1981. */
  1982. mc = m.mh.msg_class;
  1983. if (mc == BFI_MC_IOC) {
  1984. bfa_ioc_isr(ioc, &m);
  1985. return;
  1986. }
  1987. if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
  1988. return;
  1989. mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
  1990. }
  1991. bfa_ioc_lpu_read_stat(ioc);
  1992. /*
  1993. * Try to send pending mailbox commands
  1994. */
  1995. bfa_ioc_mbox_poll(ioc);
  1996. }
  1997. void
  1998. bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
  1999. {
  2000. bfa_ioc_stats(ioc, ioc_hbfails);
  2001. ioc->stats.hb_count = ioc->hb_count;
  2002. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  2003. }
  2004. /*
  2005. * return true if IOC is disabled
  2006. */
  2007. bfa_boolean_t
  2008. bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
  2009. {
  2010. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
  2011. bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
  2012. }
  2013. /*
  2014. * return true if IOC firmware is different.
  2015. */
  2016. bfa_boolean_t
  2017. bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
  2018. {
  2019. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
  2020. bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
  2021. bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
  2022. }
  2023. #define bfa_ioc_state_disabled(__sm) \
  2024. (((__sm) == BFI_IOC_UNINIT) || \
  2025. ((__sm) == BFI_IOC_INITING) || \
  2026. ((__sm) == BFI_IOC_HWINIT) || \
  2027. ((__sm) == BFI_IOC_DISABLED) || \
  2028. ((__sm) == BFI_IOC_FAIL) || \
  2029. ((__sm) == BFI_IOC_CFG_DISABLED))
  2030. /*
  2031. * Check if adapter is disabled -- both IOCs should be in a disabled
  2032. * state.
  2033. */
  2034. bfa_boolean_t
  2035. bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
  2036. {
  2037. u32 ioc_state;
  2038. if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
  2039. return BFA_FALSE;
  2040. ioc_state = readl(ioc->ioc_regs.ioc_fwstate);
  2041. if (!bfa_ioc_state_disabled(ioc_state))
  2042. return BFA_FALSE;
  2043. if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
  2044. ioc_state = readl(ioc->ioc_regs.alt_ioc_fwstate);
  2045. if (!bfa_ioc_state_disabled(ioc_state))
  2046. return BFA_FALSE;
  2047. }
  2048. return BFA_TRUE;
  2049. }
  2050. /*
  2051. * Reset IOC fwstate registers.
  2052. */
  2053. void
  2054. bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
  2055. {
  2056. writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
  2057. writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
  2058. }
  2059. #define BFA_MFG_NAME "Brocade"
  2060. void
  2061. bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  2062. struct bfa_adapter_attr_s *ad_attr)
  2063. {
  2064. struct bfi_ioc_attr_s *ioc_attr;
  2065. ioc_attr = ioc->attr;
  2066. bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
  2067. bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
  2068. bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
  2069. bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
  2070. memcpy(&ad_attr->vpd, &ioc_attr->vpd,
  2071. sizeof(struct bfa_mfg_vpd_s));
  2072. ad_attr->nports = bfa_ioc_get_nports(ioc);
  2073. ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
  2074. bfa_ioc_get_adapter_model(ioc, ad_attr->model);
  2075. /* For now, model descr uses same model string */
  2076. bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
  2077. ad_attr->card_type = ioc_attr->card_type;
  2078. ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
  2079. if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
  2080. ad_attr->prototype = 1;
  2081. else
  2082. ad_attr->prototype = 0;
  2083. ad_attr->pwwn = ioc->attr->pwwn;
  2084. ad_attr->mac = bfa_ioc_get_mac(ioc);
  2085. ad_attr->pcie_gen = ioc_attr->pcie_gen;
  2086. ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
  2087. ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
  2088. ad_attr->asic_rev = ioc_attr->asic_rev;
  2089. bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
  2090. ad_attr->cna_capable = bfa_ioc_is_cna(ioc);
  2091. ad_attr->trunk_capable = (ad_attr->nports > 1) &&
  2092. !bfa_ioc_is_cna(ioc) && !ad_attr->is_mezz;
  2093. }
  2094. enum bfa_ioc_type_e
  2095. bfa_ioc_get_type(struct bfa_ioc_s *ioc)
  2096. {
  2097. if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
  2098. return BFA_IOC_TYPE_LL;
  2099. WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_FC);
  2100. return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
  2101. ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
  2102. }
  2103. void
  2104. bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
  2105. {
  2106. memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
  2107. memcpy((void *)serial_num,
  2108. (void *)ioc->attr->brcd_serialnum,
  2109. BFA_ADAPTER_SERIAL_NUM_LEN);
  2110. }
  2111. void
  2112. bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
  2113. {
  2114. memset((void *)fw_ver, 0, BFA_VERSION_LEN);
  2115. memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
  2116. }
  2117. void
  2118. bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
  2119. {
  2120. WARN_ON(!chip_rev);
  2121. memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
  2122. chip_rev[0] = 'R';
  2123. chip_rev[1] = 'e';
  2124. chip_rev[2] = 'v';
  2125. chip_rev[3] = '-';
  2126. chip_rev[4] = ioc->attr->asic_rev;
  2127. chip_rev[5] = '\0';
  2128. }
  2129. void
  2130. bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
  2131. {
  2132. memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
  2133. memcpy(optrom_ver, ioc->attr->optrom_version,
  2134. BFA_VERSION_LEN);
  2135. }
  2136. void
  2137. bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
  2138. {
  2139. memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
  2140. memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
  2141. }
  2142. void
  2143. bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
  2144. {
  2145. struct bfi_ioc_attr_s *ioc_attr;
  2146. WARN_ON(!model);
  2147. memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
  2148. ioc_attr = ioc->attr;
  2149. snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
  2150. BFA_MFG_NAME, ioc_attr->card_type);
  2151. }
  2152. enum bfa_ioc_state
  2153. bfa_ioc_get_state(struct bfa_ioc_s *ioc)
  2154. {
  2155. enum bfa_iocpf_state iocpf_st;
  2156. enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
  2157. if (ioc_st == BFA_IOC_ENABLING ||
  2158. ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
  2159. iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
  2160. switch (iocpf_st) {
  2161. case BFA_IOCPF_SEMWAIT:
  2162. ioc_st = BFA_IOC_SEMWAIT;
  2163. break;
  2164. case BFA_IOCPF_HWINIT:
  2165. ioc_st = BFA_IOC_HWINIT;
  2166. break;
  2167. case BFA_IOCPF_FWMISMATCH:
  2168. ioc_st = BFA_IOC_FWMISMATCH;
  2169. break;
  2170. case BFA_IOCPF_FAIL:
  2171. ioc_st = BFA_IOC_FAIL;
  2172. break;
  2173. case BFA_IOCPF_INITFAIL:
  2174. ioc_st = BFA_IOC_INITFAIL;
  2175. break;
  2176. default:
  2177. break;
  2178. }
  2179. }
  2180. return ioc_st;
  2181. }
  2182. void
  2183. bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
  2184. {
  2185. memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
  2186. ioc_attr->state = bfa_ioc_get_state(ioc);
  2187. ioc_attr->port_id = ioc->port_id;
  2188. ioc_attr->port_mode = ioc->port_mode;
  2189. ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
  2190. ioc_attr->cap_bm = ioc->ad_cap_bm;
  2191. ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
  2192. bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
  2193. ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
  2194. ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
  2195. bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
  2196. }
  2197. mac_t
  2198. bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
  2199. {
  2200. /*
  2201. * Check the IOC type and return the appropriate MAC
  2202. */
  2203. if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
  2204. return ioc->attr->fcoe_mac;
  2205. else
  2206. return ioc->attr->mac;
  2207. }
  2208. mac_t
  2209. bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
  2210. {
  2211. mac_t m;
  2212. m = ioc->attr->mfg_mac;
  2213. if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
  2214. m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
  2215. else
  2216. bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
  2217. bfa_ioc_pcifn(ioc));
  2218. return m;
  2219. }
  2220. /*
  2221. * Send AEN notification
  2222. */
  2223. void
  2224. bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
  2225. {
  2226. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  2227. struct bfa_aen_entry_s *aen_entry;
  2228. enum bfa_ioc_type_e ioc_type;
  2229. bfad_get_aen_entry(bfad, aen_entry);
  2230. if (!aen_entry)
  2231. return;
  2232. ioc_type = bfa_ioc_get_type(ioc);
  2233. switch (ioc_type) {
  2234. case BFA_IOC_TYPE_FC:
  2235. aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn;
  2236. break;
  2237. case BFA_IOC_TYPE_FCoE:
  2238. aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn;
  2239. aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  2240. break;
  2241. case BFA_IOC_TYPE_LL:
  2242. aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  2243. break;
  2244. default:
  2245. WARN_ON(ioc_type != BFA_IOC_TYPE_FC);
  2246. break;
  2247. }
  2248. /* Send the AEN notification */
  2249. aen_entry->aen_data.ioc.ioc_type = ioc_type;
  2250. bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq,
  2251. BFA_AEN_CAT_IOC, event);
  2252. }
  2253. /*
  2254. * Retrieve saved firmware trace from a prior IOC failure.
  2255. */
  2256. bfa_status_t
  2257. bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  2258. {
  2259. int tlen;
  2260. if (ioc->dbg_fwsave_len == 0)
  2261. return BFA_STATUS_ENOFSAVE;
  2262. tlen = *trclen;
  2263. if (tlen > ioc->dbg_fwsave_len)
  2264. tlen = ioc->dbg_fwsave_len;
  2265. memcpy(trcdata, ioc->dbg_fwsave, tlen);
  2266. *trclen = tlen;
  2267. return BFA_STATUS_OK;
  2268. }
  2269. /*
  2270. * Retrieve saved firmware trace from a prior IOC failure.
  2271. */
  2272. bfa_status_t
  2273. bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  2274. {
  2275. u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
  2276. int tlen;
  2277. bfa_status_t status;
  2278. bfa_trc(ioc, *trclen);
  2279. tlen = *trclen;
  2280. if (tlen > BFA_DBG_FWTRC_LEN)
  2281. tlen = BFA_DBG_FWTRC_LEN;
  2282. status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
  2283. *trclen = tlen;
  2284. return status;
  2285. }
  2286. static void
  2287. bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
  2288. {
  2289. struct bfa_mbox_cmd_s cmd;
  2290. struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
  2291. bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
  2292. bfa_ioc_portid(ioc));
  2293. req->clscode = cpu_to_be16(ioc->clscode);
  2294. bfa_ioc_mbox_queue(ioc, &cmd);
  2295. }
  2296. static void
  2297. bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
  2298. {
  2299. u32 fwsync_iter = 1000;
  2300. bfa_ioc_send_fwsync(ioc);
  2301. /*
  2302. * After sending a fw sync mbox command wait for it to
  2303. * take effect. We will not wait for a response because
  2304. * 1. fw_sync mbox cmd doesn't have a response.
  2305. * 2. Even if we implement that, interrupts might not
  2306. * be enabled when we call this function.
  2307. * So, just keep checking if any mbox cmd is pending, and
  2308. * after waiting for a reasonable amount of time, go ahead.
  2309. * It is possible that fw has crashed and the mbox command
  2310. * is never acknowledged.
  2311. */
  2312. while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
  2313. fwsync_iter--;
  2314. }
  2315. /*
  2316. * Dump firmware smem
  2317. */
  2318. bfa_status_t
  2319. bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
  2320. u32 *offset, int *buflen)
  2321. {
  2322. u32 loff;
  2323. int dlen;
  2324. bfa_status_t status;
  2325. u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
  2326. if (*offset >= smem_len) {
  2327. *offset = *buflen = 0;
  2328. return BFA_STATUS_EINVAL;
  2329. }
  2330. loff = *offset;
  2331. dlen = *buflen;
  2332. /*
  2333. * First smem read, sync smem before proceeding
  2334. * No need to sync before reading every chunk.
  2335. */
  2336. if (loff == 0)
  2337. bfa_ioc_fwsync(ioc);
  2338. if ((loff + dlen) >= smem_len)
  2339. dlen = smem_len - loff;
  2340. status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
  2341. if (status != BFA_STATUS_OK) {
  2342. *offset = *buflen = 0;
  2343. return status;
  2344. }
  2345. *offset += dlen;
  2346. if (*offset >= smem_len)
  2347. *offset = 0;
  2348. *buflen = dlen;
  2349. return status;
  2350. }
  2351. /*
  2352. * Firmware statistics
  2353. */
  2354. bfa_status_t
  2355. bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
  2356. {
  2357. u32 loff = BFI_IOC_FWSTATS_OFF + \
  2358. BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
  2359. int tlen;
  2360. bfa_status_t status;
  2361. if (ioc->stats_busy) {
  2362. bfa_trc(ioc, ioc->stats_busy);
  2363. return BFA_STATUS_DEVBUSY;
  2364. }
  2365. ioc->stats_busy = BFA_TRUE;
  2366. tlen = sizeof(struct bfa_fw_stats_s);
  2367. status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
  2368. ioc->stats_busy = BFA_FALSE;
  2369. return status;
  2370. }
  2371. bfa_status_t
  2372. bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
  2373. {
  2374. u32 loff = BFI_IOC_FWSTATS_OFF + \
  2375. BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
  2376. int tlen;
  2377. bfa_status_t status;
  2378. if (ioc->stats_busy) {
  2379. bfa_trc(ioc, ioc->stats_busy);
  2380. return BFA_STATUS_DEVBUSY;
  2381. }
  2382. ioc->stats_busy = BFA_TRUE;
  2383. tlen = sizeof(struct bfa_fw_stats_s);
  2384. status = bfa_ioc_smem_clr(ioc, loff, tlen);
  2385. ioc->stats_busy = BFA_FALSE;
  2386. return status;
  2387. }
  2388. /*
  2389. * Save firmware trace if configured.
  2390. */
  2391. void
  2392. bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
  2393. {
  2394. int tlen;
  2395. if (ioc->dbg_fwsave_once) {
  2396. ioc->dbg_fwsave_once = BFA_FALSE;
  2397. if (ioc->dbg_fwsave_len) {
  2398. tlen = ioc->dbg_fwsave_len;
  2399. bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
  2400. }
  2401. }
  2402. }
  2403. /*
  2404. * Firmware failure detected. Start recovery actions.
  2405. */
  2406. static void
  2407. bfa_ioc_recover(struct bfa_ioc_s *ioc)
  2408. {
  2409. bfa_ioc_stats(ioc, ioc_hbfails);
  2410. ioc->stats.hb_count = ioc->hb_count;
  2411. bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
  2412. }
  2413. /*
  2414. * BFA IOC PF private functions
  2415. */
  2416. static void
  2417. bfa_iocpf_timeout(void *ioc_arg)
  2418. {
  2419. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2420. bfa_trc(ioc, 0);
  2421. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
  2422. }
  2423. static void
  2424. bfa_iocpf_sem_timeout(void *ioc_arg)
  2425. {
  2426. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2427. bfa_ioc_hw_sem_get(ioc);
  2428. }
  2429. static void
  2430. bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc)
  2431. {
  2432. u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
  2433. bfa_trc(ioc, fwstate);
  2434. if (fwstate == BFI_IOC_DISABLED) {
  2435. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
  2436. return;
  2437. }
  2438. if (ioc->iocpf.poll_time >= (3 * BFA_IOC_TOV))
  2439. bfa_iocpf_timeout(ioc);
  2440. else {
  2441. ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
  2442. bfa_iocpf_poll_timer_start(ioc);
  2443. }
  2444. }
  2445. static void
  2446. bfa_iocpf_poll_timeout(void *ioc_arg)
  2447. {
  2448. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2449. bfa_ioc_poll_fwinit(ioc);
  2450. }
  2451. /*
  2452. * bfa timer function
  2453. */
  2454. void
  2455. bfa_timer_beat(struct bfa_timer_mod_s *mod)
  2456. {
  2457. struct list_head *qh = &mod->timer_q;
  2458. struct list_head *qe, *qe_next;
  2459. struct bfa_timer_s *elem;
  2460. struct list_head timedout_q;
  2461. INIT_LIST_HEAD(&timedout_q);
  2462. qe = bfa_q_next(qh);
  2463. while (qe != qh) {
  2464. qe_next = bfa_q_next(qe);
  2465. elem = (struct bfa_timer_s *) qe;
  2466. if (elem->timeout <= BFA_TIMER_FREQ) {
  2467. elem->timeout = 0;
  2468. list_del(&elem->qe);
  2469. list_add_tail(&elem->qe, &timedout_q);
  2470. } else {
  2471. elem->timeout -= BFA_TIMER_FREQ;
  2472. }
  2473. qe = qe_next; /* go to next elem */
  2474. }
  2475. /*
  2476. * Pop all the timeout entries
  2477. */
  2478. while (!list_empty(&timedout_q)) {
  2479. bfa_q_deq(&timedout_q, &elem);
  2480. elem->timercb(elem->arg);
  2481. }
  2482. }
  2483. /*
  2484. * Should be called with lock protection
  2485. */
  2486. void
  2487. bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
  2488. void (*timercb) (void *), void *arg, unsigned int timeout)
  2489. {
  2490. WARN_ON(timercb == NULL);
  2491. WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
  2492. timer->timeout = timeout;
  2493. timer->timercb = timercb;
  2494. timer->arg = arg;
  2495. list_add_tail(&timer->qe, &mod->timer_q);
  2496. }
  2497. /*
  2498. * Should be called with lock protection
  2499. */
  2500. void
  2501. bfa_timer_stop(struct bfa_timer_s *timer)
  2502. {
  2503. WARN_ON(list_empty(&timer->qe));
  2504. list_del(&timer->qe);
  2505. }
  2506. /*
  2507. * ASIC block related
  2508. */
  2509. static void
  2510. bfa_ablk_config_swap(struct bfa_ablk_cfg_s *cfg)
  2511. {
  2512. struct bfa_ablk_cfg_inst_s *cfg_inst;
  2513. int i, j;
  2514. u16 be16;
  2515. u32 be32;
  2516. for (i = 0; i < BFA_ABLK_MAX; i++) {
  2517. cfg_inst = &cfg->inst[i];
  2518. for (j = 0; j < BFA_ABLK_MAX_PFS; j++) {
  2519. be16 = cfg_inst->pf_cfg[j].pers;
  2520. cfg_inst->pf_cfg[j].pers = be16_to_cpu(be16);
  2521. be16 = cfg_inst->pf_cfg[j].num_qpairs;
  2522. cfg_inst->pf_cfg[j].num_qpairs = be16_to_cpu(be16);
  2523. be16 = cfg_inst->pf_cfg[j].num_vectors;
  2524. cfg_inst->pf_cfg[j].num_vectors = be16_to_cpu(be16);
  2525. be32 = cfg_inst->pf_cfg[j].bw;
  2526. cfg_inst->pf_cfg[j].bw = be16_to_cpu(be32);
  2527. }
  2528. }
  2529. }
  2530. static void
  2531. bfa_ablk_isr(void *cbarg, struct bfi_mbmsg_s *msg)
  2532. {
  2533. struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
  2534. struct bfi_ablk_i2h_rsp_s *rsp = (struct bfi_ablk_i2h_rsp_s *)msg;
  2535. bfa_ablk_cbfn_t cbfn;
  2536. WARN_ON(msg->mh.msg_class != BFI_MC_ABLK);
  2537. bfa_trc(ablk->ioc, msg->mh.msg_id);
  2538. switch (msg->mh.msg_id) {
  2539. case BFI_ABLK_I2H_QUERY:
  2540. if (rsp->status == BFA_STATUS_OK) {
  2541. memcpy(ablk->cfg, ablk->dma_addr.kva,
  2542. sizeof(struct bfa_ablk_cfg_s));
  2543. bfa_ablk_config_swap(ablk->cfg);
  2544. ablk->cfg = NULL;
  2545. }
  2546. break;
  2547. case BFI_ABLK_I2H_ADPT_CONFIG:
  2548. case BFI_ABLK_I2H_PORT_CONFIG:
  2549. /* update config port mode */
  2550. ablk->ioc->port_mode_cfg = rsp->port_mode;
  2551. case BFI_ABLK_I2H_PF_DELETE:
  2552. case BFI_ABLK_I2H_PF_UPDATE:
  2553. case BFI_ABLK_I2H_OPTROM_ENABLE:
  2554. case BFI_ABLK_I2H_OPTROM_DISABLE:
  2555. /* No-op */
  2556. break;
  2557. case BFI_ABLK_I2H_PF_CREATE:
  2558. *(ablk->pcifn) = rsp->pcifn;
  2559. ablk->pcifn = NULL;
  2560. break;
  2561. default:
  2562. WARN_ON(1);
  2563. }
  2564. ablk->busy = BFA_FALSE;
  2565. if (ablk->cbfn) {
  2566. cbfn = ablk->cbfn;
  2567. ablk->cbfn = NULL;
  2568. cbfn(ablk->cbarg, rsp->status);
  2569. }
  2570. }
  2571. static void
  2572. bfa_ablk_notify(void *cbarg, enum bfa_ioc_event_e event)
  2573. {
  2574. struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
  2575. bfa_trc(ablk->ioc, event);
  2576. switch (event) {
  2577. case BFA_IOC_E_ENABLED:
  2578. WARN_ON(ablk->busy != BFA_FALSE);
  2579. break;
  2580. case BFA_IOC_E_DISABLED:
  2581. case BFA_IOC_E_FAILED:
  2582. /* Fail any pending requests */
  2583. ablk->pcifn = NULL;
  2584. if (ablk->busy) {
  2585. if (ablk->cbfn)
  2586. ablk->cbfn(ablk->cbarg, BFA_STATUS_FAILED);
  2587. ablk->cbfn = NULL;
  2588. ablk->busy = BFA_FALSE;
  2589. }
  2590. break;
  2591. default:
  2592. WARN_ON(1);
  2593. break;
  2594. }
  2595. }
  2596. u32
  2597. bfa_ablk_meminfo(void)
  2598. {
  2599. return BFA_ROUNDUP(sizeof(struct bfa_ablk_cfg_s), BFA_DMA_ALIGN_SZ);
  2600. }
  2601. void
  2602. bfa_ablk_memclaim(struct bfa_ablk_s *ablk, u8 *dma_kva, u64 dma_pa)
  2603. {
  2604. ablk->dma_addr.kva = dma_kva;
  2605. ablk->dma_addr.pa = dma_pa;
  2606. }
  2607. void
  2608. bfa_ablk_attach(struct bfa_ablk_s *ablk, struct bfa_ioc_s *ioc)
  2609. {
  2610. ablk->ioc = ioc;
  2611. bfa_ioc_mbox_regisr(ablk->ioc, BFI_MC_ABLK, bfa_ablk_isr, ablk);
  2612. bfa_q_qe_init(&ablk->ioc_notify);
  2613. bfa_ioc_notify_init(&ablk->ioc_notify, bfa_ablk_notify, ablk);
  2614. list_add_tail(&ablk->ioc_notify.qe, &ablk->ioc->notify_q);
  2615. }
  2616. bfa_status_t
  2617. bfa_ablk_query(struct bfa_ablk_s *ablk, struct bfa_ablk_cfg_s *ablk_cfg,
  2618. bfa_ablk_cbfn_t cbfn, void *cbarg)
  2619. {
  2620. struct bfi_ablk_h2i_query_s *m;
  2621. WARN_ON(!ablk_cfg);
  2622. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2623. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2624. return BFA_STATUS_IOC_FAILURE;
  2625. }
  2626. if (ablk->busy) {
  2627. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2628. return BFA_STATUS_DEVBUSY;
  2629. }
  2630. ablk->cfg = ablk_cfg;
  2631. ablk->cbfn = cbfn;
  2632. ablk->cbarg = cbarg;
  2633. ablk->busy = BFA_TRUE;
  2634. m = (struct bfi_ablk_h2i_query_s *)ablk->mb.msg;
  2635. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_QUERY,
  2636. bfa_ioc_portid(ablk->ioc));
  2637. bfa_dma_be_addr_set(m->addr, ablk->dma_addr.pa);
  2638. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2639. return BFA_STATUS_OK;
  2640. }
  2641. bfa_status_t
  2642. bfa_ablk_pf_create(struct bfa_ablk_s *ablk, u16 *pcifn,
  2643. u8 port, enum bfi_pcifn_class personality, int bw,
  2644. bfa_ablk_cbfn_t cbfn, void *cbarg)
  2645. {
  2646. struct bfi_ablk_h2i_pf_req_s *m;
  2647. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2648. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2649. return BFA_STATUS_IOC_FAILURE;
  2650. }
  2651. if (ablk->busy) {
  2652. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2653. return BFA_STATUS_DEVBUSY;
  2654. }
  2655. ablk->pcifn = pcifn;
  2656. ablk->cbfn = cbfn;
  2657. ablk->cbarg = cbarg;
  2658. ablk->busy = BFA_TRUE;
  2659. m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
  2660. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_CREATE,
  2661. bfa_ioc_portid(ablk->ioc));
  2662. m->pers = cpu_to_be16((u16)personality);
  2663. m->bw = cpu_to_be32(bw);
  2664. m->port = port;
  2665. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2666. return BFA_STATUS_OK;
  2667. }
  2668. bfa_status_t
  2669. bfa_ablk_pf_delete(struct bfa_ablk_s *ablk, int pcifn,
  2670. bfa_ablk_cbfn_t cbfn, void *cbarg)
  2671. {
  2672. struct bfi_ablk_h2i_pf_req_s *m;
  2673. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2674. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2675. return BFA_STATUS_IOC_FAILURE;
  2676. }
  2677. if (ablk->busy) {
  2678. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2679. return BFA_STATUS_DEVBUSY;
  2680. }
  2681. ablk->cbfn = cbfn;
  2682. ablk->cbarg = cbarg;
  2683. ablk->busy = BFA_TRUE;
  2684. m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
  2685. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_DELETE,
  2686. bfa_ioc_portid(ablk->ioc));
  2687. m->pcifn = (u8)pcifn;
  2688. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2689. return BFA_STATUS_OK;
  2690. }
  2691. bfa_status_t
  2692. bfa_ablk_adapter_config(struct bfa_ablk_s *ablk, enum bfa_mode_s mode,
  2693. int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2694. {
  2695. struct bfi_ablk_h2i_cfg_req_s *m;
  2696. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2697. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2698. return BFA_STATUS_IOC_FAILURE;
  2699. }
  2700. if (ablk->busy) {
  2701. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2702. return BFA_STATUS_DEVBUSY;
  2703. }
  2704. ablk->cbfn = cbfn;
  2705. ablk->cbarg = cbarg;
  2706. ablk->busy = BFA_TRUE;
  2707. m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
  2708. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_ADPT_CONFIG,
  2709. bfa_ioc_portid(ablk->ioc));
  2710. m->mode = (u8)mode;
  2711. m->max_pf = (u8)max_pf;
  2712. m->max_vf = (u8)max_vf;
  2713. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2714. return BFA_STATUS_OK;
  2715. }
  2716. bfa_status_t
  2717. bfa_ablk_port_config(struct bfa_ablk_s *ablk, int port, enum bfa_mode_s mode,
  2718. int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2719. {
  2720. struct bfi_ablk_h2i_cfg_req_s *m;
  2721. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2722. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2723. return BFA_STATUS_IOC_FAILURE;
  2724. }
  2725. if (ablk->busy) {
  2726. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2727. return BFA_STATUS_DEVBUSY;
  2728. }
  2729. ablk->cbfn = cbfn;
  2730. ablk->cbarg = cbarg;
  2731. ablk->busy = BFA_TRUE;
  2732. m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
  2733. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PORT_CONFIG,
  2734. bfa_ioc_portid(ablk->ioc));
  2735. m->port = (u8)port;
  2736. m->mode = (u8)mode;
  2737. m->max_pf = (u8)max_pf;
  2738. m->max_vf = (u8)max_vf;
  2739. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2740. return BFA_STATUS_OK;
  2741. }
  2742. bfa_status_t
  2743. bfa_ablk_pf_update(struct bfa_ablk_s *ablk, int pcifn, int bw,
  2744. bfa_ablk_cbfn_t cbfn, void *cbarg)
  2745. {
  2746. struct bfi_ablk_h2i_pf_req_s *m;
  2747. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2748. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2749. return BFA_STATUS_IOC_FAILURE;
  2750. }
  2751. if (ablk->busy) {
  2752. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2753. return BFA_STATUS_DEVBUSY;
  2754. }
  2755. ablk->cbfn = cbfn;
  2756. ablk->cbarg = cbarg;
  2757. ablk->busy = BFA_TRUE;
  2758. m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
  2759. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_UPDATE,
  2760. bfa_ioc_portid(ablk->ioc));
  2761. m->pcifn = (u8)pcifn;
  2762. m->bw = cpu_to_be32(bw);
  2763. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2764. return BFA_STATUS_OK;
  2765. }
  2766. bfa_status_t
  2767. bfa_ablk_optrom_en(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2768. {
  2769. struct bfi_ablk_h2i_optrom_s *m;
  2770. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2771. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2772. return BFA_STATUS_IOC_FAILURE;
  2773. }
  2774. if (ablk->busy) {
  2775. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2776. return BFA_STATUS_DEVBUSY;
  2777. }
  2778. ablk->cbfn = cbfn;
  2779. ablk->cbarg = cbarg;
  2780. ablk->busy = BFA_TRUE;
  2781. m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
  2782. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_ENABLE,
  2783. bfa_ioc_portid(ablk->ioc));
  2784. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2785. return BFA_STATUS_OK;
  2786. }
  2787. bfa_status_t
  2788. bfa_ablk_optrom_dis(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2789. {
  2790. struct bfi_ablk_h2i_optrom_s *m;
  2791. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2792. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2793. return BFA_STATUS_IOC_FAILURE;
  2794. }
  2795. if (ablk->busy) {
  2796. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2797. return BFA_STATUS_DEVBUSY;
  2798. }
  2799. ablk->cbfn = cbfn;
  2800. ablk->cbarg = cbarg;
  2801. ablk->busy = BFA_TRUE;
  2802. m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
  2803. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_DISABLE,
  2804. bfa_ioc_portid(ablk->ioc));
  2805. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2806. return BFA_STATUS_OK;
  2807. }
  2808. /*
  2809. * SFP module specific
  2810. */
  2811. /* forward declarations */
  2812. static void bfa_sfp_getdata_send(struct bfa_sfp_s *sfp);
  2813. static void bfa_sfp_media_get(struct bfa_sfp_s *sfp);
  2814. static bfa_status_t bfa_sfp_speed_valid(struct bfa_sfp_s *sfp,
  2815. enum bfa_port_speed portspeed);
  2816. static void
  2817. bfa_cb_sfp_show(struct bfa_sfp_s *sfp)
  2818. {
  2819. bfa_trc(sfp, sfp->lock);
  2820. if (sfp->cbfn)
  2821. sfp->cbfn(sfp->cbarg, sfp->status);
  2822. sfp->lock = 0;
  2823. sfp->cbfn = NULL;
  2824. }
  2825. static void
  2826. bfa_cb_sfp_state_query(struct bfa_sfp_s *sfp)
  2827. {
  2828. bfa_trc(sfp, sfp->portspeed);
  2829. if (sfp->media) {
  2830. bfa_sfp_media_get(sfp);
  2831. if (sfp->state_query_cbfn)
  2832. sfp->state_query_cbfn(sfp->state_query_cbarg,
  2833. sfp->status);
  2834. sfp->media = NULL;
  2835. }
  2836. if (sfp->portspeed) {
  2837. sfp->status = bfa_sfp_speed_valid(sfp, sfp->portspeed);
  2838. if (sfp->state_query_cbfn)
  2839. sfp->state_query_cbfn(sfp->state_query_cbarg,
  2840. sfp->status);
  2841. sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
  2842. }
  2843. sfp->state_query_lock = 0;
  2844. sfp->state_query_cbfn = NULL;
  2845. }
  2846. /*
  2847. * IOC event handler.
  2848. */
  2849. static void
  2850. bfa_sfp_notify(void *sfp_arg, enum bfa_ioc_event_e event)
  2851. {
  2852. struct bfa_sfp_s *sfp = sfp_arg;
  2853. bfa_trc(sfp, event);
  2854. bfa_trc(sfp, sfp->lock);
  2855. bfa_trc(sfp, sfp->state_query_lock);
  2856. switch (event) {
  2857. case BFA_IOC_E_DISABLED:
  2858. case BFA_IOC_E_FAILED:
  2859. if (sfp->lock) {
  2860. sfp->status = BFA_STATUS_IOC_FAILURE;
  2861. bfa_cb_sfp_show(sfp);
  2862. }
  2863. if (sfp->state_query_lock) {
  2864. sfp->status = BFA_STATUS_IOC_FAILURE;
  2865. bfa_cb_sfp_state_query(sfp);
  2866. }
  2867. break;
  2868. default:
  2869. break;
  2870. }
  2871. }
  2872. /*
  2873. * SFP's State Change Notification post to AEN
  2874. */
  2875. static void
  2876. bfa_sfp_scn_aen_post(struct bfa_sfp_s *sfp, struct bfi_sfp_scn_s *rsp)
  2877. {
  2878. struct bfad_s *bfad = (struct bfad_s *)sfp->ioc->bfa->bfad;
  2879. struct bfa_aen_entry_s *aen_entry;
  2880. enum bfa_port_aen_event aen_evt = 0;
  2881. bfa_trc(sfp, (((u64)rsp->pomlvl) << 16) | (((u64)rsp->sfpid) << 8) |
  2882. ((u64)rsp->event));
  2883. bfad_get_aen_entry(bfad, aen_entry);
  2884. if (!aen_entry)
  2885. return;
  2886. aen_entry->aen_data.port.ioc_type = bfa_ioc_get_type(sfp->ioc);
  2887. aen_entry->aen_data.port.pwwn = sfp->ioc->attr->pwwn;
  2888. aen_entry->aen_data.port.mac = bfa_ioc_get_mac(sfp->ioc);
  2889. switch (rsp->event) {
  2890. case BFA_SFP_SCN_INSERTED:
  2891. aen_evt = BFA_PORT_AEN_SFP_INSERT;
  2892. break;
  2893. case BFA_SFP_SCN_REMOVED:
  2894. aen_evt = BFA_PORT_AEN_SFP_REMOVE;
  2895. break;
  2896. case BFA_SFP_SCN_FAILED:
  2897. aen_evt = BFA_PORT_AEN_SFP_ACCESS_ERROR;
  2898. break;
  2899. case BFA_SFP_SCN_UNSUPPORT:
  2900. aen_evt = BFA_PORT_AEN_SFP_UNSUPPORT;
  2901. break;
  2902. case BFA_SFP_SCN_POM:
  2903. aen_evt = BFA_PORT_AEN_SFP_POM;
  2904. aen_entry->aen_data.port.level = rsp->pomlvl;
  2905. break;
  2906. default:
  2907. bfa_trc(sfp, rsp->event);
  2908. WARN_ON(1);
  2909. }
  2910. /* Send the AEN notification */
  2911. bfad_im_post_vendor_event(aen_entry, bfad, ++sfp->ioc->ioc_aen_seq,
  2912. BFA_AEN_CAT_PORT, aen_evt);
  2913. }
  2914. /*
  2915. * SFP get data send
  2916. */
  2917. static void
  2918. bfa_sfp_getdata_send(struct bfa_sfp_s *sfp)
  2919. {
  2920. struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
  2921. bfa_trc(sfp, req->memtype);
  2922. /* build host command */
  2923. bfi_h2i_set(req->mh, BFI_MC_SFP, BFI_SFP_H2I_SHOW,
  2924. bfa_ioc_portid(sfp->ioc));
  2925. /* send mbox cmd */
  2926. bfa_ioc_mbox_queue(sfp->ioc, &sfp->mbcmd);
  2927. }
  2928. /*
  2929. * SFP is valid, read sfp data
  2930. */
  2931. static void
  2932. bfa_sfp_getdata(struct bfa_sfp_s *sfp, enum bfi_sfp_mem_e memtype)
  2933. {
  2934. struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
  2935. WARN_ON(sfp->lock != 0);
  2936. bfa_trc(sfp, sfp->state);
  2937. sfp->lock = 1;
  2938. sfp->memtype = memtype;
  2939. req->memtype = memtype;
  2940. /* Setup SG list */
  2941. bfa_alen_set(&req->alen, sizeof(struct sfp_mem_s), sfp->dbuf_pa);
  2942. bfa_sfp_getdata_send(sfp);
  2943. }
  2944. /*
  2945. * SFP scn handler
  2946. */
  2947. static void
  2948. bfa_sfp_scn(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg)
  2949. {
  2950. struct bfi_sfp_scn_s *rsp = (struct bfi_sfp_scn_s *) msg;
  2951. switch (rsp->event) {
  2952. case BFA_SFP_SCN_INSERTED:
  2953. sfp->state = BFA_SFP_STATE_INSERTED;
  2954. sfp->data_valid = 0;
  2955. bfa_sfp_scn_aen_post(sfp, rsp);
  2956. break;
  2957. case BFA_SFP_SCN_REMOVED:
  2958. sfp->state = BFA_SFP_STATE_REMOVED;
  2959. sfp->data_valid = 0;
  2960. bfa_sfp_scn_aen_post(sfp, rsp);
  2961. break;
  2962. case BFA_SFP_SCN_FAILED:
  2963. sfp->state = BFA_SFP_STATE_FAILED;
  2964. sfp->data_valid = 0;
  2965. bfa_sfp_scn_aen_post(sfp, rsp);
  2966. break;
  2967. case BFA_SFP_SCN_UNSUPPORT:
  2968. sfp->state = BFA_SFP_STATE_UNSUPPORT;
  2969. bfa_sfp_scn_aen_post(sfp, rsp);
  2970. if (!sfp->lock)
  2971. bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
  2972. break;
  2973. case BFA_SFP_SCN_POM:
  2974. bfa_sfp_scn_aen_post(sfp, rsp);
  2975. break;
  2976. case BFA_SFP_SCN_VALID:
  2977. sfp->state = BFA_SFP_STATE_VALID;
  2978. if (!sfp->lock)
  2979. bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
  2980. break;
  2981. default:
  2982. bfa_trc(sfp, rsp->event);
  2983. WARN_ON(1);
  2984. }
  2985. }
  2986. /*
  2987. * SFP show complete
  2988. */
  2989. static void
  2990. bfa_sfp_show_comp(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg)
  2991. {
  2992. struct bfi_sfp_rsp_s *rsp = (struct bfi_sfp_rsp_s *) msg;
  2993. if (!sfp->lock) {
  2994. /*
  2995. * receiving response after ioc failure
  2996. */
  2997. bfa_trc(sfp, sfp->lock);
  2998. return;
  2999. }
  3000. bfa_trc(sfp, rsp->status);
  3001. if (rsp->status == BFA_STATUS_OK) {
  3002. sfp->data_valid = 1;
  3003. if (sfp->state == BFA_SFP_STATE_VALID)
  3004. sfp->status = BFA_STATUS_OK;
  3005. else if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
  3006. sfp->status = BFA_STATUS_SFP_UNSUPP;
  3007. else
  3008. bfa_trc(sfp, sfp->state);
  3009. } else {
  3010. sfp->data_valid = 0;
  3011. sfp->status = rsp->status;
  3012. /* sfpshow shouldn't change sfp state */
  3013. }
  3014. bfa_trc(sfp, sfp->memtype);
  3015. if (sfp->memtype == BFI_SFP_MEM_DIAGEXT) {
  3016. bfa_trc(sfp, sfp->data_valid);
  3017. if (sfp->data_valid) {
  3018. u32 size = sizeof(struct sfp_mem_s);
  3019. u8 *des = (u8 *) &(sfp->sfpmem->srlid_base);
  3020. memcpy(des, sfp->dbuf_kva, size);
  3021. }
  3022. /*
  3023. * Queue completion callback.
  3024. */
  3025. bfa_cb_sfp_show(sfp);
  3026. } else
  3027. sfp->lock = 0;
  3028. bfa_trc(sfp, sfp->state_query_lock);
  3029. if (sfp->state_query_lock) {
  3030. sfp->state = rsp->state;
  3031. /* Complete callback */
  3032. bfa_cb_sfp_state_query(sfp);
  3033. }
  3034. }
  3035. /*
  3036. * SFP query fw sfp state
  3037. */
  3038. static void
  3039. bfa_sfp_state_query(struct bfa_sfp_s *sfp)
  3040. {
  3041. struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
  3042. /* Should not be doing query if not in _INIT state */
  3043. WARN_ON(sfp->state != BFA_SFP_STATE_INIT);
  3044. WARN_ON(sfp->state_query_lock != 0);
  3045. bfa_trc(sfp, sfp->state);
  3046. sfp->state_query_lock = 1;
  3047. req->memtype = 0;
  3048. if (!sfp->lock)
  3049. bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
  3050. }
  3051. static void
  3052. bfa_sfp_media_get(struct bfa_sfp_s *sfp)
  3053. {
  3054. enum bfa_defs_sfp_media_e *media = sfp->media;
  3055. *media = BFA_SFP_MEDIA_UNKNOWN;
  3056. if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
  3057. *media = BFA_SFP_MEDIA_UNSUPPORT;
  3058. else if (sfp->state == BFA_SFP_STATE_VALID) {
  3059. union sfp_xcvr_e10g_code_u e10g;
  3060. struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
  3061. u16 xmtr_tech = (sfpmem->srlid_base.xcvr[4] & 0x3) << 7 |
  3062. (sfpmem->srlid_base.xcvr[5] >> 1);
  3063. e10g.b = sfpmem->srlid_base.xcvr[0];
  3064. bfa_trc(sfp, e10g.b);
  3065. bfa_trc(sfp, xmtr_tech);
  3066. /* check fc transmitter tech */
  3067. if ((xmtr_tech & SFP_XMTR_TECH_CU) ||
  3068. (xmtr_tech & SFP_XMTR_TECH_CP) ||
  3069. (xmtr_tech & SFP_XMTR_TECH_CA))
  3070. *media = BFA_SFP_MEDIA_CU;
  3071. else if ((xmtr_tech & SFP_XMTR_TECH_EL_INTRA) ||
  3072. (xmtr_tech & SFP_XMTR_TECH_EL_INTER))
  3073. *media = BFA_SFP_MEDIA_EL;
  3074. else if ((xmtr_tech & SFP_XMTR_TECH_LL) ||
  3075. (xmtr_tech & SFP_XMTR_TECH_LC))
  3076. *media = BFA_SFP_MEDIA_LW;
  3077. else if ((xmtr_tech & SFP_XMTR_TECH_SL) ||
  3078. (xmtr_tech & SFP_XMTR_TECH_SN) ||
  3079. (xmtr_tech & SFP_XMTR_TECH_SA))
  3080. *media = BFA_SFP_MEDIA_SW;
  3081. /* Check 10G Ethernet Compilance code */
  3082. else if (e10g.r.e10g_sr)
  3083. *media = BFA_SFP_MEDIA_SW;
  3084. else if (e10g.r.e10g_lrm && e10g.r.e10g_lr)
  3085. *media = BFA_SFP_MEDIA_LW;
  3086. else if (e10g.r.e10g_unall)
  3087. *media = BFA_SFP_MEDIA_UNKNOWN;
  3088. else
  3089. bfa_trc(sfp, 0);
  3090. } else
  3091. bfa_trc(sfp, sfp->state);
  3092. }
  3093. static bfa_status_t
  3094. bfa_sfp_speed_valid(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed)
  3095. {
  3096. struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
  3097. struct sfp_xcvr_s *xcvr = (struct sfp_xcvr_s *) sfpmem->srlid_base.xcvr;
  3098. union sfp_xcvr_fc3_code_u fc3 = xcvr->fc3;
  3099. union sfp_xcvr_e10g_code_u e10g = xcvr->e10g;
  3100. if (portspeed == BFA_PORT_SPEED_10GBPS) {
  3101. if (e10g.r.e10g_sr || e10g.r.e10g_lr)
  3102. return BFA_STATUS_OK;
  3103. else {
  3104. bfa_trc(sfp, e10g.b);
  3105. return BFA_STATUS_UNSUPP_SPEED;
  3106. }
  3107. }
  3108. if (((portspeed & BFA_PORT_SPEED_16GBPS) && fc3.r.mb1600) ||
  3109. ((portspeed & BFA_PORT_SPEED_8GBPS) && fc3.r.mb800) ||
  3110. ((portspeed & BFA_PORT_SPEED_4GBPS) && fc3.r.mb400) ||
  3111. ((portspeed & BFA_PORT_SPEED_2GBPS) && fc3.r.mb200) ||
  3112. ((portspeed & BFA_PORT_SPEED_1GBPS) && fc3.r.mb100))
  3113. return BFA_STATUS_OK;
  3114. else {
  3115. bfa_trc(sfp, portspeed);
  3116. bfa_trc(sfp, fc3.b);
  3117. bfa_trc(sfp, e10g.b);
  3118. return BFA_STATUS_UNSUPP_SPEED;
  3119. }
  3120. }
  3121. /*
  3122. * SFP hmbox handler
  3123. */
  3124. void
  3125. bfa_sfp_intr(void *sfparg, struct bfi_mbmsg_s *msg)
  3126. {
  3127. struct bfa_sfp_s *sfp = sfparg;
  3128. switch (msg->mh.msg_id) {
  3129. case BFI_SFP_I2H_SHOW:
  3130. bfa_sfp_show_comp(sfp, msg);
  3131. break;
  3132. case BFI_SFP_I2H_SCN:
  3133. bfa_sfp_scn(sfp, msg);
  3134. break;
  3135. default:
  3136. bfa_trc(sfp, msg->mh.msg_id);
  3137. WARN_ON(1);
  3138. }
  3139. }
  3140. /*
  3141. * Return DMA memory needed by sfp module.
  3142. */
  3143. u32
  3144. bfa_sfp_meminfo(void)
  3145. {
  3146. return BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
  3147. }
  3148. /*
  3149. * Attach virtual and physical memory for SFP.
  3150. */
  3151. void
  3152. bfa_sfp_attach(struct bfa_sfp_s *sfp, struct bfa_ioc_s *ioc, void *dev,
  3153. struct bfa_trc_mod_s *trcmod)
  3154. {
  3155. sfp->dev = dev;
  3156. sfp->ioc = ioc;
  3157. sfp->trcmod = trcmod;
  3158. sfp->cbfn = NULL;
  3159. sfp->cbarg = NULL;
  3160. sfp->sfpmem = NULL;
  3161. sfp->lock = 0;
  3162. sfp->data_valid = 0;
  3163. sfp->state = BFA_SFP_STATE_INIT;
  3164. sfp->state_query_lock = 0;
  3165. sfp->state_query_cbfn = NULL;
  3166. sfp->state_query_cbarg = NULL;
  3167. sfp->media = NULL;
  3168. sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
  3169. sfp->is_elb = BFA_FALSE;
  3170. bfa_ioc_mbox_regisr(sfp->ioc, BFI_MC_SFP, bfa_sfp_intr, sfp);
  3171. bfa_q_qe_init(&sfp->ioc_notify);
  3172. bfa_ioc_notify_init(&sfp->ioc_notify, bfa_sfp_notify, sfp);
  3173. list_add_tail(&sfp->ioc_notify.qe, &sfp->ioc->notify_q);
  3174. }
  3175. /*
  3176. * Claim Memory for SFP
  3177. */
  3178. void
  3179. bfa_sfp_memclaim(struct bfa_sfp_s *sfp, u8 *dm_kva, u64 dm_pa)
  3180. {
  3181. sfp->dbuf_kva = dm_kva;
  3182. sfp->dbuf_pa = dm_pa;
  3183. memset(sfp->dbuf_kva, 0, sizeof(struct sfp_mem_s));
  3184. dm_kva += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
  3185. dm_pa += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
  3186. }
  3187. /*
  3188. * Show SFP eeprom content
  3189. *
  3190. * @param[in] sfp - bfa sfp module
  3191. *
  3192. * @param[out] sfpmem - sfp eeprom data
  3193. *
  3194. */
  3195. bfa_status_t
  3196. bfa_sfp_show(struct bfa_sfp_s *sfp, struct sfp_mem_s *sfpmem,
  3197. bfa_cb_sfp_t cbfn, void *cbarg)
  3198. {
  3199. if (!bfa_ioc_is_operational(sfp->ioc)) {
  3200. bfa_trc(sfp, 0);
  3201. return BFA_STATUS_IOC_NON_OP;
  3202. }
  3203. if (sfp->lock) {
  3204. bfa_trc(sfp, 0);
  3205. return BFA_STATUS_DEVBUSY;
  3206. }
  3207. sfp->cbfn = cbfn;
  3208. sfp->cbarg = cbarg;
  3209. sfp->sfpmem = sfpmem;
  3210. bfa_sfp_getdata(sfp, BFI_SFP_MEM_DIAGEXT);
  3211. return BFA_STATUS_OK;
  3212. }
  3213. /*
  3214. * Return SFP Media type
  3215. *
  3216. * @param[in] sfp - bfa sfp module
  3217. *
  3218. * @param[out] media - port speed from user
  3219. *
  3220. */
  3221. bfa_status_t
  3222. bfa_sfp_media(struct bfa_sfp_s *sfp, enum bfa_defs_sfp_media_e *media,
  3223. bfa_cb_sfp_t cbfn, void *cbarg)
  3224. {
  3225. if (!bfa_ioc_is_operational(sfp->ioc)) {
  3226. bfa_trc(sfp, 0);
  3227. return BFA_STATUS_IOC_NON_OP;
  3228. }
  3229. sfp->media = media;
  3230. if (sfp->state == BFA_SFP_STATE_INIT) {
  3231. if (sfp->state_query_lock) {
  3232. bfa_trc(sfp, 0);
  3233. return BFA_STATUS_DEVBUSY;
  3234. } else {
  3235. sfp->state_query_cbfn = cbfn;
  3236. sfp->state_query_cbarg = cbarg;
  3237. bfa_sfp_state_query(sfp);
  3238. return BFA_STATUS_SFP_NOT_READY;
  3239. }
  3240. }
  3241. bfa_sfp_media_get(sfp);
  3242. return BFA_STATUS_OK;
  3243. }
  3244. /*
  3245. * Check if user set port speed is allowed by the SFP
  3246. *
  3247. * @param[in] sfp - bfa sfp module
  3248. * @param[in] portspeed - port speed from user
  3249. *
  3250. */
  3251. bfa_status_t
  3252. bfa_sfp_speed(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed,
  3253. bfa_cb_sfp_t cbfn, void *cbarg)
  3254. {
  3255. WARN_ON(portspeed == BFA_PORT_SPEED_UNKNOWN);
  3256. if (!bfa_ioc_is_operational(sfp->ioc))
  3257. return BFA_STATUS_IOC_NON_OP;
  3258. /* For Mezz card, all speed is allowed */
  3259. if (bfa_mfg_is_mezz(sfp->ioc->attr->card_type))
  3260. return BFA_STATUS_OK;
  3261. /* Check SFP state */
  3262. sfp->portspeed = portspeed;
  3263. if (sfp->state == BFA_SFP_STATE_INIT) {
  3264. if (sfp->state_query_lock) {
  3265. bfa_trc(sfp, 0);
  3266. return BFA_STATUS_DEVBUSY;
  3267. } else {
  3268. sfp->state_query_cbfn = cbfn;
  3269. sfp->state_query_cbarg = cbarg;
  3270. bfa_sfp_state_query(sfp);
  3271. return BFA_STATUS_SFP_NOT_READY;
  3272. }
  3273. }
  3274. if (sfp->state == BFA_SFP_STATE_REMOVED ||
  3275. sfp->state == BFA_SFP_STATE_FAILED) {
  3276. bfa_trc(sfp, sfp->state);
  3277. return BFA_STATUS_NO_SFP_DEV;
  3278. }
  3279. if (sfp->state == BFA_SFP_STATE_INSERTED) {
  3280. bfa_trc(sfp, sfp->state);
  3281. return BFA_STATUS_DEVBUSY; /* sfp is reading data */
  3282. }
  3283. /* For eloopback, all speed is allowed */
  3284. if (sfp->is_elb)
  3285. return BFA_STATUS_OK;
  3286. return bfa_sfp_speed_valid(sfp, portspeed);
  3287. }
  3288. /*
  3289. * Flash module specific
  3290. */
  3291. /*
  3292. * FLASH DMA buffer should be big enough to hold both MFG block and
  3293. * asic block(64k) at the same time and also should be 2k aligned to
  3294. * avoid write segement to cross sector boundary.
  3295. */
  3296. #define BFA_FLASH_SEG_SZ 2048
  3297. #define BFA_FLASH_DMA_BUF_SZ \
  3298. BFA_ROUNDUP(0x010000 + sizeof(struct bfa_mfg_block_s), BFA_FLASH_SEG_SZ)
  3299. static void
  3300. bfa_flash_aen_audit_post(struct bfa_ioc_s *ioc, enum bfa_audit_aen_event event,
  3301. int inst, int type)
  3302. {
  3303. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  3304. struct bfa_aen_entry_s *aen_entry;
  3305. bfad_get_aen_entry(bfad, aen_entry);
  3306. if (!aen_entry)
  3307. return;
  3308. aen_entry->aen_data.audit.pwwn = ioc->attr->pwwn;
  3309. aen_entry->aen_data.audit.partition_inst = inst;
  3310. aen_entry->aen_data.audit.partition_type = type;
  3311. /* Send the AEN notification */
  3312. bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq,
  3313. BFA_AEN_CAT_AUDIT, event);
  3314. }
  3315. static void
  3316. bfa_flash_cb(struct bfa_flash_s *flash)
  3317. {
  3318. flash->op_busy = 0;
  3319. if (flash->cbfn)
  3320. flash->cbfn(flash->cbarg, flash->status);
  3321. }
  3322. static void
  3323. bfa_flash_notify(void *cbarg, enum bfa_ioc_event_e event)
  3324. {
  3325. struct bfa_flash_s *flash = cbarg;
  3326. bfa_trc(flash, event);
  3327. switch (event) {
  3328. case BFA_IOC_E_DISABLED:
  3329. case BFA_IOC_E_FAILED:
  3330. if (flash->op_busy) {
  3331. flash->status = BFA_STATUS_IOC_FAILURE;
  3332. flash->cbfn(flash->cbarg, flash->status);
  3333. flash->op_busy = 0;
  3334. }
  3335. break;
  3336. default:
  3337. break;
  3338. }
  3339. }
  3340. /*
  3341. * Send flash attribute query request.
  3342. *
  3343. * @param[in] cbarg - callback argument
  3344. */
  3345. static void
  3346. bfa_flash_query_send(void *cbarg)
  3347. {
  3348. struct bfa_flash_s *flash = cbarg;
  3349. struct bfi_flash_query_req_s *msg =
  3350. (struct bfi_flash_query_req_s *) flash->mb.msg;
  3351. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_QUERY_REQ,
  3352. bfa_ioc_portid(flash->ioc));
  3353. bfa_alen_set(&msg->alen, sizeof(struct bfa_flash_attr_s),
  3354. flash->dbuf_pa);
  3355. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3356. }
  3357. /*
  3358. * Send flash write request.
  3359. *
  3360. * @param[in] cbarg - callback argument
  3361. */
  3362. static void
  3363. bfa_flash_write_send(struct bfa_flash_s *flash)
  3364. {
  3365. struct bfi_flash_write_req_s *msg =
  3366. (struct bfi_flash_write_req_s *) flash->mb.msg;
  3367. u32 len;
  3368. msg->type = be32_to_cpu(flash->type);
  3369. msg->instance = flash->instance;
  3370. msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
  3371. len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
  3372. flash->residue : BFA_FLASH_DMA_BUF_SZ;
  3373. msg->length = be32_to_cpu(len);
  3374. /* indicate if it's the last msg of the whole write operation */
  3375. msg->last = (len == flash->residue) ? 1 : 0;
  3376. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_WRITE_REQ,
  3377. bfa_ioc_portid(flash->ioc));
  3378. bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
  3379. memcpy(flash->dbuf_kva, flash->ubuf + flash->offset, len);
  3380. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3381. flash->residue -= len;
  3382. flash->offset += len;
  3383. }
  3384. /*
  3385. * Send flash read request.
  3386. *
  3387. * @param[in] cbarg - callback argument
  3388. */
  3389. static void
  3390. bfa_flash_read_send(void *cbarg)
  3391. {
  3392. struct bfa_flash_s *flash = cbarg;
  3393. struct bfi_flash_read_req_s *msg =
  3394. (struct bfi_flash_read_req_s *) flash->mb.msg;
  3395. u32 len;
  3396. msg->type = be32_to_cpu(flash->type);
  3397. msg->instance = flash->instance;
  3398. msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
  3399. len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
  3400. flash->residue : BFA_FLASH_DMA_BUF_SZ;
  3401. msg->length = be32_to_cpu(len);
  3402. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_READ_REQ,
  3403. bfa_ioc_portid(flash->ioc));
  3404. bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
  3405. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3406. }
  3407. /*
  3408. * Send flash erase request.
  3409. *
  3410. * @param[in] cbarg - callback argument
  3411. */
  3412. static void
  3413. bfa_flash_erase_send(void *cbarg)
  3414. {
  3415. struct bfa_flash_s *flash = cbarg;
  3416. struct bfi_flash_erase_req_s *msg =
  3417. (struct bfi_flash_erase_req_s *) flash->mb.msg;
  3418. msg->type = be32_to_cpu(flash->type);
  3419. msg->instance = flash->instance;
  3420. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_ERASE_REQ,
  3421. bfa_ioc_portid(flash->ioc));
  3422. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3423. }
  3424. /*
  3425. * Process flash response messages upon receiving interrupts.
  3426. *
  3427. * @param[in] flasharg - flash structure
  3428. * @param[in] msg - message structure
  3429. */
  3430. static void
  3431. bfa_flash_intr(void *flasharg, struct bfi_mbmsg_s *msg)
  3432. {
  3433. struct bfa_flash_s *flash = flasharg;
  3434. u32 status;
  3435. union {
  3436. struct bfi_flash_query_rsp_s *query;
  3437. struct bfi_flash_erase_rsp_s *erase;
  3438. struct bfi_flash_write_rsp_s *write;
  3439. struct bfi_flash_read_rsp_s *read;
  3440. struct bfi_flash_event_s *event;
  3441. struct bfi_mbmsg_s *msg;
  3442. } m;
  3443. m.msg = msg;
  3444. bfa_trc(flash, msg->mh.msg_id);
  3445. if (!flash->op_busy && msg->mh.msg_id != BFI_FLASH_I2H_EVENT) {
  3446. /* receiving response after ioc failure */
  3447. bfa_trc(flash, 0x9999);
  3448. return;
  3449. }
  3450. switch (msg->mh.msg_id) {
  3451. case BFI_FLASH_I2H_QUERY_RSP:
  3452. status = be32_to_cpu(m.query->status);
  3453. bfa_trc(flash, status);
  3454. if (status == BFA_STATUS_OK) {
  3455. u32 i;
  3456. struct bfa_flash_attr_s *attr, *f;
  3457. attr = (struct bfa_flash_attr_s *) flash->ubuf;
  3458. f = (struct bfa_flash_attr_s *) flash->dbuf_kva;
  3459. attr->status = be32_to_cpu(f->status);
  3460. attr->npart = be32_to_cpu(f->npart);
  3461. bfa_trc(flash, attr->status);
  3462. bfa_trc(flash, attr->npart);
  3463. for (i = 0; i < attr->npart; i++) {
  3464. attr->part[i].part_type =
  3465. be32_to_cpu(f->part[i].part_type);
  3466. attr->part[i].part_instance =
  3467. be32_to_cpu(f->part[i].part_instance);
  3468. attr->part[i].part_off =
  3469. be32_to_cpu(f->part[i].part_off);
  3470. attr->part[i].part_size =
  3471. be32_to_cpu(f->part[i].part_size);
  3472. attr->part[i].part_len =
  3473. be32_to_cpu(f->part[i].part_len);
  3474. attr->part[i].part_status =
  3475. be32_to_cpu(f->part[i].part_status);
  3476. }
  3477. }
  3478. flash->status = status;
  3479. bfa_flash_cb(flash);
  3480. break;
  3481. case BFI_FLASH_I2H_ERASE_RSP:
  3482. status = be32_to_cpu(m.erase->status);
  3483. bfa_trc(flash, status);
  3484. flash->status = status;
  3485. bfa_flash_cb(flash);
  3486. break;
  3487. case BFI_FLASH_I2H_WRITE_RSP:
  3488. status = be32_to_cpu(m.write->status);
  3489. bfa_trc(flash, status);
  3490. if (status != BFA_STATUS_OK || flash->residue == 0) {
  3491. flash->status = status;
  3492. bfa_flash_cb(flash);
  3493. } else {
  3494. bfa_trc(flash, flash->offset);
  3495. bfa_flash_write_send(flash);
  3496. }
  3497. break;
  3498. case BFI_FLASH_I2H_READ_RSP:
  3499. status = be32_to_cpu(m.read->status);
  3500. bfa_trc(flash, status);
  3501. if (status != BFA_STATUS_OK) {
  3502. flash->status = status;
  3503. bfa_flash_cb(flash);
  3504. } else {
  3505. u32 len = be32_to_cpu(m.read->length);
  3506. bfa_trc(flash, flash->offset);
  3507. bfa_trc(flash, len);
  3508. memcpy(flash->ubuf + flash->offset,
  3509. flash->dbuf_kva, len);
  3510. flash->residue -= len;
  3511. flash->offset += len;
  3512. if (flash->residue == 0) {
  3513. flash->status = status;
  3514. bfa_flash_cb(flash);
  3515. } else
  3516. bfa_flash_read_send(flash);
  3517. }
  3518. break;
  3519. case BFI_FLASH_I2H_BOOT_VER_RSP:
  3520. break;
  3521. case BFI_FLASH_I2H_EVENT:
  3522. status = be32_to_cpu(m.event->status);
  3523. bfa_trc(flash, status);
  3524. if (status == BFA_STATUS_BAD_FWCFG)
  3525. bfa_ioc_aen_post(flash->ioc, BFA_IOC_AEN_FWCFG_ERROR);
  3526. else if (status == BFA_STATUS_INVALID_VENDOR) {
  3527. u32 param;
  3528. param = be32_to_cpu(m.event->param);
  3529. bfa_trc(flash, param);
  3530. bfa_ioc_aen_post(flash->ioc,
  3531. BFA_IOC_AEN_INVALID_VENDOR);
  3532. }
  3533. break;
  3534. default:
  3535. WARN_ON(1);
  3536. }
  3537. }
  3538. /*
  3539. * Flash memory info API.
  3540. *
  3541. * @param[in] mincfg - minimal cfg variable
  3542. */
  3543. u32
  3544. bfa_flash_meminfo(bfa_boolean_t mincfg)
  3545. {
  3546. /* min driver doesn't need flash */
  3547. if (mincfg)
  3548. return 0;
  3549. return BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  3550. }
  3551. /*
  3552. * Flash attach API.
  3553. *
  3554. * @param[in] flash - flash structure
  3555. * @param[in] ioc - ioc structure
  3556. * @param[in] dev - device structure
  3557. * @param[in] trcmod - trace module
  3558. * @param[in] logmod - log module
  3559. */
  3560. void
  3561. bfa_flash_attach(struct bfa_flash_s *flash, struct bfa_ioc_s *ioc, void *dev,
  3562. struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
  3563. {
  3564. flash->ioc = ioc;
  3565. flash->trcmod = trcmod;
  3566. flash->cbfn = NULL;
  3567. flash->cbarg = NULL;
  3568. flash->op_busy = 0;
  3569. bfa_ioc_mbox_regisr(flash->ioc, BFI_MC_FLASH, bfa_flash_intr, flash);
  3570. bfa_q_qe_init(&flash->ioc_notify);
  3571. bfa_ioc_notify_init(&flash->ioc_notify, bfa_flash_notify, flash);
  3572. list_add_tail(&flash->ioc_notify.qe, &flash->ioc->notify_q);
  3573. /* min driver doesn't need flash */
  3574. if (mincfg) {
  3575. flash->dbuf_kva = NULL;
  3576. flash->dbuf_pa = 0;
  3577. }
  3578. }
  3579. /*
  3580. * Claim memory for flash
  3581. *
  3582. * @param[in] flash - flash structure
  3583. * @param[in] dm_kva - pointer to virtual memory address
  3584. * @param[in] dm_pa - physical memory address
  3585. * @param[in] mincfg - minimal cfg variable
  3586. */
  3587. void
  3588. bfa_flash_memclaim(struct bfa_flash_s *flash, u8 *dm_kva, u64 dm_pa,
  3589. bfa_boolean_t mincfg)
  3590. {
  3591. if (mincfg)
  3592. return;
  3593. flash->dbuf_kva = dm_kva;
  3594. flash->dbuf_pa = dm_pa;
  3595. memset(flash->dbuf_kva, 0, BFA_FLASH_DMA_BUF_SZ);
  3596. dm_kva += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  3597. dm_pa += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  3598. }
  3599. /*
  3600. * Get flash attribute.
  3601. *
  3602. * @param[in] flash - flash structure
  3603. * @param[in] attr - flash attribute structure
  3604. * @param[in] cbfn - callback function
  3605. * @param[in] cbarg - callback argument
  3606. *
  3607. * Return status.
  3608. */
  3609. bfa_status_t
  3610. bfa_flash_get_attr(struct bfa_flash_s *flash, struct bfa_flash_attr_s *attr,
  3611. bfa_cb_flash_t cbfn, void *cbarg)
  3612. {
  3613. bfa_trc(flash, BFI_FLASH_H2I_QUERY_REQ);
  3614. if (!bfa_ioc_is_operational(flash->ioc))
  3615. return BFA_STATUS_IOC_NON_OP;
  3616. if (flash->op_busy) {
  3617. bfa_trc(flash, flash->op_busy);
  3618. return BFA_STATUS_DEVBUSY;
  3619. }
  3620. flash->op_busy = 1;
  3621. flash->cbfn = cbfn;
  3622. flash->cbarg = cbarg;
  3623. flash->ubuf = (u8 *) attr;
  3624. bfa_flash_query_send(flash);
  3625. return BFA_STATUS_OK;
  3626. }
  3627. /*
  3628. * Erase flash partition.
  3629. *
  3630. * @param[in] flash - flash structure
  3631. * @param[in] type - flash partition type
  3632. * @param[in] instance - flash partition instance
  3633. * @param[in] cbfn - callback function
  3634. * @param[in] cbarg - callback argument
  3635. *
  3636. * Return status.
  3637. */
  3638. bfa_status_t
  3639. bfa_flash_erase_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
  3640. u8 instance, bfa_cb_flash_t cbfn, void *cbarg)
  3641. {
  3642. bfa_trc(flash, BFI_FLASH_H2I_ERASE_REQ);
  3643. bfa_trc(flash, type);
  3644. bfa_trc(flash, instance);
  3645. if (!bfa_ioc_is_operational(flash->ioc))
  3646. return BFA_STATUS_IOC_NON_OP;
  3647. if (flash->op_busy) {
  3648. bfa_trc(flash, flash->op_busy);
  3649. return BFA_STATUS_DEVBUSY;
  3650. }
  3651. flash->op_busy = 1;
  3652. flash->cbfn = cbfn;
  3653. flash->cbarg = cbarg;
  3654. flash->type = type;
  3655. flash->instance = instance;
  3656. bfa_flash_erase_send(flash);
  3657. bfa_flash_aen_audit_post(flash->ioc, BFA_AUDIT_AEN_FLASH_ERASE,
  3658. instance, type);
  3659. return BFA_STATUS_OK;
  3660. }
  3661. /*
  3662. * Update flash partition.
  3663. *
  3664. * @param[in] flash - flash structure
  3665. * @param[in] type - flash partition type
  3666. * @param[in] instance - flash partition instance
  3667. * @param[in] buf - update data buffer
  3668. * @param[in] len - data buffer length
  3669. * @param[in] offset - offset relative to the partition starting address
  3670. * @param[in] cbfn - callback function
  3671. * @param[in] cbarg - callback argument
  3672. *
  3673. * Return status.
  3674. */
  3675. bfa_status_t
  3676. bfa_flash_update_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
  3677. u8 instance, void *buf, u32 len, u32 offset,
  3678. bfa_cb_flash_t cbfn, void *cbarg)
  3679. {
  3680. bfa_trc(flash, BFI_FLASH_H2I_WRITE_REQ);
  3681. bfa_trc(flash, type);
  3682. bfa_trc(flash, instance);
  3683. bfa_trc(flash, len);
  3684. bfa_trc(flash, offset);
  3685. if (!bfa_ioc_is_operational(flash->ioc))
  3686. return BFA_STATUS_IOC_NON_OP;
  3687. /*
  3688. * 'len' must be in word (4-byte) boundary
  3689. * 'offset' must be in sector (16kb) boundary
  3690. */
  3691. if (!len || (len & 0x03) || (offset & 0x00003FFF))
  3692. return BFA_STATUS_FLASH_BAD_LEN;
  3693. if (type == BFA_FLASH_PART_MFG)
  3694. return BFA_STATUS_EINVAL;
  3695. if (flash->op_busy) {
  3696. bfa_trc(flash, flash->op_busy);
  3697. return BFA_STATUS_DEVBUSY;
  3698. }
  3699. flash->op_busy = 1;
  3700. flash->cbfn = cbfn;
  3701. flash->cbarg = cbarg;
  3702. flash->type = type;
  3703. flash->instance = instance;
  3704. flash->residue = len;
  3705. flash->offset = 0;
  3706. flash->addr_off = offset;
  3707. flash->ubuf = buf;
  3708. bfa_flash_write_send(flash);
  3709. return BFA_STATUS_OK;
  3710. }
  3711. /*
  3712. * Read flash partition.
  3713. *
  3714. * @param[in] flash - flash structure
  3715. * @param[in] type - flash partition type
  3716. * @param[in] instance - flash partition instance
  3717. * @param[in] buf - read data buffer
  3718. * @param[in] len - data buffer length
  3719. * @param[in] offset - offset relative to the partition starting address
  3720. * @param[in] cbfn - callback function
  3721. * @param[in] cbarg - callback argument
  3722. *
  3723. * Return status.
  3724. */
  3725. bfa_status_t
  3726. bfa_flash_read_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
  3727. u8 instance, void *buf, u32 len, u32 offset,
  3728. bfa_cb_flash_t cbfn, void *cbarg)
  3729. {
  3730. bfa_trc(flash, BFI_FLASH_H2I_READ_REQ);
  3731. bfa_trc(flash, type);
  3732. bfa_trc(flash, instance);
  3733. bfa_trc(flash, len);
  3734. bfa_trc(flash, offset);
  3735. if (!bfa_ioc_is_operational(flash->ioc))
  3736. return BFA_STATUS_IOC_NON_OP;
  3737. /*
  3738. * 'len' must be in word (4-byte) boundary
  3739. * 'offset' must be in sector (16kb) boundary
  3740. */
  3741. if (!len || (len & 0x03) || (offset & 0x00003FFF))
  3742. return BFA_STATUS_FLASH_BAD_LEN;
  3743. if (flash->op_busy) {
  3744. bfa_trc(flash, flash->op_busy);
  3745. return BFA_STATUS_DEVBUSY;
  3746. }
  3747. flash->op_busy = 1;
  3748. flash->cbfn = cbfn;
  3749. flash->cbarg = cbarg;
  3750. flash->type = type;
  3751. flash->instance = instance;
  3752. flash->residue = len;
  3753. flash->offset = 0;
  3754. flash->addr_off = offset;
  3755. flash->ubuf = buf;
  3756. bfa_flash_read_send(flash);
  3757. return BFA_STATUS_OK;
  3758. }
  3759. /*
  3760. * DIAG module specific
  3761. */
  3762. #define BFA_DIAG_MEMTEST_TOV 50000 /* memtest timeout in msec */
  3763. #define CT2_BFA_DIAG_MEMTEST_TOV (9*30*1000) /* 4.5 min */
  3764. /* IOC event handler */
  3765. static void
  3766. bfa_diag_notify(void *diag_arg, enum bfa_ioc_event_e event)
  3767. {
  3768. struct bfa_diag_s *diag = diag_arg;
  3769. bfa_trc(diag, event);
  3770. bfa_trc(diag, diag->block);
  3771. bfa_trc(diag, diag->fwping.lock);
  3772. bfa_trc(diag, diag->tsensor.lock);
  3773. switch (event) {
  3774. case BFA_IOC_E_DISABLED:
  3775. case BFA_IOC_E_FAILED:
  3776. if (diag->fwping.lock) {
  3777. diag->fwping.status = BFA_STATUS_IOC_FAILURE;
  3778. diag->fwping.cbfn(diag->fwping.cbarg,
  3779. diag->fwping.status);
  3780. diag->fwping.lock = 0;
  3781. }
  3782. if (diag->tsensor.lock) {
  3783. diag->tsensor.status = BFA_STATUS_IOC_FAILURE;
  3784. diag->tsensor.cbfn(diag->tsensor.cbarg,
  3785. diag->tsensor.status);
  3786. diag->tsensor.lock = 0;
  3787. }
  3788. if (diag->block) {
  3789. if (diag->timer_active) {
  3790. bfa_timer_stop(&diag->timer);
  3791. diag->timer_active = 0;
  3792. }
  3793. diag->status = BFA_STATUS_IOC_FAILURE;
  3794. diag->cbfn(diag->cbarg, diag->status);
  3795. diag->block = 0;
  3796. }
  3797. break;
  3798. default:
  3799. break;
  3800. }
  3801. }
  3802. static void
  3803. bfa_diag_memtest_done(void *cbarg)
  3804. {
  3805. struct bfa_diag_s *diag = cbarg;
  3806. struct bfa_ioc_s *ioc = diag->ioc;
  3807. struct bfa_diag_memtest_result *res = diag->result;
  3808. u32 loff = BFI_BOOT_MEMTEST_RES_ADDR;
  3809. u32 pgnum, pgoff, i;
  3810. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  3811. pgoff = PSS_SMEM_PGOFF(loff);
  3812. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  3813. for (i = 0; i < (sizeof(struct bfa_diag_memtest_result) /
  3814. sizeof(u32)); i++) {
  3815. /* read test result from smem */
  3816. *((u32 *) res + i) =
  3817. bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  3818. loff += sizeof(u32);
  3819. }
  3820. /* Reset IOC fwstates to BFI_IOC_UNINIT */
  3821. bfa_ioc_reset_fwstate(ioc);
  3822. res->status = swab32(res->status);
  3823. bfa_trc(diag, res->status);
  3824. if (res->status == BFI_BOOT_MEMTEST_RES_SIG)
  3825. diag->status = BFA_STATUS_OK;
  3826. else {
  3827. diag->status = BFA_STATUS_MEMTEST_FAILED;
  3828. res->addr = swab32(res->addr);
  3829. res->exp = swab32(res->exp);
  3830. res->act = swab32(res->act);
  3831. res->err_status = swab32(res->err_status);
  3832. res->err_status1 = swab32(res->err_status1);
  3833. res->err_addr = swab32(res->err_addr);
  3834. bfa_trc(diag, res->addr);
  3835. bfa_trc(diag, res->exp);
  3836. bfa_trc(diag, res->act);
  3837. bfa_trc(diag, res->err_status);
  3838. bfa_trc(diag, res->err_status1);
  3839. bfa_trc(diag, res->err_addr);
  3840. }
  3841. diag->timer_active = 0;
  3842. diag->cbfn(diag->cbarg, diag->status);
  3843. diag->block = 0;
  3844. }
  3845. /*
  3846. * Firmware ping
  3847. */
  3848. /*
  3849. * Perform DMA test directly
  3850. */
  3851. static void
  3852. diag_fwping_send(struct bfa_diag_s *diag)
  3853. {
  3854. struct bfi_diag_fwping_req_s *fwping_req;
  3855. u32 i;
  3856. bfa_trc(diag, diag->fwping.dbuf_pa);
  3857. /* fill DMA area with pattern */
  3858. for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++)
  3859. *((u32 *)diag->fwping.dbuf_kva + i) = diag->fwping.data;
  3860. /* Fill mbox msg */
  3861. fwping_req = (struct bfi_diag_fwping_req_s *)diag->fwping.mbcmd.msg;
  3862. /* Setup SG list */
  3863. bfa_alen_set(&fwping_req->alen, BFI_DIAG_DMA_BUF_SZ,
  3864. diag->fwping.dbuf_pa);
  3865. /* Set up dma count */
  3866. fwping_req->count = cpu_to_be32(diag->fwping.count);
  3867. /* Set up data pattern */
  3868. fwping_req->data = diag->fwping.data;
  3869. /* build host command */
  3870. bfi_h2i_set(fwping_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_FWPING,
  3871. bfa_ioc_portid(diag->ioc));
  3872. /* send mbox cmd */
  3873. bfa_ioc_mbox_queue(diag->ioc, &diag->fwping.mbcmd);
  3874. }
  3875. static void
  3876. diag_fwping_comp(struct bfa_diag_s *diag,
  3877. struct bfi_diag_fwping_rsp_s *diag_rsp)
  3878. {
  3879. u32 rsp_data = diag_rsp->data;
  3880. u8 rsp_dma_status = diag_rsp->dma_status;
  3881. bfa_trc(diag, rsp_data);
  3882. bfa_trc(diag, rsp_dma_status);
  3883. if (rsp_dma_status == BFA_STATUS_OK) {
  3884. u32 i, pat;
  3885. pat = (diag->fwping.count & 0x1) ? ~(diag->fwping.data) :
  3886. diag->fwping.data;
  3887. /* Check mbox data */
  3888. if (diag->fwping.data != rsp_data) {
  3889. bfa_trc(diag, rsp_data);
  3890. diag->fwping.result->dmastatus =
  3891. BFA_STATUS_DATACORRUPTED;
  3892. diag->fwping.status = BFA_STATUS_DATACORRUPTED;
  3893. diag->fwping.cbfn(diag->fwping.cbarg,
  3894. diag->fwping.status);
  3895. diag->fwping.lock = 0;
  3896. return;
  3897. }
  3898. /* Check dma pattern */
  3899. for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++) {
  3900. if (*((u32 *)diag->fwping.dbuf_kva + i) != pat) {
  3901. bfa_trc(diag, i);
  3902. bfa_trc(diag, pat);
  3903. bfa_trc(diag,
  3904. *((u32 *)diag->fwping.dbuf_kva + i));
  3905. diag->fwping.result->dmastatus =
  3906. BFA_STATUS_DATACORRUPTED;
  3907. diag->fwping.status = BFA_STATUS_DATACORRUPTED;
  3908. diag->fwping.cbfn(diag->fwping.cbarg,
  3909. diag->fwping.status);
  3910. diag->fwping.lock = 0;
  3911. return;
  3912. }
  3913. }
  3914. diag->fwping.result->dmastatus = BFA_STATUS_OK;
  3915. diag->fwping.status = BFA_STATUS_OK;
  3916. diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status);
  3917. diag->fwping.lock = 0;
  3918. } else {
  3919. diag->fwping.status = BFA_STATUS_HDMA_FAILED;
  3920. diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status);
  3921. diag->fwping.lock = 0;
  3922. }
  3923. }
  3924. /*
  3925. * Temperature Sensor
  3926. */
  3927. static void
  3928. diag_tempsensor_send(struct bfa_diag_s *diag)
  3929. {
  3930. struct bfi_diag_ts_req_s *msg;
  3931. msg = (struct bfi_diag_ts_req_s *)diag->tsensor.mbcmd.msg;
  3932. bfa_trc(diag, msg->temp);
  3933. /* build host command */
  3934. bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_TEMPSENSOR,
  3935. bfa_ioc_portid(diag->ioc));
  3936. /* send mbox cmd */
  3937. bfa_ioc_mbox_queue(diag->ioc, &diag->tsensor.mbcmd);
  3938. }
  3939. static void
  3940. diag_tempsensor_comp(struct bfa_diag_s *diag, bfi_diag_ts_rsp_t *rsp)
  3941. {
  3942. if (!diag->tsensor.lock) {
  3943. /* receiving response after ioc failure */
  3944. bfa_trc(diag, diag->tsensor.lock);
  3945. return;
  3946. }
  3947. /*
  3948. * ASIC junction tempsensor is a reg read operation
  3949. * it will always return OK
  3950. */
  3951. diag->tsensor.temp->temp = be16_to_cpu(rsp->temp);
  3952. diag->tsensor.temp->ts_junc = rsp->ts_junc;
  3953. diag->tsensor.temp->ts_brd = rsp->ts_brd;
  3954. diag->tsensor.temp->status = BFA_STATUS_OK;
  3955. if (rsp->ts_brd) {
  3956. if (rsp->status == BFA_STATUS_OK) {
  3957. diag->tsensor.temp->brd_temp =
  3958. be16_to_cpu(rsp->brd_temp);
  3959. } else {
  3960. bfa_trc(diag, rsp->status);
  3961. diag->tsensor.temp->brd_temp = 0;
  3962. diag->tsensor.temp->status = BFA_STATUS_DEVBUSY;
  3963. }
  3964. }
  3965. bfa_trc(diag, rsp->ts_junc);
  3966. bfa_trc(diag, rsp->temp);
  3967. bfa_trc(diag, rsp->ts_brd);
  3968. bfa_trc(diag, rsp->brd_temp);
  3969. diag->tsensor.cbfn(diag->tsensor.cbarg, diag->tsensor.status);
  3970. diag->tsensor.lock = 0;
  3971. }
  3972. /*
  3973. * LED Test command
  3974. */
  3975. static void
  3976. diag_ledtest_send(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest)
  3977. {
  3978. struct bfi_diag_ledtest_req_s *msg;
  3979. msg = (struct bfi_diag_ledtest_req_s *)diag->ledtest.mbcmd.msg;
  3980. /* build host command */
  3981. bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LEDTEST,
  3982. bfa_ioc_portid(diag->ioc));
  3983. /*
  3984. * convert the freq from N blinks per 10 sec to
  3985. * crossbow ontime value. We do it here because division is need
  3986. */
  3987. if (ledtest->freq)
  3988. ledtest->freq = 500 / ledtest->freq;
  3989. if (ledtest->freq == 0)
  3990. ledtest->freq = 1;
  3991. bfa_trc(diag, ledtest->freq);
  3992. /* mcpy(&ledtest_req->req, ledtest, sizeof(bfa_diag_ledtest_t)); */
  3993. msg->cmd = (u8) ledtest->cmd;
  3994. msg->color = (u8) ledtest->color;
  3995. msg->portid = bfa_ioc_portid(diag->ioc);
  3996. msg->led = ledtest->led;
  3997. msg->freq = cpu_to_be16(ledtest->freq);
  3998. /* send mbox cmd */
  3999. bfa_ioc_mbox_queue(diag->ioc, &diag->ledtest.mbcmd);
  4000. }
  4001. static void
  4002. diag_ledtest_comp(struct bfa_diag_s *diag, struct bfi_diag_ledtest_rsp_s *msg)
  4003. {
  4004. bfa_trc(diag, diag->ledtest.lock);
  4005. diag->ledtest.lock = BFA_FALSE;
  4006. /* no bfa_cb_queue is needed because driver is not waiting */
  4007. }
  4008. /*
  4009. * Port beaconing
  4010. */
  4011. static void
  4012. diag_portbeacon_send(struct bfa_diag_s *diag, bfa_boolean_t beacon, u32 sec)
  4013. {
  4014. struct bfi_diag_portbeacon_req_s *msg;
  4015. msg = (struct bfi_diag_portbeacon_req_s *)diag->beacon.mbcmd.msg;
  4016. /* build host command */
  4017. bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_PORTBEACON,
  4018. bfa_ioc_portid(diag->ioc));
  4019. msg->beacon = beacon;
  4020. msg->period = cpu_to_be32(sec);
  4021. /* send mbox cmd */
  4022. bfa_ioc_mbox_queue(diag->ioc, &diag->beacon.mbcmd);
  4023. }
  4024. static void
  4025. diag_portbeacon_comp(struct bfa_diag_s *diag)
  4026. {
  4027. bfa_trc(diag, diag->beacon.state);
  4028. diag->beacon.state = BFA_FALSE;
  4029. if (diag->cbfn_beacon)
  4030. diag->cbfn_beacon(diag->dev, BFA_FALSE, diag->beacon.link_e2e);
  4031. }
  4032. /*
  4033. * Diag hmbox handler
  4034. */
  4035. void
  4036. bfa_diag_intr(void *diagarg, struct bfi_mbmsg_s *msg)
  4037. {
  4038. struct bfa_diag_s *diag = diagarg;
  4039. switch (msg->mh.msg_id) {
  4040. case BFI_DIAG_I2H_PORTBEACON:
  4041. diag_portbeacon_comp(diag);
  4042. break;
  4043. case BFI_DIAG_I2H_FWPING:
  4044. diag_fwping_comp(diag, (struct bfi_diag_fwping_rsp_s *) msg);
  4045. break;
  4046. case BFI_DIAG_I2H_TEMPSENSOR:
  4047. diag_tempsensor_comp(diag, (bfi_diag_ts_rsp_t *) msg);
  4048. break;
  4049. case BFI_DIAG_I2H_LEDTEST:
  4050. diag_ledtest_comp(diag, (struct bfi_diag_ledtest_rsp_s *) msg);
  4051. break;
  4052. default:
  4053. bfa_trc(diag, msg->mh.msg_id);
  4054. WARN_ON(1);
  4055. }
  4056. }
  4057. /*
  4058. * Gen RAM Test
  4059. *
  4060. * @param[in] *diag - diag data struct
  4061. * @param[in] *memtest - mem test params input from upper layer,
  4062. * @param[in] pattern - mem test pattern
  4063. * @param[in] *result - mem test result
  4064. * @param[in] cbfn - mem test callback functioin
  4065. * @param[in] cbarg - callback functioin arg
  4066. *
  4067. * @param[out]
  4068. */
  4069. bfa_status_t
  4070. bfa_diag_memtest(struct bfa_diag_s *diag, struct bfa_diag_memtest_s *memtest,
  4071. u32 pattern, struct bfa_diag_memtest_result *result,
  4072. bfa_cb_diag_t cbfn, void *cbarg)
  4073. {
  4074. u32 memtest_tov;
  4075. bfa_trc(diag, pattern);
  4076. if (!bfa_ioc_adapter_is_disabled(diag->ioc))
  4077. return BFA_STATUS_ADAPTER_ENABLED;
  4078. /* check to see if there is another destructive diag cmd running */
  4079. if (diag->block) {
  4080. bfa_trc(diag, diag->block);
  4081. return BFA_STATUS_DEVBUSY;
  4082. } else
  4083. diag->block = 1;
  4084. diag->result = result;
  4085. diag->cbfn = cbfn;
  4086. diag->cbarg = cbarg;
  4087. /* download memtest code and take LPU0 out of reset */
  4088. bfa_ioc_boot(diag->ioc, BFI_FWBOOT_TYPE_MEMTEST, BFI_FWBOOT_ENV_OS);
  4089. memtest_tov = (bfa_ioc_asic_gen(diag->ioc) == BFI_ASIC_GEN_CT2) ?
  4090. CT2_BFA_DIAG_MEMTEST_TOV : BFA_DIAG_MEMTEST_TOV;
  4091. bfa_timer_begin(diag->ioc->timer_mod, &diag->timer,
  4092. bfa_diag_memtest_done, diag, memtest_tov);
  4093. diag->timer_active = 1;
  4094. return BFA_STATUS_OK;
  4095. }
  4096. /*
  4097. * DIAG firmware ping command
  4098. *
  4099. * @param[in] *diag - diag data struct
  4100. * @param[in] cnt - dma loop count for testing PCIE
  4101. * @param[in] data - data pattern to pass in fw
  4102. * @param[in] *result - pt to bfa_diag_fwping_result_t data struct
  4103. * @param[in] cbfn - callback function
  4104. * @param[in] *cbarg - callback functioin arg
  4105. *
  4106. * @param[out]
  4107. */
  4108. bfa_status_t
  4109. bfa_diag_fwping(struct bfa_diag_s *diag, u32 cnt, u32 data,
  4110. struct bfa_diag_results_fwping *result, bfa_cb_diag_t cbfn,
  4111. void *cbarg)
  4112. {
  4113. bfa_trc(diag, cnt);
  4114. bfa_trc(diag, data);
  4115. if (!bfa_ioc_is_operational(diag->ioc))
  4116. return BFA_STATUS_IOC_NON_OP;
  4117. if (bfa_asic_id_ct2(bfa_ioc_devid((diag->ioc))) &&
  4118. ((diag->ioc)->clscode == BFI_PCIFN_CLASS_ETH))
  4119. return BFA_STATUS_CMD_NOTSUPP;
  4120. /* check to see if there is another destructive diag cmd running */
  4121. if (diag->block || diag->fwping.lock) {
  4122. bfa_trc(diag, diag->block);
  4123. bfa_trc(diag, diag->fwping.lock);
  4124. return BFA_STATUS_DEVBUSY;
  4125. }
  4126. /* Initialization */
  4127. diag->fwping.lock = 1;
  4128. diag->fwping.cbfn = cbfn;
  4129. diag->fwping.cbarg = cbarg;
  4130. diag->fwping.result = result;
  4131. diag->fwping.data = data;
  4132. diag->fwping.count = cnt;
  4133. /* Init test results */
  4134. diag->fwping.result->data = 0;
  4135. diag->fwping.result->status = BFA_STATUS_OK;
  4136. /* kick off the first ping */
  4137. diag_fwping_send(diag);
  4138. return BFA_STATUS_OK;
  4139. }
  4140. /*
  4141. * Read Temperature Sensor
  4142. *
  4143. * @param[in] *diag - diag data struct
  4144. * @param[in] *result - pt to bfa_diag_temp_t data struct
  4145. * @param[in] cbfn - callback function
  4146. * @param[in] *cbarg - callback functioin arg
  4147. *
  4148. * @param[out]
  4149. */
  4150. bfa_status_t
  4151. bfa_diag_tsensor_query(struct bfa_diag_s *diag,
  4152. struct bfa_diag_results_tempsensor_s *result,
  4153. bfa_cb_diag_t cbfn, void *cbarg)
  4154. {
  4155. /* check to see if there is a destructive diag cmd running */
  4156. if (diag->block || diag->tsensor.lock) {
  4157. bfa_trc(diag, diag->block);
  4158. bfa_trc(diag, diag->tsensor.lock);
  4159. return BFA_STATUS_DEVBUSY;
  4160. }
  4161. if (!bfa_ioc_is_operational(diag->ioc))
  4162. return BFA_STATUS_IOC_NON_OP;
  4163. /* Init diag mod params */
  4164. diag->tsensor.lock = 1;
  4165. diag->tsensor.temp = result;
  4166. diag->tsensor.cbfn = cbfn;
  4167. diag->tsensor.cbarg = cbarg;
  4168. /* Send msg to fw */
  4169. diag_tempsensor_send(diag);
  4170. return BFA_STATUS_OK;
  4171. }
  4172. /*
  4173. * LED Test command
  4174. *
  4175. * @param[in] *diag - diag data struct
  4176. * @param[in] *ledtest - pt to ledtest data structure
  4177. *
  4178. * @param[out]
  4179. */
  4180. bfa_status_t
  4181. bfa_diag_ledtest(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest)
  4182. {
  4183. bfa_trc(diag, ledtest->cmd);
  4184. if (!bfa_ioc_is_operational(diag->ioc))
  4185. return BFA_STATUS_IOC_NON_OP;
  4186. if (diag->beacon.state)
  4187. return BFA_STATUS_BEACON_ON;
  4188. if (diag->ledtest.lock)
  4189. return BFA_STATUS_LEDTEST_OP;
  4190. /* Send msg to fw */
  4191. diag->ledtest.lock = BFA_TRUE;
  4192. diag_ledtest_send(diag, ledtest);
  4193. return BFA_STATUS_OK;
  4194. }
  4195. /*
  4196. * Port beaconing command
  4197. *
  4198. * @param[in] *diag - diag data struct
  4199. * @param[in] beacon - port beaconing 1:ON 0:OFF
  4200. * @param[in] link_e2e_beacon - link beaconing 1:ON 0:OFF
  4201. * @param[in] sec - beaconing duration in seconds
  4202. *
  4203. * @param[out]
  4204. */
  4205. bfa_status_t
  4206. bfa_diag_beacon_port(struct bfa_diag_s *diag, bfa_boolean_t beacon,
  4207. bfa_boolean_t link_e2e_beacon, uint32_t sec)
  4208. {
  4209. bfa_trc(diag, beacon);
  4210. bfa_trc(diag, link_e2e_beacon);
  4211. bfa_trc(diag, sec);
  4212. if (!bfa_ioc_is_operational(diag->ioc))
  4213. return BFA_STATUS_IOC_NON_OP;
  4214. if (diag->ledtest.lock)
  4215. return BFA_STATUS_LEDTEST_OP;
  4216. if (diag->beacon.state && beacon) /* beacon alread on */
  4217. return BFA_STATUS_BEACON_ON;
  4218. diag->beacon.state = beacon;
  4219. diag->beacon.link_e2e = link_e2e_beacon;
  4220. if (diag->cbfn_beacon)
  4221. diag->cbfn_beacon(diag->dev, beacon, link_e2e_beacon);
  4222. /* Send msg to fw */
  4223. diag_portbeacon_send(diag, beacon, sec);
  4224. return BFA_STATUS_OK;
  4225. }
  4226. /*
  4227. * Return DMA memory needed by diag module.
  4228. */
  4229. u32
  4230. bfa_diag_meminfo(void)
  4231. {
  4232. return BFA_ROUNDUP(BFI_DIAG_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4233. }
  4234. /*
  4235. * Attach virtual and physical memory for Diag.
  4236. */
  4237. void
  4238. bfa_diag_attach(struct bfa_diag_s *diag, struct bfa_ioc_s *ioc, void *dev,
  4239. bfa_cb_diag_beacon_t cbfn_beacon, struct bfa_trc_mod_s *trcmod)
  4240. {
  4241. diag->dev = dev;
  4242. diag->ioc = ioc;
  4243. diag->trcmod = trcmod;
  4244. diag->block = 0;
  4245. diag->cbfn = NULL;
  4246. diag->cbarg = NULL;
  4247. diag->result = NULL;
  4248. diag->cbfn_beacon = cbfn_beacon;
  4249. bfa_ioc_mbox_regisr(diag->ioc, BFI_MC_DIAG, bfa_diag_intr, diag);
  4250. bfa_q_qe_init(&diag->ioc_notify);
  4251. bfa_ioc_notify_init(&diag->ioc_notify, bfa_diag_notify, diag);
  4252. list_add_tail(&diag->ioc_notify.qe, &diag->ioc->notify_q);
  4253. }
  4254. void
  4255. bfa_diag_memclaim(struct bfa_diag_s *diag, u8 *dm_kva, u64 dm_pa)
  4256. {
  4257. diag->fwping.dbuf_kva = dm_kva;
  4258. diag->fwping.dbuf_pa = dm_pa;
  4259. memset(diag->fwping.dbuf_kva, 0, BFI_DIAG_DMA_BUF_SZ);
  4260. }
  4261. /*
  4262. * PHY module specific
  4263. */
  4264. #define BFA_PHY_DMA_BUF_SZ 0x02000 /* 8k dma buffer */
  4265. #define BFA_PHY_LOCK_STATUS 0x018878 /* phy semaphore status reg */
  4266. static void
  4267. bfa_phy_ntoh32(u32 *obuf, u32 *ibuf, int sz)
  4268. {
  4269. int i, m = sz >> 2;
  4270. for (i = 0; i < m; i++)
  4271. obuf[i] = be32_to_cpu(ibuf[i]);
  4272. }
  4273. static bfa_boolean_t
  4274. bfa_phy_present(struct bfa_phy_s *phy)
  4275. {
  4276. return (phy->ioc->attr->card_type == BFA_MFG_TYPE_LIGHTNING);
  4277. }
  4278. static void
  4279. bfa_phy_notify(void *cbarg, enum bfa_ioc_event_e event)
  4280. {
  4281. struct bfa_phy_s *phy = cbarg;
  4282. bfa_trc(phy, event);
  4283. switch (event) {
  4284. case BFA_IOC_E_DISABLED:
  4285. case BFA_IOC_E_FAILED:
  4286. if (phy->op_busy) {
  4287. phy->status = BFA_STATUS_IOC_FAILURE;
  4288. phy->cbfn(phy->cbarg, phy->status);
  4289. phy->op_busy = 0;
  4290. }
  4291. break;
  4292. default:
  4293. break;
  4294. }
  4295. }
  4296. /*
  4297. * Send phy attribute query request.
  4298. *
  4299. * @param[in] cbarg - callback argument
  4300. */
  4301. static void
  4302. bfa_phy_query_send(void *cbarg)
  4303. {
  4304. struct bfa_phy_s *phy = cbarg;
  4305. struct bfi_phy_query_req_s *msg =
  4306. (struct bfi_phy_query_req_s *) phy->mb.msg;
  4307. msg->instance = phy->instance;
  4308. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_QUERY_REQ,
  4309. bfa_ioc_portid(phy->ioc));
  4310. bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_attr_s), phy->dbuf_pa);
  4311. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4312. }
  4313. /*
  4314. * Send phy write request.
  4315. *
  4316. * @param[in] cbarg - callback argument
  4317. */
  4318. static void
  4319. bfa_phy_write_send(void *cbarg)
  4320. {
  4321. struct bfa_phy_s *phy = cbarg;
  4322. struct bfi_phy_write_req_s *msg =
  4323. (struct bfi_phy_write_req_s *) phy->mb.msg;
  4324. u32 len;
  4325. u16 *buf, *dbuf;
  4326. int i, sz;
  4327. msg->instance = phy->instance;
  4328. msg->offset = cpu_to_be32(phy->addr_off + phy->offset);
  4329. len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ?
  4330. phy->residue : BFA_PHY_DMA_BUF_SZ;
  4331. msg->length = cpu_to_be32(len);
  4332. /* indicate if it's the last msg of the whole write operation */
  4333. msg->last = (len == phy->residue) ? 1 : 0;
  4334. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_WRITE_REQ,
  4335. bfa_ioc_portid(phy->ioc));
  4336. bfa_alen_set(&msg->alen, len, phy->dbuf_pa);
  4337. buf = (u16 *) (phy->ubuf + phy->offset);
  4338. dbuf = (u16 *)phy->dbuf_kva;
  4339. sz = len >> 1;
  4340. for (i = 0; i < sz; i++)
  4341. buf[i] = cpu_to_be16(dbuf[i]);
  4342. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4343. phy->residue -= len;
  4344. phy->offset += len;
  4345. }
  4346. /*
  4347. * Send phy read request.
  4348. *
  4349. * @param[in] cbarg - callback argument
  4350. */
  4351. static void
  4352. bfa_phy_read_send(void *cbarg)
  4353. {
  4354. struct bfa_phy_s *phy = cbarg;
  4355. struct bfi_phy_read_req_s *msg =
  4356. (struct bfi_phy_read_req_s *) phy->mb.msg;
  4357. u32 len;
  4358. msg->instance = phy->instance;
  4359. msg->offset = cpu_to_be32(phy->addr_off + phy->offset);
  4360. len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ?
  4361. phy->residue : BFA_PHY_DMA_BUF_SZ;
  4362. msg->length = cpu_to_be32(len);
  4363. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_READ_REQ,
  4364. bfa_ioc_portid(phy->ioc));
  4365. bfa_alen_set(&msg->alen, len, phy->dbuf_pa);
  4366. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4367. }
  4368. /*
  4369. * Send phy stats request.
  4370. *
  4371. * @param[in] cbarg - callback argument
  4372. */
  4373. static void
  4374. bfa_phy_stats_send(void *cbarg)
  4375. {
  4376. struct bfa_phy_s *phy = cbarg;
  4377. struct bfi_phy_stats_req_s *msg =
  4378. (struct bfi_phy_stats_req_s *) phy->mb.msg;
  4379. msg->instance = phy->instance;
  4380. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_STATS_REQ,
  4381. bfa_ioc_portid(phy->ioc));
  4382. bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_stats_s), phy->dbuf_pa);
  4383. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4384. }
  4385. /*
  4386. * Flash memory info API.
  4387. *
  4388. * @param[in] mincfg - minimal cfg variable
  4389. */
  4390. u32
  4391. bfa_phy_meminfo(bfa_boolean_t mincfg)
  4392. {
  4393. /* min driver doesn't need phy */
  4394. if (mincfg)
  4395. return 0;
  4396. return BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4397. }
  4398. /*
  4399. * Flash attach API.
  4400. *
  4401. * @param[in] phy - phy structure
  4402. * @param[in] ioc - ioc structure
  4403. * @param[in] dev - device structure
  4404. * @param[in] trcmod - trace module
  4405. * @param[in] logmod - log module
  4406. */
  4407. void
  4408. bfa_phy_attach(struct bfa_phy_s *phy, struct bfa_ioc_s *ioc, void *dev,
  4409. struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
  4410. {
  4411. phy->ioc = ioc;
  4412. phy->trcmod = trcmod;
  4413. phy->cbfn = NULL;
  4414. phy->cbarg = NULL;
  4415. phy->op_busy = 0;
  4416. bfa_ioc_mbox_regisr(phy->ioc, BFI_MC_PHY, bfa_phy_intr, phy);
  4417. bfa_q_qe_init(&phy->ioc_notify);
  4418. bfa_ioc_notify_init(&phy->ioc_notify, bfa_phy_notify, phy);
  4419. list_add_tail(&phy->ioc_notify.qe, &phy->ioc->notify_q);
  4420. /* min driver doesn't need phy */
  4421. if (mincfg) {
  4422. phy->dbuf_kva = NULL;
  4423. phy->dbuf_pa = 0;
  4424. }
  4425. }
  4426. /*
  4427. * Claim memory for phy
  4428. *
  4429. * @param[in] phy - phy structure
  4430. * @param[in] dm_kva - pointer to virtual memory address
  4431. * @param[in] dm_pa - physical memory address
  4432. * @param[in] mincfg - minimal cfg variable
  4433. */
  4434. void
  4435. bfa_phy_memclaim(struct bfa_phy_s *phy, u8 *dm_kva, u64 dm_pa,
  4436. bfa_boolean_t mincfg)
  4437. {
  4438. if (mincfg)
  4439. return;
  4440. phy->dbuf_kva = dm_kva;
  4441. phy->dbuf_pa = dm_pa;
  4442. memset(phy->dbuf_kva, 0, BFA_PHY_DMA_BUF_SZ);
  4443. dm_kva += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4444. dm_pa += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4445. }
  4446. bfa_boolean_t
  4447. bfa_phy_busy(struct bfa_ioc_s *ioc)
  4448. {
  4449. void __iomem *rb;
  4450. rb = bfa_ioc_bar0(ioc);
  4451. return readl(rb + BFA_PHY_LOCK_STATUS);
  4452. }
  4453. /*
  4454. * Get phy attribute.
  4455. *
  4456. * @param[in] phy - phy structure
  4457. * @param[in] attr - phy attribute structure
  4458. * @param[in] cbfn - callback function
  4459. * @param[in] cbarg - callback argument
  4460. *
  4461. * Return status.
  4462. */
  4463. bfa_status_t
  4464. bfa_phy_get_attr(struct bfa_phy_s *phy, u8 instance,
  4465. struct bfa_phy_attr_s *attr, bfa_cb_phy_t cbfn, void *cbarg)
  4466. {
  4467. bfa_trc(phy, BFI_PHY_H2I_QUERY_REQ);
  4468. bfa_trc(phy, instance);
  4469. if (!bfa_phy_present(phy))
  4470. return BFA_STATUS_PHY_NOT_PRESENT;
  4471. if (!bfa_ioc_is_operational(phy->ioc))
  4472. return BFA_STATUS_IOC_NON_OP;
  4473. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4474. bfa_trc(phy, phy->op_busy);
  4475. return BFA_STATUS_DEVBUSY;
  4476. }
  4477. phy->op_busy = 1;
  4478. phy->cbfn = cbfn;
  4479. phy->cbarg = cbarg;
  4480. phy->instance = instance;
  4481. phy->ubuf = (uint8_t *) attr;
  4482. bfa_phy_query_send(phy);
  4483. return BFA_STATUS_OK;
  4484. }
  4485. /*
  4486. * Get phy stats.
  4487. *
  4488. * @param[in] phy - phy structure
  4489. * @param[in] instance - phy image instance
  4490. * @param[in] stats - pointer to phy stats
  4491. * @param[in] cbfn - callback function
  4492. * @param[in] cbarg - callback argument
  4493. *
  4494. * Return status.
  4495. */
  4496. bfa_status_t
  4497. bfa_phy_get_stats(struct bfa_phy_s *phy, u8 instance,
  4498. struct bfa_phy_stats_s *stats,
  4499. bfa_cb_phy_t cbfn, void *cbarg)
  4500. {
  4501. bfa_trc(phy, BFI_PHY_H2I_STATS_REQ);
  4502. bfa_trc(phy, instance);
  4503. if (!bfa_phy_present(phy))
  4504. return BFA_STATUS_PHY_NOT_PRESENT;
  4505. if (!bfa_ioc_is_operational(phy->ioc))
  4506. return BFA_STATUS_IOC_NON_OP;
  4507. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4508. bfa_trc(phy, phy->op_busy);
  4509. return BFA_STATUS_DEVBUSY;
  4510. }
  4511. phy->op_busy = 1;
  4512. phy->cbfn = cbfn;
  4513. phy->cbarg = cbarg;
  4514. phy->instance = instance;
  4515. phy->ubuf = (u8 *) stats;
  4516. bfa_phy_stats_send(phy);
  4517. return BFA_STATUS_OK;
  4518. }
  4519. /*
  4520. * Update phy image.
  4521. *
  4522. * @param[in] phy - phy structure
  4523. * @param[in] instance - phy image instance
  4524. * @param[in] buf - update data buffer
  4525. * @param[in] len - data buffer length
  4526. * @param[in] offset - offset relative to starting address
  4527. * @param[in] cbfn - callback function
  4528. * @param[in] cbarg - callback argument
  4529. *
  4530. * Return status.
  4531. */
  4532. bfa_status_t
  4533. bfa_phy_update(struct bfa_phy_s *phy, u8 instance,
  4534. void *buf, u32 len, u32 offset,
  4535. bfa_cb_phy_t cbfn, void *cbarg)
  4536. {
  4537. bfa_trc(phy, BFI_PHY_H2I_WRITE_REQ);
  4538. bfa_trc(phy, instance);
  4539. bfa_trc(phy, len);
  4540. bfa_trc(phy, offset);
  4541. if (!bfa_phy_present(phy))
  4542. return BFA_STATUS_PHY_NOT_PRESENT;
  4543. if (!bfa_ioc_is_operational(phy->ioc))
  4544. return BFA_STATUS_IOC_NON_OP;
  4545. /* 'len' must be in word (4-byte) boundary */
  4546. if (!len || (len & 0x03))
  4547. return BFA_STATUS_FAILED;
  4548. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4549. bfa_trc(phy, phy->op_busy);
  4550. return BFA_STATUS_DEVBUSY;
  4551. }
  4552. phy->op_busy = 1;
  4553. phy->cbfn = cbfn;
  4554. phy->cbarg = cbarg;
  4555. phy->instance = instance;
  4556. phy->residue = len;
  4557. phy->offset = 0;
  4558. phy->addr_off = offset;
  4559. phy->ubuf = buf;
  4560. bfa_phy_write_send(phy);
  4561. return BFA_STATUS_OK;
  4562. }
  4563. /*
  4564. * Read phy image.
  4565. *
  4566. * @param[in] phy - phy structure
  4567. * @param[in] instance - phy image instance
  4568. * @param[in] buf - read data buffer
  4569. * @param[in] len - data buffer length
  4570. * @param[in] offset - offset relative to starting address
  4571. * @param[in] cbfn - callback function
  4572. * @param[in] cbarg - callback argument
  4573. *
  4574. * Return status.
  4575. */
  4576. bfa_status_t
  4577. bfa_phy_read(struct bfa_phy_s *phy, u8 instance,
  4578. void *buf, u32 len, u32 offset,
  4579. bfa_cb_phy_t cbfn, void *cbarg)
  4580. {
  4581. bfa_trc(phy, BFI_PHY_H2I_READ_REQ);
  4582. bfa_trc(phy, instance);
  4583. bfa_trc(phy, len);
  4584. bfa_trc(phy, offset);
  4585. if (!bfa_phy_present(phy))
  4586. return BFA_STATUS_PHY_NOT_PRESENT;
  4587. if (!bfa_ioc_is_operational(phy->ioc))
  4588. return BFA_STATUS_IOC_NON_OP;
  4589. /* 'len' must be in word (4-byte) boundary */
  4590. if (!len || (len & 0x03))
  4591. return BFA_STATUS_FAILED;
  4592. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4593. bfa_trc(phy, phy->op_busy);
  4594. return BFA_STATUS_DEVBUSY;
  4595. }
  4596. phy->op_busy = 1;
  4597. phy->cbfn = cbfn;
  4598. phy->cbarg = cbarg;
  4599. phy->instance = instance;
  4600. phy->residue = len;
  4601. phy->offset = 0;
  4602. phy->addr_off = offset;
  4603. phy->ubuf = buf;
  4604. bfa_phy_read_send(phy);
  4605. return BFA_STATUS_OK;
  4606. }
  4607. /*
  4608. * Process phy response messages upon receiving interrupts.
  4609. *
  4610. * @param[in] phyarg - phy structure
  4611. * @param[in] msg - message structure
  4612. */
  4613. void
  4614. bfa_phy_intr(void *phyarg, struct bfi_mbmsg_s *msg)
  4615. {
  4616. struct bfa_phy_s *phy = phyarg;
  4617. u32 status;
  4618. union {
  4619. struct bfi_phy_query_rsp_s *query;
  4620. struct bfi_phy_stats_rsp_s *stats;
  4621. struct bfi_phy_write_rsp_s *write;
  4622. struct bfi_phy_read_rsp_s *read;
  4623. struct bfi_mbmsg_s *msg;
  4624. } m;
  4625. m.msg = msg;
  4626. bfa_trc(phy, msg->mh.msg_id);
  4627. if (!phy->op_busy) {
  4628. /* receiving response after ioc failure */
  4629. bfa_trc(phy, 0x9999);
  4630. return;
  4631. }
  4632. switch (msg->mh.msg_id) {
  4633. case BFI_PHY_I2H_QUERY_RSP:
  4634. status = be32_to_cpu(m.query->status);
  4635. bfa_trc(phy, status);
  4636. if (status == BFA_STATUS_OK) {
  4637. struct bfa_phy_attr_s *attr =
  4638. (struct bfa_phy_attr_s *) phy->ubuf;
  4639. bfa_phy_ntoh32((u32 *)attr, (u32 *)phy->dbuf_kva,
  4640. sizeof(struct bfa_phy_attr_s));
  4641. bfa_trc(phy, attr->status);
  4642. bfa_trc(phy, attr->length);
  4643. }
  4644. phy->status = status;
  4645. phy->op_busy = 0;
  4646. if (phy->cbfn)
  4647. phy->cbfn(phy->cbarg, phy->status);
  4648. break;
  4649. case BFI_PHY_I2H_STATS_RSP:
  4650. status = be32_to_cpu(m.stats->status);
  4651. bfa_trc(phy, status);
  4652. if (status == BFA_STATUS_OK) {
  4653. struct bfa_phy_stats_s *stats =
  4654. (struct bfa_phy_stats_s *) phy->ubuf;
  4655. bfa_phy_ntoh32((u32 *)stats, (u32 *)phy->dbuf_kva,
  4656. sizeof(struct bfa_phy_stats_s));
  4657. bfa_trc(phy, stats->status);
  4658. }
  4659. phy->status = status;
  4660. phy->op_busy = 0;
  4661. if (phy->cbfn)
  4662. phy->cbfn(phy->cbarg, phy->status);
  4663. break;
  4664. case BFI_PHY_I2H_WRITE_RSP:
  4665. status = be32_to_cpu(m.write->status);
  4666. bfa_trc(phy, status);
  4667. if (status != BFA_STATUS_OK || phy->residue == 0) {
  4668. phy->status = status;
  4669. phy->op_busy = 0;
  4670. if (phy->cbfn)
  4671. phy->cbfn(phy->cbarg, phy->status);
  4672. } else {
  4673. bfa_trc(phy, phy->offset);
  4674. bfa_phy_write_send(phy);
  4675. }
  4676. break;
  4677. case BFI_PHY_I2H_READ_RSP:
  4678. status = be32_to_cpu(m.read->status);
  4679. bfa_trc(phy, status);
  4680. if (status != BFA_STATUS_OK) {
  4681. phy->status = status;
  4682. phy->op_busy = 0;
  4683. if (phy->cbfn)
  4684. phy->cbfn(phy->cbarg, phy->status);
  4685. } else {
  4686. u32 len = be32_to_cpu(m.read->length);
  4687. u16 *buf = (u16 *)(phy->ubuf + phy->offset);
  4688. u16 *dbuf = (u16 *)phy->dbuf_kva;
  4689. int i, sz = len >> 1;
  4690. bfa_trc(phy, phy->offset);
  4691. bfa_trc(phy, len);
  4692. for (i = 0; i < sz; i++)
  4693. buf[i] = be16_to_cpu(dbuf[i]);
  4694. phy->residue -= len;
  4695. phy->offset += len;
  4696. if (phy->residue == 0) {
  4697. phy->status = status;
  4698. phy->op_busy = 0;
  4699. if (phy->cbfn)
  4700. phy->cbfn(phy->cbarg, phy->status);
  4701. } else
  4702. bfa_phy_read_send(phy);
  4703. }
  4704. break;
  4705. default:
  4706. WARN_ON(1);
  4707. }
  4708. }
  4709. /*
  4710. * DCONF module specific
  4711. */
  4712. BFA_MODULE(dconf);
  4713. /*
  4714. * DCONF state machine events
  4715. */
  4716. enum bfa_dconf_event {
  4717. BFA_DCONF_SM_INIT = 1, /* dconf Init */
  4718. BFA_DCONF_SM_FLASH_COMP = 2, /* read/write to flash */
  4719. BFA_DCONF_SM_WR = 3, /* binding change, map */
  4720. BFA_DCONF_SM_TIMEOUT = 4, /* Start timer */
  4721. BFA_DCONF_SM_EXIT = 5, /* exit dconf module */
  4722. BFA_DCONF_SM_IOCDISABLE = 6, /* IOC disable event */
  4723. };
  4724. /* forward declaration of DCONF state machine */
  4725. static void bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf,
  4726. enum bfa_dconf_event event);
  4727. static void bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf,
  4728. enum bfa_dconf_event event);
  4729. static void bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf,
  4730. enum bfa_dconf_event event);
  4731. static void bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf,
  4732. enum bfa_dconf_event event);
  4733. static void bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf,
  4734. enum bfa_dconf_event event);
  4735. static void bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf,
  4736. enum bfa_dconf_event event);
  4737. static void bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf,
  4738. enum bfa_dconf_event event);
  4739. static void bfa_dconf_cbfn(void *dconf, bfa_status_t status);
  4740. static void bfa_dconf_timer(void *cbarg);
  4741. static bfa_status_t bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf);
  4742. static void bfa_dconf_init_cb(void *arg, bfa_status_t status);
  4743. /*
  4744. * Beginning state of dconf module. Waiting for an event to start.
  4745. */
  4746. static void
  4747. bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  4748. {
  4749. bfa_status_t bfa_status;
  4750. bfa_trc(dconf->bfa, event);
  4751. switch (event) {
  4752. case BFA_DCONF_SM_INIT:
  4753. if (dconf->min_cfg) {
  4754. bfa_trc(dconf->bfa, dconf->min_cfg);
  4755. bfa_fsm_send_event(&dconf->bfa->iocfc,
  4756. IOCFC_E_DCONF_DONE);
  4757. return;
  4758. }
  4759. bfa_sm_set_state(dconf, bfa_dconf_sm_flash_read);
  4760. bfa_timer_start(dconf->bfa, &dconf->timer,
  4761. bfa_dconf_timer, dconf, 2 * BFA_DCONF_UPDATE_TOV);
  4762. bfa_status = bfa_flash_read_part(BFA_FLASH(dconf->bfa),
  4763. BFA_FLASH_PART_DRV, dconf->instance,
  4764. dconf->dconf,
  4765. sizeof(struct bfa_dconf_s), 0,
  4766. bfa_dconf_init_cb, dconf->bfa);
  4767. if (bfa_status != BFA_STATUS_OK) {
  4768. bfa_timer_stop(&dconf->timer);
  4769. bfa_dconf_init_cb(dconf->bfa, BFA_STATUS_FAILED);
  4770. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4771. return;
  4772. }
  4773. break;
  4774. case BFA_DCONF_SM_EXIT:
  4775. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  4776. case BFA_DCONF_SM_IOCDISABLE:
  4777. case BFA_DCONF_SM_WR:
  4778. case BFA_DCONF_SM_FLASH_COMP:
  4779. break;
  4780. default:
  4781. bfa_sm_fault(dconf->bfa, event);
  4782. }
  4783. }
  4784. /*
  4785. * Read flash for dconf entries and make a call back to the driver once done.
  4786. */
  4787. static void
  4788. bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf,
  4789. enum bfa_dconf_event event)
  4790. {
  4791. bfa_trc(dconf->bfa, event);
  4792. switch (event) {
  4793. case BFA_DCONF_SM_FLASH_COMP:
  4794. bfa_timer_stop(&dconf->timer);
  4795. bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
  4796. break;
  4797. case BFA_DCONF_SM_TIMEOUT:
  4798. bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
  4799. bfa_ioc_suspend(&dconf->bfa->ioc);
  4800. break;
  4801. case BFA_DCONF_SM_EXIT:
  4802. bfa_timer_stop(&dconf->timer);
  4803. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4804. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  4805. break;
  4806. case BFA_DCONF_SM_IOCDISABLE:
  4807. bfa_timer_stop(&dconf->timer);
  4808. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4809. break;
  4810. default:
  4811. bfa_sm_fault(dconf->bfa, event);
  4812. }
  4813. }
  4814. /*
  4815. * DCONF Module is in ready state. Has completed the initialization.
  4816. */
  4817. static void
  4818. bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  4819. {
  4820. bfa_trc(dconf->bfa, event);
  4821. switch (event) {
  4822. case BFA_DCONF_SM_WR:
  4823. bfa_timer_start(dconf->bfa, &dconf->timer,
  4824. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  4825. bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
  4826. break;
  4827. case BFA_DCONF_SM_EXIT:
  4828. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4829. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  4830. break;
  4831. case BFA_DCONF_SM_INIT:
  4832. case BFA_DCONF_SM_IOCDISABLE:
  4833. break;
  4834. default:
  4835. bfa_sm_fault(dconf->bfa, event);
  4836. }
  4837. }
  4838. /*
  4839. * entries are dirty, write back to the flash.
  4840. */
  4841. static void
  4842. bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  4843. {
  4844. bfa_trc(dconf->bfa, event);
  4845. switch (event) {
  4846. case BFA_DCONF_SM_TIMEOUT:
  4847. bfa_sm_set_state(dconf, bfa_dconf_sm_sync);
  4848. bfa_dconf_flash_write(dconf);
  4849. break;
  4850. case BFA_DCONF_SM_WR:
  4851. bfa_timer_stop(&dconf->timer);
  4852. bfa_timer_start(dconf->bfa, &dconf->timer,
  4853. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  4854. break;
  4855. case BFA_DCONF_SM_EXIT:
  4856. bfa_timer_stop(&dconf->timer);
  4857. bfa_timer_start(dconf->bfa, &dconf->timer,
  4858. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  4859. bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync);
  4860. bfa_dconf_flash_write(dconf);
  4861. break;
  4862. case BFA_DCONF_SM_FLASH_COMP:
  4863. break;
  4864. case BFA_DCONF_SM_IOCDISABLE:
  4865. bfa_timer_stop(&dconf->timer);
  4866. bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty);
  4867. break;
  4868. default:
  4869. bfa_sm_fault(dconf->bfa, event);
  4870. }
  4871. }
  4872. /*
  4873. * Sync the dconf entries to the flash.
  4874. */
  4875. static void
  4876. bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf,
  4877. enum bfa_dconf_event event)
  4878. {
  4879. bfa_trc(dconf->bfa, event);
  4880. switch (event) {
  4881. case BFA_DCONF_SM_IOCDISABLE:
  4882. case BFA_DCONF_SM_FLASH_COMP:
  4883. bfa_timer_stop(&dconf->timer);
  4884. case BFA_DCONF_SM_TIMEOUT:
  4885. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4886. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  4887. break;
  4888. default:
  4889. bfa_sm_fault(dconf->bfa, event);
  4890. }
  4891. }
  4892. static void
  4893. bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  4894. {
  4895. bfa_trc(dconf->bfa, event);
  4896. switch (event) {
  4897. case BFA_DCONF_SM_FLASH_COMP:
  4898. bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
  4899. break;
  4900. case BFA_DCONF_SM_WR:
  4901. bfa_timer_start(dconf->bfa, &dconf->timer,
  4902. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  4903. bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
  4904. break;
  4905. case BFA_DCONF_SM_EXIT:
  4906. bfa_timer_start(dconf->bfa, &dconf->timer,
  4907. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  4908. bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync);
  4909. break;
  4910. case BFA_DCONF_SM_IOCDISABLE:
  4911. bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty);
  4912. break;
  4913. default:
  4914. bfa_sm_fault(dconf->bfa, event);
  4915. }
  4916. }
  4917. static void
  4918. bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf,
  4919. enum bfa_dconf_event event)
  4920. {
  4921. bfa_trc(dconf->bfa, event);
  4922. switch (event) {
  4923. case BFA_DCONF_SM_INIT:
  4924. bfa_timer_start(dconf->bfa, &dconf->timer,
  4925. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  4926. bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
  4927. break;
  4928. case BFA_DCONF_SM_EXIT:
  4929. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4930. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  4931. break;
  4932. case BFA_DCONF_SM_IOCDISABLE:
  4933. break;
  4934. default:
  4935. bfa_sm_fault(dconf->bfa, event);
  4936. }
  4937. }
  4938. /*
  4939. * Compute and return memory needed by DRV_CFG module.
  4940. */
  4941. static void
  4942. bfa_dconf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
  4943. struct bfa_s *bfa)
  4944. {
  4945. struct bfa_mem_kva_s *dconf_kva = BFA_MEM_DCONF_KVA(bfa);
  4946. if (cfg->drvcfg.min_cfg)
  4947. bfa_mem_kva_setup(meminfo, dconf_kva,
  4948. sizeof(struct bfa_dconf_hdr_s));
  4949. else
  4950. bfa_mem_kva_setup(meminfo, dconf_kva,
  4951. sizeof(struct bfa_dconf_s));
  4952. }
  4953. static void
  4954. bfa_dconf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4955. struct bfa_pcidev_s *pcidev)
  4956. {
  4957. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  4958. dconf->bfad = bfad;
  4959. dconf->bfa = bfa;
  4960. dconf->instance = bfa->ioc.port_id;
  4961. bfa_trc(bfa, dconf->instance);
  4962. dconf->dconf = (struct bfa_dconf_s *) bfa_mem_kva_curp(dconf);
  4963. if (cfg->drvcfg.min_cfg) {
  4964. bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_hdr_s);
  4965. dconf->min_cfg = BFA_TRUE;
  4966. } else {
  4967. dconf->min_cfg = BFA_FALSE;
  4968. bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_s);
  4969. }
  4970. bfa_dconf_read_data_valid(bfa) = BFA_FALSE;
  4971. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4972. }
  4973. static void
  4974. bfa_dconf_init_cb(void *arg, bfa_status_t status)
  4975. {
  4976. struct bfa_s *bfa = arg;
  4977. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  4978. if (status == BFA_STATUS_OK) {
  4979. bfa_dconf_read_data_valid(bfa) = BFA_TRUE;
  4980. if (dconf->dconf->hdr.signature != BFI_DCONF_SIGNATURE)
  4981. dconf->dconf->hdr.signature = BFI_DCONF_SIGNATURE;
  4982. if (dconf->dconf->hdr.version != BFI_DCONF_VERSION)
  4983. dconf->dconf->hdr.version = BFI_DCONF_VERSION;
  4984. }
  4985. bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
  4986. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_DCONF_DONE);
  4987. }
  4988. void
  4989. bfa_dconf_modinit(struct bfa_s *bfa)
  4990. {
  4991. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  4992. bfa_sm_send_event(dconf, BFA_DCONF_SM_INIT);
  4993. }
  4994. static void
  4995. bfa_dconf_start(struct bfa_s *bfa)
  4996. {
  4997. }
  4998. static void
  4999. bfa_dconf_stop(struct bfa_s *bfa)
  5000. {
  5001. }
  5002. static void bfa_dconf_timer(void *cbarg)
  5003. {
  5004. struct bfa_dconf_mod_s *dconf = cbarg;
  5005. bfa_sm_send_event(dconf, BFA_DCONF_SM_TIMEOUT);
  5006. }
  5007. static void
  5008. bfa_dconf_iocdisable(struct bfa_s *bfa)
  5009. {
  5010. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5011. bfa_sm_send_event(dconf, BFA_DCONF_SM_IOCDISABLE);
  5012. }
  5013. static void
  5014. bfa_dconf_detach(struct bfa_s *bfa)
  5015. {
  5016. }
  5017. static bfa_status_t
  5018. bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf)
  5019. {
  5020. bfa_status_t bfa_status;
  5021. bfa_trc(dconf->bfa, 0);
  5022. bfa_status = bfa_flash_update_part(BFA_FLASH(dconf->bfa),
  5023. BFA_FLASH_PART_DRV, dconf->instance,
  5024. dconf->dconf, sizeof(struct bfa_dconf_s), 0,
  5025. bfa_dconf_cbfn, dconf);
  5026. if (bfa_status != BFA_STATUS_OK)
  5027. WARN_ON(bfa_status);
  5028. bfa_trc(dconf->bfa, bfa_status);
  5029. return bfa_status;
  5030. }
  5031. bfa_status_t
  5032. bfa_dconf_update(struct bfa_s *bfa)
  5033. {
  5034. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5035. bfa_trc(dconf->bfa, 0);
  5036. if (bfa_sm_cmp_state(dconf, bfa_dconf_sm_iocdown_dirty))
  5037. return BFA_STATUS_FAILED;
  5038. if (dconf->min_cfg) {
  5039. bfa_trc(dconf->bfa, dconf->min_cfg);
  5040. return BFA_STATUS_FAILED;
  5041. }
  5042. bfa_sm_send_event(dconf, BFA_DCONF_SM_WR);
  5043. return BFA_STATUS_OK;
  5044. }
  5045. static void
  5046. bfa_dconf_cbfn(void *arg, bfa_status_t status)
  5047. {
  5048. struct bfa_dconf_mod_s *dconf = arg;
  5049. WARN_ON(status);
  5050. bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
  5051. }
  5052. void
  5053. bfa_dconf_modexit(struct bfa_s *bfa)
  5054. {
  5055. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5056. bfa_sm_send_event(dconf, BFA_DCONF_SM_EXIT);
  5057. }