bfa_ioc.c 160 KB

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