bfa_ioc.c 71 KB

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