bfa_ioc.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088
  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. pgnum = bfa_ioc_smem_pgnum(ioc, loff);
  946. pgoff = bfa_ioc_smem_pgoff(ioc, loff);
  947. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  948. for (i = 0; i < bfa_ioc_fwimg_get_size(ioc); i++) {
  949. if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
  950. chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
  951. fwimg = bfa_ioc_fwimg_get_chunk(ioc,
  952. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  953. }
  954. /**
  955. * write smem
  956. */
  957. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
  958. fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
  959. loff += sizeof(u32);
  960. /**
  961. * handle page offset wrap around
  962. */
  963. loff = PSS_SMEM_PGOFF(loff);
  964. if (loff == 0) {
  965. pgnum++;
  966. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  967. }
  968. }
  969. bfa_reg_write(ioc->ioc_regs.host_page_num_fn,
  970. bfa_ioc_smem_pgnum(ioc, 0));
  971. /*
  972. * Set boot type and boot param at the end.
  973. */
  974. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF,
  975. bfa_os_swap32(boot_type));
  976. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_PARAM_OFF,
  977. bfa_os_swap32(boot_param));
  978. }
  979. static void
  980. bfa_ioc_reset(struct bfa_ioc_s *ioc, bfa_boolean_t force)
  981. {
  982. bfa_ioc_hwinit(ioc, force);
  983. }
  984. /**
  985. * Update BFA configuration from firmware configuration.
  986. */
  987. static void
  988. bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
  989. {
  990. struct bfi_ioc_attr_s *attr = ioc->attr;
  991. attr->adapter_prop = bfa_os_ntohl(attr->adapter_prop);
  992. attr->maxfrsize = bfa_os_ntohs(attr->maxfrsize);
  993. bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
  994. }
  995. /**
  996. * Attach time initialization of mbox logic.
  997. */
  998. static void
  999. bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
  1000. {
  1001. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1002. int mc;
  1003. INIT_LIST_HEAD(&mod->cmd_q);
  1004. for (mc = 0; mc < BFI_MC_MAX; mc++) {
  1005. mod->mbhdlr[mc].cbfn = NULL;
  1006. mod->mbhdlr[mc].cbarg = ioc->bfa;
  1007. }
  1008. }
  1009. /**
  1010. * Mbox poll timer -- restarts any pending mailbox requests.
  1011. */
  1012. static void
  1013. bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
  1014. {
  1015. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1016. struct bfa_mbox_cmd_s *cmd;
  1017. u32 stat;
  1018. /**
  1019. * If no command pending, do nothing
  1020. */
  1021. if (list_empty(&mod->cmd_q))
  1022. return;
  1023. /**
  1024. * If previous command is not yet fetched by firmware, do nothing
  1025. */
  1026. stat = bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd);
  1027. if (stat)
  1028. return;
  1029. /**
  1030. * Enqueue command to firmware.
  1031. */
  1032. bfa_q_deq(&mod->cmd_q, &cmd);
  1033. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1034. }
  1035. /**
  1036. * Cleanup any pending requests.
  1037. */
  1038. static void
  1039. bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc)
  1040. {
  1041. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1042. struct bfa_mbox_cmd_s *cmd;
  1043. while (!list_empty(&mod->cmd_q))
  1044. bfa_q_deq(&mod->cmd_q, &cmd);
  1045. }
  1046. /**
  1047. * bfa_ioc_public
  1048. */
  1049. /**
  1050. * Interface used by diag module to do firmware boot with memory test
  1051. * as the entry vector.
  1052. */
  1053. void
  1054. bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_param)
  1055. {
  1056. bfa_os_addr_t rb;
  1057. bfa_ioc_stats(ioc, ioc_boots);
  1058. if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
  1059. return;
  1060. /**
  1061. * Initialize IOC state of all functions on a chip reset.
  1062. */
  1063. rb = ioc->pcidev.pci_bar_kva;
  1064. if (boot_param == BFI_BOOT_TYPE_MEMTEST) {
  1065. bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_MEMTEST);
  1066. bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_MEMTEST);
  1067. } else {
  1068. bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_INITING);
  1069. bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_INITING);
  1070. }
  1071. bfa_ioc_download_fw(ioc, boot_type, boot_param);
  1072. /**
  1073. * Enable interrupts just before starting LPU
  1074. */
  1075. ioc->cbfn->reset_cbfn(ioc->bfa);
  1076. bfa_ioc_lpu_start(ioc);
  1077. }
  1078. /**
  1079. * Enable/disable IOC failure auto recovery.
  1080. */
  1081. void
  1082. bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
  1083. {
  1084. bfa_auto_recover = auto_recover;
  1085. }
  1086. bfa_boolean_t
  1087. bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
  1088. {
  1089. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
  1090. }
  1091. void
  1092. bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
  1093. {
  1094. u32 *msgp = mbmsg;
  1095. u32 r32;
  1096. int i;
  1097. /**
  1098. * read the MBOX msg
  1099. */
  1100. for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
  1101. i++) {
  1102. r32 = bfa_reg_read(ioc->ioc_regs.lpu_mbox +
  1103. i * sizeof(u32));
  1104. msgp[i] = bfa_os_htonl(r32);
  1105. }
  1106. /**
  1107. * turn off mailbox interrupt by clearing mailbox status
  1108. */
  1109. bfa_reg_write(ioc->ioc_regs.lpu_mbox_cmd, 1);
  1110. bfa_reg_read(ioc->ioc_regs.lpu_mbox_cmd);
  1111. }
  1112. void
  1113. bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
  1114. {
  1115. union bfi_ioc_i2h_msg_u *msg;
  1116. msg = (union bfi_ioc_i2h_msg_u *)m;
  1117. bfa_ioc_stats(ioc, ioc_isrs);
  1118. switch (msg->mh.msg_id) {
  1119. case BFI_IOC_I2H_HBEAT:
  1120. break;
  1121. case BFI_IOC_I2H_READY_EVENT:
  1122. bfa_fsm_send_event(ioc, IOC_E_FWREADY);
  1123. break;
  1124. case BFI_IOC_I2H_ENABLE_REPLY:
  1125. bfa_fsm_send_event(ioc, IOC_E_FWRSP_ENABLE);
  1126. break;
  1127. case BFI_IOC_I2H_DISABLE_REPLY:
  1128. bfa_fsm_send_event(ioc, IOC_E_FWRSP_DISABLE);
  1129. break;
  1130. case BFI_IOC_I2H_GETATTR_REPLY:
  1131. bfa_ioc_getattr_reply(ioc);
  1132. break;
  1133. default:
  1134. bfa_trc(ioc, msg->mh.msg_id);
  1135. bfa_assert(0);
  1136. }
  1137. }
  1138. /**
  1139. * IOC attach time initialization and setup.
  1140. *
  1141. * @param[in] ioc memory for IOC
  1142. * @param[in] bfa driver instance structure
  1143. * @param[in] trcmod kernel trace module
  1144. * @param[in] aen kernel aen event module
  1145. * @param[in] logm kernel logging module
  1146. */
  1147. void
  1148. bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
  1149. struct bfa_timer_mod_s *timer_mod, struct bfa_trc_mod_s *trcmod,
  1150. struct bfa_aen_s *aen, struct bfa_log_mod_s *logm)
  1151. {
  1152. ioc->bfa = bfa;
  1153. ioc->cbfn = cbfn;
  1154. ioc->timer_mod = timer_mod;
  1155. ioc->trcmod = trcmod;
  1156. ioc->aen = aen;
  1157. ioc->logm = logm;
  1158. ioc->fcmode = BFA_FALSE;
  1159. ioc->pllinit = BFA_FALSE;
  1160. ioc->dbg_fwsave_once = BFA_TRUE;
  1161. bfa_ioc_mbox_attach(ioc);
  1162. INIT_LIST_HEAD(&ioc->hb_notify_q);
  1163. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  1164. }
  1165. /**
  1166. * Driver detach time IOC cleanup.
  1167. */
  1168. void
  1169. bfa_ioc_detach(struct bfa_ioc_s *ioc)
  1170. {
  1171. bfa_fsm_send_event(ioc, IOC_E_DETACH);
  1172. }
  1173. /**
  1174. * Setup IOC PCI properties.
  1175. *
  1176. * @param[in] pcidev PCI device information for this IOC
  1177. */
  1178. void
  1179. bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  1180. enum bfi_mclass mc)
  1181. {
  1182. ioc->ioc_mc = mc;
  1183. ioc->pcidev = *pcidev;
  1184. ioc->ctdev = (ioc->pcidev.device_id == BFA_PCI_DEVICE_ID_CT);
  1185. ioc->cna = ioc->ctdev && !ioc->fcmode;
  1186. /**
  1187. * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
  1188. */
  1189. if (ioc->ctdev)
  1190. bfa_ioc_set_ct_hwif(ioc);
  1191. else
  1192. bfa_ioc_set_cb_hwif(ioc);
  1193. bfa_ioc_map_port(ioc);
  1194. bfa_ioc_reg_init(ioc);
  1195. }
  1196. /**
  1197. * Initialize IOC dma memory
  1198. *
  1199. * @param[in] dm_kva kernel virtual address of IOC dma memory
  1200. * @param[in] dm_pa physical address of IOC dma memory
  1201. */
  1202. void
  1203. bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
  1204. {
  1205. /**
  1206. * dma memory for firmware attribute
  1207. */
  1208. ioc->attr_dma.kva = dm_kva;
  1209. ioc->attr_dma.pa = dm_pa;
  1210. ioc->attr = (struct bfi_ioc_attr_s *)dm_kva;
  1211. }
  1212. /**
  1213. * Return size of dma memory required.
  1214. */
  1215. u32
  1216. bfa_ioc_meminfo(void)
  1217. {
  1218. return BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ);
  1219. }
  1220. void
  1221. bfa_ioc_enable(struct bfa_ioc_s *ioc)
  1222. {
  1223. bfa_ioc_stats(ioc, ioc_enables);
  1224. ioc->dbg_fwsave_once = BFA_TRUE;
  1225. bfa_fsm_send_event(ioc, IOC_E_ENABLE);
  1226. }
  1227. void
  1228. bfa_ioc_disable(struct bfa_ioc_s *ioc)
  1229. {
  1230. bfa_ioc_stats(ioc, ioc_disables);
  1231. bfa_fsm_send_event(ioc, IOC_E_DISABLE);
  1232. }
  1233. /**
  1234. * Returns memory required for saving firmware trace in case of crash.
  1235. * Driver must call this interface to allocate memory required for
  1236. * automatic saving of firmware trace. Driver should call
  1237. * bfa_ioc_debug_memclaim() right after bfa_ioc_attach() to setup this
  1238. * trace memory.
  1239. */
  1240. int
  1241. bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover)
  1242. {
  1243. return (auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
  1244. }
  1245. /**
  1246. * Initialize memory for saving firmware trace. Driver must initialize
  1247. * trace memory before call bfa_ioc_enable().
  1248. */
  1249. void
  1250. bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
  1251. {
  1252. ioc->dbg_fwsave = dbg_fwsave;
  1253. ioc->dbg_fwsave_len = bfa_ioc_debug_trcsz(ioc->auto_recover);
  1254. }
  1255. u32
  1256. bfa_ioc_smem_pgnum(struct bfa_ioc_s *ioc, u32 fmaddr)
  1257. {
  1258. return PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, fmaddr);
  1259. }
  1260. u32
  1261. bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr)
  1262. {
  1263. return PSS_SMEM_PGOFF(fmaddr);
  1264. }
  1265. /**
  1266. * Register mailbox message handler functions
  1267. *
  1268. * @param[in] ioc IOC instance
  1269. * @param[in] mcfuncs message class handler functions
  1270. */
  1271. void
  1272. bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
  1273. {
  1274. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1275. int mc;
  1276. for (mc = 0; mc < BFI_MC_MAX; mc++)
  1277. mod->mbhdlr[mc].cbfn = mcfuncs[mc];
  1278. }
  1279. /**
  1280. * Register mailbox message handler function, to be called by common modules
  1281. */
  1282. void
  1283. bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  1284. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
  1285. {
  1286. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1287. mod->mbhdlr[mc].cbfn = cbfn;
  1288. mod->mbhdlr[mc].cbarg = cbarg;
  1289. }
  1290. /**
  1291. * Queue a mailbox command request to firmware. Waits if mailbox is busy.
  1292. * Responsibility of caller to serialize
  1293. *
  1294. * @param[in] ioc IOC instance
  1295. * @param[i] cmd Mailbox command
  1296. */
  1297. void
  1298. bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
  1299. {
  1300. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1301. u32 stat;
  1302. /**
  1303. * If a previous command is pending, queue new command
  1304. */
  1305. if (!list_empty(&mod->cmd_q)) {
  1306. list_add_tail(&cmd->qe, &mod->cmd_q);
  1307. return;
  1308. }
  1309. /**
  1310. * If mailbox is busy, queue command for poll timer
  1311. */
  1312. stat = bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd);
  1313. if (stat) {
  1314. list_add_tail(&cmd->qe, &mod->cmd_q);
  1315. return;
  1316. }
  1317. /**
  1318. * mailbox is free -- queue command to firmware
  1319. */
  1320. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1321. }
  1322. /**
  1323. * Handle mailbox interrupts
  1324. */
  1325. void
  1326. bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
  1327. {
  1328. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1329. struct bfi_mbmsg_s m;
  1330. int mc;
  1331. bfa_ioc_msgget(ioc, &m);
  1332. /**
  1333. * Treat IOC message class as special.
  1334. */
  1335. mc = m.mh.msg_class;
  1336. if (mc == BFI_MC_IOC) {
  1337. bfa_ioc_isr(ioc, &m);
  1338. return;
  1339. }
  1340. if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
  1341. return;
  1342. mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
  1343. }
  1344. void
  1345. bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
  1346. {
  1347. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  1348. }
  1349. #ifndef BFA_BIOS_BUILD
  1350. /**
  1351. * return true if IOC is disabled
  1352. */
  1353. bfa_boolean_t
  1354. bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
  1355. {
  1356. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling)
  1357. || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
  1358. }
  1359. /**
  1360. * return true if IOC firmware is different.
  1361. */
  1362. bfa_boolean_t
  1363. bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
  1364. {
  1365. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset)
  1366. || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_fwcheck)
  1367. || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_mismatch);
  1368. }
  1369. #define bfa_ioc_state_disabled(__sm) \
  1370. (((__sm) == BFI_IOC_UNINIT) || \
  1371. ((__sm) == BFI_IOC_INITING) || \
  1372. ((__sm) == BFI_IOC_HWINIT) || \
  1373. ((__sm) == BFI_IOC_DISABLED) || \
  1374. ((__sm) == BFI_IOC_FAIL) || \
  1375. ((__sm) == BFI_IOC_CFG_DISABLED))
  1376. /**
  1377. * Check if adapter is disabled -- both IOCs should be in a disabled
  1378. * state.
  1379. */
  1380. bfa_boolean_t
  1381. bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
  1382. {
  1383. u32 ioc_state;
  1384. bfa_os_addr_t rb = ioc->pcidev.pci_bar_kva;
  1385. if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
  1386. return BFA_FALSE;
  1387. ioc_state = bfa_reg_read(rb + BFA_IOC0_STATE_REG);
  1388. if (!bfa_ioc_state_disabled(ioc_state))
  1389. return BFA_FALSE;
  1390. ioc_state = bfa_reg_read(rb + BFA_IOC1_STATE_REG);
  1391. if (!bfa_ioc_state_disabled(ioc_state))
  1392. return BFA_FALSE;
  1393. return BFA_TRUE;
  1394. }
  1395. /**
  1396. * Add to IOC heartbeat failure notification queue. To be used by common
  1397. * modules such as
  1398. */
  1399. void
  1400. bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc,
  1401. struct bfa_ioc_hbfail_notify_s *notify)
  1402. {
  1403. list_add_tail(&notify->qe, &ioc->hb_notify_q);
  1404. }
  1405. #define BFA_MFG_NAME "Brocade"
  1406. void
  1407. bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  1408. struct bfa_adapter_attr_s *ad_attr)
  1409. {
  1410. struct bfi_ioc_attr_s *ioc_attr;
  1411. ioc_attr = ioc->attr;
  1412. bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
  1413. bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
  1414. bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
  1415. bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
  1416. bfa_os_memcpy(&ad_attr->vpd, &ioc_attr->vpd,
  1417. sizeof(struct bfa_mfg_vpd_s));
  1418. ad_attr->nports = bfa_ioc_get_nports(ioc);
  1419. ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
  1420. bfa_ioc_get_adapter_model(ioc, ad_attr->model);
  1421. /* For now, model descr uses same model string */
  1422. bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
  1423. if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
  1424. ad_attr->prototype = 1;
  1425. else
  1426. ad_attr->prototype = 0;
  1427. ad_attr->pwwn = bfa_ioc_get_pwwn(ioc);
  1428. ad_attr->mac = bfa_ioc_get_mac(ioc);
  1429. ad_attr->pcie_gen = ioc_attr->pcie_gen;
  1430. ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
  1431. ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
  1432. ad_attr->asic_rev = ioc_attr->asic_rev;
  1433. bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
  1434. ad_attr->cna_capable = ioc->cna;
  1435. }
  1436. enum bfa_ioc_type_e
  1437. bfa_ioc_get_type(struct bfa_ioc_s *ioc)
  1438. {
  1439. if (!ioc->ctdev || ioc->fcmode)
  1440. return BFA_IOC_TYPE_FC;
  1441. else if (ioc->ioc_mc == BFI_MC_IOCFC)
  1442. return BFA_IOC_TYPE_FCoE;
  1443. else if (ioc->ioc_mc == BFI_MC_LL)
  1444. return BFA_IOC_TYPE_LL;
  1445. else {
  1446. bfa_assert(ioc->ioc_mc == BFI_MC_LL);
  1447. return BFA_IOC_TYPE_LL;
  1448. }
  1449. }
  1450. void
  1451. bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
  1452. {
  1453. bfa_os_memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
  1454. bfa_os_memcpy((void *)serial_num,
  1455. (void *)ioc->attr->brcd_serialnum,
  1456. BFA_ADAPTER_SERIAL_NUM_LEN);
  1457. }
  1458. void
  1459. bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
  1460. {
  1461. bfa_os_memset((void *)fw_ver, 0, BFA_VERSION_LEN);
  1462. bfa_os_memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
  1463. }
  1464. void
  1465. bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
  1466. {
  1467. bfa_assert(chip_rev);
  1468. bfa_os_memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
  1469. chip_rev[0] = 'R';
  1470. chip_rev[1] = 'e';
  1471. chip_rev[2] = 'v';
  1472. chip_rev[3] = '-';
  1473. chip_rev[4] = ioc->attr->asic_rev;
  1474. chip_rev[5] = '\0';
  1475. }
  1476. void
  1477. bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
  1478. {
  1479. bfa_os_memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
  1480. bfa_os_memcpy(optrom_ver, ioc->attr->optrom_version,
  1481. BFA_VERSION_LEN);
  1482. }
  1483. void
  1484. bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
  1485. {
  1486. bfa_os_memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
  1487. bfa_os_memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
  1488. }
  1489. void
  1490. bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
  1491. {
  1492. struct bfi_ioc_attr_s *ioc_attr;
  1493. u8 nports;
  1494. u8 max_speed;
  1495. bfa_assert(model);
  1496. bfa_os_memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
  1497. ioc_attr = ioc->attr;
  1498. nports = bfa_ioc_get_nports(ioc);
  1499. max_speed = bfa_ioc_speed_sup(ioc);
  1500. /**
  1501. * model name
  1502. */
  1503. if (max_speed == 10) {
  1504. strcpy(model, "BR-10?0");
  1505. model[5] = '0' + nports;
  1506. } else {
  1507. strcpy(model, "Brocade-??5");
  1508. model[8] = '0' + max_speed;
  1509. model[9] = '0' + nports;
  1510. }
  1511. }
  1512. enum bfa_ioc_state
  1513. bfa_ioc_get_state(struct bfa_ioc_s *ioc)
  1514. {
  1515. return bfa_sm_to_state(ioc_sm_table, ioc->fsm);
  1516. }
  1517. void
  1518. bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
  1519. {
  1520. bfa_os_memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
  1521. ioc_attr->state = bfa_ioc_get_state(ioc);
  1522. ioc_attr->port_id = ioc->port_id;
  1523. ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
  1524. bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
  1525. ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
  1526. ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
  1527. bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
  1528. }
  1529. /**
  1530. * hal_wwn_public
  1531. */
  1532. wwn_t
  1533. bfa_ioc_get_pwwn(struct bfa_ioc_s *ioc)
  1534. {
  1535. union {
  1536. wwn_t wwn;
  1537. u8 byte[sizeof(wwn_t)];
  1538. }
  1539. w;
  1540. w.wwn = ioc->attr->mfg_wwn;
  1541. if (bfa_ioc_portid(ioc) == 1)
  1542. w.byte[7]++;
  1543. return w.wwn;
  1544. }
  1545. wwn_t
  1546. bfa_ioc_get_nwwn(struct bfa_ioc_s *ioc)
  1547. {
  1548. union {
  1549. wwn_t wwn;
  1550. u8 byte[sizeof(wwn_t)];
  1551. }
  1552. w;
  1553. w.wwn = ioc->attr->mfg_wwn;
  1554. if (bfa_ioc_portid(ioc) == 1)
  1555. w.byte[7]++;
  1556. w.byte[0] = 0x20;
  1557. return w.wwn;
  1558. }
  1559. wwn_t
  1560. bfa_ioc_get_wwn_naa5(struct bfa_ioc_s *ioc, u16 inst)
  1561. {
  1562. union {
  1563. wwn_t wwn;
  1564. u8 byte[sizeof(wwn_t)];
  1565. }
  1566. w , w5;
  1567. bfa_trc(ioc, inst);
  1568. w.wwn = ioc->attr->mfg_wwn;
  1569. w5.byte[0] = 0x50 | w.byte[2] >> 4;
  1570. w5.byte[1] = w.byte[2] << 4 | w.byte[3] >> 4;
  1571. w5.byte[2] = w.byte[3] << 4 | w.byte[4] >> 4;
  1572. w5.byte[3] = w.byte[4] << 4 | w.byte[5] >> 4;
  1573. w5.byte[4] = w.byte[5] << 4 | w.byte[6] >> 4;
  1574. w5.byte[5] = w.byte[6] << 4 | w.byte[7] >> 4;
  1575. w5.byte[6] = w.byte[7] << 4 | (inst & 0x0f00) >> 8;
  1576. w5.byte[7] = (inst & 0xff);
  1577. return w5.wwn;
  1578. }
  1579. u64
  1580. bfa_ioc_get_adid(struct bfa_ioc_s *ioc)
  1581. {
  1582. return ioc->attr->mfg_wwn;
  1583. }
  1584. mac_t
  1585. bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
  1586. {
  1587. mac_t mac;
  1588. mac = ioc->attr->mfg_mac;
  1589. mac.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
  1590. return mac;
  1591. }
  1592. void
  1593. bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
  1594. {
  1595. ioc->fcmode = BFA_TRUE;
  1596. ioc->port_id = bfa_ioc_pcifn(ioc);
  1597. }
  1598. bfa_boolean_t
  1599. bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
  1600. {
  1601. return ioc->fcmode || (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_CT);
  1602. }
  1603. /**
  1604. * Send AEN notification
  1605. */
  1606. static void
  1607. bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
  1608. {
  1609. union bfa_aen_data_u aen_data;
  1610. struct bfa_log_mod_s *logmod = ioc->logm;
  1611. s32 inst_num = 0;
  1612. enum bfa_ioc_type_e ioc_type;
  1613. bfa_log(logmod, BFA_LOG_CREATE_ID(BFA_AEN_CAT_IOC, event), inst_num);
  1614. memset(&aen_data.ioc.pwwn, 0, sizeof(aen_data.ioc.pwwn));
  1615. memset(&aen_data.ioc.mac, 0, sizeof(aen_data.ioc.mac));
  1616. ioc_type = bfa_ioc_get_type(ioc);
  1617. switch (ioc_type) {
  1618. case BFA_IOC_TYPE_FC:
  1619. aen_data.ioc.pwwn = bfa_ioc_get_pwwn(ioc);
  1620. break;
  1621. case BFA_IOC_TYPE_FCoE:
  1622. aen_data.ioc.pwwn = bfa_ioc_get_pwwn(ioc);
  1623. aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  1624. break;
  1625. case BFA_IOC_TYPE_LL:
  1626. aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  1627. break;
  1628. default:
  1629. bfa_assert(ioc_type == BFA_IOC_TYPE_FC);
  1630. break;
  1631. }
  1632. aen_data.ioc.ioc_type = ioc_type;
  1633. }
  1634. /**
  1635. * Retrieve saved firmware trace from a prior IOC failure.
  1636. */
  1637. bfa_status_t
  1638. bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  1639. {
  1640. int tlen;
  1641. if (ioc->dbg_fwsave_len == 0)
  1642. return BFA_STATUS_ENOFSAVE;
  1643. tlen = *trclen;
  1644. if (tlen > ioc->dbg_fwsave_len)
  1645. tlen = ioc->dbg_fwsave_len;
  1646. bfa_os_memcpy(trcdata, ioc->dbg_fwsave, tlen);
  1647. *trclen = tlen;
  1648. return BFA_STATUS_OK;
  1649. }
  1650. /**
  1651. * Clear saved firmware trace
  1652. */
  1653. void
  1654. bfa_ioc_debug_fwsave_clear(struct bfa_ioc_s *ioc)
  1655. {
  1656. ioc->dbg_fwsave_once = BFA_TRUE;
  1657. }
  1658. /**
  1659. * Retrieve saved firmware trace from a prior IOC failure.
  1660. */
  1661. bfa_status_t
  1662. bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  1663. {
  1664. u32 pgnum;
  1665. u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
  1666. int i, tlen;
  1667. u32 *tbuf = trcdata, r32;
  1668. bfa_trc(ioc, *trclen);
  1669. pgnum = bfa_ioc_smem_pgnum(ioc, loff);
  1670. loff = bfa_ioc_smem_pgoff(ioc, loff);
  1671. /*
  1672. * Hold semaphore to serialize pll init and fwtrc.
  1673. */
  1674. if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg))
  1675. return BFA_STATUS_FAILED;
  1676. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  1677. tlen = *trclen;
  1678. if (tlen > BFA_DBG_FWTRC_LEN)
  1679. tlen = BFA_DBG_FWTRC_LEN;
  1680. tlen /= sizeof(u32);
  1681. bfa_trc(ioc, tlen);
  1682. for (i = 0; i < tlen; i++) {
  1683. r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  1684. tbuf[i] = bfa_os_ntohl(r32);
  1685. loff += sizeof(u32);
  1686. /**
  1687. * handle page offset wrap around
  1688. */
  1689. loff = PSS_SMEM_PGOFF(loff);
  1690. if (loff == 0) {
  1691. pgnum++;
  1692. bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
  1693. }
  1694. }
  1695. bfa_reg_write(ioc->ioc_regs.host_page_num_fn,
  1696. bfa_ioc_smem_pgnum(ioc, 0));
  1697. /*
  1698. * release semaphore.
  1699. */
  1700. bfa_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
  1701. bfa_trc(ioc, pgnum);
  1702. *trclen = tlen * sizeof(u32);
  1703. return BFA_STATUS_OK;
  1704. }
  1705. /**
  1706. * Save firmware trace if configured.
  1707. */
  1708. static void
  1709. bfa_ioc_debug_save(struct bfa_ioc_s *ioc)
  1710. {
  1711. int tlen;
  1712. if (ioc->dbg_fwsave_len) {
  1713. tlen = ioc->dbg_fwsave_len;
  1714. bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
  1715. }
  1716. }
  1717. /**
  1718. * Firmware failure detected. Start recovery actions.
  1719. */
  1720. static void
  1721. bfa_ioc_recover(struct bfa_ioc_s *ioc)
  1722. {
  1723. if (ioc->dbg_fwsave_once) {
  1724. ioc->dbg_fwsave_once = BFA_FALSE;
  1725. bfa_ioc_debug_save(ioc);
  1726. }
  1727. bfa_ioc_stats(ioc, ioc_hbfails);
  1728. bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
  1729. }
  1730. #else
  1731. static void
  1732. bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
  1733. {
  1734. }
  1735. static void
  1736. bfa_ioc_recover(struct bfa_ioc_s *ioc)
  1737. {
  1738. bfa_assert(0);
  1739. }
  1740. #endif