bfa_ioc.c 44 KB

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