bfa_ioc.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379
  1. /*
  2. * Linux network driver for QLogic BR-series Converged Network Adapter.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License (GPL) Version 2 as
  6. * published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. /*
  14. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  15. * Copyright (c) 2014-2015 QLogic Corporation
  16. * All rights reserved
  17. * www.qlogic.com
  18. */
  19. #include "bfa_ioc.h"
  20. #include "bfi_reg.h"
  21. #include "bfa_defs.h"
  22. /* IOC local definitions */
  23. /* Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details. */
  24. #define bfa_ioc_firmware_lock(__ioc) \
  25. ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
  26. #define bfa_ioc_firmware_unlock(__ioc) \
  27. ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
  28. #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
  29. #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
  30. #define bfa_ioc_notify_fail(__ioc) \
  31. ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
  32. #define bfa_ioc_sync_start(__ioc) \
  33. ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
  34. #define bfa_ioc_sync_join(__ioc) \
  35. ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
  36. #define bfa_ioc_sync_leave(__ioc) \
  37. ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
  38. #define bfa_ioc_sync_ack(__ioc) \
  39. ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
  40. #define bfa_ioc_sync_complete(__ioc) \
  41. ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
  42. #define bfa_ioc_set_cur_ioc_fwstate(__ioc, __fwstate) \
  43. ((__ioc)->ioc_hwif->ioc_set_fwstate(__ioc, __fwstate))
  44. #define bfa_ioc_get_cur_ioc_fwstate(__ioc) \
  45. ((__ioc)->ioc_hwif->ioc_get_fwstate(__ioc))
  46. #define bfa_ioc_set_alt_ioc_fwstate(__ioc, __fwstate) \
  47. ((__ioc)->ioc_hwif->ioc_set_alt_fwstate(__ioc, __fwstate))
  48. static bool bfa_nw_auto_recover = true;
  49. /*
  50. * forward declarations
  51. */
  52. static void bfa_ioc_hw_sem_init(struct bfa_ioc *ioc);
  53. static void bfa_ioc_hw_sem_get(struct bfa_ioc *ioc);
  54. static void bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc);
  55. static void bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force);
  56. static void bfa_ioc_poll_fwinit(struct bfa_ioc *ioc);
  57. static void bfa_ioc_send_enable(struct bfa_ioc *ioc);
  58. static void bfa_ioc_send_disable(struct bfa_ioc *ioc);
  59. static void bfa_ioc_send_getattr(struct bfa_ioc *ioc);
  60. static void bfa_ioc_hb_monitor(struct bfa_ioc *ioc);
  61. static void bfa_ioc_hb_stop(struct bfa_ioc *ioc);
  62. static void bfa_ioc_reset(struct bfa_ioc *ioc, bool force);
  63. static void bfa_ioc_mbox_poll(struct bfa_ioc *ioc);
  64. static void bfa_ioc_mbox_flush(struct bfa_ioc *ioc);
  65. static void bfa_ioc_recover(struct bfa_ioc *ioc);
  66. static void bfa_ioc_event_notify(struct bfa_ioc *, enum bfa_ioc_event);
  67. static void bfa_ioc_disable_comp(struct bfa_ioc *ioc);
  68. static void bfa_ioc_lpu_stop(struct bfa_ioc *ioc);
  69. static void bfa_nw_ioc_debug_save_ftrc(struct bfa_ioc *ioc);
  70. static void bfa_ioc_fail_notify(struct bfa_ioc *ioc);
  71. static void bfa_ioc_pf_enabled(struct bfa_ioc *ioc);
  72. static void bfa_ioc_pf_disabled(struct bfa_ioc *ioc);
  73. static void bfa_ioc_pf_failed(struct bfa_ioc *ioc);
  74. static void bfa_ioc_pf_hwfailed(struct bfa_ioc *ioc);
  75. static void bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc);
  76. static enum bfa_status bfa_ioc_boot(struct bfa_ioc *ioc,
  77. enum bfi_fwboot_type boot_type, u32 boot_param);
  78. static u32 bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr);
  79. static void bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc,
  80. char *serial_num);
  81. static void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc,
  82. char *fw_ver);
  83. static void bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc,
  84. char *chip_rev);
  85. static void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc,
  86. char *optrom_ver);
  87. static void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc,
  88. char *manufacturer);
  89. static void bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model);
  90. static u64 bfa_ioc_get_pwwn(struct bfa_ioc *ioc);
  91. /* IOC state machine definitions/declarations */
  92. enum ioc_event {
  93. IOC_E_RESET = 1, /*!< IOC reset request */
  94. IOC_E_ENABLE = 2, /*!< IOC enable request */
  95. IOC_E_DISABLE = 3, /*!< IOC disable request */
  96. IOC_E_DETACH = 4, /*!< driver detach cleanup */
  97. IOC_E_ENABLED = 5, /*!< f/w enabled */
  98. IOC_E_FWRSP_GETATTR = 6, /*!< IOC get attribute response */
  99. IOC_E_DISABLED = 7, /*!< f/w disabled */
  100. IOC_E_PFFAILED = 8, /*!< failure notice by iocpf sm */
  101. IOC_E_HBFAIL = 9, /*!< heartbeat failure */
  102. IOC_E_HWERROR = 10, /*!< hardware error interrupt */
  103. IOC_E_TIMEOUT = 11, /*!< timeout */
  104. IOC_E_HWFAILED = 12, /*!< PCI mapping failure notice */
  105. };
  106. bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc, enum ioc_event);
  107. bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc, enum ioc_event);
  108. bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc, enum ioc_event);
  109. bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc, enum ioc_event);
  110. bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc, enum ioc_event);
  111. bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc, enum ioc_event);
  112. bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc, enum ioc_event);
  113. bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc, enum ioc_event);
  114. bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc, enum ioc_event);
  115. bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc, enum ioc_event);
  116. static struct bfa_sm_table 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. };
  128. /*
  129. * Forward declareations for iocpf state machine
  130. */
  131. static void bfa_iocpf_enable(struct bfa_ioc *ioc);
  132. static void bfa_iocpf_disable(struct bfa_ioc *ioc);
  133. static void bfa_iocpf_fail(struct bfa_ioc *ioc);
  134. static void bfa_iocpf_initfail(struct bfa_ioc *ioc);
  135. static void bfa_iocpf_getattrfail(struct bfa_ioc *ioc);
  136. static void bfa_iocpf_stop(struct bfa_ioc *ioc);
  137. /* IOCPF state machine events */
  138. enum iocpf_event {
  139. IOCPF_E_ENABLE = 1, /*!< IOCPF enable request */
  140. IOCPF_E_DISABLE = 2, /*!< IOCPF disable request */
  141. IOCPF_E_STOP = 3, /*!< stop on driver detach */
  142. IOCPF_E_FWREADY = 4, /*!< f/w initialization done */
  143. IOCPF_E_FWRSP_ENABLE = 5, /*!< enable f/w response */
  144. IOCPF_E_FWRSP_DISABLE = 6, /*!< disable f/w response */
  145. IOCPF_E_FAIL = 7, /*!< failure notice by ioc sm */
  146. IOCPF_E_INITFAIL = 8, /*!< init fail notice by ioc sm */
  147. IOCPF_E_GETATTRFAIL = 9, /*!< init fail notice by ioc sm */
  148. IOCPF_E_SEMLOCKED = 10, /*!< h/w semaphore is locked */
  149. IOCPF_E_TIMEOUT = 11, /*!< f/w response timeout */
  150. IOCPF_E_SEM_ERROR = 12, /*!< h/w sem mapping error */
  151. };
  152. /* IOCPF states */
  153. enum bfa_iocpf_state {
  154. BFA_IOCPF_RESET = 1, /*!< IOC is in reset state */
  155. BFA_IOCPF_SEMWAIT = 2, /*!< Waiting for IOC h/w semaphore */
  156. BFA_IOCPF_HWINIT = 3, /*!< IOC h/w is being initialized */
  157. BFA_IOCPF_READY = 4, /*!< IOCPF is initialized */
  158. BFA_IOCPF_INITFAIL = 5, /*!< IOCPF failed */
  159. BFA_IOCPF_FAIL = 6, /*!< IOCPF failed */
  160. BFA_IOCPF_DISABLING = 7, /*!< IOCPF is being disabled */
  161. BFA_IOCPF_DISABLED = 8, /*!< IOCPF is disabled */
  162. BFA_IOCPF_FWMISMATCH = 9, /*!< IOC f/w different from drivers */
  163. };
  164. bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf, enum iocpf_event);
  165. bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf, enum iocpf_event);
  166. bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf, enum iocpf_event);
  167. bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf, enum iocpf_event);
  168. bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf, enum iocpf_event);
  169. bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf, enum iocpf_event);
  170. bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf, enum iocpf_event);
  171. bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf,
  172. enum iocpf_event);
  173. bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf, enum iocpf_event);
  174. bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf, enum iocpf_event);
  175. bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf, enum iocpf_event);
  176. bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf, enum iocpf_event);
  177. bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf,
  178. enum iocpf_event);
  179. bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf, enum iocpf_event);
  180. static struct bfa_sm_table iocpf_sm_table[] = {
  181. {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
  182. {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
  183. {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
  184. {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
  185. {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
  186. {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
  187. {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
  188. {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
  189. {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
  190. {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
  191. {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
  192. {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
  193. {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
  194. {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
  195. };
  196. /* IOC State Machine */
  197. /* Beginning state. IOC uninit state. */
  198. static void
  199. bfa_ioc_sm_uninit_entry(struct bfa_ioc *ioc)
  200. {
  201. }
  202. /* IOC is in uninit state. */
  203. static void
  204. bfa_ioc_sm_uninit(struct bfa_ioc *ioc, enum ioc_event event)
  205. {
  206. switch (event) {
  207. case IOC_E_RESET:
  208. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  209. break;
  210. default:
  211. bfa_sm_fault(event);
  212. }
  213. }
  214. /* Reset entry actions -- initialize state machine */
  215. static void
  216. bfa_ioc_sm_reset_entry(struct bfa_ioc *ioc)
  217. {
  218. bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
  219. }
  220. /* IOC is in reset state. */
  221. static void
  222. bfa_ioc_sm_reset(struct bfa_ioc *ioc, enum ioc_event event)
  223. {
  224. switch (event) {
  225. case IOC_E_ENABLE:
  226. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  227. break;
  228. case IOC_E_DISABLE:
  229. bfa_ioc_disable_comp(ioc);
  230. break;
  231. case IOC_E_DETACH:
  232. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  233. break;
  234. default:
  235. bfa_sm_fault(event);
  236. }
  237. }
  238. static void
  239. bfa_ioc_sm_enabling_entry(struct bfa_ioc *ioc)
  240. {
  241. bfa_iocpf_enable(ioc);
  242. }
  243. /* Host IOC function is being enabled, awaiting response from firmware.
  244. * Semaphore is acquired.
  245. */
  246. static void
  247. bfa_ioc_sm_enabling(struct bfa_ioc *ioc, enum ioc_event event)
  248. {
  249. switch (event) {
  250. case IOC_E_ENABLED:
  251. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  252. break;
  253. case IOC_E_PFFAILED:
  254. /* !!! fall through !!! */
  255. case IOC_E_HWERROR:
  256. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  257. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  258. if (event != IOC_E_PFFAILED)
  259. bfa_iocpf_initfail(ioc);
  260. break;
  261. case IOC_E_HWFAILED:
  262. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  263. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  264. break;
  265. case IOC_E_DISABLE:
  266. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  267. break;
  268. case IOC_E_DETACH:
  269. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  270. bfa_iocpf_stop(ioc);
  271. break;
  272. case IOC_E_ENABLE:
  273. break;
  274. default:
  275. bfa_sm_fault(event);
  276. }
  277. }
  278. /* Semaphore should be acquired for version check. */
  279. static void
  280. bfa_ioc_sm_getattr_entry(struct bfa_ioc *ioc)
  281. {
  282. mod_timer(&ioc->ioc_timer, jiffies +
  283. msecs_to_jiffies(BFA_IOC_TOV));
  284. bfa_ioc_send_getattr(ioc);
  285. }
  286. /* IOC configuration in progress. Timer is active. */
  287. static void
  288. bfa_ioc_sm_getattr(struct bfa_ioc *ioc, enum ioc_event event)
  289. {
  290. switch (event) {
  291. case IOC_E_FWRSP_GETATTR:
  292. del_timer(&ioc->ioc_timer);
  293. bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
  294. break;
  295. case IOC_E_PFFAILED:
  296. case IOC_E_HWERROR:
  297. del_timer(&ioc->ioc_timer);
  298. /* fall through */
  299. case IOC_E_TIMEOUT:
  300. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  301. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  302. if (event != IOC_E_PFFAILED)
  303. bfa_iocpf_getattrfail(ioc);
  304. break;
  305. case IOC_E_DISABLE:
  306. del_timer(&ioc->ioc_timer);
  307. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  308. break;
  309. case IOC_E_ENABLE:
  310. break;
  311. default:
  312. bfa_sm_fault(event);
  313. }
  314. }
  315. static void
  316. bfa_ioc_sm_op_entry(struct bfa_ioc *ioc)
  317. {
  318. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
  319. bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
  320. bfa_ioc_hb_monitor(ioc);
  321. }
  322. static void
  323. bfa_ioc_sm_op(struct bfa_ioc *ioc, enum ioc_event event)
  324. {
  325. switch (event) {
  326. case IOC_E_ENABLE:
  327. break;
  328. case IOC_E_DISABLE:
  329. bfa_ioc_hb_stop(ioc);
  330. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  331. break;
  332. case IOC_E_PFFAILED:
  333. case IOC_E_HWERROR:
  334. bfa_ioc_hb_stop(ioc);
  335. /* !!! fall through !!! */
  336. case IOC_E_HBFAIL:
  337. if (ioc->iocpf.auto_recover)
  338. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
  339. else
  340. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  341. bfa_ioc_fail_notify(ioc);
  342. if (event != IOC_E_PFFAILED)
  343. bfa_iocpf_fail(ioc);
  344. break;
  345. default:
  346. bfa_sm_fault(event);
  347. }
  348. }
  349. static void
  350. bfa_ioc_sm_disabling_entry(struct bfa_ioc *ioc)
  351. {
  352. bfa_iocpf_disable(ioc);
  353. }
  354. /* IOC is being disabled */
  355. static void
  356. bfa_ioc_sm_disabling(struct bfa_ioc *ioc, enum ioc_event event)
  357. {
  358. switch (event) {
  359. case IOC_E_DISABLED:
  360. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  361. break;
  362. case IOC_E_HWERROR:
  363. /*
  364. * No state change. Will move to disabled state
  365. * after iocpf sm completes failure processing and
  366. * moves to disabled state.
  367. */
  368. bfa_iocpf_fail(ioc);
  369. break;
  370. case IOC_E_HWFAILED:
  371. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  372. bfa_ioc_disable_comp(ioc);
  373. break;
  374. default:
  375. bfa_sm_fault(event);
  376. }
  377. }
  378. /* IOC disable completion entry. */
  379. static void
  380. bfa_ioc_sm_disabled_entry(struct bfa_ioc *ioc)
  381. {
  382. bfa_ioc_disable_comp(ioc);
  383. }
  384. static void
  385. bfa_ioc_sm_disabled(struct bfa_ioc *ioc, enum ioc_event event)
  386. {
  387. switch (event) {
  388. case IOC_E_ENABLE:
  389. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  390. break;
  391. case IOC_E_DISABLE:
  392. ioc->cbfn->disable_cbfn(ioc->bfa);
  393. break;
  394. case IOC_E_DETACH:
  395. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  396. bfa_iocpf_stop(ioc);
  397. break;
  398. default:
  399. bfa_sm_fault(event);
  400. }
  401. }
  402. static void
  403. bfa_ioc_sm_fail_retry_entry(struct bfa_ioc *ioc)
  404. {
  405. }
  406. /* Hardware initialization retry. */
  407. static void
  408. bfa_ioc_sm_fail_retry(struct bfa_ioc *ioc, enum ioc_event event)
  409. {
  410. switch (event) {
  411. case IOC_E_ENABLED:
  412. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  413. break;
  414. case IOC_E_PFFAILED:
  415. case IOC_E_HWERROR:
  416. /**
  417. * Initialization retry failed.
  418. */
  419. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  420. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  421. if (event != IOC_E_PFFAILED)
  422. bfa_iocpf_initfail(ioc);
  423. break;
  424. case IOC_E_HWFAILED:
  425. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  426. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  427. break;
  428. case IOC_E_ENABLE:
  429. break;
  430. case IOC_E_DISABLE:
  431. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  432. break;
  433. case IOC_E_DETACH:
  434. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  435. bfa_iocpf_stop(ioc);
  436. break;
  437. default:
  438. bfa_sm_fault(event);
  439. }
  440. }
  441. static void
  442. bfa_ioc_sm_fail_entry(struct bfa_ioc *ioc)
  443. {
  444. }
  445. /* IOC failure. */
  446. static void
  447. bfa_ioc_sm_fail(struct bfa_ioc *ioc, enum ioc_event event)
  448. {
  449. switch (event) {
  450. case IOC_E_ENABLE:
  451. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  452. break;
  453. case IOC_E_DISABLE:
  454. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  455. break;
  456. case IOC_E_DETACH:
  457. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  458. bfa_iocpf_stop(ioc);
  459. break;
  460. case IOC_E_HWERROR:
  461. /* HB failure notification, ignore. */
  462. break;
  463. default:
  464. bfa_sm_fault(event);
  465. }
  466. }
  467. static void
  468. bfa_ioc_sm_hwfail_entry(struct bfa_ioc *ioc)
  469. {
  470. }
  471. /* IOC failure. */
  472. static void
  473. bfa_ioc_sm_hwfail(struct bfa_ioc *ioc, enum ioc_event event)
  474. {
  475. switch (event) {
  476. case IOC_E_ENABLE:
  477. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  478. break;
  479. case IOC_E_DISABLE:
  480. ioc->cbfn->disable_cbfn(ioc->bfa);
  481. break;
  482. case IOC_E_DETACH:
  483. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  484. break;
  485. default:
  486. bfa_sm_fault(event);
  487. }
  488. }
  489. /* IOCPF State Machine */
  490. /* Reset entry actions -- initialize state machine */
  491. static void
  492. bfa_iocpf_sm_reset_entry(struct bfa_iocpf *iocpf)
  493. {
  494. iocpf->fw_mismatch_notified = false;
  495. iocpf->auto_recover = bfa_nw_auto_recover;
  496. }
  497. /* Beginning state. IOC is in reset state. */
  498. static void
  499. bfa_iocpf_sm_reset(struct bfa_iocpf *iocpf, enum iocpf_event event)
  500. {
  501. switch (event) {
  502. case IOCPF_E_ENABLE:
  503. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
  504. break;
  505. case IOCPF_E_STOP:
  506. break;
  507. default:
  508. bfa_sm_fault(event);
  509. }
  510. }
  511. /* Semaphore should be acquired for version check. */
  512. static void
  513. bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf *iocpf)
  514. {
  515. bfa_ioc_hw_sem_init(iocpf->ioc);
  516. bfa_ioc_hw_sem_get(iocpf->ioc);
  517. }
  518. /* Awaiting h/w semaphore to continue with version check. */
  519. static void
  520. bfa_iocpf_sm_fwcheck(struct bfa_iocpf *iocpf, enum iocpf_event event)
  521. {
  522. struct bfa_ioc *ioc = iocpf->ioc;
  523. switch (event) {
  524. case IOCPF_E_SEMLOCKED:
  525. if (bfa_ioc_firmware_lock(ioc)) {
  526. if (bfa_ioc_sync_start(ioc)) {
  527. bfa_ioc_sync_join(ioc);
  528. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  529. } else {
  530. bfa_ioc_firmware_unlock(ioc);
  531. bfa_nw_ioc_hw_sem_release(ioc);
  532. mod_timer(&ioc->sem_timer, jiffies +
  533. msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
  534. }
  535. } else {
  536. bfa_nw_ioc_hw_sem_release(ioc);
  537. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
  538. }
  539. break;
  540. case IOCPF_E_SEM_ERROR:
  541. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  542. bfa_ioc_pf_hwfailed(ioc);
  543. break;
  544. case IOCPF_E_DISABLE:
  545. bfa_ioc_hw_sem_get_cancel(ioc);
  546. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  547. bfa_ioc_pf_disabled(ioc);
  548. break;
  549. case IOCPF_E_STOP:
  550. bfa_ioc_hw_sem_get_cancel(ioc);
  551. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  552. break;
  553. default:
  554. bfa_sm_fault(event);
  555. }
  556. }
  557. /* Notify enable completion callback */
  558. static void
  559. bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf *iocpf)
  560. {
  561. /* Call only the first time sm enters fwmismatch state. */
  562. if (!iocpf->fw_mismatch_notified)
  563. bfa_ioc_pf_fwmismatch(iocpf->ioc);
  564. iocpf->fw_mismatch_notified = true;
  565. mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
  566. msecs_to_jiffies(BFA_IOC_TOV));
  567. }
  568. /* Awaiting firmware version match. */
  569. static void
  570. bfa_iocpf_sm_mismatch(struct bfa_iocpf *iocpf, enum iocpf_event event)
  571. {
  572. struct bfa_ioc *ioc = iocpf->ioc;
  573. switch (event) {
  574. case IOCPF_E_TIMEOUT:
  575. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
  576. break;
  577. case IOCPF_E_DISABLE:
  578. del_timer(&ioc->iocpf_timer);
  579. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  580. bfa_ioc_pf_disabled(ioc);
  581. break;
  582. case IOCPF_E_STOP:
  583. del_timer(&ioc->iocpf_timer);
  584. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  585. break;
  586. default:
  587. bfa_sm_fault(event);
  588. }
  589. }
  590. /* Request for semaphore. */
  591. static void
  592. bfa_iocpf_sm_semwait_entry(struct bfa_iocpf *iocpf)
  593. {
  594. bfa_ioc_hw_sem_get(iocpf->ioc);
  595. }
  596. /* Awaiting semaphore for h/w initialzation. */
  597. static void
  598. bfa_iocpf_sm_semwait(struct bfa_iocpf *iocpf, enum iocpf_event event)
  599. {
  600. struct bfa_ioc *ioc = iocpf->ioc;
  601. switch (event) {
  602. case IOCPF_E_SEMLOCKED:
  603. if (bfa_ioc_sync_complete(ioc)) {
  604. bfa_ioc_sync_join(ioc);
  605. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  606. } else {
  607. bfa_nw_ioc_hw_sem_release(ioc);
  608. mod_timer(&ioc->sem_timer, jiffies +
  609. msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
  610. }
  611. break;
  612. case IOCPF_E_SEM_ERROR:
  613. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  614. bfa_ioc_pf_hwfailed(ioc);
  615. break;
  616. case IOCPF_E_DISABLE:
  617. bfa_ioc_hw_sem_get_cancel(ioc);
  618. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  619. break;
  620. default:
  621. bfa_sm_fault(event);
  622. }
  623. }
  624. static void
  625. bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf *iocpf)
  626. {
  627. iocpf->poll_time = 0;
  628. bfa_ioc_reset(iocpf->ioc, false);
  629. }
  630. /* Hardware is being initialized. Interrupts are enabled.
  631. * Holding hardware semaphore lock.
  632. */
  633. static void
  634. bfa_iocpf_sm_hwinit(struct bfa_iocpf *iocpf, enum iocpf_event event)
  635. {
  636. struct bfa_ioc *ioc = iocpf->ioc;
  637. switch (event) {
  638. case IOCPF_E_FWREADY:
  639. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
  640. break;
  641. case IOCPF_E_TIMEOUT:
  642. bfa_nw_ioc_hw_sem_release(ioc);
  643. bfa_ioc_pf_failed(ioc);
  644. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  645. break;
  646. case IOCPF_E_DISABLE:
  647. del_timer(&ioc->iocpf_timer);
  648. bfa_ioc_sync_leave(ioc);
  649. bfa_nw_ioc_hw_sem_release(ioc);
  650. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  651. break;
  652. default:
  653. bfa_sm_fault(event);
  654. }
  655. }
  656. static void
  657. bfa_iocpf_sm_enabling_entry(struct bfa_iocpf *iocpf)
  658. {
  659. mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
  660. msecs_to_jiffies(BFA_IOC_TOV));
  661. /**
  662. * Enable Interrupts before sending fw IOC ENABLE cmd.
  663. */
  664. iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa);
  665. bfa_ioc_send_enable(iocpf->ioc);
  666. }
  667. /* Host IOC function is being enabled, awaiting response from firmware.
  668. * Semaphore is acquired.
  669. */
  670. static void
  671. bfa_iocpf_sm_enabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
  672. {
  673. struct bfa_ioc *ioc = iocpf->ioc;
  674. switch (event) {
  675. case IOCPF_E_FWRSP_ENABLE:
  676. del_timer(&ioc->iocpf_timer);
  677. bfa_nw_ioc_hw_sem_release(ioc);
  678. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
  679. break;
  680. case IOCPF_E_INITFAIL:
  681. del_timer(&ioc->iocpf_timer);
  682. /*
  683. * !!! fall through !!!
  684. */
  685. case IOCPF_E_TIMEOUT:
  686. bfa_nw_ioc_hw_sem_release(ioc);
  687. if (event == IOCPF_E_TIMEOUT)
  688. bfa_ioc_pf_failed(ioc);
  689. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  690. break;
  691. case IOCPF_E_DISABLE:
  692. del_timer(&ioc->iocpf_timer);
  693. bfa_nw_ioc_hw_sem_release(ioc);
  694. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
  695. break;
  696. default:
  697. bfa_sm_fault(event);
  698. }
  699. }
  700. static void
  701. bfa_iocpf_sm_ready_entry(struct bfa_iocpf *iocpf)
  702. {
  703. bfa_ioc_pf_enabled(iocpf->ioc);
  704. }
  705. static void
  706. bfa_iocpf_sm_ready(struct bfa_iocpf *iocpf, enum iocpf_event event)
  707. {
  708. switch (event) {
  709. case IOCPF_E_DISABLE:
  710. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
  711. break;
  712. case IOCPF_E_GETATTRFAIL:
  713. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  714. break;
  715. case IOCPF_E_FAIL:
  716. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
  717. break;
  718. default:
  719. bfa_sm_fault(event);
  720. }
  721. }
  722. static void
  723. bfa_iocpf_sm_disabling_entry(struct bfa_iocpf *iocpf)
  724. {
  725. mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
  726. msecs_to_jiffies(BFA_IOC_TOV));
  727. bfa_ioc_send_disable(iocpf->ioc);
  728. }
  729. /* IOC is being disabled */
  730. static void
  731. bfa_iocpf_sm_disabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
  732. {
  733. struct bfa_ioc *ioc = iocpf->ioc;
  734. switch (event) {
  735. case IOCPF_E_FWRSP_DISABLE:
  736. del_timer(&ioc->iocpf_timer);
  737. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  738. break;
  739. case IOCPF_E_FAIL:
  740. del_timer(&ioc->iocpf_timer);
  741. /*
  742. * !!! fall through !!!
  743. */
  744. case IOCPF_E_TIMEOUT:
  745. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
  746. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  747. break;
  748. case IOCPF_E_FWRSP_ENABLE:
  749. break;
  750. default:
  751. bfa_sm_fault(event);
  752. }
  753. }
  754. static void
  755. bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf *iocpf)
  756. {
  757. bfa_ioc_hw_sem_get(iocpf->ioc);
  758. }
  759. /* IOC hb ack request is being removed. */
  760. static void
  761. bfa_iocpf_sm_disabling_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
  762. {
  763. struct bfa_ioc *ioc = iocpf->ioc;
  764. switch (event) {
  765. case IOCPF_E_SEMLOCKED:
  766. bfa_ioc_sync_leave(ioc);
  767. bfa_nw_ioc_hw_sem_release(ioc);
  768. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  769. break;
  770. case IOCPF_E_SEM_ERROR:
  771. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  772. bfa_ioc_pf_hwfailed(ioc);
  773. break;
  774. case IOCPF_E_FAIL:
  775. break;
  776. default:
  777. bfa_sm_fault(event);
  778. }
  779. }
  780. /* IOC disable completion entry. */
  781. static void
  782. bfa_iocpf_sm_disabled_entry(struct bfa_iocpf *iocpf)
  783. {
  784. bfa_ioc_mbox_flush(iocpf->ioc);
  785. bfa_ioc_pf_disabled(iocpf->ioc);
  786. }
  787. static void
  788. bfa_iocpf_sm_disabled(struct bfa_iocpf *iocpf, enum iocpf_event event)
  789. {
  790. struct bfa_ioc *ioc = iocpf->ioc;
  791. switch (event) {
  792. case IOCPF_E_ENABLE:
  793. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  794. break;
  795. case IOCPF_E_STOP:
  796. bfa_ioc_firmware_unlock(ioc);
  797. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  798. break;
  799. default:
  800. bfa_sm_fault(event);
  801. }
  802. }
  803. static void
  804. bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf *iocpf)
  805. {
  806. bfa_nw_ioc_debug_save_ftrc(iocpf->ioc);
  807. bfa_ioc_hw_sem_get(iocpf->ioc);
  808. }
  809. /* Hardware initialization failed. */
  810. static void
  811. bfa_iocpf_sm_initfail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
  812. {
  813. struct bfa_ioc *ioc = iocpf->ioc;
  814. switch (event) {
  815. case IOCPF_E_SEMLOCKED:
  816. bfa_ioc_notify_fail(ioc);
  817. bfa_ioc_sync_leave(ioc);
  818. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
  819. bfa_nw_ioc_hw_sem_release(ioc);
  820. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
  821. break;
  822. case IOCPF_E_SEM_ERROR:
  823. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  824. bfa_ioc_pf_hwfailed(ioc);
  825. break;
  826. case IOCPF_E_DISABLE:
  827. bfa_ioc_hw_sem_get_cancel(ioc);
  828. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  829. break;
  830. case IOCPF_E_STOP:
  831. bfa_ioc_hw_sem_get_cancel(ioc);
  832. bfa_ioc_firmware_unlock(ioc);
  833. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  834. break;
  835. case IOCPF_E_FAIL:
  836. break;
  837. default:
  838. bfa_sm_fault(event);
  839. }
  840. }
  841. static void
  842. bfa_iocpf_sm_initfail_entry(struct bfa_iocpf *iocpf)
  843. {
  844. }
  845. /* Hardware initialization failed. */
  846. static void
  847. bfa_iocpf_sm_initfail(struct bfa_iocpf *iocpf, enum iocpf_event event)
  848. {
  849. struct bfa_ioc *ioc = iocpf->ioc;
  850. switch (event) {
  851. case IOCPF_E_DISABLE:
  852. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  853. break;
  854. case IOCPF_E_STOP:
  855. bfa_ioc_firmware_unlock(ioc);
  856. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  857. break;
  858. default:
  859. bfa_sm_fault(event);
  860. }
  861. }
  862. static void
  863. bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf *iocpf)
  864. {
  865. /**
  866. * Mark IOC as failed in hardware and stop firmware.
  867. */
  868. bfa_ioc_lpu_stop(iocpf->ioc);
  869. /**
  870. * Flush any queued up mailbox requests.
  871. */
  872. bfa_ioc_mbox_flush(iocpf->ioc);
  873. bfa_ioc_hw_sem_get(iocpf->ioc);
  874. }
  875. /* IOC is in failed state. */
  876. static void
  877. bfa_iocpf_sm_fail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
  878. {
  879. struct bfa_ioc *ioc = iocpf->ioc;
  880. switch (event) {
  881. case IOCPF_E_SEMLOCKED:
  882. bfa_ioc_sync_ack(ioc);
  883. bfa_ioc_notify_fail(ioc);
  884. if (!iocpf->auto_recover) {
  885. bfa_ioc_sync_leave(ioc);
  886. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
  887. bfa_nw_ioc_hw_sem_release(ioc);
  888. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  889. } else {
  890. if (bfa_ioc_sync_complete(ioc))
  891. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  892. else {
  893. bfa_nw_ioc_hw_sem_release(ioc);
  894. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  895. }
  896. }
  897. break;
  898. case IOCPF_E_SEM_ERROR:
  899. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  900. bfa_ioc_pf_hwfailed(ioc);
  901. break;
  902. case IOCPF_E_DISABLE:
  903. bfa_ioc_hw_sem_get_cancel(ioc);
  904. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  905. break;
  906. case IOCPF_E_FAIL:
  907. break;
  908. default:
  909. bfa_sm_fault(event);
  910. }
  911. }
  912. static void
  913. bfa_iocpf_sm_fail_entry(struct bfa_iocpf *iocpf)
  914. {
  915. }
  916. /* IOC is in failed state. */
  917. static void
  918. bfa_iocpf_sm_fail(struct bfa_iocpf *iocpf, enum iocpf_event event)
  919. {
  920. switch (event) {
  921. case IOCPF_E_DISABLE:
  922. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  923. break;
  924. default:
  925. bfa_sm_fault(event);
  926. }
  927. }
  928. /* BFA IOC private functions */
  929. /* Notify common modules registered for notification. */
  930. static void
  931. bfa_ioc_event_notify(struct bfa_ioc *ioc, enum bfa_ioc_event event)
  932. {
  933. struct bfa_ioc_notify *notify;
  934. list_for_each_entry(notify, &ioc->notify_q, qe)
  935. notify->cbfn(notify->cbarg, event);
  936. }
  937. static void
  938. bfa_ioc_disable_comp(struct bfa_ioc *ioc)
  939. {
  940. ioc->cbfn->disable_cbfn(ioc->bfa);
  941. bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
  942. }
  943. bool
  944. bfa_nw_ioc_sem_get(void __iomem *sem_reg)
  945. {
  946. u32 r32;
  947. int cnt = 0;
  948. #define BFA_SEM_SPINCNT 3000
  949. r32 = readl(sem_reg);
  950. while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) {
  951. cnt++;
  952. udelay(2);
  953. r32 = readl(sem_reg);
  954. }
  955. if (!(r32 & 1))
  956. return true;
  957. return false;
  958. }
  959. void
  960. bfa_nw_ioc_sem_release(void __iomem *sem_reg)
  961. {
  962. readl(sem_reg);
  963. writel(1, sem_reg);
  964. }
  965. /* Clear fwver hdr */
  966. static void
  967. bfa_ioc_fwver_clear(struct bfa_ioc *ioc)
  968. {
  969. u32 pgnum, pgoff, loff = 0;
  970. int i;
  971. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  972. pgoff = PSS_SMEM_PGOFF(loff);
  973. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  974. for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr) / sizeof(u32)); i++) {
  975. writel(0, ioc->ioc_regs.smem_page_start + loff);
  976. loff += sizeof(u32);
  977. }
  978. }
  979. static void
  980. bfa_ioc_hw_sem_init(struct bfa_ioc *ioc)
  981. {
  982. struct bfi_ioc_image_hdr fwhdr;
  983. u32 fwstate, r32;
  984. /* Spin on init semaphore to serialize. */
  985. r32 = readl(ioc->ioc_regs.ioc_init_sem_reg);
  986. while (r32 & 0x1) {
  987. udelay(20);
  988. r32 = readl(ioc->ioc_regs.ioc_init_sem_reg);
  989. }
  990. fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
  991. if (fwstate == BFI_IOC_UNINIT) {
  992. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  993. return;
  994. }
  995. bfa_nw_ioc_fwver_get(ioc, &fwhdr);
  996. if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL) {
  997. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  998. return;
  999. }
  1000. bfa_ioc_fwver_clear(ioc);
  1001. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_UNINIT);
  1002. bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_UNINIT);
  1003. /*
  1004. * Try to lock and then unlock the semaphore.
  1005. */
  1006. readl(ioc->ioc_regs.ioc_sem_reg);
  1007. writel(1, ioc->ioc_regs.ioc_sem_reg);
  1008. /* Unlock init semaphore */
  1009. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1010. }
  1011. static void
  1012. bfa_ioc_hw_sem_get(struct bfa_ioc *ioc)
  1013. {
  1014. u32 r32;
  1015. /**
  1016. * First read to the semaphore register will return 0, subsequent reads
  1017. * will return 1. Semaphore is released by writing 1 to the register
  1018. */
  1019. r32 = readl(ioc->ioc_regs.ioc_sem_reg);
  1020. if (r32 == ~0) {
  1021. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEM_ERROR);
  1022. return;
  1023. }
  1024. if (!(r32 & 1)) {
  1025. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
  1026. return;
  1027. }
  1028. mod_timer(&ioc->sem_timer, jiffies +
  1029. msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
  1030. }
  1031. void
  1032. bfa_nw_ioc_hw_sem_release(struct bfa_ioc *ioc)
  1033. {
  1034. writel(1, ioc->ioc_regs.ioc_sem_reg);
  1035. }
  1036. static void
  1037. bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc)
  1038. {
  1039. del_timer(&ioc->sem_timer);
  1040. }
  1041. /* Initialize LPU local memory (aka secondary memory / SRAM) */
  1042. static void
  1043. bfa_ioc_lmem_init(struct bfa_ioc *ioc)
  1044. {
  1045. u32 pss_ctl;
  1046. int i;
  1047. #define PSS_LMEM_INIT_TIME 10000
  1048. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1049. pss_ctl &= ~__PSS_LMEM_RESET;
  1050. pss_ctl |= __PSS_LMEM_INIT_EN;
  1051. /*
  1052. * i2c workaround 12.5khz clock
  1053. */
  1054. pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
  1055. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1056. /**
  1057. * wait for memory initialization to be complete
  1058. */
  1059. i = 0;
  1060. do {
  1061. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1062. i++;
  1063. } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
  1064. /**
  1065. * If memory initialization is not successful, IOC timeout will catch
  1066. * such failures.
  1067. */
  1068. BUG_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
  1069. pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
  1070. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1071. }
  1072. static void
  1073. bfa_ioc_lpu_start(struct bfa_ioc *ioc)
  1074. {
  1075. u32 pss_ctl;
  1076. /**
  1077. * Take processor out of reset.
  1078. */
  1079. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1080. pss_ctl &= ~__PSS_LPU0_RESET;
  1081. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1082. }
  1083. static void
  1084. bfa_ioc_lpu_stop(struct bfa_ioc *ioc)
  1085. {
  1086. u32 pss_ctl;
  1087. /**
  1088. * Put processors in reset.
  1089. */
  1090. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1091. pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
  1092. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1093. }
  1094. /* Get driver and firmware versions. */
  1095. void
  1096. bfa_nw_ioc_fwver_get(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
  1097. {
  1098. u32 pgnum;
  1099. u32 loff = 0;
  1100. int i;
  1101. u32 *fwsig = (u32 *) fwhdr;
  1102. pgnum = bfa_ioc_smem_pgnum(ioc, loff);
  1103. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1104. for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr) / sizeof(u32));
  1105. i++) {
  1106. fwsig[i] =
  1107. swab32(readl(loff + ioc->ioc_regs.smem_page_start));
  1108. loff += sizeof(u32);
  1109. }
  1110. }
  1111. static bool
  1112. bfa_ioc_fwver_md5_check(struct bfi_ioc_image_hdr *fwhdr_1,
  1113. struct bfi_ioc_image_hdr *fwhdr_2)
  1114. {
  1115. int i;
  1116. for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
  1117. if (fwhdr_1->md5sum[i] != fwhdr_2->md5sum[i])
  1118. return false;
  1119. }
  1120. return true;
  1121. }
  1122. /* Returns TRUE if major minor and maintenance are same.
  1123. * If patch version are same, check for MD5 Checksum to be same.
  1124. */
  1125. static bool
  1126. bfa_ioc_fw_ver_compatible(struct bfi_ioc_image_hdr *drv_fwhdr,
  1127. struct bfi_ioc_image_hdr *fwhdr_to_cmp)
  1128. {
  1129. if (drv_fwhdr->signature != fwhdr_to_cmp->signature)
  1130. return false;
  1131. if (drv_fwhdr->fwver.major != fwhdr_to_cmp->fwver.major)
  1132. return false;
  1133. if (drv_fwhdr->fwver.minor != fwhdr_to_cmp->fwver.minor)
  1134. return false;
  1135. if (drv_fwhdr->fwver.maint != fwhdr_to_cmp->fwver.maint)
  1136. return false;
  1137. if (drv_fwhdr->fwver.patch == fwhdr_to_cmp->fwver.patch &&
  1138. drv_fwhdr->fwver.phase == fwhdr_to_cmp->fwver.phase &&
  1139. drv_fwhdr->fwver.build == fwhdr_to_cmp->fwver.build)
  1140. return bfa_ioc_fwver_md5_check(drv_fwhdr, fwhdr_to_cmp);
  1141. return true;
  1142. }
  1143. static bool
  1144. bfa_ioc_flash_fwver_valid(struct bfi_ioc_image_hdr *flash_fwhdr)
  1145. {
  1146. if (flash_fwhdr->fwver.major == 0 || flash_fwhdr->fwver.major == 0xFF)
  1147. return false;
  1148. return true;
  1149. }
  1150. static bool
  1151. fwhdr_is_ga(struct bfi_ioc_image_hdr *fwhdr)
  1152. {
  1153. if (fwhdr->fwver.phase == 0 &&
  1154. fwhdr->fwver.build == 0)
  1155. return false;
  1156. return true;
  1157. }
  1158. /* Returns TRUE if both are compatible and patch of fwhdr_to_cmp is better. */
  1159. static enum bfi_ioc_img_ver_cmp
  1160. bfa_ioc_fw_ver_patch_cmp(struct bfi_ioc_image_hdr *base_fwhdr,
  1161. struct bfi_ioc_image_hdr *fwhdr_to_cmp)
  1162. {
  1163. if (!bfa_ioc_fw_ver_compatible(base_fwhdr, fwhdr_to_cmp))
  1164. return BFI_IOC_IMG_VER_INCOMP;
  1165. if (fwhdr_to_cmp->fwver.patch > base_fwhdr->fwver.patch)
  1166. return BFI_IOC_IMG_VER_BETTER;
  1167. else if (fwhdr_to_cmp->fwver.patch < base_fwhdr->fwver.patch)
  1168. return BFI_IOC_IMG_VER_OLD;
  1169. /* GA takes priority over internal builds of the same patch stream.
  1170. * At this point major minor maint and patch numbers are same.
  1171. */
  1172. if (fwhdr_is_ga(base_fwhdr))
  1173. if (fwhdr_is_ga(fwhdr_to_cmp))
  1174. return BFI_IOC_IMG_VER_SAME;
  1175. else
  1176. return BFI_IOC_IMG_VER_OLD;
  1177. else
  1178. if (fwhdr_is_ga(fwhdr_to_cmp))
  1179. return BFI_IOC_IMG_VER_BETTER;
  1180. if (fwhdr_to_cmp->fwver.phase > base_fwhdr->fwver.phase)
  1181. return BFI_IOC_IMG_VER_BETTER;
  1182. else if (fwhdr_to_cmp->fwver.phase < base_fwhdr->fwver.phase)
  1183. return BFI_IOC_IMG_VER_OLD;
  1184. if (fwhdr_to_cmp->fwver.build > base_fwhdr->fwver.build)
  1185. return BFI_IOC_IMG_VER_BETTER;
  1186. else if (fwhdr_to_cmp->fwver.build < base_fwhdr->fwver.build)
  1187. return BFI_IOC_IMG_VER_OLD;
  1188. /* All Version Numbers are equal.
  1189. * Md5 check to be done as a part of compatibility check.
  1190. */
  1191. return BFI_IOC_IMG_VER_SAME;
  1192. }
  1193. /* register definitions */
  1194. #define FLI_CMD_REG 0x0001d000
  1195. #define FLI_WRDATA_REG 0x0001d00c
  1196. #define FLI_RDDATA_REG 0x0001d010
  1197. #define FLI_ADDR_REG 0x0001d004
  1198. #define FLI_DEV_STATUS_REG 0x0001d014
  1199. #define BFA_FLASH_FIFO_SIZE 128 /* fifo size */
  1200. #define BFA_FLASH_CHECK_MAX 10000 /* max # of status check */
  1201. #define BFA_FLASH_BLOCKING_OP_MAX 1000000 /* max # of blocking op check */
  1202. #define BFA_FLASH_WIP_MASK 0x01 /* write in progress bit mask */
  1203. #define NFC_STATE_RUNNING 0x20000001
  1204. #define NFC_STATE_PAUSED 0x00004560
  1205. #define NFC_VER_VALID 0x147
  1206. enum bfa_flash_cmd {
  1207. BFA_FLASH_FAST_READ = 0x0b, /* fast read */
  1208. BFA_FLASH_WRITE_ENABLE = 0x06, /* write enable */
  1209. BFA_FLASH_SECTOR_ERASE = 0xd8, /* sector erase */
  1210. BFA_FLASH_WRITE = 0x02, /* write */
  1211. BFA_FLASH_READ_STATUS = 0x05, /* read status */
  1212. };
  1213. /* hardware error definition */
  1214. enum bfa_flash_err {
  1215. BFA_FLASH_NOT_PRESENT = -1, /*!< flash not present */
  1216. BFA_FLASH_UNINIT = -2, /*!< flash not initialized */
  1217. BFA_FLASH_BAD = -3, /*!< flash bad */
  1218. BFA_FLASH_BUSY = -4, /*!< flash busy */
  1219. BFA_FLASH_ERR_CMD_ACT = -5, /*!< command active never cleared */
  1220. BFA_FLASH_ERR_FIFO_CNT = -6, /*!< fifo count never cleared */
  1221. BFA_FLASH_ERR_WIP = -7, /*!< write-in-progress never cleared */
  1222. BFA_FLASH_ERR_TIMEOUT = -8, /*!< fli timeout */
  1223. BFA_FLASH_ERR_LEN = -9, /*!< invalid length */
  1224. };
  1225. /* flash command register data structure */
  1226. union bfa_flash_cmd_reg {
  1227. struct {
  1228. #ifdef __BIG_ENDIAN
  1229. u32 act:1;
  1230. u32 rsv:1;
  1231. u32 write_cnt:9;
  1232. u32 read_cnt:9;
  1233. u32 addr_cnt:4;
  1234. u32 cmd:8;
  1235. #else
  1236. u32 cmd:8;
  1237. u32 addr_cnt:4;
  1238. u32 read_cnt:9;
  1239. u32 write_cnt:9;
  1240. u32 rsv:1;
  1241. u32 act:1;
  1242. #endif
  1243. } r;
  1244. u32 i;
  1245. };
  1246. /* flash device status register data structure */
  1247. union bfa_flash_dev_status_reg {
  1248. struct {
  1249. #ifdef __BIG_ENDIAN
  1250. u32 rsv:21;
  1251. u32 fifo_cnt:6;
  1252. u32 busy:1;
  1253. u32 init_status:1;
  1254. u32 present:1;
  1255. u32 bad:1;
  1256. u32 good:1;
  1257. #else
  1258. u32 good:1;
  1259. u32 bad:1;
  1260. u32 present:1;
  1261. u32 init_status:1;
  1262. u32 busy:1;
  1263. u32 fifo_cnt:6;
  1264. u32 rsv:21;
  1265. #endif
  1266. } r;
  1267. u32 i;
  1268. };
  1269. /* flash address register data structure */
  1270. union bfa_flash_addr_reg {
  1271. struct {
  1272. #ifdef __BIG_ENDIAN
  1273. u32 addr:24;
  1274. u32 dummy:8;
  1275. #else
  1276. u32 dummy:8;
  1277. u32 addr:24;
  1278. #endif
  1279. } r;
  1280. u32 i;
  1281. };
  1282. /* Flash raw private functions */
  1283. static void
  1284. bfa_flash_set_cmd(void __iomem *pci_bar, u8 wr_cnt,
  1285. u8 rd_cnt, u8 ad_cnt, u8 op)
  1286. {
  1287. union bfa_flash_cmd_reg cmd;
  1288. cmd.i = 0;
  1289. cmd.r.act = 1;
  1290. cmd.r.write_cnt = wr_cnt;
  1291. cmd.r.read_cnt = rd_cnt;
  1292. cmd.r.addr_cnt = ad_cnt;
  1293. cmd.r.cmd = op;
  1294. writel(cmd.i, (pci_bar + FLI_CMD_REG));
  1295. }
  1296. static void
  1297. bfa_flash_set_addr(void __iomem *pci_bar, u32 address)
  1298. {
  1299. union bfa_flash_addr_reg addr;
  1300. addr.r.addr = address & 0x00ffffff;
  1301. addr.r.dummy = 0;
  1302. writel(addr.i, (pci_bar + FLI_ADDR_REG));
  1303. }
  1304. static int
  1305. bfa_flash_cmd_act_check(void __iomem *pci_bar)
  1306. {
  1307. union bfa_flash_cmd_reg cmd;
  1308. cmd.i = readl(pci_bar + FLI_CMD_REG);
  1309. if (cmd.r.act)
  1310. return BFA_FLASH_ERR_CMD_ACT;
  1311. return 0;
  1312. }
  1313. /* Flush FLI data fifo. */
  1314. static int
  1315. bfa_flash_fifo_flush(void __iomem *pci_bar)
  1316. {
  1317. u32 i;
  1318. u32 t;
  1319. union bfa_flash_dev_status_reg dev_status;
  1320. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  1321. if (!dev_status.r.fifo_cnt)
  1322. return 0;
  1323. /* fifo counter in terms of words */
  1324. for (i = 0; i < dev_status.r.fifo_cnt; i++)
  1325. t = readl(pci_bar + FLI_RDDATA_REG);
  1326. /* Check the device status. It may take some time. */
  1327. for (i = 0; i < BFA_FLASH_CHECK_MAX; i++) {
  1328. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  1329. if (!dev_status.r.fifo_cnt)
  1330. break;
  1331. }
  1332. if (dev_status.r.fifo_cnt)
  1333. return BFA_FLASH_ERR_FIFO_CNT;
  1334. return 0;
  1335. }
  1336. /* Read flash status. */
  1337. static int
  1338. bfa_flash_status_read(void __iomem *pci_bar)
  1339. {
  1340. union bfa_flash_dev_status_reg dev_status;
  1341. int status;
  1342. u32 ret_status;
  1343. int i;
  1344. status = bfa_flash_fifo_flush(pci_bar);
  1345. if (status < 0)
  1346. return status;
  1347. bfa_flash_set_cmd(pci_bar, 0, 4, 0, BFA_FLASH_READ_STATUS);
  1348. for (i = 0; i < BFA_FLASH_CHECK_MAX; i++) {
  1349. status = bfa_flash_cmd_act_check(pci_bar);
  1350. if (!status)
  1351. break;
  1352. }
  1353. if (status)
  1354. return status;
  1355. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  1356. if (!dev_status.r.fifo_cnt)
  1357. return BFA_FLASH_BUSY;
  1358. ret_status = readl(pci_bar + FLI_RDDATA_REG);
  1359. ret_status >>= 24;
  1360. status = bfa_flash_fifo_flush(pci_bar);
  1361. if (status < 0)
  1362. return status;
  1363. return ret_status;
  1364. }
  1365. /* Start flash read operation. */
  1366. static int
  1367. bfa_flash_read_start(void __iomem *pci_bar, u32 offset, u32 len,
  1368. char *buf)
  1369. {
  1370. int status;
  1371. /* len must be mutiple of 4 and not exceeding fifo size */
  1372. if (len == 0 || len > BFA_FLASH_FIFO_SIZE || (len & 0x03) != 0)
  1373. return BFA_FLASH_ERR_LEN;
  1374. /* check status */
  1375. status = bfa_flash_status_read(pci_bar);
  1376. if (status == BFA_FLASH_BUSY)
  1377. status = bfa_flash_status_read(pci_bar);
  1378. if (status < 0)
  1379. return status;
  1380. /* check if write-in-progress bit is cleared */
  1381. if (status & BFA_FLASH_WIP_MASK)
  1382. return BFA_FLASH_ERR_WIP;
  1383. bfa_flash_set_addr(pci_bar, offset);
  1384. bfa_flash_set_cmd(pci_bar, 0, (u8)len, 4, BFA_FLASH_FAST_READ);
  1385. return 0;
  1386. }
  1387. /* Check flash read operation. */
  1388. static u32
  1389. bfa_flash_read_check(void __iomem *pci_bar)
  1390. {
  1391. if (bfa_flash_cmd_act_check(pci_bar))
  1392. return 1;
  1393. return 0;
  1394. }
  1395. /* End flash read operation. */
  1396. static void
  1397. bfa_flash_read_end(void __iomem *pci_bar, u32 len, char *buf)
  1398. {
  1399. u32 i;
  1400. /* read data fifo up to 32 words */
  1401. for (i = 0; i < len; i += 4) {
  1402. u32 w = readl(pci_bar + FLI_RDDATA_REG);
  1403. *((u32 *)(buf + i)) = swab32(w);
  1404. }
  1405. bfa_flash_fifo_flush(pci_bar);
  1406. }
  1407. /* Perform flash raw read. */
  1408. #define FLASH_BLOCKING_OP_MAX 500
  1409. #define FLASH_SEM_LOCK_REG 0x18820
  1410. static int
  1411. bfa_raw_sem_get(void __iomem *bar)
  1412. {
  1413. int locked;
  1414. locked = readl(bar + FLASH_SEM_LOCK_REG);
  1415. return !locked;
  1416. }
  1417. static enum bfa_status
  1418. bfa_flash_sem_get(void __iomem *bar)
  1419. {
  1420. u32 n = FLASH_BLOCKING_OP_MAX;
  1421. while (!bfa_raw_sem_get(bar)) {
  1422. if (--n <= 0)
  1423. return BFA_STATUS_BADFLASH;
  1424. mdelay(10);
  1425. }
  1426. return BFA_STATUS_OK;
  1427. }
  1428. static void
  1429. bfa_flash_sem_put(void __iomem *bar)
  1430. {
  1431. writel(0, (bar + FLASH_SEM_LOCK_REG));
  1432. }
  1433. static enum bfa_status
  1434. bfa_flash_raw_read(void __iomem *pci_bar, u32 offset, char *buf,
  1435. u32 len)
  1436. {
  1437. u32 n;
  1438. int status;
  1439. u32 off, l, s, residue, fifo_sz;
  1440. residue = len;
  1441. off = 0;
  1442. fifo_sz = BFA_FLASH_FIFO_SIZE;
  1443. status = bfa_flash_sem_get(pci_bar);
  1444. if (status != BFA_STATUS_OK)
  1445. return status;
  1446. while (residue) {
  1447. s = offset + off;
  1448. n = s / fifo_sz;
  1449. l = (n + 1) * fifo_sz - s;
  1450. if (l > residue)
  1451. l = residue;
  1452. status = bfa_flash_read_start(pci_bar, offset + off, l,
  1453. &buf[off]);
  1454. if (status < 0) {
  1455. bfa_flash_sem_put(pci_bar);
  1456. return BFA_STATUS_FAILED;
  1457. }
  1458. n = BFA_FLASH_BLOCKING_OP_MAX;
  1459. while (bfa_flash_read_check(pci_bar)) {
  1460. if (--n <= 0) {
  1461. bfa_flash_sem_put(pci_bar);
  1462. return BFA_STATUS_FAILED;
  1463. }
  1464. }
  1465. bfa_flash_read_end(pci_bar, l, &buf[off]);
  1466. residue -= l;
  1467. off += l;
  1468. }
  1469. bfa_flash_sem_put(pci_bar);
  1470. return BFA_STATUS_OK;
  1471. }
  1472. #define BFA_FLASH_PART_FWIMG_ADDR 0x100000 /* fw image address */
  1473. static enum bfa_status
  1474. bfa_nw_ioc_flash_img_get_chnk(struct bfa_ioc *ioc, u32 off,
  1475. u32 *fwimg)
  1476. {
  1477. return bfa_flash_raw_read(ioc->pcidev.pci_bar_kva,
  1478. BFA_FLASH_PART_FWIMG_ADDR + (off * sizeof(u32)),
  1479. (char *)fwimg, BFI_FLASH_CHUNK_SZ);
  1480. }
  1481. static enum bfi_ioc_img_ver_cmp
  1482. bfa_ioc_flash_fwver_cmp(struct bfa_ioc *ioc,
  1483. struct bfi_ioc_image_hdr *base_fwhdr)
  1484. {
  1485. struct bfi_ioc_image_hdr *flash_fwhdr;
  1486. enum bfa_status status;
  1487. u32 fwimg[BFI_FLASH_CHUNK_SZ_WORDS];
  1488. status = bfa_nw_ioc_flash_img_get_chnk(ioc, 0, fwimg);
  1489. if (status != BFA_STATUS_OK)
  1490. return BFI_IOC_IMG_VER_INCOMP;
  1491. flash_fwhdr = (struct bfi_ioc_image_hdr *)fwimg;
  1492. if (bfa_ioc_flash_fwver_valid(flash_fwhdr))
  1493. return bfa_ioc_fw_ver_patch_cmp(base_fwhdr, flash_fwhdr);
  1494. else
  1495. return BFI_IOC_IMG_VER_INCOMP;
  1496. }
  1497. /**
  1498. * Returns TRUE if driver is willing to work with current smem f/w version.
  1499. */
  1500. bool
  1501. bfa_nw_ioc_fwver_cmp(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
  1502. {
  1503. struct bfi_ioc_image_hdr *drv_fwhdr;
  1504. enum bfi_ioc_img_ver_cmp smem_flash_cmp, drv_smem_cmp;
  1505. drv_fwhdr = (struct bfi_ioc_image_hdr *)
  1506. bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
  1507. /* If smem is incompatible or old, driver should not work with it. */
  1508. drv_smem_cmp = bfa_ioc_fw_ver_patch_cmp(drv_fwhdr, fwhdr);
  1509. if (drv_smem_cmp == BFI_IOC_IMG_VER_INCOMP ||
  1510. drv_smem_cmp == BFI_IOC_IMG_VER_OLD) {
  1511. return false;
  1512. }
  1513. /* IF Flash has a better F/W than smem do not work with smem.
  1514. * If smem f/w == flash f/w, as smem f/w not old | incmp, work with it.
  1515. * If Flash is old or incomp work with smem iff smem f/w == drv f/w.
  1516. */
  1517. smem_flash_cmp = bfa_ioc_flash_fwver_cmp(ioc, fwhdr);
  1518. if (smem_flash_cmp == BFI_IOC_IMG_VER_BETTER)
  1519. return false;
  1520. else if (smem_flash_cmp == BFI_IOC_IMG_VER_SAME)
  1521. return true;
  1522. else
  1523. return (drv_smem_cmp == BFI_IOC_IMG_VER_SAME) ?
  1524. true : false;
  1525. }
  1526. /* Return true if current running version is valid. Firmware signature and
  1527. * execution context (driver/bios) must match.
  1528. */
  1529. static bool
  1530. bfa_ioc_fwver_valid(struct bfa_ioc *ioc, u32 boot_env)
  1531. {
  1532. struct bfi_ioc_image_hdr fwhdr;
  1533. bfa_nw_ioc_fwver_get(ioc, &fwhdr);
  1534. if (swab32(fwhdr.bootenv) != boot_env)
  1535. return false;
  1536. return bfa_nw_ioc_fwver_cmp(ioc, &fwhdr);
  1537. }
  1538. /* Conditionally flush any pending message from firmware at start. */
  1539. static void
  1540. bfa_ioc_msgflush(struct bfa_ioc *ioc)
  1541. {
  1542. u32 r32;
  1543. r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
  1544. if (r32)
  1545. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  1546. }
  1547. static void
  1548. bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force)
  1549. {
  1550. enum bfi_ioc_state ioc_fwstate;
  1551. bool fwvalid;
  1552. u32 boot_env;
  1553. ioc_fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
  1554. if (force)
  1555. ioc_fwstate = BFI_IOC_UNINIT;
  1556. boot_env = BFI_FWBOOT_ENV_OS;
  1557. /**
  1558. * check if firmware is valid
  1559. */
  1560. fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
  1561. false : bfa_ioc_fwver_valid(ioc, boot_env);
  1562. if (!fwvalid) {
  1563. if (bfa_ioc_boot(ioc, BFI_FWBOOT_TYPE_NORMAL, boot_env) ==
  1564. BFA_STATUS_OK)
  1565. bfa_ioc_poll_fwinit(ioc);
  1566. return;
  1567. }
  1568. /**
  1569. * If hardware initialization is in progress (initialized by other IOC),
  1570. * just wait for an initialization completion interrupt.
  1571. */
  1572. if (ioc_fwstate == BFI_IOC_INITING) {
  1573. bfa_ioc_poll_fwinit(ioc);
  1574. return;
  1575. }
  1576. /**
  1577. * If IOC function is disabled and firmware version is same,
  1578. * just re-enable IOC.
  1579. */
  1580. if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
  1581. /**
  1582. * When using MSI-X any pending firmware ready event should
  1583. * be flushed. Otherwise MSI-X interrupts are not delivered.
  1584. */
  1585. bfa_ioc_msgflush(ioc);
  1586. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
  1587. return;
  1588. }
  1589. /**
  1590. * Initialize the h/w for any other states.
  1591. */
  1592. if (bfa_ioc_boot(ioc, BFI_FWBOOT_TYPE_NORMAL, boot_env) ==
  1593. BFA_STATUS_OK)
  1594. bfa_ioc_poll_fwinit(ioc);
  1595. }
  1596. void
  1597. bfa_nw_ioc_timeout(struct bfa_ioc *ioc)
  1598. {
  1599. bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
  1600. }
  1601. static void
  1602. bfa_ioc_mbox_send(struct bfa_ioc *ioc, void *ioc_msg, int len)
  1603. {
  1604. u32 *msgp = (u32 *) ioc_msg;
  1605. u32 i;
  1606. BUG_ON(!(len <= BFI_IOC_MSGLEN_MAX));
  1607. /*
  1608. * first write msg to mailbox registers
  1609. */
  1610. for (i = 0; i < len / sizeof(u32); i++)
  1611. writel(cpu_to_le32(msgp[i]),
  1612. ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1613. for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
  1614. writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1615. /*
  1616. * write 1 to mailbox CMD to trigger LPU event
  1617. */
  1618. writel(1, ioc->ioc_regs.hfn_mbox_cmd);
  1619. (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
  1620. }
  1621. static void
  1622. bfa_ioc_send_enable(struct bfa_ioc *ioc)
  1623. {
  1624. struct bfi_ioc_ctrl_req enable_req;
  1625. struct timeval tv;
  1626. bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
  1627. bfa_ioc_portid(ioc));
  1628. enable_req.clscode = htons(ioc->clscode);
  1629. do_gettimeofday(&tv);
  1630. enable_req.tv_sec = ntohl(tv.tv_sec);
  1631. bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req));
  1632. }
  1633. static void
  1634. bfa_ioc_send_disable(struct bfa_ioc *ioc)
  1635. {
  1636. struct bfi_ioc_ctrl_req disable_req;
  1637. bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
  1638. bfa_ioc_portid(ioc));
  1639. bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req));
  1640. }
  1641. static void
  1642. bfa_ioc_send_getattr(struct bfa_ioc *ioc)
  1643. {
  1644. struct bfi_ioc_getattr_req attr_req;
  1645. bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
  1646. bfa_ioc_portid(ioc));
  1647. bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
  1648. bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
  1649. }
  1650. void
  1651. bfa_nw_ioc_hb_check(struct bfa_ioc *ioc)
  1652. {
  1653. u32 hb_count;
  1654. hb_count = readl(ioc->ioc_regs.heartbeat);
  1655. if (ioc->hb_count == hb_count) {
  1656. bfa_ioc_recover(ioc);
  1657. return;
  1658. } else {
  1659. ioc->hb_count = hb_count;
  1660. }
  1661. bfa_ioc_mbox_poll(ioc);
  1662. mod_timer(&ioc->hb_timer, jiffies +
  1663. msecs_to_jiffies(BFA_IOC_HB_TOV));
  1664. }
  1665. static void
  1666. bfa_ioc_hb_monitor(struct bfa_ioc *ioc)
  1667. {
  1668. ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
  1669. mod_timer(&ioc->hb_timer, jiffies +
  1670. msecs_to_jiffies(BFA_IOC_HB_TOV));
  1671. }
  1672. static void
  1673. bfa_ioc_hb_stop(struct bfa_ioc *ioc)
  1674. {
  1675. del_timer(&ioc->hb_timer);
  1676. }
  1677. /* Initiate a full firmware download. */
  1678. static enum bfa_status
  1679. bfa_ioc_download_fw(struct bfa_ioc *ioc, u32 boot_type,
  1680. u32 boot_env)
  1681. {
  1682. u32 *fwimg;
  1683. u32 pgnum;
  1684. u32 loff = 0;
  1685. u32 chunkno = 0;
  1686. u32 i;
  1687. u32 asicmode;
  1688. u32 fwimg_size;
  1689. u32 fwimg_buf[BFI_FLASH_CHUNK_SZ_WORDS];
  1690. enum bfa_status status;
  1691. if (boot_env == BFI_FWBOOT_ENV_OS &&
  1692. boot_type == BFI_FWBOOT_TYPE_FLASH) {
  1693. fwimg_size = BFI_FLASH_IMAGE_SZ/sizeof(u32);
  1694. status = bfa_nw_ioc_flash_img_get_chnk(ioc,
  1695. BFA_IOC_FLASH_CHUNK_ADDR(chunkno), fwimg_buf);
  1696. if (status != BFA_STATUS_OK)
  1697. return status;
  1698. fwimg = fwimg_buf;
  1699. } else {
  1700. fwimg_size = bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc));
  1701. fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc),
  1702. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  1703. }
  1704. pgnum = bfa_ioc_smem_pgnum(ioc, loff);
  1705. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1706. for (i = 0; i < fwimg_size; i++) {
  1707. if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
  1708. chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
  1709. if (boot_env == BFI_FWBOOT_ENV_OS &&
  1710. boot_type == BFI_FWBOOT_TYPE_FLASH) {
  1711. status = bfa_nw_ioc_flash_img_get_chnk(ioc,
  1712. BFA_IOC_FLASH_CHUNK_ADDR(chunkno),
  1713. fwimg_buf);
  1714. if (status != BFA_STATUS_OK)
  1715. return status;
  1716. fwimg = fwimg_buf;
  1717. } else {
  1718. fwimg = bfa_cb_image_get_chunk(
  1719. bfa_ioc_asic_gen(ioc),
  1720. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  1721. }
  1722. }
  1723. /**
  1724. * write smem
  1725. */
  1726. writel(swab32(fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]),
  1727. ioc->ioc_regs.smem_page_start + loff);
  1728. loff += sizeof(u32);
  1729. /**
  1730. * handle page offset wrap around
  1731. */
  1732. loff = PSS_SMEM_PGOFF(loff);
  1733. if (loff == 0) {
  1734. pgnum++;
  1735. writel(pgnum,
  1736. ioc->ioc_regs.host_page_num_fn);
  1737. }
  1738. }
  1739. writel(bfa_ioc_smem_pgnum(ioc, 0),
  1740. ioc->ioc_regs.host_page_num_fn);
  1741. /*
  1742. * Set boot type, env and device mode at the end.
  1743. */
  1744. if (boot_env == BFI_FWBOOT_ENV_OS &&
  1745. boot_type == BFI_FWBOOT_TYPE_FLASH) {
  1746. boot_type = BFI_FWBOOT_TYPE_NORMAL;
  1747. }
  1748. asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode,
  1749. ioc->port0_mode, ioc->port1_mode);
  1750. writel(asicmode, ((ioc->ioc_regs.smem_page_start)
  1751. + BFI_FWBOOT_DEVMODE_OFF));
  1752. writel(boot_type, ((ioc->ioc_regs.smem_page_start)
  1753. + (BFI_FWBOOT_TYPE_OFF)));
  1754. writel(boot_env, ((ioc->ioc_regs.smem_page_start)
  1755. + (BFI_FWBOOT_ENV_OFF)));
  1756. return BFA_STATUS_OK;
  1757. }
  1758. static void
  1759. bfa_ioc_reset(struct bfa_ioc *ioc, bool force)
  1760. {
  1761. bfa_ioc_hwinit(ioc, force);
  1762. }
  1763. /* BFA ioc enable reply by firmware */
  1764. static void
  1765. bfa_ioc_enable_reply(struct bfa_ioc *ioc, enum bfa_mode port_mode,
  1766. u8 cap_bm)
  1767. {
  1768. struct bfa_iocpf *iocpf = &ioc->iocpf;
  1769. ioc->port_mode = ioc->port_mode_cfg = port_mode;
  1770. ioc->ad_cap_bm = cap_bm;
  1771. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
  1772. }
  1773. /* Update BFA configuration from firmware configuration. */
  1774. static void
  1775. bfa_ioc_getattr_reply(struct bfa_ioc *ioc)
  1776. {
  1777. struct bfi_ioc_attr *attr = ioc->attr;
  1778. attr->adapter_prop = ntohl(attr->adapter_prop);
  1779. attr->card_type = ntohl(attr->card_type);
  1780. attr->maxfrsize = ntohs(attr->maxfrsize);
  1781. bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
  1782. }
  1783. /* Attach time initialization of mbox logic. */
  1784. static void
  1785. bfa_ioc_mbox_attach(struct bfa_ioc *ioc)
  1786. {
  1787. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  1788. int mc;
  1789. INIT_LIST_HEAD(&mod->cmd_q);
  1790. for (mc = 0; mc < BFI_MC_MAX; mc++) {
  1791. mod->mbhdlr[mc].cbfn = NULL;
  1792. mod->mbhdlr[mc].cbarg = ioc->bfa;
  1793. }
  1794. }
  1795. /* Mbox poll timer -- restarts any pending mailbox requests. */
  1796. static void
  1797. bfa_ioc_mbox_poll(struct bfa_ioc *ioc)
  1798. {
  1799. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  1800. struct bfa_mbox_cmd *cmd;
  1801. bfa_mbox_cmd_cbfn_t cbfn;
  1802. void *cbarg;
  1803. u32 stat;
  1804. /**
  1805. * If no command pending, do nothing
  1806. */
  1807. if (list_empty(&mod->cmd_q))
  1808. return;
  1809. /**
  1810. * If previous command is not yet fetched by firmware, do nothing
  1811. */
  1812. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  1813. if (stat)
  1814. return;
  1815. /**
  1816. * Enqueue command to firmware.
  1817. */
  1818. cmd = list_first_entry(&mod->cmd_q, struct bfa_mbox_cmd, qe);
  1819. list_del(&cmd->qe);
  1820. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1821. /**
  1822. * Give a callback to the client, indicating that the command is sent
  1823. */
  1824. if (cmd->cbfn) {
  1825. cbfn = cmd->cbfn;
  1826. cbarg = cmd->cbarg;
  1827. cmd->cbfn = NULL;
  1828. cbfn(cbarg);
  1829. }
  1830. }
  1831. /* Cleanup any pending requests. */
  1832. static void
  1833. bfa_ioc_mbox_flush(struct bfa_ioc *ioc)
  1834. {
  1835. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  1836. struct bfa_mbox_cmd *cmd;
  1837. while (!list_empty(&mod->cmd_q)) {
  1838. cmd = list_first_entry(&mod->cmd_q, struct bfa_mbox_cmd, qe);
  1839. list_del(&cmd->qe);
  1840. }
  1841. }
  1842. /**
  1843. * bfa_nw_ioc_smem_read - Read data from SMEM to host through PCI memmap
  1844. *
  1845. * @ioc: memory for IOC
  1846. * @tbuf: app memory to store data from smem
  1847. * @soff: smem offset
  1848. * @sz: size of smem in bytes
  1849. */
  1850. static int
  1851. bfa_nw_ioc_smem_read(struct bfa_ioc *ioc, void *tbuf, u32 soff, u32 sz)
  1852. {
  1853. u32 pgnum, loff, r32;
  1854. int i, len;
  1855. u32 *buf = tbuf;
  1856. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
  1857. loff = PSS_SMEM_PGOFF(soff);
  1858. /*
  1859. * Hold semaphore to serialize pll init and fwtrc.
  1860. */
  1861. if (!bfa_nw_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg))
  1862. return 1;
  1863. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1864. len = sz/sizeof(u32);
  1865. for (i = 0; i < len; i++) {
  1866. r32 = swab32(readl(loff + ioc->ioc_regs.smem_page_start));
  1867. buf[i] = be32_to_cpu(r32);
  1868. loff += sizeof(u32);
  1869. /**
  1870. * handle page offset wrap around
  1871. */
  1872. loff = PSS_SMEM_PGOFF(loff);
  1873. if (loff == 0) {
  1874. pgnum++;
  1875. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1876. }
  1877. }
  1878. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1879. ioc->ioc_regs.host_page_num_fn);
  1880. /*
  1881. * release semaphore
  1882. */
  1883. readl(ioc->ioc_regs.ioc_init_sem_reg);
  1884. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1885. return 0;
  1886. }
  1887. /* Retrieve saved firmware trace from a prior IOC failure. */
  1888. int
  1889. bfa_nw_ioc_debug_fwtrc(struct bfa_ioc *ioc, void *trcdata, int *trclen)
  1890. {
  1891. u32 loff = BFI_IOC_TRC_OFF + BNA_DBG_FWTRC_LEN * ioc->port_id;
  1892. int tlen, status = 0;
  1893. tlen = *trclen;
  1894. if (tlen > BNA_DBG_FWTRC_LEN)
  1895. tlen = BNA_DBG_FWTRC_LEN;
  1896. status = bfa_nw_ioc_smem_read(ioc, trcdata, loff, tlen);
  1897. *trclen = tlen;
  1898. return status;
  1899. }
  1900. /* Save firmware trace if configured. */
  1901. static void
  1902. bfa_nw_ioc_debug_save_ftrc(struct bfa_ioc *ioc)
  1903. {
  1904. int tlen;
  1905. if (ioc->dbg_fwsave_once) {
  1906. ioc->dbg_fwsave_once = false;
  1907. if (ioc->dbg_fwsave_len) {
  1908. tlen = ioc->dbg_fwsave_len;
  1909. bfa_nw_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
  1910. }
  1911. }
  1912. }
  1913. /* Retrieve saved firmware trace from a prior IOC failure. */
  1914. int
  1915. bfa_nw_ioc_debug_fwsave(struct bfa_ioc *ioc, void *trcdata, int *trclen)
  1916. {
  1917. int tlen;
  1918. if (ioc->dbg_fwsave_len == 0)
  1919. return BFA_STATUS_ENOFSAVE;
  1920. tlen = *trclen;
  1921. if (tlen > ioc->dbg_fwsave_len)
  1922. tlen = ioc->dbg_fwsave_len;
  1923. memcpy(trcdata, ioc->dbg_fwsave, tlen);
  1924. *trclen = tlen;
  1925. return BFA_STATUS_OK;
  1926. }
  1927. static void
  1928. bfa_ioc_fail_notify(struct bfa_ioc *ioc)
  1929. {
  1930. /**
  1931. * Notify driver and common modules registered for notification.
  1932. */
  1933. ioc->cbfn->hbfail_cbfn(ioc->bfa);
  1934. bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
  1935. bfa_nw_ioc_debug_save_ftrc(ioc);
  1936. }
  1937. /* IOCPF to IOC interface */
  1938. static void
  1939. bfa_ioc_pf_enabled(struct bfa_ioc *ioc)
  1940. {
  1941. bfa_fsm_send_event(ioc, IOC_E_ENABLED);
  1942. }
  1943. static void
  1944. bfa_ioc_pf_disabled(struct bfa_ioc *ioc)
  1945. {
  1946. bfa_fsm_send_event(ioc, IOC_E_DISABLED);
  1947. }
  1948. static void
  1949. bfa_ioc_pf_failed(struct bfa_ioc *ioc)
  1950. {
  1951. bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
  1952. }
  1953. static void
  1954. bfa_ioc_pf_hwfailed(struct bfa_ioc *ioc)
  1955. {
  1956. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  1957. }
  1958. static void
  1959. bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc)
  1960. {
  1961. /**
  1962. * Provide enable completion callback and AEN notification.
  1963. */
  1964. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  1965. }
  1966. /* IOC public */
  1967. static enum bfa_status
  1968. bfa_ioc_pll_init(struct bfa_ioc *ioc)
  1969. {
  1970. /*
  1971. * Hold semaphore so that nobody can access the chip during init.
  1972. */
  1973. bfa_nw_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
  1974. bfa_ioc_pll_init_asic(ioc);
  1975. ioc->pllinit = true;
  1976. /* Initialize LMEM */
  1977. bfa_ioc_lmem_init(ioc);
  1978. /*
  1979. * release semaphore.
  1980. */
  1981. bfa_nw_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
  1982. return BFA_STATUS_OK;
  1983. }
  1984. /* Interface used by diag module to do firmware boot with memory test
  1985. * as the entry vector.
  1986. */
  1987. static enum bfa_status
  1988. bfa_ioc_boot(struct bfa_ioc *ioc, enum bfi_fwboot_type boot_type,
  1989. u32 boot_env)
  1990. {
  1991. struct bfi_ioc_image_hdr *drv_fwhdr;
  1992. enum bfa_status status;
  1993. bfa_ioc_stats(ioc, ioc_boots);
  1994. if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
  1995. return BFA_STATUS_FAILED;
  1996. if (boot_env == BFI_FWBOOT_ENV_OS &&
  1997. boot_type == BFI_FWBOOT_TYPE_NORMAL) {
  1998. drv_fwhdr = (struct bfi_ioc_image_hdr *)
  1999. bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
  2000. /* Work with Flash iff flash f/w is better than driver f/w.
  2001. * Otherwise push drivers firmware.
  2002. */
  2003. if (bfa_ioc_flash_fwver_cmp(ioc, drv_fwhdr) ==
  2004. BFI_IOC_IMG_VER_BETTER)
  2005. boot_type = BFI_FWBOOT_TYPE_FLASH;
  2006. }
  2007. /**
  2008. * Initialize IOC state of all functions on a chip reset.
  2009. */
  2010. if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) {
  2011. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_MEMTEST);
  2012. bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_MEMTEST);
  2013. } else {
  2014. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_INITING);
  2015. bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_INITING);
  2016. }
  2017. bfa_ioc_msgflush(ioc);
  2018. status = bfa_ioc_download_fw(ioc, boot_type, boot_env);
  2019. if (status == BFA_STATUS_OK)
  2020. bfa_ioc_lpu_start(ioc);
  2021. else
  2022. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
  2023. return status;
  2024. }
  2025. /* Enable/disable IOC failure auto recovery. */
  2026. void
  2027. bfa_nw_ioc_auto_recover(bool auto_recover)
  2028. {
  2029. bfa_nw_auto_recover = auto_recover;
  2030. }
  2031. static bool
  2032. bfa_ioc_msgget(struct bfa_ioc *ioc, void *mbmsg)
  2033. {
  2034. u32 *msgp = mbmsg;
  2035. u32 r32;
  2036. int i;
  2037. r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
  2038. if ((r32 & 1) == 0)
  2039. return false;
  2040. /**
  2041. * read the MBOX msg
  2042. */
  2043. for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
  2044. i++) {
  2045. r32 = readl(ioc->ioc_regs.lpu_mbox +
  2046. i * sizeof(u32));
  2047. msgp[i] = htonl(r32);
  2048. }
  2049. /**
  2050. * turn off mailbox interrupt by clearing mailbox status
  2051. */
  2052. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  2053. readl(ioc->ioc_regs.lpu_mbox_cmd);
  2054. return true;
  2055. }
  2056. static void
  2057. bfa_ioc_isr(struct bfa_ioc *ioc, struct bfi_mbmsg *m)
  2058. {
  2059. union bfi_ioc_i2h_msg_u *msg;
  2060. struct bfa_iocpf *iocpf = &ioc->iocpf;
  2061. msg = (union bfi_ioc_i2h_msg_u *) m;
  2062. bfa_ioc_stats(ioc, ioc_isrs);
  2063. switch (msg->mh.msg_id) {
  2064. case BFI_IOC_I2H_HBEAT:
  2065. break;
  2066. case BFI_IOC_I2H_ENABLE_REPLY:
  2067. bfa_ioc_enable_reply(ioc,
  2068. (enum bfa_mode)msg->fw_event.port_mode,
  2069. msg->fw_event.cap_bm);
  2070. break;
  2071. case BFI_IOC_I2H_DISABLE_REPLY:
  2072. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
  2073. break;
  2074. case BFI_IOC_I2H_GETATTR_REPLY:
  2075. bfa_ioc_getattr_reply(ioc);
  2076. break;
  2077. default:
  2078. BUG_ON(1);
  2079. }
  2080. }
  2081. /**
  2082. * bfa_nw_ioc_attach - IOC attach time initialization and setup.
  2083. *
  2084. * @ioc: memory for IOC
  2085. * @bfa: driver instance structure
  2086. */
  2087. void
  2088. bfa_nw_ioc_attach(struct bfa_ioc *ioc, void *bfa, struct bfa_ioc_cbfn *cbfn)
  2089. {
  2090. ioc->bfa = bfa;
  2091. ioc->cbfn = cbfn;
  2092. ioc->fcmode = false;
  2093. ioc->pllinit = false;
  2094. ioc->dbg_fwsave_once = true;
  2095. ioc->iocpf.ioc = ioc;
  2096. bfa_ioc_mbox_attach(ioc);
  2097. INIT_LIST_HEAD(&ioc->notify_q);
  2098. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  2099. bfa_fsm_send_event(ioc, IOC_E_RESET);
  2100. }
  2101. /* Driver detach time IOC cleanup. */
  2102. void
  2103. bfa_nw_ioc_detach(struct bfa_ioc *ioc)
  2104. {
  2105. bfa_fsm_send_event(ioc, IOC_E_DETACH);
  2106. /* Done with detach, empty the notify_q. */
  2107. INIT_LIST_HEAD(&ioc->notify_q);
  2108. }
  2109. /**
  2110. * bfa_nw_ioc_pci_init - Setup IOC PCI properties.
  2111. *
  2112. * @pcidev: PCI device information for this IOC
  2113. */
  2114. void
  2115. bfa_nw_ioc_pci_init(struct bfa_ioc *ioc, struct bfa_pcidev *pcidev,
  2116. enum bfi_pcifn_class clscode)
  2117. {
  2118. ioc->clscode = clscode;
  2119. ioc->pcidev = *pcidev;
  2120. /**
  2121. * Initialize IOC and device personality
  2122. */
  2123. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
  2124. ioc->asic_mode = BFI_ASIC_MODE_FC;
  2125. switch (pcidev->device_id) {
  2126. case PCI_DEVICE_ID_BROCADE_CT:
  2127. ioc->asic_gen = BFI_ASIC_GEN_CT;
  2128. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
  2129. ioc->asic_mode = BFI_ASIC_MODE_ETH;
  2130. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
  2131. ioc->ad_cap_bm = BFA_CM_CNA;
  2132. break;
  2133. case BFA_PCI_DEVICE_ID_CT2:
  2134. ioc->asic_gen = BFI_ASIC_GEN_CT2;
  2135. if (clscode == BFI_PCIFN_CLASS_FC &&
  2136. pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
  2137. ioc->asic_mode = BFI_ASIC_MODE_FC16;
  2138. ioc->fcmode = true;
  2139. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
  2140. ioc->ad_cap_bm = BFA_CM_HBA;
  2141. } else {
  2142. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
  2143. ioc->asic_mode = BFI_ASIC_MODE_ETH;
  2144. if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
  2145. ioc->port_mode =
  2146. ioc->port_mode_cfg = BFA_MODE_CNA;
  2147. ioc->ad_cap_bm = BFA_CM_CNA;
  2148. } else {
  2149. ioc->port_mode =
  2150. ioc->port_mode_cfg = BFA_MODE_NIC;
  2151. ioc->ad_cap_bm = BFA_CM_NIC;
  2152. }
  2153. }
  2154. break;
  2155. default:
  2156. BUG_ON(1);
  2157. }
  2158. /**
  2159. * Set asic specific interfaces.
  2160. */
  2161. if (ioc->asic_gen == BFI_ASIC_GEN_CT)
  2162. bfa_nw_ioc_set_ct_hwif(ioc);
  2163. else {
  2164. WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2);
  2165. bfa_nw_ioc_set_ct2_hwif(ioc);
  2166. bfa_nw_ioc_ct2_poweron(ioc);
  2167. }
  2168. bfa_ioc_map_port(ioc);
  2169. bfa_ioc_reg_init(ioc);
  2170. }
  2171. /**
  2172. * bfa_nw_ioc_mem_claim - Initialize IOC dma memory
  2173. *
  2174. * @dm_kva: kernel virtual address of IOC dma memory
  2175. * @dm_pa: physical address of IOC dma memory
  2176. */
  2177. void
  2178. bfa_nw_ioc_mem_claim(struct bfa_ioc *ioc, u8 *dm_kva, u64 dm_pa)
  2179. {
  2180. /**
  2181. * dma memory for firmware attribute
  2182. */
  2183. ioc->attr_dma.kva = dm_kva;
  2184. ioc->attr_dma.pa = dm_pa;
  2185. ioc->attr = (struct bfi_ioc_attr *) dm_kva;
  2186. }
  2187. /* Return size of dma memory required. */
  2188. u32
  2189. bfa_nw_ioc_meminfo(void)
  2190. {
  2191. return roundup(sizeof(struct bfi_ioc_attr), BFA_DMA_ALIGN_SZ);
  2192. }
  2193. void
  2194. bfa_nw_ioc_enable(struct bfa_ioc *ioc)
  2195. {
  2196. bfa_ioc_stats(ioc, ioc_enables);
  2197. ioc->dbg_fwsave_once = true;
  2198. bfa_fsm_send_event(ioc, IOC_E_ENABLE);
  2199. }
  2200. void
  2201. bfa_nw_ioc_disable(struct bfa_ioc *ioc)
  2202. {
  2203. bfa_ioc_stats(ioc, ioc_disables);
  2204. bfa_fsm_send_event(ioc, IOC_E_DISABLE);
  2205. }
  2206. /* Initialize memory for saving firmware trace. */
  2207. void
  2208. bfa_nw_ioc_debug_memclaim(struct bfa_ioc *ioc, void *dbg_fwsave)
  2209. {
  2210. ioc->dbg_fwsave = dbg_fwsave;
  2211. ioc->dbg_fwsave_len = ioc->iocpf.auto_recover ? BNA_DBG_FWTRC_LEN : 0;
  2212. }
  2213. static u32
  2214. bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr)
  2215. {
  2216. return PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, fmaddr);
  2217. }
  2218. /* Register mailbox message handler function, to be called by common modules */
  2219. void
  2220. bfa_nw_ioc_mbox_regisr(struct bfa_ioc *ioc, enum bfi_mclass mc,
  2221. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
  2222. {
  2223. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  2224. mod->mbhdlr[mc].cbfn = cbfn;
  2225. mod->mbhdlr[mc].cbarg = cbarg;
  2226. }
  2227. /**
  2228. * bfa_nw_ioc_mbox_queue - Queue a mailbox command request to firmware.
  2229. *
  2230. * @ioc: IOC instance
  2231. * @cmd: Mailbox command
  2232. *
  2233. * Waits if mailbox is busy. Responsibility of caller to serialize
  2234. */
  2235. bool
  2236. bfa_nw_ioc_mbox_queue(struct bfa_ioc *ioc, struct bfa_mbox_cmd *cmd,
  2237. bfa_mbox_cmd_cbfn_t cbfn, void *cbarg)
  2238. {
  2239. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  2240. u32 stat;
  2241. cmd->cbfn = cbfn;
  2242. cmd->cbarg = cbarg;
  2243. /**
  2244. * If a previous command is pending, queue new command
  2245. */
  2246. if (!list_empty(&mod->cmd_q)) {
  2247. list_add_tail(&cmd->qe, &mod->cmd_q);
  2248. return true;
  2249. }
  2250. /**
  2251. * If mailbox is busy, queue command for poll timer
  2252. */
  2253. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  2254. if (stat) {
  2255. list_add_tail(&cmd->qe, &mod->cmd_q);
  2256. return true;
  2257. }
  2258. /**
  2259. * mailbox is free -- queue command to firmware
  2260. */
  2261. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  2262. return false;
  2263. }
  2264. /* Handle mailbox interrupts */
  2265. void
  2266. bfa_nw_ioc_mbox_isr(struct bfa_ioc *ioc)
  2267. {
  2268. struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
  2269. struct bfi_mbmsg m;
  2270. int mc;
  2271. if (bfa_ioc_msgget(ioc, &m)) {
  2272. /**
  2273. * Treat IOC message class as special.
  2274. */
  2275. mc = m.mh.msg_class;
  2276. if (mc == BFI_MC_IOC) {
  2277. bfa_ioc_isr(ioc, &m);
  2278. return;
  2279. }
  2280. if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
  2281. return;
  2282. mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
  2283. }
  2284. bfa_ioc_lpu_read_stat(ioc);
  2285. /**
  2286. * Try to send pending mailbox commands
  2287. */
  2288. bfa_ioc_mbox_poll(ioc);
  2289. }
  2290. void
  2291. bfa_nw_ioc_error_isr(struct bfa_ioc *ioc)
  2292. {
  2293. bfa_ioc_stats(ioc, ioc_hbfails);
  2294. bfa_ioc_stats_hb_count(ioc, ioc->hb_count);
  2295. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  2296. }
  2297. /* return true if IOC is disabled */
  2298. bool
  2299. bfa_nw_ioc_is_disabled(struct bfa_ioc *ioc)
  2300. {
  2301. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
  2302. bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
  2303. }
  2304. /* return true if IOC is operational */
  2305. bool
  2306. bfa_nw_ioc_is_operational(struct bfa_ioc *ioc)
  2307. {
  2308. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
  2309. }
  2310. /* Add to IOC heartbeat failure notification queue. To be used by common
  2311. * modules such as cee, port, diag.
  2312. */
  2313. void
  2314. bfa_nw_ioc_notify_register(struct bfa_ioc *ioc,
  2315. struct bfa_ioc_notify *notify)
  2316. {
  2317. list_add_tail(&notify->qe, &ioc->notify_q);
  2318. }
  2319. #define BFA_MFG_NAME "QLogic"
  2320. static void
  2321. bfa_ioc_get_adapter_attr(struct bfa_ioc *ioc,
  2322. struct bfa_adapter_attr *ad_attr)
  2323. {
  2324. struct bfi_ioc_attr *ioc_attr;
  2325. ioc_attr = ioc->attr;
  2326. bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
  2327. bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
  2328. bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
  2329. bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
  2330. memcpy(&ad_attr->vpd, &ioc_attr->vpd,
  2331. sizeof(struct bfa_mfg_vpd));
  2332. ad_attr->nports = bfa_ioc_get_nports(ioc);
  2333. ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
  2334. bfa_ioc_get_adapter_model(ioc, ad_attr->model);
  2335. /* For now, model descr uses same model string */
  2336. bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
  2337. ad_attr->card_type = ioc_attr->card_type;
  2338. ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
  2339. if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
  2340. ad_attr->prototype = 1;
  2341. else
  2342. ad_attr->prototype = 0;
  2343. ad_attr->pwwn = bfa_ioc_get_pwwn(ioc);
  2344. bfa_nw_ioc_get_mac(ioc, ad_attr->mac);
  2345. ad_attr->pcie_gen = ioc_attr->pcie_gen;
  2346. ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
  2347. ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
  2348. ad_attr->asic_rev = ioc_attr->asic_rev;
  2349. bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
  2350. }
  2351. static enum bfa_ioc_type
  2352. bfa_ioc_get_type(struct bfa_ioc *ioc)
  2353. {
  2354. if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
  2355. return BFA_IOC_TYPE_LL;
  2356. BUG_ON(!(ioc->clscode == BFI_PCIFN_CLASS_FC));
  2357. return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
  2358. ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
  2359. }
  2360. static void
  2361. bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc, char *serial_num)
  2362. {
  2363. memcpy(serial_num,
  2364. (void *)ioc->attr->brcd_serialnum,
  2365. BFA_ADAPTER_SERIAL_NUM_LEN);
  2366. }
  2367. static void
  2368. bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc, char *fw_ver)
  2369. {
  2370. memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
  2371. }
  2372. static void
  2373. bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc, char *chip_rev)
  2374. {
  2375. BUG_ON(!(chip_rev));
  2376. memset(chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
  2377. chip_rev[0] = 'R';
  2378. chip_rev[1] = 'e';
  2379. chip_rev[2] = 'v';
  2380. chip_rev[3] = '-';
  2381. chip_rev[4] = ioc->attr->asic_rev;
  2382. chip_rev[5] = '\0';
  2383. }
  2384. static void
  2385. bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc, char *optrom_ver)
  2386. {
  2387. memcpy(optrom_ver, ioc->attr->optrom_version,
  2388. BFA_VERSION_LEN);
  2389. }
  2390. static void
  2391. bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc, char *manufacturer)
  2392. {
  2393. memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
  2394. }
  2395. static void
  2396. bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model)
  2397. {
  2398. struct bfi_ioc_attr *ioc_attr;
  2399. BUG_ON(!(model));
  2400. memset(model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
  2401. ioc_attr = ioc->attr;
  2402. snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
  2403. BFA_MFG_NAME, ioc_attr->card_type);
  2404. }
  2405. static enum bfa_ioc_state
  2406. bfa_ioc_get_state(struct bfa_ioc *ioc)
  2407. {
  2408. enum bfa_iocpf_state iocpf_st;
  2409. enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
  2410. if (ioc_st == BFA_IOC_ENABLING ||
  2411. ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
  2412. iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
  2413. switch (iocpf_st) {
  2414. case BFA_IOCPF_SEMWAIT:
  2415. ioc_st = BFA_IOC_SEMWAIT;
  2416. break;
  2417. case BFA_IOCPF_HWINIT:
  2418. ioc_st = BFA_IOC_HWINIT;
  2419. break;
  2420. case BFA_IOCPF_FWMISMATCH:
  2421. ioc_st = BFA_IOC_FWMISMATCH;
  2422. break;
  2423. case BFA_IOCPF_FAIL:
  2424. ioc_st = BFA_IOC_FAIL;
  2425. break;
  2426. case BFA_IOCPF_INITFAIL:
  2427. ioc_st = BFA_IOC_INITFAIL;
  2428. break;
  2429. default:
  2430. break;
  2431. }
  2432. }
  2433. return ioc_st;
  2434. }
  2435. void
  2436. bfa_nw_ioc_get_attr(struct bfa_ioc *ioc, struct bfa_ioc_attr *ioc_attr)
  2437. {
  2438. memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr));
  2439. ioc_attr->state = bfa_ioc_get_state(ioc);
  2440. ioc_attr->port_id = bfa_ioc_portid(ioc);
  2441. ioc_attr->port_mode = ioc->port_mode;
  2442. ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
  2443. ioc_attr->cap_bm = ioc->ad_cap_bm;
  2444. ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
  2445. bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
  2446. ioc_attr->pci_attr.device_id = bfa_ioc_devid(ioc);
  2447. ioc_attr->pci_attr.pcifn = bfa_ioc_pcifn(ioc);
  2448. ioc_attr->def_fn = bfa_ioc_is_default(ioc);
  2449. bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
  2450. }
  2451. /* WWN public */
  2452. static u64
  2453. bfa_ioc_get_pwwn(struct bfa_ioc *ioc)
  2454. {
  2455. return ioc->attr->pwwn;
  2456. }
  2457. void
  2458. bfa_nw_ioc_get_mac(struct bfa_ioc *ioc, u8 *mac)
  2459. {
  2460. ether_addr_copy(mac, ioc->attr->mac);
  2461. }
  2462. /* Firmware failure detected. Start recovery actions. */
  2463. static void
  2464. bfa_ioc_recover(struct bfa_ioc *ioc)
  2465. {
  2466. pr_crit("Heart Beat of IOC has failed\n");
  2467. bfa_ioc_stats(ioc, ioc_hbfails);
  2468. bfa_ioc_stats_hb_count(ioc, ioc->hb_count);
  2469. bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
  2470. }
  2471. /* BFA IOC PF private functions */
  2472. static void
  2473. bfa_iocpf_enable(struct bfa_ioc *ioc)
  2474. {
  2475. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
  2476. }
  2477. static void
  2478. bfa_iocpf_disable(struct bfa_ioc *ioc)
  2479. {
  2480. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
  2481. }
  2482. static void
  2483. bfa_iocpf_fail(struct bfa_ioc *ioc)
  2484. {
  2485. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
  2486. }
  2487. static void
  2488. bfa_iocpf_initfail(struct bfa_ioc *ioc)
  2489. {
  2490. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
  2491. }
  2492. static void
  2493. bfa_iocpf_getattrfail(struct bfa_ioc *ioc)
  2494. {
  2495. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
  2496. }
  2497. static void
  2498. bfa_iocpf_stop(struct bfa_ioc *ioc)
  2499. {
  2500. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  2501. }
  2502. void
  2503. bfa_nw_iocpf_timeout(struct bfa_ioc *ioc)
  2504. {
  2505. enum bfa_iocpf_state iocpf_st;
  2506. iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
  2507. if (iocpf_st == BFA_IOCPF_HWINIT)
  2508. bfa_ioc_poll_fwinit(ioc);
  2509. else
  2510. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
  2511. }
  2512. void
  2513. bfa_nw_iocpf_sem_timeout(struct bfa_ioc *ioc)
  2514. {
  2515. bfa_ioc_hw_sem_get(ioc);
  2516. }
  2517. static void
  2518. bfa_ioc_poll_fwinit(struct bfa_ioc *ioc)
  2519. {
  2520. u32 fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
  2521. if (fwstate == BFI_IOC_DISABLED) {
  2522. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
  2523. return;
  2524. }
  2525. if (ioc->iocpf.poll_time >= BFA_IOC_TOV) {
  2526. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
  2527. } else {
  2528. ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
  2529. mod_timer(&ioc->iocpf_timer, jiffies +
  2530. msecs_to_jiffies(BFA_IOC_POLL_TOV));
  2531. }
  2532. }
  2533. /*
  2534. * Flash module specific
  2535. */
  2536. /*
  2537. * FLASH DMA buffer should be big enough to hold both MFG block and
  2538. * asic block(64k) at the same time and also should be 2k aligned to
  2539. * avoid write segement to cross sector boundary.
  2540. */
  2541. #define BFA_FLASH_SEG_SZ 2048
  2542. #define BFA_FLASH_DMA_BUF_SZ \
  2543. roundup(0x010000 + sizeof(struct bfa_mfg_block), BFA_FLASH_SEG_SZ)
  2544. static void
  2545. bfa_flash_cb(struct bfa_flash *flash)
  2546. {
  2547. flash->op_busy = 0;
  2548. if (flash->cbfn)
  2549. flash->cbfn(flash->cbarg, flash->status);
  2550. }
  2551. static void
  2552. bfa_flash_notify(void *cbarg, enum bfa_ioc_event event)
  2553. {
  2554. struct bfa_flash *flash = cbarg;
  2555. switch (event) {
  2556. case BFA_IOC_E_DISABLED:
  2557. case BFA_IOC_E_FAILED:
  2558. if (flash->op_busy) {
  2559. flash->status = BFA_STATUS_IOC_FAILURE;
  2560. flash->cbfn(flash->cbarg, flash->status);
  2561. flash->op_busy = 0;
  2562. }
  2563. break;
  2564. default:
  2565. break;
  2566. }
  2567. }
  2568. /*
  2569. * Send flash write request.
  2570. */
  2571. static void
  2572. bfa_flash_write_send(struct bfa_flash *flash)
  2573. {
  2574. struct bfi_flash_write_req *msg =
  2575. (struct bfi_flash_write_req *) flash->mb.msg;
  2576. u32 len;
  2577. msg->type = be32_to_cpu(flash->type);
  2578. msg->instance = flash->instance;
  2579. msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
  2580. len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
  2581. flash->residue : BFA_FLASH_DMA_BUF_SZ;
  2582. msg->length = be32_to_cpu(len);
  2583. /* indicate if it's the last msg of the whole write operation */
  2584. msg->last = (len == flash->residue) ? 1 : 0;
  2585. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_WRITE_REQ,
  2586. bfa_ioc_portid(flash->ioc));
  2587. bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
  2588. memcpy(flash->dbuf_kva, flash->ubuf + flash->offset, len);
  2589. bfa_nw_ioc_mbox_queue(flash->ioc, &flash->mb, NULL, NULL);
  2590. flash->residue -= len;
  2591. flash->offset += len;
  2592. }
  2593. /**
  2594. * bfa_flash_read_send - Send flash read request.
  2595. *
  2596. * @cbarg: callback argument
  2597. */
  2598. static void
  2599. bfa_flash_read_send(void *cbarg)
  2600. {
  2601. struct bfa_flash *flash = cbarg;
  2602. struct bfi_flash_read_req *msg =
  2603. (struct bfi_flash_read_req *) flash->mb.msg;
  2604. u32 len;
  2605. msg->type = be32_to_cpu(flash->type);
  2606. msg->instance = flash->instance;
  2607. msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
  2608. len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
  2609. flash->residue : BFA_FLASH_DMA_BUF_SZ;
  2610. msg->length = be32_to_cpu(len);
  2611. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_READ_REQ,
  2612. bfa_ioc_portid(flash->ioc));
  2613. bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
  2614. bfa_nw_ioc_mbox_queue(flash->ioc, &flash->mb, NULL, NULL);
  2615. }
  2616. /**
  2617. * bfa_flash_intr - Process flash response messages upon receiving interrupts.
  2618. *
  2619. * @flasharg: flash structure
  2620. * @msg: message structure
  2621. */
  2622. static void
  2623. bfa_flash_intr(void *flasharg, struct bfi_mbmsg *msg)
  2624. {
  2625. struct bfa_flash *flash = flasharg;
  2626. u32 status;
  2627. union {
  2628. struct bfi_flash_query_rsp *query;
  2629. struct bfi_flash_write_rsp *write;
  2630. struct bfi_flash_read_rsp *read;
  2631. struct bfi_mbmsg *msg;
  2632. } m;
  2633. m.msg = msg;
  2634. /* receiving response after ioc failure */
  2635. if (!flash->op_busy && msg->mh.msg_id != BFI_FLASH_I2H_EVENT)
  2636. return;
  2637. switch (msg->mh.msg_id) {
  2638. case BFI_FLASH_I2H_QUERY_RSP:
  2639. status = be32_to_cpu(m.query->status);
  2640. if (status == BFA_STATUS_OK) {
  2641. u32 i;
  2642. struct bfa_flash_attr *attr, *f;
  2643. attr = (struct bfa_flash_attr *) flash->ubuf;
  2644. f = (struct bfa_flash_attr *) flash->dbuf_kva;
  2645. attr->status = be32_to_cpu(f->status);
  2646. attr->npart = be32_to_cpu(f->npart);
  2647. for (i = 0; i < attr->npart; i++) {
  2648. attr->part[i].part_type =
  2649. be32_to_cpu(f->part[i].part_type);
  2650. attr->part[i].part_instance =
  2651. be32_to_cpu(f->part[i].part_instance);
  2652. attr->part[i].part_off =
  2653. be32_to_cpu(f->part[i].part_off);
  2654. attr->part[i].part_size =
  2655. be32_to_cpu(f->part[i].part_size);
  2656. attr->part[i].part_len =
  2657. be32_to_cpu(f->part[i].part_len);
  2658. attr->part[i].part_status =
  2659. be32_to_cpu(f->part[i].part_status);
  2660. }
  2661. }
  2662. flash->status = status;
  2663. bfa_flash_cb(flash);
  2664. break;
  2665. case BFI_FLASH_I2H_WRITE_RSP:
  2666. status = be32_to_cpu(m.write->status);
  2667. if (status != BFA_STATUS_OK || flash->residue == 0) {
  2668. flash->status = status;
  2669. bfa_flash_cb(flash);
  2670. } else
  2671. bfa_flash_write_send(flash);
  2672. break;
  2673. case BFI_FLASH_I2H_READ_RSP:
  2674. status = be32_to_cpu(m.read->status);
  2675. if (status != BFA_STATUS_OK) {
  2676. flash->status = status;
  2677. bfa_flash_cb(flash);
  2678. } else {
  2679. u32 len = be32_to_cpu(m.read->length);
  2680. memcpy(flash->ubuf + flash->offset,
  2681. flash->dbuf_kva, len);
  2682. flash->residue -= len;
  2683. flash->offset += len;
  2684. if (flash->residue == 0) {
  2685. flash->status = status;
  2686. bfa_flash_cb(flash);
  2687. } else
  2688. bfa_flash_read_send(flash);
  2689. }
  2690. break;
  2691. case BFI_FLASH_I2H_BOOT_VER_RSP:
  2692. case BFI_FLASH_I2H_EVENT:
  2693. break;
  2694. default:
  2695. WARN_ON(1);
  2696. }
  2697. }
  2698. /*
  2699. * Flash memory info API.
  2700. */
  2701. u32
  2702. bfa_nw_flash_meminfo(void)
  2703. {
  2704. return roundup(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  2705. }
  2706. /**
  2707. * bfa_nw_flash_attach - Flash attach API.
  2708. *
  2709. * @flash: flash structure
  2710. * @ioc: ioc structure
  2711. * @dev: device structure
  2712. */
  2713. void
  2714. bfa_nw_flash_attach(struct bfa_flash *flash, struct bfa_ioc *ioc, void *dev)
  2715. {
  2716. flash->ioc = ioc;
  2717. flash->cbfn = NULL;
  2718. flash->cbarg = NULL;
  2719. flash->op_busy = 0;
  2720. bfa_nw_ioc_mbox_regisr(flash->ioc, BFI_MC_FLASH, bfa_flash_intr, flash);
  2721. bfa_ioc_notify_init(&flash->ioc_notify, bfa_flash_notify, flash);
  2722. list_add_tail(&flash->ioc_notify.qe, &flash->ioc->notify_q);
  2723. }
  2724. /**
  2725. * bfa_nw_flash_memclaim - Claim memory for flash
  2726. *
  2727. * @flash: flash structure
  2728. * @dm_kva: pointer to virtual memory address
  2729. * @dm_pa: physical memory address
  2730. */
  2731. void
  2732. bfa_nw_flash_memclaim(struct bfa_flash *flash, u8 *dm_kva, u64 dm_pa)
  2733. {
  2734. flash->dbuf_kva = dm_kva;
  2735. flash->dbuf_pa = dm_pa;
  2736. memset(flash->dbuf_kva, 0, BFA_FLASH_DMA_BUF_SZ);
  2737. dm_kva += roundup(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  2738. dm_pa += roundup(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  2739. }
  2740. /**
  2741. * bfa_nw_flash_get_attr - Get flash attribute.
  2742. *
  2743. * @flash: flash structure
  2744. * @attr: flash attribute structure
  2745. * @cbfn: callback function
  2746. * @cbarg: callback argument
  2747. *
  2748. * Return status.
  2749. */
  2750. enum bfa_status
  2751. bfa_nw_flash_get_attr(struct bfa_flash *flash, struct bfa_flash_attr *attr,
  2752. bfa_cb_flash cbfn, void *cbarg)
  2753. {
  2754. struct bfi_flash_query_req *msg =
  2755. (struct bfi_flash_query_req *) flash->mb.msg;
  2756. if (!bfa_nw_ioc_is_operational(flash->ioc))
  2757. return BFA_STATUS_IOC_NON_OP;
  2758. if (flash->op_busy)
  2759. return BFA_STATUS_DEVBUSY;
  2760. flash->op_busy = 1;
  2761. flash->cbfn = cbfn;
  2762. flash->cbarg = cbarg;
  2763. flash->ubuf = (u8 *) attr;
  2764. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_QUERY_REQ,
  2765. bfa_ioc_portid(flash->ioc));
  2766. bfa_alen_set(&msg->alen, sizeof(struct bfa_flash_attr), flash->dbuf_pa);
  2767. bfa_nw_ioc_mbox_queue(flash->ioc, &flash->mb, NULL, NULL);
  2768. return BFA_STATUS_OK;
  2769. }
  2770. /**
  2771. * bfa_nw_flash_update_part - Update flash partition.
  2772. *
  2773. * @flash: flash structure
  2774. * @type: flash partition type
  2775. * @instance: flash partition instance
  2776. * @buf: update data buffer
  2777. * @len: data buffer length
  2778. * @offset: offset relative to the partition starting address
  2779. * @cbfn: callback function
  2780. * @cbarg: callback argument
  2781. *
  2782. * Return status.
  2783. */
  2784. enum bfa_status
  2785. bfa_nw_flash_update_part(struct bfa_flash *flash, u32 type, u8 instance,
  2786. void *buf, u32 len, u32 offset,
  2787. bfa_cb_flash cbfn, void *cbarg)
  2788. {
  2789. if (!bfa_nw_ioc_is_operational(flash->ioc))
  2790. return BFA_STATUS_IOC_NON_OP;
  2791. /*
  2792. * 'len' must be in word (4-byte) boundary
  2793. */
  2794. if (!len || (len & 0x03))
  2795. return BFA_STATUS_FLASH_BAD_LEN;
  2796. if (type == BFA_FLASH_PART_MFG)
  2797. return BFA_STATUS_EINVAL;
  2798. if (flash->op_busy)
  2799. return BFA_STATUS_DEVBUSY;
  2800. flash->op_busy = 1;
  2801. flash->cbfn = cbfn;
  2802. flash->cbarg = cbarg;
  2803. flash->type = type;
  2804. flash->instance = instance;
  2805. flash->residue = len;
  2806. flash->offset = 0;
  2807. flash->addr_off = offset;
  2808. flash->ubuf = buf;
  2809. bfa_flash_write_send(flash);
  2810. return BFA_STATUS_OK;
  2811. }
  2812. /**
  2813. * bfa_nw_flash_read_part - Read flash partition.
  2814. *
  2815. * @flash: flash structure
  2816. * @type: flash partition type
  2817. * @instance: flash partition instance
  2818. * @buf: read data buffer
  2819. * @len: data buffer length
  2820. * @offset: offset relative to the partition starting address
  2821. * @cbfn: callback function
  2822. * @cbarg: callback argument
  2823. *
  2824. * Return status.
  2825. */
  2826. enum bfa_status
  2827. bfa_nw_flash_read_part(struct bfa_flash *flash, u32 type, u8 instance,
  2828. void *buf, u32 len, u32 offset,
  2829. bfa_cb_flash cbfn, void *cbarg)
  2830. {
  2831. if (!bfa_nw_ioc_is_operational(flash->ioc))
  2832. return BFA_STATUS_IOC_NON_OP;
  2833. /*
  2834. * 'len' must be in word (4-byte) boundary
  2835. */
  2836. if (!len || (len & 0x03))
  2837. return BFA_STATUS_FLASH_BAD_LEN;
  2838. if (flash->op_busy)
  2839. return BFA_STATUS_DEVBUSY;
  2840. flash->op_busy = 1;
  2841. flash->cbfn = cbfn;
  2842. flash->cbarg = cbarg;
  2843. flash->type = type;
  2844. flash->instance = instance;
  2845. flash->residue = len;
  2846. flash->offset = 0;
  2847. flash->addr_off = offset;
  2848. flash->ubuf = buf;
  2849. bfa_flash_read_send(flash);
  2850. return BFA_STATUS_OK;
  2851. }