bfa_ioc.c 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384
  1. /*
  2. * Linux network driver for QLogic BR-series Converged Network Adapter.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License (GPL) Version 2 as
  6. * published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. /*
  14. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  15. * Copyright (c) 2014-2015 QLogic Corporation
  16. * All rights reserved
  17. * www.qlogic.com
  18. */
  19. #include "bfa_ioc.h"
  20. #include "bfi_reg.h"
  21. #include "bfa_defs.h"
  22. /* IOC local definitions */
  23. /* Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details. */
  24. #define bfa_ioc_firmware_lock(__ioc) \
  25. ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
  26. #define bfa_ioc_firmware_unlock(__ioc) \
  27. ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
  28. #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
  29. #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
  30. #define bfa_ioc_notify_fail(__ioc) \
  31. ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
  32. #define bfa_ioc_sync_start(__ioc) \
  33. ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
  34. #define bfa_ioc_sync_join(__ioc) \
  35. ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
  36. #define bfa_ioc_sync_leave(__ioc) \
  37. ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
  38. #define bfa_ioc_sync_ack(__ioc) \
  39. ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
  40. #define bfa_ioc_sync_complete(__ioc) \
  41. ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
  42. #define bfa_ioc_set_cur_ioc_fwstate(__ioc, __fwstate) \
  43. ((__ioc)->ioc_hwif->ioc_set_fwstate(__ioc, __fwstate))
  44. #define bfa_ioc_get_cur_ioc_fwstate(__ioc) \
  45. ((__ioc)->ioc_hwif->ioc_get_fwstate(__ioc))
  46. #define bfa_ioc_set_alt_ioc_fwstate(__ioc, __fwstate) \
  47. ((__ioc)->ioc_hwif->ioc_set_alt_fwstate(__ioc, __fwstate))
  48. static bool bfa_nw_auto_recover = true;
  49. /*
  50. * forward declarations
  51. */
  52. static void bfa_ioc_hw_sem_init(struct bfa_ioc *ioc);
  53. static void bfa_ioc_hw_sem_get(struct bfa_ioc *ioc);
  54. static void bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc);
  55. static void bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force);
  56. static void bfa_ioc_poll_fwinit(struct bfa_ioc *ioc);
  57. static void bfa_ioc_send_enable(struct bfa_ioc *ioc);
  58. static void bfa_ioc_send_disable(struct bfa_ioc *ioc);
  59. static void bfa_ioc_send_getattr(struct bfa_ioc *ioc);
  60. static void bfa_ioc_hb_monitor(struct bfa_ioc *ioc);
  61. static void bfa_ioc_hb_stop(struct bfa_ioc *ioc);
  62. static void bfa_ioc_reset(struct bfa_ioc *ioc, bool force);
  63. static void bfa_ioc_mbox_poll(struct bfa_ioc *ioc);
  64. static void bfa_ioc_mbox_flush(struct bfa_ioc *ioc);
  65. static void bfa_ioc_recover(struct bfa_ioc *ioc);
  66. static void bfa_ioc_event_notify(struct bfa_ioc *, enum bfa_ioc_event);
  67. static void bfa_ioc_disable_comp(struct bfa_ioc *ioc);
  68. static void bfa_ioc_lpu_stop(struct bfa_ioc *ioc);
  69. static void bfa_nw_ioc_debug_save_ftrc(struct bfa_ioc *ioc);
  70. static void bfa_ioc_fail_notify(struct bfa_ioc *ioc);
  71. static void bfa_ioc_pf_enabled(struct bfa_ioc *ioc);
  72. static void bfa_ioc_pf_disabled(struct bfa_ioc *ioc);
  73. static void bfa_ioc_pf_failed(struct bfa_ioc *ioc);
  74. static void bfa_ioc_pf_hwfailed(struct bfa_ioc *ioc);
  75. static void bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc);
  76. static enum bfa_status bfa_ioc_boot(struct bfa_ioc *ioc,
  77. enum bfi_fwboot_type boot_type, u32 boot_param);
  78. static u32 bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr);
  79. static void bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc,
  80. char *serial_num);
  81. static void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc,
  82. char *fw_ver);
  83. static void bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc,
  84. char *chip_rev);
  85. static void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc,
  86. char *optrom_ver);
  87. static void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc,
  88. char *manufacturer);
  89. static void bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model);
  90. static u64 bfa_ioc_get_pwwn(struct bfa_ioc *ioc);
  91. /* IOC state machine definitions/declarations */
  92. enum ioc_event {
  93. IOC_E_RESET = 1, /*!< IOC reset request */
  94. IOC_E_ENABLE = 2, /*!< IOC enable request */
  95. IOC_E_DISABLE = 3, /*!< IOC disable request */
  96. IOC_E_DETACH = 4, /*!< driver detach cleanup */
  97. IOC_E_ENABLED = 5, /*!< f/w enabled */
  98. IOC_E_FWRSP_GETATTR = 6, /*!< IOC get attribute response */
  99. IOC_E_DISABLED = 7, /*!< f/w disabled */
  100. IOC_E_PFFAILED = 8, /*!< failure notice by iocpf sm */
  101. IOC_E_HBFAIL = 9, /*!< heartbeat failure */
  102. IOC_E_HWERROR = 10, /*!< hardware error interrupt */
  103. IOC_E_TIMEOUT = 11, /*!< timeout */
  104. IOC_E_HWFAILED = 12, /*!< PCI mapping failure notice */
  105. };
  106. bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc, enum ioc_event);
  107. bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc, enum ioc_event);
  108. bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc, enum ioc_event);
  109. bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc, enum ioc_event);
  110. bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc, enum ioc_event);
  111. bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc, enum ioc_event);
  112. bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc, enum ioc_event);
  113. bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc, enum ioc_event);
  114. bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc, enum ioc_event);
  115. bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc, enum ioc_event);
  116. static struct bfa_sm_table 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. };
  128. /*
  129. * Forward declareations for iocpf state machine
  130. */
  131. static void bfa_iocpf_enable(struct bfa_ioc *ioc);
  132. static void bfa_iocpf_disable(struct bfa_ioc *ioc);
  133. static void bfa_iocpf_fail(struct bfa_ioc *ioc);
  134. static void bfa_iocpf_initfail(struct bfa_ioc *ioc);
  135. static void bfa_iocpf_getattrfail(struct bfa_ioc *ioc);
  136. static void bfa_iocpf_stop(struct bfa_ioc *ioc);
  137. /* IOCPF state machine events */
  138. enum iocpf_event {
  139. IOCPF_E_ENABLE = 1, /*!< IOCPF enable request */
  140. IOCPF_E_DISABLE = 2, /*!< IOCPF disable request */
  141. IOCPF_E_STOP = 3, /*!< stop on driver detach */
  142. IOCPF_E_FWREADY = 4, /*!< f/w initialization done */
  143. IOCPF_E_FWRSP_ENABLE = 5, /*!< enable f/w response */
  144. IOCPF_E_FWRSP_DISABLE = 6, /*!< disable f/w response */
  145. IOCPF_E_FAIL = 7, /*!< failure notice by ioc sm */
  146. IOCPF_E_INITFAIL = 8, /*!< init fail notice by ioc sm */
  147. IOCPF_E_GETATTRFAIL = 9, /*!< init fail notice by ioc sm */
  148. IOCPF_E_SEMLOCKED = 10, /*!< h/w semaphore is locked */
  149. IOCPF_E_TIMEOUT = 11, /*!< f/w response timeout */
  150. IOCPF_E_SEM_ERROR = 12, /*!< h/w sem mapping error */
  151. };
  152. /* IOCPF states */
  153. enum bfa_iocpf_state {
  154. BFA_IOCPF_RESET = 1, /*!< IOC is in reset state */
  155. BFA_IOCPF_SEMWAIT = 2, /*!< Waiting for IOC h/w semaphore */
  156. BFA_IOCPF_HWINIT = 3, /*!< IOC h/w is being initialized */
  157. BFA_IOCPF_READY = 4, /*!< IOCPF is initialized */
  158. BFA_IOCPF_INITFAIL = 5, /*!< IOCPF failed */
  159. BFA_IOCPF_FAIL = 6, /*!< IOCPF failed */
  160. BFA_IOCPF_DISABLING = 7, /*!< IOCPF is being disabled */
  161. BFA_IOCPF_DISABLED = 8, /*!< IOCPF is disabled */
  162. BFA_IOCPF_FWMISMATCH = 9, /*!< IOC f/w different from drivers */
  163. };
  164. bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf, enum iocpf_event);
  165. bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf, enum iocpf_event);
  166. bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf, enum iocpf_event);
  167. bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf, enum iocpf_event);
  168. bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf, enum iocpf_event);
  169. bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf, enum iocpf_event);
  170. bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf, enum iocpf_event);
  171. bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf,
  172. enum iocpf_event);
  173. bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf, enum iocpf_event);
  174. bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf, enum iocpf_event);
  175. bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf, enum iocpf_event);
  176. bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf, enum iocpf_event);
  177. bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf,
  178. enum iocpf_event);
  179. bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf, enum iocpf_event);
  180. static struct bfa_sm_table iocpf_sm_table[] = {
  181. {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
  182. {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
  183. {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
  184. {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
  185. {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
  186. {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
  187. {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
  188. {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
  189. {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
  190. {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
  191. {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
  192. {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
  193. {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
  194. {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
  195. };
  196. /* IOC State Machine */
  197. /* Beginning state. IOC uninit state. */
  198. static void
  199. bfa_ioc_sm_uninit_entry(struct bfa_ioc *ioc)
  200. {
  201. }
  202. /* IOC is in uninit state. */
  203. static void
  204. bfa_ioc_sm_uninit(struct bfa_ioc *ioc, enum ioc_event event)
  205. {
  206. switch (event) {
  207. case IOC_E_RESET:
  208. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  209. break;
  210. default:
  211. bfa_sm_fault(event);
  212. }
  213. }
  214. /* Reset entry actions -- initialize state machine */
  215. static void
  216. bfa_ioc_sm_reset_entry(struct bfa_ioc *ioc)
  217. {
  218. bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
  219. }
  220. /* IOC is in reset state. */
  221. static void
  222. bfa_ioc_sm_reset(struct bfa_ioc *ioc, enum ioc_event event)
  223. {
  224. switch (event) {
  225. case IOC_E_ENABLE:
  226. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  227. break;
  228. case IOC_E_DISABLE:
  229. bfa_ioc_disable_comp(ioc);
  230. break;
  231. case IOC_E_DETACH:
  232. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  233. break;
  234. default:
  235. bfa_sm_fault(event);
  236. }
  237. }
  238. static void
  239. bfa_ioc_sm_enabling_entry(struct bfa_ioc *ioc)
  240. {
  241. bfa_iocpf_enable(ioc);
  242. }
  243. /* Host IOC function is being enabled, awaiting response from firmware.
  244. * Semaphore is acquired.
  245. */
  246. static void
  247. bfa_ioc_sm_enabling(struct bfa_ioc *ioc, enum ioc_event event)
  248. {
  249. switch (event) {
  250. case IOC_E_ENABLED:
  251. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  252. break;
  253. case IOC_E_PFFAILED:
  254. /* !!! fall through !!! */
  255. case IOC_E_HWERROR:
  256. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  257. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  258. if (event != IOC_E_PFFAILED)
  259. bfa_iocpf_initfail(ioc);
  260. break;
  261. case IOC_E_HWFAILED:
  262. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  263. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  264. break;
  265. case IOC_E_DISABLE:
  266. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  267. break;
  268. case IOC_E_DETACH:
  269. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  270. bfa_iocpf_stop(ioc);
  271. break;
  272. case IOC_E_ENABLE:
  273. break;
  274. default:
  275. bfa_sm_fault(event);
  276. }
  277. }
  278. /* Semaphore should be acquired for version check. */
  279. static void
  280. bfa_ioc_sm_getattr_entry(struct bfa_ioc *ioc)
  281. {
  282. mod_timer(&ioc->ioc_timer, jiffies +
  283. msecs_to_jiffies(BFA_IOC_TOV));
  284. bfa_ioc_send_getattr(ioc);
  285. }
  286. /* IOC configuration in progress. Timer is active. */
  287. static void
  288. bfa_ioc_sm_getattr(struct bfa_ioc *ioc, enum ioc_event event)
  289. {
  290. switch (event) {
  291. case IOC_E_FWRSP_GETATTR:
  292. del_timer(&ioc->ioc_timer);
  293. bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
  294. break;
  295. case IOC_E_PFFAILED:
  296. case IOC_E_HWERROR:
  297. del_timer(&ioc->ioc_timer);
  298. /* fall through */
  299. case IOC_E_TIMEOUT:
  300. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  301. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  302. if (event != IOC_E_PFFAILED)
  303. bfa_iocpf_getattrfail(ioc);
  304. break;
  305. case IOC_E_DISABLE:
  306. del_timer(&ioc->ioc_timer);
  307. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  308. break;
  309. case IOC_E_ENABLE:
  310. break;
  311. default:
  312. bfa_sm_fault(event);
  313. }
  314. }
  315. static void
  316. bfa_ioc_sm_op_entry(struct bfa_ioc *ioc)
  317. {
  318. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
  319. bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
  320. bfa_ioc_hb_monitor(ioc);
  321. }
  322. static void
  323. bfa_ioc_sm_op(struct bfa_ioc *ioc, enum ioc_event event)
  324. {
  325. switch (event) {
  326. case IOC_E_ENABLE:
  327. break;
  328. case IOC_E_DISABLE:
  329. bfa_ioc_hb_stop(ioc);
  330. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  331. break;
  332. case IOC_E_PFFAILED:
  333. case IOC_E_HWERROR:
  334. bfa_ioc_hb_stop(ioc);
  335. /* !!! fall through !!! */
  336. case IOC_E_HBFAIL:
  337. if (ioc->iocpf.auto_recover)
  338. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
  339. else
  340. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  341. bfa_ioc_fail_notify(ioc);
  342. if (event != IOC_E_PFFAILED)
  343. bfa_iocpf_fail(ioc);
  344. break;
  345. default:
  346. bfa_sm_fault(event);
  347. }
  348. }
  349. static void
  350. bfa_ioc_sm_disabling_entry(struct bfa_ioc *ioc)
  351. {
  352. bfa_iocpf_disable(ioc);
  353. }
  354. /* IOC is being disabled */
  355. static void
  356. bfa_ioc_sm_disabling(struct bfa_ioc *ioc, enum ioc_event event)
  357. {
  358. switch (event) {
  359. case IOC_E_DISABLED:
  360. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  361. break;
  362. case IOC_E_HWERROR:
  363. /*
  364. * No state change. Will move to disabled state
  365. * after iocpf sm completes failure processing and
  366. * moves to disabled state.
  367. */
  368. bfa_iocpf_fail(ioc);
  369. break;
  370. case IOC_E_HWFAILED:
  371. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  372. bfa_ioc_disable_comp(ioc);
  373. break;
  374. default:
  375. bfa_sm_fault(event);
  376. }
  377. }
  378. /* IOC disable completion entry. */
  379. static void
  380. bfa_ioc_sm_disabled_entry(struct bfa_ioc *ioc)
  381. {
  382. bfa_ioc_disable_comp(ioc);
  383. }
  384. static void
  385. bfa_ioc_sm_disabled(struct bfa_ioc *ioc, enum ioc_event event)
  386. {
  387. switch (event) {
  388. case IOC_E_ENABLE:
  389. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  390. break;
  391. case IOC_E_DISABLE:
  392. ioc->cbfn->disable_cbfn(ioc->bfa);
  393. break;
  394. case IOC_E_DETACH:
  395. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  396. bfa_iocpf_stop(ioc);
  397. break;
  398. default:
  399. bfa_sm_fault(event);
  400. }
  401. }
  402. static void
  403. bfa_ioc_sm_fail_retry_entry(struct bfa_ioc *ioc)
  404. {
  405. }
  406. /* Hardware initialization retry. */
  407. static void
  408. bfa_ioc_sm_fail_retry(struct bfa_ioc *ioc, enum ioc_event event)
  409. {
  410. switch (event) {
  411. case IOC_E_ENABLED:
  412. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  413. break;
  414. case IOC_E_PFFAILED:
  415. case IOC_E_HWERROR:
  416. /**
  417. * Initialization retry failed.
  418. */
  419. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  420. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  421. if (event != IOC_E_PFFAILED)
  422. bfa_iocpf_initfail(ioc);
  423. break;
  424. case IOC_E_HWFAILED:
  425. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  426. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  427. break;
  428. case IOC_E_ENABLE:
  429. break;
  430. case IOC_E_DISABLE:
  431. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  432. break;
  433. case IOC_E_DETACH:
  434. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  435. bfa_iocpf_stop(ioc);
  436. break;
  437. default:
  438. bfa_sm_fault(event);
  439. }
  440. }
  441. static void
  442. bfa_ioc_sm_fail_entry(struct bfa_ioc *ioc)
  443. {
  444. }
  445. /* IOC failure. */
  446. static void
  447. bfa_ioc_sm_fail(struct bfa_ioc *ioc, enum ioc_event event)
  448. {
  449. switch (event) {
  450. case IOC_E_ENABLE:
  451. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  452. break;
  453. case IOC_E_DISABLE:
  454. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  455. break;
  456. case IOC_E_DETACH:
  457. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  458. bfa_iocpf_stop(ioc);
  459. break;
  460. case IOC_E_HWERROR:
  461. /* HB failure notification, ignore. */
  462. break;
  463. default:
  464. bfa_sm_fault(event);
  465. }
  466. }
  467. static void
  468. bfa_ioc_sm_hwfail_entry(struct bfa_ioc *ioc)
  469. {
  470. }
  471. /* IOC failure. */
  472. static void
  473. bfa_ioc_sm_hwfail(struct bfa_ioc *ioc, enum ioc_event event)
  474. {
  475. switch (event) {
  476. case IOC_E_ENABLE:
  477. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  478. break;
  479. case IOC_E_DISABLE:
  480. ioc->cbfn->disable_cbfn(ioc->bfa);
  481. break;
  482. case IOC_E_DETACH:
  483. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  484. break;
  485. default:
  486. bfa_sm_fault(event);
  487. }
  488. }
  489. /* IOCPF State Machine */
  490. /* Reset entry actions -- initialize state machine */
  491. static void
  492. bfa_iocpf_sm_reset_entry(struct bfa_iocpf *iocpf)
  493. {
  494. iocpf->fw_mismatch_notified = false;
  495. iocpf->auto_recover = bfa_nw_auto_recover;
  496. }
  497. /* Beginning state. IOC is in reset state. */
  498. static void
  499. bfa_iocpf_sm_reset(struct bfa_iocpf *iocpf, enum iocpf_event event)
  500. {
  501. switch (event) {
  502. case IOCPF_E_ENABLE:
  503. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
  504. break;
  505. case IOCPF_E_STOP:
  506. break;
  507. default:
  508. bfa_sm_fault(event);
  509. }
  510. }
  511. /* Semaphore should be acquired for version check. */
  512. static void
  513. bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf *iocpf)
  514. {
  515. bfa_ioc_hw_sem_init(iocpf->ioc);
  516. bfa_ioc_hw_sem_get(iocpf->ioc);
  517. }
  518. /* Awaiting h/w semaphore to continue with version check. */
  519. static void
  520. bfa_iocpf_sm_fwcheck(struct bfa_iocpf *iocpf, enum iocpf_event event)
  521. {
  522. struct bfa_ioc *ioc = iocpf->ioc;
  523. switch (event) {
  524. case IOCPF_E_SEMLOCKED:
  525. if (bfa_ioc_firmware_lock(ioc)) {
  526. if (bfa_ioc_sync_start(ioc)) {
  527. bfa_ioc_sync_join(ioc);
  528. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  529. } else {
  530. bfa_ioc_firmware_unlock(ioc);
  531. bfa_nw_ioc_hw_sem_release(ioc);
  532. mod_timer(&ioc->sem_timer, jiffies +
  533. msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
  534. }
  535. } else {
  536. bfa_nw_ioc_hw_sem_release(ioc);
  537. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
  538. }
  539. break;
  540. case IOCPF_E_SEM_ERROR:
  541. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  542. bfa_ioc_pf_hwfailed(ioc);
  543. break;
  544. case IOCPF_E_DISABLE:
  545. bfa_ioc_hw_sem_get_cancel(ioc);
  546. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  547. bfa_ioc_pf_disabled(ioc);
  548. break;
  549. case IOCPF_E_STOP:
  550. bfa_ioc_hw_sem_get_cancel(ioc);
  551. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  552. break;
  553. default:
  554. bfa_sm_fault(event);
  555. }
  556. }
  557. /* Notify enable completion callback */
  558. static void
  559. bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf *iocpf)
  560. {
  561. /* Call only the first time sm enters fwmismatch state. */
  562. if (!iocpf->fw_mismatch_notified)
  563. bfa_ioc_pf_fwmismatch(iocpf->ioc);
  564. iocpf->fw_mismatch_notified = true;
  565. mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
  566. msecs_to_jiffies(BFA_IOC_TOV));
  567. }
  568. /* Awaiting firmware version match. */
  569. static void
  570. bfa_iocpf_sm_mismatch(struct bfa_iocpf *iocpf, enum iocpf_event event)
  571. {
  572. struct bfa_ioc *ioc = iocpf->ioc;
  573. switch (event) {
  574. case IOCPF_E_TIMEOUT:
  575. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
  576. break;
  577. case IOCPF_E_DISABLE:
  578. del_timer(&ioc->iocpf_timer);
  579. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  580. bfa_ioc_pf_disabled(ioc);
  581. break;
  582. case IOCPF_E_STOP:
  583. del_timer(&ioc->iocpf_timer);
  584. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  585. break;
  586. default:
  587. bfa_sm_fault(event);
  588. }
  589. }
  590. /* Request for semaphore. */
  591. static void
  592. bfa_iocpf_sm_semwait_entry(struct bfa_iocpf *iocpf)
  593. {
  594. bfa_ioc_hw_sem_get(iocpf->ioc);
  595. }
  596. /* Awaiting semaphore for h/w initialzation. */
  597. static void
  598. bfa_iocpf_sm_semwait(struct bfa_iocpf *iocpf, enum iocpf_event event)
  599. {
  600. struct bfa_ioc *ioc = iocpf->ioc;
  601. switch (event) {
  602. case IOCPF_E_SEMLOCKED:
  603. if (bfa_ioc_sync_complete(ioc)) {
  604. bfa_ioc_sync_join(ioc);
  605. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  606. } else {
  607. bfa_nw_ioc_hw_sem_release(ioc);
  608. mod_timer(&ioc->sem_timer, jiffies +
  609. msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
  610. }
  611. break;
  612. case IOCPF_E_SEM_ERROR:
  613. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  614. bfa_ioc_pf_hwfailed(ioc);
  615. break;
  616. case IOCPF_E_DISABLE:
  617. bfa_ioc_hw_sem_get_cancel(ioc);
  618. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  619. break;
  620. default:
  621. bfa_sm_fault(event);
  622. }
  623. }
  624. static void
  625. bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf *iocpf)
  626. {
  627. iocpf->poll_time = 0;
  628. bfa_ioc_reset(iocpf->ioc, false);
  629. }
  630. /* Hardware is being initialized. Interrupts are enabled.
  631. * Holding hardware semaphore lock.
  632. */
  633. static void
  634. bfa_iocpf_sm_hwinit(struct bfa_iocpf *iocpf, enum iocpf_event event)
  635. {
  636. struct bfa_ioc *ioc = iocpf->ioc;
  637. switch (event) {
  638. case IOCPF_E_FWREADY:
  639. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
  640. break;
  641. case IOCPF_E_TIMEOUT:
  642. bfa_nw_ioc_hw_sem_release(ioc);
  643. bfa_ioc_pf_failed(ioc);
  644. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  645. break;
  646. case IOCPF_E_DISABLE:
  647. del_timer(&ioc->iocpf_timer);
  648. bfa_ioc_sync_leave(ioc);
  649. bfa_nw_ioc_hw_sem_release(ioc);
  650. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  651. break;
  652. default:
  653. bfa_sm_fault(event);
  654. }
  655. }
  656. static void
  657. bfa_iocpf_sm_enabling_entry(struct bfa_iocpf *iocpf)
  658. {
  659. mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
  660. msecs_to_jiffies(BFA_IOC_TOV));
  661. /**
  662. * Enable Interrupts before sending fw IOC ENABLE cmd.
  663. */
  664. iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa);
  665. bfa_ioc_send_enable(iocpf->ioc);
  666. }
  667. /* Host IOC function is being enabled, awaiting response from firmware.
  668. * Semaphore is acquired.
  669. */
  670. static void
  671. bfa_iocpf_sm_enabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
  672. {
  673. struct bfa_ioc *ioc = iocpf->ioc;
  674. switch (event) {
  675. case IOCPF_E_FWRSP_ENABLE:
  676. del_timer(&ioc->iocpf_timer);
  677. bfa_nw_ioc_hw_sem_release(ioc);
  678. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
  679. break;
  680. case IOCPF_E_INITFAIL:
  681. del_timer(&ioc->iocpf_timer);
  682. /*
  683. * !!! fall through !!!
  684. */
  685. case IOCPF_E_TIMEOUT:
  686. bfa_nw_ioc_hw_sem_release(ioc);
  687. if (event == IOCPF_E_TIMEOUT)
  688. bfa_ioc_pf_failed(ioc);
  689. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  690. break;
  691. case IOCPF_E_DISABLE:
  692. del_timer(&ioc->iocpf_timer);
  693. bfa_nw_ioc_hw_sem_release(ioc);
  694. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
  695. break;
  696. default:
  697. bfa_sm_fault(event);
  698. }
  699. }
  700. static void
  701. bfa_iocpf_sm_ready_entry(struct bfa_iocpf *iocpf)
  702. {
  703. bfa_ioc_pf_enabled(iocpf->ioc);
  704. }
  705. static void
  706. bfa_iocpf_sm_ready(struct bfa_iocpf *iocpf, enum iocpf_event event)
  707. {
  708. switch (event) {
  709. case IOCPF_E_DISABLE:
  710. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
  711. break;
  712. case IOCPF_E_GETATTRFAIL:
  713. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  714. break;
  715. case IOCPF_E_FAIL:
  716. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
  717. break;
  718. default:
  719. bfa_sm_fault(event);
  720. }
  721. }
  722. static void
  723. bfa_iocpf_sm_disabling_entry(struct bfa_iocpf *iocpf)
  724. {
  725. mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
  726. msecs_to_jiffies(BFA_IOC_TOV));
  727. bfa_ioc_send_disable(iocpf->ioc);
  728. }
  729. /* IOC is being disabled */
  730. static void
  731. bfa_iocpf_sm_disabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
  732. {
  733. struct bfa_ioc *ioc = iocpf->ioc;
  734. switch (event) {
  735. case IOCPF_E_FWRSP_DISABLE:
  736. del_timer(&ioc->iocpf_timer);
  737. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  738. break;
  739. case IOCPF_E_FAIL:
  740. del_timer(&ioc->iocpf_timer);
  741. /*
  742. * !!! fall through !!!
  743. */
  744. case IOCPF_E_TIMEOUT:
  745. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
  746. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  747. break;
  748. case IOCPF_E_FWRSP_ENABLE:
  749. break;
  750. default:
  751. bfa_sm_fault(event);
  752. }
  753. }
  754. static void
  755. bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf *iocpf)
  756. {
  757. bfa_ioc_hw_sem_get(iocpf->ioc);
  758. }
  759. /* IOC hb ack request is being removed. */
  760. static void
  761. bfa_iocpf_sm_disabling_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
  762. {
  763. struct bfa_ioc *ioc = iocpf->ioc;
  764. switch (event) {
  765. case IOCPF_E_SEMLOCKED:
  766. bfa_ioc_sync_leave(ioc);
  767. bfa_nw_ioc_hw_sem_release(ioc);
  768. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  769. break;
  770. case IOCPF_E_SEM_ERROR:
  771. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  772. bfa_ioc_pf_hwfailed(ioc);
  773. break;
  774. case IOCPF_E_FAIL:
  775. break;
  776. default:
  777. bfa_sm_fault(event);
  778. }
  779. }
  780. /* IOC disable completion entry. */
  781. static void
  782. bfa_iocpf_sm_disabled_entry(struct bfa_iocpf *iocpf)
  783. {
  784. bfa_ioc_mbox_flush(iocpf->ioc);
  785. bfa_ioc_pf_disabled(iocpf->ioc);
  786. }
  787. static void
  788. bfa_iocpf_sm_disabled(struct bfa_iocpf *iocpf, enum iocpf_event event)
  789. {
  790. struct bfa_ioc *ioc = iocpf->ioc;
  791. switch (event) {
  792. case IOCPF_E_ENABLE:
  793. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  794. break;
  795. case IOCPF_E_STOP:
  796. bfa_ioc_firmware_unlock(ioc);
  797. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  798. break;
  799. default:
  800. bfa_sm_fault(event);
  801. }
  802. }
  803. static void
  804. bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf *iocpf)
  805. {
  806. bfa_nw_ioc_debug_save_ftrc(iocpf->ioc);
  807. bfa_ioc_hw_sem_get(iocpf->ioc);
  808. }
  809. /* Hardware initialization failed. */
  810. static void
  811. bfa_iocpf_sm_initfail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
  812. {
  813. struct bfa_ioc *ioc = iocpf->ioc;
  814. switch (event) {
  815. case IOCPF_E_SEMLOCKED:
  816. bfa_ioc_notify_fail(ioc);
  817. bfa_ioc_sync_leave(ioc);
  818. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
  819. bfa_nw_ioc_hw_sem_release(ioc);
  820. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
  821. break;
  822. case IOCPF_E_SEM_ERROR:
  823. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  824. bfa_ioc_pf_hwfailed(ioc);
  825. break;
  826. case IOCPF_E_DISABLE:
  827. bfa_ioc_hw_sem_get_cancel(ioc);
  828. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  829. break;
  830. case IOCPF_E_STOP:
  831. bfa_ioc_hw_sem_get_cancel(ioc);
  832. bfa_ioc_firmware_unlock(ioc);
  833. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  834. break;
  835. case IOCPF_E_FAIL:
  836. break;
  837. default:
  838. bfa_sm_fault(event);
  839. }
  840. }
  841. static void
  842. bfa_iocpf_sm_initfail_entry(struct bfa_iocpf *iocpf)
  843. {
  844. }
  845. /* Hardware initialization failed. */
  846. static void
  847. bfa_iocpf_sm_initfail(struct bfa_iocpf *iocpf, enum iocpf_event event)
  848. {
  849. struct bfa_ioc *ioc = iocpf->ioc;
  850. switch (event) {
  851. case IOCPF_E_DISABLE:
  852. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  853. break;
  854. case IOCPF_E_STOP:
  855. bfa_ioc_firmware_unlock(ioc);
  856. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  857. break;
  858. default:
  859. bfa_sm_fault(event);
  860. }
  861. }
  862. static void
  863. bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf *iocpf)
  864. {
  865. /**
  866. * Mark IOC as failed in hardware and stop firmware.
  867. */
  868. bfa_ioc_lpu_stop(iocpf->ioc);
  869. /**
  870. * Flush any queued up mailbox requests.
  871. */
  872. bfa_ioc_mbox_flush(iocpf->ioc);
  873. bfa_ioc_hw_sem_get(iocpf->ioc);
  874. }
  875. /* IOC is in failed state. */
  876. static void
  877. bfa_iocpf_sm_fail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
  878. {
  879. struct bfa_ioc *ioc = iocpf->ioc;
  880. switch (event) {
  881. case IOCPF_E_SEMLOCKED:
  882. bfa_ioc_sync_ack(ioc);
  883. bfa_ioc_notify_fail(ioc);
  884. if (!iocpf->auto_recover) {
  885. bfa_ioc_sync_leave(ioc);
  886. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
  887. bfa_nw_ioc_hw_sem_release(ioc);
  888. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  889. } else {
  890. if (bfa_ioc_sync_complete(ioc))
  891. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  892. else {
  893. bfa_nw_ioc_hw_sem_release(ioc);
  894. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  895. }
  896. }
  897. break;
  898. case IOCPF_E_SEM_ERROR:
  899. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  900. bfa_ioc_pf_hwfailed(ioc);
  901. break;
  902. case IOCPF_E_DISABLE:
  903. bfa_ioc_hw_sem_get_cancel(ioc);
  904. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  905. break;
  906. case IOCPF_E_FAIL:
  907. break;
  908. default:
  909. bfa_sm_fault(event);
  910. }
  911. }
  912. static void
  913. bfa_iocpf_sm_fail_entry(struct bfa_iocpf *iocpf)
  914. {
  915. }
  916. /* IOC is in failed state. */
  917. static void
  918. bfa_iocpf_sm_fail(struct bfa_iocpf *iocpf, enum iocpf_event event)
  919. {
  920. switch (event) {
  921. case IOCPF_E_DISABLE:
  922. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  923. break;
  924. default:
  925. bfa_sm_fault(event);
  926. }
  927. }
  928. /* BFA IOC private functions */
  929. /* Notify common modules registered for notification. */
  930. static void
  931. bfa_ioc_event_notify(struct bfa_ioc *ioc, enum bfa_ioc_event event)
  932. {
  933. struct bfa_ioc_notify *notify;
  934. list_for_each_entry(notify, &ioc->notify_q, qe)
  935. notify->cbfn(notify->cbarg, event);
  936. }
  937. static void
  938. bfa_ioc_disable_comp(struct bfa_ioc *ioc)
  939. {
  940. ioc->cbfn->disable_cbfn(ioc->bfa);
  941. bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
  942. }
  943. bool
  944. bfa_nw_ioc_sem_get(void __iomem *sem_reg)
  945. {
  946. u32 r32;
  947. int cnt = 0;
  948. #define BFA_SEM_SPINCNT 3000
  949. r32 = readl(sem_reg);
  950. while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) {
  951. cnt++;
  952. udelay(2);
  953. r32 = readl(sem_reg);
  954. }
  955. if (!(r32 & 1))
  956. return true;
  957. return false;
  958. }
  959. void
  960. bfa_nw_ioc_sem_release(void __iomem *sem_reg)
  961. {
  962. readl(sem_reg);
  963. writel(1, sem_reg);
  964. }
  965. /* Clear fwver hdr */
  966. static void
  967. bfa_ioc_fwver_clear(struct bfa_ioc *ioc)
  968. {
  969. u32 pgnum, pgoff, loff = 0;
  970. int i;
  971. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  972. pgoff = PSS_SMEM_PGOFF(loff);
  973. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  974. for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr) / sizeof(u32)); i++) {
  975. writel(0, ioc->ioc_regs.smem_page_start + loff);
  976. loff += sizeof(u32);
  977. }
  978. }
  979. static void
  980. bfa_ioc_hw_sem_init(struct bfa_ioc *ioc)
  981. {
  982. struct bfi_ioc_image_hdr fwhdr;
  983. u32 fwstate, r32;
  984. /* Spin on init semaphore to serialize. */
  985. r32 = readl(ioc->ioc_regs.ioc_init_sem_reg);
  986. while (r32 & 0x1) {
  987. udelay(20);
  988. r32 = readl(ioc->ioc_regs.ioc_init_sem_reg);
  989. }
  990. fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
  991. if (fwstate == BFI_IOC_UNINIT) {
  992. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  993. return;
  994. }
  995. bfa_nw_ioc_fwver_get(ioc, &fwhdr);
  996. if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL) {
  997. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  998. return;
  999. }
  1000. bfa_ioc_fwver_clear(ioc);
  1001. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_UNINIT);
  1002. bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_UNINIT);
  1003. /*
  1004. * Try to lock and then unlock the semaphore.
  1005. */
  1006. readl(ioc->ioc_regs.ioc_sem_reg);
  1007. writel(1, ioc->ioc_regs.ioc_sem_reg);
  1008. /* Unlock init semaphore */
  1009. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1010. }
  1011. static void
  1012. bfa_ioc_hw_sem_get(struct bfa_ioc *ioc)
  1013. {
  1014. u32 r32;
  1015. /**
  1016. * First read to the semaphore register will return 0, subsequent reads
  1017. * will return 1. Semaphore is released by writing 1 to the register
  1018. */
  1019. r32 = readl(ioc->ioc_regs.ioc_sem_reg);
  1020. if (r32 == ~0) {
  1021. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEM_ERROR);
  1022. return;
  1023. }
  1024. if (!(r32 & 1)) {
  1025. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
  1026. return;
  1027. }
  1028. mod_timer(&ioc->sem_timer, jiffies +
  1029. msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
  1030. }
  1031. void
  1032. bfa_nw_ioc_hw_sem_release(struct bfa_ioc *ioc)
  1033. {
  1034. writel(1, ioc->ioc_regs.ioc_sem_reg);
  1035. }
  1036. static void
  1037. bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc)
  1038. {
  1039. del_timer(&ioc->sem_timer);
  1040. }
  1041. /* Initialize LPU local memory (aka secondary memory / SRAM) */
  1042. static void
  1043. bfa_ioc_lmem_init(struct bfa_ioc *ioc)
  1044. {
  1045. u32 pss_ctl;
  1046. int i;
  1047. #define PSS_LMEM_INIT_TIME 10000
  1048. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1049. pss_ctl &= ~__PSS_LMEM_RESET;
  1050. pss_ctl |= __PSS_LMEM_INIT_EN;
  1051. /*
  1052. * i2c workaround 12.5khz clock
  1053. */
  1054. pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
  1055. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1056. /**
  1057. * wait for memory initialization to be complete
  1058. */
  1059. i = 0;
  1060. do {
  1061. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1062. i++;
  1063. } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
  1064. /**
  1065. * If memory initialization is not successful, IOC timeout will catch
  1066. * such failures.
  1067. */
  1068. BUG_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
  1069. pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
  1070. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1071. }
  1072. static void
  1073. bfa_ioc_lpu_start(struct bfa_ioc *ioc)
  1074. {
  1075. u32 pss_ctl;
  1076. /**
  1077. * Take processor out of reset.
  1078. */
  1079. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1080. pss_ctl &= ~__PSS_LPU0_RESET;
  1081. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1082. }
  1083. static void
  1084. bfa_ioc_lpu_stop(struct bfa_ioc *ioc)
  1085. {
  1086. u32 pss_ctl;
  1087. /**
  1088. * Put processors in reset.
  1089. */
  1090. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1091. pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
  1092. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1093. }
  1094. /* Get driver and firmware versions. */
  1095. void
  1096. bfa_nw_ioc_fwver_get(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
  1097. {
  1098. u32 pgnum;
  1099. u32 loff = 0;
  1100. int i;
  1101. u32 *fwsig = (u32 *) fwhdr;
  1102. pgnum = bfa_ioc_smem_pgnum(ioc, loff);
  1103. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1104. for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr) / sizeof(u32));
  1105. i++) {
  1106. fwsig[i] =
  1107. swab32(readl(loff + ioc->ioc_regs.smem_page_start));
  1108. loff += sizeof(u32);
  1109. }
  1110. }
  1111. static bool
  1112. bfa_ioc_fwver_md5_check(struct bfi_ioc_image_hdr *fwhdr_1,
  1113. struct bfi_ioc_image_hdr *fwhdr_2)
  1114. {
  1115. int i;
  1116. for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
  1117. if (fwhdr_1->md5sum[i] != fwhdr_2->md5sum[i])
  1118. return false;
  1119. }
  1120. return true;
  1121. }
  1122. /* Returns TRUE if major minor and maintenance are same.
  1123. * If patch version are same, check for MD5 Checksum to be same.
  1124. */
  1125. static bool
  1126. bfa_ioc_fw_ver_compatible(struct bfi_ioc_image_hdr *drv_fwhdr,
  1127. struct bfi_ioc_image_hdr *fwhdr_to_cmp)
  1128. {
  1129. if (drv_fwhdr->signature != fwhdr_to_cmp->signature)
  1130. return false;
  1131. if (drv_fwhdr->fwver.major != fwhdr_to_cmp->fwver.major)
  1132. return false;
  1133. if (drv_fwhdr->fwver.minor != fwhdr_to_cmp->fwver.minor)
  1134. return false;
  1135. if (drv_fwhdr->fwver.maint != fwhdr_to_cmp->fwver.maint)
  1136. return false;
  1137. if (drv_fwhdr->fwver.patch == fwhdr_to_cmp->fwver.patch &&
  1138. drv_fwhdr->fwver.phase == fwhdr_to_cmp->fwver.phase &&
  1139. drv_fwhdr->fwver.build == fwhdr_to_cmp->fwver.build)
  1140. return bfa_ioc_fwver_md5_check(drv_fwhdr, fwhdr_to_cmp);
  1141. return true;
  1142. }
  1143. static bool
  1144. bfa_ioc_flash_fwver_valid(struct bfi_ioc_image_hdr *flash_fwhdr)
  1145. {
  1146. if (flash_fwhdr->fwver.major == 0 || flash_fwhdr->fwver.major == 0xFF)
  1147. return false;
  1148. return true;
  1149. }
  1150. static bool
  1151. fwhdr_is_ga(struct bfi_ioc_image_hdr *fwhdr)
  1152. {
  1153. if (fwhdr->fwver.phase == 0 &&
  1154. fwhdr->fwver.build == 0)
  1155. return false;
  1156. return true;
  1157. }
  1158. /* Returns TRUE if both are compatible and patch of fwhdr_to_cmp is better. */
  1159. static enum bfi_ioc_img_ver_cmp
  1160. bfa_ioc_fw_ver_patch_cmp(struct bfi_ioc_image_hdr *base_fwhdr,
  1161. struct bfi_ioc_image_hdr *fwhdr_to_cmp)
  1162. {
  1163. if (!bfa_ioc_fw_ver_compatible(base_fwhdr, fwhdr_to_cmp))
  1164. return BFI_IOC_IMG_VER_INCOMP;
  1165. if (fwhdr_to_cmp->fwver.patch > base_fwhdr->fwver.patch)
  1166. return BFI_IOC_IMG_VER_BETTER;
  1167. else if (fwhdr_to_cmp->fwver.patch < base_fwhdr->fwver.patch)
  1168. return BFI_IOC_IMG_VER_OLD;
  1169. /* GA takes priority over internal builds of the same patch stream.
  1170. * At this point major minor maint and patch numbers are same.
  1171. */
  1172. if (fwhdr_is_ga(base_fwhdr))
  1173. if (fwhdr_is_ga(fwhdr_to_cmp))
  1174. return BFI_IOC_IMG_VER_SAME;
  1175. else
  1176. return BFI_IOC_IMG_VER_OLD;
  1177. else
  1178. if (fwhdr_is_ga(fwhdr_to_cmp))
  1179. return BFI_IOC_IMG_VER_BETTER;
  1180. if (fwhdr_to_cmp->fwver.phase > base_fwhdr->fwver.phase)
  1181. return BFI_IOC_IMG_VER_BETTER;
  1182. else if (fwhdr_to_cmp->fwver.phase < base_fwhdr->fwver.phase)
  1183. return BFI_IOC_IMG_VER_OLD;
  1184. if (fwhdr_to_cmp->fwver.build > base_fwhdr->fwver.build)
  1185. return BFI_IOC_IMG_VER_BETTER;
  1186. else if (fwhdr_to_cmp->fwver.build < base_fwhdr->fwver.build)
  1187. return BFI_IOC_IMG_VER_OLD;
  1188. /* All Version Numbers are equal.
  1189. * Md5 check to be done as a part of compatibility check.
  1190. */
  1191. return BFI_IOC_IMG_VER_SAME;
  1192. }
  1193. /* register definitions */
  1194. #define FLI_CMD_REG 0x0001d000
  1195. #define FLI_WRDATA_REG 0x0001d00c
  1196. #define FLI_RDDATA_REG 0x0001d010
  1197. #define FLI_ADDR_REG 0x0001d004
  1198. #define FLI_DEV_STATUS_REG 0x0001d014
  1199. #define BFA_FLASH_FIFO_SIZE 128 /* fifo size */
  1200. #define BFA_FLASH_CHECK_MAX 10000 /* max # of status check */
  1201. #define BFA_FLASH_BLOCKING_OP_MAX 1000000 /* max # of blocking op check */
  1202. #define BFA_FLASH_WIP_MASK 0x01 /* write in progress bit mask */
  1203. #define NFC_STATE_RUNNING 0x20000001
  1204. #define NFC_STATE_PAUSED 0x00004560
  1205. #define NFC_VER_VALID 0x147
  1206. enum bfa_flash_cmd {
  1207. BFA_FLASH_FAST_READ = 0x0b, /* fast read */
  1208. BFA_FLASH_WRITE_ENABLE = 0x06, /* write enable */
  1209. BFA_FLASH_SECTOR_ERASE = 0xd8, /* sector erase */
  1210. BFA_FLASH_WRITE = 0x02, /* write */
  1211. BFA_FLASH_READ_STATUS = 0x05, /* read status */
  1212. };
  1213. /* hardware error definition */
  1214. enum bfa_flash_err {
  1215. BFA_FLASH_NOT_PRESENT = -1, /*!< flash not present */
  1216. BFA_FLASH_UNINIT = -2, /*!< flash not initialized */
  1217. BFA_FLASH_BAD = -3, /*!< flash bad */
  1218. BFA_FLASH_BUSY = -4, /*!< flash busy */
  1219. BFA_FLASH_ERR_CMD_ACT = -5, /*!< command active never cleared */
  1220. BFA_FLASH_ERR_FIFO_CNT = -6, /*!< fifo count never cleared */
  1221. BFA_FLASH_ERR_WIP = -7, /*!< write-in-progress never cleared */
  1222. BFA_FLASH_ERR_TIMEOUT = -8, /*!< fli timeout */
  1223. BFA_FLASH_ERR_LEN = -9, /*!< invalid length */
  1224. };
  1225. /* flash command register data structure */
  1226. union bfa_flash_cmd_reg {
  1227. struct {
  1228. #ifdef __BIG_ENDIAN
  1229. u32 act:1;
  1230. u32 rsv:1;
  1231. u32 write_cnt:9;
  1232. u32 read_cnt:9;
  1233. u32 addr_cnt:4;
  1234. u32 cmd:8;
  1235. #else
  1236. u32 cmd:8;
  1237. u32 addr_cnt:4;
  1238. u32 read_cnt:9;
  1239. u32 write_cnt:9;
  1240. u32 rsv:1;
  1241. u32 act:1;
  1242. #endif
  1243. } r;
  1244. u32 i;
  1245. };
  1246. /* flash device status register data structure */
  1247. union bfa_flash_dev_status_reg {
  1248. struct {
  1249. #ifdef __BIG_ENDIAN
  1250. u32 rsv:21;
  1251. u32 fifo_cnt:6;
  1252. u32 busy:1;
  1253. u32 init_status:1;
  1254. u32 present:1;
  1255. u32 bad:1;
  1256. u32 good:1;
  1257. #else
  1258. u32 good:1;
  1259. u32 bad:1;
  1260. u32 present:1;
  1261. u32 init_status:1;
  1262. u32 busy:1;
  1263. u32 fifo_cnt:6;
  1264. u32 rsv:21;
  1265. #endif
  1266. } r;
  1267. u32 i;
  1268. };
  1269. /* flash address register data structure */
  1270. union bfa_flash_addr_reg {
  1271. struct {
  1272. #ifdef __BIG_ENDIAN
  1273. u32 addr:24;
  1274. u32 dummy:8;
  1275. #else
  1276. u32 dummy:8;
  1277. u32 addr:24;
  1278. #endif
  1279. } r;
  1280. u32 i;
  1281. };
  1282. /* Flash raw private functions */
  1283. static void
  1284. bfa_flash_set_cmd(void __iomem *pci_bar, u8 wr_cnt,
  1285. u8 rd_cnt, u8 ad_cnt, u8 op)
  1286. {
  1287. union bfa_flash_cmd_reg cmd;
  1288. cmd.i = 0;
  1289. cmd.r.act = 1;
  1290. cmd.r.write_cnt = wr_cnt;
  1291. cmd.r.read_cnt = rd_cnt;
  1292. cmd.r.addr_cnt = ad_cnt;
  1293. cmd.r.cmd = op;
  1294. writel(cmd.i, (pci_bar + FLI_CMD_REG));
  1295. }
  1296. static void
  1297. bfa_flash_set_addr(void __iomem *pci_bar, u32 address)
  1298. {
  1299. union bfa_flash_addr_reg addr;
  1300. addr.r.addr = address & 0x00ffffff;
  1301. addr.r.dummy = 0;
  1302. writel(addr.i, (pci_bar + FLI_ADDR_REG));
  1303. }
  1304. static int
  1305. bfa_flash_cmd_act_check(void __iomem *pci_bar)
  1306. {
  1307. union bfa_flash_cmd_reg cmd;
  1308. cmd.i = readl(pci_bar + FLI_CMD_REG);
  1309. if (cmd.r.act)
  1310. return BFA_FLASH_ERR_CMD_ACT;
  1311. return 0;
  1312. }
  1313. /* Flush FLI data fifo. */
  1314. static int
  1315. bfa_flash_fifo_flush(void __iomem *pci_bar)
  1316. {
  1317. u32 i;
  1318. u32 t;
  1319. union bfa_flash_dev_status_reg dev_status;
  1320. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  1321. if (!dev_status.r.fifo_cnt)
  1322. return 0;
  1323. /* fifo counter in terms of words */
  1324. for (i = 0; i < dev_status.r.fifo_cnt; i++)
  1325. t = readl(pci_bar + FLI_RDDATA_REG);
  1326. /* Check the device status. It may take some time. */
  1327. for (i = 0; i < BFA_FLASH_CHECK_MAX; i++) {
  1328. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  1329. if (!dev_status.r.fifo_cnt)
  1330. break;
  1331. }
  1332. if (dev_status.r.fifo_cnt)
  1333. return BFA_FLASH_ERR_FIFO_CNT;
  1334. return 0;
  1335. }
  1336. /* Read flash status. */
  1337. static int
  1338. bfa_flash_status_read(void __iomem *pci_bar)
  1339. {
  1340. union bfa_flash_dev_status_reg dev_status;
  1341. int status;
  1342. u32 ret_status;
  1343. int i;
  1344. status = bfa_flash_fifo_flush(pci_bar);
  1345. if (status < 0)
  1346. return status;
  1347. bfa_flash_set_cmd(pci_bar, 0, 4, 0, BFA_FLASH_READ_STATUS);
  1348. for (i = 0; i < BFA_FLASH_CHECK_MAX; i++) {
  1349. status = bfa_flash_cmd_act_check(pci_bar);
  1350. if (!status)
  1351. break;
  1352. }
  1353. if (status)
  1354. return status;
  1355. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  1356. if (!dev_status.r.fifo_cnt)
  1357. return BFA_FLASH_BUSY;
  1358. ret_status = readl(pci_bar + FLI_RDDATA_REG);
  1359. ret_status >>= 24;
  1360. status = bfa_flash_fifo_flush(pci_bar);
  1361. if (status < 0)
  1362. return status;
  1363. return ret_status;
  1364. }
  1365. /* Start flash read operation. */
  1366. static int
  1367. bfa_flash_read_start(void __iomem *pci_bar, u32 offset, u32 len,
  1368. char *buf)
  1369. {
  1370. int status;
  1371. /* len must be mutiple of 4 and not exceeding fifo size */
  1372. if (len == 0 || len > BFA_FLASH_FIFO_SIZE || (len & 0x03) != 0)
  1373. return BFA_FLASH_ERR_LEN;
  1374. /* check status */
  1375. status = bfa_flash_status_read(pci_bar);
  1376. if (status == BFA_FLASH_BUSY)
  1377. status = bfa_flash_status_read(pci_bar);
  1378. if (status < 0)
  1379. return status;
  1380. /* check if write-in-progress bit is cleared */
  1381. if (status & BFA_FLASH_WIP_MASK)
  1382. return BFA_FLASH_ERR_WIP;
  1383. bfa_flash_set_addr(pci_bar, offset);
  1384. bfa_flash_set_cmd(pci_bar, 0, (u8)len, 4, BFA_FLASH_FAST_READ);
  1385. return 0;
  1386. }
  1387. /* Check flash read operation. */
  1388. static u32
  1389. bfa_flash_read_check(void __iomem *pci_bar)
  1390. {
  1391. if (bfa_flash_cmd_act_check(pci_bar))
  1392. return 1;
  1393. return 0;
  1394. }
  1395. /* End flash read operation. */
  1396. static void
  1397. bfa_flash_read_end(void __iomem *pci_bar, u32 len, char *buf)
  1398. {
  1399. u32 i;
  1400. /* read data fifo up to 32 words */
  1401. for (i = 0; i < len; i += 4) {
  1402. u32 w = readl(pci_bar + FLI_RDDATA_REG);
  1403. *((u32 *)(buf + i)) = swab32(w);
  1404. }
  1405. bfa_flash_fifo_flush(pci_bar);
  1406. }
  1407. /* Perform flash raw read. */
  1408. #define FLASH_BLOCKING_OP_MAX 500
  1409. #define FLASH_SEM_LOCK_REG 0x18820
  1410. static int
  1411. bfa_raw_sem_get(void __iomem *bar)
  1412. {
  1413. int locked;
  1414. locked = readl(bar + FLASH_SEM_LOCK_REG);
  1415. return !locked;
  1416. }
  1417. static enum bfa_status
  1418. bfa_flash_sem_get(void __iomem *bar)
  1419. {
  1420. u32 n = FLASH_BLOCKING_OP_MAX;
  1421. while (!bfa_raw_sem_get(bar)) {
  1422. if (--n <= 0)
  1423. return BFA_STATUS_BADFLASH;
  1424. mdelay(10);
  1425. }
  1426. return BFA_STATUS_OK;
  1427. }
  1428. static void
  1429. bfa_flash_sem_put(void __iomem *bar)
  1430. {
  1431. writel(0, (bar + FLASH_SEM_LOCK_REG));
  1432. }
  1433. static enum bfa_status
  1434. bfa_flash_raw_read(void __iomem *pci_bar, u32 offset, char *buf,
  1435. u32 len)
  1436. {
  1437. u32 n;
  1438. int status;
  1439. u32 off, l, s, residue, fifo_sz;
  1440. residue = len;
  1441. off = 0;
  1442. fifo_sz = BFA_FLASH_FIFO_SIZE;
  1443. status = bfa_flash_sem_get(pci_bar);
  1444. if (status != BFA_STATUS_OK)
  1445. return status;
  1446. while (residue) {
  1447. s = offset + off;
  1448. n = s / fifo_sz;
  1449. l = (n + 1) * fifo_sz - s;
  1450. if (l > residue)
  1451. l = residue;
  1452. status = bfa_flash_read_start(pci_bar, offset + off, l,
  1453. &buf[off]);
  1454. if (status < 0) {
  1455. bfa_flash_sem_put(pci_bar);
  1456. return BFA_STATUS_FAILED;
  1457. }
  1458. n = BFA_FLASH_BLOCKING_OP_MAX;
  1459. while (bfa_flash_read_check(pci_bar)) {
  1460. if (--n <= 0) {
  1461. bfa_flash_sem_put(pci_bar);
  1462. return BFA_STATUS_FAILED;
  1463. }
  1464. }
  1465. bfa_flash_read_end(pci_bar, l, &buf[off]);
  1466. residue -= l;
  1467. off += l;
  1468. }
  1469. bfa_flash_sem_put(pci_bar);
  1470. return BFA_STATUS_OK;
  1471. }
  1472. #define BFA_FLASH_PART_FWIMG_ADDR 0x100000 /* fw image address */
  1473. static enum bfa_status
  1474. bfa_nw_ioc_flash_img_get_chnk(struct bfa_ioc *ioc, u32 off,
  1475. u32 *fwimg)
  1476. {
  1477. return bfa_flash_raw_read(ioc->pcidev.pci_bar_kva,
  1478. BFA_FLASH_PART_FWIMG_ADDR + (off * sizeof(u32)),
  1479. (char *)fwimg, BFI_FLASH_CHUNK_SZ);
  1480. }
  1481. static enum bfi_ioc_img_ver_cmp
  1482. bfa_ioc_flash_fwver_cmp(struct bfa_ioc *ioc,
  1483. struct bfi_ioc_image_hdr *base_fwhdr)
  1484. {
  1485. struct bfi_ioc_image_hdr *flash_fwhdr;
  1486. enum bfa_status status;
  1487. u32 fwimg[BFI_FLASH_CHUNK_SZ_WORDS];
  1488. status = bfa_nw_ioc_flash_img_get_chnk(ioc, 0, fwimg);
  1489. if (status != BFA_STATUS_OK)
  1490. return BFI_IOC_IMG_VER_INCOMP;
  1491. flash_fwhdr = (struct bfi_ioc_image_hdr *)fwimg;
  1492. if (bfa_ioc_flash_fwver_valid(flash_fwhdr))
  1493. return bfa_ioc_fw_ver_patch_cmp(base_fwhdr, flash_fwhdr);
  1494. else
  1495. return BFI_IOC_IMG_VER_INCOMP;
  1496. }
  1497. /**
  1498. * Returns TRUE if driver is willing to work with current smem f/w version.
  1499. */
  1500. bool
  1501. bfa_nw_ioc_fwver_cmp(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
  1502. {
  1503. struct bfi_ioc_image_hdr *drv_fwhdr;
  1504. enum bfi_ioc_img_ver_cmp smem_flash_cmp, drv_smem_cmp;
  1505. drv_fwhdr = (struct bfi_ioc_image_hdr *)
  1506. bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
  1507. /* If smem is incompatible or old, driver should not work with it. */
  1508. drv_smem_cmp = bfa_ioc_fw_ver_patch_cmp(drv_fwhdr, fwhdr);
  1509. if (drv_smem_cmp == BFI_IOC_IMG_VER_INCOMP ||
  1510. drv_smem_cmp == BFI_IOC_IMG_VER_OLD) {
  1511. return false;
  1512. }
  1513. /* IF Flash has a better F/W than smem do not work with smem.
  1514. * If smem f/w == flash f/w, as smem f/w not old | incmp, work with it.
  1515. * If Flash is old or incomp work with smem iff smem f/w == drv f/w.
  1516. */
  1517. smem_flash_cmp = bfa_ioc_flash_fwver_cmp(ioc, fwhdr);
  1518. if (smem_flash_cmp == BFI_IOC_IMG_VER_BETTER)
  1519. return false;
  1520. else if (smem_flash_cmp == BFI_IOC_IMG_VER_SAME)
  1521. return true;
  1522. else
  1523. return (drv_smem_cmp == BFI_IOC_IMG_VER_SAME) ?
  1524. true : false;
  1525. }
  1526. /* Return true if current running version is valid. Firmware signature and
  1527. * execution context (driver/bios) must match.
  1528. */
  1529. static bool
  1530. bfa_ioc_fwver_valid(struct bfa_ioc *ioc, u32 boot_env)
  1531. {
  1532. struct bfi_ioc_image_hdr fwhdr;
  1533. bfa_nw_ioc_fwver_get(ioc, &fwhdr);
  1534. if (swab32(fwhdr.bootenv) != boot_env)
  1535. return false;
  1536. return bfa_nw_ioc_fwver_cmp(ioc, &fwhdr);
  1537. }
  1538. /* Conditionally flush any pending message from firmware at start. */
  1539. static void
  1540. bfa_ioc_msgflush(struct bfa_ioc *ioc)
  1541. {
  1542. u32 r32;
  1543. r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
  1544. if (r32)
  1545. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  1546. }
  1547. static void
  1548. bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force)
  1549. {
  1550. enum bfi_ioc_state ioc_fwstate;
  1551. bool fwvalid;
  1552. u32 boot_env;
  1553. ioc_fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
  1554. if (force)
  1555. ioc_fwstate = BFI_IOC_UNINIT;
  1556. boot_env = BFI_FWBOOT_ENV_OS;
  1557. /**
  1558. * check if firmware is valid
  1559. */
  1560. fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
  1561. false : bfa_ioc_fwver_valid(ioc, boot_env);
  1562. if (!fwvalid) {
  1563. if (bfa_ioc_boot(ioc, BFI_FWBOOT_TYPE_NORMAL, boot_env) ==
  1564. BFA_STATUS_OK)
  1565. bfa_ioc_poll_fwinit(ioc);
  1566. return;
  1567. }
  1568. /**
  1569. * If hardware initialization is in progress (initialized by other IOC),
  1570. * just wait for an initialization completion interrupt.
  1571. */
  1572. if (ioc_fwstate == BFI_IOC_INITING) {
  1573. bfa_ioc_poll_fwinit(ioc);
  1574. return;
  1575. }
  1576. /**
  1577. * If IOC function is disabled and firmware version is same,
  1578. * just re-enable IOC.
  1579. */
  1580. if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
  1581. /**
  1582. * When using MSI-X any pending firmware ready event should
  1583. * be flushed. Otherwise MSI-X interrupts are not delivered.
  1584. */
  1585. bfa_ioc_msgflush(ioc);
  1586. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
  1587. return;
  1588. }
  1589. /**
  1590. * Initialize the h/w for any other states.
  1591. */
  1592. if (bfa_ioc_boot(ioc, BFI_FWBOOT_TYPE_NORMAL, boot_env) ==
  1593. BFA_STATUS_OK)
  1594. bfa_ioc_poll_fwinit(ioc);
  1595. }
  1596. void
  1597. bfa_nw_ioc_timeout(struct bfa_ioc *ioc)
  1598. {
  1599. bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
  1600. }
  1601. static void
  1602. bfa_ioc_mbox_send(struct bfa_ioc *ioc, void *ioc_msg, int len)
  1603. {
  1604. u32 *msgp = (u32 *) ioc_msg;
  1605. u32 i;
  1606. BUG_ON(!(len <= BFI_IOC_MSGLEN_MAX));
  1607. /*
  1608. * first write msg to mailbox registers
  1609. */
  1610. for (i = 0; i < len / sizeof(u32); i++)
  1611. writel(cpu_to_le32(msgp[i]),
  1612. ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1613. for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
  1614. writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1615. /*
  1616. * write 1 to mailbox CMD to trigger LPU event
  1617. */
  1618. writel(1, ioc->ioc_regs.hfn_mbox_cmd);
  1619. (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
  1620. }
  1621. static void
  1622. bfa_ioc_send_enable(struct bfa_ioc *ioc)
  1623. {
  1624. struct bfi_ioc_ctrl_req enable_req;
  1625. bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
  1626. bfa_ioc_portid(ioc));
  1627. enable_req.clscode = htons(ioc->clscode);
  1628. enable_req.rsvd = htons(0);
  1629. /* overflow in 2106 */
  1630. enable_req.tv_sec = ntohl(ktime_get_real_seconds());
  1631. bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req));
  1632. }
  1633. static void
  1634. bfa_ioc_send_disable(struct bfa_ioc *ioc)
  1635. {
  1636. struct bfi_ioc_ctrl_req disable_req;
  1637. bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
  1638. bfa_ioc_portid(ioc));
  1639. disable_req.clscode = htons(ioc->clscode);
  1640. disable_req.rsvd = htons(0);
  1641. /* overflow in 2106 */
  1642. disable_req.tv_sec = ntohl(ktime_get_real_seconds());
  1643. bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req));
  1644. }
  1645. static void
  1646. bfa_ioc_send_getattr(struct bfa_ioc *ioc)
  1647. {
  1648. struct bfi_ioc_getattr_req attr_req;
  1649. bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
  1650. bfa_ioc_portid(ioc));
  1651. bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
  1652. bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
  1653. }
  1654. void
  1655. bfa_nw_ioc_hb_check(struct bfa_ioc *ioc)
  1656. {
  1657. u32 hb_count;
  1658. hb_count = readl(ioc->ioc_regs.heartbeat);
  1659. if (ioc->hb_count == hb_count) {
  1660. bfa_ioc_recover(ioc);
  1661. return;
  1662. } else {
  1663. ioc->hb_count = hb_count;
  1664. }
  1665. bfa_ioc_mbox_poll(ioc);
  1666. mod_timer(&ioc->hb_timer, jiffies +
  1667. msecs_to_jiffies(BFA_IOC_HB_TOV));
  1668. }
  1669. static void
  1670. bfa_ioc_hb_monitor(struct bfa_ioc *ioc)
  1671. {
  1672. ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
  1673. mod_timer(&ioc->hb_timer, jiffies +
  1674. msecs_to_jiffies(BFA_IOC_HB_TOV));
  1675. }
  1676. static void
  1677. bfa_ioc_hb_stop(struct bfa_ioc *ioc)
  1678. {
  1679. del_timer(&ioc->hb_timer);
  1680. }
  1681. /* Initiate a full firmware download. */
  1682. static enum bfa_status
  1683. bfa_ioc_download_fw(struct bfa_ioc *ioc, u32 boot_type,
  1684. u32 boot_env)
  1685. {
  1686. u32 *fwimg;
  1687. u32 pgnum;
  1688. u32 loff = 0;
  1689. u32 chunkno = 0;
  1690. u32 i;
  1691. u32 asicmode;
  1692. u32 fwimg_size;
  1693. u32 fwimg_buf[BFI_FLASH_CHUNK_SZ_WORDS];
  1694. enum bfa_status status;
  1695. if (boot_env == BFI_FWBOOT_ENV_OS &&
  1696. boot_type == BFI_FWBOOT_TYPE_FLASH) {
  1697. fwimg_size = BFI_FLASH_IMAGE_SZ/sizeof(u32);
  1698. status = bfa_nw_ioc_flash_img_get_chnk(ioc,
  1699. BFA_IOC_FLASH_CHUNK_ADDR(chunkno), fwimg_buf);
  1700. if (status != BFA_STATUS_OK)
  1701. return status;
  1702. fwimg = fwimg_buf;
  1703. } else {
  1704. fwimg_size = bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc));
  1705. fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc),
  1706. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  1707. }
  1708. pgnum = bfa_ioc_smem_pgnum(ioc, loff);
  1709. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1710. for (i = 0; i < fwimg_size; i++) {
  1711. if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
  1712. chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
  1713. if (boot_env == BFI_FWBOOT_ENV_OS &&
  1714. boot_type == BFI_FWBOOT_TYPE_FLASH) {
  1715. status = bfa_nw_ioc_flash_img_get_chnk(ioc,
  1716. BFA_IOC_FLASH_CHUNK_ADDR(chunkno),
  1717. fwimg_buf);
  1718. if (status != BFA_STATUS_OK)
  1719. return status;
  1720. fwimg = fwimg_buf;
  1721. } else {
  1722. fwimg = bfa_cb_image_get_chunk(
  1723. bfa_ioc_asic_gen(ioc),
  1724. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  1725. }
  1726. }
  1727. /**
  1728. * write smem
  1729. */
  1730. writel(swab32(fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]),
  1731. ioc->ioc_regs.smem_page_start + loff);
  1732. loff += sizeof(u32);
  1733. /**
  1734. * handle page offset wrap around
  1735. */
  1736. loff = PSS_SMEM_PGOFF(loff);
  1737. if (loff == 0) {
  1738. pgnum++;
  1739. writel(pgnum,
  1740. ioc->ioc_regs.host_page_num_fn);
  1741. }
  1742. }
  1743. writel(bfa_ioc_smem_pgnum(ioc, 0),
  1744. ioc->ioc_regs.host_page_num_fn);
  1745. /*
  1746. * Set boot type, env and device mode at the end.
  1747. */
  1748. if (boot_env == BFI_FWBOOT_ENV_OS &&
  1749. boot_type == BFI_FWBOOT_TYPE_FLASH) {
  1750. boot_type = BFI_FWBOOT_TYPE_NORMAL;
  1751. }
  1752. asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode,
  1753. ioc->port0_mode, ioc->port1_mode);
  1754. writel(asicmode, ((ioc->ioc_regs.smem_page_start)
  1755. + BFI_FWBOOT_DEVMODE_OFF));
  1756. writel(boot_type, ((ioc->ioc_regs.smem_page_start)
  1757. + (BFI_FWBOOT_TYPE_OFF)));
  1758. writel(boot_env, ((ioc->ioc_regs.smem_page_start)
  1759. + (BFI_FWBOOT_ENV_OFF)));
  1760. return BFA_STATUS_OK;
  1761. }
  1762. static void
  1763. bfa_ioc_reset(struct bfa_ioc *ioc, bool force)
  1764. {
  1765. bfa_ioc_hwinit(ioc, force);
  1766. }
  1767. /* BFA ioc enable reply by firmware */
  1768. static void
  1769. bfa_ioc_enable_reply(struct bfa_ioc *ioc, enum bfa_mode port_mode,
  1770. u8 cap_bm)
  1771. {
  1772. struct bfa_iocpf *iocpf = &ioc->iocpf;
  1773. ioc->port_mode = ioc->port_mode_cfg = port_mode;
  1774. ioc->ad_cap_bm = cap_bm;
  1775. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
  1776. }
  1777. /* Update BFA configuration from firmware configuration. */
  1778. static void
  1779. bfa_ioc_getattr_reply(struct bfa_ioc *ioc)
  1780. {
  1781. struct bfi_ioc_attr *attr = ioc->attr;
  1782. attr->adapter_prop = ntohl(attr->adapter_prop);
  1783. attr->card_type = ntohl(attr->card_type);
  1784. attr->maxfrsize = ntohs(attr->maxfrsize);
  1785. bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
  1786. }
  1787. /* Attach time initialization of mbox logic. */
  1788. static void
  1789. bfa_ioc_mbox_attach(struct bfa_ioc *ioc)
  1790. {
  1791. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  1792. int mc;
  1793. INIT_LIST_HEAD(&mod->cmd_q);
  1794. for (mc = 0; mc < BFI_MC_MAX; mc++) {
  1795. mod->mbhdlr[mc].cbfn = NULL;
  1796. mod->mbhdlr[mc].cbarg = ioc->bfa;
  1797. }
  1798. }
  1799. /* Mbox poll timer -- restarts any pending mailbox requests. */
  1800. static void
  1801. bfa_ioc_mbox_poll(struct bfa_ioc *ioc)
  1802. {
  1803. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  1804. struct bfa_mbox_cmd *cmd;
  1805. bfa_mbox_cmd_cbfn_t cbfn;
  1806. void *cbarg;
  1807. u32 stat;
  1808. /**
  1809. * If no command pending, do nothing
  1810. */
  1811. if (list_empty(&mod->cmd_q))
  1812. return;
  1813. /**
  1814. * If previous command is not yet fetched by firmware, do nothing
  1815. */
  1816. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  1817. if (stat)
  1818. return;
  1819. /**
  1820. * Enqueue command to firmware.
  1821. */
  1822. cmd = list_first_entry(&mod->cmd_q, struct bfa_mbox_cmd, qe);
  1823. list_del(&cmd->qe);
  1824. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1825. /**
  1826. * Give a callback to the client, indicating that the command is sent
  1827. */
  1828. if (cmd->cbfn) {
  1829. cbfn = cmd->cbfn;
  1830. cbarg = cmd->cbarg;
  1831. cmd->cbfn = NULL;
  1832. cbfn(cbarg);
  1833. }
  1834. }
  1835. /* Cleanup any pending requests. */
  1836. static void
  1837. bfa_ioc_mbox_flush(struct bfa_ioc *ioc)
  1838. {
  1839. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  1840. struct bfa_mbox_cmd *cmd;
  1841. while (!list_empty(&mod->cmd_q)) {
  1842. cmd = list_first_entry(&mod->cmd_q, struct bfa_mbox_cmd, qe);
  1843. list_del(&cmd->qe);
  1844. }
  1845. }
  1846. /**
  1847. * bfa_nw_ioc_smem_read - Read data from SMEM to host through PCI memmap
  1848. *
  1849. * @ioc: memory for IOC
  1850. * @tbuf: app memory to store data from smem
  1851. * @soff: smem offset
  1852. * @sz: size of smem in bytes
  1853. */
  1854. static int
  1855. bfa_nw_ioc_smem_read(struct bfa_ioc *ioc, void *tbuf, u32 soff, u32 sz)
  1856. {
  1857. u32 pgnum, loff, r32;
  1858. int i, len;
  1859. u32 *buf = tbuf;
  1860. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
  1861. loff = PSS_SMEM_PGOFF(soff);
  1862. /*
  1863. * Hold semaphore to serialize pll init and fwtrc.
  1864. */
  1865. if (!bfa_nw_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg))
  1866. return 1;
  1867. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1868. len = sz/sizeof(u32);
  1869. for (i = 0; i < len; i++) {
  1870. r32 = swab32(readl(loff + ioc->ioc_regs.smem_page_start));
  1871. buf[i] = be32_to_cpu(r32);
  1872. loff += sizeof(u32);
  1873. /**
  1874. * handle page offset wrap around
  1875. */
  1876. loff = PSS_SMEM_PGOFF(loff);
  1877. if (loff == 0) {
  1878. pgnum++;
  1879. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1880. }
  1881. }
  1882. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1883. ioc->ioc_regs.host_page_num_fn);
  1884. /*
  1885. * release semaphore
  1886. */
  1887. readl(ioc->ioc_regs.ioc_init_sem_reg);
  1888. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1889. return 0;
  1890. }
  1891. /* Retrieve saved firmware trace from a prior IOC failure. */
  1892. int
  1893. bfa_nw_ioc_debug_fwtrc(struct bfa_ioc *ioc, void *trcdata, int *trclen)
  1894. {
  1895. u32 loff = BFI_IOC_TRC_OFF + BNA_DBG_FWTRC_LEN * ioc->port_id;
  1896. int tlen, status = 0;
  1897. tlen = *trclen;
  1898. if (tlen > BNA_DBG_FWTRC_LEN)
  1899. tlen = BNA_DBG_FWTRC_LEN;
  1900. status = bfa_nw_ioc_smem_read(ioc, trcdata, loff, tlen);
  1901. *trclen = tlen;
  1902. return status;
  1903. }
  1904. /* Save firmware trace if configured. */
  1905. static void
  1906. bfa_nw_ioc_debug_save_ftrc(struct bfa_ioc *ioc)
  1907. {
  1908. int tlen;
  1909. if (ioc->dbg_fwsave_once) {
  1910. ioc->dbg_fwsave_once = false;
  1911. if (ioc->dbg_fwsave_len) {
  1912. tlen = ioc->dbg_fwsave_len;
  1913. bfa_nw_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
  1914. }
  1915. }
  1916. }
  1917. /* Retrieve saved firmware trace from a prior IOC failure. */
  1918. int
  1919. bfa_nw_ioc_debug_fwsave(struct bfa_ioc *ioc, void *trcdata, int *trclen)
  1920. {
  1921. int tlen;
  1922. if (ioc->dbg_fwsave_len == 0)
  1923. return BFA_STATUS_ENOFSAVE;
  1924. tlen = *trclen;
  1925. if (tlen > ioc->dbg_fwsave_len)
  1926. tlen = ioc->dbg_fwsave_len;
  1927. memcpy(trcdata, ioc->dbg_fwsave, tlen);
  1928. *trclen = tlen;
  1929. return BFA_STATUS_OK;
  1930. }
  1931. static void
  1932. bfa_ioc_fail_notify(struct bfa_ioc *ioc)
  1933. {
  1934. /**
  1935. * Notify driver and common modules registered for notification.
  1936. */
  1937. ioc->cbfn->hbfail_cbfn(ioc->bfa);
  1938. bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
  1939. bfa_nw_ioc_debug_save_ftrc(ioc);
  1940. }
  1941. /* IOCPF to IOC interface */
  1942. static void
  1943. bfa_ioc_pf_enabled(struct bfa_ioc *ioc)
  1944. {
  1945. bfa_fsm_send_event(ioc, IOC_E_ENABLED);
  1946. }
  1947. static void
  1948. bfa_ioc_pf_disabled(struct bfa_ioc *ioc)
  1949. {
  1950. bfa_fsm_send_event(ioc, IOC_E_DISABLED);
  1951. }
  1952. static void
  1953. bfa_ioc_pf_failed(struct bfa_ioc *ioc)
  1954. {
  1955. bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
  1956. }
  1957. static void
  1958. bfa_ioc_pf_hwfailed(struct bfa_ioc *ioc)
  1959. {
  1960. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  1961. }
  1962. static void
  1963. bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc)
  1964. {
  1965. /**
  1966. * Provide enable completion callback and AEN notification.
  1967. */
  1968. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  1969. }
  1970. /* IOC public */
  1971. static enum bfa_status
  1972. bfa_ioc_pll_init(struct bfa_ioc *ioc)
  1973. {
  1974. /*
  1975. * Hold semaphore so that nobody can access the chip during init.
  1976. */
  1977. bfa_nw_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
  1978. bfa_ioc_pll_init_asic(ioc);
  1979. ioc->pllinit = true;
  1980. /* Initialize LMEM */
  1981. bfa_ioc_lmem_init(ioc);
  1982. /*
  1983. * release semaphore.
  1984. */
  1985. bfa_nw_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
  1986. return BFA_STATUS_OK;
  1987. }
  1988. /* Interface used by diag module to do firmware boot with memory test
  1989. * as the entry vector.
  1990. */
  1991. static enum bfa_status
  1992. bfa_ioc_boot(struct bfa_ioc *ioc, enum bfi_fwboot_type boot_type,
  1993. u32 boot_env)
  1994. {
  1995. struct bfi_ioc_image_hdr *drv_fwhdr;
  1996. enum bfa_status status;
  1997. bfa_ioc_stats(ioc, ioc_boots);
  1998. if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
  1999. return BFA_STATUS_FAILED;
  2000. if (boot_env == BFI_FWBOOT_ENV_OS &&
  2001. boot_type == BFI_FWBOOT_TYPE_NORMAL) {
  2002. drv_fwhdr = (struct bfi_ioc_image_hdr *)
  2003. bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
  2004. /* Work with Flash iff flash f/w is better than driver f/w.
  2005. * Otherwise push drivers firmware.
  2006. */
  2007. if (bfa_ioc_flash_fwver_cmp(ioc, drv_fwhdr) ==
  2008. BFI_IOC_IMG_VER_BETTER)
  2009. boot_type = BFI_FWBOOT_TYPE_FLASH;
  2010. }
  2011. /**
  2012. * Initialize IOC state of all functions on a chip reset.
  2013. */
  2014. if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) {
  2015. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_MEMTEST);
  2016. bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_MEMTEST);
  2017. } else {
  2018. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_INITING);
  2019. bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_INITING);
  2020. }
  2021. bfa_ioc_msgflush(ioc);
  2022. status = bfa_ioc_download_fw(ioc, boot_type, boot_env);
  2023. if (status == BFA_STATUS_OK)
  2024. bfa_ioc_lpu_start(ioc);
  2025. else
  2026. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
  2027. return status;
  2028. }
  2029. /* Enable/disable IOC failure auto recovery. */
  2030. void
  2031. bfa_nw_ioc_auto_recover(bool auto_recover)
  2032. {
  2033. bfa_nw_auto_recover = auto_recover;
  2034. }
  2035. static bool
  2036. bfa_ioc_msgget(struct bfa_ioc *ioc, void *mbmsg)
  2037. {
  2038. u32 *msgp = mbmsg;
  2039. u32 r32;
  2040. int i;
  2041. r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
  2042. if ((r32 & 1) == 0)
  2043. return false;
  2044. /**
  2045. * read the MBOX msg
  2046. */
  2047. for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
  2048. i++) {
  2049. r32 = readl(ioc->ioc_regs.lpu_mbox +
  2050. i * sizeof(u32));
  2051. msgp[i] = htonl(r32);
  2052. }
  2053. /**
  2054. * turn off mailbox interrupt by clearing mailbox status
  2055. */
  2056. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  2057. readl(ioc->ioc_regs.lpu_mbox_cmd);
  2058. return true;
  2059. }
  2060. static void
  2061. bfa_ioc_isr(struct bfa_ioc *ioc, struct bfi_mbmsg *m)
  2062. {
  2063. union bfi_ioc_i2h_msg_u *msg;
  2064. struct bfa_iocpf *iocpf = &ioc->iocpf;
  2065. msg = (union bfi_ioc_i2h_msg_u *) m;
  2066. bfa_ioc_stats(ioc, ioc_isrs);
  2067. switch (msg->mh.msg_id) {
  2068. case BFI_IOC_I2H_HBEAT:
  2069. break;
  2070. case BFI_IOC_I2H_ENABLE_REPLY:
  2071. bfa_ioc_enable_reply(ioc,
  2072. (enum bfa_mode)msg->fw_event.port_mode,
  2073. msg->fw_event.cap_bm);
  2074. break;
  2075. case BFI_IOC_I2H_DISABLE_REPLY:
  2076. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
  2077. break;
  2078. case BFI_IOC_I2H_GETATTR_REPLY:
  2079. bfa_ioc_getattr_reply(ioc);
  2080. break;
  2081. default:
  2082. BUG_ON(1);
  2083. }
  2084. }
  2085. /**
  2086. * bfa_nw_ioc_attach - IOC attach time initialization and setup.
  2087. *
  2088. * @ioc: memory for IOC
  2089. * @bfa: driver instance structure
  2090. */
  2091. void
  2092. bfa_nw_ioc_attach(struct bfa_ioc *ioc, void *bfa, struct bfa_ioc_cbfn *cbfn)
  2093. {
  2094. ioc->bfa = bfa;
  2095. ioc->cbfn = cbfn;
  2096. ioc->fcmode = false;
  2097. ioc->pllinit = false;
  2098. ioc->dbg_fwsave_once = true;
  2099. ioc->iocpf.ioc = ioc;
  2100. bfa_ioc_mbox_attach(ioc);
  2101. INIT_LIST_HEAD(&ioc->notify_q);
  2102. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  2103. bfa_fsm_send_event(ioc, IOC_E_RESET);
  2104. }
  2105. /* Driver detach time IOC cleanup. */
  2106. void
  2107. bfa_nw_ioc_detach(struct bfa_ioc *ioc)
  2108. {
  2109. bfa_fsm_send_event(ioc, IOC_E_DETACH);
  2110. /* Done with detach, empty the notify_q. */
  2111. INIT_LIST_HEAD(&ioc->notify_q);
  2112. }
  2113. /**
  2114. * bfa_nw_ioc_pci_init - Setup IOC PCI properties.
  2115. *
  2116. * @pcidev: PCI device information for this IOC
  2117. */
  2118. void
  2119. bfa_nw_ioc_pci_init(struct bfa_ioc *ioc, struct bfa_pcidev *pcidev,
  2120. enum bfi_pcifn_class clscode)
  2121. {
  2122. ioc->clscode = clscode;
  2123. ioc->pcidev = *pcidev;
  2124. /**
  2125. * Initialize IOC and device personality
  2126. */
  2127. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
  2128. ioc->asic_mode = BFI_ASIC_MODE_FC;
  2129. switch (pcidev->device_id) {
  2130. case PCI_DEVICE_ID_BROCADE_CT:
  2131. ioc->asic_gen = BFI_ASIC_GEN_CT;
  2132. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
  2133. ioc->asic_mode = BFI_ASIC_MODE_ETH;
  2134. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
  2135. ioc->ad_cap_bm = BFA_CM_CNA;
  2136. break;
  2137. case BFA_PCI_DEVICE_ID_CT2:
  2138. ioc->asic_gen = BFI_ASIC_GEN_CT2;
  2139. if (clscode == BFI_PCIFN_CLASS_FC &&
  2140. pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
  2141. ioc->asic_mode = BFI_ASIC_MODE_FC16;
  2142. ioc->fcmode = true;
  2143. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
  2144. ioc->ad_cap_bm = BFA_CM_HBA;
  2145. } else {
  2146. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
  2147. ioc->asic_mode = BFI_ASIC_MODE_ETH;
  2148. if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
  2149. ioc->port_mode =
  2150. ioc->port_mode_cfg = BFA_MODE_CNA;
  2151. ioc->ad_cap_bm = BFA_CM_CNA;
  2152. } else {
  2153. ioc->port_mode =
  2154. ioc->port_mode_cfg = BFA_MODE_NIC;
  2155. ioc->ad_cap_bm = BFA_CM_NIC;
  2156. }
  2157. }
  2158. break;
  2159. default:
  2160. BUG_ON(1);
  2161. }
  2162. /**
  2163. * Set asic specific interfaces.
  2164. */
  2165. if (ioc->asic_gen == BFI_ASIC_GEN_CT)
  2166. bfa_nw_ioc_set_ct_hwif(ioc);
  2167. else {
  2168. WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2);
  2169. bfa_nw_ioc_set_ct2_hwif(ioc);
  2170. bfa_nw_ioc_ct2_poweron(ioc);
  2171. }
  2172. bfa_ioc_map_port(ioc);
  2173. bfa_ioc_reg_init(ioc);
  2174. }
  2175. /**
  2176. * bfa_nw_ioc_mem_claim - Initialize IOC dma memory
  2177. *
  2178. * @dm_kva: kernel virtual address of IOC dma memory
  2179. * @dm_pa: physical address of IOC dma memory
  2180. */
  2181. void
  2182. bfa_nw_ioc_mem_claim(struct bfa_ioc *ioc, u8 *dm_kva, u64 dm_pa)
  2183. {
  2184. /**
  2185. * dma memory for firmware attribute
  2186. */
  2187. ioc->attr_dma.kva = dm_kva;
  2188. ioc->attr_dma.pa = dm_pa;
  2189. ioc->attr = (struct bfi_ioc_attr *) dm_kva;
  2190. }
  2191. /* Return size of dma memory required. */
  2192. u32
  2193. bfa_nw_ioc_meminfo(void)
  2194. {
  2195. return roundup(sizeof(struct bfi_ioc_attr), BFA_DMA_ALIGN_SZ);
  2196. }
  2197. void
  2198. bfa_nw_ioc_enable(struct bfa_ioc *ioc)
  2199. {
  2200. bfa_ioc_stats(ioc, ioc_enables);
  2201. ioc->dbg_fwsave_once = true;
  2202. bfa_fsm_send_event(ioc, IOC_E_ENABLE);
  2203. }
  2204. void
  2205. bfa_nw_ioc_disable(struct bfa_ioc *ioc)
  2206. {
  2207. bfa_ioc_stats(ioc, ioc_disables);
  2208. bfa_fsm_send_event(ioc, IOC_E_DISABLE);
  2209. }
  2210. /* Initialize memory for saving firmware trace. */
  2211. void
  2212. bfa_nw_ioc_debug_memclaim(struct bfa_ioc *ioc, void *dbg_fwsave)
  2213. {
  2214. ioc->dbg_fwsave = dbg_fwsave;
  2215. ioc->dbg_fwsave_len = ioc->iocpf.auto_recover ? BNA_DBG_FWTRC_LEN : 0;
  2216. }
  2217. static u32
  2218. bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr)
  2219. {
  2220. return PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, fmaddr);
  2221. }
  2222. /* Register mailbox message handler function, to be called by common modules */
  2223. void
  2224. bfa_nw_ioc_mbox_regisr(struct bfa_ioc *ioc, enum bfi_mclass mc,
  2225. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
  2226. {
  2227. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  2228. mod->mbhdlr[mc].cbfn = cbfn;
  2229. mod->mbhdlr[mc].cbarg = cbarg;
  2230. }
  2231. /**
  2232. * bfa_nw_ioc_mbox_queue - Queue a mailbox command request to firmware.
  2233. *
  2234. * @ioc: IOC instance
  2235. * @cmd: Mailbox command
  2236. *
  2237. * Waits if mailbox is busy. Responsibility of caller to serialize
  2238. */
  2239. bool
  2240. bfa_nw_ioc_mbox_queue(struct bfa_ioc *ioc, struct bfa_mbox_cmd *cmd,
  2241. bfa_mbox_cmd_cbfn_t cbfn, void *cbarg)
  2242. {
  2243. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  2244. u32 stat;
  2245. cmd->cbfn = cbfn;
  2246. cmd->cbarg = cbarg;
  2247. /**
  2248. * If a previous command is pending, queue new command
  2249. */
  2250. if (!list_empty(&mod->cmd_q)) {
  2251. list_add_tail(&cmd->qe, &mod->cmd_q);
  2252. return true;
  2253. }
  2254. /**
  2255. * If mailbox is busy, queue command for poll timer
  2256. */
  2257. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  2258. if (stat) {
  2259. list_add_tail(&cmd->qe, &mod->cmd_q);
  2260. return true;
  2261. }
  2262. /**
  2263. * mailbox is free -- queue command to firmware
  2264. */
  2265. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  2266. return false;
  2267. }
  2268. /* Handle mailbox interrupts */
  2269. void
  2270. bfa_nw_ioc_mbox_isr(struct bfa_ioc *ioc)
  2271. {
  2272. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  2273. struct bfi_mbmsg m;
  2274. int mc;
  2275. if (bfa_ioc_msgget(ioc, &m)) {
  2276. /**
  2277. * Treat IOC message class as special.
  2278. */
  2279. mc = m.mh.msg_class;
  2280. if (mc == BFI_MC_IOC) {
  2281. bfa_ioc_isr(ioc, &m);
  2282. return;
  2283. }
  2284. if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
  2285. return;
  2286. mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
  2287. }
  2288. bfa_ioc_lpu_read_stat(ioc);
  2289. /**
  2290. * Try to send pending mailbox commands
  2291. */
  2292. bfa_ioc_mbox_poll(ioc);
  2293. }
  2294. void
  2295. bfa_nw_ioc_error_isr(struct bfa_ioc *ioc)
  2296. {
  2297. bfa_ioc_stats(ioc, ioc_hbfails);
  2298. bfa_ioc_stats_hb_count(ioc, ioc->hb_count);
  2299. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  2300. }
  2301. /* return true if IOC is disabled */
  2302. bool
  2303. bfa_nw_ioc_is_disabled(struct bfa_ioc *ioc)
  2304. {
  2305. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
  2306. bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
  2307. }
  2308. /* return true if IOC is operational */
  2309. bool
  2310. bfa_nw_ioc_is_operational(struct bfa_ioc *ioc)
  2311. {
  2312. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
  2313. }
  2314. /* Add to IOC heartbeat failure notification queue. To be used by common
  2315. * modules such as cee, port, diag.
  2316. */
  2317. void
  2318. bfa_nw_ioc_notify_register(struct bfa_ioc *ioc,
  2319. struct bfa_ioc_notify *notify)
  2320. {
  2321. list_add_tail(&notify->qe, &ioc->notify_q);
  2322. }
  2323. #define BFA_MFG_NAME "QLogic"
  2324. static void
  2325. bfa_ioc_get_adapter_attr(struct bfa_ioc *ioc,
  2326. struct bfa_adapter_attr *ad_attr)
  2327. {
  2328. struct bfi_ioc_attr *ioc_attr;
  2329. ioc_attr = ioc->attr;
  2330. bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
  2331. bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
  2332. bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
  2333. bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
  2334. memcpy(&ad_attr->vpd, &ioc_attr->vpd,
  2335. sizeof(struct bfa_mfg_vpd));
  2336. ad_attr->nports = bfa_ioc_get_nports(ioc);
  2337. ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
  2338. bfa_ioc_get_adapter_model(ioc, ad_attr->model);
  2339. /* For now, model descr uses same model string */
  2340. bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
  2341. ad_attr->card_type = ioc_attr->card_type;
  2342. ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
  2343. if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
  2344. ad_attr->prototype = 1;
  2345. else
  2346. ad_attr->prototype = 0;
  2347. ad_attr->pwwn = bfa_ioc_get_pwwn(ioc);
  2348. bfa_nw_ioc_get_mac(ioc, ad_attr->mac);
  2349. ad_attr->pcie_gen = ioc_attr->pcie_gen;
  2350. ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
  2351. ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
  2352. ad_attr->asic_rev = ioc_attr->asic_rev;
  2353. bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
  2354. }
  2355. static enum bfa_ioc_type
  2356. bfa_ioc_get_type(struct bfa_ioc *ioc)
  2357. {
  2358. if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
  2359. return BFA_IOC_TYPE_LL;
  2360. BUG_ON(!(ioc->clscode == BFI_PCIFN_CLASS_FC));
  2361. return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
  2362. ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
  2363. }
  2364. static void
  2365. bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc, char *serial_num)
  2366. {
  2367. memcpy(serial_num,
  2368. (void *)ioc->attr->brcd_serialnum,
  2369. BFA_ADAPTER_SERIAL_NUM_LEN);
  2370. }
  2371. static void
  2372. bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc, char *fw_ver)
  2373. {
  2374. memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
  2375. }
  2376. static void
  2377. bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc, char *chip_rev)
  2378. {
  2379. BUG_ON(!(chip_rev));
  2380. memset(chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
  2381. chip_rev[0] = 'R';
  2382. chip_rev[1] = 'e';
  2383. chip_rev[2] = 'v';
  2384. chip_rev[3] = '-';
  2385. chip_rev[4] = ioc->attr->asic_rev;
  2386. chip_rev[5] = '\0';
  2387. }
  2388. static void
  2389. bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc, char *optrom_ver)
  2390. {
  2391. memcpy(optrom_ver, ioc->attr->optrom_version,
  2392. BFA_VERSION_LEN);
  2393. }
  2394. static void
  2395. bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc, char *manufacturer)
  2396. {
  2397. strncpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
  2398. }
  2399. static void
  2400. bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model)
  2401. {
  2402. struct bfi_ioc_attr *ioc_attr;
  2403. BUG_ON(!(model));
  2404. memset(model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
  2405. ioc_attr = ioc->attr;
  2406. snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
  2407. BFA_MFG_NAME, ioc_attr->card_type);
  2408. }
  2409. static enum bfa_ioc_state
  2410. bfa_ioc_get_state(struct bfa_ioc *ioc)
  2411. {
  2412. enum bfa_iocpf_state iocpf_st;
  2413. enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
  2414. if (ioc_st == BFA_IOC_ENABLING ||
  2415. ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
  2416. iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
  2417. switch (iocpf_st) {
  2418. case BFA_IOCPF_SEMWAIT:
  2419. ioc_st = BFA_IOC_SEMWAIT;
  2420. break;
  2421. case BFA_IOCPF_HWINIT:
  2422. ioc_st = BFA_IOC_HWINIT;
  2423. break;
  2424. case BFA_IOCPF_FWMISMATCH:
  2425. ioc_st = BFA_IOC_FWMISMATCH;
  2426. break;
  2427. case BFA_IOCPF_FAIL:
  2428. ioc_st = BFA_IOC_FAIL;
  2429. break;
  2430. case BFA_IOCPF_INITFAIL:
  2431. ioc_st = BFA_IOC_INITFAIL;
  2432. break;
  2433. default:
  2434. break;
  2435. }
  2436. }
  2437. return ioc_st;
  2438. }
  2439. void
  2440. bfa_nw_ioc_get_attr(struct bfa_ioc *ioc, struct bfa_ioc_attr *ioc_attr)
  2441. {
  2442. memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr));
  2443. ioc_attr->state = bfa_ioc_get_state(ioc);
  2444. ioc_attr->port_id = bfa_ioc_portid(ioc);
  2445. ioc_attr->port_mode = ioc->port_mode;
  2446. ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
  2447. ioc_attr->cap_bm = ioc->ad_cap_bm;
  2448. ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
  2449. bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
  2450. ioc_attr->pci_attr.device_id = bfa_ioc_devid(ioc);
  2451. ioc_attr->pci_attr.pcifn = bfa_ioc_pcifn(ioc);
  2452. ioc_attr->def_fn = bfa_ioc_is_default(ioc);
  2453. bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
  2454. }
  2455. /* WWN public */
  2456. static u64
  2457. bfa_ioc_get_pwwn(struct bfa_ioc *ioc)
  2458. {
  2459. return ioc->attr->pwwn;
  2460. }
  2461. void
  2462. bfa_nw_ioc_get_mac(struct bfa_ioc *ioc, u8 *mac)
  2463. {
  2464. ether_addr_copy(mac, ioc->attr->mac);
  2465. }
  2466. /* Firmware failure detected. Start recovery actions. */
  2467. static void
  2468. bfa_ioc_recover(struct bfa_ioc *ioc)
  2469. {
  2470. pr_crit("Heart Beat of IOC has failed\n");
  2471. bfa_ioc_stats(ioc, ioc_hbfails);
  2472. bfa_ioc_stats_hb_count(ioc, ioc->hb_count);
  2473. bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
  2474. }
  2475. /* BFA IOC PF private functions */
  2476. static void
  2477. bfa_iocpf_enable(struct bfa_ioc *ioc)
  2478. {
  2479. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
  2480. }
  2481. static void
  2482. bfa_iocpf_disable(struct bfa_ioc *ioc)
  2483. {
  2484. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
  2485. }
  2486. static void
  2487. bfa_iocpf_fail(struct bfa_ioc *ioc)
  2488. {
  2489. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
  2490. }
  2491. static void
  2492. bfa_iocpf_initfail(struct bfa_ioc *ioc)
  2493. {
  2494. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
  2495. }
  2496. static void
  2497. bfa_iocpf_getattrfail(struct bfa_ioc *ioc)
  2498. {
  2499. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
  2500. }
  2501. static void
  2502. bfa_iocpf_stop(struct bfa_ioc *ioc)
  2503. {
  2504. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  2505. }
  2506. void
  2507. bfa_nw_iocpf_timeout(struct bfa_ioc *ioc)
  2508. {
  2509. enum bfa_iocpf_state iocpf_st;
  2510. iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
  2511. if (iocpf_st == BFA_IOCPF_HWINIT)
  2512. bfa_ioc_poll_fwinit(ioc);
  2513. else
  2514. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
  2515. }
  2516. void
  2517. bfa_nw_iocpf_sem_timeout(struct bfa_ioc *ioc)
  2518. {
  2519. bfa_ioc_hw_sem_get(ioc);
  2520. }
  2521. static void
  2522. bfa_ioc_poll_fwinit(struct bfa_ioc *ioc)
  2523. {
  2524. u32 fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
  2525. if (fwstate == BFI_IOC_DISABLED) {
  2526. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
  2527. return;
  2528. }
  2529. if (ioc->iocpf.poll_time >= BFA_IOC_TOV) {
  2530. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
  2531. } else {
  2532. ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
  2533. mod_timer(&ioc->iocpf_timer, jiffies +
  2534. msecs_to_jiffies(BFA_IOC_POLL_TOV));
  2535. }
  2536. }
  2537. /*
  2538. * Flash module specific
  2539. */
  2540. /*
  2541. * FLASH DMA buffer should be big enough to hold both MFG block and
  2542. * asic block(64k) at the same time and also should be 2k aligned to
  2543. * avoid write segement to cross sector boundary.
  2544. */
  2545. #define BFA_FLASH_SEG_SZ 2048
  2546. #define BFA_FLASH_DMA_BUF_SZ \
  2547. roundup(0x010000 + sizeof(struct bfa_mfg_block), BFA_FLASH_SEG_SZ)
  2548. static void
  2549. bfa_flash_cb(struct bfa_flash *flash)
  2550. {
  2551. flash->op_busy = 0;
  2552. if (flash->cbfn)
  2553. flash->cbfn(flash->cbarg, flash->status);
  2554. }
  2555. static void
  2556. bfa_flash_notify(void *cbarg, enum bfa_ioc_event event)
  2557. {
  2558. struct bfa_flash *flash = cbarg;
  2559. switch (event) {
  2560. case BFA_IOC_E_DISABLED:
  2561. case BFA_IOC_E_FAILED:
  2562. if (flash->op_busy) {
  2563. flash->status = BFA_STATUS_IOC_FAILURE;
  2564. flash->cbfn(flash->cbarg, flash->status);
  2565. flash->op_busy = 0;
  2566. }
  2567. break;
  2568. default:
  2569. break;
  2570. }
  2571. }
  2572. /*
  2573. * Send flash write request.
  2574. */
  2575. static void
  2576. bfa_flash_write_send(struct bfa_flash *flash)
  2577. {
  2578. struct bfi_flash_write_req *msg =
  2579. (struct bfi_flash_write_req *) flash->mb.msg;
  2580. u32 len;
  2581. msg->type = be32_to_cpu(flash->type);
  2582. msg->instance = flash->instance;
  2583. msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
  2584. len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
  2585. flash->residue : BFA_FLASH_DMA_BUF_SZ;
  2586. msg->length = be32_to_cpu(len);
  2587. /* indicate if it's the last msg of the whole write operation */
  2588. msg->last = (len == flash->residue) ? 1 : 0;
  2589. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_WRITE_REQ,
  2590. bfa_ioc_portid(flash->ioc));
  2591. bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
  2592. memcpy(flash->dbuf_kva, flash->ubuf + flash->offset, len);
  2593. bfa_nw_ioc_mbox_queue(flash->ioc, &flash->mb, NULL, NULL);
  2594. flash->residue -= len;
  2595. flash->offset += len;
  2596. }
  2597. /**
  2598. * bfa_flash_read_send - Send flash read request.
  2599. *
  2600. * @cbarg: callback argument
  2601. */
  2602. static void
  2603. bfa_flash_read_send(void *cbarg)
  2604. {
  2605. struct bfa_flash *flash = cbarg;
  2606. struct bfi_flash_read_req *msg =
  2607. (struct bfi_flash_read_req *) flash->mb.msg;
  2608. u32 len;
  2609. msg->type = be32_to_cpu(flash->type);
  2610. msg->instance = flash->instance;
  2611. msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
  2612. len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
  2613. flash->residue : BFA_FLASH_DMA_BUF_SZ;
  2614. msg->length = be32_to_cpu(len);
  2615. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_READ_REQ,
  2616. bfa_ioc_portid(flash->ioc));
  2617. bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
  2618. bfa_nw_ioc_mbox_queue(flash->ioc, &flash->mb, NULL, NULL);
  2619. }
  2620. /**
  2621. * bfa_flash_intr - Process flash response messages upon receiving interrupts.
  2622. *
  2623. * @flasharg: flash structure
  2624. * @msg: message structure
  2625. */
  2626. static void
  2627. bfa_flash_intr(void *flasharg, struct bfi_mbmsg *msg)
  2628. {
  2629. struct bfa_flash *flash = flasharg;
  2630. u32 status;
  2631. union {
  2632. struct bfi_flash_query_rsp *query;
  2633. struct bfi_flash_write_rsp *write;
  2634. struct bfi_flash_read_rsp *read;
  2635. struct bfi_mbmsg *msg;
  2636. } m;
  2637. m.msg = msg;
  2638. /* receiving response after ioc failure */
  2639. if (!flash->op_busy && msg->mh.msg_id != BFI_FLASH_I2H_EVENT)
  2640. return;
  2641. switch (msg->mh.msg_id) {
  2642. case BFI_FLASH_I2H_QUERY_RSP:
  2643. status = be32_to_cpu(m.query->status);
  2644. if (status == BFA_STATUS_OK) {
  2645. u32 i;
  2646. struct bfa_flash_attr *attr, *f;
  2647. attr = (struct bfa_flash_attr *) flash->ubuf;
  2648. f = (struct bfa_flash_attr *) flash->dbuf_kva;
  2649. attr->status = be32_to_cpu(f->status);
  2650. attr->npart = be32_to_cpu(f->npart);
  2651. for (i = 0; i < attr->npart; i++) {
  2652. attr->part[i].part_type =
  2653. be32_to_cpu(f->part[i].part_type);
  2654. attr->part[i].part_instance =
  2655. be32_to_cpu(f->part[i].part_instance);
  2656. attr->part[i].part_off =
  2657. be32_to_cpu(f->part[i].part_off);
  2658. attr->part[i].part_size =
  2659. be32_to_cpu(f->part[i].part_size);
  2660. attr->part[i].part_len =
  2661. be32_to_cpu(f->part[i].part_len);
  2662. attr->part[i].part_status =
  2663. be32_to_cpu(f->part[i].part_status);
  2664. }
  2665. }
  2666. flash->status = status;
  2667. bfa_flash_cb(flash);
  2668. break;
  2669. case BFI_FLASH_I2H_WRITE_RSP:
  2670. status = be32_to_cpu(m.write->status);
  2671. if (status != BFA_STATUS_OK || flash->residue == 0) {
  2672. flash->status = status;
  2673. bfa_flash_cb(flash);
  2674. } else
  2675. bfa_flash_write_send(flash);
  2676. break;
  2677. case BFI_FLASH_I2H_READ_RSP:
  2678. status = be32_to_cpu(m.read->status);
  2679. if (status != BFA_STATUS_OK) {
  2680. flash->status = status;
  2681. bfa_flash_cb(flash);
  2682. } else {
  2683. u32 len = be32_to_cpu(m.read->length);
  2684. memcpy(flash->ubuf + flash->offset,
  2685. flash->dbuf_kva, len);
  2686. flash->residue -= len;
  2687. flash->offset += len;
  2688. if (flash->residue == 0) {
  2689. flash->status = status;
  2690. bfa_flash_cb(flash);
  2691. } else
  2692. bfa_flash_read_send(flash);
  2693. }
  2694. break;
  2695. case BFI_FLASH_I2H_BOOT_VER_RSP:
  2696. case BFI_FLASH_I2H_EVENT:
  2697. break;
  2698. default:
  2699. WARN_ON(1);
  2700. }
  2701. }
  2702. /*
  2703. * Flash memory info API.
  2704. */
  2705. u32
  2706. bfa_nw_flash_meminfo(void)
  2707. {
  2708. return roundup(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  2709. }
  2710. /**
  2711. * bfa_nw_flash_attach - Flash attach API.
  2712. *
  2713. * @flash: flash structure
  2714. * @ioc: ioc structure
  2715. * @dev: device structure
  2716. */
  2717. void
  2718. bfa_nw_flash_attach(struct bfa_flash *flash, struct bfa_ioc *ioc, void *dev)
  2719. {
  2720. flash->ioc = ioc;
  2721. flash->cbfn = NULL;
  2722. flash->cbarg = NULL;
  2723. flash->op_busy = 0;
  2724. bfa_nw_ioc_mbox_regisr(flash->ioc, BFI_MC_FLASH, bfa_flash_intr, flash);
  2725. bfa_ioc_notify_init(&flash->ioc_notify, bfa_flash_notify, flash);
  2726. list_add_tail(&flash->ioc_notify.qe, &flash->ioc->notify_q);
  2727. }
  2728. /**
  2729. * bfa_nw_flash_memclaim - Claim memory for flash
  2730. *
  2731. * @flash: flash structure
  2732. * @dm_kva: pointer to virtual memory address
  2733. * @dm_pa: physical memory address
  2734. */
  2735. void
  2736. bfa_nw_flash_memclaim(struct bfa_flash *flash, u8 *dm_kva, u64 dm_pa)
  2737. {
  2738. flash->dbuf_kva = dm_kva;
  2739. flash->dbuf_pa = dm_pa;
  2740. memset(flash->dbuf_kva, 0, BFA_FLASH_DMA_BUF_SZ);
  2741. dm_kva += roundup(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  2742. dm_pa += roundup(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  2743. }
  2744. /**
  2745. * bfa_nw_flash_get_attr - Get flash attribute.
  2746. *
  2747. * @flash: flash structure
  2748. * @attr: flash attribute structure
  2749. * @cbfn: callback function
  2750. * @cbarg: callback argument
  2751. *
  2752. * Return status.
  2753. */
  2754. enum bfa_status
  2755. bfa_nw_flash_get_attr(struct bfa_flash *flash, struct bfa_flash_attr *attr,
  2756. bfa_cb_flash cbfn, void *cbarg)
  2757. {
  2758. struct bfi_flash_query_req *msg =
  2759. (struct bfi_flash_query_req *) flash->mb.msg;
  2760. if (!bfa_nw_ioc_is_operational(flash->ioc))
  2761. return BFA_STATUS_IOC_NON_OP;
  2762. if (flash->op_busy)
  2763. return BFA_STATUS_DEVBUSY;
  2764. flash->op_busy = 1;
  2765. flash->cbfn = cbfn;
  2766. flash->cbarg = cbarg;
  2767. flash->ubuf = (u8 *) attr;
  2768. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_QUERY_REQ,
  2769. bfa_ioc_portid(flash->ioc));
  2770. bfa_alen_set(&msg->alen, sizeof(struct bfa_flash_attr), flash->dbuf_pa);
  2771. bfa_nw_ioc_mbox_queue(flash->ioc, &flash->mb, NULL, NULL);
  2772. return BFA_STATUS_OK;
  2773. }
  2774. /**
  2775. * bfa_nw_flash_update_part - Update flash partition.
  2776. *
  2777. * @flash: flash structure
  2778. * @type: flash partition type
  2779. * @instance: flash partition instance
  2780. * @buf: update data buffer
  2781. * @len: data buffer length
  2782. * @offset: offset relative to the partition starting address
  2783. * @cbfn: callback function
  2784. * @cbarg: callback argument
  2785. *
  2786. * Return status.
  2787. */
  2788. enum bfa_status
  2789. bfa_nw_flash_update_part(struct bfa_flash *flash, u32 type, u8 instance,
  2790. void *buf, u32 len, u32 offset,
  2791. bfa_cb_flash cbfn, void *cbarg)
  2792. {
  2793. if (!bfa_nw_ioc_is_operational(flash->ioc))
  2794. return BFA_STATUS_IOC_NON_OP;
  2795. /*
  2796. * 'len' must be in word (4-byte) boundary
  2797. */
  2798. if (!len || (len & 0x03))
  2799. return BFA_STATUS_FLASH_BAD_LEN;
  2800. if (type == BFA_FLASH_PART_MFG)
  2801. return BFA_STATUS_EINVAL;
  2802. if (flash->op_busy)
  2803. return BFA_STATUS_DEVBUSY;
  2804. flash->op_busy = 1;
  2805. flash->cbfn = cbfn;
  2806. flash->cbarg = cbarg;
  2807. flash->type = type;
  2808. flash->instance = instance;
  2809. flash->residue = len;
  2810. flash->offset = 0;
  2811. flash->addr_off = offset;
  2812. flash->ubuf = buf;
  2813. bfa_flash_write_send(flash);
  2814. return BFA_STATUS_OK;
  2815. }
  2816. /**
  2817. * bfa_nw_flash_read_part - Read flash partition.
  2818. *
  2819. * @flash: flash structure
  2820. * @type: flash partition type
  2821. * @instance: flash partition instance
  2822. * @buf: read data buffer
  2823. * @len: data buffer length
  2824. * @offset: offset relative to the partition starting address
  2825. * @cbfn: callback function
  2826. * @cbarg: callback argument
  2827. *
  2828. * Return status.
  2829. */
  2830. enum bfa_status
  2831. bfa_nw_flash_read_part(struct bfa_flash *flash, u32 type, u8 instance,
  2832. void *buf, u32 len, u32 offset,
  2833. bfa_cb_flash cbfn, void *cbarg)
  2834. {
  2835. if (!bfa_nw_ioc_is_operational(flash->ioc))
  2836. return BFA_STATUS_IOC_NON_OP;
  2837. /*
  2838. * 'len' must be in word (4-byte) boundary
  2839. */
  2840. if (!len || (len & 0x03))
  2841. return BFA_STATUS_FLASH_BAD_LEN;
  2842. if (flash->op_busy)
  2843. return BFA_STATUS_DEVBUSY;
  2844. flash->op_busy = 1;
  2845. flash->cbfn = cbfn;
  2846. flash->cbarg = cbarg;
  2847. flash->type = type;
  2848. flash->instance = instance;
  2849. flash->residue = len;
  2850. flash->offset = 0;
  2851. flash->addr_off = offset;
  2852. flash->ubuf = buf;
  2853. bfa_flash_read_send(flash);
  2854. return BFA_STATUS_OK;
  2855. }