bfa_ioc.c 161 KB

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