bfa_ioc.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794
  1. /*
  2. * Copyright (c) 2005-2010 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 "bfad_drv.h"
  18. #include "bfa_ioc.h"
  19. #include "bfi_ctreg.h"
  20. #include "bfa_defs.h"
  21. #include "bfa_defs_svc.h"
  22. BFA_TRC_FILE(CNA, IOC);
  23. /*
  24. * IOC local definitions
  25. */
  26. #define BFA_IOC_TOV 3000 /* msecs */
  27. #define BFA_IOC_HWSEM_TOV 500 /* msecs */
  28. #define BFA_IOC_HB_TOV 500 /* msecs */
  29. #define BFA_IOC_HWINIT_MAX 5
  30. #define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
  31. #define bfa_ioc_timer_start(__ioc) \
  32. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
  33. bfa_ioc_timeout, (__ioc), BFA_IOC_TOV)
  34. #define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
  35. #define bfa_hb_timer_start(__ioc) \
  36. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->hb_timer, \
  37. bfa_ioc_hb_check, (__ioc), BFA_IOC_HB_TOV)
  38. #define bfa_hb_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->hb_timer)
  39. #define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
  40. /*
  41. * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
  42. */
  43. #define bfa_ioc_firmware_lock(__ioc) \
  44. ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
  45. #define bfa_ioc_firmware_unlock(__ioc) \
  46. ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
  47. #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
  48. #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
  49. #define bfa_ioc_notify_fail(__ioc) \
  50. ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
  51. #define bfa_ioc_sync_join(__ioc) \
  52. ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
  53. #define bfa_ioc_sync_leave(__ioc) \
  54. ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
  55. #define bfa_ioc_sync_ack(__ioc) \
  56. ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
  57. #define bfa_ioc_sync_complete(__ioc) \
  58. ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
  59. #define bfa_ioc_mbox_cmd_pending(__ioc) \
  60. (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
  61. readl((__ioc)->ioc_regs.hfn_mbox_cmd))
  62. bfa_boolean_t bfa_auto_recover = BFA_TRUE;
  63. /*
  64. * forward declarations
  65. */
  66. static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
  67. static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
  68. static void bfa_ioc_timeout(void *ioc);
  69. static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
  70. static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
  71. static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
  72. static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
  73. static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
  74. static void bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc);
  75. static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
  76. static void bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc);
  77. static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
  78. static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
  79. static void bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc);
  80. static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc);
  81. static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
  82. /*
  83. * IOC state machine definitions/declarations
  84. */
  85. enum ioc_event {
  86. IOC_E_RESET = 1, /* IOC reset request */
  87. IOC_E_ENABLE = 2, /* IOC enable request */
  88. IOC_E_DISABLE = 3, /* IOC disable request */
  89. IOC_E_DETACH = 4, /* driver detach cleanup */
  90. IOC_E_ENABLED = 5, /* f/w enabled */
  91. IOC_E_FWRSP_GETATTR = 6, /* IOC get attribute response */
  92. IOC_E_DISABLED = 7, /* f/w disabled */
  93. IOC_E_INITFAILED = 8, /* failure notice by iocpf sm */
  94. IOC_E_PFFAILED = 9, /* failure notice by iocpf sm */
  95. IOC_E_HBFAIL = 10, /* heartbeat failure */
  96. IOC_E_HWERROR = 11, /* hardware error interrupt */
  97. IOC_E_TIMEOUT = 12, /* timeout */
  98. };
  99. bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event);
  100. bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
  101. bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
  102. bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
  103. bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
  104. bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc_s, enum ioc_event);
  105. bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event);
  106. bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
  107. bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
  108. static struct bfa_sm_table_s ioc_sm_table[] = {
  109. {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
  110. {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
  111. {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
  112. {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
  113. {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
  114. {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
  115. {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
  116. {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
  117. {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
  118. };
  119. /*
  120. * IOCPF state machine definitions/declarations
  121. */
  122. #define bfa_iocpf_timer_start(__ioc) \
  123. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
  124. bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
  125. #define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
  126. #define bfa_iocpf_recovery_timer_start(__ioc) \
  127. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
  128. bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV_RECOVER)
  129. #define bfa_sem_timer_start(__ioc) \
  130. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
  131. bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
  132. #define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
  133. /*
  134. * Forward declareations for iocpf state machine
  135. */
  136. static void bfa_iocpf_timeout(void *ioc_arg);
  137. static void bfa_iocpf_sem_timeout(void *ioc_arg);
  138. /*
  139. * IOCPF state machine events
  140. */
  141. enum iocpf_event {
  142. IOCPF_E_ENABLE = 1, /* IOCPF enable request */
  143. IOCPF_E_DISABLE = 2, /* IOCPF disable request */
  144. IOCPF_E_STOP = 3, /* stop on driver detach */
  145. IOCPF_E_FWREADY = 4, /* f/w initialization done */
  146. IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */
  147. IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */
  148. IOCPF_E_FAIL = 7, /* failure notice by ioc sm */
  149. IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */
  150. IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */
  151. IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */
  152. IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
  153. };
  154. /*
  155. * IOCPF states
  156. */
  157. enum bfa_iocpf_state {
  158. BFA_IOCPF_RESET = 1, /* IOC is in reset state */
  159. BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
  160. BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
  161. BFA_IOCPF_READY = 4, /* IOCPF is initialized */
  162. BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
  163. BFA_IOCPF_FAIL = 6, /* IOCPF failed */
  164. BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
  165. BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
  166. BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
  167. };
  168. bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
  169. bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
  170. bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
  171. bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
  172. bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
  173. bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
  174. bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
  175. bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s,
  176. enum iocpf_event);
  177. bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
  178. bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event);
  179. bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
  180. bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
  181. bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s,
  182. enum iocpf_event);
  183. bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
  184. static struct bfa_sm_table_s iocpf_sm_table[] = {
  185. {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
  186. {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
  187. {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
  188. {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
  189. {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
  190. {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
  191. {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
  192. {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
  193. {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
  194. {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
  195. {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
  196. {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
  197. {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
  198. {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
  199. };
  200. /*
  201. * IOC State Machine
  202. */
  203. /*
  204. * Beginning state. IOC uninit state.
  205. */
  206. static void
  207. bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
  208. {
  209. }
  210. /*
  211. * IOC is in uninit state.
  212. */
  213. static void
  214. bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
  215. {
  216. bfa_trc(ioc, event);
  217. switch (event) {
  218. case IOC_E_RESET:
  219. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  220. break;
  221. default:
  222. bfa_sm_fault(ioc, event);
  223. }
  224. }
  225. /*
  226. * Reset entry actions -- initialize state machine
  227. */
  228. static void
  229. bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
  230. {
  231. bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
  232. }
  233. /*
  234. * IOC is in reset state.
  235. */
  236. static void
  237. bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
  238. {
  239. bfa_trc(ioc, event);
  240. switch (event) {
  241. case IOC_E_ENABLE:
  242. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  243. break;
  244. case IOC_E_DISABLE:
  245. bfa_ioc_disable_comp(ioc);
  246. break;
  247. case IOC_E_DETACH:
  248. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  249. break;
  250. default:
  251. bfa_sm_fault(ioc, event);
  252. }
  253. }
  254. static void
  255. bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
  256. {
  257. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
  258. }
  259. /*
  260. * Host IOC function is being enabled, awaiting response from firmware.
  261. * Semaphore is acquired.
  262. */
  263. static void
  264. bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
  265. {
  266. bfa_trc(ioc, event);
  267. switch (event) {
  268. case IOC_E_ENABLED:
  269. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  270. break;
  271. case IOC_E_PFFAILED:
  272. /* !!! fall through !!! */
  273. case IOC_E_HWERROR:
  274. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  275. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
  276. if (event != IOC_E_PFFAILED)
  277. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
  278. break;
  279. case IOC_E_DISABLE:
  280. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  281. break;
  282. case IOC_E_DETACH:
  283. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  284. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  285. break;
  286. case IOC_E_ENABLE:
  287. break;
  288. default:
  289. bfa_sm_fault(ioc, event);
  290. }
  291. }
  292. static void
  293. bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
  294. {
  295. bfa_ioc_timer_start(ioc);
  296. bfa_ioc_send_getattr(ioc);
  297. }
  298. /*
  299. * IOC configuration in progress. Timer is active.
  300. */
  301. static void
  302. bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
  303. {
  304. bfa_trc(ioc, event);
  305. switch (event) {
  306. case IOC_E_FWRSP_GETATTR:
  307. bfa_ioc_timer_stop(ioc);
  308. bfa_ioc_check_attr_wwns(ioc);
  309. bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
  310. break;
  311. break;
  312. case IOC_E_PFFAILED:
  313. case IOC_E_HWERROR:
  314. bfa_ioc_timer_stop(ioc);
  315. /* !!! fall through !!! */
  316. case IOC_E_TIMEOUT:
  317. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  318. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
  319. if (event != IOC_E_PFFAILED)
  320. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
  321. break;
  322. case IOC_E_DISABLE:
  323. bfa_ioc_timer_stop(ioc);
  324. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  325. break;
  326. case IOC_E_ENABLE:
  327. break;
  328. default:
  329. bfa_sm_fault(ioc, event);
  330. }
  331. }
  332. static void
  333. bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
  334. {
  335. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  336. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
  337. bfa_ioc_hb_monitor(ioc);
  338. BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
  339. }
  340. static void
  341. bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
  342. {
  343. bfa_trc(ioc, event);
  344. switch (event) {
  345. case IOC_E_ENABLE:
  346. break;
  347. case IOC_E_DISABLE:
  348. bfa_hb_timer_stop(ioc);
  349. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  350. break;
  351. case IOC_E_PFFAILED:
  352. case IOC_E_HWERROR:
  353. bfa_hb_timer_stop(ioc);
  354. /* !!! fall through !!! */
  355. case IOC_E_HBFAIL:
  356. bfa_ioc_fail_notify(ioc);
  357. if (ioc->iocpf.auto_recover)
  358. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
  359. else
  360. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  361. if (event != IOC_E_PFFAILED)
  362. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
  363. break;
  364. default:
  365. bfa_sm_fault(ioc, event);
  366. }
  367. }
  368. static void
  369. bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
  370. {
  371. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  372. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
  373. BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
  374. }
  375. /*
  376. * IOC is being disabled
  377. */
  378. static void
  379. bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
  380. {
  381. bfa_trc(ioc, event);
  382. switch (event) {
  383. case IOC_E_DISABLED:
  384. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  385. break;
  386. case IOC_E_HWERROR:
  387. /*
  388. * No state change. Will move to disabled state
  389. * after iocpf sm completes failure processing and
  390. * moves to disabled state.
  391. */
  392. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
  393. break;
  394. default:
  395. bfa_sm_fault(ioc, event);
  396. }
  397. }
  398. /*
  399. * IOC disable completion entry.
  400. */
  401. static void
  402. bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
  403. {
  404. bfa_ioc_disable_comp(ioc);
  405. }
  406. static void
  407. bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
  408. {
  409. bfa_trc(ioc, event);
  410. switch (event) {
  411. case IOC_E_ENABLE:
  412. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  413. break;
  414. case IOC_E_DISABLE:
  415. ioc->cbfn->disable_cbfn(ioc->bfa);
  416. break;
  417. case IOC_E_DETACH:
  418. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  419. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  420. break;
  421. default:
  422. bfa_sm_fault(ioc, event);
  423. }
  424. }
  425. static void
  426. bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc)
  427. {
  428. bfa_trc(ioc, 0);
  429. }
  430. /*
  431. * Hardware initialization retry.
  432. */
  433. static void
  434. bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event)
  435. {
  436. bfa_trc(ioc, event);
  437. switch (event) {
  438. case IOC_E_ENABLED:
  439. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  440. break;
  441. case IOC_E_PFFAILED:
  442. case IOC_E_HWERROR:
  443. /*
  444. * Initialization retry failed.
  445. */
  446. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  447. if (event != IOC_E_PFFAILED)
  448. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
  449. break;
  450. case IOC_E_INITFAILED:
  451. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  452. break;
  453. case IOC_E_ENABLE:
  454. break;
  455. case IOC_E_DISABLE:
  456. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  457. break;
  458. case IOC_E_DETACH:
  459. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  460. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  461. break;
  462. default:
  463. bfa_sm_fault(ioc, event);
  464. }
  465. }
  466. static void
  467. bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
  468. {
  469. bfa_trc(ioc, 0);
  470. }
  471. /*
  472. * IOC failure.
  473. */
  474. static void
  475. bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
  476. {
  477. bfa_trc(ioc, event);
  478. switch (event) {
  479. case IOC_E_ENABLE:
  480. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  481. break;
  482. case IOC_E_DISABLE:
  483. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  484. break;
  485. case IOC_E_DETACH:
  486. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  487. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  488. break;
  489. case IOC_E_HWERROR:
  490. /*
  491. * HB failure notification, ignore.
  492. */
  493. break;
  494. default:
  495. bfa_sm_fault(ioc, event);
  496. }
  497. }
  498. /*
  499. * IOCPF State Machine
  500. */
  501. /*
  502. * Reset entry actions -- initialize state machine
  503. */
  504. static void
  505. bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
  506. {
  507. iocpf->retry_count = 0;
  508. iocpf->auto_recover = bfa_auto_recover;
  509. }
  510. /*
  511. * Beginning state. IOC is in reset state.
  512. */
  513. static void
  514. bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  515. {
  516. struct bfa_ioc_s *ioc = iocpf->ioc;
  517. bfa_trc(ioc, event);
  518. switch (event) {
  519. case IOCPF_E_ENABLE:
  520. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
  521. break;
  522. case IOCPF_E_STOP:
  523. break;
  524. default:
  525. bfa_sm_fault(ioc, event);
  526. }
  527. }
  528. /*
  529. * Semaphore should be acquired for version check.
  530. */
  531. static void
  532. bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
  533. {
  534. bfa_ioc_hw_sem_get(iocpf->ioc);
  535. }
  536. /*
  537. * Awaiting h/w semaphore to continue with version check.
  538. */
  539. static void
  540. bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  541. {
  542. struct bfa_ioc_s *ioc = iocpf->ioc;
  543. bfa_trc(ioc, event);
  544. switch (event) {
  545. case IOCPF_E_SEMLOCKED:
  546. if (bfa_ioc_firmware_lock(ioc)) {
  547. if (bfa_ioc_sync_complete(ioc)) {
  548. iocpf->retry_count = 0;
  549. bfa_ioc_sync_join(ioc);
  550. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  551. } else {
  552. bfa_ioc_firmware_unlock(ioc);
  553. writel(1, ioc->ioc_regs.ioc_sem_reg);
  554. bfa_sem_timer_start(ioc);
  555. }
  556. } else {
  557. writel(1, ioc->ioc_regs.ioc_sem_reg);
  558. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
  559. }
  560. break;
  561. case IOCPF_E_DISABLE:
  562. bfa_sem_timer_stop(ioc);
  563. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  564. bfa_fsm_send_event(ioc, IOC_E_DISABLED);
  565. break;
  566. case IOCPF_E_STOP:
  567. bfa_sem_timer_stop(ioc);
  568. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  569. break;
  570. default:
  571. bfa_sm_fault(ioc, event);
  572. }
  573. }
  574. /*
  575. * Notify enable completion callback.
  576. */
  577. static void
  578. bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
  579. {
  580. /*
  581. * Call only the first time sm enters fwmismatch state.
  582. */
  583. if (iocpf->retry_count == 0)
  584. bfa_ioc_pf_fwmismatch(iocpf->ioc);
  585. iocpf->retry_count++;
  586. bfa_iocpf_timer_start(iocpf->ioc);
  587. }
  588. /*
  589. * Awaiting firmware version match.
  590. */
  591. static void
  592. bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  593. {
  594. struct bfa_ioc_s *ioc = iocpf->ioc;
  595. bfa_trc(ioc, event);
  596. switch (event) {
  597. case IOCPF_E_TIMEOUT:
  598. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
  599. break;
  600. case IOCPF_E_DISABLE:
  601. bfa_iocpf_timer_stop(ioc);
  602. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  603. bfa_fsm_send_event(ioc, IOC_E_DISABLED);
  604. break;
  605. case IOCPF_E_STOP:
  606. bfa_iocpf_timer_stop(ioc);
  607. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  608. break;
  609. default:
  610. bfa_sm_fault(ioc, event);
  611. }
  612. }
  613. /*
  614. * Request for semaphore.
  615. */
  616. static void
  617. bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
  618. {
  619. bfa_ioc_hw_sem_get(iocpf->ioc);
  620. }
  621. /*
  622. * Awaiting semaphore for h/w initialzation.
  623. */
  624. static void
  625. bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  626. {
  627. struct bfa_ioc_s *ioc = iocpf->ioc;
  628. bfa_trc(ioc, event);
  629. switch (event) {
  630. case IOCPF_E_SEMLOCKED:
  631. if (bfa_ioc_sync_complete(ioc)) {
  632. bfa_ioc_sync_join(ioc);
  633. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  634. } else {
  635. writel(1, ioc->ioc_regs.ioc_sem_reg);
  636. bfa_sem_timer_start(ioc);
  637. }
  638. break;
  639. case IOCPF_E_DISABLE:
  640. bfa_sem_timer_stop(ioc);
  641. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  642. break;
  643. default:
  644. bfa_sm_fault(ioc, event);
  645. }
  646. }
  647. static void
  648. bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
  649. {
  650. bfa_iocpf_timer_start(iocpf->ioc);
  651. bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE);
  652. }
  653. /*
  654. * Hardware is being initialized. Interrupts are enabled.
  655. * Holding hardware semaphore lock.
  656. */
  657. static void
  658. bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  659. {
  660. struct bfa_ioc_s *ioc = iocpf->ioc;
  661. bfa_trc(ioc, event);
  662. switch (event) {
  663. case IOCPF_E_FWREADY:
  664. bfa_iocpf_timer_stop(ioc);
  665. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
  666. break;
  667. case IOCPF_E_INITFAIL:
  668. bfa_iocpf_timer_stop(ioc);
  669. /*
  670. * !!! fall through !!!
  671. */
  672. case IOCPF_E_TIMEOUT:
  673. writel(1, ioc->ioc_regs.ioc_sem_reg);
  674. if (event == IOCPF_E_TIMEOUT)
  675. bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
  676. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  677. break;
  678. case IOCPF_E_DISABLE:
  679. bfa_iocpf_timer_stop(ioc);
  680. bfa_ioc_sync_leave(ioc);
  681. writel(1, ioc->ioc_regs.ioc_sem_reg);
  682. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  683. break;
  684. default:
  685. bfa_sm_fault(ioc, event);
  686. }
  687. }
  688. static void
  689. bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
  690. {
  691. bfa_iocpf_timer_start(iocpf->ioc);
  692. bfa_ioc_send_enable(iocpf->ioc);
  693. }
  694. /*
  695. * Host IOC function is being enabled, awaiting response from firmware.
  696. * Semaphore is acquired.
  697. */
  698. static void
  699. bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  700. {
  701. struct bfa_ioc_s *ioc = iocpf->ioc;
  702. bfa_trc(ioc, event);
  703. switch (event) {
  704. case IOCPF_E_FWRSP_ENABLE:
  705. bfa_iocpf_timer_stop(ioc);
  706. writel(1, ioc->ioc_regs.ioc_sem_reg);
  707. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
  708. break;
  709. case IOCPF_E_INITFAIL:
  710. bfa_iocpf_timer_stop(ioc);
  711. /*
  712. * !!! fall through !!!
  713. */
  714. case IOCPF_E_TIMEOUT:
  715. writel(1, ioc->ioc_regs.ioc_sem_reg);
  716. if (event == IOCPF_E_TIMEOUT)
  717. bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
  718. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  719. break;
  720. case IOCPF_E_DISABLE:
  721. bfa_iocpf_timer_stop(ioc);
  722. writel(1, ioc->ioc_regs.ioc_sem_reg);
  723. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
  724. break;
  725. case IOCPF_E_FWREADY:
  726. bfa_ioc_send_enable(ioc);
  727. break;
  728. default:
  729. bfa_sm_fault(ioc, event);
  730. }
  731. }
  732. static void
  733. bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
  734. {
  735. bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED);
  736. }
  737. static void
  738. bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  739. {
  740. struct bfa_ioc_s *ioc = iocpf->ioc;
  741. bfa_trc(ioc, event);
  742. switch (event) {
  743. case IOCPF_E_DISABLE:
  744. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
  745. break;
  746. case IOCPF_E_GETATTRFAIL:
  747. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  748. break;
  749. case IOCPF_E_FAIL:
  750. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
  751. break;
  752. case IOCPF_E_FWREADY:
  753. if (bfa_ioc_is_operational(ioc)) {
  754. bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
  755. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
  756. } else {
  757. bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
  758. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  759. }
  760. break;
  761. default:
  762. bfa_sm_fault(ioc, event);
  763. }
  764. }
  765. static void
  766. bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
  767. {
  768. bfa_iocpf_timer_start(iocpf->ioc);
  769. bfa_ioc_send_disable(iocpf->ioc);
  770. }
  771. /*
  772. * IOC is being disabled
  773. */
  774. static void
  775. bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  776. {
  777. struct bfa_ioc_s *ioc = iocpf->ioc;
  778. bfa_trc(ioc, event);
  779. switch (event) {
  780. case IOCPF_E_FWRSP_DISABLE:
  781. case IOCPF_E_FWREADY:
  782. bfa_iocpf_timer_stop(ioc);
  783. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  784. break;
  785. case IOCPF_E_FAIL:
  786. bfa_iocpf_timer_stop(ioc);
  787. /*
  788. * !!! fall through !!!
  789. */
  790. case IOCPF_E_TIMEOUT:
  791. writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
  792. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  793. break;
  794. case IOCPF_E_FWRSP_ENABLE:
  795. break;
  796. default:
  797. bfa_sm_fault(ioc, event);
  798. }
  799. }
  800. static void
  801. bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf)
  802. {
  803. bfa_ioc_hw_sem_get(iocpf->ioc);
  804. }
  805. /**
  806. * IOC hb ack request is being removed.
  807. */
  808. static void
  809. bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  810. {
  811. struct bfa_ioc_s *ioc = iocpf->ioc;
  812. bfa_trc(ioc, event);
  813. switch (event) {
  814. case IOCPF_E_SEMLOCKED:
  815. bfa_ioc_sync_leave(ioc);
  816. writel(1, ioc->ioc_regs.ioc_sem_reg);
  817. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  818. break;
  819. case IOCPF_E_FAIL:
  820. break;
  821. default:
  822. bfa_sm_fault(ioc, event);
  823. }
  824. }
  825. /*
  826. * IOC disable completion entry.
  827. */
  828. static void
  829. bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
  830. {
  831. bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED);
  832. }
  833. static void
  834. bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  835. {
  836. struct bfa_ioc_s *ioc = iocpf->ioc;
  837. bfa_trc(ioc, event);
  838. switch (event) {
  839. case IOCPF_E_ENABLE:
  840. iocpf->retry_count = 0;
  841. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  842. break;
  843. case IOCPF_E_STOP:
  844. bfa_ioc_firmware_unlock(ioc);
  845. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  846. break;
  847. default:
  848. bfa_sm_fault(ioc, event);
  849. }
  850. }
  851. static void
  852. bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf)
  853. {
  854. bfa_ioc_hw_sem_get(iocpf->ioc);
  855. }
  856. /**
  857. * @brief
  858. * Hardware initialization failed.
  859. */
  860. static void
  861. bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  862. {
  863. struct bfa_ioc_s *ioc = iocpf->ioc;
  864. bfa_trc(ioc, event);
  865. switch (event) {
  866. case IOCPF_E_SEMLOCKED:
  867. bfa_ioc_notify_fail(ioc);
  868. bfa_ioc_sync_ack(ioc);
  869. iocpf->retry_count++;
  870. if (iocpf->retry_count >= BFA_IOC_HWINIT_MAX) {
  871. bfa_ioc_sync_leave(ioc);
  872. writel(1, ioc->ioc_regs.ioc_sem_reg);
  873. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
  874. } else {
  875. if (bfa_ioc_sync_complete(ioc))
  876. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  877. else {
  878. writel(1, ioc->ioc_regs.ioc_sem_reg);
  879. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  880. }
  881. }
  882. break;
  883. case IOCPF_E_DISABLE:
  884. bfa_sem_timer_stop(ioc);
  885. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  886. break;
  887. case IOCPF_E_STOP:
  888. bfa_sem_timer_stop(ioc);
  889. bfa_ioc_firmware_unlock(ioc);
  890. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  891. break;
  892. case IOCPF_E_FAIL:
  893. break;
  894. default:
  895. bfa_sm_fault(ioc, event);
  896. }
  897. }
  898. static void
  899. bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
  900. {
  901. bfa_fsm_send_event(iocpf->ioc, IOC_E_INITFAILED);
  902. }
  903. /*
  904. * Hardware initialization failed.
  905. */
  906. static void
  907. bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  908. {
  909. struct bfa_ioc_s *ioc = iocpf->ioc;
  910. bfa_trc(ioc, event);
  911. switch (event) {
  912. case IOCPF_E_DISABLE:
  913. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  914. break;
  915. case IOCPF_E_STOP:
  916. bfa_ioc_firmware_unlock(ioc);
  917. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  918. break;
  919. default:
  920. bfa_sm_fault(ioc, event);
  921. }
  922. }
  923. static void
  924. bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
  925. {
  926. /**
  927. * Mark IOC as failed in hardware and stop firmware.
  928. */
  929. bfa_ioc_lpu_stop(iocpf->ioc);
  930. /**
  931. * Flush any queued up mailbox requests.
  932. */
  933. bfa_ioc_mbox_hbfail(iocpf->ioc);
  934. bfa_ioc_hw_sem_get(iocpf->ioc);
  935. }
  936. static void
  937. bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  938. {
  939. struct bfa_ioc_s *ioc = iocpf->ioc;
  940. bfa_trc(ioc, event);
  941. switch (event) {
  942. case IOCPF_E_SEMLOCKED:
  943. iocpf->retry_count = 0;
  944. bfa_ioc_sync_ack(ioc);
  945. bfa_ioc_notify_fail(ioc);
  946. if (!iocpf->auto_recover) {
  947. bfa_ioc_sync_leave(ioc);
  948. writel(1, ioc->ioc_regs.ioc_sem_reg);
  949. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  950. } else {
  951. if (bfa_ioc_sync_complete(ioc))
  952. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  953. else {
  954. writel(1, ioc->ioc_regs.ioc_sem_reg);
  955. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  956. }
  957. }
  958. break;
  959. case IOCPF_E_DISABLE:
  960. bfa_sem_timer_stop(ioc);
  961. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  962. break;
  963. case IOCPF_E_FAIL:
  964. break;
  965. default:
  966. bfa_sm_fault(ioc, event);
  967. }
  968. }
  969. static void
  970. bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
  971. {
  972. }
  973. /*
  974. * IOC is in failed state.
  975. */
  976. static void
  977. bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  978. {
  979. struct bfa_ioc_s *ioc = iocpf->ioc;
  980. bfa_trc(ioc, event);
  981. switch (event) {
  982. case IOCPF_E_DISABLE:
  983. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  984. break;
  985. default:
  986. bfa_sm_fault(ioc, event);
  987. }
  988. }
  989. /*
  990. * BFA IOC private functions
  991. */
  992. static void
  993. bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
  994. {
  995. struct list_head *qe;
  996. struct bfa_ioc_hbfail_notify_s *notify;
  997. ioc->cbfn->disable_cbfn(ioc->bfa);
  998. /*
  999. * Notify common modules registered for notification.
  1000. */
  1001. list_for_each(qe, &ioc->hb_notify_q) {
  1002. notify = (struct bfa_ioc_hbfail_notify_s *) qe;
  1003. notify->cbfn(notify->cbarg);
  1004. }
  1005. }
  1006. bfa_boolean_t
  1007. bfa_ioc_sem_get(void __iomem *sem_reg)
  1008. {
  1009. u32 r32;
  1010. int cnt = 0;
  1011. #define BFA_SEM_SPINCNT 3000
  1012. r32 = readl(sem_reg);
  1013. while (r32 && (cnt < BFA_SEM_SPINCNT)) {
  1014. cnt++;
  1015. udelay(2);
  1016. r32 = readl(sem_reg);
  1017. }
  1018. if (r32 == 0)
  1019. return BFA_TRUE;
  1020. bfa_assert(cnt < BFA_SEM_SPINCNT);
  1021. return BFA_FALSE;
  1022. }
  1023. static void
  1024. bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
  1025. {
  1026. u32 r32;
  1027. /*
  1028. * First read to the semaphore register will return 0, subsequent reads
  1029. * will return 1. Semaphore is released by writing 1 to the register
  1030. */
  1031. r32 = readl(ioc->ioc_regs.ioc_sem_reg);
  1032. if (r32 == 0) {
  1033. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
  1034. return;
  1035. }
  1036. bfa_sem_timer_start(ioc);
  1037. }
  1038. /*
  1039. * Initialize LPU local memory (aka secondary memory / SRAM)
  1040. */
  1041. static void
  1042. bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
  1043. {
  1044. u32 pss_ctl;
  1045. int i;
  1046. #define PSS_LMEM_INIT_TIME 10000
  1047. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1048. pss_ctl &= ~__PSS_LMEM_RESET;
  1049. pss_ctl |= __PSS_LMEM_INIT_EN;
  1050. /*
  1051. * i2c workaround 12.5khz clock
  1052. */
  1053. pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
  1054. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1055. /*
  1056. * wait for memory initialization to be complete
  1057. */
  1058. i = 0;
  1059. do {
  1060. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1061. i++;
  1062. } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
  1063. /*
  1064. * If memory initialization is not successful, IOC timeout will catch
  1065. * such failures.
  1066. */
  1067. bfa_assert(pss_ctl & __PSS_LMEM_INIT_DONE);
  1068. bfa_trc(ioc, pss_ctl);
  1069. pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
  1070. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1071. }
  1072. static void
  1073. bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
  1074. {
  1075. u32 pss_ctl;
  1076. /*
  1077. * Take processor out of reset.
  1078. */
  1079. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1080. pss_ctl &= ~__PSS_LPU0_RESET;
  1081. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1082. }
  1083. static void
  1084. bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
  1085. {
  1086. u32 pss_ctl;
  1087. /*
  1088. * Put processors in reset.
  1089. */
  1090. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1091. pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
  1092. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1093. }
  1094. /*
  1095. * Get driver and firmware versions.
  1096. */
  1097. void
  1098. bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
  1099. {
  1100. u32 pgnum, pgoff;
  1101. u32 loff = 0;
  1102. int i;
  1103. u32 *fwsig = (u32 *) fwhdr;
  1104. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  1105. pgoff = PSS_SMEM_PGOFF(loff);
  1106. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1107. for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
  1108. i++) {
  1109. fwsig[i] =
  1110. bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  1111. loff += sizeof(u32);
  1112. }
  1113. }
  1114. /*
  1115. * Returns TRUE if same.
  1116. */
  1117. bfa_boolean_t
  1118. bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
  1119. {
  1120. struct bfi_ioc_image_hdr_s *drv_fwhdr;
  1121. int i;
  1122. drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
  1123. bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
  1124. for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
  1125. if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
  1126. bfa_trc(ioc, i);
  1127. bfa_trc(ioc, fwhdr->md5sum[i]);
  1128. bfa_trc(ioc, drv_fwhdr->md5sum[i]);
  1129. return BFA_FALSE;
  1130. }
  1131. }
  1132. bfa_trc(ioc, fwhdr->md5sum[0]);
  1133. return BFA_TRUE;
  1134. }
  1135. /*
  1136. * Return true if current running version is valid. Firmware signature and
  1137. * execution context (driver/bios) must match.
  1138. */
  1139. static bfa_boolean_t
  1140. bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
  1141. {
  1142. struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
  1143. /*
  1144. * If bios/efi boot (flash based) -- return true
  1145. */
  1146. if (bfa_ioc_is_bios_optrom(ioc))
  1147. return BFA_TRUE;
  1148. bfa_ioc_fwver_get(ioc, &fwhdr);
  1149. drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
  1150. bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
  1151. if (fwhdr.signature != drv_fwhdr->signature) {
  1152. bfa_trc(ioc, fwhdr.signature);
  1153. bfa_trc(ioc, drv_fwhdr->signature);
  1154. return BFA_FALSE;
  1155. }
  1156. if (swab32(fwhdr.param) != boot_env) {
  1157. bfa_trc(ioc, fwhdr.param);
  1158. bfa_trc(ioc, boot_env);
  1159. return BFA_FALSE;
  1160. }
  1161. return bfa_ioc_fwver_cmp(ioc, &fwhdr);
  1162. }
  1163. /*
  1164. * Conditionally flush any pending message from firmware at start.
  1165. */
  1166. static void
  1167. bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
  1168. {
  1169. u32 r32;
  1170. r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
  1171. if (r32)
  1172. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  1173. }
  1174. static void
  1175. bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
  1176. {
  1177. enum bfi_ioc_state ioc_fwstate;
  1178. bfa_boolean_t fwvalid;
  1179. u32 boot_type;
  1180. u32 boot_env;
  1181. ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
  1182. if (force)
  1183. ioc_fwstate = BFI_IOC_UNINIT;
  1184. bfa_trc(ioc, ioc_fwstate);
  1185. boot_type = BFI_BOOT_TYPE_NORMAL;
  1186. boot_env = BFI_BOOT_LOADER_OS;
  1187. /*
  1188. * Flash based firmware boot BIOS env.
  1189. */
  1190. if (bfa_ioc_is_bios_optrom(ioc)) {
  1191. boot_type = BFI_BOOT_TYPE_FLASH;
  1192. boot_env = BFI_BOOT_LOADER_BIOS;
  1193. }
  1194. /*
  1195. * Flash based firmware boot UEFI env.
  1196. */
  1197. if (bfa_ioc_is_uefi(ioc)) {
  1198. boot_type = BFI_BOOT_TYPE_FLASH;
  1199. boot_env = BFI_BOOT_LOADER_UEFI;
  1200. }
  1201. /*
  1202. * check if firmware is valid
  1203. */
  1204. fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
  1205. BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
  1206. if (!fwvalid) {
  1207. bfa_ioc_boot(ioc, boot_type, boot_env);
  1208. return;
  1209. }
  1210. /*
  1211. * If hardware initialization is in progress (initialized by other IOC),
  1212. * just wait for an initialization completion interrupt.
  1213. */
  1214. if (ioc_fwstate == BFI_IOC_INITING) {
  1215. ioc->cbfn->reset_cbfn(ioc->bfa);
  1216. return;
  1217. }
  1218. /*
  1219. * If IOC function is disabled and firmware version is same,
  1220. * just re-enable IOC.
  1221. *
  1222. * If option rom, IOC must not be in operational state. With
  1223. * convergence, IOC will be in operational state when 2nd driver
  1224. * is loaded.
  1225. */
  1226. if (ioc_fwstate == BFI_IOC_DISABLED ||
  1227. (!bfa_ioc_is_bios_optrom(ioc) && ioc_fwstate == BFI_IOC_OP)) {
  1228. /*
  1229. * When using MSI-X any pending firmware ready event should
  1230. * be flushed. Otherwise MSI-X interrupts are not delivered.
  1231. */
  1232. bfa_ioc_msgflush(ioc);
  1233. ioc->cbfn->reset_cbfn(ioc->bfa);
  1234. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
  1235. return;
  1236. }
  1237. /*
  1238. * Initialize the h/w for any other states.
  1239. */
  1240. bfa_ioc_boot(ioc, boot_type, boot_env);
  1241. }
  1242. static void
  1243. bfa_ioc_timeout(void *ioc_arg)
  1244. {
  1245. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  1246. bfa_trc(ioc, 0);
  1247. bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
  1248. }
  1249. void
  1250. bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
  1251. {
  1252. u32 *msgp = (u32 *) ioc_msg;
  1253. u32 i;
  1254. bfa_trc(ioc, msgp[0]);
  1255. bfa_trc(ioc, len);
  1256. bfa_assert(len <= BFI_IOC_MSGLEN_MAX);
  1257. /*
  1258. * first write msg to mailbox registers
  1259. */
  1260. for (i = 0; i < len / sizeof(u32); i++)
  1261. writel(cpu_to_le32(msgp[i]),
  1262. ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1263. for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
  1264. writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1265. /*
  1266. * write 1 to mailbox CMD to trigger LPU event
  1267. */
  1268. writel(1, ioc->ioc_regs.hfn_mbox_cmd);
  1269. (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
  1270. }
  1271. static void
  1272. bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
  1273. {
  1274. struct bfi_ioc_ctrl_req_s enable_req;
  1275. struct timeval tv;
  1276. bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
  1277. bfa_ioc_portid(ioc));
  1278. enable_req.ioc_class = ioc->ioc_mc;
  1279. do_gettimeofday(&tv);
  1280. enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
  1281. bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  1282. }
  1283. static void
  1284. bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
  1285. {
  1286. struct bfi_ioc_ctrl_req_s disable_req;
  1287. bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
  1288. bfa_ioc_portid(ioc));
  1289. bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  1290. }
  1291. static void
  1292. bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
  1293. {
  1294. struct bfi_ioc_getattr_req_s attr_req;
  1295. bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
  1296. bfa_ioc_portid(ioc));
  1297. bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
  1298. bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
  1299. }
  1300. static void
  1301. bfa_ioc_hb_check(void *cbarg)
  1302. {
  1303. struct bfa_ioc_s *ioc = cbarg;
  1304. u32 hb_count;
  1305. hb_count = readl(ioc->ioc_regs.heartbeat);
  1306. if (ioc->hb_count == hb_count) {
  1307. bfa_ioc_recover(ioc);
  1308. return;
  1309. } else {
  1310. ioc->hb_count = hb_count;
  1311. }
  1312. bfa_ioc_mbox_poll(ioc);
  1313. bfa_hb_timer_start(ioc);
  1314. }
  1315. static void
  1316. bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
  1317. {
  1318. ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
  1319. bfa_hb_timer_start(ioc);
  1320. }
  1321. /*
  1322. * Initiate a full firmware download.
  1323. */
  1324. static void
  1325. bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
  1326. u32 boot_env)
  1327. {
  1328. u32 *fwimg;
  1329. u32 pgnum, pgoff;
  1330. u32 loff = 0;
  1331. u32 chunkno = 0;
  1332. u32 i;
  1333. /*
  1334. * Initialize LMEM first before code download
  1335. */
  1336. bfa_ioc_lmem_init(ioc);
  1337. bfa_trc(ioc, bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)));
  1338. fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno);
  1339. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  1340. pgoff = PSS_SMEM_PGOFF(loff);
  1341. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1342. for (i = 0; i < bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
  1343. if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
  1344. chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
  1345. fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc),
  1346. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  1347. }
  1348. /*
  1349. * write smem
  1350. */
  1351. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
  1352. fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
  1353. loff += sizeof(u32);
  1354. /*
  1355. * handle page offset wrap around
  1356. */
  1357. loff = PSS_SMEM_PGOFF(loff);
  1358. if (loff == 0) {
  1359. pgnum++;
  1360. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1361. }
  1362. }
  1363. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1364. ioc->ioc_regs.host_page_num_fn);
  1365. /*
  1366. * Set boot type and boot param at the end.
  1367. */
  1368. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF,
  1369. swab32(boot_type));
  1370. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_LOADER_OFF,
  1371. swab32(boot_env));
  1372. }
  1373. /*
  1374. * Update BFA configuration from firmware configuration.
  1375. */
  1376. static void
  1377. bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
  1378. {
  1379. struct bfi_ioc_attr_s *attr = ioc->attr;
  1380. attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
  1381. attr->card_type = be32_to_cpu(attr->card_type);
  1382. attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
  1383. bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
  1384. }
  1385. /*
  1386. * Attach time initialization of mbox logic.
  1387. */
  1388. static void
  1389. bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
  1390. {
  1391. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1392. int mc;
  1393. INIT_LIST_HEAD(&mod->cmd_q);
  1394. for (mc = 0; mc < BFI_MC_MAX; mc++) {
  1395. mod->mbhdlr[mc].cbfn = NULL;
  1396. mod->mbhdlr[mc].cbarg = ioc->bfa;
  1397. }
  1398. }
  1399. /*
  1400. * Mbox poll timer -- restarts any pending mailbox requests.
  1401. */
  1402. static void
  1403. bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
  1404. {
  1405. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1406. struct bfa_mbox_cmd_s *cmd;
  1407. u32 stat;
  1408. /*
  1409. * If no command pending, do nothing
  1410. */
  1411. if (list_empty(&mod->cmd_q))
  1412. return;
  1413. /*
  1414. * If previous command is not yet fetched by firmware, do nothing
  1415. */
  1416. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  1417. if (stat)
  1418. return;
  1419. /*
  1420. * Enqueue command to firmware.
  1421. */
  1422. bfa_q_deq(&mod->cmd_q, &cmd);
  1423. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1424. }
  1425. /*
  1426. * Cleanup any pending requests.
  1427. */
  1428. static void
  1429. bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc)
  1430. {
  1431. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1432. struct bfa_mbox_cmd_s *cmd;
  1433. while (!list_empty(&mod->cmd_q))
  1434. bfa_q_deq(&mod->cmd_q, &cmd);
  1435. }
  1436. /*
  1437. * Read data from SMEM to host through PCI memmap
  1438. *
  1439. * @param[in] ioc memory for IOC
  1440. * @param[in] tbuf app memory to store data from smem
  1441. * @param[in] soff smem offset
  1442. * @param[in] sz size of smem in bytes
  1443. */
  1444. static bfa_status_t
  1445. bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
  1446. {
  1447. u32 pgnum, loff;
  1448. __be32 r32;
  1449. int i, len;
  1450. u32 *buf = tbuf;
  1451. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
  1452. loff = PSS_SMEM_PGOFF(soff);
  1453. bfa_trc(ioc, pgnum);
  1454. bfa_trc(ioc, loff);
  1455. bfa_trc(ioc, sz);
  1456. /*
  1457. * Hold semaphore to serialize pll init and fwtrc.
  1458. */
  1459. if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
  1460. bfa_trc(ioc, 0);
  1461. return BFA_STATUS_FAILED;
  1462. }
  1463. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1464. len = sz/sizeof(u32);
  1465. bfa_trc(ioc, len);
  1466. for (i = 0; i < len; i++) {
  1467. r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  1468. buf[i] = be32_to_cpu(r32);
  1469. loff += sizeof(u32);
  1470. /*
  1471. * handle page offset wrap around
  1472. */
  1473. loff = PSS_SMEM_PGOFF(loff);
  1474. if (loff == 0) {
  1475. pgnum++;
  1476. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1477. }
  1478. }
  1479. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1480. ioc->ioc_regs.host_page_num_fn);
  1481. /*
  1482. * release semaphore.
  1483. */
  1484. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1485. bfa_trc(ioc, pgnum);
  1486. return BFA_STATUS_OK;
  1487. }
  1488. /*
  1489. * Clear SMEM data from host through PCI memmap
  1490. *
  1491. * @param[in] ioc memory for IOC
  1492. * @param[in] soff smem offset
  1493. * @param[in] sz size of smem in bytes
  1494. */
  1495. static bfa_status_t
  1496. bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
  1497. {
  1498. int i, len;
  1499. u32 pgnum, loff;
  1500. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
  1501. loff = PSS_SMEM_PGOFF(soff);
  1502. bfa_trc(ioc, pgnum);
  1503. bfa_trc(ioc, loff);
  1504. bfa_trc(ioc, sz);
  1505. /*
  1506. * Hold semaphore to serialize pll init and fwtrc.
  1507. */
  1508. if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
  1509. bfa_trc(ioc, 0);
  1510. return BFA_STATUS_FAILED;
  1511. }
  1512. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1513. len = sz/sizeof(u32); /* len in words */
  1514. bfa_trc(ioc, len);
  1515. for (i = 0; i < len; i++) {
  1516. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
  1517. loff += sizeof(u32);
  1518. /*
  1519. * handle page offset wrap around
  1520. */
  1521. loff = PSS_SMEM_PGOFF(loff);
  1522. if (loff == 0) {
  1523. pgnum++;
  1524. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1525. }
  1526. }
  1527. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1528. ioc->ioc_regs.host_page_num_fn);
  1529. /*
  1530. * release semaphore.
  1531. */
  1532. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1533. bfa_trc(ioc, pgnum);
  1534. return BFA_STATUS_OK;
  1535. }
  1536. static void
  1537. bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
  1538. {
  1539. struct list_head *qe;
  1540. struct bfa_ioc_hbfail_notify_s *notify;
  1541. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  1542. /**
  1543. * Notify driver and common modules registered for notification.
  1544. */
  1545. ioc->cbfn->hbfail_cbfn(ioc->bfa);
  1546. list_for_each(qe, &ioc->hb_notify_q) {
  1547. notify = (struct bfa_ioc_hbfail_notify_s *) qe;
  1548. notify->cbfn(notify->cbarg);
  1549. }
  1550. bfa_ioc_debug_save_ftrc(ioc);
  1551. BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
  1552. "Heart Beat of IOC has failed\n");
  1553. }
  1554. static void
  1555. bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
  1556. {
  1557. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  1558. /*
  1559. * Provide enable completion callback.
  1560. */
  1561. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  1562. BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
  1563. "Running firmware version is incompatible "
  1564. "with the driver version\n");
  1565. }
  1566. bfa_status_t
  1567. bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
  1568. {
  1569. /*
  1570. * Hold semaphore so that nobody can access the chip during init.
  1571. */
  1572. bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
  1573. bfa_ioc_pll_init_asic(ioc);
  1574. ioc->pllinit = BFA_TRUE;
  1575. /*
  1576. * release semaphore.
  1577. */
  1578. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1579. return BFA_STATUS_OK;
  1580. }
  1581. /*
  1582. * Interface used by diag module to do firmware boot with memory test
  1583. * as the entry vector.
  1584. */
  1585. void
  1586. bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
  1587. {
  1588. void __iomem *rb;
  1589. bfa_ioc_stats(ioc, ioc_boots);
  1590. if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
  1591. return;
  1592. /*
  1593. * Initialize IOC state of all functions on a chip reset.
  1594. */
  1595. rb = ioc->pcidev.pci_bar_kva;
  1596. if (boot_type == BFI_BOOT_TYPE_MEMTEST) {
  1597. writel(BFI_IOC_MEMTEST, (rb + BFA_IOC0_STATE_REG));
  1598. writel(BFI_IOC_MEMTEST, (rb + BFA_IOC1_STATE_REG));
  1599. } else {
  1600. writel(BFI_IOC_INITING, (rb + BFA_IOC0_STATE_REG));
  1601. writel(BFI_IOC_INITING, (rb + BFA_IOC1_STATE_REG));
  1602. }
  1603. bfa_ioc_msgflush(ioc);
  1604. bfa_ioc_download_fw(ioc, boot_type, boot_env);
  1605. /*
  1606. * Enable interrupts just before starting LPU
  1607. */
  1608. ioc->cbfn->reset_cbfn(ioc->bfa);
  1609. bfa_ioc_lpu_start(ioc);
  1610. }
  1611. /*
  1612. * Enable/disable IOC failure auto recovery.
  1613. */
  1614. void
  1615. bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
  1616. {
  1617. bfa_auto_recover = auto_recover;
  1618. }
  1619. bfa_boolean_t
  1620. bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
  1621. {
  1622. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
  1623. }
  1624. bfa_boolean_t
  1625. bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
  1626. {
  1627. u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
  1628. return ((r32 != BFI_IOC_UNINIT) &&
  1629. (r32 != BFI_IOC_INITING) &&
  1630. (r32 != BFI_IOC_MEMTEST));
  1631. }
  1632. void
  1633. bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
  1634. {
  1635. __be32 *msgp = mbmsg;
  1636. u32 r32;
  1637. int i;
  1638. /*
  1639. * read the MBOX msg
  1640. */
  1641. for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
  1642. i++) {
  1643. r32 = readl(ioc->ioc_regs.lpu_mbox +
  1644. i * sizeof(u32));
  1645. msgp[i] = cpu_to_be32(r32);
  1646. }
  1647. /*
  1648. * turn off mailbox interrupt by clearing mailbox status
  1649. */
  1650. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  1651. readl(ioc->ioc_regs.lpu_mbox_cmd);
  1652. }
  1653. void
  1654. bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
  1655. {
  1656. union bfi_ioc_i2h_msg_u *msg;
  1657. struct bfa_iocpf_s *iocpf = &ioc->iocpf;
  1658. msg = (union bfi_ioc_i2h_msg_u *) m;
  1659. bfa_ioc_stats(ioc, ioc_isrs);
  1660. switch (msg->mh.msg_id) {
  1661. case BFI_IOC_I2H_HBEAT:
  1662. break;
  1663. case BFI_IOC_I2H_READY_EVENT:
  1664. bfa_fsm_send_event(iocpf, IOCPF_E_FWREADY);
  1665. break;
  1666. case BFI_IOC_I2H_ENABLE_REPLY:
  1667. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
  1668. break;
  1669. case BFI_IOC_I2H_DISABLE_REPLY:
  1670. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
  1671. break;
  1672. case BFI_IOC_I2H_GETATTR_REPLY:
  1673. bfa_ioc_getattr_reply(ioc);
  1674. break;
  1675. default:
  1676. bfa_trc(ioc, msg->mh.msg_id);
  1677. bfa_assert(0);
  1678. }
  1679. }
  1680. /*
  1681. * IOC attach time initialization and setup.
  1682. *
  1683. * @param[in] ioc memory for IOC
  1684. * @param[in] bfa driver instance structure
  1685. */
  1686. void
  1687. bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
  1688. struct bfa_timer_mod_s *timer_mod)
  1689. {
  1690. ioc->bfa = bfa;
  1691. ioc->cbfn = cbfn;
  1692. ioc->timer_mod = timer_mod;
  1693. ioc->fcmode = BFA_FALSE;
  1694. ioc->pllinit = BFA_FALSE;
  1695. ioc->dbg_fwsave_once = BFA_TRUE;
  1696. ioc->iocpf.ioc = ioc;
  1697. bfa_ioc_mbox_attach(ioc);
  1698. INIT_LIST_HEAD(&ioc->hb_notify_q);
  1699. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  1700. bfa_fsm_send_event(ioc, IOC_E_RESET);
  1701. }
  1702. /*
  1703. * Driver detach time IOC cleanup.
  1704. */
  1705. void
  1706. bfa_ioc_detach(struct bfa_ioc_s *ioc)
  1707. {
  1708. bfa_fsm_send_event(ioc, IOC_E_DETACH);
  1709. }
  1710. /*
  1711. * Setup IOC PCI properties.
  1712. *
  1713. * @param[in] pcidev PCI device information for this IOC
  1714. */
  1715. void
  1716. bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  1717. enum bfi_mclass mc)
  1718. {
  1719. ioc->ioc_mc = mc;
  1720. ioc->pcidev = *pcidev;
  1721. ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
  1722. ioc->cna = ioc->ctdev && !ioc->fcmode;
  1723. /*
  1724. * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
  1725. */
  1726. if (ioc->ctdev)
  1727. bfa_ioc_set_ct_hwif(ioc);
  1728. else
  1729. bfa_ioc_set_cb_hwif(ioc);
  1730. bfa_ioc_map_port(ioc);
  1731. bfa_ioc_reg_init(ioc);
  1732. }
  1733. /*
  1734. * Initialize IOC dma memory
  1735. *
  1736. * @param[in] dm_kva kernel virtual address of IOC dma memory
  1737. * @param[in] dm_pa physical address of IOC dma memory
  1738. */
  1739. void
  1740. bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
  1741. {
  1742. /*
  1743. * dma memory for firmware attribute
  1744. */
  1745. ioc->attr_dma.kva = dm_kva;
  1746. ioc->attr_dma.pa = dm_pa;
  1747. ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
  1748. }
  1749. void
  1750. bfa_ioc_enable(struct bfa_ioc_s *ioc)
  1751. {
  1752. bfa_ioc_stats(ioc, ioc_enables);
  1753. ioc->dbg_fwsave_once = BFA_TRUE;
  1754. bfa_fsm_send_event(ioc, IOC_E_ENABLE);
  1755. }
  1756. void
  1757. bfa_ioc_disable(struct bfa_ioc_s *ioc)
  1758. {
  1759. bfa_ioc_stats(ioc, ioc_disables);
  1760. bfa_fsm_send_event(ioc, IOC_E_DISABLE);
  1761. }
  1762. /*
  1763. * Initialize memory for saving firmware trace. Driver must initialize
  1764. * trace memory before call bfa_ioc_enable().
  1765. */
  1766. void
  1767. bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
  1768. {
  1769. ioc->dbg_fwsave = dbg_fwsave;
  1770. ioc->dbg_fwsave_len = (ioc->iocpf.auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
  1771. }
  1772. /*
  1773. * Register mailbox message handler functions
  1774. *
  1775. * @param[in] ioc IOC instance
  1776. * @param[in] mcfuncs message class handler functions
  1777. */
  1778. void
  1779. bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
  1780. {
  1781. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1782. int mc;
  1783. for (mc = 0; mc < BFI_MC_MAX; mc++)
  1784. mod->mbhdlr[mc].cbfn = mcfuncs[mc];
  1785. }
  1786. /*
  1787. * Register mailbox message handler function, to be called by common modules
  1788. */
  1789. void
  1790. bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  1791. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
  1792. {
  1793. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1794. mod->mbhdlr[mc].cbfn = cbfn;
  1795. mod->mbhdlr[mc].cbarg = cbarg;
  1796. }
  1797. /*
  1798. * Queue a mailbox command request to firmware. Waits if mailbox is busy.
  1799. * Responsibility of caller to serialize
  1800. *
  1801. * @param[in] ioc IOC instance
  1802. * @param[i] cmd Mailbox command
  1803. */
  1804. void
  1805. bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
  1806. {
  1807. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1808. u32 stat;
  1809. /*
  1810. * If a previous command is pending, queue new command
  1811. */
  1812. if (!list_empty(&mod->cmd_q)) {
  1813. list_add_tail(&cmd->qe, &mod->cmd_q);
  1814. return;
  1815. }
  1816. /*
  1817. * If mailbox is busy, queue command for poll timer
  1818. */
  1819. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  1820. if (stat) {
  1821. list_add_tail(&cmd->qe, &mod->cmd_q);
  1822. return;
  1823. }
  1824. /*
  1825. * mailbox is free -- queue command to firmware
  1826. */
  1827. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1828. }
  1829. /*
  1830. * Handle mailbox interrupts
  1831. */
  1832. void
  1833. bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
  1834. {
  1835. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1836. struct bfi_mbmsg_s m;
  1837. int mc;
  1838. bfa_ioc_msgget(ioc, &m);
  1839. /*
  1840. * Treat IOC message class as special.
  1841. */
  1842. mc = m.mh.msg_class;
  1843. if (mc == BFI_MC_IOC) {
  1844. bfa_ioc_isr(ioc, &m);
  1845. return;
  1846. }
  1847. if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
  1848. return;
  1849. mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
  1850. }
  1851. void
  1852. bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
  1853. {
  1854. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  1855. }
  1856. void
  1857. bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
  1858. {
  1859. ioc->fcmode = BFA_TRUE;
  1860. ioc->port_id = bfa_ioc_pcifn(ioc);
  1861. }
  1862. /*
  1863. * return true if IOC is disabled
  1864. */
  1865. bfa_boolean_t
  1866. bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
  1867. {
  1868. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
  1869. bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
  1870. }
  1871. /*
  1872. * return true if IOC firmware is different.
  1873. */
  1874. bfa_boolean_t
  1875. bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
  1876. {
  1877. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
  1878. bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
  1879. bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
  1880. }
  1881. #define bfa_ioc_state_disabled(__sm) \
  1882. (((__sm) == BFI_IOC_UNINIT) || \
  1883. ((__sm) == BFI_IOC_INITING) || \
  1884. ((__sm) == BFI_IOC_HWINIT) || \
  1885. ((__sm) == BFI_IOC_DISABLED) || \
  1886. ((__sm) == BFI_IOC_FAIL) || \
  1887. ((__sm) == BFI_IOC_CFG_DISABLED))
  1888. /*
  1889. * Check if adapter is disabled -- both IOCs should be in a disabled
  1890. * state.
  1891. */
  1892. bfa_boolean_t
  1893. bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
  1894. {
  1895. u32 ioc_state;
  1896. void __iomem *rb = ioc->pcidev.pci_bar_kva;
  1897. if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
  1898. return BFA_FALSE;
  1899. ioc_state = readl(rb + BFA_IOC0_STATE_REG);
  1900. if (!bfa_ioc_state_disabled(ioc_state))
  1901. return BFA_FALSE;
  1902. if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
  1903. ioc_state = readl(rb + BFA_IOC1_STATE_REG);
  1904. if (!bfa_ioc_state_disabled(ioc_state))
  1905. return BFA_FALSE;
  1906. }
  1907. return BFA_TRUE;
  1908. }
  1909. /**
  1910. * Reset IOC fwstate registers.
  1911. */
  1912. void
  1913. bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
  1914. {
  1915. writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
  1916. writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
  1917. }
  1918. #define BFA_MFG_NAME "Brocade"
  1919. void
  1920. bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  1921. struct bfa_adapter_attr_s *ad_attr)
  1922. {
  1923. struct bfi_ioc_attr_s *ioc_attr;
  1924. ioc_attr = ioc->attr;
  1925. bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
  1926. bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
  1927. bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
  1928. bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
  1929. memcpy(&ad_attr->vpd, &ioc_attr->vpd,
  1930. sizeof(struct bfa_mfg_vpd_s));
  1931. ad_attr->nports = bfa_ioc_get_nports(ioc);
  1932. ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
  1933. bfa_ioc_get_adapter_model(ioc, ad_attr->model);
  1934. /* For now, model descr uses same model string */
  1935. bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
  1936. ad_attr->card_type = ioc_attr->card_type;
  1937. ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
  1938. if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
  1939. ad_attr->prototype = 1;
  1940. else
  1941. ad_attr->prototype = 0;
  1942. ad_attr->pwwn = ioc->attr->pwwn;
  1943. ad_attr->mac = bfa_ioc_get_mac(ioc);
  1944. ad_attr->pcie_gen = ioc_attr->pcie_gen;
  1945. ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
  1946. ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
  1947. ad_attr->asic_rev = ioc_attr->asic_rev;
  1948. bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
  1949. ad_attr->cna_capable = ioc->cna;
  1950. ad_attr->trunk_capable = (ad_attr->nports > 1) && !ioc->cna &&
  1951. !ad_attr->is_mezz;
  1952. }
  1953. enum bfa_ioc_type_e
  1954. bfa_ioc_get_type(struct bfa_ioc_s *ioc)
  1955. {
  1956. if (!ioc->ctdev || ioc->fcmode)
  1957. return BFA_IOC_TYPE_FC;
  1958. else if (ioc->ioc_mc == BFI_MC_IOCFC)
  1959. return BFA_IOC_TYPE_FCoE;
  1960. else if (ioc->ioc_mc == BFI_MC_LL)
  1961. return BFA_IOC_TYPE_LL;
  1962. else {
  1963. bfa_assert(ioc->ioc_mc == BFI_MC_LL);
  1964. return BFA_IOC_TYPE_LL;
  1965. }
  1966. }
  1967. void
  1968. bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
  1969. {
  1970. memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
  1971. memcpy((void *)serial_num,
  1972. (void *)ioc->attr->brcd_serialnum,
  1973. BFA_ADAPTER_SERIAL_NUM_LEN);
  1974. }
  1975. void
  1976. bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
  1977. {
  1978. memset((void *)fw_ver, 0, BFA_VERSION_LEN);
  1979. memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
  1980. }
  1981. void
  1982. bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
  1983. {
  1984. bfa_assert(chip_rev);
  1985. memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
  1986. chip_rev[0] = 'R';
  1987. chip_rev[1] = 'e';
  1988. chip_rev[2] = 'v';
  1989. chip_rev[3] = '-';
  1990. chip_rev[4] = ioc->attr->asic_rev;
  1991. chip_rev[5] = '\0';
  1992. }
  1993. void
  1994. bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
  1995. {
  1996. memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
  1997. memcpy(optrom_ver, ioc->attr->optrom_version,
  1998. BFA_VERSION_LEN);
  1999. }
  2000. void
  2001. bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
  2002. {
  2003. memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
  2004. memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
  2005. }
  2006. void
  2007. bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
  2008. {
  2009. struct bfi_ioc_attr_s *ioc_attr;
  2010. bfa_assert(model);
  2011. memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
  2012. ioc_attr = ioc->attr;
  2013. /*
  2014. * model name
  2015. */
  2016. snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
  2017. BFA_MFG_NAME, ioc_attr->card_type);
  2018. }
  2019. enum bfa_ioc_state
  2020. bfa_ioc_get_state(struct bfa_ioc_s *ioc)
  2021. {
  2022. enum bfa_iocpf_state iocpf_st;
  2023. enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
  2024. if (ioc_st == BFA_IOC_ENABLING ||
  2025. ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
  2026. iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
  2027. switch (iocpf_st) {
  2028. case BFA_IOCPF_SEMWAIT:
  2029. ioc_st = BFA_IOC_SEMWAIT;
  2030. break;
  2031. case BFA_IOCPF_HWINIT:
  2032. ioc_st = BFA_IOC_HWINIT;
  2033. break;
  2034. case BFA_IOCPF_FWMISMATCH:
  2035. ioc_st = BFA_IOC_FWMISMATCH;
  2036. break;
  2037. case BFA_IOCPF_FAIL:
  2038. ioc_st = BFA_IOC_FAIL;
  2039. break;
  2040. case BFA_IOCPF_INITFAIL:
  2041. ioc_st = BFA_IOC_INITFAIL;
  2042. break;
  2043. default:
  2044. break;
  2045. }
  2046. }
  2047. return ioc_st;
  2048. }
  2049. void
  2050. bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
  2051. {
  2052. memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
  2053. ioc_attr->state = bfa_ioc_get_state(ioc);
  2054. ioc_attr->port_id = ioc->port_id;
  2055. ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
  2056. bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
  2057. ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
  2058. ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
  2059. bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
  2060. }
  2061. mac_t
  2062. bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
  2063. {
  2064. /*
  2065. * Check the IOC type and return the appropriate MAC
  2066. */
  2067. if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
  2068. return ioc->attr->fcoe_mac;
  2069. else
  2070. return ioc->attr->mac;
  2071. }
  2072. mac_t
  2073. bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
  2074. {
  2075. mac_t m;
  2076. m = ioc->attr->mfg_mac;
  2077. if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
  2078. m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
  2079. else
  2080. bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
  2081. bfa_ioc_pcifn(ioc));
  2082. return m;
  2083. }
  2084. bfa_boolean_t
  2085. bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
  2086. {
  2087. return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id);
  2088. }
  2089. /*
  2090. * Retrieve saved firmware trace from a prior IOC failure.
  2091. */
  2092. bfa_status_t
  2093. bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  2094. {
  2095. int tlen;
  2096. if (ioc->dbg_fwsave_len == 0)
  2097. return BFA_STATUS_ENOFSAVE;
  2098. tlen = *trclen;
  2099. if (tlen > ioc->dbg_fwsave_len)
  2100. tlen = ioc->dbg_fwsave_len;
  2101. memcpy(trcdata, ioc->dbg_fwsave, tlen);
  2102. *trclen = tlen;
  2103. return BFA_STATUS_OK;
  2104. }
  2105. /*
  2106. * Retrieve saved firmware trace from a prior IOC failure.
  2107. */
  2108. bfa_status_t
  2109. bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  2110. {
  2111. u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
  2112. int tlen;
  2113. bfa_status_t status;
  2114. bfa_trc(ioc, *trclen);
  2115. tlen = *trclen;
  2116. if (tlen > BFA_DBG_FWTRC_LEN)
  2117. tlen = BFA_DBG_FWTRC_LEN;
  2118. status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
  2119. *trclen = tlen;
  2120. return status;
  2121. }
  2122. static void
  2123. bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
  2124. {
  2125. struct bfa_mbox_cmd_s cmd;
  2126. struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
  2127. bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
  2128. bfa_ioc_portid(ioc));
  2129. req->ioc_class = ioc->ioc_mc;
  2130. bfa_ioc_mbox_queue(ioc, &cmd);
  2131. }
  2132. static void
  2133. bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
  2134. {
  2135. u32 fwsync_iter = 1000;
  2136. bfa_ioc_send_fwsync(ioc);
  2137. /*
  2138. * After sending a fw sync mbox command wait for it to
  2139. * take effect. We will not wait for a response because
  2140. * 1. fw_sync mbox cmd doesn't have a response.
  2141. * 2. Even if we implement that, interrupts might not
  2142. * be enabled when we call this function.
  2143. * So, just keep checking if any mbox cmd is pending, and
  2144. * after waiting for a reasonable amount of time, go ahead.
  2145. * It is possible that fw has crashed and the mbox command
  2146. * is never acknowledged.
  2147. */
  2148. while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
  2149. fwsync_iter--;
  2150. }
  2151. /*
  2152. * Dump firmware smem
  2153. */
  2154. bfa_status_t
  2155. bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
  2156. u32 *offset, int *buflen)
  2157. {
  2158. u32 loff;
  2159. int dlen;
  2160. bfa_status_t status;
  2161. u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
  2162. if (*offset >= smem_len) {
  2163. *offset = *buflen = 0;
  2164. return BFA_STATUS_EINVAL;
  2165. }
  2166. loff = *offset;
  2167. dlen = *buflen;
  2168. /*
  2169. * First smem read, sync smem before proceeding
  2170. * No need to sync before reading every chunk.
  2171. */
  2172. if (loff == 0)
  2173. bfa_ioc_fwsync(ioc);
  2174. if ((loff + dlen) >= smem_len)
  2175. dlen = smem_len - loff;
  2176. status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
  2177. if (status != BFA_STATUS_OK) {
  2178. *offset = *buflen = 0;
  2179. return status;
  2180. }
  2181. *offset += dlen;
  2182. if (*offset >= smem_len)
  2183. *offset = 0;
  2184. *buflen = dlen;
  2185. return status;
  2186. }
  2187. /*
  2188. * Firmware statistics
  2189. */
  2190. bfa_status_t
  2191. bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
  2192. {
  2193. u32 loff = BFI_IOC_FWSTATS_OFF + \
  2194. BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
  2195. int tlen;
  2196. bfa_status_t status;
  2197. if (ioc->stats_busy) {
  2198. bfa_trc(ioc, ioc->stats_busy);
  2199. return BFA_STATUS_DEVBUSY;
  2200. }
  2201. ioc->stats_busy = BFA_TRUE;
  2202. tlen = sizeof(struct bfa_fw_stats_s);
  2203. status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
  2204. ioc->stats_busy = BFA_FALSE;
  2205. return status;
  2206. }
  2207. bfa_status_t
  2208. bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
  2209. {
  2210. u32 loff = BFI_IOC_FWSTATS_OFF + \
  2211. BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
  2212. int tlen;
  2213. bfa_status_t status;
  2214. if (ioc->stats_busy) {
  2215. bfa_trc(ioc, ioc->stats_busy);
  2216. return BFA_STATUS_DEVBUSY;
  2217. }
  2218. ioc->stats_busy = BFA_TRUE;
  2219. tlen = sizeof(struct bfa_fw_stats_s);
  2220. status = bfa_ioc_smem_clr(ioc, loff, tlen);
  2221. ioc->stats_busy = BFA_FALSE;
  2222. return status;
  2223. }
  2224. /*
  2225. * Save firmware trace if configured.
  2226. */
  2227. static void
  2228. bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
  2229. {
  2230. int tlen;
  2231. if (ioc->dbg_fwsave_once) {
  2232. ioc->dbg_fwsave_once = BFA_FALSE;
  2233. if (ioc->dbg_fwsave_len) {
  2234. tlen = ioc->dbg_fwsave_len;
  2235. bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
  2236. }
  2237. }
  2238. }
  2239. /*
  2240. * Firmware failure detected. Start recovery actions.
  2241. */
  2242. static void
  2243. bfa_ioc_recover(struct bfa_ioc_s *ioc)
  2244. {
  2245. bfa_ioc_stats(ioc, ioc_hbfails);
  2246. bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
  2247. }
  2248. static void
  2249. bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
  2250. {
  2251. if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
  2252. return;
  2253. }
  2254. /*
  2255. * BFA IOC PF private functions
  2256. */
  2257. static void
  2258. bfa_iocpf_timeout(void *ioc_arg)
  2259. {
  2260. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2261. bfa_trc(ioc, 0);
  2262. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
  2263. }
  2264. static void
  2265. bfa_iocpf_sem_timeout(void *ioc_arg)
  2266. {
  2267. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2268. bfa_ioc_hw_sem_get(ioc);
  2269. }
  2270. /*
  2271. * bfa timer function
  2272. */
  2273. void
  2274. bfa_timer_beat(struct bfa_timer_mod_s *mod)
  2275. {
  2276. struct list_head *qh = &mod->timer_q;
  2277. struct list_head *qe, *qe_next;
  2278. struct bfa_timer_s *elem;
  2279. struct list_head timedout_q;
  2280. INIT_LIST_HEAD(&timedout_q);
  2281. qe = bfa_q_next(qh);
  2282. while (qe != qh) {
  2283. qe_next = bfa_q_next(qe);
  2284. elem = (struct bfa_timer_s *) qe;
  2285. if (elem->timeout <= BFA_TIMER_FREQ) {
  2286. elem->timeout = 0;
  2287. list_del(&elem->qe);
  2288. list_add_tail(&elem->qe, &timedout_q);
  2289. } else {
  2290. elem->timeout -= BFA_TIMER_FREQ;
  2291. }
  2292. qe = qe_next; /* go to next elem */
  2293. }
  2294. /*
  2295. * Pop all the timeout entries
  2296. */
  2297. while (!list_empty(&timedout_q)) {
  2298. bfa_q_deq(&timedout_q, &elem);
  2299. elem->timercb(elem->arg);
  2300. }
  2301. }
  2302. /*
  2303. * Should be called with lock protection
  2304. */
  2305. void
  2306. bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
  2307. void (*timercb) (void *), void *arg, unsigned int timeout)
  2308. {
  2309. bfa_assert(timercb != NULL);
  2310. bfa_assert(!bfa_q_is_on_q(&mod->timer_q, timer));
  2311. timer->timeout = timeout;
  2312. timer->timercb = timercb;
  2313. timer->arg = arg;
  2314. list_add_tail(&timer->qe, &mod->timer_q);
  2315. }
  2316. /*
  2317. * Should be called with lock protection
  2318. */
  2319. void
  2320. bfa_timer_stop(struct bfa_timer_s *timer)
  2321. {
  2322. bfa_assert(!list_empty(&timer->qe));
  2323. list_del(&timer->qe);
  2324. }