bfa_ioc.c 77 KB

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