bfa_ioc.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770
  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. * Hardware initialization failed.
  858. */
  859. static void
  860. bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  861. {
  862. struct bfa_ioc_s *ioc = iocpf->ioc;
  863. bfa_trc(ioc, event);
  864. switch (event) {
  865. case IOCPF_E_SEMLOCKED:
  866. bfa_ioc_notify_fail(ioc);
  867. bfa_ioc_sync_ack(ioc);
  868. iocpf->retry_count++;
  869. if (iocpf->retry_count >= BFA_IOC_HWINIT_MAX) {
  870. bfa_ioc_sync_leave(ioc);
  871. writel(1, ioc->ioc_regs.ioc_sem_reg);
  872. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
  873. } else {
  874. if (bfa_ioc_sync_complete(ioc))
  875. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  876. else {
  877. writel(1, ioc->ioc_regs.ioc_sem_reg);
  878. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  879. }
  880. }
  881. break;
  882. case IOCPF_E_DISABLE:
  883. bfa_sem_timer_stop(ioc);
  884. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  885. break;
  886. case IOCPF_E_STOP:
  887. bfa_sem_timer_stop(ioc);
  888. bfa_ioc_firmware_unlock(ioc);
  889. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  890. break;
  891. case IOCPF_E_FAIL:
  892. break;
  893. default:
  894. bfa_sm_fault(ioc, event);
  895. }
  896. }
  897. static void
  898. bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
  899. {
  900. bfa_fsm_send_event(iocpf->ioc, IOC_E_INITFAILED);
  901. }
  902. /*
  903. * Hardware initialization failed.
  904. */
  905. static void
  906. bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  907. {
  908. struct bfa_ioc_s *ioc = iocpf->ioc;
  909. bfa_trc(ioc, event);
  910. switch (event) {
  911. case IOCPF_E_DISABLE:
  912. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  913. break;
  914. case IOCPF_E_STOP:
  915. bfa_ioc_firmware_unlock(ioc);
  916. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  917. break;
  918. default:
  919. bfa_sm_fault(ioc, event);
  920. }
  921. }
  922. static void
  923. bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
  924. {
  925. /*
  926. * Mark IOC as failed in hardware and stop firmware.
  927. */
  928. bfa_ioc_lpu_stop(iocpf->ioc);
  929. /*
  930. * Flush any queued up mailbox requests.
  931. */
  932. bfa_ioc_mbox_hbfail(iocpf->ioc);
  933. bfa_ioc_hw_sem_get(iocpf->ioc);
  934. }
  935. static void
  936. bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  937. {
  938. struct bfa_ioc_s *ioc = iocpf->ioc;
  939. bfa_trc(ioc, event);
  940. switch (event) {
  941. case IOCPF_E_SEMLOCKED:
  942. iocpf->retry_count = 0;
  943. bfa_ioc_sync_ack(ioc);
  944. bfa_ioc_notify_fail(ioc);
  945. if (!iocpf->auto_recover) {
  946. bfa_ioc_sync_leave(ioc);
  947. writel(1, ioc->ioc_regs.ioc_sem_reg);
  948. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  949. } else {
  950. if (bfa_ioc_sync_complete(ioc))
  951. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  952. else {
  953. writel(1, ioc->ioc_regs.ioc_sem_reg);
  954. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  955. }
  956. }
  957. break;
  958. case IOCPF_E_DISABLE:
  959. bfa_sem_timer_stop(ioc);
  960. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  961. break;
  962. case IOCPF_E_FAIL:
  963. break;
  964. default:
  965. bfa_sm_fault(ioc, event);
  966. }
  967. }
  968. static void
  969. bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
  970. {
  971. }
  972. /*
  973. * IOC is in failed state.
  974. */
  975. static void
  976. bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  977. {
  978. struct bfa_ioc_s *ioc = iocpf->ioc;
  979. bfa_trc(ioc, event);
  980. switch (event) {
  981. case IOCPF_E_DISABLE:
  982. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  983. break;
  984. default:
  985. bfa_sm_fault(ioc, event);
  986. }
  987. }
  988. /*
  989. * BFA IOC private functions
  990. */
  991. static void
  992. bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
  993. {
  994. struct list_head *qe;
  995. struct bfa_ioc_hbfail_notify_s *notify;
  996. ioc->cbfn->disable_cbfn(ioc->bfa);
  997. /*
  998. * Notify common modules registered for notification.
  999. */
  1000. list_for_each(qe, &ioc->hb_notify_q) {
  1001. notify = (struct bfa_ioc_hbfail_notify_s *) qe;
  1002. notify->cbfn(notify->cbarg);
  1003. }
  1004. }
  1005. bfa_boolean_t
  1006. bfa_ioc_sem_get(void __iomem *sem_reg)
  1007. {
  1008. u32 r32;
  1009. int cnt = 0;
  1010. #define BFA_SEM_SPINCNT 3000
  1011. r32 = readl(sem_reg);
  1012. while (r32 && (cnt < BFA_SEM_SPINCNT)) {
  1013. cnt++;
  1014. udelay(2);
  1015. r32 = readl(sem_reg);
  1016. }
  1017. if (r32 == 0)
  1018. return BFA_TRUE;
  1019. WARN_ON(cnt >= BFA_SEM_SPINCNT);
  1020. return BFA_FALSE;
  1021. }
  1022. static void
  1023. bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
  1024. {
  1025. u32 r32;
  1026. /*
  1027. * First read to the semaphore register will return 0, subsequent reads
  1028. * will return 1. Semaphore is released by writing 1 to the register
  1029. */
  1030. r32 = readl(ioc->ioc_regs.ioc_sem_reg);
  1031. if (r32 == 0) {
  1032. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
  1033. return;
  1034. }
  1035. bfa_sem_timer_start(ioc);
  1036. }
  1037. /*
  1038. * Initialize LPU local memory (aka secondary memory / SRAM)
  1039. */
  1040. static void
  1041. bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
  1042. {
  1043. u32 pss_ctl;
  1044. int i;
  1045. #define PSS_LMEM_INIT_TIME 10000
  1046. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1047. pss_ctl &= ~__PSS_LMEM_RESET;
  1048. pss_ctl |= __PSS_LMEM_INIT_EN;
  1049. /*
  1050. * i2c workaround 12.5khz clock
  1051. */
  1052. pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
  1053. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1054. /*
  1055. * wait for memory initialization to be complete
  1056. */
  1057. i = 0;
  1058. do {
  1059. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1060. i++;
  1061. } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
  1062. /*
  1063. * If memory initialization is not successful, IOC timeout will catch
  1064. * such failures.
  1065. */
  1066. WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
  1067. bfa_trc(ioc, pss_ctl);
  1068. pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
  1069. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1070. }
  1071. static void
  1072. bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
  1073. {
  1074. u32 pss_ctl;
  1075. /*
  1076. * Take processor out of reset.
  1077. */
  1078. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1079. pss_ctl &= ~__PSS_LPU0_RESET;
  1080. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1081. }
  1082. static void
  1083. bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
  1084. {
  1085. u32 pss_ctl;
  1086. /*
  1087. * Put processors in reset.
  1088. */
  1089. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1090. pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
  1091. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1092. }
  1093. /*
  1094. * Get driver and firmware versions.
  1095. */
  1096. void
  1097. bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
  1098. {
  1099. u32 pgnum, pgoff;
  1100. u32 loff = 0;
  1101. int i;
  1102. u32 *fwsig = (u32 *) fwhdr;
  1103. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  1104. pgoff = PSS_SMEM_PGOFF(loff);
  1105. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1106. for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
  1107. i++) {
  1108. fwsig[i] =
  1109. bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  1110. loff += sizeof(u32);
  1111. }
  1112. }
  1113. /*
  1114. * Returns TRUE if same.
  1115. */
  1116. bfa_boolean_t
  1117. bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
  1118. {
  1119. struct bfi_ioc_image_hdr_s *drv_fwhdr;
  1120. int i;
  1121. drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
  1122. bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
  1123. for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
  1124. if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
  1125. bfa_trc(ioc, i);
  1126. bfa_trc(ioc, fwhdr->md5sum[i]);
  1127. bfa_trc(ioc, drv_fwhdr->md5sum[i]);
  1128. return BFA_FALSE;
  1129. }
  1130. }
  1131. bfa_trc(ioc, fwhdr->md5sum[0]);
  1132. return BFA_TRUE;
  1133. }
  1134. /*
  1135. * Return true if current running version is valid. Firmware signature and
  1136. * execution context (driver/bios) must match.
  1137. */
  1138. static bfa_boolean_t
  1139. bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
  1140. {
  1141. struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
  1142. bfa_ioc_fwver_get(ioc, &fwhdr);
  1143. drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
  1144. bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
  1145. if (fwhdr.signature != drv_fwhdr->signature) {
  1146. bfa_trc(ioc, fwhdr.signature);
  1147. bfa_trc(ioc, drv_fwhdr->signature);
  1148. return BFA_FALSE;
  1149. }
  1150. if (swab32(fwhdr.param) != boot_env) {
  1151. bfa_trc(ioc, fwhdr.param);
  1152. bfa_trc(ioc, boot_env);
  1153. return BFA_FALSE;
  1154. }
  1155. return bfa_ioc_fwver_cmp(ioc, &fwhdr);
  1156. }
  1157. /*
  1158. * Conditionally flush any pending message from firmware at start.
  1159. */
  1160. static void
  1161. bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
  1162. {
  1163. u32 r32;
  1164. r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
  1165. if (r32)
  1166. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  1167. }
  1168. static void
  1169. bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
  1170. {
  1171. enum bfi_ioc_state ioc_fwstate;
  1172. bfa_boolean_t fwvalid;
  1173. u32 boot_type;
  1174. u32 boot_env;
  1175. ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
  1176. if (force)
  1177. ioc_fwstate = BFI_IOC_UNINIT;
  1178. bfa_trc(ioc, ioc_fwstate);
  1179. boot_type = BFI_BOOT_TYPE_NORMAL;
  1180. boot_env = BFI_BOOT_LOADER_OS;
  1181. /*
  1182. * check if firmware is valid
  1183. */
  1184. fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
  1185. BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
  1186. if (!fwvalid) {
  1187. bfa_ioc_boot(ioc, boot_type, boot_env);
  1188. return;
  1189. }
  1190. /*
  1191. * If hardware initialization is in progress (initialized by other IOC),
  1192. * just wait for an initialization completion interrupt.
  1193. */
  1194. if (ioc_fwstate == BFI_IOC_INITING) {
  1195. ioc->cbfn->reset_cbfn(ioc->bfa);
  1196. return;
  1197. }
  1198. /*
  1199. * If IOC function is disabled and firmware version is same,
  1200. * just re-enable IOC.
  1201. *
  1202. * If option rom, IOC must not be in operational state. With
  1203. * convergence, IOC will be in operational state when 2nd driver
  1204. * is loaded.
  1205. */
  1206. if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
  1207. /*
  1208. * When using MSI-X any pending firmware ready event should
  1209. * be flushed. Otherwise MSI-X interrupts are not delivered.
  1210. */
  1211. bfa_ioc_msgflush(ioc);
  1212. ioc->cbfn->reset_cbfn(ioc->bfa);
  1213. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
  1214. return;
  1215. }
  1216. /*
  1217. * Initialize the h/w for any other states.
  1218. */
  1219. bfa_ioc_boot(ioc, boot_type, boot_env);
  1220. }
  1221. static void
  1222. bfa_ioc_timeout(void *ioc_arg)
  1223. {
  1224. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  1225. bfa_trc(ioc, 0);
  1226. bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
  1227. }
  1228. void
  1229. bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
  1230. {
  1231. u32 *msgp = (u32 *) ioc_msg;
  1232. u32 i;
  1233. bfa_trc(ioc, msgp[0]);
  1234. bfa_trc(ioc, len);
  1235. WARN_ON(len > BFI_IOC_MSGLEN_MAX);
  1236. /*
  1237. * first write msg to mailbox registers
  1238. */
  1239. for (i = 0; i < len / sizeof(u32); i++)
  1240. writel(cpu_to_le32(msgp[i]),
  1241. ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1242. for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
  1243. writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1244. /*
  1245. * write 1 to mailbox CMD to trigger LPU event
  1246. */
  1247. writel(1, ioc->ioc_regs.hfn_mbox_cmd);
  1248. (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
  1249. }
  1250. static void
  1251. bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
  1252. {
  1253. struct bfi_ioc_ctrl_req_s enable_req;
  1254. struct timeval tv;
  1255. bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
  1256. bfa_ioc_portid(ioc));
  1257. enable_req.ioc_class = ioc->ioc_mc;
  1258. do_gettimeofday(&tv);
  1259. enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
  1260. bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  1261. }
  1262. static void
  1263. bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
  1264. {
  1265. struct bfi_ioc_ctrl_req_s disable_req;
  1266. bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
  1267. bfa_ioc_portid(ioc));
  1268. bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  1269. }
  1270. static void
  1271. bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
  1272. {
  1273. struct bfi_ioc_getattr_req_s attr_req;
  1274. bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
  1275. bfa_ioc_portid(ioc));
  1276. bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
  1277. bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
  1278. }
  1279. static void
  1280. bfa_ioc_hb_check(void *cbarg)
  1281. {
  1282. struct bfa_ioc_s *ioc = cbarg;
  1283. u32 hb_count;
  1284. hb_count = readl(ioc->ioc_regs.heartbeat);
  1285. if (ioc->hb_count == hb_count) {
  1286. bfa_ioc_recover(ioc);
  1287. return;
  1288. } else {
  1289. ioc->hb_count = hb_count;
  1290. }
  1291. bfa_ioc_mbox_poll(ioc);
  1292. bfa_hb_timer_start(ioc);
  1293. }
  1294. static void
  1295. bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
  1296. {
  1297. ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
  1298. bfa_hb_timer_start(ioc);
  1299. }
  1300. /*
  1301. * Initiate a full firmware download.
  1302. */
  1303. static void
  1304. bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
  1305. u32 boot_env)
  1306. {
  1307. u32 *fwimg;
  1308. u32 pgnum, pgoff;
  1309. u32 loff = 0;
  1310. u32 chunkno = 0;
  1311. u32 i;
  1312. /*
  1313. * Initialize LMEM first before code download
  1314. */
  1315. bfa_ioc_lmem_init(ioc);
  1316. bfa_trc(ioc, bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)));
  1317. fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno);
  1318. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  1319. pgoff = PSS_SMEM_PGOFF(loff);
  1320. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1321. for (i = 0; i < bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
  1322. if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
  1323. chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
  1324. fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc),
  1325. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  1326. }
  1327. /*
  1328. * write smem
  1329. */
  1330. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
  1331. fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
  1332. loff += sizeof(u32);
  1333. /*
  1334. * handle page offset wrap around
  1335. */
  1336. loff = PSS_SMEM_PGOFF(loff);
  1337. if (loff == 0) {
  1338. pgnum++;
  1339. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1340. }
  1341. }
  1342. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1343. ioc->ioc_regs.host_page_num_fn);
  1344. /*
  1345. * Set boot type and boot param at the end.
  1346. */
  1347. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF,
  1348. swab32(boot_type));
  1349. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_LOADER_OFF,
  1350. swab32(boot_env));
  1351. }
  1352. /*
  1353. * Update BFA configuration from firmware configuration.
  1354. */
  1355. static void
  1356. bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
  1357. {
  1358. struct bfi_ioc_attr_s *attr = ioc->attr;
  1359. attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
  1360. attr->card_type = be32_to_cpu(attr->card_type);
  1361. attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
  1362. bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
  1363. }
  1364. /*
  1365. * Attach time initialization of mbox logic.
  1366. */
  1367. static void
  1368. bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
  1369. {
  1370. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1371. int mc;
  1372. INIT_LIST_HEAD(&mod->cmd_q);
  1373. for (mc = 0; mc < BFI_MC_MAX; mc++) {
  1374. mod->mbhdlr[mc].cbfn = NULL;
  1375. mod->mbhdlr[mc].cbarg = ioc->bfa;
  1376. }
  1377. }
  1378. /*
  1379. * Mbox poll timer -- restarts any pending mailbox requests.
  1380. */
  1381. static void
  1382. bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
  1383. {
  1384. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1385. struct bfa_mbox_cmd_s *cmd;
  1386. u32 stat;
  1387. /*
  1388. * If no command pending, do nothing
  1389. */
  1390. if (list_empty(&mod->cmd_q))
  1391. return;
  1392. /*
  1393. * If previous command is not yet fetched by firmware, do nothing
  1394. */
  1395. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  1396. if (stat)
  1397. return;
  1398. /*
  1399. * Enqueue command to firmware.
  1400. */
  1401. bfa_q_deq(&mod->cmd_q, &cmd);
  1402. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1403. }
  1404. /*
  1405. * Cleanup any pending requests.
  1406. */
  1407. static void
  1408. bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc)
  1409. {
  1410. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1411. struct bfa_mbox_cmd_s *cmd;
  1412. while (!list_empty(&mod->cmd_q))
  1413. bfa_q_deq(&mod->cmd_q, &cmd);
  1414. }
  1415. /*
  1416. * Read data from SMEM to host through PCI memmap
  1417. *
  1418. * @param[in] ioc memory for IOC
  1419. * @param[in] tbuf app memory to store data from smem
  1420. * @param[in] soff smem offset
  1421. * @param[in] sz size of smem in bytes
  1422. */
  1423. static bfa_status_t
  1424. bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
  1425. {
  1426. u32 pgnum, loff;
  1427. __be32 r32;
  1428. int i, len;
  1429. u32 *buf = tbuf;
  1430. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
  1431. loff = PSS_SMEM_PGOFF(soff);
  1432. bfa_trc(ioc, pgnum);
  1433. bfa_trc(ioc, loff);
  1434. bfa_trc(ioc, sz);
  1435. /*
  1436. * Hold semaphore to serialize pll init and fwtrc.
  1437. */
  1438. if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
  1439. bfa_trc(ioc, 0);
  1440. return BFA_STATUS_FAILED;
  1441. }
  1442. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1443. len = sz/sizeof(u32);
  1444. bfa_trc(ioc, len);
  1445. for (i = 0; i < len; i++) {
  1446. r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  1447. buf[i] = be32_to_cpu(r32);
  1448. loff += sizeof(u32);
  1449. /*
  1450. * handle page offset wrap around
  1451. */
  1452. loff = PSS_SMEM_PGOFF(loff);
  1453. if (loff == 0) {
  1454. pgnum++;
  1455. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1456. }
  1457. }
  1458. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1459. ioc->ioc_regs.host_page_num_fn);
  1460. /*
  1461. * release semaphore.
  1462. */
  1463. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1464. bfa_trc(ioc, pgnum);
  1465. return BFA_STATUS_OK;
  1466. }
  1467. /*
  1468. * Clear SMEM data from host through PCI memmap
  1469. *
  1470. * @param[in] ioc memory for IOC
  1471. * @param[in] soff smem offset
  1472. * @param[in] sz size of smem in bytes
  1473. */
  1474. static bfa_status_t
  1475. bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
  1476. {
  1477. int i, len;
  1478. u32 pgnum, loff;
  1479. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
  1480. loff = PSS_SMEM_PGOFF(soff);
  1481. bfa_trc(ioc, pgnum);
  1482. bfa_trc(ioc, loff);
  1483. bfa_trc(ioc, sz);
  1484. /*
  1485. * Hold semaphore to serialize pll init and fwtrc.
  1486. */
  1487. if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
  1488. bfa_trc(ioc, 0);
  1489. return BFA_STATUS_FAILED;
  1490. }
  1491. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1492. len = sz/sizeof(u32); /* len in words */
  1493. bfa_trc(ioc, len);
  1494. for (i = 0; i < len; i++) {
  1495. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
  1496. loff += sizeof(u32);
  1497. /*
  1498. * handle page offset wrap around
  1499. */
  1500. loff = PSS_SMEM_PGOFF(loff);
  1501. if (loff == 0) {
  1502. pgnum++;
  1503. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1504. }
  1505. }
  1506. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1507. ioc->ioc_regs.host_page_num_fn);
  1508. /*
  1509. * release semaphore.
  1510. */
  1511. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1512. bfa_trc(ioc, pgnum);
  1513. return BFA_STATUS_OK;
  1514. }
  1515. static void
  1516. bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
  1517. {
  1518. struct list_head *qe;
  1519. struct bfa_ioc_hbfail_notify_s *notify;
  1520. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  1521. /*
  1522. * Notify driver and common modules registered for notification.
  1523. */
  1524. ioc->cbfn->hbfail_cbfn(ioc->bfa);
  1525. list_for_each(qe, &ioc->hb_notify_q) {
  1526. notify = (struct bfa_ioc_hbfail_notify_s *) qe;
  1527. notify->cbfn(notify->cbarg);
  1528. }
  1529. bfa_ioc_debug_save_ftrc(ioc);
  1530. BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
  1531. "Heart Beat of IOC has failed\n");
  1532. }
  1533. static void
  1534. bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
  1535. {
  1536. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  1537. /*
  1538. * Provide enable completion callback.
  1539. */
  1540. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  1541. BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
  1542. "Running firmware version is incompatible "
  1543. "with the driver version\n");
  1544. }
  1545. bfa_status_t
  1546. bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
  1547. {
  1548. /*
  1549. * Hold semaphore so that nobody can access the chip during init.
  1550. */
  1551. bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
  1552. bfa_ioc_pll_init_asic(ioc);
  1553. ioc->pllinit = BFA_TRUE;
  1554. /*
  1555. * release semaphore.
  1556. */
  1557. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1558. return BFA_STATUS_OK;
  1559. }
  1560. /*
  1561. * Interface used by diag module to do firmware boot with memory test
  1562. * as the entry vector.
  1563. */
  1564. void
  1565. bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
  1566. {
  1567. void __iomem *rb;
  1568. bfa_ioc_stats(ioc, ioc_boots);
  1569. if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
  1570. return;
  1571. /*
  1572. * Initialize IOC state of all functions on a chip reset.
  1573. */
  1574. rb = ioc->pcidev.pci_bar_kva;
  1575. if (boot_type == BFI_BOOT_TYPE_MEMTEST) {
  1576. writel(BFI_IOC_MEMTEST, (rb + BFA_IOC0_STATE_REG));
  1577. writel(BFI_IOC_MEMTEST, (rb + BFA_IOC1_STATE_REG));
  1578. } else {
  1579. writel(BFI_IOC_INITING, (rb + BFA_IOC0_STATE_REG));
  1580. writel(BFI_IOC_INITING, (rb + BFA_IOC1_STATE_REG));
  1581. }
  1582. bfa_ioc_msgflush(ioc);
  1583. bfa_ioc_download_fw(ioc, boot_type, boot_env);
  1584. /*
  1585. * Enable interrupts just before starting LPU
  1586. */
  1587. ioc->cbfn->reset_cbfn(ioc->bfa);
  1588. bfa_ioc_lpu_start(ioc);
  1589. }
  1590. /*
  1591. * Enable/disable IOC failure auto recovery.
  1592. */
  1593. void
  1594. bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
  1595. {
  1596. bfa_auto_recover = auto_recover;
  1597. }
  1598. bfa_boolean_t
  1599. bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
  1600. {
  1601. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
  1602. }
  1603. bfa_boolean_t
  1604. bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
  1605. {
  1606. u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
  1607. return ((r32 != BFI_IOC_UNINIT) &&
  1608. (r32 != BFI_IOC_INITING) &&
  1609. (r32 != BFI_IOC_MEMTEST));
  1610. }
  1611. void
  1612. bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
  1613. {
  1614. __be32 *msgp = mbmsg;
  1615. u32 r32;
  1616. int i;
  1617. /*
  1618. * read the MBOX msg
  1619. */
  1620. for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
  1621. i++) {
  1622. r32 = readl(ioc->ioc_regs.lpu_mbox +
  1623. i * sizeof(u32));
  1624. msgp[i] = cpu_to_be32(r32);
  1625. }
  1626. /*
  1627. * turn off mailbox interrupt by clearing mailbox status
  1628. */
  1629. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  1630. readl(ioc->ioc_regs.lpu_mbox_cmd);
  1631. }
  1632. void
  1633. bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
  1634. {
  1635. union bfi_ioc_i2h_msg_u *msg;
  1636. struct bfa_iocpf_s *iocpf = &ioc->iocpf;
  1637. msg = (union bfi_ioc_i2h_msg_u *) m;
  1638. bfa_ioc_stats(ioc, ioc_isrs);
  1639. switch (msg->mh.msg_id) {
  1640. case BFI_IOC_I2H_HBEAT:
  1641. break;
  1642. case BFI_IOC_I2H_READY_EVENT:
  1643. bfa_fsm_send_event(iocpf, IOCPF_E_FWREADY);
  1644. break;
  1645. case BFI_IOC_I2H_ENABLE_REPLY:
  1646. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
  1647. break;
  1648. case BFI_IOC_I2H_DISABLE_REPLY:
  1649. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
  1650. break;
  1651. case BFI_IOC_I2H_GETATTR_REPLY:
  1652. bfa_ioc_getattr_reply(ioc);
  1653. break;
  1654. default:
  1655. bfa_trc(ioc, msg->mh.msg_id);
  1656. WARN_ON(1);
  1657. }
  1658. }
  1659. /*
  1660. * IOC attach time initialization and setup.
  1661. *
  1662. * @param[in] ioc memory for IOC
  1663. * @param[in] bfa driver instance structure
  1664. */
  1665. void
  1666. bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
  1667. struct bfa_timer_mod_s *timer_mod)
  1668. {
  1669. ioc->bfa = bfa;
  1670. ioc->cbfn = cbfn;
  1671. ioc->timer_mod = timer_mod;
  1672. ioc->fcmode = BFA_FALSE;
  1673. ioc->pllinit = BFA_FALSE;
  1674. ioc->dbg_fwsave_once = BFA_TRUE;
  1675. ioc->iocpf.ioc = ioc;
  1676. bfa_ioc_mbox_attach(ioc);
  1677. INIT_LIST_HEAD(&ioc->hb_notify_q);
  1678. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  1679. bfa_fsm_send_event(ioc, IOC_E_RESET);
  1680. }
  1681. /*
  1682. * Driver detach time IOC cleanup.
  1683. */
  1684. void
  1685. bfa_ioc_detach(struct bfa_ioc_s *ioc)
  1686. {
  1687. bfa_fsm_send_event(ioc, IOC_E_DETACH);
  1688. }
  1689. /*
  1690. * Setup IOC PCI properties.
  1691. *
  1692. * @param[in] pcidev PCI device information for this IOC
  1693. */
  1694. void
  1695. bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  1696. enum bfi_mclass mc)
  1697. {
  1698. ioc->ioc_mc = mc;
  1699. ioc->pcidev = *pcidev;
  1700. ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
  1701. ioc->cna = ioc->ctdev && !ioc->fcmode;
  1702. /*
  1703. * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
  1704. */
  1705. if (ioc->ctdev)
  1706. bfa_ioc_set_ct_hwif(ioc);
  1707. else
  1708. bfa_ioc_set_cb_hwif(ioc);
  1709. bfa_ioc_map_port(ioc);
  1710. bfa_ioc_reg_init(ioc);
  1711. }
  1712. /*
  1713. * Initialize IOC dma memory
  1714. *
  1715. * @param[in] dm_kva kernel virtual address of IOC dma memory
  1716. * @param[in] dm_pa physical address of IOC dma memory
  1717. */
  1718. void
  1719. bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
  1720. {
  1721. /*
  1722. * dma memory for firmware attribute
  1723. */
  1724. ioc->attr_dma.kva = dm_kva;
  1725. ioc->attr_dma.pa = dm_pa;
  1726. ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
  1727. }
  1728. void
  1729. bfa_ioc_enable(struct bfa_ioc_s *ioc)
  1730. {
  1731. bfa_ioc_stats(ioc, ioc_enables);
  1732. ioc->dbg_fwsave_once = BFA_TRUE;
  1733. bfa_fsm_send_event(ioc, IOC_E_ENABLE);
  1734. }
  1735. void
  1736. bfa_ioc_disable(struct bfa_ioc_s *ioc)
  1737. {
  1738. bfa_ioc_stats(ioc, ioc_disables);
  1739. bfa_fsm_send_event(ioc, IOC_E_DISABLE);
  1740. }
  1741. /*
  1742. * Initialize memory for saving firmware trace. Driver must initialize
  1743. * trace memory before call bfa_ioc_enable().
  1744. */
  1745. void
  1746. bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
  1747. {
  1748. ioc->dbg_fwsave = dbg_fwsave;
  1749. ioc->dbg_fwsave_len = (ioc->iocpf.auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
  1750. }
  1751. /*
  1752. * Register mailbox message handler functions
  1753. *
  1754. * @param[in] ioc IOC instance
  1755. * @param[in] mcfuncs message class handler functions
  1756. */
  1757. void
  1758. bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
  1759. {
  1760. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1761. int mc;
  1762. for (mc = 0; mc < BFI_MC_MAX; mc++)
  1763. mod->mbhdlr[mc].cbfn = mcfuncs[mc];
  1764. }
  1765. /*
  1766. * Register mailbox message handler function, to be called by common modules
  1767. */
  1768. void
  1769. bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  1770. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
  1771. {
  1772. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1773. mod->mbhdlr[mc].cbfn = cbfn;
  1774. mod->mbhdlr[mc].cbarg = cbarg;
  1775. }
  1776. /*
  1777. * Queue a mailbox command request to firmware. Waits if mailbox is busy.
  1778. * Responsibility of caller to serialize
  1779. *
  1780. * @param[in] ioc IOC instance
  1781. * @param[i] cmd Mailbox command
  1782. */
  1783. void
  1784. bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
  1785. {
  1786. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1787. u32 stat;
  1788. /*
  1789. * If a previous command is pending, queue new command
  1790. */
  1791. if (!list_empty(&mod->cmd_q)) {
  1792. list_add_tail(&cmd->qe, &mod->cmd_q);
  1793. return;
  1794. }
  1795. /*
  1796. * If mailbox is busy, queue command for poll timer
  1797. */
  1798. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  1799. if (stat) {
  1800. list_add_tail(&cmd->qe, &mod->cmd_q);
  1801. return;
  1802. }
  1803. /*
  1804. * mailbox is free -- queue command to firmware
  1805. */
  1806. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1807. }
  1808. /*
  1809. * Handle mailbox interrupts
  1810. */
  1811. void
  1812. bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
  1813. {
  1814. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1815. struct bfi_mbmsg_s m;
  1816. int mc;
  1817. bfa_ioc_msgget(ioc, &m);
  1818. /*
  1819. * Treat IOC message class as special.
  1820. */
  1821. mc = m.mh.msg_class;
  1822. if (mc == BFI_MC_IOC) {
  1823. bfa_ioc_isr(ioc, &m);
  1824. return;
  1825. }
  1826. if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
  1827. return;
  1828. mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
  1829. }
  1830. void
  1831. bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
  1832. {
  1833. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  1834. }
  1835. void
  1836. bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
  1837. {
  1838. ioc->fcmode = BFA_TRUE;
  1839. ioc->port_id = bfa_ioc_pcifn(ioc);
  1840. }
  1841. /*
  1842. * return true if IOC is disabled
  1843. */
  1844. bfa_boolean_t
  1845. bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
  1846. {
  1847. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
  1848. bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
  1849. }
  1850. /*
  1851. * return true if IOC firmware is different.
  1852. */
  1853. bfa_boolean_t
  1854. bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
  1855. {
  1856. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
  1857. bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
  1858. bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
  1859. }
  1860. #define bfa_ioc_state_disabled(__sm) \
  1861. (((__sm) == BFI_IOC_UNINIT) || \
  1862. ((__sm) == BFI_IOC_INITING) || \
  1863. ((__sm) == BFI_IOC_HWINIT) || \
  1864. ((__sm) == BFI_IOC_DISABLED) || \
  1865. ((__sm) == BFI_IOC_FAIL) || \
  1866. ((__sm) == BFI_IOC_CFG_DISABLED))
  1867. /*
  1868. * Check if adapter is disabled -- both IOCs should be in a disabled
  1869. * state.
  1870. */
  1871. bfa_boolean_t
  1872. bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
  1873. {
  1874. u32 ioc_state;
  1875. void __iomem *rb = ioc->pcidev.pci_bar_kva;
  1876. if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
  1877. return BFA_FALSE;
  1878. ioc_state = readl(rb + BFA_IOC0_STATE_REG);
  1879. if (!bfa_ioc_state_disabled(ioc_state))
  1880. return BFA_FALSE;
  1881. if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
  1882. ioc_state = readl(rb + BFA_IOC1_STATE_REG);
  1883. if (!bfa_ioc_state_disabled(ioc_state))
  1884. return BFA_FALSE;
  1885. }
  1886. return BFA_TRUE;
  1887. }
  1888. /*
  1889. * Reset IOC fwstate registers.
  1890. */
  1891. void
  1892. bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
  1893. {
  1894. writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
  1895. writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
  1896. }
  1897. #define BFA_MFG_NAME "Brocade"
  1898. void
  1899. bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  1900. struct bfa_adapter_attr_s *ad_attr)
  1901. {
  1902. struct bfi_ioc_attr_s *ioc_attr;
  1903. ioc_attr = ioc->attr;
  1904. bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
  1905. bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
  1906. bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
  1907. bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
  1908. memcpy(&ad_attr->vpd, &ioc_attr->vpd,
  1909. sizeof(struct bfa_mfg_vpd_s));
  1910. ad_attr->nports = bfa_ioc_get_nports(ioc);
  1911. ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
  1912. bfa_ioc_get_adapter_model(ioc, ad_attr->model);
  1913. /* For now, model descr uses same model string */
  1914. bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
  1915. ad_attr->card_type = ioc_attr->card_type;
  1916. ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
  1917. if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
  1918. ad_attr->prototype = 1;
  1919. else
  1920. ad_attr->prototype = 0;
  1921. ad_attr->pwwn = ioc->attr->pwwn;
  1922. ad_attr->mac = bfa_ioc_get_mac(ioc);
  1923. ad_attr->pcie_gen = ioc_attr->pcie_gen;
  1924. ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
  1925. ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
  1926. ad_attr->asic_rev = ioc_attr->asic_rev;
  1927. bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
  1928. ad_attr->cna_capable = ioc->cna;
  1929. ad_attr->trunk_capable = (ad_attr->nports > 1) && !ioc->cna &&
  1930. !ad_attr->is_mezz;
  1931. }
  1932. enum bfa_ioc_type_e
  1933. bfa_ioc_get_type(struct bfa_ioc_s *ioc)
  1934. {
  1935. if (!ioc->ctdev || ioc->fcmode)
  1936. return BFA_IOC_TYPE_FC;
  1937. else if (ioc->ioc_mc == BFI_MC_IOCFC)
  1938. return BFA_IOC_TYPE_FCoE;
  1939. else if (ioc->ioc_mc == BFI_MC_LL)
  1940. return BFA_IOC_TYPE_LL;
  1941. else {
  1942. WARN_ON(ioc->ioc_mc != BFI_MC_LL);
  1943. return BFA_IOC_TYPE_LL;
  1944. }
  1945. }
  1946. void
  1947. bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
  1948. {
  1949. memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
  1950. memcpy((void *)serial_num,
  1951. (void *)ioc->attr->brcd_serialnum,
  1952. BFA_ADAPTER_SERIAL_NUM_LEN);
  1953. }
  1954. void
  1955. bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
  1956. {
  1957. memset((void *)fw_ver, 0, BFA_VERSION_LEN);
  1958. memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
  1959. }
  1960. void
  1961. bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
  1962. {
  1963. WARN_ON(!chip_rev);
  1964. memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
  1965. chip_rev[0] = 'R';
  1966. chip_rev[1] = 'e';
  1967. chip_rev[2] = 'v';
  1968. chip_rev[3] = '-';
  1969. chip_rev[4] = ioc->attr->asic_rev;
  1970. chip_rev[5] = '\0';
  1971. }
  1972. void
  1973. bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
  1974. {
  1975. memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
  1976. memcpy(optrom_ver, ioc->attr->optrom_version,
  1977. BFA_VERSION_LEN);
  1978. }
  1979. void
  1980. bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
  1981. {
  1982. memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
  1983. memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
  1984. }
  1985. void
  1986. bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
  1987. {
  1988. struct bfi_ioc_attr_s *ioc_attr;
  1989. WARN_ON(!model);
  1990. memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
  1991. ioc_attr = ioc->attr;
  1992. /*
  1993. * model name
  1994. */
  1995. snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
  1996. BFA_MFG_NAME, ioc_attr->card_type);
  1997. }
  1998. enum bfa_ioc_state
  1999. bfa_ioc_get_state(struct bfa_ioc_s *ioc)
  2000. {
  2001. enum bfa_iocpf_state iocpf_st;
  2002. enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
  2003. if (ioc_st == BFA_IOC_ENABLING ||
  2004. ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
  2005. iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
  2006. switch (iocpf_st) {
  2007. case BFA_IOCPF_SEMWAIT:
  2008. ioc_st = BFA_IOC_SEMWAIT;
  2009. break;
  2010. case BFA_IOCPF_HWINIT:
  2011. ioc_st = BFA_IOC_HWINIT;
  2012. break;
  2013. case BFA_IOCPF_FWMISMATCH:
  2014. ioc_st = BFA_IOC_FWMISMATCH;
  2015. break;
  2016. case BFA_IOCPF_FAIL:
  2017. ioc_st = BFA_IOC_FAIL;
  2018. break;
  2019. case BFA_IOCPF_INITFAIL:
  2020. ioc_st = BFA_IOC_INITFAIL;
  2021. break;
  2022. default:
  2023. break;
  2024. }
  2025. }
  2026. return ioc_st;
  2027. }
  2028. void
  2029. bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
  2030. {
  2031. memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
  2032. ioc_attr->state = bfa_ioc_get_state(ioc);
  2033. ioc_attr->port_id = ioc->port_id;
  2034. ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
  2035. bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
  2036. ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
  2037. ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
  2038. bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
  2039. }
  2040. mac_t
  2041. bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
  2042. {
  2043. /*
  2044. * Check the IOC type and return the appropriate MAC
  2045. */
  2046. if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
  2047. return ioc->attr->fcoe_mac;
  2048. else
  2049. return ioc->attr->mac;
  2050. }
  2051. mac_t
  2052. bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
  2053. {
  2054. mac_t m;
  2055. m = ioc->attr->mfg_mac;
  2056. if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
  2057. m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
  2058. else
  2059. bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
  2060. bfa_ioc_pcifn(ioc));
  2061. return m;
  2062. }
  2063. bfa_boolean_t
  2064. bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
  2065. {
  2066. return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id);
  2067. }
  2068. /*
  2069. * Retrieve saved firmware trace from a prior IOC failure.
  2070. */
  2071. bfa_status_t
  2072. bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  2073. {
  2074. int tlen;
  2075. if (ioc->dbg_fwsave_len == 0)
  2076. return BFA_STATUS_ENOFSAVE;
  2077. tlen = *trclen;
  2078. if (tlen > ioc->dbg_fwsave_len)
  2079. tlen = ioc->dbg_fwsave_len;
  2080. memcpy(trcdata, ioc->dbg_fwsave, tlen);
  2081. *trclen = tlen;
  2082. return BFA_STATUS_OK;
  2083. }
  2084. /*
  2085. * Retrieve saved firmware trace from a prior IOC failure.
  2086. */
  2087. bfa_status_t
  2088. bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  2089. {
  2090. u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
  2091. int tlen;
  2092. bfa_status_t status;
  2093. bfa_trc(ioc, *trclen);
  2094. tlen = *trclen;
  2095. if (tlen > BFA_DBG_FWTRC_LEN)
  2096. tlen = BFA_DBG_FWTRC_LEN;
  2097. status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
  2098. *trclen = tlen;
  2099. return status;
  2100. }
  2101. static void
  2102. bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
  2103. {
  2104. struct bfa_mbox_cmd_s cmd;
  2105. struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
  2106. bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
  2107. bfa_ioc_portid(ioc));
  2108. req->ioc_class = ioc->ioc_mc;
  2109. bfa_ioc_mbox_queue(ioc, &cmd);
  2110. }
  2111. static void
  2112. bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
  2113. {
  2114. u32 fwsync_iter = 1000;
  2115. bfa_ioc_send_fwsync(ioc);
  2116. /*
  2117. * After sending a fw sync mbox command wait for it to
  2118. * take effect. We will not wait for a response because
  2119. * 1. fw_sync mbox cmd doesn't have a response.
  2120. * 2. Even if we implement that, interrupts might not
  2121. * be enabled when we call this function.
  2122. * So, just keep checking if any mbox cmd is pending, and
  2123. * after waiting for a reasonable amount of time, go ahead.
  2124. * It is possible that fw has crashed and the mbox command
  2125. * is never acknowledged.
  2126. */
  2127. while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
  2128. fwsync_iter--;
  2129. }
  2130. /*
  2131. * Dump firmware smem
  2132. */
  2133. bfa_status_t
  2134. bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
  2135. u32 *offset, int *buflen)
  2136. {
  2137. u32 loff;
  2138. int dlen;
  2139. bfa_status_t status;
  2140. u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
  2141. if (*offset >= smem_len) {
  2142. *offset = *buflen = 0;
  2143. return BFA_STATUS_EINVAL;
  2144. }
  2145. loff = *offset;
  2146. dlen = *buflen;
  2147. /*
  2148. * First smem read, sync smem before proceeding
  2149. * No need to sync before reading every chunk.
  2150. */
  2151. if (loff == 0)
  2152. bfa_ioc_fwsync(ioc);
  2153. if ((loff + dlen) >= smem_len)
  2154. dlen = smem_len - loff;
  2155. status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
  2156. if (status != BFA_STATUS_OK) {
  2157. *offset = *buflen = 0;
  2158. return status;
  2159. }
  2160. *offset += dlen;
  2161. if (*offset >= smem_len)
  2162. *offset = 0;
  2163. *buflen = dlen;
  2164. return status;
  2165. }
  2166. /*
  2167. * Firmware statistics
  2168. */
  2169. bfa_status_t
  2170. bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
  2171. {
  2172. u32 loff = BFI_IOC_FWSTATS_OFF + \
  2173. BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
  2174. int tlen;
  2175. bfa_status_t status;
  2176. if (ioc->stats_busy) {
  2177. bfa_trc(ioc, ioc->stats_busy);
  2178. return BFA_STATUS_DEVBUSY;
  2179. }
  2180. ioc->stats_busy = BFA_TRUE;
  2181. tlen = sizeof(struct bfa_fw_stats_s);
  2182. status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
  2183. ioc->stats_busy = BFA_FALSE;
  2184. return status;
  2185. }
  2186. bfa_status_t
  2187. bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
  2188. {
  2189. u32 loff = BFI_IOC_FWSTATS_OFF + \
  2190. BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
  2191. int tlen;
  2192. bfa_status_t status;
  2193. if (ioc->stats_busy) {
  2194. bfa_trc(ioc, ioc->stats_busy);
  2195. return BFA_STATUS_DEVBUSY;
  2196. }
  2197. ioc->stats_busy = BFA_TRUE;
  2198. tlen = sizeof(struct bfa_fw_stats_s);
  2199. status = bfa_ioc_smem_clr(ioc, loff, tlen);
  2200. ioc->stats_busy = BFA_FALSE;
  2201. return status;
  2202. }
  2203. /*
  2204. * Save firmware trace if configured.
  2205. */
  2206. static void
  2207. bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
  2208. {
  2209. int tlen;
  2210. if (ioc->dbg_fwsave_once) {
  2211. ioc->dbg_fwsave_once = BFA_FALSE;
  2212. if (ioc->dbg_fwsave_len) {
  2213. tlen = ioc->dbg_fwsave_len;
  2214. bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
  2215. }
  2216. }
  2217. }
  2218. /*
  2219. * Firmware failure detected. Start recovery actions.
  2220. */
  2221. static void
  2222. bfa_ioc_recover(struct bfa_ioc_s *ioc)
  2223. {
  2224. bfa_ioc_stats(ioc, ioc_hbfails);
  2225. bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
  2226. }
  2227. static void
  2228. bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
  2229. {
  2230. if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
  2231. return;
  2232. }
  2233. /*
  2234. * BFA IOC PF private functions
  2235. */
  2236. static void
  2237. bfa_iocpf_timeout(void *ioc_arg)
  2238. {
  2239. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2240. bfa_trc(ioc, 0);
  2241. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
  2242. }
  2243. static void
  2244. bfa_iocpf_sem_timeout(void *ioc_arg)
  2245. {
  2246. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2247. bfa_ioc_hw_sem_get(ioc);
  2248. }
  2249. /*
  2250. * bfa timer function
  2251. */
  2252. void
  2253. bfa_timer_beat(struct bfa_timer_mod_s *mod)
  2254. {
  2255. struct list_head *qh = &mod->timer_q;
  2256. struct list_head *qe, *qe_next;
  2257. struct bfa_timer_s *elem;
  2258. struct list_head timedout_q;
  2259. INIT_LIST_HEAD(&timedout_q);
  2260. qe = bfa_q_next(qh);
  2261. while (qe != qh) {
  2262. qe_next = bfa_q_next(qe);
  2263. elem = (struct bfa_timer_s *) qe;
  2264. if (elem->timeout <= BFA_TIMER_FREQ) {
  2265. elem->timeout = 0;
  2266. list_del(&elem->qe);
  2267. list_add_tail(&elem->qe, &timedout_q);
  2268. } else {
  2269. elem->timeout -= BFA_TIMER_FREQ;
  2270. }
  2271. qe = qe_next; /* go to next elem */
  2272. }
  2273. /*
  2274. * Pop all the timeout entries
  2275. */
  2276. while (!list_empty(&timedout_q)) {
  2277. bfa_q_deq(&timedout_q, &elem);
  2278. elem->timercb(elem->arg);
  2279. }
  2280. }
  2281. /*
  2282. * Should be called with lock protection
  2283. */
  2284. void
  2285. bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
  2286. void (*timercb) (void *), void *arg, unsigned int timeout)
  2287. {
  2288. WARN_ON(timercb == NULL);
  2289. WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
  2290. timer->timeout = timeout;
  2291. timer->timercb = timercb;
  2292. timer->arg = arg;
  2293. list_add_tail(&timer->qe, &mod->timer_q);
  2294. }
  2295. /*
  2296. * Should be called with lock protection
  2297. */
  2298. void
  2299. bfa_timer_stop(struct bfa_timer_s *timer)
  2300. {
  2301. WARN_ON(list_empty(&timer->qe));
  2302. list_del(&timer->qe);
  2303. }