bfa_ioc.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include <bfa.h>
  18. #include <bfa_ioc.h>
  19. #include <bfa_fwimg_priv.h>
  20. #include <cna/bfa_cna_trcmod.h>
  21. #include <cs/bfa_debug.h>
  22. #include <bfi/bfi_ioc.h>
  23. #include <bfi/bfi_ctreg.h>
  24. #include <aen/bfa_aen_ioc.h>
  25. #include <aen/bfa_aen.h>
  26. #include <log/bfa_log_hal.h>
  27. #include <defs/bfa_defs_pci.h>
  28. BFA_TRC_FILE(CNA, IOC);
  29. /**
  30. * IOC local definitions
  31. */
  32. #define BFA_IOC_TOV 2000 /* msecs */
  33. #define BFA_IOC_HWSEM_TOV 500 /* msecs */
  34. #define BFA_IOC_HB_TOV 500 /* msecs */
  35. #define BFA_IOC_HWINIT_MAX 2
  36. #define BFA_IOC_FWIMG_MINSZ (16 * 1024)
  37. #define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
  38. #define bfa_ioc_timer_start(__ioc) \
  39. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
  40. bfa_ioc_timeout, (__ioc), BFA_IOC_TOV)
  41. #define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
  42. #define BFA_DBG_FWTRC_ENTS (BFI_IOC_TRC_ENTS)
  43. #define BFA_DBG_FWTRC_LEN \
  44. (BFA_DBG_FWTRC_ENTS * sizeof(struct bfa_trc_s) + \
  45. (sizeof(struct bfa_trc_mod_s) - \
  46. BFA_TRC_MAX * sizeof(struct bfa_trc_s)))
  47. #define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
  48. /**
  49. * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
  50. */
  51. #define bfa_ioc_firmware_lock(__ioc) \
  52. ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
  53. #define bfa_ioc_firmware_unlock(__ioc) \
  54. ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
  55. #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
  56. #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
  57. #define bfa_ioc_notify_hbfail(__ioc) \
  58. ((__ioc)->ioc_hwif->ioc_notify_hbfail(__ioc))
  59. #define bfa_ioc_is_optrom(__ioc) \
  60. (bfi_image_get_size(BFA_IOC_FWIMG_TYPE(__ioc)) < BFA_IOC_FWIMG_MINSZ)
  61. bfa_boolean_t bfa_auto_recover = BFA_TRUE;
  62. /*
  63. * forward declarations
  64. */
  65. static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
  66. static void bfa_ioc_hw_sem_get_cancel(struct bfa_ioc_s *ioc);
  67. static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
  68. static void bfa_ioc_timeout(void *ioc);
  69. static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
  70. static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
  71. static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
  72. static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
  73. static void bfa_ioc_hb_stop(struct bfa_ioc_s *ioc);
  74. static void bfa_ioc_reset(struct bfa_ioc_s *ioc, bfa_boolean_t force);
  75. static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
  76. static void bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc);
  77. static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
  78. static void bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc);
  79. static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
  80. static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
  81. /**
  82. * bfa_ioc_sm
  83. */
  84. /**
  85. * IOC state machine events
  86. */
  87. enum ioc_event {
  88. IOC_E_ENABLE = 1, /* IOC enable request */
  89. IOC_E_DISABLE = 2, /* IOC disable request */
  90. IOC_E_TIMEOUT = 3, /* f/w response timeout */
  91. IOC_E_FWREADY = 4, /* f/w initialization done */
  92. IOC_E_FWRSP_GETATTR = 5, /* IOC get attribute response */
  93. IOC_E_FWRSP_ENABLE = 6, /* enable f/w response */
  94. IOC_E_FWRSP_DISABLE = 7, /* disable f/w response */
  95. IOC_E_HBFAIL = 8, /* heartbeat failure */
  96. IOC_E_HWERROR = 9, /* hardware error interrupt */
  97. IOC_E_SEMLOCKED = 10, /* h/w semaphore is locked */
  98. IOC_E_DETACH = 11, /* driver detach cleanup */
  99. };
  100. bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
  101. bfa_fsm_state_decl(bfa_ioc, fwcheck, struct bfa_ioc_s, enum ioc_event);
  102. bfa_fsm_state_decl(bfa_ioc, mismatch, struct bfa_ioc_s, enum ioc_event);
  103. bfa_fsm_state_decl(bfa_ioc, semwait, struct bfa_ioc_s, enum ioc_event);
  104. bfa_fsm_state_decl(bfa_ioc, hwinit, struct bfa_ioc_s, enum ioc_event);
  105. bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
  106. bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
  107. bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
  108. bfa_fsm_state_decl(bfa_ioc, initfail, struct bfa_ioc_s, enum ioc_event);
  109. bfa_fsm_state_decl(bfa_ioc, hbfail, struct bfa_ioc_s, enum ioc_event);
  110. bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
  111. bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
  112. static struct bfa_sm_table_s ioc_sm_table[] = {
  113. {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
  114. {BFA_SM(bfa_ioc_sm_fwcheck), BFA_IOC_FWMISMATCH},
  115. {BFA_SM(bfa_ioc_sm_mismatch), BFA_IOC_FWMISMATCH},
  116. {BFA_SM(bfa_ioc_sm_semwait), BFA_IOC_SEMWAIT},
  117. {BFA_SM(bfa_ioc_sm_hwinit), BFA_IOC_HWINIT},
  118. {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_HWINIT},
  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_initfail), BFA_IOC_INITFAIL},
  122. {BFA_SM(bfa_ioc_sm_hbfail), BFA_IOC_HBFAIL},
  123. {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
  124. {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
  125. };
  126. /**
  127. * Reset entry actions -- initialize state machine
  128. */
  129. static void
  130. bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
  131. {
  132. ioc->retry_count = 0;
  133. ioc->auto_recover = bfa_auto_recover;
  134. }
  135. /**
  136. * Beginning state. IOC is in reset state.
  137. */
  138. static void
  139. bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
  140. {
  141. bfa_trc(ioc, event);
  142. switch (event) {
  143. case IOC_E_ENABLE:
  144. bfa_fsm_set_state(ioc, bfa_ioc_sm_fwcheck);
  145. break;
  146. case IOC_E_DISABLE:
  147. bfa_ioc_disable_comp(ioc);
  148. break;
  149. case IOC_E_DETACH:
  150. break;
  151. default:
  152. bfa_sm_fault(ioc, event);
  153. }
  154. }
  155. /**
  156. * Semaphore should be acquired for version check.
  157. */
  158. static void
  159. bfa_ioc_sm_fwcheck_entry(struct bfa_ioc_s *ioc)
  160. {
  161. bfa_ioc_hw_sem_get(ioc);
  162. }
  163. /**
  164. * Awaiting h/w semaphore to continue with version check.
  165. */
  166. static void
  167. bfa_ioc_sm_fwcheck(struct bfa_ioc_s *ioc, enum ioc_event event)
  168. {
  169. bfa_trc(ioc, event);
  170. switch (event) {
  171. case IOC_E_SEMLOCKED:
  172. if (bfa_ioc_firmware_lock(ioc)) {
  173. ioc->retry_count = 0;
  174. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwinit);
  175. } else {
  176. bfa_ioc_hw_sem_release(ioc);
  177. bfa_fsm_set_state(ioc, bfa_ioc_sm_mismatch);
  178. }
  179. break;
  180. case IOC_E_DISABLE:
  181. bfa_ioc_disable_comp(ioc);
  182. /*
  183. * fall through
  184. */
  185. case IOC_E_DETACH:
  186. bfa_ioc_hw_sem_get_cancel(ioc);
  187. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  188. break;
  189. case IOC_E_FWREADY:
  190. break;
  191. default:
  192. bfa_sm_fault(ioc, event);
  193. }
  194. }
  195. /**
  196. * Notify enable completion callback and generate mismatch AEN.
  197. */
  198. static void
  199. bfa_ioc_sm_mismatch_entry(struct bfa_ioc_s *ioc)
  200. {
  201. /**
  202. * Provide enable completion callback and AEN notification only once.
  203. */
  204. if (ioc->retry_count == 0) {
  205. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  206. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_FWMISMATCH);
  207. }
  208. ioc->retry_count++;
  209. bfa_ioc_timer_start(ioc);
  210. }
  211. /**
  212. * Awaiting firmware version match.
  213. */
  214. static void
  215. bfa_ioc_sm_mismatch(struct bfa_ioc_s *ioc, enum ioc_event event)
  216. {
  217. bfa_trc(ioc, event);
  218. switch (event) {
  219. case IOC_E_TIMEOUT:
  220. bfa_fsm_set_state(ioc, bfa_ioc_sm_fwcheck);
  221. break;
  222. case IOC_E_DISABLE:
  223. bfa_ioc_disable_comp(ioc);
  224. /*
  225. * fall through
  226. */
  227. case IOC_E_DETACH:
  228. bfa_ioc_timer_stop(ioc);
  229. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  230. break;
  231. case IOC_E_FWREADY:
  232. break;
  233. default:
  234. bfa_sm_fault(ioc, event);
  235. }
  236. }
  237. /**
  238. * Request for semaphore.
  239. */
  240. static void
  241. bfa_ioc_sm_semwait_entry(struct bfa_ioc_s *ioc)
  242. {
  243. bfa_ioc_hw_sem_get(ioc);
  244. }
  245. /**
  246. * Awaiting semaphore for h/w initialzation.
  247. */
  248. static void
  249. bfa_ioc_sm_semwait(struct bfa_ioc_s *ioc, enum ioc_event event)
  250. {
  251. bfa_trc(ioc, event);
  252. switch (event) {
  253. case IOC_E_SEMLOCKED:
  254. ioc->retry_count = 0;
  255. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwinit);
  256. break;
  257. case IOC_E_DISABLE:
  258. bfa_ioc_hw_sem_get_cancel(ioc);
  259. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  260. break;
  261. default:
  262. bfa_sm_fault(ioc, event);
  263. }
  264. }
  265. static void
  266. bfa_ioc_sm_hwinit_entry(struct bfa_ioc_s *ioc)
  267. {
  268. bfa_ioc_timer_start(ioc);
  269. bfa_ioc_reset(ioc, BFA_FALSE);
  270. }
  271. /**
  272. * Hardware is being initialized. Interrupts are enabled.
  273. * Holding hardware semaphore lock.
  274. */
  275. static void
  276. bfa_ioc_sm_hwinit(struct bfa_ioc_s *ioc, enum ioc_event event)
  277. {
  278. bfa_trc(ioc, event);
  279. switch (event) {
  280. case IOC_E_FWREADY:
  281. bfa_ioc_timer_stop(ioc);
  282. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  283. break;
  284. case IOC_E_HWERROR:
  285. bfa_ioc_timer_stop(ioc);
  286. /*
  287. * fall through
  288. */
  289. case IOC_E_TIMEOUT:
  290. ioc->retry_count++;
  291. if (ioc->retry_count < BFA_IOC_HWINIT_MAX) {
  292. bfa_ioc_timer_start(ioc);
  293. bfa_ioc_reset(ioc, BFA_TRUE);
  294. break;
  295. }
  296. bfa_ioc_hw_sem_release(ioc);
  297. bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
  298. break;
  299. case IOC_E_DISABLE:
  300. bfa_ioc_hw_sem_release(ioc);
  301. bfa_ioc_timer_stop(ioc);
  302. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  303. break;
  304. default:
  305. bfa_sm_fault(ioc, event);
  306. }
  307. }
  308. static void
  309. bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
  310. {
  311. bfa_ioc_timer_start(ioc);
  312. bfa_ioc_send_enable(ioc);
  313. }
  314. /**
  315. * Host IOC function is being enabled, awaiting response from firmware.
  316. * Semaphore is acquired.
  317. */
  318. static void
  319. bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
  320. {
  321. bfa_trc(ioc, event);
  322. switch (event) {
  323. case IOC_E_FWRSP_ENABLE:
  324. bfa_ioc_timer_stop(ioc);
  325. bfa_ioc_hw_sem_release(ioc);
  326. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  327. break;
  328. case IOC_E_HWERROR:
  329. bfa_ioc_timer_stop(ioc);
  330. /*
  331. * fall through
  332. */
  333. case IOC_E_TIMEOUT:
  334. ioc->retry_count++;
  335. if (ioc->retry_count < BFA_IOC_HWINIT_MAX) {
  336. bfa_reg_write(ioc->ioc_regs.ioc_fwstate,
  337. BFI_IOC_UNINIT);
  338. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwinit);
  339. break;
  340. }
  341. bfa_ioc_hw_sem_release(ioc);
  342. bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
  343. break;
  344. case IOC_E_DISABLE:
  345. bfa_ioc_timer_stop(ioc);
  346. bfa_ioc_hw_sem_release(ioc);
  347. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  348. break;
  349. case IOC_E_FWREADY:
  350. bfa_ioc_send_enable(ioc);
  351. break;
  352. default:
  353. bfa_sm_fault(ioc, event);
  354. }
  355. }
  356. static void
  357. bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
  358. {
  359. bfa_ioc_timer_start(ioc);
  360. bfa_ioc_send_getattr(ioc);
  361. }
  362. /**
  363. * IOC configuration in progress. Timer is active.
  364. */
  365. static void
  366. bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
  367. {
  368. bfa_trc(ioc, event);
  369. switch (event) {
  370. case IOC_E_FWRSP_GETATTR:
  371. bfa_ioc_timer_stop(ioc);
  372. bfa_ioc_check_attr_wwns(ioc);
  373. bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
  374. break;
  375. case IOC_E_HWERROR:
  376. bfa_ioc_timer_stop(ioc);
  377. /*
  378. * fall through
  379. */
  380. case IOC_E_TIMEOUT:
  381. bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
  382. break;
  383. case IOC_E_DISABLE:
  384. bfa_ioc_timer_stop(ioc);
  385. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  386. break;
  387. default:
  388. bfa_sm_fault(ioc, event);
  389. }
  390. }
  391. static void
  392. bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
  393. {
  394. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
  395. bfa_ioc_hb_monitor(ioc);
  396. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_ENABLE);
  397. }
  398. static void
  399. bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
  400. {
  401. bfa_trc(ioc, event);
  402. switch (event) {
  403. case IOC_E_ENABLE:
  404. break;
  405. case IOC_E_DISABLE:
  406. bfa_ioc_hb_stop(ioc);
  407. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  408. break;
  409. case IOC_E_HWERROR:
  410. case IOC_E_FWREADY:
  411. /**
  412. * Hard error or IOC recovery by other function.
  413. * Treat it same as heartbeat failure.
  414. */
  415. bfa_ioc_hb_stop(ioc);
  416. /*
  417. * !!! fall through !!!
  418. */
  419. case IOC_E_HBFAIL:
  420. bfa_fsm_set_state(ioc, bfa_ioc_sm_hbfail);
  421. break;
  422. default:
  423. bfa_sm_fault(ioc, event);
  424. }
  425. }
  426. static void
  427. bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
  428. {
  429. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_DISABLE);
  430. bfa_ioc_timer_start(ioc);
  431. bfa_ioc_send_disable(ioc);
  432. }
  433. /**
  434. * IOC is being disabled
  435. */
  436. static void
  437. bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
  438. {
  439. bfa_trc(ioc, event);
  440. switch (event) {
  441. case IOC_E_FWRSP_DISABLE:
  442. bfa_ioc_timer_stop(ioc);
  443. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  444. break;
  445. case IOC_E_HWERROR:
  446. bfa_ioc_timer_stop(ioc);
  447. /*
  448. * !!! fall through !!!
  449. */
  450. case IOC_E_TIMEOUT:
  451. bfa_reg_write(ioc->ioc_regs.ioc_fwstate, BFI_IOC_FAIL);
  452. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  453. break;
  454. default:
  455. bfa_sm_fault(ioc, event);
  456. }
  457. }
  458. /**
  459. * IOC disable completion entry.
  460. */
  461. static void
  462. bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
  463. {
  464. bfa_ioc_disable_comp(ioc);
  465. }
  466. static void
  467. bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
  468. {
  469. bfa_trc(ioc, event);
  470. switch (event) {
  471. case IOC_E_ENABLE:
  472. bfa_fsm_set_state(ioc, bfa_ioc_sm_semwait);
  473. break;
  474. case IOC_E_DISABLE:
  475. ioc->cbfn->disable_cbfn(ioc->bfa);
  476. break;
  477. case IOC_E_FWREADY:
  478. break;
  479. case IOC_E_DETACH:
  480. bfa_ioc_firmware_unlock(ioc);
  481. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  482. break;
  483. default:
  484. bfa_sm_fault(ioc, event);
  485. }
  486. }
  487. static void
  488. bfa_ioc_sm_initfail_entry(struct bfa_ioc_s *ioc)
  489. {
  490. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  491. bfa_ioc_timer_start(ioc);
  492. }
  493. /**
  494. * Hardware initialization failed.
  495. */
  496. static void
  497. bfa_ioc_sm_initfail(struct bfa_ioc_s *ioc, enum ioc_event event)
  498. {
  499. bfa_trc(ioc, event);
  500. switch (event) {
  501. case IOC_E_DISABLE:
  502. bfa_ioc_timer_stop(ioc);
  503. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  504. break;
  505. case IOC_E_DETACH:
  506. bfa_ioc_timer_stop(ioc);
  507. bfa_ioc_firmware_unlock(ioc);
  508. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  509. break;
  510. case IOC_E_TIMEOUT:
  511. bfa_fsm_set_state(ioc, bfa_ioc_sm_semwait);
  512. break;
  513. default:
  514. bfa_sm_fault(ioc, event);
  515. }
  516. }
  517. static void
  518. bfa_ioc_sm_hbfail_entry(struct bfa_ioc_s *ioc)
  519. {
  520. struct list_head *qe;
  521. struct bfa_ioc_hbfail_notify_s *notify;
  522. /**
  523. * Mark IOC as failed in hardware and stop firmware.
  524. */
  525. bfa_ioc_lpu_stop(ioc);
  526. bfa_reg_write(ioc->ioc_regs.ioc_fwstate, BFI_IOC_FAIL);
  527. /**
  528. * Notify other functions on HB failure.
  529. */
  530. bfa_ioc_notify_hbfail(ioc);
  531. /**
  532. * Notify driver and common modules registered for notification.
  533. */
  534. ioc->cbfn->hbfail_cbfn(ioc->bfa);
  535. list_for_each(qe, &ioc->hb_notify_q) {
  536. notify = (struct bfa_ioc_hbfail_notify_s *)qe;
  537. notify->cbfn(notify->cbarg);
  538. }
  539. /**
  540. * Flush any queued up mailbox requests.
  541. */
  542. bfa_ioc_mbox_hbfail(ioc);
  543. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_HBFAIL);
  544. /**
  545. * Trigger auto-recovery after a delay.
  546. */
  547. if (ioc->auto_recover) {
  548. bfa_timer_begin(ioc->timer_mod, &ioc->ioc_timer,
  549. bfa_ioc_timeout, ioc, BFA_IOC_TOV_RECOVER);
  550. }
  551. }
  552. /**
  553. * IOC heartbeat failure.
  554. */
  555. static void
  556. bfa_ioc_sm_hbfail(struct bfa_ioc_s *ioc, enum ioc_event event)
  557. {
  558. bfa_trc(ioc, event);
  559. switch (event) {
  560. case IOC_E_ENABLE:
  561. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  562. break;
  563. case IOC_E_DISABLE:
  564. if (ioc->auto_recover)
  565. bfa_ioc_timer_stop(ioc);
  566. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  567. break;
  568. case IOC_E_TIMEOUT:
  569. bfa_fsm_set_state(ioc, bfa_ioc_sm_semwait);
  570. break;
  571. case IOC_E_FWREADY:
  572. /**
  573. * Recovery is already initiated by other function.
  574. */
  575. break;
  576. case IOC_E_HWERROR:
  577. /*
  578. * HB failure notification, ignore.
  579. */
  580. break;
  581. default:
  582. bfa_sm_fault(ioc, event);
  583. }
  584. }
  585. /**
  586. * bfa_ioc_pvt BFA IOC private functions
  587. */
  588. static void
  589. bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
  590. {
  591. struct list_head *qe;
  592. struct bfa_ioc_hbfail_notify_s *notify;
  593. ioc->cbfn->disable_cbfn(ioc->bfa);
  594. /**
  595. * Notify common modules registered for notification.
  596. */
  597. list_for_each(qe, &ioc->hb_notify_q) {
  598. notify = (struct bfa_ioc_hbfail_notify_s *)qe;
  599. notify->cbfn(notify->cbarg);
  600. }
  601. }
  602. void
  603. bfa_ioc_sem_timeout(void *ioc_arg)
  604. {
  605. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *)ioc_arg;
  606. bfa_ioc_hw_sem_get(ioc);
  607. }
  608. bfa_boolean_t
  609. bfa_ioc_sem_get(bfa_os_addr_t sem_reg)
  610. {
  611. u32 r32;
  612. int cnt = 0;
  613. #define BFA_SEM_SPINCNT 3000
  614. r32 = bfa_reg_read(sem_reg);
  615. while (r32 && (cnt < BFA_SEM_SPINCNT)) {
  616. cnt++;
  617. bfa_os_udelay(2);
  618. r32 = bfa_reg_read(sem_reg);
  619. }
  620. if (r32 == 0)
  621. return BFA_TRUE;
  622. bfa_assert(cnt < BFA_SEM_SPINCNT);
  623. return BFA_FALSE;
  624. }
  625. void
  626. bfa_ioc_sem_release(bfa_os_addr_t sem_reg)
  627. {
  628. bfa_reg_write(sem_reg, 1);
  629. }
  630. static void
  631. bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
  632. {
  633. u32 r32;
  634. /**
  635. * First read to the semaphore register will return 0, subsequent reads
  636. * will return 1. Semaphore is released by writing 1 to the register
  637. */
  638. r32 = bfa_reg_read(ioc->ioc_regs.ioc_sem_reg);
  639. if (r32 == 0) {
  640. bfa_fsm_send_event(ioc, IOC_E_SEMLOCKED);
  641. return;
  642. }
  643. bfa_timer_begin(ioc->timer_mod, &ioc->sem_timer, bfa_ioc_sem_timeout,
  644. ioc, BFA_IOC_HWSEM_TOV);
  645. }
  646. void
  647. bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc)
  648. {
  649. bfa_reg_write(ioc->ioc_regs.ioc_sem_reg, 1);
  650. }
  651. static void
  652. bfa_ioc_hw_sem_get_cancel(struct bfa_ioc_s *ioc)
  653. {
  654. bfa_timer_stop(&ioc->sem_timer);
  655. }
  656. /**
  657. * Initialize LPU local memory (aka secondary memory / SRAM)
  658. */
  659. static void
  660. bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
  661. {
  662. u32 pss_ctl;
  663. int i;
  664. #define PSS_LMEM_INIT_TIME 10000
  665. pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg);
  666. pss_ctl &= ~__PSS_LMEM_RESET;
  667. pss_ctl |= __PSS_LMEM_INIT_EN;
  668. pss_ctl |= __PSS_I2C_CLK_DIV(3UL); /* i2c workaround 12.5khz clock */
  669. bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl);
  670. /**
  671. * wait for memory initialization to be complete
  672. */
  673. i = 0;
  674. do {
  675. pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg);
  676. i++;
  677. } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
  678. /**
  679. * If memory initialization is not successful, IOC timeout will catch
  680. * such failures.
  681. */
  682. bfa_assert(pss_ctl & __PSS_LMEM_INIT_DONE);
  683. bfa_trc(ioc, pss_ctl);
  684. pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
  685. bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl);
  686. }
  687. static void
  688. bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
  689. {
  690. u32 pss_ctl;
  691. /**
  692. * Take processor out of reset.
  693. */
  694. pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg);
  695. pss_ctl &= ~__PSS_LPU0_RESET;
  696. bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl);
  697. }
  698. static void
  699. bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
  700. {
  701. u32 pss_ctl;
  702. /**
  703. * Put processors in reset.
  704. */
  705. pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg);
  706. pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
  707. bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl);
  708. }
  709. /**
  710. * Get driver and firmware versions.
  711. */
  712. void
  713. bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
  714. {
  715. u32 pgnum, pgoff;
  716. u32 loff = 0;
  717. int i;
  718. u32 *fwsig = (u32 *) fwhdr;
  719. pgnum = bfa_ioc_smem_pgnum(ioc, loff);
  720. pgoff = bfa_ioc_smem_pgoff(ioc, loff);
  721. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  722. for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
  723. i++) {
  724. fwsig[i] = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  725. loff += sizeof(u32);
  726. }
  727. }
  728. /**
  729. * Returns TRUE if same.
  730. */
  731. bfa_boolean_t
  732. bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
  733. {
  734. struct bfi_ioc_image_hdr_s *drv_fwhdr;
  735. int i;
  736. drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
  737. bfi_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
  738. for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
  739. if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
  740. bfa_trc(ioc, i);
  741. bfa_trc(ioc, fwhdr->md5sum[i]);
  742. bfa_trc(ioc, drv_fwhdr->md5sum[i]);
  743. return BFA_FALSE;
  744. }
  745. }
  746. bfa_trc(ioc, fwhdr->md5sum[0]);
  747. return BFA_TRUE;
  748. }
  749. /**
  750. * Return true if current running version is valid. Firmware signature and
  751. * execution context (driver/bios) must match.
  752. */
  753. static bfa_boolean_t
  754. bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc)
  755. {
  756. struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
  757. /**
  758. * If bios/efi boot (flash based) -- return true
  759. */
  760. if (bfa_ioc_is_optrom(ioc))
  761. return BFA_TRUE;
  762. bfa_ioc_fwver_get(ioc, &fwhdr);
  763. drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
  764. bfi_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
  765. if (fwhdr.signature != drv_fwhdr->signature) {
  766. bfa_trc(ioc, fwhdr.signature);
  767. bfa_trc(ioc, drv_fwhdr->signature);
  768. return BFA_FALSE;
  769. }
  770. if (fwhdr.exec != drv_fwhdr->exec) {
  771. bfa_trc(ioc, fwhdr.exec);
  772. bfa_trc(ioc, drv_fwhdr->exec);
  773. return BFA_FALSE;
  774. }
  775. return bfa_ioc_fwver_cmp(ioc, &fwhdr);
  776. }
  777. /**
  778. * Conditionally flush any pending message from firmware at start.
  779. */
  780. static void
  781. bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
  782. {
  783. u32 r32;
  784. r32 = bfa_reg_read(ioc->ioc_regs.lpu_mbox_cmd);
  785. if (r32)
  786. bfa_reg_write(ioc->ioc_regs.lpu_mbox_cmd, 1);
  787. }
  788. static void
  789. bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
  790. {
  791. enum bfi_ioc_state ioc_fwstate;
  792. bfa_boolean_t fwvalid;
  793. ioc_fwstate = bfa_reg_read(ioc->ioc_regs.ioc_fwstate);
  794. if (force)
  795. ioc_fwstate = BFI_IOC_UNINIT;
  796. bfa_trc(ioc, ioc_fwstate);
  797. /**
  798. * check if firmware is valid
  799. */
  800. fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
  801. BFA_FALSE : bfa_ioc_fwver_valid(ioc);
  802. if (!fwvalid) {
  803. bfa_ioc_boot(ioc, BFI_BOOT_TYPE_NORMAL, ioc->pcidev.device_id);
  804. return;
  805. }
  806. /**
  807. * If hardware initialization is in progress (initialized by other IOC),
  808. * just wait for an initialization completion interrupt.
  809. */
  810. if (ioc_fwstate == BFI_IOC_INITING) {
  811. bfa_trc(ioc, ioc_fwstate);
  812. ioc->cbfn->reset_cbfn(ioc->bfa);
  813. return;
  814. }
  815. /**
  816. * If IOC function is disabled and firmware version is same,
  817. * just re-enable IOC.
  818. *
  819. * If option rom, IOC must not be in operational state. With
  820. * convergence, IOC will be in operational state when 2nd driver
  821. * is loaded.
  822. */
  823. if (ioc_fwstate == BFI_IOC_DISABLED ||
  824. (!bfa_ioc_is_optrom(ioc) && ioc_fwstate == BFI_IOC_OP)) {
  825. bfa_trc(ioc, ioc_fwstate);
  826. /**
  827. * When using MSI-X any pending firmware ready event should
  828. * be flushed. Otherwise MSI-X interrupts are not delivered.
  829. */
  830. bfa_ioc_msgflush(ioc);
  831. ioc->cbfn->reset_cbfn(ioc->bfa);
  832. bfa_fsm_send_event(ioc, IOC_E_FWREADY);
  833. return;
  834. }
  835. /**
  836. * Initialize the h/w for any other states.
  837. */
  838. bfa_ioc_boot(ioc, BFI_BOOT_TYPE_NORMAL, ioc->pcidev.device_id);
  839. }
  840. static void
  841. bfa_ioc_timeout(void *ioc_arg)
  842. {
  843. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *)ioc_arg;
  844. bfa_trc(ioc, 0);
  845. bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
  846. }
  847. void
  848. bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
  849. {
  850. u32 *msgp = (u32 *) ioc_msg;
  851. u32 i;
  852. bfa_trc(ioc, msgp[0]);
  853. bfa_trc(ioc, len);
  854. bfa_assert(len <= BFI_IOC_MSGLEN_MAX);
  855. /*
  856. * first write msg to mailbox registers
  857. */
  858. for (i = 0; i < len / sizeof(u32); i++)
  859. bfa_reg_write(ioc->ioc_regs.hfn_mbox + i * sizeof(u32),
  860. bfa_os_wtole(msgp[i]));
  861. for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
  862. bfa_reg_write(ioc->ioc_regs.hfn_mbox + i * sizeof(u32), 0);
  863. /*
  864. * write 1 to mailbox CMD to trigger LPU event
  865. */
  866. bfa_reg_write(ioc->ioc_regs.hfn_mbox_cmd, 1);
  867. (void)bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd);
  868. }
  869. static void
  870. bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
  871. {
  872. struct bfi_ioc_ctrl_req_s enable_req;
  873. bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
  874. bfa_ioc_portid(ioc));
  875. enable_req.ioc_class = ioc->ioc_mc;
  876. bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  877. }
  878. static void
  879. bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
  880. {
  881. struct bfi_ioc_ctrl_req_s disable_req;
  882. bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
  883. bfa_ioc_portid(ioc));
  884. bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  885. }
  886. static void
  887. bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
  888. {
  889. struct bfi_ioc_getattr_req_s attr_req;
  890. bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
  891. bfa_ioc_portid(ioc));
  892. bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
  893. bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
  894. }
  895. static void
  896. bfa_ioc_hb_check(void *cbarg)
  897. {
  898. struct bfa_ioc_s *ioc = cbarg;
  899. u32 hb_count;
  900. hb_count = bfa_reg_read(ioc->ioc_regs.heartbeat);
  901. if (ioc->hb_count == hb_count) {
  902. bfa_log(ioc->logm, BFA_LOG_HAL_HEARTBEAT_FAILURE,
  903. hb_count);
  904. bfa_ioc_recover(ioc);
  905. return;
  906. } else {
  907. ioc->hb_count = hb_count;
  908. }
  909. bfa_ioc_mbox_poll(ioc);
  910. bfa_timer_begin(ioc->timer_mod, &ioc->ioc_timer, bfa_ioc_hb_check,
  911. ioc, BFA_IOC_HB_TOV);
  912. }
  913. static void
  914. bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
  915. {
  916. ioc->hb_count = bfa_reg_read(ioc->ioc_regs.heartbeat);
  917. bfa_timer_begin(ioc->timer_mod, &ioc->ioc_timer, bfa_ioc_hb_check, ioc,
  918. BFA_IOC_HB_TOV);
  919. }
  920. static void
  921. bfa_ioc_hb_stop(struct bfa_ioc_s *ioc)
  922. {
  923. bfa_timer_stop(&ioc->ioc_timer);
  924. }
  925. /**
  926. * Initiate a full firmware download.
  927. */
  928. static void
  929. bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
  930. u32 boot_param)
  931. {
  932. u32 *fwimg;
  933. u32 pgnum, pgoff;
  934. u32 loff = 0;
  935. u32 chunkno = 0;
  936. u32 i;
  937. /**
  938. * Initialize LMEM first before code download
  939. */
  940. bfa_ioc_lmem_init(ioc);
  941. /**
  942. * Flash based firmware boot
  943. */
  944. bfa_trc(ioc, bfi_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)));
  945. if (bfa_ioc_is_optrom(ioc))
  946. boot_type = BFI_BOOT_TYPE_FLASH;
  947. fwimg = bfi_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno);
  948. pgnum = bfa_ioc_smem_pgnum(ioc, loff);
  949. pgoff = bfa_ioc_smem_pgoff(ioc, loff);
  950. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  951. for (i = 0; i < bfi_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
  952. if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
  953. chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
  954. fwimg = bfi_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc),
  955. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  956. }
  957. /**
  958. * write smem
  959. */
  960. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
  961. fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
  962. loff += sizeof(u32);
  963. /**
  964. * handle page offset wrap around
  965. */
  966. loff = PSS_SMEM_PGOFF(loff);
  967. if (loff == 0) {
  968. pgnum++;
  969. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  970. }
  971. }
  972. bfa_reg_write(ioc->ioc_regs.host_page_num_fn,
  973. bfa_ioc_smem_pgnum(ioc, 0));
  974. /*
  975. * Set boot type and boot param at the end.
  976. */
  977. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF,
  978. bfa_os_swap32(boot_type));
  979. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_PARAM_OFF,
  980. bfa_os_swap32(boot_param));
  981. }
  982. static void
  983. bfa_ioc_reset(struct bfa_ioc_s *ioc, bfa_boolean_t force)
  984. {
  985. bfa_ioc_hwinit(ioc, force);
  986. }
  987. /**
  988. * Update BFA configuration from firmware configuration.
  989. */
  990. static void
  991. bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
  992. {
  993. struct bfi_ioc_attr_s *attr = ioc->attr;
  994. attr->adapter_prop = bfa_os_ntohl(attr->adapter_prop);
  995. attr->card_type = bfa_os_ntohl(attr->card_type);
  996. attr->maxfrsize = bfa_os_ntohs(attr->maxfrsize);
  997. bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
  998. }
  999. /**
  1000. * Attach time initialization of mbox logic.
  1001. */
  1002. static void
  1003. bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
  1004. {
  1005. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1006. int mc;
  1007. INIT_LIST_HEAD(&mod->cmd_q);
  1008. for (mc = 0; mc < BFI_MC_MAX; mc++) {
  1009. mod->mbhdlr[mc].cbfn = NULL;
  1010. mod->mbhdlr[mc].cbarg = ioc->bfa;
  1011. }
  1012. }
  1013. /**
  1014. * Mbox poll timer -- restarts any pending mailbox requests.
  1015. */
  1016. static void
  1017. bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
  1018. {
  1019. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1020. struct bfa_mbox_cmd_s *cmd;
  1021. u32 stat;
  1022. /**
  1023. * If no command pending, do nothing
  1024. */
  1025. if (list_empty(&mod->cmd_q))
  1026. return;
  1027. /**
  1028. * If previous command is not yet fetched by firmware, do nothing
  1029. */
  1030. stat = bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd);
  1031. if (stat)
  1032. return;
  1033. /**
  1034. * Enqueue command to firmware.
  1035. */
  1036. bfa_q_deq(&mod->cmd_q, &cmd);
  1037. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1038. }
  1039. /**
  1040. * Cleanup any pending requests.
  1041. */
  1042. static void
  1043. bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc)
  1044. {
  1045. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1046. struct bfa_mbox_cmd_s *cmd;
  1047. while (!list_empty(&mod->cmd_q))
  1048. bfa_q_deq(&mod->cmd_q, &cmd);
  1049. }
  1050. /**
  1051. * bfa_ioc_public
  1052. */
  1053. /**
  1054. * Interface used by diag module to do firmware boot with memory test
  1055. * as the entry vector.
  1056. */
  1057. void
  1058. bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_param)
  1059. {
  1060. bfa_os_addr_t rb;
  1061. bfa_ioc_stats(ioc, ioc_boots);
  1062. if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
  1063. return;
  1064. /**
  1065. * Initialize IOC state of all functions on a chip reset.
  1066. */
  1067. rb = ioc->pcidev.pci_bar_kva;
  1068. if (boot_param == BFI_BOOT_TYPE_MEMTEST) {
  1069. bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_MEMTEST);
  1070. bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_MEMTEST);
  1071. } else {
  1072. bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_INITING);
  1073. bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_INITING);
  1074. }
  1075. bfa_ioc_msgflush(ioc);
  1076. bfa_ioc_download_fw(ioc, boot_type, boot_param);
  1077. /**
  1078. * Enable interrupts just before starting LPU
  1079. */
  1080. ioc->cbfn->reset_cbfn(ioc->bfa);
  1081. bfa_ioc_lpu_start(ioc);
  1082. }
  1083. /**
  1084. * Enable/disable IOC failure auto recovery.
  1085. */
  1086. void
  1087. bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
  1088. {
  1089. bfa_auto_recover = auto_recover;
  1090. }
  1091. bfa_boolean_t
  1092. bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
  1093. {
  1094. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
  1095. }
  1096. void
  1097. bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
  1098. {
  1099. u32 *msgp = mbmsg;
  1100. u32 r32;
  1101. int i;
  1102. /**
  1103. * read the MBOX msg
  1104. */
  1105. for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
  1106. i++) {
  1107. r32 = bfa_reg_read(ioc->ioc_regs.lpu_mbox +
  1108. i * sizeof(u32));
  1109. msgp[i] = bfa_os_htonl(r32);
  1110. }
  1111. /**
  1112. * turn off mailbox interrupt by clearing mailbox status
  1113. */
  1114. bfa_reg_write(ioc->ioc_regs.lpu_mbox_cmd, 1);
  1115. bfa_reg_read(ioc->ioc_regs.lpu_mbox_cmd);
  1116. }
  1117. void
  1118. bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
  1119. {
  1120. union bfi_ioc_i2h_msg_u *msg;
  1121. msg = (union bfi_ioc_i2h_msg_u *)m;
  1122. bfa_ioc_stats(ioc, ioc_isrs);
  1123. switch (msg->mh.msg_id) {
  1124. case BFI_IOC_I2H_HBEAT:
  1125. break;
  1126. case BFI_IOC_I2H_READY_EVENT:
  1127. bfa_fsm_send_event(ioc, IOC_E_FWREADY);
  1128. break;
  1129. case BFI_IOC_I2H_ENABLE_REPLY:
  1130. bfa_fsm_send_event(ioc, IOC_E_FWRSP_ENABLE);
  1131. break;
  1132. case BFI_IOC_I2H_DISABLE_REPLY:
  1133. bfa_fsm_send_event(ioc, IOC_E_FWRSP_DISABLE);
  1134. break;
  1135. case BFI_IOC_I2H_GETATTR_REPLY:
  1136. bfa_ioc_getattr_reply(ioc);
  1137. break;
  1138. default:
  1139. bfa_trc(ioc, msg->mh.msg_id);
  1140. bfa_assert(0);
  1141. }
  1142. }
  1143. /**
  1144. * IOC attach time initialization and setup.
  1145. *
  1146. * @param[in] ioc memory for IOC
  1147. * @param[in] bfa driver instance structure
  1148. * @param[in] trcmod kernel trace module
  1149. * @param[in] aen kernel aen event module
  1150. * @param[in] logm kernel logging module
  1151. */
  1152. void
  1153. bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
  1154. struct bfa_timer_mod_s *timer_mod, struct bfa_trc_mod_s *trcmod,
  1155. struct bfa_aen_s *aen, struct bfa_log_mod_s *logm)
  1156. {
  1157. ioc->bfa = bfa;
  1158. ioc->cbfn = cbfn;
  1159. ioc->timer_mod = timer_mod;
  1160. ioc->trcmod = trcmod;
  1161. ioc->aen = aen;
  1162. ioc->logm = logm;
  1163. ioc->fcmode = BFA_FALSE;
  1164. ioc->pllinit = BFA_FALSE;
  1165. ioc->dbg_fwsave_once = BFA_TRUE;
  1166. bfa_ioc_mbox_attach(ioc);
  1167. INIT_LIST_HEAD(&ioc->hb_notify_q);
  1168. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  1169. }
  1170. /**
  1171. * Driver detach time IOC cleanup.
  1172. */
  1173. void
  1174. bfa_ioc_detach(struct bfa_ioc_s *ioc)
  1175. {
  1176. bfa_fsm_send_event(ioc, IOC_E_DETACH);
  1177. }
  1178. /**
  1179. * Setup IOC PCI properties.
  1180. *
  1181. * @param[in] pcidev PCI device information for this IOC
  1182. */
  1183. void
  1184. bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  1185. enum bfi_mclass mc)
  1186. {
  1187. ioc->ioc_mc = mc;
  1188. ioc->pcidev = *pcidev;
  1189. ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
  1190. ioc->cna = ioc->ctdev && !ioc->fcmode;
  1191. /**
  1192. * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
  1193. */
  1194. if (ioc->ctdev)
  1195. bfa_ioc_set_ct_hwif(ioc);
  1196. else
  1197. bfa_ioc_set_cb_hwif(ioc);
  1198. bfa_ioc_map_port(ioc);
  1199. bfa_ioc_reg_init(ioc);
  1200. }
  1201. /**
  1202. * Initialize IOC dma memory
  1203. *
  1204. * @param[in] dm_kva kernel virtual address of IOC dma memory
  1205. * @param[in] dm_pa physical address of IOC dma memory
  1206. */
  1207. void
  1208. bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
  1209. {
  1210. /**
  1211. * dma memory for firmware attribute
  1212. */
  1213. ioc->attr_dma.kva = dm_kva;
  1214. ioc->attr_dma.pa = dm_pa;
  1215. ioc->attr = (struct bfi_ioc_attr_s *)dm_kva;
  1216. }
  1217. /**
  1218. * Return size of dma memory required.
  1219. */
  1220. u32
  1221. bfa_ioc_meminfo(void)
  1222. {
  1223. return BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ);
  1224. }
  1225. void
  1226. bfa_ioc_enable(struct bfa_ioc_s *ioc)
  1227. {
  1228. bfa_ioc_stats(ioc, ioc_enables);
  1229. ioc->dbg_fwsave_once = BFA_TRUE;
  1230. bfa_fsm_send_event(ioc, IOC_E_ENABLE);
  1231. }
  1232. void
  1233. bfa_ioc_disable(struct bfa_ioc_s *ioc)
  1234. {
  1235. bfa_ioc_stats(ioc, ioc_disables);
  1236. bfa_fsm_send_event(ioc, IOC_E_DISABLE);
  1237. }
  1238. /**
  1239. * Returns memory required for saving firmware trace in case of crash.
  1240. * Driver must call this interface to allocate memory required for
  1241. * automatic saving of firmware trace. Driver should call
  1242. * bfa_ioc_debug_memclaim() right after bfa_ioc_attach() to setup this
  1243. * trace memory.
  1244. */
  1245. int
  1246. bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover)
  1247. {
  1248. return (auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
  1249. }
  1250. /**
  1251. * Initialize memory for saving firmware trace. Driver must initialize
  1252. * trace memory before call bfa_ioc_enable().
  1253. */
  1254. void
  1255. bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
  1256. {
  1257. ioc->dbg_fwsave = dbg_fwsave;
  1258. ioc->dbg_fwsave_len = bfa_ioc_debug_trcsz(ioc->auto_recover);
  1259. }
  1260. u32
  1261. bfa_ioc_smem_pgnum(struct bfa_ioc_s *ioc, u32 fmaddr)
  1262. {
  1263. return PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, fmaddr);
  1264. }
  1265. u32
  1266. bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr)
  1267. {
  1268. return PSS_SMEM_PGOFF(fmaddr);
  1269. }
  1270. /**
  1271. * Register mailbox message handler functions
  1272. *
  1273. * @param[in] ioc IOC instance
  1274. * @param[in] mcfuncs message class handler functions
  1275. */
  1276. void
  1277. bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
  1278. {
  1279. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1280. int mc;
  1281. for (mc = 0; mc < BFI_MC_MAX; mc++)
  1282. mod->mbhdlr[mc].cbfn = mcfuncs[mc];
  1283. }
  1284. /**
  1285. * Register mailbox message handler function, to be called by common modules
  1286. */
  1287. void
  1288. bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  1289. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
  1290. {
  1291. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1292. mod->mbhdlr[mc].cbfn = cbfn;
  1293. mod->mbhdlr[mc].cbarg = cbarg;
  1294. }
  1295. /**
  1296. * Queue a mailbox command request to firmware. Waits if mailbox is busy.
  1297. * Responsibility of caller to serialize
  1298. *
  1299. * @param[in] ioc IOC instance
  1300. * @param[i] cmd Mailbox command
  1301. */
  1302. void
  1303. bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
  1304. {
  1305. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1306. u32 stat;
  1307. /**
  1308. * If a previous command is pending, queue new command
  1309. */
  1310. if (!list_empty(&mod->cmd_q)) {
  1311. list_add_tail(&cmd->qe, &mod->cmd_q);
  1312. return;
  1313. }
  1314. /**
  1315. * If mailbox is busy, queue command for poll timer
  1316. */
  1317. stat = bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd);
  1318. if (stat) {
  1319. list_add_tail(&cmd->qe, &mod->cmd_q);
  1320. return;
  1321. }
  1322. /**
  1323. * mailbox is free -- queue command to firmware
  1324. */
  1325. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1326. }
  1327. /**
  1328. * Handle mailbox interrupts
  1329. */
  1330. void
  1331. bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
  1332. {
  1333. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1334. struct bfi_mbmsg_s m;
  1335. int mc;
  1336. bfa_ioc_msgget(ioc, &m);
  1337. /**
  1338. * Treat IOC message class as special.
  1339. */
  1340. mc = m.mh.msg_class;
  1341. if (mc == BFI_MC_IOC) {
  1342. bfa_ioc_isr(ioc, &m);
  1343. return;
  1344. }
  1345. if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
  1346. return;
  1347. mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
  1348. }
  1349. void
  1350. bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
  1351. {
  1352. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  1353. }
  1354. void
  1355. bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
  1356. {
  1357. ioc->fcmode = BFA_TRUE;
  1358. ioc->port_id = bfa_ioc_pcifn(ioc);
  1359. }
  1360. #ifndef BFA_BIOS_BUILD
  1361. /**
  1362. * return true if IOC is disabled
  1363. */
  1364. bfa_boolean_t
  1365. bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
  1366. {
  1367. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling)
  1368. || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
  1369. }
  1370. /**
  1371. * return true if IOC firmware is different.
  1372. */
  1373. bfa_boolean_t
  1374. bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
  1375. {
  1376. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset)
  1377. || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_fwcheck)
  1378. || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_mismatch);
  1379. }
  1380. #define bfa_ioc_state_disabled(__sm) \
  1381. (((__sm) == BFI_IOC_UNINIT) || \
  1382. ((__sm) == BFI_IOC_INITING) || \
  1383. ((__sm) == BFI_IOC_HWINIT) || \
  1384. ((__sm) == BFI_IOC_DISABLED) || \
  1385. ((__sm) == BFI_IOC_FAIL) || \
  1386. ((__sm) == BFI_IOC_CFG_DISABLED))
  1387. /**
  1388. * Check if adapter is disabled -- both IOCs should be in a disabled
  1389. * state.
  1390. */
  1391. bfa_boolean_t
  1392. bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
  1393. {
  1394. u32 ioc_state;
  1395. bfa_os_addr_t rb = ioc->pcidev.pci_bar_kva;
  1396. if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
  1397. return BFA_FALSE;
  1398. ioc_state = bfa_reg_read(rb + BFA_IOC0_STATE_REG);
  1399. if (!bfa_ioc_state_disabled(ioc_state))
  1400. return BFA_FALSE;
  1401. ioc_state = bfa_reg_read(rb + BFA_IOC1_STATE_REG);
  1402. if (!bfa_ioc_state_disabled(ioc_state))
  1403. return BFA_FALSE;
  1404. return BFA_TRUE;
  1405. }
  1406. /**
  1407. * Add to IOC heartbeat failure notification queue. To be used by common
  1408. * modules such as
  1409. */
  1410. void
  1411. bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc,
  1412. struct bfa_ioc_hbfail_notify_s *notify)
  1413. {
  1414. list_add_tail(&notify->qe, &ioc->hb_notify_q);
  1415. }
  1416. #define BFA_MFG_NAME "Brocade"
  1417. void
  1418. bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  1419. struct bfa_adapter_attr_s *ad_attr)
  1420. {
  1421. struct bfi_ioc_attr_s *ioc_attr;
  1422. ioc_attr = ioc->attr;
  1423. bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
  1424. bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
  1425. bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
  1426. bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
  1427. bfa_os_memcpy(&ad_attr->vpd, &ioc_attr->vpd,
  1428. sizeof(struct bfa_mfg_vpd_s));
  1429. ad_attr->nports = bfa_ioc_get_nports(ioc);
  1430. ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
  1431. bfa_ioc_get_adapter_model(ioc, ad_attr->model);
  1432. /* For now, model descr uses same model string */
  1433. bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
  1434. ad_attr->card_type = ioc_attr->card_type;
  1435. ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
  1436. if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
  1437. ad_attr->prototype = 1;
  1438. else
  1439. ad_attr->prototype = 0;
  1440. ad_attr->pwwn = bfa_ioc_get_pwwn(ioc);
  1441. ad_attr->mac = bfa_ioc_get_mac(ioc);
  1442. ad_attr->pcie_gen = ioc_attr->pcie_gen;
  1443. ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
  1444. ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
  1445. ad_attr->asic_rev = ioc_attr->asic_rev;
  1446. bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
  1447. ad_attr->cna_capable = ioc->cna;
  1448. }
  1449. enum bfa_ioc_type_e
  1450. bfa_ioc_get_type(struct bfa_ioc_s *ioc)
  1451. {
  1452. if (!ioc->ctdev || ioc->fcmode)
  1453. return BFA_IOC_TYPE_FC;
  1454. else if (ioc->ioc_mc == BFI_MC_IOCFC)
  1455. return BFA_IOC_TYPE_FCoE;
  1456. else if (ioc->ioc_mc == BFI_MC_LL)
  1457. return BFA_IOC_TYPE_LL;
  1458. else {
  1459. bfa_assert(ioc->ioc_mc == BFI_MC_LL);
  1460. return BFA_IOC_TYPE_LL;
  1461. }
  1462. }
  1463. void
  1464. bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
  1465. {
  1466. bfa_os_memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
  1467. bfa_os_memcpy((void *)serial_num,
  1468. (void *)ioc->attr->brcd_serialnum,
  1469. BFA_ADAPTER_SERIAL_NUM_LEN);
  1470. }
  1471. void
  1472. bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
  1473. {
  1474. bfa_os_memset((void *)fw_ver, 0, BFA_VERSION_LEN);
  1475. bfa_os_memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
  1476. }
  1477. void
  1478. bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
  1479. {
  1480. bfa_assert(chip_rev);
  1481. bfa_os_memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
  1482. chip_rev[0] = 'R';
  1483. chip_rev[1] = 'e';
  1484. chip_rev[2] = 'v';
  1485. chip_rev[3] = '-';
  1486. chip_rev[4] = ioc->attr->asic_rev;
  1487. chip_rev[5] = '\0';
  1488. }
  1489. void
  1490. bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
  1491. {
  1492. bfa_os_memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
  1493. bfa_os_memcpy(optrom_ver, ioc->attr->optrom_version,
  1494. BFA_VERSION_LEN);
  1495. }
  1496. void
  1497. bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
  1498. {
  1499. bfa_os_memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
  1500. bfa_os_memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
  1501. }
  1502. void
  1503. bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
  1504. {
  1505. struct bfi_ioc_attr_s *ioc_attr;
  1506. bfa_assert(model);
  1507. bfa_os_memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
  1508. ioc_attr = ioc->attr;
  1509. /**
  1510. * model name
  1511. */
  1512. snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
  1513. BFA_MFG_NAME, ioc_attr->card_type);
  1514. }
  1515. enum bfa_ioc_state
  1516. bfa_ioc_get_state(struct bfa_ioc_s *ioc)
  1517. {
  1518. return bfa_sm_to_state(ioc_sm_table, ioc->fsm);
  1519. }
  1520. void
  1521. bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
  1522. {
  1523. bfa_os_memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
  1524. ioc_attr->state = bfa_ioc_get_state(ioc);
  1525. ioc_attr->port_id = ioc->port_id;
  1526. ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
  1527. bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
  1528. ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
  1529. ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
  1530. bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
  1531. }
  1532. /**
  1533. * bfa_wwn_public
  1534. */
  1535. wwn_t
  1536. bfa_ioc_get_pwwn(struct bfa_ioc_s *ioc)
  1537. {
  1538. return ioc->attr->pwwn;
  1539. }
  1540. wwn_t
  1541. bfa_ioc_get_nwwn(struct bfa_ioc_s *ioc)
  1542. {
  1543. return ioc->attr->nwwn;
  1544. }
  1545. u64
  1546. bfa_ioc_get_adid(struct bfa_ioc_s *ioc)
  1547. {
  1548. return ioc->attr->mfg_pwwn;
  1549. }
  1550. mac_t
  1551. bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
  1552. {
  1553. /*
  1554. * Currently mfg mac is used as FCoE enode mac (not configured by PBC)
  1555. */
  1556. if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
  1557. return bfa_ioc_get_mfg_mac(ioc);
  1558. else
  1559. return ioc->attr->mac;
  1560. }
  1561. wwn_t
  1562. bfa_ioc_get_mfg_pwwn(struct bfa_ioc_s *ioc)
  1563. {
  1564. return ioc->attr->mfg_pwwn;
  1565. }
  1566. wwn_t
  1567. bfa_ioc_get_mfg_nwwn(struct bfa_ioc_s *ioc)
  1568. {
  1569. return ioc->attr->mfg_nwwn;
  1570. }
  1571. mac_t
  1572. bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
  1573. {
  1574. mac_t mac;
  1575. mac = ioc->attr->mfg_mac;
  1576. mac.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
  1577. return mac;
  1578. }
  1579. bfa_boolean_t
  1580. bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
  1581. {
  1582. return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id);
  1583. }
  1584. /**
  1585. * Send AEN notification
  1586. */
  1587. void
  1588. bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
  1589. {
  1590. union bfa_aen_data_u aen_data;
  1591. struct bfa_log_mod_s *logmod = ioc->logm;
  1592. s32 inst_num = 0;
  1593. enum bfa_ioc_type_e ioc_type;
  1594. bfa_log(logmod, BFA_LOG_CREATE_ID(BFA_AEN_CAT_IOC, event), inst_num);
  1595. memset(&aen_data.ioc.pwwn, 0, sizeof(aen_data.ioc.pwwn));
  1596. memset(&aen_data.ioc.mac, 0, sizeof(aen_data.ioc.mac));
  1597. ioc_type = bfa_ioc_get_type(ioc);
  1598. switch (ioc_type) {
  1599. case BFA_IOC_TYPE_FC:
  1600. aen_data.ioc.pwwn = bfa_ioc_get_pwwn(ioc);
  1601. break;
  1602. case BFA_IOC_TYPE_FCoE:
  1603. aen_data.ioc.pwwn = bfa_ioc_get_pwwn(ioc);
  1604. aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  1605. break;
  1606. case BFA_IOC_TYPE_LL:
  1607. aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  1608. break;
  1609. default:
  1610. bfa_assert(ioc_type == BFA_IOC_TYPE_FC);
  1611. break;
  1612. }
  1613. aen_data.ioc.ioc_type = ioc_type;
  1614. }
  1615. /**
  1616. * Retrieve saved firmware trace from a prior IOC failure.
  1617. */
  1618. bfa_status_t
  1619. bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  1620. {
  1621. int tlen;
  1622. if (ioc->dbg_fwsave_len == 0)
  1623. return BFA_STATUS_ENOFSAVE;
  1624. tlen = *trclen;
  1625. if (tlen > ioc->dbg_fwsave_len)
  1626. tlen = ioc->dbg_fwsave_len;
  1627. bfa_os_memcpy(trcdata, ioc->dbg_fwsave, tlen);
  1628. *trclen = tlen;
  1629. return BFA_STATUS_OK;
  1630. }
  1631. /**
  1632. * Clear saved firmware trace
  1633. */
  1634. void
  1635. bfa_ioc_debug_fwsave_clear(struct bfa_ioc_s *ioc)
  1636. {
  1637. ioc->dbg_fwsave_once = BFA_TRUE;
  1638. }
  1639. /**
  1640. * Retrieve saved firmware trace from a prior IOC failure.
  1641. */
  1642. bfa_status_t
  1643. bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  1644. {
  1645. u32 pgnum;
  1646. u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
  1647. int i, tlen;
  1648. u32 *tbuf = trcdata, r32;
  1649. bfa_trc(ioc, *trclen);
  1650. pgnum = bfa_ioc_smem_pgnum(ioc, loff);
  1651. loff = bfa_ioc_smem_pgoff(ioc, loff);
  1652. /*
  1653. * Hold semaphore to serialize pll init and fwtrc.
  1654. */
  1655. if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg))
  1656. return BFA_STATUS_FAILED;
  1657. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  1658. tlen = *trclen;
  1659. if (tlen > BFA_DBG_FWTRC_LEN)
  1660. tlen = BFA_DBG_FWTRC_LEN;
  1661. tlen /= sizeof(u32);
  1662. bfa_trc(ioc, tlen);
  1663. for (i = 0; i < tlen; i++) {
  1664. r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  1665. tbuf[i] = bfa_os_ntohl(r32);
  1666. loff += sizeof(u32);
  1667. /**
  1668. * handle page offset wrap around
  1669. */
  1670. loff = PSS_SMEM_PGOFF(loff);
  1671. if (loff == 0) {
  1672. pgnum++;
  1673. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  1674. }
  1675. }
  1676. bfa_reg_write(ioc->ioc_regs.host_page_num_fn,
  1677. bfa_ioc_smem_pgnum(ioc, 0));
  1678. /*
  1679. * release semaphore.
  1680. */
  1681. bfa_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
  1682. bfa_trc(ioc, pgnum);
  1683. *trclen = tlen * sizeof(u32);
  1684. return BFA_STATUS_OK;
  1685. }
  1686. /**
  1687. * Save firmware trace if configured.
  1688. */
  1689. static void
  1690. bfa_ioc_debug_save(struct bfa_ioc_s *ioc)
  1691. {
  1692. int tlen;
  1693. if (ioc->dbg_fwsave_len) {
  1694. tlen = ioc->dbg_fwsave_len;
  1695. bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
  1696. }
  1697. }
  1698. /**
  1699. * Firmware failure detected. Start recovery actions.
  1700. */
  1701. static void
  1702. bfa_ioc_recover(struct bfa_ioc_s *ioc)
  1703. {
  1704. if (ioc->dbg_fwsave_once) {
  1705. ioc->dbg_fwsave_once = BFA_FALSE;
  1706. bfa_ioc_debug_save(ioc);
  1707. }
  1708. bfa_ioc_stats(ioc, ioc_hbfails);
  1709. bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
  1710. }
  1711. static void
  1712. bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
  1713. {
  1714. if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
  1715. return;
  1716. if (ioc->attr->nwwn == 0)
  1717. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_INVALID_NWWN);
  1718. if (ioc->attr->pwwn == 0)
  1719. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_INVALID_PWWN);
  1720. }
  1721. #endif