bfa_ioc.c 49 KB

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