bfa_ioc.c 146 KB

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