bfa_ioc.c 75 KB

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