bfa_ioc.c 54 KB

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