bfa_ioc.c 65 KB

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