bfa_ioc.c 49 KB

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