bfa_ioc.c 65 KB

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