bfa_ioc.c 65 KB

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