bfa_ioc.c 65 KB

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