bfa_ioc.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089
  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_aen_post(struct bfa_ioc_s *bfa,
  66. enum bfa_ioc_aen_event event);
  67. static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
  68. static void bfa_ioc_hw_sem_get_cancel(struct bfa_ioc_s *ioc);
  69. static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
  70. static void bfa_ioc_timeout(void *ioc);
  71. static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
  72. static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
  73. static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
  74. static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
  75. static void bfa_ioc_hb_stop(struct bfa_ioc_s *ioc);
  76. static void bfa_ioc_reset(struct bfa_ioc_s *ioc, bfa_boolean_t force);
  77. static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
  78. static void bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc);
  79. static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
  80. static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
  81. static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
  82. /**
  83. * bfa_ioc_sm
  84. */
  85. /**
  86. * IOC state machine events
  87. */
  88. enum ioc_event {
  89. IOC_E_ENABLE = 1, /* IOC enable request */
  90. IOC_E_DISABLE = 2, /* IOC disable request */
  91. IOC_E_TIMEOUT = 3, /* f/w response timeout */
  92. IOC_E_FWREADY = 4, /* f/w initialization done */
  93. IOC_E_FWRSP_GETATTR = 5, /* IOC get attribute response */
  94. IOC_E_FWRSP_ENABLE = 6, /* enable f/w response */
  95. IOC_E_FWRSP_DISABLE = 7, /* disable f/w response */
  96. IOC_E_HBFAIL = 8, /* heartbeat failure */
  97. IOC_E_HWERROR = 9, /* hardware error interrupt */
  98. IOC_E_SEMLOCKED = 10, /* h/w semaphore is locked */
  99. IOC_E_DETACH = 11, /* driver detach cleanup */
  100. };
  101. bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
  102. bfa_fsm_state_decl(bfa_ioc, fwcheck, struct bfa_ioc_s, enum ioc_event);
  103. bfa_fsm_state_decl(bfa_ioc, mismatch, struct bfa_ioc_s, enum ioc_event);
  104. bfa_fsm_state_decl(bfa_ioc, semwait, struct bfa_ioc_s, enum ioc_event);
  105. bfa_fsm_state_decl(bfa_ioc, hwinit, struct bfa_ioc_s, enum ioc_event);
  106. bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
  107. bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
  108. bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
  109. bfa_fsm_state_decl(bfa_ioc, initfail, struct bfa_ioc_s, enum ioc_event);
  110. bfa_fsm_state_decl(bfa_ioc, hbfail, struct bfa_ioc_s, enum ioc_event);
  111. bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
  112. bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
  113. static struct bfa_sm_table_s ioc_sm_table[] = {
  114. {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
  115. {BFA_SM(bfa_ioc_sm_fwcheck), BFA_IOC_FWMISMATCH},
  116. {BFA_SM(bfa_ioc_sm_mismatch), BFA_IOC_FWMISMATCH},
  117. {BFA_SM(bfa_ioc_sm_semwait), BFA_IOC_SEMWAIT},
  118. {BFA_SM(bfa_ioc_sm_hwinit), BFA_IOC_HWINIT},
  119. {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_HWINIT},
  120. {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
  121. {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
  122. {BFA_SM(bfa_ioc_sm_initfail), BFA_IOC_INITFAIL},
  123. {BFA_SM(bfa_ioc_sm_hbfail), BFA_IOC_HBFAIL},
  124. {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
  125. {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
  126. };
  127. /**
  128. * Reset entry actions -- initialize state machine
  129. */
  130. static void
  131. bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
  132. {
  133. ioc->retry_count = 0;
  134. ioc->auto_recover = bfa_auto_recover;
  135. }
  136. /**
  137. * Beginning state. IOC is in reset state.
  138. */
  139. static void
  140. bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
  141. {
  142. bfa_trc(ioc, event);
  143. switch (event) {
  144. case IOC_E_ENABLE:
  145. bfa_fsm_set_state(ioc, bfa_ioc_sm_fwcheck);
  146. break;
  147. case IOC_E_DISABLE:
  148. bfa_ioc_disable_comp(ioc);
  149. break;
  150. case IOC_E_DETACH:
  151. break;
  152. default:
  153. bfa_sm_fault(ioc, event);
  154. }
  155. }
  156. /**
  157. * Semaphore should be acquired for version check.
  158. */
  159. static void
  160. bfa_ioc_sm_fwcheck_entry(struct bfa_ioc_s *ioc)
  161. {
  162. bfa_ioc_hw_sem_get(ioc);
  163. }
  164. /**
  165. * Awaiting h/w semaphore to continue with version check.
  166. */
  167. static void
  168. bfa_ioc_sm_fwcheck(struct bfa_ioc_s *ioc, enum ioc_event event)
  169. {
  170. bfa_trc(ioc, event);
  171. switch (event) {
  172. case IOC_E_SEMLOCKED:
  173. if (bfa_ioc_firmware_lock(ioc)) {
  174. ioc->retry_count = 0;
  175. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwinit);
  176. } else {
  177. bfa_ioc_hw_sem_release(ioc);
  178. bfa_fsm_set_state(ioc, bfa_ioc_sm_mismatch);
  179. }
  180. break;
  181. case IOC_E_DISABLE:
  182. bfa_ioc_disable_comp(ioc);
  183. /*
  184. * fall through
  185. */
  186. case IOC_E_DETACH:
  187. bfa_ioc_hw_sem_get_cancel(ioc);
  188. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  189. break;
  190. case IOC_E_FWREADY:
  191. break;
  192. default:
  193. bfa_sm_fault(ioc, event);
  194. }
  195. }
  196. /**
  197. * Notify enable completion callback and generate mismatch AEN.
  198. */
  199. static void
  200. bfa_ioc_sm_mismatch_entry(struct bfa_ioc_s *ioc)
  201. {
  202. /**
  203. * Provide enable completion callback and AEN notification only once.
  204. */
  205. if (ioc->retry_count == 0) {
  206. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  207. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_FWMISMATCH);
  208. }
  209. ioc->retry_count++;
  210. bfa_ioc_timer_start(ioc);
  211. }
  212. /**
  213. * Awaiting firmware version match.
  214. */
  215. static void
  216. bfa_ioc_sm_mismatch(struct bfa_ioc_s *ioc, enum ioc_event event)
  217. {
  218. bfa_trc(ioc, event);
  219. switch (event) {
  220. case IOC_E_TIMEOUT:
  221. bfa_fsm_set_state(ioc, bfa_ioc_sm_fwcheck);
  222. break;
  223. case IOC_E_DISABLE:
  224. bfa_ioc_disable_comp(ioc);
  225. /*
  226. * fall through
  227. */
  228. case IOC_E_DETACH:
  229. bfa_ioc_timer_stop(ioc);
  230. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  231. break;
  232. case IOC_E_FWREADY:
  233. break;
  234. default:
  235. bfa_sm_fault(ioc, event);
  236. }
  237. }
  238. /**
  239. * Request for semaphore.
  240. */
  241. static void
  242. bfa_ioc_sm_semwait_entry(struct bfa_ioc_s *ioc)
  243. {
  244. bfa_ioc_hw_sem_get(ioc);
  245. }
  246. /**
  247. * Awaiting semaphore for h/w initialzation.
  248. */
  249. static void
  250. bfa_ioc_sm_semwait(struct bfa_ioc_s *ioc, enum ioc_event event)
  251. {
  252. bfa_trc(ioc, event);
  253. switch (event) {
  254. case IOC_E_SEMLOCKED:
  255. ioc->retry_count = 0;
  256. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwinit);
  257. break;
  258. case IOC_E_DISABLE:
  259. bfa_ioc_hw_sem_get_cancel(ioc);
  260. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  261. break;
  262. default:
  263. bfa_sm_fault(ioc, event);
  264. }
  265. }
  266. static void
  267. bfa_ioc_sm_hwinit_entry(struct bfa_ioc_s *ioc)
  268. {
  269. bfa_ioc_timer_start(ioc);
  270. bfa_ioc_reset(ioc, BFA_FALSE);
  271. }
  272. /**
  273. * Hardware is being initialized. Interrupts are enabled.
  274. * Holding hardware semaphore lock.
  275. */
  276. static void
  277. bfa_ioc_sm_hwinit(struct bfa_ioc_s *ioc, enum ioc_event event)
  278. {
  279. bfa_trc(ioc, event);
  280. switch (event) {
  281. case IOC_E_FWREADY:
  282. bfa_ioc_timer_stop(ioc);
  283. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  284. break;
  285. case IOC_E_HWERROR:
  286. bfa_ioc_timer_stop(ioc);
  287. /*
  288. * fall through
  289. */
  290. case IOC_E_TIMEOUT:
  291. ioc->retry_count++;
  292. if (ioc->retry_count < BFA_IOC_HWINIT_MAX) {
  293. bfa_ioc_timer_start(ioc);
  294. bfa_ioc_reset(ioc, BFA_TRUE);
  295. break;
  296. }
  297. bfa_ioc_hw_sem_release(ioc);
  298. bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
  299. break;
  300. case IOC_E_DISABLE:
  301. bfa_ioc_hw_sem_release(ioc);
  302. bfa_ioc_timer_stop(ioc);
  303. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  304. break;
  305. default:
  306. bfa_sm_fault(ioc, event);
  307. }
  308. }
  309. static void
  310. bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
  311. {
  312. bfa_ioc_timer_start(ioc);
  313. bfa_ioc_send_enable(ioc);
  314. }
  315. /**
  316. * Host IOC function is being enabled, awaiting response from firmware.
  317. * Semaphore is acquired.
  318. */
  319. static void
  320. bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
  321. {
  322. bfa_trc(ioc, event);
  323. switch (event) {
  324. case IOC_E_FWRSP_ENABLE:
  325. bfa_ioc_timer_stop(ioc);
  326. bfa_ioc_hw_sem_release(ioc);
  327. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  328. break;
  329. case IOC_E_HWERROR:
  330. bfa_ioc_timer_stop(ioc);
  331. /*
  332. * fall through
  333. */
  334. case IOC_E_TIMEOUT:
  335. ioc->retry_count++;
  336. if (ioc->retry_count < BFA_IOC_HWINIT_MAX) {
  337. bfa_reg_write(ioc->ioc_regs.ioc_fwstate,
  338. BFI_IOC_UNINIT);
  339. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwinit);
  340. break;
  341. }
  342. bfa_ioc_hw_sem_release(ioc);
  343. bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
  344. break;
  345. case IOC_E_DISABLE:
  346. bfa_ioc_timer_stop(ioc);
  347. bfa_ioc_hw_sem_release(ioc);
  348. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  349. break;
  350. case IOC_E_FWREADY:
  351. bfa_ioc_send_enable(ioc);
  352. break;
  353. default:
  354. bfa_sm_fault(ioc, event);
  355. }
  356. }
  357. static void
  358. bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
  359. {
  360. bfa_ioc_timer_start(ioc);
  361. bfa_ioc_send_getattr(ioc);
  362. }
  363. /**
  364. * IOC configuration in progress. Timer is active.
  365. */
  366. static void
  367. bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
  368. {
  369. bfa_trc(ioc, event);
  370. switch (event) {
  371. case IOC_E_FWRSP_GETATTR:
  372. bfa_ioc_timer_stop(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 (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
  820. bfa_trc(ioc, ioc_fwstate);
  821. /**
  822. * When using MSI-X any pending firmware ready event should
  823. * be flushed. Otherwise MSI-X interrupts are not delivered.
  824. */
  825. bfa_ioc_msgflush(ioc);
  826. ioc->cbfn->reset_cbfn(ioc->bfa);
  827. bfa_fsm_send_event(ioc, IOC_E_FWREADY);
  828. return;
  829. }
  830. /**
  831. * Initialize the h/w for any other states.
  832. */
  833. bfa_ioc_boot(ioc, BFI_BOOT_TYPE_NORMAL, ioc->pcidev.device_id);
  834. }
  835. static void
  836. bfa_ioc_timeout(void *ioc_arg)
  837. {
  838. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *)ioc_arg;
  839. bfa_trc(ioc, 0);
  840. bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
  841. }
  842. void
  843. bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
  844. {
  845. u32 *msgp = (u32 *) ioc_msg;
  846. u32 i;
  847. bfa_trc(ioc, msgp[0]);
  848. bfa_trc(ioc, len);
  849. bfa_assert(len <= BFI_IOC_MSGLEN_MAX);
  850. /*
  851. * first write msg to mailbox registers
  852. */
  853. for (i = 0; i < len / sizeof(u32); i++)
  854. bfa_reg_write(ioc->ioc_regs.hfn_mbox + i * sizeof(u32),
  855. bfa_os_wtole(msgp[i]));
  856. for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
  857. bfa_reg_write(ioc->ioc_regs.hfn_mbox + i * sizeof(u32), 0);
  858. /*
  859. * write 1 to mailbox CMD to trigger LPU event
  860. */
  861. bfa_reg_write(ioc->ioc_regs.hfn_mbox_cmd, 1);
  862. (void)bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd);
  863. }
  864. static void
  865. bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
  866. {
  867. struct bfi_ioc_ctrl_req_s enable_req;
  868. bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
  869. bfa_ioc_portid(ioc));
  870. enable_req.ioc_class = ioc->ioc_mc;
  871. bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  872. }
  873. static void
  874. bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
  875. {
  876. struct bfi_ioc_ctrl_req_s disable_req;
  877. bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
  878. bfa_ioc_portid(ioc));
  879. bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  880. }
  881. static void
  882. bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
  883. {
  884. struct bfi_ioc_getattr_req_s attr_req;
  885. bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
  886. bfa_ioc_portid(ioc));
  887. bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
  888. bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
  889. }
  890. static void
  891. bfa_ioc_hb_check(void *cbarg)
  892. {
  893. struct bfa_ioc_s *ioc = cbarg;
  894. u32 hb_count;
  895. hb_count = bfa_reg_read(ioc->ioc_regs.heartbeat);
  896. if (ioc->hb_count == hb_count) {
  897. bfa_log(ioc->logm, BFA_LOG_HAL_HEARTBEAT_FAILURE,
  898. hb_count);
  899. bfa_ioc_recover(ioc);
  900. return;
  901. } else {
  902. ioc->hb_count = hb_count;
  903. }
  904. bfa_ioc_mbox_poll(ioc);
  905. bfa_timer_begin(ioc->timer_mod, &ioc->ioc_timer, bfa_ioc_hb_check,
  906. ioc, BFA_IOC_HB_TOV);
  907. }
  908. static void
  909. bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
  910. {
  911. ioc->hb_count = bfa_reg_read(ioc->ioc_regs.heartbeat);
  912. bfa_timer_begin(ioc->timer_mod, &ioc->ioc_timer, bfa_ioc_hb_check, ioc,
  913. BFA_IOC_HB_TOV);
  914. }
  915. static void
  916. bfa_ioc_hb_stop(struct bfa_ioc_s *ioc)
  917. {
  918. bfa_timer_stop(&ioc->ioc_timer);
  919. }
  920. /**
  921. * Initiate a full firmware download.
  922. */
  923. static void
  924. bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
  925. u32 boot_param)
  926. {
  927. u32 *fwimg;
  928. u32 pgnum, pgoff;
  929. u32 loff = 0;
  930. u32 chunkno = 0;
  931. u32 i;
  932. /**
  933. * Initialize LMEM first before code download
  934. */
  935. bfa_ioc_lmem_init(ioc);
  936. /**
  937. * Flash based firmware boot
  938. */
  939. bfa_trc(ioc, bfi_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)));
  940. if (bfa_ioc_is_optrom(ioc))
  941. boot_type = BFI_BOOT_TYPE_FLASH;
  942. fwimg = bfi_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno);
  943. pgnum = bfa_ioc_smem_pgnum(ioc, loff);
  944. pgoff = bfa_ioc_smem_pgoff(ioc, loff);
  945. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  946. for (i = 0; i < bfi_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
  947. if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
  948. chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
  949. fwimg = bfi_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc),
  950. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  951. }
  952. /**
  953. * write smem
  954. */
  955. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
  956. fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
  957. loff += sizeof(u32);
  958. /**
  959. * handle page offset wrap around
  960. */
  961. loff = PSS_SMEM_PGOFF(loff);
  962. if (loff == 0) {
  963. pgnum++;
  964. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  965. }
  966. }
  967. bfa_reg_write(ioc->ioc_regs.host_page_num_fn,
  968. bfa_ioc_smem_pgnum(ioc, 0));
  969. /*
  970. * Set boot type and boot param at the end.
  971. */
  972. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF,
  973. bfa_os_swap32(boot_type));
  974. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_PARAM_OFF,
  975. bfa_os_swap32(boot_param));
  976. }
  977. static void
  978. bfa_ioc_reset(struct bfa_ioc_s *ioc, bfa_boolean_t force)
  979. {
  980. bfa_ioc_hwinit(ioc, force);
  981. }
  982. /**
  983. * Update BFA configuration from firmware configuration.
  984. */
  985. static void
  986. bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
  987. {
  988. struct bfi_ioc_attr_s *attr = ioc->attr;
  989. attr->adapter_prop = bfa_os_ntohl(attr->adapter_prop);
  990. attr->card_type = bfa_os_ntohl(attr->card_type);
  991. attr->maxfrsize = bfa_os_ntohs(attr->maxfrsize);
  992. bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
  993. }
  994. /**
  995. * Attach time initialization of mbox logic.
  996. */
  997. static void
  998. bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
  999. {
  1000. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1001. int mc;
  1002. INIT_LIST_HEAD(&mod->cmd_q);
  1003. for (mc = 0; mc < BFI_MC_MAX; mc++) {
  1004. mod->mbhdlr[mc].cbfn = NULL;
  1005. mod->mbhdlr[mc].cbarg = ioc->bfa;
  1006. }
  1007. }
  1008. /**
  1009. * Mbox poll timer -- restarts any pending mailbox requests.
  1010. */
  1011. static void
  1012. bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
  1013. {
  1014. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1015. struct bfa_mbox_cmd_s *cmd;
  1016. u32 stat;
  1017. /**
  1018. * If no command pending, do nothing
  1019. */
  1020. if (list_empty(&mod->cmd_q))
  1021. return;
  1022. /**
  1023. * If previous command is not yet fetched by firmware, do nothing
  1024. */
  1025. stat = bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd);
  1026. if (stat)
  1027. return;
  1028. /**
  1029. * Enqueue command to firmware.
  1030. */
  1031. bfa_q_deq(&mod->cmd_q, &cmd);
  1032. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1033. }
  1034. /**
  1035. * Cleanup any pending requests.
  1036. */
  1037. static void
  1038. bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc)
  1039. {
  1040. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1041. struct bfa_mbox_cmd_s *cmd;
  1042. while (!list_empty(&mod->cmd_q))
  1043. bfa_q_deq(&mod->cmd_q, &cmd);
  1044. }
  1045. /**
  1046. * bfa_ioc_public
  1047. */
  1048. /**
  1049. * Interface used by diag module to do firmware boot with memory test
  1050. * as the entry vector.
  1051. */
  1052. void
  1053. bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_param)
  1054. {
  1055. bfa_os_addr_t rb;
  1056. bfa_ioc_stats(ioc, ioc_boots);
  1057. if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
  1058. return;
  1059. /**
  1060. * Initialize IOC state of all functions on a chip reset.
  1061. */
  1062. rb = ioc->pcidev.pci_bar_kva;
  1063. if (boot_param == BFI_BOOT_TYPE_MEMTEST) {
  1064. bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_MEMTEST);
  1065. bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_MEMTEST);
  1066. } else {
  1067. bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_INITING);
  1068. bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_INITING);
  1069. }
  1070. bfa_ioc_download_fw(ioc, boot_type, boot_param);
  1071. /**
  1072. * Enable interrupts just before starting LPU
  1073. */
  1074. ioc->cbfn->reset_cbfn(ioc->bfa);
  1075. bfa_ioc_lpu_start(ioc);
  1076. }
  1077. /**
  1078. * Enable/disable IOC failure auto recovery.
  1079. */
  1080. void
  1081. bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
  1082. {
  1083. bfa_auto_recover = auto_recover;
  1084. }
  1085. bfa_boolean_t
  1086. bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
  1087. {
  1088. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
  1089. }
  1090. void
  1091. bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
  1092. {
  1093. u32 *msgp = mbmsg;
  1094. u32 r32;
  1095. int i;
  1096. /**
  1097. * read the MBOX msg
  1098. */
  1099. for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
  1100. i++) {
  1101. r32 = bfa_reg_read(ioc->ioc_regs.lpu_mbox +
  1102. i * sizeof(u32));
  1103. msgp[i] = bfa_os_htonl(r32);
  1104. }
  1105. /**
  1106. * turn off mailbox interrupt by clearing mailbox status
  1107. */
  1108. bfa_reg_write(ioc->ioc_regs.lpu_mbox_cmd, 1);
  1109. bfa_reg_read(ioc->ioc_regs.lpu_mbox_cmd);
  1110. }
  1111. void
  1112. bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
  1113. {
  1114. union bfi_ioc_i2h_msg_u *msg;
  1115. msg = (union bfi_ioc_i2h_msg_u *)m;
  1116. bfa_ioc_stats(ioc, ioc_isrs);
  1117. switch (msg->mh.msg_id) {
  1118. case BFI_IOC_I2H_HBEAT:
  1119. break;
  1120. case BFI_IOC_I2H_READY_EVENT:
  1121. bfa_fsm_send_event(ioc, IOC_E_FWREADY);
  1122. break;
  1123. case BFI_IOC_I2H_ENABLE_REPLY:
  1124. bfa_fsm_send_event(ioc, IOC_E_FWRSP_ENABLE);
  1125. break;
  1126. case BFI_IOC_I2H_DISABLE_REPLY:
  1127. bfa_fsm_send_event(ioc, IOC_E_FWRSP_DISABLE);
  1128. break;
  1129. case BFI_IOC_I2H_GETATTR_REPLY:
  1130. bfa_ioc_getattr_reply(ioc);
  1131. break;
  1132. default:
  1133. bfa_trc(ioc, msg->mh.msg_id);
  1134. bfa_assert(0);
  1135. }
  1136. }
  1137. /**
  1138. * IOC attach time initialization and setup.
  1139. *
  1140. * @param[in] ioc memory for IOC
  1141. * @param[in] bfa driver instance structure
  1142. * @param[in] trcmod kernel trace module
  1143. * @param[in] aen kernel aen event module
  1144. * @param[in] logm kernel logging module
  1145. */
  1146. void
  1147. bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
  1148. struct bfa_timer_mod_s *timer_mod, struct bfa_trc_mod_s *trcmod,
  1149. struct bfa_aen_s *aen, struct bfa_log_mod_s *logm)
  1150. {
  1151. ioc->bfa = bfa;
  1152. ioc->cbfn = cbfn;
  1153. ioc->timer_mod = timer_mod;
  1154. ioc->trcmod = trcmod;
  1155. ioc->aen = aen;
  1156. ioc->logm = logm;
  1157. ioc->fcmode = BFA_FALSE;
  1158. ioc->pllinit = BFA_FALSE;
  1159. ioc->dbg_fwsave_once = BFA_TRUE;
  1160. bfa_ioc_mbox_attach(ioc);
  1161. INIT_LIST_HEAD(&ioc->hb_notify_q);
  1162. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  1163. }
  1164. /**
  1165. * Driver detach time IOC cleanup.
  1166. */
  1167. void
  1168. bfa_ioc_detach(struct bfa_ioc_s *ioc)
  1169. {
  1170. bfa_fsm_send_event(ioc, IOC_E_DETACH);
  1171. }
  1172. /**
  1173. * Setup IOC PCI properties.
  1174. *
  1175. * @param[in] pcidev PCI device information for this IOC
  1176. */
  1177. void
  1178. bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  1179. enum bfi_mclass mc)
  1180. {
  1181. ioc->ioc_mc = mc;
  1182. ioc->pcidev = *pcidev;
  1183. ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
  1184. ioc->cna = ioc->ctdev && !ioc->fcmode;
  1185. /**
  1186. * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
  1187. */
  1188. if (ioc->ctdev)
  1189. bfa_ioc_set_ct_hwif(ioc);
  1190. else
  1191. bfa_ioc_set_cb_hwif(ioc);
  1192. bfa_ioc_map_port(ioc);
  1193. bfa_ioc_reg_init(ioc);
  1194. }
  1195. /**
  1196. * Initialize IOC dma memory
  1197. *
  1198. * @param[in] dm_kva kernel virtual address of IOC dma memory
  1199. * @param[in] dm_pa physical address of IOC dma memory
  1200. */
  1201. void
  1202. bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
  1203. {
  1204. /**
  1205. * dma memory for firmware attribute
  1206. */
  1207. ioc->attr_dma.kva = dm_kva;
  1208. ioc->attr_dma.pa = dm_pa;
  1209. ioc->attr = (struct bfi_ioc_attr_s *)dm_kva;
  1210. }
  1211. /**
  1212. * Return size of dma memory required.
  1213. */
  1214. u32
  1215. bfa_ioc_meminfo(void)
  1216. {
  1217. return BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ);
  1218. }
  1219. void
  1220. bfa_ioc_enable(struct bfa_ioc_s *ioc)
  1221. {
  1222. bfa_ioc_stats(ioc, ioc_enables);
  1223. ioc->dbg_fwsave_once = BFA_TRUE;
  1224. bfa_fsm_send_event(ioc, IOC_E_ENABLE);
  1225. }
  1226. void
  1227. bfa_ioc_disable(struct bfa_ioc_s *ioc)
  1228. {
  1229. bfa_ioc_stats(ioc, ioc_disables);
  1230. bfa_fsm_send_event(ioc, IOC_E_DISABLE);
  1231. }
  1232. /**
  1233. * Returns memory required for saving firmware trace in case of crash.
  1234. * Driver must call this interface to allocate memory required for
  1235. * automatic saving of firmware trace. Driver should call
  1236. * bfa_ioc_debug_memclaim() right after bfa_ioc_attach() to setup this
  1237. * trace memory.
  1238. */
  1239. int
  1240. bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover)
  1241. {
  1242. return (auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
  1243. }
  1244. /**
  1245. * Initialize memory for saving firmware trace. Driver must initialize
  1246. * trace memory before call bfa_ioc_enable().
  1247. */
  1248. void
  1249. bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
  1250. {
  1251. ioc->dbg_fwsave = dbg_fwsave;
  1252. ioc->dbg_fwsave_len = bfa_ioc_debug_trcsz(ioc->auto_recover);
  1253. }
  1254. u32
  1255. bfa_ioc_smem_pgnum(struct bfa_ioc_s *ioc, u32 fmaddr)
  1256. {
  1257. return PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, fmaddr);
  1258. }
  1259. u32
  1260. bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr)
  1261. {
  1262. return PSS_SMEM_PGOFF(fmaddr);
  1263. }
  1264. /**
  1265. * Register mailbox message handler functions
  1266. *
  1267. * @param[in] ioc IOC instance
  1268. * @param[in] mcfuncs message class handler functions
  1269. */
  1270. void
  1271. bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
  1272. {
  1273. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1274. int mc;
  1275. for (mc = 0; mc < BFI_MC_MAX; mc++)
  1276. mod->mbhdlr[mc].cbfn = mcfuncs[mc];
  1277. }
  1278. /**
  1279. * Register mailbox message handler function, to be called by common modules
  1280. */
  1281. void
  1282. bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  1283. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
  1284. {
  1285. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1286. mod->mbhdlr[mc].cbfn = cbfn;
  1287. mod->mbhdlr[mc].cbarg = cbarg;
  1288. }
  1289. /**
  1290. * Queue a mailbox command request to firmware. Waits if mailbox is busy.
  1291. * Responsibility of caller to serialize
  1292. *
  1293. * @param[in] ioc IOC instance
  1294. * @param[i] cmd Mailbox command
  1295. */
  1296. void
  1297. bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
  1298. {
  1299. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1300. u32 stat;
  1301. /**
  1302. * If a previous command is pending, queue new command
  1303. */
  1304. if (!list_empty(&mod->cmd_q)) {
  1305. list_add_tail(&cmd->qe, &mod->cmd_q);
  1306. return;
  1307. }
  1308. /**
  1309. * If mailbox is busy, queue command for poll timer
  1310. */
  1311. stat = bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd);
  1312. if (stat) {
  1313. list_add_tail(&cmd->qe, &mod->cmd_q);
  1314. return;
  1315. }
  1316. /**
  1317. * mailbox is free -- queue command to firmware
  1318. */
  1319. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1320. }
  1321. /**
  1322. * Handle mailbox interrupts
  1323. */
  1324. void
  1325. bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
  1326. {
  1327. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1328. struct bfi_mbmsg_s m;
  1329. int mc;
  1330. bfa_ioc_msgget(ioc, &m);
  1331. /**
  1332. * Treat IOC message class as special.
  1333. */
  1334. mc = m.mh.msg_class;
  1335. if (mc == BFI_MC_IOC) {
  1336. bfa_ioc_isr(ioc, &m);
  1337. return;
  1338. }
  1339. if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
  1340. return;
  1341. mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
  1342. }
  1343. void
  1344. bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
  1345. {
  1346. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  1347. }
  1348. #ifndef BFA_BIOS_BUILD
  1349. /**
  1350. * return true if IOC is disabled
  1351. */
  1352. bfa_boolean_t
  1353. bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
  1354. {
  1355. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling)
  1356. || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
  1357. }
  1358. /**
  1359. * return true if IOC firmware is different.
  1360. */
  1361. bfa_boolean_t
  1362. bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
  1363. {
  1364. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset)
  1365. || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_fwcheck)
  1366. || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_mismatch);
  1367. }
  1368. #define bfa_ioc_state_disabled(__sm) \
  1369. (((__sm) == BFI_IOC_UNINIT) || \
  1370. ((__sm) == BFI_IOC_INITING) || \
  1371. ((__sm) == BFI_IOC_HWINIT) || \
  1372. ((__sm) == BFI_IOC_DISABLED) || \
  1373. ((__sm) == BFI_IOC_FAIL) || \
  1374. ((__sm) == BFI_IOC_CFG_DISABLED))
  1375. /**
  1376. * Check if adapter is disabled -- both IOCs should be in a disabled
  1377. * state.
  1378. */
  1379. bfa_boolean_t
  1380. bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
  1381. {
  1382. u32 ioc_state;
  1383. bfa_os_addr_t rb = ioc->pcidev.pci_bar_kva;
  1384. if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
  1385. return BFA_FALSE;
  1386. ioc_state = bfa_reg_read(rb + BFA_IOC0_STATE_REG);
  1387. if (!bfa_ioc_state_disabled(ioc_state))
  1388. return BFA_FALSE;
  1389. ioc_state = bfa_reg_read(rb + BFA_IOC1_STATE_REG);
  1390. if (!bfa_ioc_state_disabled(ioc_state))
  1391. return BFA_FALSE;
  1392. return BFA_TRUE;
  1393. }
  1394. /**
  1395. * Add to IOC heartbeat failure notification queue. To be used by common
  1396. * modules such as
  1397. */
  1398. void
  1399. bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc,
  1400. struct bfa_ioc_hbfail_notify_s *notify)
  1401. {
  1402. list_add_tail(&notify->qe, &ioc->hb_notify_q);
  1403. }
  1404. #define BFA_MFG_NAME "Brocade"
  1405. void
  1406. bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  1407. struct bfa_adapter_attr_s *ad_attr)
  1408. {
  1409. struct bfi_ioc_attr_s *ioc_attr;
  1410. ioc_attr = ioc->attr;
  1411. bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
  1412. bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
  1413. bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
  1414. bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
  1415. bfa_os_memcpy(&ad_attr->vpd, &ioc_attr->vpd,
  1416. sizeof(struct bfa_mfg_vpd_s));
  1417. ad_attr->nports = bfa_ioc_get_nports(ioc);
  1418. ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
  1419. bfa_ioc_get_adapter_model(ioc, ad_attr->model);
  1420. /* For now, model descr uses same model string */
  1421. bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
  1422. if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
  1423. ad_attr->prototype = 1;
  1424. else
  1425. ad_attr->prototype = 0;
  1426. ad_attr->pwwn = bfa_ioc_get_pwwn(ioc);
  1427. ad_attr->mac = bfa_ioc_get_mac(ioc);
  1428. ad_attr->pcie_gen = ioc_attr->pcie_gen;
  1429. ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
  1430. ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
  1431. ad_attr->asic_rev = ioc_attr->asic_rev;
  1432. bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
  1433. ad_attr->cna_capable = ioc->cna;
  1434. }
  1435. enum bfa_ioc_type_e
  1436. bfa_ioc_get_type(struct bfa_ioc_s *ioc)
  1437. {
  1438. if (!ioc->ctdev || ioc->fcmode)
  1439. return BFA_IOC_TYPE_FC;
  1440. else if (ioc->ioc_mc == BFI_MC_IOCFC)
  1441. return BFA_IOC_TYPE_FCoE;
  1442. else if (ioc->ioc_mc == BFI_MC_LL)
  1443. return BFA_IOC_TYPE_LL;
  1444. else {
  1445. bfa_assert(ioc->ioc_mc == BFI_MC_LL);
  1446. return BFA_IOC_TYPE_LL;
  1447. }
  1448. }
  1449. void
  1450. bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
  1451. {
  1452. bfa_os_memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
  1453. bfa_os_memcpy((void *)serial_num,
  1454. (void *)ioc->attr->brcd_serialnum,
  1455. BFA_ADAPTER_SERIAL_NUM_LEN);
  1456. }
  1457. void
  1458. bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
  1459. {
  1460. bfa_os_memset((void *)fw_ver, 0, BFA_VERSION_LEN);
  1461. bfa_os_memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
  1462. }
  1463. void
  1464. bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
  1465. {
  1466. bfa_assert(chip_rev);
  1467. bfa_os_memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
  1468. chip_rev[0] = 'R';
  1469. chip_rev[1] = 'e';
  1470. chip_rev[2] = 'v';
  1471. chip_rev[3] = '-';
  1472. chip_rev[4] = ioc->attr->asic_rev;
  1473. chip_rev[5] = '\0';
  1474. }
  1475. void
  1476. bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
  1477. {
  1478. bfa_os_memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
  1479. bfa_os_memcpy(optrom_ver, ioc->attr->optrom_version,
  1480. BFA_VERSION_LEN);
  1481. }
  1482. void
  1483. bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
  1484. {
  1485. bfa_os_memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
  1486. bfa_os_memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
  1487. }
  1488. void
  1489. bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
  1490. {
  1491. struct bfi_ioc_attr_s *ioc_attr;
  1492. u8 nports;
  1493. u8 max_speed;
  1494. bfa_assert(model);
  1495. bfa_os_memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
  1496. ioc_attr = ioc->attr;
  1497. nports = bfa_ioc_get_nports(ioc);
  1498. max_speed = bfa_ioc_speed_sup(ioc);
  1499. /**
  1500. * model name
  1501. */
  1502. if (max_speed == 10) {
  1503. strcpy(model, "BR-10?0");
  1504. model[5] = '0' + nports;
  1505. } else {
  1506. strcpy(model, "Brocade-??5");
  1507. model[8] = '0' + max_speed;
  1508. model[9] = '0' + nports;
  1509. }
  1510. }
  1511. enum bfa_ioc_state
  1512. bfa_ioc_get_state(struct bfa_ioc_s *ioc)
  1513. {
  1514. return bfa_sm_to_state(ioc_sm_table, ioc->fsm);
  1515. }
  1516. void
  1517. bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
  1518. {
  1519. bfa_os_memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
  1520. ioc_attr->state = bfa_ioc_get_state(ioc);
  1521. ioc_attr->port_id = ioc->port_id;
  1522. ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
  1523. bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
  1524. ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
  1525. ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
  1526. bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
  1527. }
  1528. /**
  1529. * hal_wwn_public
  1530. */
  1531. wwn_t
  1532. bfa_ioc_get_pwwn(struct bfa_ioc_s *ioc)
  1533. {
  1534. union {
  1535. wwn_t wwn;
  1536. u8 byte[sizeof(wwn_t)];
  1537. }
  1538. w;
  1539. w.wwn = ioc->attr->mfg_wwn;
  1540. if (bfa_ioc_portid(ioc) == 1)
  1541. w.byte[7]++;
  1542. return w.wwn;
  1543. }
  1544. wwn_t
  1545. bfa_ioc_get_nwwn(struct bfa_ioc_s *ioc)
  1546. {
  1547. union {
  1548. wwn_t wwn;
  1549. u8 byte[sizeof(wwn_t)];
  1550. }
  1551. w;
  1552. w.wwn = ioc->attr->mfg_wwn;
  1553. if (bfa_ioc_portid(ioc) == 1)
  1554. w.byte[7]++;
  1555. w.byte[0] = 0x20;
  1556. return w.wwn;
  1557. }
  1558. wwn_t
  1559. bfa_ioc_get_wwn_naa5(struct bfa_ioc_s *ioc, u16 inst)
  1560. {
  1561. union {
  1562. wwn_t wwn;
  1563. u8 byte[sizeof(wwn_t)];
  1564. }
  1565. w , w5;
  1566. bfa_trc(ioc, inst);
  1567. w.wwn = ioc->attr->mfg_wwn;
  1568. w5.byte[0] = 0x50 | w.byte[2] >> 4;
  1569. w5.byte[1] = w.byte[2] << 4 | w.byte[3] >> 4;
  1570. w5.byte[2] = w.byte[3] << 4 | w.byte[4] >> 4;
  1571. w5.byte[3] = w.byte[4] << 4 | w.byte[5] >> 4;
  1572. w5.byte[4] = w.byte[5] << 4 | w.byte[6] >> 4;
  1573. w5.byte[5] = w.byte[6] << 4 | w.byte[7] >> 4;
  1574. w5.byte[6] = w.byte[7] << 4 | (inst & 0x0f00) >> 8;
  1575. w5.byte[7] = (inst & 0xff);
  1576. return w5.wwn;
  1577. }
  1578. u64
  1579. bfa_ioc_get_adid(struct bfa_ioc_s *ioc)
  1580. {
  1581. return ioc->attr->mfg_wwn;
  1582. }
  1583. mac_t
  1584. bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
  1585. {
  1586. mac_t mac;
  1587. mac = ioc->attr->mfg_mac;
  1588. mac.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
  1589. return mac;
  1590. }
  1591. void
  1592. bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
  1593. {
  1594. ioc->fcmode = BFA_TRUE;
  1595. ioc->port_id = bfa_ioc_pcifn(ioc);
  1596. }
  1597. bfa_boolean_t
  1598. bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
  1599. {
  1600. return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id);
  1601. }
  1602. /**
  1603. * Send AEN notification
  1604. */
  1605. static void
  1606. bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
  1607. {
  1608. union bfa_aen_data_u aen_data;
  1609. struct bfa_log_mod_s *logmod = ioc->logm;
  1610. s32 inst_num = 0;
  1611. enum bfa_ioc_type_e ioc_type;
  1612. bfa_log(logmod, BFA_LOG_CREATE_ID(BFA_AEN_CAT_IOC, event), inst_num);
  1613. memset(&aen_data.ioc.pwwn, 0, sizeof(aen_data.ioc.pwwn));
  1614. memset(&aen_data.ioc.mac, 0, sizeof(aen_data.ioc.mac));
  1615. ioc_type = bfa_ioc_get_type(ioc);
  1616. switch (ioc_type) {
  1617. case BFA_IOC_TYPE_FC:
  1618. aen_data.ioc.pwwn = bfa_ioc_get_pwwn(ioc);
  1619. break;
  1620. case BFA_IOC_TYPE_FCoE:
  1621. aen_data.ioc.pwwn = bfa_ioc_get_pwwn(ioc);
  1622. aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  1623. break;
  1624. case BFA_IOC_TYPE_LL:
  1625. aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  1626. break;
  1627. default:
  1628. bfa_assert(ioc_type == BFA_IOC_TYPE_FC);
  1629. break;
  1630. }
  1631. aen_data.ioc.ioc_type = ioc_type;
  1632. }
  1633. /**
  1634. * Retrieve saved firmware trace from a prior IOC failure.
  1635. */
  1636. bfa_status_t
  1637. bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  1638. {
  1639. int tlen;
  1640. if (ioc->dbg_fwsave_len == 0)
  1641. return BFA_STATUS_ENOFSAVE;
  1642. tlen = *trclen;
  1643. if (tlen > ioc->dbg_fwsave_len)
  1644. tlen = ioc->dbg_fwsave_len;
  1645. bfa_os_memcpy(trcdata, ioc->dbg_fwsave, tlen);
  1646. *trclen = tlen;
  1647. return BFA_STATUS_OK;
  1648. }
  1649. /**
  1650. * Clear saved firmware trace
  1651. */
  1652. void
  1653. bfa_ioc_debug_fwsave_clear(struct bfa_ioc_s *ioc)
  1654. {
  1655. ioc->dbg_fwsave_once = BFA_TRUE;
  1656. }
  1657. /**
  1658. * Retrieve saved firmware trace from a prior IOC failure.
  1659. */
  1660. bfa_status_t
  1661. bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  1662. {
  1663. u32 pgnum;
  1664. u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
  1665. int i, tlen;
  1666. u32 *tbuf = trcdata, r32;
  1667. bfa_trc(ioc, *trclen);
  1668. pgnum = bfa_ioc_smem_pgnum(ioc, loff);
  1669. loff = bfa_ioc_smem_pgoff(ioc, loff);
  1670. /*
  1671. * Hold semaphore to serialize pll init and fwtrc.
  1672. */
  1673. if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg))
  1674. return BFA_STATUS_FAILED;
  1675. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  1676. tlen = *trclen;
  1677. if (tlen > BFA_DBG_FWTRC_LEN)
  1678. tlen = BFA_DBG_FWTRC_LEN;
  1679. tlen /= sizeof(u32);
  1680. bfa_trc(ioc, tlen);
  1681. for (i = 0; i < tlen; i++) {
  1682. r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  1683. tbuf[i] = bfa_os_ntohl(r32);
  1684. loff += sizeof(u32);
  1685. /**
  1686. * handle page offset wrap around
  1687. */
  1688. loff = PSS_SMEM_PGOFF(loff);
  1689. if (loff == 0) {
  1690. pgnum++;
  1691. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  1692. }
  1693. }
  1694. bfa_reg_write(ioc->ioc_regs.host_page_num_fn,
  1695. bfa_ioc_smem_pgnum(ioc, 0));
  1696. /*
  1697. * release semaphore.
  1698. */
  1699. bfa_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
  1700. bfa_trc(ioc, pgnum);
  1701. *trclen = tlen * sizeof(u32);
  1702. return BFA_STATUS_OK;
  1703. }
  1704. /**
  1705. * Save firmware trace if configured.
  1706. */
  1707. static void
  1708. bfa_ioc_debug_save(struct bfa_ioc_s *ioc)
  1709. {
  1710. int tlen;
  1711. if (ioc->dbg_fwsave_len) {
  1712. tlen = ioc->dbg_fwsave_len;
  1713. bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
  1714. }
  1715. }
  1716. /**
  1717. * Firmware failure detected. Start recovery actions.
  1718. */
  1719. static void
  1720. bfa_ioc_recover(struct bfa_ioc_s *ioc)
  1721. {
  1722. if (ioc->dbg_fwsave_once) {
  1723. ioc->dbg_fwsave_once = BFA_FALSE;
  1724. bfa_ioc_debug_save(ioc);
  1725. }
  1726. bfa_ioc_stats(ioc, ioc_hbfails);
  1727. bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
  1728. }
  1729. #else
  1730. static void
  1731. bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
  1732. {
  1733. }
  1734. static void
  1735. bfa_ioc_recover(struct bfa_ioc_s *ioc)
  1736. {
  1737. bfa_assert(0);
  1738. }
  1739. #endif