bfa_ioc.c 122 KB

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