bfa_ioc.c 78 KB

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