bfa_ioc.c 78 KB

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