csio_hw.c 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974
  1. /*
  2. * This file is part of the Chelsio FCoE driver for Linux.
  3. *
  4. * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/pci.h>
  35. #include <linux/pci_regs.h>
  36. #include <linux/firmware.h>
  37. #include <linux/stddef.h>
  38. #include <linux/delay.h>
  39. #include <linux/string.h>
  40. #include <linux/compiler.h>
  41. #include <linux/jiffies.h>
  42. #include <linux/kernel.h>
  43. #include <linux/log2.h>
  44. #include "csio_hw.h"
  45. #include "csio_lnode.h"
  46. #include "csio_rnode.h"
  47. int csio_dbg_level = 0xFEFF;
  48. unsigned int csio_port_mask = 0xf;
  49. /* Default FW event queue entries. */
  50. static uint32_t csio_evtq_sz = CSIO_EVTQ_SIZE;
  51. /* Default MSI param level */
  52. int csio_msi = 2;
  53. /* FCoE function instances */
  54. static int dev_num;
  55. /* FCoE Adapter types & its description */
  56. static const struct csio_adap_desc csio_t5_fcoe_adapters[] = {
  57. {"T580-Dbg 10G", "Chelsio T580-Dbg 10G [FCoE]"},
  58. {"T520-CR 10G", "Chelsio T520-CR 10G [FCoE]"},
  59. {"T522-CR 10G/1G", "Chelsio T522-CR 10G/1G [FCoE]"},
  60. {"T540-CR 10G", "Chelsio T540-CR 10G [FCoE]"},
  61. {"T520-BCH 10G", "Chelsio T520-BCH 10G [FCoE]"},
  62. {"T540-BCH 10G", "Chelsio T540-BCH 10G [FCoE]"},
  63. {"T540-CH 10G", "Chelsio T540-CH 10G [FCoE]"},
  64. {"T520-SO 10G", "Chelsio T520-SO 10G [FCoE]"},
  65. {"T520-CX4 10G", "Chelsio T520-CX4 10G [FCoE]"},
  66. {"T520-BT 10G", "Chelsio T520-BT 10G [FCoE]"},
  67. {"T504-BT 1G", "Chelsio T504-BT 1G [FCoE]"},
  68. {"B520-SR 10G", "Chelsio B520-SR 10G [FCoE]"},
  69. {"B504-BT 1G", "Chelsio B504-BT 1G [FCoE]"},
  70. {"T580-CR 10G", "Chelsio T580-CR 10G [FCoE]"},
  71. {"T540-LP-CR 10G", "Chelsio T540-LP-CR 10G [FCoE]"},
  72. {"AMSTERDAM 10G", "Chelsio AMSTERDAM 10G [FCoE]"},
  73. {"T580-LP-CR 40G", "Chelsio T580-LP-CR 40G [FCoE]"},
  74. {"T520-LL-CR 10G", "Chelsio T520-LL-CR 10G [FCoE]"},
  75. {"T560-CR 40G", "Chelsio T560-CR 40G [FCoE]"},
  76. {"T580-CR 40G", "Chelsio T580-CR 40G [FCoE]"},
  77. {"T580-SO 40G", "Chelsio T580-SO 40G [FCoE]"},
  78. {"T502-BT 1G", "Chelsio T502-BT 1G [FCoE]"}
  79. };
  80. static void csio_mgmtm_cleanup(struct csio_mgmtm *);
  81. static void csio_hw_mbm_cleanup(struct csio_hw *);
  82. /* State machine forward declarations */
  83. static void csio_hws_uninit(struct csio_hw *, enum csio_hw_ev);
  84. static void csio_hws_configuring(struct csio_hw *, enum csio_hw_ev);
  85. static void csio_hws_initializing(struct csio_hw *, enum csio_hw_ev);
  86. static void csio_hws_ready(struct csio_hw *, enum csio_hw_ev);
  87. static void csio_hws_quiescing(struct csio_hw *, enum csio_hw_ev);
  88. static void csio_hws_quiesced(struct csio_hw *, enum csio_hw_ev);
  89. static void csio_hws_resetting(struct csio_hw *, enum csio_hw_ev);
  90. static void csio_hws_removing(struct csio_hw *, enum csio_hw_ev);
  91. static void csio_hws_pcierr(struct csio_hw *, enum csio_hw_ev);
  92. static void csio_hw_initialize(struct csio_hw *hw);
  93. static void csio_evtq_stop(struct csio_hw *hw);
  94. static void csio_evtq_start(struct csio_hw *hw);
  95. int csio_is_hw_ready(struct csio_hw *hw)
  96. {
  97. return csio_match_state(hw, csio_hws_ready);
  98. }
  99. int csio_is_hw_removing(struct csio_hw *hw)
  100. {
  101. return csio_match_state(hw, csio_hws_removing);
  102. }
  103. /*
  104. * csio_hw_wait_op_done_val - wait until an operation is completed
  105. * @hw: the HW module
  106. * @reg: the register to check for completion
  107. * @mask: a single-bit field within @reg that indicates completion
  108. * @polarity: the value of the field when the operation is completed
  109. * @attempts: number of check iterations
  110. * @delay: delay in usecs between iterations
  111. * @valp: where to store the value of the register at completion time
  112. *
  113. * Wait until an operation is completed by checking a bit in a register
  114. * up to @attempts times. If @valp is not NULL the value of the register
  115. * at the time it indicated completion is stored there. Returns 0 if the
  116. * operation completes and -EAGAIN otherwise.
  117. */
  118. int
  119. csio_hw_wait_op_done_val(struct csio_hw *hw, int reg, uint32_t mask,
  120. int polarity, int attempts, int delay, uint32_t *valp)
  121. {
  122. uint32_t val;
  123. while (1) {
  124. val = csio_rd_reg32(hw, reg);
  125. if (!!(val & mask) == polarity) {
  126. if (valp)
  127. *valp = val;
  128. return 0;
  129. }
  130. if (--attempts == 0)
  131. return -EAGAIN;
  132. if (delay)
  133. udelay(delay);
  134. }
  135. }
  136. /*
  137. * csio_hw_tp_wr_bits_indirect - set/clear bits in an indirect TP register
  138. * @hw: the adapter
  139. * @addr: the indirect TP register address
  140. * @mask: specifies the field within the register to modify
  141. * @val: new value for the field
  142. *
  143. * Sets a field of an indirect TP register to the given value.
  144. */
  145. void
  146. csio_hw_tp_wr_bits_indirect(struct csio_hw *hw, unsigned int addr,
  147. unsigned int mask, unsigned int val)
  148. {
  149. csio_wr_reg32(hw, addr, TP_PIO_ADDR_A);
  150. val |= csio_rd_reg32(hw, TP_PIO_DATA_A) & ~mask;
  151. csio_wr_reg32(hw, val, TP_PIO_DATA_A);
  152. }
  153. void
  154. csio_set_reg_field(struct csio_hw *hw, uint32_t reg, uint32_t mask,
  155. uint32_t value)
  156. {
  157. uint32_t val = csio_rd_reg32(hw, reg) & ~mask;
  158. csio_wr_reg32(hw, val | value, reg);
  159. /* Flush */
  160. csio_rd_reg32(hw, reg);
  161. }
  162. static int
  163. csio_memory_write(struct csio_hw *hw, int mtype, u32 addr, u32 len, u32 *buf)
  164. {
  165. return hw->chip_ops->chip_memory_rw(hw, MEMWIN_CSIOSTOR, mtype,
  166. addr, len, buf, 0);
  167. }
  168. /*
  169. * EEPROM reads take a few tens of us while writes can take a bit over 5 ms.
  170. */
  171. #define EEPROM_MAX_RD_POLL 40
  172. #define EEPROM_MAX_WR_POLL 6
  173. #define EEPROM_STAT_ADDR 0x7bfc
  174. #define VPD_BASE 0x400
  175. #define VPD_BASE_OLD 0
  176. #define VPD_LEN 1024
  177. #define VPD_INFO_FLD_HDR_SIZE 3
  178. /*
  179. * csio_hw_seeprom_read - read a serial EEPROM location
  180. * @hw: hw to read
  181. * @addr: EEPROM virtual address
  182. * @data: where to store the read data
  183. *
  184. * Read a 32-bit word from a location in serial EEPROM using the card's PCI
  185. * VPD capability. Note that this function must be called with a virtual
  186. * address.
  187. */
  188. static int
  189. csio_hw_seeprom_read(struct csio_hw *hw, uint32_t addr, uint32_t *data)
  190. {
  191. uint16_t val = 0;
  192. int attempts = EEPROM_MAX_RD_POLL;
  193. uint32_t base = hw->params.pci.vpd_cap_addr;
  194. if (addr >= EEPROMVSIZE || (addr & 3))
  195. return -EINVAL;
  196. pci_write_config_word(hw->pdev, base + PCI_VPD_ADDR, (uint16_t)addr);
  197. do {
  198. udelay(10);
  199. pci_read_config_word(hw->pdev, base + PCI_VPD_ADDR, &val);
  200. } while (!(val & PCI_VPD_ADDR_F) && --attempts);
  201. if (!(val & PCI_VPD_ADDR_F)) {
  202. csio_err(hw, "reading EEPROM address 0x%x failed\n", addr);
  203. return -EINVAL;
  204. }
  205. pci_read_config_dword(hw->pdev, base + PCI_VPD_DATA, data);
  206. *data = le32_to_cpu(*(__le32 *)data);
  207. return 0;
  208. }
  209. /*
  210. * Partial EEPROM Vital Product Data structure. Includes only the ID and
  211. * VPD-R sections.
  212. */
  213. struct t4_vpd_hdr {
  214. u8 id_tag;
  215. u8 id_len[2];
  216. u8 id_data[ID_LEN];
  217. u8 vpdr_tag;
  218. u8 vpdr_len[2];
  219. };
  220. /*
  221. * csio_hw_get_vpd_keyword_val - Locates an information field keyword in
  222. * the VPD
  223. * @v: Pointer to buffered vpd data structure
  224. * @kw: The keyword to search for
  225. *
  226. * Returns the value of the information field keyword or
  227. * -EINVAL otherwise.
  228. */
  229. static int
  230. csio_hw_get_vpd_keyword_val(const struct t4_vpd_hdr *v, const char *kw)
  231. {
  232. int32_t i;
  233. int32_t offset , len;
  234. const uint8_t *buf = &v->id_tag;
  235. const uint8_t *vpdr_len = &v->vpdr_tag;
  236. offset = sizeof(struct t4_vpd_hdr);
  237. len = (uint16_t)vpdr_len[1] + ((uint16_t)vpdr_len[2] << 8);
  238. if (len + sizeof(struct t4_vpd_hdr) > VPD_LEN)
  239. return -EINVAL;
  240. for (i = offset; (i + VPD_INFO_FLD_HDR_SIZE) <= (offset + len);) {
  241. if (memcmp(buf + i , kw, 2) == 0) {
  242. i += VPD_INFO_FLD_HDR_SIZE;
  243. return i;
  244. }
  245. i += VPD_INFO_FLD_HDR_SIZE + buf[i+2];
  246. }
  247. return -EINVAL;
  248. }
  249. static int
  250. csio_pci_capability(struct pci_dev *pdev, int cap, int *pos)
  251. {
  252. *pos = pci_find_capability(pdev, cap);
  253. if (*pos)
  254. return 0;
  255. return -1;
  256. }
  257. /*
  258. * csio_hw_get_vpd_params - read VPD parameters from VPD EEPROM
  259. * @hw: HW module
  260. * @p: where to store the parameters
  261. *
  262. * Reads card parameters stored in VPD EEPROM.
  263. */
  264. static int
  265. csio_hw_get_vpd_params(struct csio_hw *hw, struct csio_vpd *p)
  266. {
  267. int i, ret, ec, sn, addr;
  268. uint8_t *vpd, csum;
  269. const struct t4_vpd_hdr *v;
  270. /* To get around compilation warning from strstrip */
  271. char *s;
  272. if (csio_is_valid_vpd(hw))
  273. return 0;
  274. ret = csio_pci_capability(hw->pdev, PCI_CAP_ID_VPD,
  275. &hw->params.pci.vpd_cap_addr);
  276. if (ret)
  277. return -EINVAL;
  278. vpd = kzalloc(VPD_LEN, GFP_ATOMIC);
  279. if (vpd == NULL)
  280. return -ENOMEM;
  281. /*
  282. * Card information normally starts at VPD_BASE but early cards had
  283. * it at 0.
  284. */
  285. ret = csio_hw_seeprom_read(hw, VPD_BASE, (uint32_t *)(vpd));
  286. addr = *vpd == 0x82 ? VPD_BASE : VPD_BASE_OLD;
  287. for (i = 0; i < VPD_LEN; i += 4) {
  288. ret = csio_hw_seeprom_read(hw, addr + i, (uint32_t *)(vpd + i));
  289. if (ret) {
  290. kfree(vpd);
  291. return ret;
  292. }
  293. }
  294. /* Reset the VPD flag! */
  295. hw->flags &= (~CSIO_HWF_VPD_VALID);
  296. v = (const struct t4_vpd_hdr *)vpd;
  297. #define FIND_VPD_KW(var, name) do { \
  298. var = csio_hw_get_vpd_keyword_val(v, name); \
  299. if (var < 0) { \
  300. csio_err(hw, "missing VPD keyword " name "\n"); \
  301. kfree(vpd); \
  302. return -EINVAL; \
  303. } \
  304. } while (0)
  305. FIND_VPD_KW(i, "RV");
  306. for (csum = 0; i >= 0; i--)
  307. csum += vpd[i];
  308. if (csum) {
  309. csio_err(hw, "corrupted VPD EEPROM, actual csum %u\n", csum);
  310. kfree(vpd);
  311. return -EINVAL;
  312. }
  313. FIND_VPD_KW(ec, "EC");
  314. FIND_VPD_KW(sn, "SN");
  315. #undef FIND_VPD_KW
  316. memcpy(p->id, v->id_data, ID_LEN);
  317. s = strstrip(p->id);
  318. memcpy(p->ec, vpd + ec, EC_LEN);
  319. s = strstrip(p->ec);
  320. i = vpd[sn - VPD_INFO_FLD_HDR_SIZE + 2];
  321. memcpy(p->sn, vpd + sn, min(i, SERNUM_LEN));
  322. s = strstrip(p->sn);
  323. csio_valid_vpd_copied(hw);
  324. kfree(vpd);
  325. return 0;
  326. }
  327. /*
  328. * csio_hw_sf1_read - read data from the serial flash
  329. * @hw: the HW module
  330. * @byte_cnt: number of bytes to read
  331. * @cont: whether another operation will be chained
  332. * @lock: whether to lock SF for PL access only
  333. * @valp: where to store the read data
  334. *
  335. * Reads up to 4 bytes of data from the serial flash. The location of
  336. * the read needs to be specified prior to calling this by issuing the
  337. * appropriate commands to the serial flash.
  338. */
  339. static int
  340. csio_hw_sf1_read(struct csio_hw *hw, uint32_t byte_cnt, int32_t cont,
  341. int32_t lock, uint32_t *valp)
  342. {
  343. int ret;
  344. if (!byte_cnt || byte_cnt > 4)
  345. return -EINVAL;
  346. if (csio_rd_reg32(hw, SF_OP_A) & SF_BUSY_F)
  347. return -EBUSY;
  348. csio_wr_reg32(hw, SF_LOCK_V(lock) | SF_CONT_V(cont) |
  349. BYTECNT_V(byte_cnt - 1), SF_OP_A);
  350. ret = csio_hw_wait_op_done_val(hw, SF_OP_A, SF_BUSY_F, 0, SF_ATTEMPTS,
  351. 10, NULL);
  352. if (!ret)
  353. *valp = csio_rd_reg32(hw, SF_DATA_A);
  354. return ret;
  355. }
  356. /*
  357. * csio_hw_sf1_write - write data to the serial flash
  358. * @hw: the HW module
  359. * @byte_cnt: number of bytes to write
  360. * @cont: whether another operation will be chained
  361. * @lock: whether to lock SF for PL access only
  362. * @val: value to write
  363. *
  364. * Writes up to 4 bytes of data to the serial flash. The location of
  365. * the write needs to be specified prior to calling this by issuing the
  366. * appropriate commands to the serial flash.
  367. */
  368. static int
  369. csio_hw_sf1_write(struct csio_hw *hw, uint32_t byte_cnt, uint32_t cont,
  370. int32_t lock, uint32_t val)
  371. {
  372. if (!byte_cnt || byte_cnt > 4)
  373. return -EINVAL;
  374. if (csio_rd_reg32(hw, SF_OP_A) & SF_BUSY_F)
  375. return -EBUSY;
  376. csio_wr_reg32(hw, val, SF_DATA_A);
  377. csio_wr_reg32(hw, SF_CONT_V(cont) | BYTECNT_V(byte_cnt - 1) |
  378. OP_V(1) | SF_LOCK_V(lock), SF_OP_A);
  379. return csio_hw_wait_op_done_val(hw, SF_OP_A, SF_BUSY_F, 0, SF_ATTEMPTS,
  380. 10, NULL);
  381. }
  382. /*
  383. * csio_hw_flash_wait_op - wait for a flash operation to complete
  384. * @hw: the HW module
  385. * @attempts: max number of polls of the status register
  386. * @delay: delay between polls in ms
  387. *
  388. * Wait for a flash operation to complete by polling the status register.
  389. */
  390. static int
  391. csio_hw_flash_wait_op(struct csio_hw *hw, int32_t attempts, int32_t delay)
  392. {
  393. int ret;
  394. uint32_t status;
  395. while (1) {
  396. ret = csio_hw_sf1_write(hw, 1, 1, 1, SF_RD_STATUS);
  397. if (ret != 0)
  398. return ret;
  399. ret = csio_hw_sf1_read(hw, 1, 0, 1, &status);
  400. if (ret != 0)
  401. return ret;
  402. if (!(status & 1))
  403. return 0;
  404. if (--attempts == 0)
  405. return -EAGAIN;
  406. if (delay)
  407. msleep(delay);
  408. }
  409. }
  410. /*
  411. * csio_hw_read_flash - read words from serial flash
  412. * @hw: the HW module
  413. * @addr: the start address for the read
  414. * @nwords: how many 32-bit words to read
  415. * @data: where to store the read data
  416. * @byte_oriented: whether to store data as bytes or as words
  417. *
  418. * Read the specified number of 32-bit words from the serial flash.
  419. * If @byte_oriented is set the read data is stored as a byte array
  420. * (i.e., big-endian), otherwise as 32-bit words in the platform's
  421. * natural endianess.
  422. */
  423. static int
  424. csio_hw_read_flash(struct csio_hw *hw, uint32_t addr, uint32_t nwords,
  425. uint32_t *data, int32_t byte_oriented)
  426. {
  427. int ret;
  428. if (addr + nwords * sizeof(uint32_t) > hw->params.sf_size || (addr & 3))
  429. return -EINVAL;
  430. addr = swab32(addr) | SF_RD_DATA_FAST;
  431. ret = csio_hw_sf1_write(hw, 4, 1, 0, addr);
  432. if (ret != 0)
  433. return ret;
  434. ret = csio_hw_sf1_read(hw, 1, 1, 0, data);
  435. if (ret != 0)
  436. return ret;
  437. for ( ; nwords; nwords--, data++) {
  438. ret = csio_hw_sf1_read(hw, 4, nwords > 1, nwords == 1, data);
  439. if (nwords == 1)
  440. csio_wr_reg32(hw, 0, SF_OP_A); /* unlock SF */
  441. if (ret)
  442. return ret;
  443. if (byte_oriented)
  444. *data = (__force __u32) htonl(*data);
  445. }
  446. return 0;
  447. }
  448. /*
  449. * csio_hw_write_flash - write up to a page of data to the serial flash
  450. * @hw: the hw
  451. * @addr: the start address to write
  452. * @n: length of data to write in bytes
  453. * @data: the data to write
  454. *
  455. * Writes up to a page of data (256 bytes) to the serial flash starting
  456. * at the given address. All the data must be written to the same page.
  457. */
  458. static int
  459. csio_hw_write_flash(struct csio_hw *hw, uint32_t addr,
  460. uint32_t n, const uint8_t *data)
  461. {
  462. int ret = -EINVAL;
  463. uint32_t buf[64];
  464. uint32_t i, c, left, val, offset = addr & 0xff;
  465. if (addr >= hw->params.sf_size || offset + n > SF_PAGE_SIZE)
  466. return -EINVAL;
  467. val = swab32(addr) | SF_PROG_PAGE;
  468. ret = csio_hw_sf1_write(hw, 1, 0, 1, SF_WR_ENABLE);
  469. if (ret != 0)
  470. goto unlock;
  471. ret = csio_hw_sf1_write(hw, 4, 1, 1, val);
  472. if (ret != 0)
  473. goto unlock;
  474. for (left = n; left; left -= c) {
  475. c = min(left, 4U);
  476. for (val = 0, i = 0; i < c; ++i)
  477. val = (val << 8) + *data++;
  478. ret = csio_hw_sf1_write(hw, c, c != left, 1, val);
  479. if (ret)
  480. goto unlock;
  481. }
  482. ret = csio_hw_flash_wait_op(hw, 8, 1);
  483. if (ret)
  484. goto unlock;
  485. csio_wr_reg32(hw, 0, SF_OP_A); /* unlock SF */
  486. /* Read the page to verify the write succeeded */
  487. ret = csio_hw_read_flash(hw, addr & ~0xff, ARRAY_SIZE(buf), buf, 1);
  488. if (ret)
  489. return ret;
  490. if (memcmp(data - n, (uint8_t *)buf + offset, n)) {
  491. csio_err(hw,
  492. "failed to correctly write the flash page at %#x\n",
  493. addr);
  494. return -EINVAL;
  495. }
  496. return 0;
  497. unlock:
  498. csio_wr_reg32(hw, 0, SF_OP_A); /* unlock SF */
  499. return ret;
  500. }
  501. /*
  502. * csio_hw_flash_erase_sectors - erase a range of flash sectors
  503. * @hw: the HW module
  504. * @start: the first sector to erase
  505. * @end: the last sector to erase
  506. *
  507. * Erases the sectors in the given inclusive range.
  508. */
  509. static int
  510. csio_hw_flash_erase_sectors(struct csio_hw *hw, int32_t start, int32_t end)
  511. {
  512. int ret = 0;
  513. while (start <= end) {
  514. ret = csio_hw_sf1_write(hw, 1, 0, 1, SF_WR_ENABLE);
  515. if (ret != 0)
  516. goto out;
  517. ret = csio_hw_sf1_write(hw, 4, 0, 1,
  518. SF_ERASE_SECTOR | (start << 8));
  519. if (ret != 0)
  520. goto out;
  521. ret = csio_hw_flash_wait_op(hw, 14, 500);
  522. if (ret != 0)
  523. goto out;
  524. start++;
  525. }
  526. out:
  527. if (ret)
  528. csio_err(hw, "erase of flash sector %d failed, error %d\n",
  529. start, ret);
  530. csio_wr_reg32(hw, 0, SF_OP_A); /* unlock SF */
  531. return 0;
  532. }
  533. static void
  534. csio_hw_print_fw_version(struct csio_hw *hw, char *str)
  535. {
  536. csio_info(hw, "%s: %u.%u.%u.%u\n", str,
  537. FW_HDR_FW_VER_MAJOR_G(hw->fwrev),
  538. FW_HDR_FW_VER_MINOR_G(hw->fwrev),
  539. FW_HDR_FW_VER_MICRO_G(hw->fwrev),
  540. FW_HDR_FW_VER_BUILD_G(hw->fwrev));
  541. }
  542. /*
  543. * csio_hw_get_fw_version - read the firmware version
  544. * @hw: HW module
  545. * @vers: where to place the version
  546. *
  547. * Reads the FW version from flash.
  548. */
  549. static int
  550. csio_hw_get_fw_version(struct csio_hw *hw, uint32_t *vers)
  551. {
  552. return csio_hw_read_flash(hw, FLASH_FW_START +
  553. offsetof(struct fw_hdr, fw_ver), 1,
  554. vers, 0);
  555. }
  556. /*
  557. * csio_hw_get_tp_version - read the TP microcode version
  558. * @hw: HW module
  559. * @vers: where to place the version
  560. *
  561. * Reads the TP microcode version from flash.
  562. */
  563. static int
  564. csio_hw_get_tp_version(struct csio_hw *hw, u32 *vers)
  565. {
  566. return csio_hw_read_flash(hw, FLASH_FW_START +
  567. offsetof(struct fw_hdr, tp_microcode_ver), 1,
  568. vers, 0);
  569. }
  570. /*
  571. * csio_hw_fw_dload - download firmware.
  572. * @hw: HW module
  573. * @fw_data: firmware image to write.
  574. * @size: image size
  575. *
  576. * Write the supplied firmware image to the card's serial flash.
  577. */
  578. static int
  579. csio_hw_fw_dload(struct csio_hw *hw, uint8_t *fw_data, uint32_t size)
  580. {
  581. uint32_t csum;
  582. int32_t addr;
  583. int ret;
  584. uint32_t i;
  585. uint8_t first_page[SF_PAGE_SIZE];
  586. const __be32 *p = (const __be32 *)fw_data;
  587. struct fw_hdr *hdr = (struct fw_hdr *)fw_data;
  588. uint32_t sf_sec_size;
  589. if ((!hw->params.sf_size) || (!hw->params.sf_nsec)) {
  590. csio_err(hw, "Serial Flash data invalid\n");
  591. return -EINVAL;
  592. }
  593. if (!size) {
  594. csio_err(hw, "FW image has no data\n");
  595. return -EINVAL;
  596. }
  597. if (size & 511) {
  598. csio_err(hw, "FW image size not multiple of 512 bytes\n");
  599. return -EINVAL;
  600. }
  601. if (ntohs(hdr->len512) * 512 != size) {
  602. csio_err(hw, "FW image size differs from size in FW header\n");
  603. return -EINVAL;
  604. }
  605. if (size > FLASH_FW_MAX_SIZE) {
  606. csio_err(hw, "FW image too large, max is %u bytes\n",
  607. FLASH_FW_MAX_SIZE);
  608. return -EINVAL;
  609. }
  610. for (csum = 0, i = 0; i < size / sizeof(csum); i++)
  611. csum += ntohl(p[i]);
  612. if (csum != 0xffffffff) {
  613. csio_err(hw, "corrupted firmware image, checksum %#x\n", csum);
  614. return -EINVAL;
  615. }
  616. sf_sec_size = hw->params.sf_size / hw->params.sf_nsec;
  617. i = DIV_ROUND_UP(size, sf_sec_size); /* # of sectors spanned */
  618. csio_dbg(hw, "Erasing sectors... start:%d end:%d\n",
  619. FLASH_FW_START_SEC, FLASH_FW_START_SEC + i - 1);
  620. ret = csio_hw_flash_erase_sectors(hw, FLASH_FW_START_SEC,
  621. FLASH_FW_START_SEC + i - 1);
  622. if (ret) {
  623. csio_err(hw, "Flash Erase failed\n");
  624. goto out;
  625. }
  626. /*
  627. * We write the correct version at the end so the driver can see a bad
  628. * version if the FW write fails. Start by writing a copy of the
  629. * first page with a bad version.
  630. */
  631. memcpy(first_page, fw_data, SF_PAGE_SIZE);
  632. ((struct fw_hdr *)first_page)->fw_ver = htonl(0xffffffff);
  633. ret = csio_hw_write_flash(hw, FLASH_FW_START, SF_PAGE_SIZE, first_page);
  634. if (ret)
  635. goto out;
  636. csio_dbg(hw, "Writing Flash .. start:%d end:%d\n",
  637. FW_IMG_START, FW_IMG_START + size);
  638. addr = FLASH_FW_START;
  639. for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) {
  640. addr += SF_PAGE_SIZE;
  641. fw_data += SF_PAGE_SIZE;
  642. ret = csio_hw_write_flash(hw, addr, SF_PAGE_SIZE, fw_data);
  643. if (ret)
  644. goto out;
  645. }
  646. ret = csio_hw_write_flash(hw,
  647. FLASH_FW_START +
  648. offsetof(struct fw_hdr, fw_ver),
  649. sizeof(hdr->fw_ver),
  650. (const uint8_t *)&hdr->fw_ver);
  651. out:
  652. if (ret)
  653. csio_err(hw, "firmware download failed, error %d\n", ret);
  654. return ret;
  655. }
  656. static int
  657. csio_hw_get_flash_params(struct csio_hw *hw)
  658. {
  659. int ret;
  660. uint32_t info = 0;
  661. ret = csio_hw_sf1_write(hw, 1, 1, 0, SF_RD_ID);
  662. if (!ret)
  663. ret = csio_hw_sf1_read(hw, 3, 0, 1, &info);
  664. csio_wr_reg32(hw, 0, SF_OP_A); /* unlock SF */
  665. if (ret != 0)
  666. return ret;
  667. if ((info & 0xff) != 0x20) /* not a Numonix flash */
  668. return -EINVAL;
  669. info >>= 16; /* log2 of size */
  670. if (info >= 0x14 && info < 0x18)
  671. hw->params.sf_nsec = 1 << (info - 16);
  672. else if (info == 0x18)
  673. hw->params.sf_nsec = 64;
  674. else
  675. return -EINVAL;
  676. hw->params.sf_size = 1 << info;
  677. return 0;
  678. }
  679. /*****************************************************************************/
  680. /* HW State machine assists */
  681. /*****************************************************************************/
  682. static int
  683. csio_hw_dev_ready(struct csio_hw *hw)
  684. {
  685. uint32_t reg;
  686. int cnt = 6;
  687. while (((reg = csio_rd_reg32(hw, PL_WHOAMI_A)) == 0xFFFFFFFF) &&
  688. (--cnt != 0))
  689. mdelay(100);
  690. if ((cnt == 0) && (((int32_t)(SOURCEPF_G(reg)) < 0) ||
  691. (SOURCEPF_G(reg) >= CSIO_MAX_PFN))) {
  692. csio_err(hw, "PL_WHOAMI returned 0x%x, cnt:%d\n", reg, cnt);
  693. return -EIO;
  694. }
  695. hw->pfn = SOURCEPF_G(reg);
  696. return 0;
  697. }
  698. /*
  699. * csio_do_hello - Perform the HELLO FW Mailbox command and process response.
  700. * @hw: HW module
  701. * @state: Device state
  702. *
  703. * FW_HELLO_CMD has to be polled for completion.
  704. */
  705. static int
  706. csio_do_hello(struct csio_hw *hw, enum csio_dev_state *state)
  707. {
  708. struct csio_mb *mbp;
  709. int rv = 0;
  710. enum fw_retval retval;
  711. uint8_t mpfn;
  712. char state_str[16];
  713. int retries = FW_CMD_HELLO_RETRIES;
  714. memset(state_str, 0, sizeof(state_str));
  715. mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
  716. if (!mbp) {
  717. rv = -ENOMEM;
  718. CSIO_INC_STATS(hw, n_err_nomem);
  719. goto out;
  720. }
  721. retry:
  722. csio_mb_hello(hw, mbp, CSIO_MB_DEFAULT_TMO, hw->pfn,
  723. hw->pfn, CSIO_MASTER_MAY, NULL);
  724. rv = csio_mb_issue(hw, mbp);
  725. if (rv) {
  726. csio_err(hw, "failed to issue HELLO cmd. ret:%d.\n", rv);
  727. goto out_free_mb;
  728. }
  729. csio_mb_process_hello_rsp(hw, mbp, &retval, state, &mpfn);
  730. if (retval != FW_SUCCESS) {
  731. csio_err(hw, "HELLO cmd failed with ret: %d\n", retval);
  732. rv = -EINVAL;
  733. goto out_free_mb;
  734. }
  735. /* Firmware has designated us to be master */
  736. if (hw->pfn == mpfn) {
  737. hw->flags |= CSIO_HWF_MASTER;
  738. } else if (*state == CSIO_DEV_STATE_UNINIT) {
  739. /*
  740. * If we're not the Master PF then we need to wait around for
  741. * the Master PF Driver to finish setting up the adapter.
  742. *
  743. * Note that we also do this wait if we're a non-Master-capable
  744. * PF and there is no current Master PF; a Master PF may show up
  745. * momentarily and we wouldn't want to fail pointlessly. (This
  746. * can happen when an OS loads lots of different drivers rapidly
  747. * at the same time). In this case, the Master PF returned by
  748. * the firmware will be PCIE_FW_MASTER_MASK so the test below
  749. * will work ...
  750. */
  751. int waiting = FW_CMD_HELLO_TIMEOUT;
  752. /*
  753. * Wait for the firmware to either indicate an error or
  754. * initialized state. If we see either of these we bail out
  755. * and report the issue to the caller. If we exhaust the
  756. * "hello timeout" and we haven't exhausted our retries, try
  757. * again. Otherwise bail with a timeout error.
  758. */
  759. for (;;) {
  760. uint32_t pcie_fw;
  761. spin_unlock_irq(&hw->lock);
  762. msleep(50);
  763. spin_lock_irq(&hw->lock);
  764. waiting -= 50;
  765. /*
  766. * If neither Error nor Initialialized are indicated
  767. * by the firmware keep waiting till we exaust our
  768. * timeout ... and then retry if we haven't exhausted
  769. * our retries ...
  770. */
  771. pcie_fw = csio_rd_reg32(hw, PCIE_FW_A);
  772. if (!(pcie_fw & (PCIE_FW_ERR_F|PCIE_FW_INIT_F))) {
  773. if (waiting <= 0) {
  774. if (retries-- > 0)
  775. goto retry;
  776. rv = -ETIMEDOUT;
  777. break;
  778. }
  779. continue;
  780. }
  781. /*
  782. * We either have an Error or Initialized condition
  783. * report errors preferentially.
  784. */
  785. if (state) {
  786. if (pcie_fw & PCIE_FW_ERR_F) {
  787. *state = CSIO_DEV_STATE_ERR;
  788. rv = -ETIMEDOUT;
  789. } else if (pcie_fw & PCIE_FW_INIT_F)
  790. *state = CSIO_DEV_STATE_INIT;
  791. }
  792. /*
  793. * If we arrived before a Master PF was selected and
  794. * there's not a valid Master PF, grab its identity
  795. * for our caller.
  796. */
  797. if (mpfn == PCIE_FW_MASTER_M &&
  798. (pcie_fw & PCIE_FW_MASTER_VLD_F))
  799. mpfn = PCIE_FW_MASTER_G(pcie_fw);
  800. break;
  801. }
  802. hw->flags &= ~CSIO_HWF_MASTER;
  803. }
  804. switch (*state) {
  805. case CSIO_DEV_STATE_UNINIT:
  806. strcpy(state_str, "Initializing");
  807. break;
  808. case CSIO_DEV_STATE_INIT:
  809. strcpy(state_str, "Initialized");
  810. break;
  811. case CSIO_DEV_STATE_ERR:
  812. strcpy(state_str, "Error");
  813. break;
  814. default:
  815. strcpy(state_str, "Unknown");
  816. break;
  817. }
  818. if (hw->pfn == mpfn)
  819. csio_info(hw, "PF: %d, Coming up as MASTER, HW state: %s\n",
  820. hw->pfn, state_str);
  821. else
  822. csio_info(hw,
  823. "PF: %d, Coming up as SLAVE, Master PF: %d, HW state: %s\n",
  824. hw->pfn, mpfn, state_str);
  825. out_free_mb:
  826. mempool_free(mbp, hw->mb_mempool);
  827. out:
  828. return rv;
  829. }
  830. /*
  831. * csio_do_bye - Perform the BYE FW Mailbox command and process response.
  832. * @hw: HW module
  833. *
  834. */
  835. static int
  836. csio_do_bye(struct csio_hw *hw)
  837. {
  838. struct csio_mb *mbp;
  839. enum fw_retval retval;
  840. mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
  841. if (!mbp) {
  842. CSIO_INC_STATS(hw, n_err_nomem);
  843. return -ENOMEM;
  844. }
  845. csio_mb_bye(hw, mbp, CSIO_MB_DEFAULT_TMO, NULL);
  846. if (csio_mb_issue(hw, mbp)) {
  847. csio_err(hw, "Issue of BYE command failed\n");
  848. mempool_free(mbp, hw->mb_mempool);
  849. return -EINVAL;
  850. }
  851. retval = csio_mb_fw_retval(mbp);
  852. if (retval != FW_SUCCESS) {
  853. mempool_free(mbp, hw->mb_mempool);
  854. return -EINVAL;
  855. }
  856. mempool_free(mbp, hw->mb_mempool);
  857. return 0;
  858. }
  859. /*
  860. * csio_do_reset- Perform the device reset.
  861. * @hw: HW module
  862. * @fw_rst: FW reset
  863. *
  864. * If fw_rst is set, issues FW reset mbox cmd otherwise
  865. * does PIO reset.
  866. * Performs reset of the function.
  867. */
  868. static int
  869. csio_do_reset(struct csio_hw *hw, bool fw_rst)
  870. {
  871. struct csio_mb *mbp;
  872. enum fw_retval retval;
  873. if (!fw_rst) {
  874. /* PIO reset */
  875. csio_wr_reg32(hw, PIORSTMODE_F | PIORST_F, PL_RST_A);
  876. mdelay(2000);
  877. return 0;
  878. }
  879. mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
  880. if (!mbp) {
  881. CSIO_INC_STATS(hw, n_err_nomem);
  882. return -ENOMEM;
  883. }
  884. csio_mb_reset(hw, mbp, CSIO_MB_DEFAULT_TMO,
  885. PIORSTMODE_F | PIORST_F, 0, NULL);
  886. if (csio_mb_issue(hw, mbp)) {
  887. csio_err(hw, "Issue of RESET command failed.n");
  888. mempool_free(mbp, hw->mb_mempool);
  889. return -EINVAL;
  890. }
  891. retval = csio_mb_fw_retval(mbp);
  892. if (retval != FW_SUCCESS) {
  893. csio_err(hw, "RESET cmd failed with ret:0x%x.\n", retval);
  894. mempool_free(mbp, hw->mb_mempool);
  895. return -EINVAL;
  896. }
  897. mempool_free(mbp, hw->mb_mempool);
  898. return 0;
  899. }
  900. static int
  901. csio_hw_validate_caps(struct csio_hw *hw, struct csio_mb *mbp)
  902. {
  903. struct fw_caps_config_cmd *rsp = (struct fw_caps_config_cmd *)mbp->mb;
  904. uint16_t caps;
  905. caps = ntohs(rsp->fcoecaps);
  906. if (!(caps & FW_CAPS_CONFIG_FCOE_INITIATOR)) {
  907. csio_err(hw, "No FCoE Initiator capability in the firmware.\n");
  908. return -EINVAL;
  909. }
  910. if (!(caps & FW_CAPS_CONFIG_FCOE_CTRL_OFLD)) {
  911. csio_err(hw, "No FCoE Control Offload capability\n");
  912. return -EINVAL;
  913. }
  914. return 0;
  915. }
  916. /*
  917. * csio_hw_fw_halt - issue a reset/halt to FW and put uP into RESET
  918. * @hw: the HW module
  919. * @mbox: mailbox to use for the FW RESET command (if desired)
  920. * @force: force uP into RESET even if FW RESET command fails
  921. *
  922. * Issues a RESET command to firmware (if desired) with a HALT indication
  923. * and then puts the microprocessor into RESET state. The RESET command
  924. * will only be issued if a legitimate mailbox is provided (mbox <=
  925. * PCIE_FW_MASTER_MASK).
  926. *
  927. * This is generally used in order for the host to safely manipulate the
  928. * adapter without fear of conflicting with whatever the firmware might
  929. * be doing. The only way out of this state is to RESTART the firmware
  930. * ...
  931. */
  932. static int
  933. csio_hw_fw_halt(struct csio_hw *hw, uint32_t mbox, int32_t force)
  934. {
  935. enum fw_retval retval = 0;
  936. /*
  937. * If a legitimate mailbox is provided, issue a RESET command
  938. * with a HALT indication.
  939. */
  940. if (mbox <= PCIE_FW_MASTER_M) {
  941. struct csio_mb *mbp;
  942. mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
  943. if (!mbp) {
  944. CSIO_INC_STATS(hw, n_err_nomem);
  945. return -ENOMEM;
  946. }
  947. csio_mb_reset(hw, mbp, CSIO_MB_DEFAULT_TMO,
  948. PIORSTMODE_F | PIORST_F, FW_RESET_CMD_HALT_F,
  949. NULL);
  950. if (csio_mb_issue(hw, mbp)) {
  951. csio_err(hw, "Issue of RESET command failed!\n");
  952. mempool_free(mbp, hw->mb_mempool);
  953. return -EINVAL;
  954. }
  955. retval = csio_mb_fw_retval(mbp);
  956. mempool_free(mbp, hw->mb_mempool);
  957. }
  958. /*
  959. * Normally we won't complete the operation if the firmware RESET
  960. * command fails but if our caller insists we'll go ahead and put the
  961. * uP into RESET. This can be useful if the firmware is hung or even
  962. * missing ... We'll have to take the risk of putting the uP into
  963. * RESET without the cooperation of firmware in that case.
  964. *
  965. * We also force the firmware's HALT flag to be on in case we bypassed
  966. * the firmware RESET command above or we're dealing with old firmware
  967. * which doesn't have the HALT capability. This will serve as a flag
  968. * for the incoming firmware to know that it's coming out of a HALT
  969. * rather than a RESET ... if it's new enough to understand that ...
  970. */
  971. if (retval == 0 || force) {
  972. csio_set_reg_field(hw, CIM_BOOT_CFG_A, UPCRST_F, UPCRST_F);
  973. csio_set_reg_field(hw, PCIE_FW_A, PCIE_FW_HALT_F,
  974. PCIE_FW_HALT_F);
  975. }
  976. /*
  977. * And we always return the result of the firmware RESET command
  978. * even when we force the uP into RESET ...
  979. */
  980. return retval ? -EINVAL : 0;
  981. }
  982. /*
  983. * csio_hw_fw_restart - restart the firmware by taking the uP out of RESET
  984. * @hw: the HW module
  985. * @reset: if we want to do a RESET to restart things
  986. *
  987. * Restart firmware previously halted by csio_hw_fw_halt(). On successful
  988. * return the previous PF Master remains as the new PF Master and there
  989. * is no need to issue a new HELLO command, etc.
  990. *
  991. * We do this in two ways:
  992. *
  993. * 1. If we're dealing with newer firmware we'll simply want to take
  994. * the chip's microprocessor out of RESET. This will cause the
  995. * firmware to start up from its start vector. And then we'll loop
  996. * until the firmware indicates it's started again (PCIE_FW.HALT
  997. * reset to 0) or we timeout.
  998. *
  999. * 2. If we're dealing with older firmware then we'll need to RESET
  1000. * the chip since older firmware won't recognize the PCIE_FW.HALT
  1001. * flag and automatically RESET itself on startup.
  1002. */
  1003. static int
  1004. csio_hw_fw_restart(struct csio_hw *hw, uint32_t mbox, int32_t reset)
  1005. {
  1006. if (reset) {
  1007. /*
  1008. * Since we're directing the RESET instead of the firmware
  1009. * doing it automatically, we need to clear the PCIE_FW.HALT
  1010. * bit.
  1011. */
  1012. csio_set_reg_field(hw, PCIE_FW_A, PCIE_FW_HALT_F, 0);
  1013. /*
  1014. * If we've been given a valid mailbox, first try to get the
  1015. * firmware to do the RESET. If that works, great and we can
  1016. * return success. Otherwise, if we haven't been given a
  1017. * valid mailbox or the RESET command failed, fall back to
  1018. * hitting the chip with a hammer.
  1019. */
  1020. if (mbox <= PCIE_FW_MASTER_M) {
  1021. csio_set_reg_field(hw, CIM_BOOT_CFG_A, UPCRST_F, 0);
  1022. msleep(100);
  1023. if (csio_do_reset(hw, true) == 0)
  1024. return 0;
  1025. }
  1026. csio_wr_reg32(hw, PIORSTMODE_F | PIORST_F, PL_RST_A);
  1027. msleep(2000);
  1028. } else {
  1029. int ms;
  1030. csio_set_reg_field(hw, CIM_BOOT_CFG_A, UPCRST_F, 0);
  1031. for (ms = 0; ms < FW_CMD_MAX_TIMEOUT; ) {
  1032. if (!(csio_rd_reg32(hw, PCIE_FW_A) & PCIE_FW_HALT_F))
  1033. return 0;
  1034. msleep(100);
  1035. ms += 100;
  1036. }
  1037. return -ETIMEDOUT;
  1038. }
  1039. return 0;
  1040. }
  1041. /*
  1042. * csio_hw_fw_upgrade - perform all of the steps necessary to upgrade FW
  1043. * @hw: the HW module
  1044. * @mbox: mailbox to use for the FW RESET command (if desired)
  1045. * @fw_data: the firmware image to write
  1046. * @size: image size
  1047. * @force: force upgrade even if firmware doesn't cooperate
  1048. *
  1049. * Perform all of the steps necessary for upgrading an adapter's
  1050. * firmware image. Normally this requires the cooperation of the
  1051. * existing firmware in order to halt all existing activities
  1052. * but if an invalid mailbox token is passed in we skip that step
  1053. * (though we'll still put the adapter microprocessor into RESET in
  1054. * that case).
  1055. *
  1056. * On successful return the new firmware will have been loaded and
  1057. * the adapter will have been fully RESET losing all previous setup
  1058. * state. On unsuccessful return the adapter may be completely hosed ...
  1059. * positive errno indicates that the adapter is ~probably~ intact, a
  1060. * negative errno indicates that things are looking bad ...
  1061. */
  1062. static int
  1063. csio_hw_fw_upgrade(struct csio_hw *hw, uint32_t mbox,
  1064. const u8 *fw_data, uint32_t size, int32_t force)
  1065. {
  1066. const struct fw_hdr *fw_hdr = (const struct fw_hdr *)fw_data;
  1067. int reset, ret;
  1068. ret = csio_hw_fw_halt(hw, mbox, force);
  1069. if (ret != 0 && !force)
  1070. return ret;
  1071. ret = csio_hw_fw_dload(hw, (uint8_t *) fw_data, size);
  1072. if (ret != 0)
  1073. return ret;
  1074. /*
  1075. * Older versions of the firmware don't understand the new
  1076. * PCIE_FW.HALT flag and so won't know to perform a RESET when they
  1077. * restart. So for newly loaded older firmware we'll have to do the
  1078. * RESET for it so it starts up on a clean slate. We can tell if
  1079. * the newly loaded firmware will handle this right by checking
  1080. * its header flags to see if it advertises the capability.
  1081. */
  1082. reset = ((ntohl(fw_hdr->flags) & FW_HDR_FLAGS_RESET_HALT) == 0);
  1083. return csio_hw_fw_restart(hw, mbox, reset);
  1084. }
  1085. /*
  1086. * csio_get_device_params - Get device parameters.
  1087. * @hw: HW module
  1088. *
  1089. */
  1090. static int
  1091. csio_get_device_params(struct csio_hw *hw)
  1092. {
  1093. struct csio_wrm *wrm = csio_hw_to_wrm(hw);
  1094. struct csio_mb *mbp;
  1095. enum fw_retval retval;
  1096. u32 param[6];
  1097. int i, j = 0;
  1098. /* Initialize portids to -1 */
  1099. for (i = 0; i < CSIO_MAX_PPORTS; i++)
  1100. hw->pport[i].portid = -1;
  1101. mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
  1102. if (!mbp) {
  1103. CSIO_INC_STATS(hw, n_err_nomem);
  1104. return -ENOMEM;
  1105. }
  1106. /* Get port vec information. */
  1107. param[0] = FW_PARAM_DEV(PORTVEC);
  1108. /* Get Core clock. */
  1109. param[1] = FW_PARAM_DEV(CCLK);
  1110. /* Get EQ id start and end. */
  1111. param[2] = FW_PARAM_PFVF(EQ_START);
  1112. param[3] = FW_PARAM_PFVF(EQ_END);
  1113. /* Get IQ id start and end. */
  1114. param[4] = FW_PARAM_PFVF(IQFLINT_START);
  1115. param[5] = FW_PARAM_PFVF(IQFLINT_END);
  1116. csio_mb_params(hw, mbp, CSIO_MB_DEFAULT_TMO, hw->pfn, 0,
  1117. ARRAY_SIZE(param), param, NULL, false, NULL);
  1118. if (csio_mb_issue(hw, mbp)) {
  1119. csio_err(hw, "Issue of FW_PARAMS_CMD(read) failed!\n");
  1120. mempool_free(mbp, hw->mb_mempool);
  1121. return -EINVAL;
  1122. }
  1123. csio_mb_process_read_params_rsp(hw, mbp, &retval,
  1124. ARRAY_SIZE(param), param);
  1125. if (retval != FW_SUCCESS) {
  1126. csio_err(hw, "FW_PARAMS_CMD(read) failed with ret:0x%x!\n",
  1127. retval);
  1128. mempool_free(mbp, hw->mb_mempool);
  1129. return -EINVAL;
  1130. }
  1131. /* cache the information. */
  1132. hw->port_vec = param[0];
  1133. hw->vpd.cclk = param[1];
  1134. wrm->fw_eq_start = param[2];
  1135. wrm->fw_iq_start = param[4];
  1136. /* Using FW configured max iqs & eqs */
  1137. if ((hw->flags & CSIO_HWF_USING_SOFT_PARAMS) ||
  1138. !csio_is_hw_master(hw)) {
  1139. hw->cfg_niq = param[5] - param[4] + 1;
  1140. hw->cfg_neq = param[3] - param[2] + 1;
  1141. csio_dbg(hw, "Using fwconfig max niqs %d neqs %d\n",
  1142. hw->cfg_niq, hw->cfg_neq);
  1143. }
  1144. hw->port_vec &= csio_port_mask;
  1145. hw->num_pports = hweight32(hw->port_vec);
  1146. csio_dbg(hw, "Port vector: 0x%x, #ports: %d\n",
  1147. hw->port_vec, hw->num_pports);
  1148. for (i = 0; i < hw->num_pports; i++) {
  1149. while ((hw->port_vec & (1 << j)) == 0)
  1150. j++;
  1151. hw->pport[i].portid = j++;
  1152. csio_dbg(hw, "Found Port:%d\n", hw->pport[i].portid);
  1153. }
  1154. mempool_free(mbp, hw->mb_mempool);
  1155. return 0;
  1156. }
  1157. /*
  1158. * csio_config_device_caps - Get and set device capabilities.
  1159. * @hw: HW module
  1160. *
  1161. */
  1162. static int
  1163. csio_config_device_caps(struct csio_hw *hw)
  1164. {
  1165. struct csio_mb *mbp;
  1166. enum fw_retval retval;
  1167. int rv = -EINVAL;
  1168. mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
  1169. if (!mbp) {
  1170. CSIO_INC_STATS(hw, n_err_nomem);
  1171. return -ENOMEM;
  1172. }
  1173. /* Get device capabilities */
  1174. csio_mb_caps_config(hw, mbp, CSIO_MB_DEFAULT_TMO, 0, 0, 0, 0, NULL);
  1175. if (csio_mb_issue(hw, mbp)) {
  1176. csio_err(hw, "Issue of FW_CAPS_CONFIG_CMD(r) failed!\n");
  1177. goto out;
  1178. }
  1179. retval = csio_mb_fw_retval(mbp);
  1180. if (retval != FW_SUCCESS) {
  1181. csio_err(hw, "FW_CAPS_CONFIG_CMD(r) returned %d!\n", retval);
  1182. goto out;
  1183. }
  1184. /* Validate device capabilities */
  1185. rv = csio_hw_validate_caps(hw, mbp);
  1186. if (rv != 0)
  1187. goto out;
  1188. /* Don't config device capabilities if already configured */
  1189. if (hw->fw_state == CSIO_DEV_STATE_INIT) {
  1190. rv = 0;
  1191. goto out;
  1192. }
  1193. /* Write back desired device capabilities */
  1194. csio_mb_caps_config(hw, mbp, CSIO_MB_DEFAULT_TMO, true, true,
  1195. false, true, NULL);
  1196. if (csio_mb_issue(hw, mbp)) {
  1197. csio_err(hw, "Issue of FW_CAPS_CONFIG_CMD(w) failed!\n");
  1198. goto out;
  1199. }
  1200. retval = csio_mb_fw_retval(mbp);
  1201. if (retval != FW_SUCCESS) {
  1202. csio_err(hw, "FW_CAPS_CONFIG_CMD(w) returned %d!\n", retval);
  1203. goto out;
  1204. }
  1205. rv = 0;
  1206. out:
  1207. mempool_free(mbp, hw->mb_mempool);
  1208. return rv;
  1209. }
  1210. /*
  1211. * csio_enable_ports - Bring up all available ports.
  1212. * @hw: HW module.
  1213. *
  1214. */
  1215. static int
  1216. csio_enable_ports(struct csio_hw *hw)
  1217. {
  1218. struct csio_mb *mbp;
  1219. enum fw_retval retval;
  1220. uint8_t portid;
  1221. int i;
  1222. mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
  1223. if (!mbp) {
  1224. CSIO_INC_STATS(hw, n_err_nomem);
  1225. return -ENOMEM;
  1226. }
  1227. for (i = 0; i < hw->num_pports; i++) {
  1228. portid = hw->pport[i].portid;
  1229. /* Read PORT information */
  1230. csio_mb_port(hw, mbp, CSIO_MB_DEFAULT_TMO, portid,
  1231. false, 0, 0, NULL);
  1232. if (csio_mb_issue(hw, mbp)) {
  1233. csio_err(hw, "failed to issue FW_PORT_CMD(r) port:%d\n",
  1234. portid);
  1235. mempool_free(mbp, hw->mb_mempool);
  1236. return -EINVAL;
  1237. }
  1238. csio_mb_process_read_port_rsp(hw, mbp, &retval,
  1239. &hw->pport[i].pcap);
  1240. if (retval != FW_SUCCESS) {
  1241. csio_err(hw, "FW_PORT_CMD(r) port:%d failed: 0x%x\n",
  1242. portid, retval);
  1243. mempool_free(mbp, hw->mb_mempool);
  1244. return -EINVAL;
  1245. }
  1246. /* Write back PORT information */
  1247. csio_mb_port(hw, mbp, CSIO_MB_DEFAULT_TMO, portid, true,
  1248. (PAUSE_RX | PAUSE_TX), hw->pport[i].pcap, NULL);
  1249. if (csio_mb_issue(hw, mbp)) {
  1250. csio_err(hw, "failed to issue FW_PORT_CMD(w) port:%d\n",
  1251. portid);
  1252. mempool_free(mbp, hw->mb_mempool);
  1253. return -EINVAL;
  1254. }
  1255. retval = csio_mb_fw_retval(mbp);
  1256. if (retval != FW_SUCCESS) {
  1257. csio_err(hw, "FW_PORT_CMD(w) port:%d failed :0x%x\n",
  1258. portid, retval);
  1259. mempool_free(mbp, hw->mb_mempool);
  1260. return -EINVAL;
  1261. }
  1262. } /* For all ports */
  1263. mempool_free(mbp, hw->mb_mempool);
  1264. return 0;
  1265. }
  1266. /*
  1267. * csio_get_fcoe_resinfo - Read fcoe fw resource info.
  1268. * @hw: HW module
  1269. * Issued with lock held.
  1270. */
  1271. static int
  1272. csio_get_fcoe_resinfo(struct csio_hw *hw)
  1273. {
  1274. struct csio_fcoe_res_info *res_info = &hw->fres_info;
  1275. struct fw_fcoe_res_info_cmd *rsp;
  1276. struct csio_mb *mbp;
  1277. enum fw_retval retval;
  1278. mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
  1279. if (!mbp) {
  1280. CSIO_INC_STATS(hw, n_err_nomem);
  1281. return -ENOMEM;
  1282. }
  1283. /* Get FCoE FW resource information */
  1284. csio_fcoe_read_res_info_init_mb(hw, mbp, CSIO_MB_DEFAULT_TMO, NULL);
  1285. if (csio_mb_issue(hw, mbp)) {
  1286. csio_err(hw, "failed to issue FW_FCOE_RES_INFO_CMD\n");
  1287. mempool_free(mbp, hw->mb_mempool);
  1288. return -EINVAL;
  1289. }
  1290. rsp = (struct fw_fcoe_res_info_cmd *)(mbp->mb);
  1291. retval = FW_CMD_RETVAL_G(ntohl(rsp->retval_len16));
  1292. if (retval != FW_SUCCESS) {
  1293. csio_err(hw, "FW_FCOE_RES_INFO_CMD failed with ret x%x\n",
  1294. retval);
  1295. mempool_free(mbp, hw->mb_mempool);
  1296. return -EINVAL;
  1297. }
  1298. res_info->e_d_tov = ntohs(rsp->e_d_tov);
  1299. res_info->r_a_tov_seq = ntohs(rsp->r_a_tov_seq);
  1300. res_info->r_a_tov_els = ntohs(rsp->r_a_tov_els);
  1301. res_info->r_r_tov = ntohs(rsp->r_r_tov);
  1302. res_info->max_xchgs = ntohl(rsp->max_xchgs);
  1303. res_info->max_ssns = ntohl(rsp->max_ssns);
  1304. res_info->used_xchgs = ntohl(rsp->used_xchgs);
  1305. res_info->used_ssns = ntohl(rsp->used_ssns);
  1306. res_info->max_fcfs = ntohl(rsp->max_fcfs);
  1307. res_info->max_vnps = ntohl(rsp->max_vnps);
  1308. res_info->used_fcfs = ntohl(rsp->used_fcfs);
  1309. res_info->used_vnps = ntohl(rsp->used_vnps);
  1310. csio_dbg(hw, "max ssns:%d max xchgs:%d\n", res_info->max_ssns,
  1311. res_info->max_xchgs);
  1312. mempool_free(mbp, hw->mb_mempool);
  1313. return 0;
  1314. }
  1315. static int
  1316. csio_hw_check_fwconfig(struct csio_hw *hw, u32 *param)
  1317. {
  1318. struct csio_mb *mbp;
  1319. enum fw_retval retval;
  1320. u32 _param[1];
  1321. mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
  1322. if (!mbp) {
  1323. CSIO_INC_STATS(hw, n_err_nomem);
  1324. return -ENOMEM;
  1325. }
  1326. /*
  1327. * Find out whether we're dealing with a version of
  1328. * the firmware which has configuration file support.
  1329. */
  1330. _param[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  1331. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  1332. csio_mb_params(hw, mbp, CSIO_MB_DEFAULT_TMO, hw->pfn, 0,
  1333. ARRAY_SIZE(_param), _param, NULL, false, NULL);
  1334. if (csio_mb_issue(hw, mbp)) {
  1335. csio_err(hw, "Issue of FW_PARAMS_CMD(read) failed!\n");
  1336. mempool_free(mbp, hw->mb_mempool);
  1337. return -EINVAL;
  1338. }
  1339. csio_mb_process_read_params_rsp(hw, mbp, &retval,
  1340. ARRAY_SIZE(_param), _param);
  1341. if (retval != FW_SUCCESS) {
  1342. csio_err(hw, "FW_PARAMS_CMD(read) failed with ret:0x%x!\n",
  1343. retval);
  1344. mempool_free(mbp, hw->mb_mempool);
  1345. return -EINVAL;
  1346. }
  1347. mempool_free(mbp, hw->mb_mempool);
  1348. *param = _param[0];
  1349. return 0;
  1350. }
  1351. static int
  1352. csio_hw_flash_config(struct csio_hw *hw, u32 *fw_cfg_param, char *path)
  1353. {
  1354. int ret = 0;
  1355. const struct firmware *cf;
  1356. struct pci_dev *pci_dev = hw->pdev;
  1357. struct device *dev = &pci_dev->dev;
  1358. unsigned int mtype = 0, maddr = 0;
  1359. uint32_t *cfg_data;
  1360. int value_to_add = 0;
  1361. if (request_firmware(&cf, FW_CFG_NAME_T5, dev) < 0) {
  1362. csio_err(hw, "could not find config file %s, err: %d\n",
  1363. FW_CFG_NAME_T5, ret);
  1364. return -ENOENT;
  1365. }
  1366. if (cf->size%4 != 0)
  1367. value_to_add = 4 - (cf->size % 4);
  1368. cfg_data = kzalloc(cf->size+value_to_add, GFP_KERNEL);
  1369. if (cfg_data == NULL) {
  1370. ret = -ENOMEM;
  1371. goto leave;
  1372. }
  1373. memcpy((void *)cfg_data, (const void *)cf->data, cf->size);
  1374. if (csio_hw_check_fwconfig(hw, fw_cfg_param) != 0) {
  1375. ret = -EINVAL;
  1376. goto leave;
  1377. }
  1378. mtype = FW_PARAMS_PARAM_Y_G(*fw_cfg_param);
  1379. maddr = FW_PARAMS_PARAM_Z_G(*fw_cfg_param) << 16;
  1380. ret = csio_memory_write(hw, mtype, maddr,
  1381. cf->size + value_to_add, cfg_data);
  1382. if ((ret == 0) && (value_to_add != 0)) {
  1383. union {
  1384. u32 word;
  1385. char buf[4];
  1386. } last;
  1387. size_t size = cf->size & ~0x3;
  1388. int i;
  1389. last.word = cfg_data[size >> 2];
  1390. for (i = value_to_add; i < 4; i++)
  1391. last.buf[i] = 0;
  1392. ret = csio_memory_write(hw, mtype, maddr + size, 4, &last.word);
  1393. }
  1394. if (ret == 0) {
  1395. csio_info(hw, "config file upgraded to %s\n",
  1396. FW_CFG_NAME_T5);
  1397. snprintf(path, 64, "%s%s", "/lib/firmware/", FW_CFG_NAME_T5);
  1398. }
  1399. leave:
  1400. kfree(cfg_data);
  1401. release_firmware(cf);
  1402. return ret;
  1403. }
  1404. /*
  1405. * HW initialization: contact FW, obtain config, perform basic init.
  1406. *
  1407. * If the firmware we're dealing with has Configuration File support, then
  1408. * we use that to perform all configuration -- either using the configuration
  1409. * file stored in flash on the adapter or using a filesystem-local file
  1410. * if available.
  1411. *
  1412. * If we don't have configuration file support in the firmware, then we'll
  1413. * have to set things up the old fashioned way with hard-coded register
  1414. * writes and firmware commands ...
  1415. */
  1416. /*
  1417. * Attempt to initialize the HW via a Firmware Configuration File.
  1418. */
  1419. static int
  1420. csio_hw_use_fwconfig(struct csio_hw *hw, int reset, u32 *fw_cfg_param)
  1421. {
  1422. struct csio_mb *mbp = NULL;
  1423. struct fw_caps_config_cmd *caps_cmd;
  1424. unsigned int mtype, maddr;
  1425. int rv = -EINVAL;
  1426. uint32_t finiver = 0, finicsum = 0, cfcsum = 0;
  1427. char path[64];
  1428. char *config_name = NULL;
  1429. /*
  1430. * Reset device if necessary
  1431. */
  1432. if (reset) {
  1433. rv = csio_do_reset(hw, true);
  1434. if (rv != 0)
  1435. goto bye;
  1436. }
  1437. /*
  1438. * If we have a configuration file in host ,
  1439. * then use that. Otherwise, use the configuration file stored
  1440. * in the HW flash ...
  1441. */
  1442. spin_unlock_irq(&hw->lock);
  1443. rv = csio_hw_flash_config(hw, fw_cfg_param, path);
  1444. spin_lock_irq(&hw->lock);
  1445. if (rv != 0) {
  1446. /*
  1447. * config file was not found. Use default
  1448. * config file from flash.
  1449. */
  1450. config_name = "On FLASH";
  1451. mtype = FW_MEMTYPE_CF_FLASH;
  1452. maddr = hw->chip_ops->chip_flash_cfg_addr(hw);
  1453. } else {
  1454. config_name = path;
  1455. mtype = FW_PARAMS_PARAM_Y_G(*fw_cfg_param);
  1456. maddr = FW_PARAMS_PARAM_Z_G(*fw_cfg_param) << 16;
  1457. }
  1458. mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
  1459. if (!mbp) {
  1460. CSIO_INC_STATS(hw, n_err_nomem);
  1461. return -ENOMEM;
  1462. }
  1463. /*
  1464. * Tell the firmware to process the indicated Configuration File.
  1465. * If there are no errors and the caller has provided return value
  1466. * pointers for the [fini] section version, checksum and computed
  1467. * checksum, pass those back to the caller.
  1468. */
  1469. caps_cmd = (struct fw_caps_config_cmd *)(mbp->mb);
  1470. CSIO_INIT_MBP(mbp, caps_cmd, CSIO_MB_DEFAULT_TMO, hw, NULL, 1);
  1471. caps_cmd->op_to_write =
  1472. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  1473. FW_CMD_REQUEST_F |
  1474. FW_CMD_READ_F);
  1475. caps_cmd->cfvalid_to_len16 =
  1476. htonl(FW_CAPS_CONFIG_CMD_CFVALID_F |
  1477. FW_CAPS_CONFIG_CMD_MEMTYPE_CF_V(mtype) |
  1478. FW_CAPS_CONFIG_CMD_MEMADDR64K_CF_V(maddr >> 16) |
  1479. FW_LEN16(*caps_cmd));
  1480. if (csio_mb_issue(hw, mbp)) {
  1481. rv = -EINVAL;
  1482. goto bye;
  1483. }
  1484. rv = csio_mb_fw_retval(mbp);
  1485. /* If the CAPS_CONFIG failed with an ENOENT (for a Firmware
  1486. * Configuration File in FLASH), our last gasp effort is to use the
  1487. * Firmware Configuration File which is embedded in the
  1488. * firmware. A very few early versions of the firmware didn't
  1489. * have one embedded but we can ignore those.
  1490. */
  1491. if (rv == ENOENT) {
  1492. CSIO_INIT_MBP(mbp, caps_cmd, CSIO_MB_DEFAULT_TMO, hw, NULL, 1);
  1493. caps_cmd->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  1494. FW_CMD_REQUEST_F |
  1495. FW_CMD_READ_F);
  1496. caps_cmd->cfvalid_to_len16 = htonl(FW_LEN16(*caps_cmd));
  1497. if (csio_mb_issue(hw, mbp)) {
  1498. rv = -EINVAL;
  1499. goto bye;
  1500. }
  1501. rv = csio_mb_fw_retval(mbp);
  1502. config_name = "Firmware Default";
  1503. }
  1504. if (rv != FW_SUCCESS)
  1505. goto bye;
  1506. finiver = ntohl(caps_cmd->finiver);
  1507. finicsum = ntohl(caps_cmd->finicsum);
  1508. cfcsum = ntohl(caps_cmd->cfcsum);
  1509. /*
  1510. * And now tell the firmware to use the configuration we just loaded.
  1511. */
  1512. caps_cmd->op_to_write =
  1513. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  1514. FW_CMD_REQUEST_F |
  1515. FW_CMD_WRITE_F);
  1516. caps_cmd->cfvalid_to_len16 = htonl(FW_LEN16(*caps_cmd));
  1517. if (csio_mb_issue(hw, mbp)) {
  1518. rv = -EINVAL;
  1519. goto bye;
  1520. }
  1521. rv = csio_mb_fw_retval(mbp);
  1522. if (rv != FW_SUCCESS) {
  1523. csio_dbg(hw, "FW_CAPS_CONFIG_CMD returned %d!\n", rv);
  1524. goto bye;
  1525. }
  1526. if (finicsum != cfcsum) {
  1527. csio_warn(hw,
  1528. "Config File checksum mismatch: csum=%#x, computed=%#x\n",
  1529. finicsum, cfcsum);
  1530. }
  1531. /* Validate device capabilities */
  1532. rv = csio_hw_validate_caps(hw, mbp);
  1533. if (rv != 0)
  1534. goto bye;
  1535. mempool_free(mbp, hw->mb_mempool);
  1536. mbp = NULL;
  1537. /*
  1538. * Note that we're operating with parameters
  1539. * not supplied by the driver, rather than from hard-wired
  1540. * initialization constants buried in the driver.
  1541. */
  1542. hw->flags |= CSIO_HWF_USING_SOFT_PARAMS;
  1543. /* device parameters */
  1544. rv = csio_get_device_params(hw);
  1545. if (rv != 0)
  1546. goto bye;
  1547. /* Configure SGE */
  1548. csio_wr_sge_init(hw);
  1549. /*
  1550. * And finally tell the firmware to initialize itself using the
  1551. * parameters from the Configuration File.
  1552. */
  1553. /* Post event to notify completion of configuration */
  1554. csio_post_event(&hw->sm, CSIO_HWE_INIT);
  1555. csio_info(hw, "Successfully configure using Firmware "
  1556. "Configuration File %s, version %#x, computed checksum %#x\n",
  1557. config_name, finiver, cfcsum);
  1558. return 0;
  1559. /*
  1560. * Something bad happened. Return the error ...
  1561. */
  1562. bye:
  1563. if (mbp)
  1564. mempool_free(mbp, hw->mb_mempool);
  1565. hw->flags &= ~CSIO_HWF_USING_SOFT_PARAMS;
  1566. csio_warn(hw, "Configuration file error %d\n", rv);
  1567. return rv;
  1568. }
  1569. /* Is the given firmware API compatible with the one the driver was compiled
  1570. * with?
  1571. */
  1572. static int fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
  1573. {
  1574. /* short circuit if it's the exact same firmware version */
  1575. if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
  1576. return 1;
  1577. #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
  1578. if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
  1579. SAME_INTF(ri) && SAME_INTF(iscsi) && SAME_INTF(fcoe))
  1580. return 1;
  1581. #undef SAME_INTF
  1582. return 0;
  1583. }
  1584. /* The firmware in the filesystem is usable, but should it be installed?
  1585. * This routine explains itself in detail if it indicates the filesystem
  1586. * firmware should be installed.
  1587. */
  1588. static int csio_should_install_fs_fw(struct csio_hw *hw, int card_fw_usable,
  1589. int k, int c)
  1590. {
  1591. const char *reason;
  1592. if (!card_fw_usable) {
  1593. reason = "incompatible or unusable";
  1594. goto install;
  1595. }
  1596. if (k > c) {
  1597. reason = "older than the version supported with this driver";
  1598. goto install;
  1599. }
  1600. return 0;
  1601. install:
  1602. csio_err(hw, "firmware on card (%u.%u.%u.%u) is %s, "
  1603. "installing firmware %u.%u.%u.%u on card.\n",
  1604. FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
  1605. FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c), reason,
  1606. FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
  1607. FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
  1608. return 1;
  1609. }
  1610. static struct fw_info fw_info_array[] = {
  1611. {
  1612. .chip = CHELSIO_T5,
  1613. .fs_name = FW_CFG_NAME_T5,
  1614. .fw_mod_name = FW_FNAME_T5,
  1615. .fw_hdr = {
  1616. .chip = FW_HDR_CHIP_T5,
  1617. .fw_ver = __cpu_to_be32(FW_VERSION(T5)),
  1618. .intfver_nic = FW_INTFVER(T5, NIC),
  1619. .intfver_vnic = FW_INTFVER(T5, VNIC),
  1620. .intfver_ri = FW_INTFVER(T5, RI),
  1621. .intfver_iscsi = FW_INTFVER(T5, ISCSI),
  1622. .intfver_fcoe = FW_INTFVER(T5, FCOE),
  1623. },
  1624. }
  1625. };
  1626. static struct fw_info *find_fw_info(int chip)
  1627. {
  1628. int i;
  1629. for (i = 0; i < ARRAY_SIZE(fw_info_array); i++) {
  1630. if (fw_info_array[i].chip == chip)
  1631. return &fw_info_array[i];
  1632. }
  1633. return NULL;
  1634. }
  1635. static int csio_hw_prep_fw(struct csio_hw *hw, struct fw_info *fw_info,
  1636. const u8 *fw_data, unsigned int fw_size,
  1637. struct fw_hdr *card_fw, enum csio_dev_state state,
  1638. int *reset)
  1639. {
  1640. int ret, card_fw_usable, fs_fw_usable;
  1641. const struct fw_hdr *fs_fw;
  1642. const struct fw_hdr *drv_fw;
  1643. drv_fw = &fw_info->fw_hdr;
  1644. /* Read the header of the firmware on the card */
  1645. ret = csio_hw_read_flash(hw, FLASH_FW_START,
  1646. sizeof(*card_fw) / sizeof(uint32_t),
  1647. (uint32_t *)card_fw, 1);
  1648. if (ret == 0) {
  1649. card_fw_usable = fw_compatible(drv_fw, (const void *)card_fw);
  1650. } else {
  1651. csio_err(hw,
  1652. "Unable to read card's firmware header: %d\n", ret);
  1653. card_fw_usable = 0;
  1654. }
  1655. if (fw_data != NULL) {
  1656. fs_fw = (const void *)fw_data;
  1657. fs_fw_usable = fw_compatible(drv_fw, fs_fw);
  1658. } else {
  1659. fs_fw = NULL;
  1660. fs_fw_usable = 0;
  1661. }
  1662. if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
  1663. (!fs_fw_usable || fs_fw->fw_ver == drv_fw->fw_ver)) {
  1664. /* Common case: the firmware on the card is an exact match and
  1665. * the filesystem one is an exact match too, or the filesystem
  1666. * one is absent/incompatible.
  1667. */
  1668. } else if (fs_fw_usable && state == CSIO_DEV_STATE_UNINIT &&
  1669. csio_should_install_fs_fw(hw, card_fw_usable,
  1670. be32_to_cpu(fs_fw->fw_ver),
  1671. be32_to_cpu(card_fw->fw_ver))) {
  1672. ret = csio_hw_fw_upgrade(hw, hw->pfn, fw_data,
  1673. fw_size, 0);
  1674. if (ret != 0) {
  1675. csio_err(hw,
  1676. "failed to install firmware: %d\n", ret);
  1677. goto bye;
  1678. }
  1679. /* Installed successfully, update the cached header too. */
  1680. memcpy(card_fw, fs_fw, sizeof(*card_fw));
  1681. card_fw_usable = 1;
  1682. *reset = 0; /* already reset as part of load_fw */
  1683. }
  1684. if (!card_fw_usable) {
  1685. uint32_t d, c, k;
  1686. d = be32_to_cpu(drv_fw->fw_ver);
  1687. c = be32_to_cpu(card_fw->fw_ver);
  1688. k = fs_fw ? be32_to_cpu(fs_fw->fw_ver) : 0;
  1689. csio_err(hw, "Cannot find a usable firmware: "
  1690. "chip state %d, "
  1691. "driver compiled with %d.%d.%d.%d, "
  1692. "card has %d.%d.%d.%d, filesystem has %d.%d.%d.%d\n",
  1693. state,
  1694. FW_HDR_FW_VER_MAJOR_G(d), FW_HDR_FW_VER_MINOR_G(d),
  1695. FW_HDR_FW_VER_MICRO_G(d), FW_HDR_FW_VER_BUILD_G(d),
  1696. FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
  1697. FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c),
  1698. FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
  1699. FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
  1700. ret = EINVAL;
  1701. goto bye;
  1702. }
  1703. /* We're using whatever's on the card and it's known to be good. */
  1704. hw->fwrev = be32_to_cpu(card_fw->fw_ver);
  1705. hw->tp_vers = be32_to_cpu(card_fw->tp_microcode_ver);
  1706. bye:
  1707. return ret;
  1708. }
  1709. /*
  1710. * Returns -EINVAL if attempts to flash the firmware failed
  1711. * else returns 0,
  1712. * if flashing was not attempted because the card had the
  1713. * latest firmware ECANCELED is returned
  1714. */
  1715. static int
  1716. csio_hw_flash_fw(struct csio_hw *hw, int *reset)
  1717. {
  1718. int ret = -ECANCELED;
  1719. const struct firmware *fw;
  1720. struct fw_info *fw_info;
  1721. struct fw_hdr *card_fw;
  1722. struct pci_dev *pci_dev = hw->pdev;
  1723. struct device *dev = &pci_dev->dev ;
  1724. const u8 *fw_data = NULL;
  1725. unsigned int fw_size = 0;
  1726. /* This is the firmware whose headers the driver was compiled
  1727. * against
  1728. */
  1729. fw_info = find_fw_info(CHELSIO_CHIP_VERSION(hw->chip_id));
  1730. if (fw_info == NULL) {
  1731. csio_err(hw,
  1732. "unable to get firmware info for chip %d.\n",
  1733. CHELSIO_CHIP_VERSION(hw->chip_id));
  1734. return -EINVAL;
  1735. }
  1736. if (request_firmware(&fw, FW_FNAME_T5, dev) < 0) {
  1737. csio_err(hw, "could not find firmware image %s, err: %d\n",
  1738. FW_FNAME_T5, ret);
  1739. } else {
  1740. fw_data = fw->data;
  1741. fw_size = fw->size;
  1742. }
  1743. /* allocate memory to read the header of the firmware on the
  1744. * card
  1745. */
  1746. card_fw = kmalloc(sizeof(*card_fw), GFP_KERNEL);
  1747. /* upgrade FW logic */
  1748. ret = csio_hw_prep_fw(hw, fw_info, fw_data, fw_size, card_fw,
  1749. hw->fw_state, reset);
  1750. /* Cleaning up */
  1751. if (fw != NULL)
  1752. release_firmware(fw);
  1753. kfree(card_fw);
  1754. return ret;
  1755. }
  1756. /*
  1757. * csio_hw_configure - Configure HW
  1758. * @hw - HW module
  1759. *
  1760. */
  1761. static void
  1762. csio_hw_configure(struct csio_hw *hw)
  1763. {
  1764. int reset = 1;
  1765. int rv;
  1766. u32 param[1];
  1767. rv = csio_hw_dev_ready(hw);
  1768. if (rv != 0) {
  1769. CSIO_INC_STATS(hw, n_err_fatal);
  1770. csio_post_event(&hw->sm, CSIO_HWE_FATAL);
  1771. goto out;
  1772. }
  1773. /* HW version */
  1774. hw->chip_ver = (char)csio_rd_reg32(hw, PL_REV_A);
  1775. /* Needed for FW download */
  1776. rv = csio_hw_get_flash_params(hw);
  1777. if (rv != 0) {
  1778. csio_err(hw, "Failed to get serial flash params rv:%d\n", rv);
  1779. csio_post_event(&hw->sm, CSIO_HWE_FATAL);
  1780. goto out;
  1781. }
  1782. /* Set PCIe completion timeout to 4 seconds */
  1783. if (pci_is_pcie(hw->pdev))
  1784. pcie_capability_clear_and_set_word(hw->pdev, PCI_EXP_DEVCTL2,
  1785. PCI_EXP_DEVCTL2_COMP_TIMEOUT, 0xd);
  1786. hw->chip_ops->chip_set_mem_win(hw, MEMWIN_CSIOSTOR);
  1787. rv = csio_hw_get_fw_version(hw, &hw->fwrev);
  1788. if (rv != 0)
  1789. goto out;
  1790. csio_hw_print_fw_version(hw, "Firmware revision");
  1791. rv = csio_do_hello(hw, &hw->fw_state);
  1792. if (rv != 0) {
  1793. CSIO_INC_STATS(hw, n_err_fatal);
  1794. csio_post_event(&hw->sm, CSIO_HWE_FATAL);
  1795. goto out;
  1796. }
  1797. /* Read vpd */
  1798. rv = csio_hw_get_vpd_params(hw, &hw->vpd);
  1799. if (rv != 0)
  1800. goto out;
  1801. csio_hw_get_fw_version(hw, &hw->fwrev);
  1802. csio_hw_get_tp_version(hw, &hw->tp_vers);
  1803. if (csio_is_hw_master(hw) && hw->fw_state != CSIO_DEV_STATE_INIT) {
  1804. /* Do firmware update */
  1805. spin_unlock_irq(&hw->lock);
  1806. rv = csio_hw_flash_fw(hw, &reset);
  1807. spin_lock_irq(&hw->lock);
  1808. if (rv != 0)
  1809. goto out;
  1810. /* If the firmware doesn't support Configuration Files,
  1811. * return an error.
  1812. */
  1813. rv = csio_hw_check_fwconfig(hw, param);
  1814. if (rv != 0) {
  1815. csio_info(hw, "Firmware doesn't support "
  1816. "Firmware Configuration files\n");
  1817. goto out;
  1818. }
  1819. /* The firmware provides us with a memory buffer where we can
  1820. * load a Configuration File from the host if we want to
  1821. * override the Configuration File in flash.
  1822. */
  1823. rv = csio_hw_use_fwconfig(hw, reset, param);
  1824. if (rv == -ENOENT) {
  1825. csio_info(hw, "Could not initialize "
  1826. "adapter, error%d\n", rv);
  1827. goto out;
  1828. }
  1829. if (rv != 0) {
  1830. csio_info(hw, "Could not initialize "
  1831. "adapter, error%d\n", rv);
  1832. goto out;
  1833. }
  1834. } else {
  1835. if (hw->fw_state == CSIO_DEV_STATE_INIT) {
  1836. hw->flags |= CSIO_HWF_USING_SOFT_PARAMS;
  1837. /* device parameters */
  1838. rv = csio_get_device_params(hw);
  1839. if (rv != 0)
  1840. goto out;
  1841. /* Get device capabilities */
  1842. rv = csio_config_device_caps(hw);
  1843. if (rv != 0)
  1844. goto out;
  1845. /* Configure SGE */
  1846. csio_wr_sge_init(hw);
  1847. /* Post event to notify completion of configuration */
  1848. csio_post_event(&hw->sm, CSIO_HWE_INIT);
  1849. goto out;
  1850. }
  1851. } /* if not master */
  1852. out:
  1853. return;
  1854. }
  1855. /*
  1856. * csio_hw_initialize - Initialize HW
  1857. * @hw - HW module
  1858. *
  1859. */
  1860. static void
  1861. csio_hw_initialize(struct csio_hw *hw)
  1862. {
  1863. struct csio_mb *mbp;
  1864. enum fw_retval retval;
  1865. int rv;
  1866. int i;
  1867. if (csio_is_hw_master(hw) && hw->fw_state != CSIO_DEV_STATE_INIT) {
  1868. mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
  1869. if (!mbp)
  1870. goto out;
  1871. csio_mb_initialize(hw, mbp, CSIO_MB_DEFAULT_TMO, NULL);
  1872. if (csio_mb_issue(hw, mbp)) {
  1873. csio_err(hw, "Issue of FW_INITIALIZE_CMD failed!\n");
  1874. goto free_and_out;
  1875. }
  1876. retval = csio_mb_fw_retval(mbp);
  1877. if (retval != FW_SUCCESS) {
  1878. csio_err(hw, "FW_INITIALIZE_CMD returned 0x%x!\n",
  1879. retval);
  1880. goto free_and_out;
  1881. }
  1882. mempool_free(mbp, hw->mb_mempool);
  1883. }
  1884. rv = csio_get_fcoe_resinfo(hw);
  1885. if (rv != 0) {
  1886. csio_err(hw, "Failed to read fcoe resource info: %d\n", rv);
  1887. goto out;
  1888. }
  1889. spin_unlock_irq(&hw->lock);
  1890. rv = csio_config_queues(hw);
  1891. spin_lock_irq(&hw->lock);
  1892. if (rv != 0) {
  1893. csio_err(hw, "Config of queues failed!: %d\n", rv);
  1894. goto out;
  1895. }
  1896. for (i = 0; i < hw->num_pports; i++)
  1897. hw->pport[i].mod_type = FW_PORT_MOD_TYPE_NA;
  1898. if (csio_is_hw_master(hw) && hw->fw_state != CSIO_DEV_STATE_INIT) {
  1899. rv = csio_enable_ports(hw);
  1900. if (rv != 0) {
  1901. csio_err(hw, "Failed to enable ports: %d\n", rv);
  1902. goto out;
  1903. }
  1904. }
  1905. csio_post_event(&hw->sm, CSIO_HWE_INIT_DONE);
  1906. return;
  1907. free_and_out:
  1908. mempool_free(mbp, hw->mb_mempool);
  1909. out:
  1910. return;
  1911. }
  1912. #define PF_INTR_MASK (PFSW_F | PFCIM_F)
  1913. /*
  1914. * csio_hw_intr_enable - Enable HW interrupts
  1915. * @hw: Pointer to HW module.
  1916. *
  1917. * Enable interrupts in HW registers.
  1918. */
  1919. static void
  1920. csio_hw_intr_enable(struct csio_hw *hw)
  1921. {
  1922. uint16_t vec = (uint16_t)csio_get_mb_intr_idx(csio_hw_to_mbm(hw));
  1923. uint32_t pf = SOURCEPF_G(csio_rd_reg32(hw, PL_WHOAMI_A));
  1924. uint32_t pl = csio_rd_reg32(hw, PL_INT_ENABLE_A);
  1925. /*
  1926. * Set aivec for MSI/MSIX. PCIE_PF_CFG.INTXType is set up
  1927. * by FW, so do nothing for INTX.
  1928. */
  1929. if (hw->intr_mode == CSIO_IM_MSIX)
  1930. csio_set_reg_field(hw, MYPF_REG(PCIE_PF_CFG_A),
  1931. AIVEC_V(AIVEC_M), vec);
  1932. else if (hw->intr_mode == CSIO_IM_MSI)
  1933. csio_set_reg_field(hw, MYPF_REG(PCIE_PF_CFG_A),
  1934. AIVEC_V(AIVEC_M), 0);
  1935. csio_wr_reg32(hw, PF_INTR_MASK, MYPF_REG(PL_PF_INT_ENABLE_A));
  1936. /* Turn on MB interrupts - this will internally flush PIO as well */
  1937. csio_mb_intr_enable(hw);
  1938. /* These are common registers - only a master can modify them */
  1939. if (csio_is_hw_master(hw)) {
  1940. /*
  1941. * Disable the Serial FLASH interrupt, if enabled!
  1942. */
  1943. pl &= (~SF_F);
  1944. csio_wr_reg32(hw, pl, PL_INT_ENABLE_A);
  1945. csio_wr_reg32(hw, ERR_CPL_EXCEED_IQE_SIZE_F |
  1946. EGRESS_SIZE_ERR_F | ERR_INVALID_CIDX_INC_F |
  1947. ERR_CPL_OPCODE_0_F | ERR_DROPPED_DB_F |
  1948. ERR_DATA_CPL_ON_HIGH_QID1_F |
  1949. ERR_DATA_CPL_ON_HIGH_QID0_F | ERR_BAD_DB_PIDX3_F |
  1950. ERR_BAD_DB_PIDX2_F | ERR_BAD_DB_PIDX1_F |
  1951. ERR_BAD_DB_PIDX0_F | ERR_ING_CTXT_PRIO_F |
  1952. ERR_EGR_CTXT_PRIO_F | INGRESS_SIZE_ERR_F,
  1953. SGE_INT_ENABLE3_A);
  1954. csio_set_reg_field(hw, PL_INT_MAP0_A, 0, 1 << pf);
  1955. }
  1956. hw->flags |= CSIO_HWF_HW_INTR_ENABLED;
  1957. }
  1958. /*
  1959. * csio_hw_intr_disable - Disable HW interrupts
  1960. * @hw: Pointer to HW module.
  1961. *
  1962. * Turn off Mailbox and PCI_PF_CFG interrupts.
  1963. */
  1964. void
  1965. csio_hw_intr_disable(struct csio_hw *hw)
  1966. {
  1967. uint32_t pf = SOURCEPF_G(csio_rd_reg32(hw, PL_WHOAMI_A));
  1968. if (!(hw->flags & CSIO_HWF_HW_INTR_ENABLED))
  1969. return;
  1970. hw->flags &= ~CSIO_HWF_HW_INTR_ENABLED;
  1971. csio_wr_reg32(hw, 0, MYPF_REG(PL_PF_INT_ENABLE_A));
  1972. if (csio_is_hw_master(hw))
  1973. csio_set_reg_field(hw, PL_INT_MAP0_A, 1 << pf, 0);
  1974. /* Turn off MB interrupts */
  1975. csio_mb_intr_disable(hw);
  1976. }
  1977. void
  1978. csio_hw_fatal_err(struct csio_hw *hw)
  1979. {
  1980. csio_set_reg_field(hw, SGE_CONTROL_A, GLOBALENABLE_F, 0);
  1981. csio_hw_intr_disable(hw);
  1982. /* Do not reset HW, we may need FW state for debugging */
  1983. csio_fatal(hw, "HW Fatal error encountered!\n");
  1984. }
  1985. /*****************************************************************************/
  1986. /* START: HW SM */
  1987. /*****************************************************************************/
  1988. /*
  1989. * csio_hws_uninit - Uninit state
  1990. * @hw - HW module
  1991. * @evt - Event
  1992. *
  1993. */
  1994. static void
  1995. csio_hws_uninit(struct csio_hw *hw, enum csio_hw_ev evt)
  1996. {
  1997. hw->prev_evt = hw->cur_evt;
  1998. hw->cur_evt = evt;
  1999. CSIO_INC_STATS(hw, n_evt_sm[evt]);
  2000. switch (evt) {
  2001. case CSIO_HWE_CFG:
  2002. csio_set_state(&hw->sm, csio_hws_configuring);
  2003. csio_hw_configure(hw);
  2004. break;
  2005. default:
  2006. CSIO_INC_STATS(hw, n_evt_unexp);
  2007. break;
  2008. }
  2009. }
  2010. /*
  2011. * csio_hws_configuring - Configuring state
  2012. * @hw - HW module
  2013. * @evt - Event
  2014. *
  2015. */
  2016. static void
  2017. csio_hws_configuring(struct csio_hw *hw, enum csio_hw_ev evt)
  2018. {
  2019. hw->prev_evt = hw->cur_evt;
  2020. hw->cur_evt = evt;
  2021. CSIO_INC_STATS(hw, n_evt_sm[evt]);
  2022. switch (evt) {
  2023. case CSIO_HWE_INIT:
  2024. csio_set_state(&hw->sm, csio_hws_initializing);
  2025. csio_hw_initialize(hw);
  2026. break;
  2027. case CSIO_HWE_INIT_DONE:
  2028. csio_set_state(&hw->sm, csio_hws_ready);
  2029. /* Fan out event to all lnode SMs */
  2030. csio_notify_lnodes(hw, CSIO_LN_NOTIFY_HWREADY);
  2031. break;
  2032. case CSIO_HWE_FATAL:
  2033. csio_set_state(&hw->sm, csio_hws_uninit);
  2034. break;
  2035. case CSIO_HWE_PCI_REMOVE:
  2036. csio_do_bye(hw);
  2037. break;
  2038. default:
  2039. CSIO_INC_STATS(hw, n_evt_unexp);
  2040. break;
  2041. }
  2042. }
  2043. /*
  2044. * csio_hws_initializing - Initialiazing state
  2045. * @hw - HW module
  2046. * @evt - Event
  2047. *
  2048. */
  2049. static void
  2050. csio_hws_initializing(struct csio_hw *hw, enum csio_hw_ev evt)
  2051. {
  2052. hw->prev_evt = hw->cur_evt;
  2053. hw->cur_evt = evt;
  2054. CSIO_INC_STATS(hw, n_evt_sm[evt]);
  2055. switch (evt) {
  2056. case CSIO_HWE_INIT_DONE:
  2057. csio_set_state(&hw->sm, csio_hws_ready);
  2058. /* Fan out event to all lnode SMs */
  2059. csio_notify_lnodes(hw, CSIO_LN_NOTIFY_HWREADY);
  2060. /* Enable interrupts */
  2061. csio_hw_intr_enable(hw);
  2062. break;
  2063. case CSIO_HWE_FATAL:
  2064. csio_set_state(&hw->sm, csio_hws_uninit);
  2065. break;
  2066. case CSIO_HWE_PCI_REMOVE:
  2067. csio_do_bye(hw);
  2068. break;
  2069. default:
  2070. CSIO_INC_STATS(hw, n_evt_unexp);
  2071. break;
  2072. }
  2073. }
  2074. /*
  2075. * csio_hws_ready - Ready state
  2076. * @hw - HW module
  2077. * @evt - Event
  2078. *
  2079. */
  2080. static void
  2081. csio_hws_ready(struct csio_hw *hw, enum csio_hw_ev evt)
  2082. {
  2083. /* Remember the event */
  2084. hw->evtflag = evt;
  2085. hw->prev_evt = hw->cur_evt;
  2086. hw->cur_evt = evt;
  2087. CSIO_INC_STATS(hw, n_evt_sm[evt]);
  2088. switch (evt) {
  2089. case CSIO_HWE_HBA_RESET:
  2090. case CSIO_HWE_FW_DLOAD:
  2091. case CSIO_HWE_SUSPEND:
  2092. case CSIO_HWE_PCI_REMOVE:
  2093. case CSIO_HWE_PCIERR_DETECTED:
  2094. csio_set_state(&hw->sm, csio_hws_quiescing);
  2095. /* cleanup all outstanding cmds */
  2096. if (evt == CSIO_HWE_HBA_RESET ||
  2097. evt == CSIO_HWE_PCIERR_DETECTED)
  2098. csio_scsim_cleanup_io(csio_hw_to_scsim(hw), false);
  2099. else
  2100. csio_scsim_cleanup_io(csio_hw_to_scsim(hw), true);
  2101. csio_hw_intr_disable(hw);
  2102. csio_hw_mbm_cleanup(hw);
  2103. csio_evtq_stop(hw);
  2104. csio_notify_lnodes(hw, CSIO_LN_NOTIFY_HWSTOP);
  2105. csio_evtq_flush(hw);
  2106. csio_mgmtm_cleanup(csio_hw_to_mgmtm(hw));
  2107. csio_post_event(&hw->sm, CSIO_HWE_QUIESCED);
  2108. break;
  2109. case CSIO_HWE_FATAL:
  2110. csio_set_state(&hw->sm, csio_hws_uninit);
  2111. break;
  2112. default:
  2113. CSIO_INC_STATS(hw, n_evt_unexp);
  2114. break;
  2115. }
  2116. }
  2117. /*
  2118. * csio_hws_quiescing - Quiescing state
  2119. * @hw - HW module
  2120. * @evt - Event
  2121. *
  2122. */
  2123. static void
  2124. csio_hws_quiescing(struct csio_hw *hw, enum csio_hw_ev evt)
  2125. {
  2126. hw->prev_evt = hw->cur_evt;
  2127. hw->cur_evt = evt;
  2128. CSIO_INC_STATS(hw, n_evt_sm[evt]);
  2129. switch (evt) {
  2130. case CSIO_HWE_QUIESCED:
  2131. switch (hw->evtflag) {
  2132. case CSIO_HWE_FW_DLOAD:
  2133. csio_set_state(&hw->sm, csio_hws_resetting);
  2134. /* Download firmware */
  2135. /* Fall through */
  2136. case CSIO_HWE_HBA_RESET:
  2137. csio_set_state(&hw->sm, csio_hws_resetting);
  2138. /* Start reset of the HBA */
  2139. csio_notify_lnodes(hw, CSIO_LN_NOTIFY_HWRESET);
  2140. csio_wr_destroy_queues(hw, false);
  2141. csio_do_reset(hw, false);
  2142. csio_post_event(&hw->sm, CSIO_HWE_HBA_RESET_DONE);
  2143. break;
  2144. case CSIO_HWE_PCI_REMOVE:
  2145. csio_set_state(&hw->sm, csio_hws_removing);
  2146. csio_notify_lnodes(hw, CSIO_LN_NOTIFY_HWREMOVE);
  2147. csio_wr_destroy_queues(hw, true);
  2148. /* Now send the bye command */
  2149. csio_do_bye(hw);
  2150. break;
  2151. case CSIO_HWE_SUSPEND:
  2152. csio_set_state(&hw->sm, csio_hws_quiesced);
  2153. break;
  2154. case CSIO_HWE_PCIERR_DETECTED:
  2155. csio_set_state(&hw->sm, csio_hws_pcierr);
  2156. csio_wr_destroy_queues(hw, false);
  2157. break;
  2158. default:
  2159. CSIO_INC_STATS(hw, n_evt_unexp);
  2160. break;
  2161. }
  2162. break;
  2163. default:
  2164. CSIO_INC_STATS(hw, n_evt_unexp);
  2165. break;
  2166. }
  2167. }
  2168. /*
  2169. * csio_hws_quiesced - Quiesced state
  2170. * @hw - HW module
  2171. * @evt - Event
  2172. *
  2173. */
  2174. static void
  2175. csio_hws_quiesced(struct csio_hw *hw, enum csio_hw_ev evt)
  2176. {
  2177. hw->prev_evt = hw->cur_evt;
  2178. hw->cur_evt = evt;
  2179. CSIO_INC_STATS(hw, n_evt_sm[evt]);
  2180. switch (evt) {
  2181. case CSIO_HWE_RESUME:
  2182. csio_set_state(&hw->sm, csio_hws_configuring);
  2183. csio_hw_configure(hw);
  2184. break;
  2185. default:
  2186. CSIO_INC_STATS(hw, n_evt_unexp);
  2187. break;
  2188. }
  2189. }
  2190. /*
  2191. * csio_hws_resetting - HW Resetting state
  2192. * @hw - HW module
  2193. * @evt - Event
  2194. *
  2195. */
  2196. static void
  2197. csio_hws_resetting(struct csio_hw *hw, enum csio_hw_ev evt)
  2198. {
  2199. hw->prev_evt = hw->cur_evt;
  2200. hw->cur_evt = evt;
  2201. CSIO_INC_STATS(hw, n_evt_sm[evt]);
  2202. switch (evt) {
  2203. case CSIO_HWE_HBA_RESET_DONE:
  2204. csio_evtq_start(hw);
  2205. csio_set_state(&hw->sm, csio_hws_configuring);
  2206. csio_hw_configure(hw);
  2207. break;
  2208. default:
  2209. CSIO_INC_STATS(hw, n_evt_unexp);
  2210. break;
  2211. }
  2212. }
  2213. /*
  2214. * csio_hws_removing - PCI Hotplug removing state
  2215. * @hw - HW module
  2216. * @evt - Event
  2217. *
  2218. */
  2219. static void
  2220. csio_hws_removing(struct csio_hw *hw, enum csio_hw_ev evt)
  2221. {
  2222. hw->prev_evt = hw->cur_evt;
  2223. hw->cur_evt = evt;
  2224. CSIO_INC_STATS(hw, n_evt_sm[evt]);
  2225. switch (evt) {
  2226. case CSIO_HWE_HBA_RESET:
  2227. if (!csio_is_hw_master(hw))
  2228. break;
  2229. /*
  2230. * The BYE should have alerady been issued, so we cant
  2231. * use the mailbox interface. Hence we use the PL_RST
  2232. * register directly.
  2233. */
  2234. csio_err(hw, "Resetting HW and waiting 2 seconds...\n");
  2235. csio_wr_reg32(hw, PIORSTMODE_F | PIORST_F, PL_RST_A);
  2236. mdelay(2000);
  2237. break;
  2238. /* Should never receive any new events */
  2239. default:
  2240. CSIO_INC_STATS(hw, n_evt_unexp);
  2241. break;
  2242. }
  2243. }
  2244. /*
  2245. * csio_hws_pcierr - PCI Error state
  2246. * @hw - HW module
  2247. * @evt - Event
  2248. *
  2249. */
  2250. static void
  2251. csio_hws_pcierr(struct csio_hw *hw, enum csio_hw_ev evt)
  2252. {
  2253. hw->prev_evt = hw->cur_evt;
  2254. hw->cur_evt = evt;
  2255. CSIO_INC_STATS(hw, n_evt_sm[evt]);
  2256. switch (evt) {
  2257. case CSIO_HWE_PCIERR_SLOT_RESET:
  2258. csio_evtq_start(hw);
  2259. csio_set_state(&hw->sm, csio_hws_configuring);
  2260. csio_hw_configure(hw);
  2261. break;
  2262. default:
  2263. CSIO_INC_STATS(hw, n_evt_unexp);
  2264. break;
  2265. }
  2266. }
  2267. /*****************************************************************************/
  2268. /* END: HW SM */
  2269. /*****************************************************************************/
  2270. /*
  2271. * csio_handle_intr_status - table driven interrupt handler
  2272. * @hw: HW instance
  2273. * @reg: the interrupt status register to process
  2274. * @acts: table of interrupt actions
  2275. *
  2276. * A table driven interrupt handler that applies a set of masks to an
  2277. * interrupt status word and performs the corresponding actions if the
  2278. * interrupts described by the mask have occured. The actions include
  2279. * optionally emitting a warning or alert message. The table is terminated
  2280. * by an entry specifying mask 0. Returns the number of fatal interrupt
  2281. * conditions.
  2282. */
  2283. int
  2284. csio_handle_intr_status(struct csio_hw *hw, unsigned int reg,
  2285. const struct intr_info *acts)
  2286. {
  2287. int fatal = 0;
  2288. unsigned int mask = 0;
  2289. unsigned int status = csio_rd_reg32(hw, reg);
  2290. for ( ; acts->mask; ++acts) {
  2291. if (!(status & acts->mask))
  2292. continue;
  2293. if (acts->fatal) {
  2294. fatal++;
  2295. csio_fatal(hw, "Fatal %s (0x%x)\n",
  2296. acts->msg, status & acts->mask);
  2297. } else if (acts->msg)
  2298. csio_info(hw, "%s (0x%x)\n",
  2299. acts->msg, status & acts->mask);
  2300. mask |= acts->mask;
  2301. }
  2302. status &= mask;
  2303. if (status) /* clear processed interrupts */
  2304. csio_wr_reg32(hw, status, reg);
  2305. return fatal;
  2306. }
  2307. /*
  2308. * TP interrupt handler.
  2309. */
  2310. static void csio_tp_intr_handler(struct csio_hw *hw)
  2311. {
  2312. static struct intr_info tp_intr_info[] = {
  2313. { 0x3fffffff, "TP parity error", -1, 1 },
  2314. { FLMTXFLSTEMPTY_F, "TP out of Tx pages", -1, 1 },
  2315. { 0, NULL, 0, 0 }
  2316. };
  2317. if (csio_handle_intr_status(hw, TP_INT_CAUSE_A, tp_intr_info))
  2318. csio_hw_fatal_err(hw);
  2319. }
  2320. /*
  2321. * SGE interrupt handler.
  2322. */
  2323. static void csio_sge_intr_handler(struct csio_hw *hw)
  2324. {
  2325. uint64_t v;
  2326. static struct intr_info sge_intr_info[] = {
  2327. { ERR_CPL_EXCEED_IQE_SIZE_F,
  2328. "SGE received CPL exceeding IQE size", -1, 1 },
  2329. { ERR_INVALID_CIDX_INC_F,
  2330. "SGE GTS CIDX increment too large", -1, 0 },
  2331. { ERR_CPL_OPCODE_0_F, "SGE received 0-length CPL", -1, 0 },
  2332. { ERR_DROPPED_DB_F, "SGE doorbell dropped", -1, 0 },
  2333. { ERR_DATA_CPL_ON_HIGH_QID1_F | ERR_DATA_CPL_ON_HIGH_QID0_F,
  2334. "SGE IQID > 1023 received CPL for FL", -1, 0 },
  2335. { ERR_BAD_DB_PIDX3_F, "SGE DBP 3 pidx increment too large", -1,
  2336. 0 },
  2337. { ERR_BAD_DB_PIDX2_F, "SGE DBP 2 pidx increment too large", -1,
  2338. 0 },
  2339. { ERR_BAD_DB_PIDX1_F, "SGE DBP 1 pidx increment too large", -1,
  2340. 0 },
  2341. { ERR_BAD_DB_PIDX0_F, "SGE DBP 0 pidx increment too large", -1,
  2342. 0 },
  2343. { ERR_ING_CTXT_PRIO_F,
  2344. "SGE too many priority ingress contexts", -1, 0 },
  2345. { ERR_EGR_CTXT_PRIO_F,
  2346. "SGE too many priority egress contexts", -1, 0 },
  2347. { INGRESS_SIZE_ERR_F, "SGE illegal ingress QID", -1, 0 },
  2348. { EGRESS_SIZE_ERR_F, "SGE illegal egress QID", -1, 0 },
  2349. { 0, NULL, 0, 0 }
  2350. };
  2351. v = (uint64_t)csio_rd_reg32(hw, SGE_INT_CAUSE1_A) |
  2352. ((uint64_t)csio_rd_reg32(hw, SGE_INT_CAUSE2_A) << 32);
  2353. if (v) {
  2354. csio_fatal(hw, "SGE parity error (%#llx)\n",
  2355. (unsigned long long)v);
  2356. csio_wr_reg32(hw, (uint32_t)(v & 0xFFFFFFFF),
  2357. SGE_INT_CAUSE1_A);
  2358. csio_wr_reg32(hw, (uint32_t)(v >> 32), SGE_INT_CAUSE2_A);
  2359. }
  2360. v |= csio_handle_intr_status(hw, SGE_INT_CAUSE3_A, sge_intr_info);
  2361. if (csio_handle_intr_status(hw, SGE_INT_CAUSE3_A, sge_intr_info) ||
  2362. v != 0)
  2363. csio_hw_fatal_err(hw);
  2364. }
  2365. #define CIM_OBQ_INTR (OBQULP0PARERR_F | OBQULP1PARERR_F | OBQULP2PARERR_F |\
  2366. OBQULP3PARERR_F | OBQSGEPARERR_F | OBQNCSIPARERR_F)
  2367. #define CIM_IBQ_INTR (IBQTP0PARERR_F | IBQTP1PARERR_F | IBQULPPARERR_F |\
  2368. IBQSGEHIPARERR_F | IBQSGELOPARERR_F | IBQNCSIPARERR_F)
  2369. /*
  2370. * CIM interrupt handler.
  2371. */
  2372. static void csio_cim_intr_handler(struct csio_hw *hw)
  2373. {
  2374. static struct intr_info cim_intr_info[] = {
  2375. { PREFDROPINT_F, "CIM control register prefetch drop", -1, 1 },
  2376. { CIM_OBQ_INTR, "CIM OBQ parity error", -1, 1 },
  2377. { CIM_IBQ_INTR, "CIM IBQ parity error", -1, 1 },
  2378. { MBUPPARERR_F, "CIM mailbox uP parity error", -1, 1 },
  2379. { MBHOSTPARERR_F, "CIM mailbox host parity error", -1, 1 },
  2380. { TIEQINPARERRINT_F, "CIM TIEQ outgoing parity error", -1, 1 },
  2381. { TIEQOUTPARERRINT_F, "CIM TIEQ incoming parity error", -1, 1 },
  2382. { 0, NULL, 0, 0 }
  2383. };
  2384. static struct intr_info cim_upintr_info[] = {
  2385. { RSVDSPACEINT_F, "CIM reserved space access", -1, 1 },
  2386. { ILLTRANSINT_F, "CIM illegal transaction", -1, 1 },
  2387. { ILLWRINT_F, "CIM illegal write", -1, 1 },
  2388. { ILLRDINT_F, "CIM illegal read", -1, 1 },
  2389. { ILLRDBEINT_F, "CIM illegal read BE", -1, 1 },
  2390. { ILLWRBEINT_F, "CIM illegal write BE", -1, 1 },
  2391. { SGLRDBOOTINT_F, "CIM single read from boot space", -1, 1 },
  2392. { SGLWRBOOTINT_F, "CIM single write to boot space", -1, 1 },
  2393. { BLKWRBOOTINT_F, "CIM block write to boot space", -1, 1 },
  2394. { SGLRDFLASHINT_F, "CIM single read from flash space", -1, 1 },
  2395. { SGLWRFLASHINT_F, "CIM single write to flash space", -1, 1 },
  2396. { BLKWRFLASHINT_F, "CIM block write to flash space", -1, 1 },
  2397. { SGLRDEEPROMINT_F, "CIM single EEPROM read", -1, 1 },
  2398. { SGLWREEPROMINT_F, "CIM single EEPROM write", -1, 1 },
  2399. { BLKRDEEPROMINT_F, "CIM block EEPROM read", -1, 1 },
  2400. { BLKWREEPROMINT_F, "CIM block EEPROM write", -1, 1 },
  2401. { SGLRDCTLINT_F, "CIM single read from CTL space", -1, 1 },
  2402. { SGLWRCTLINT_F, "CIM single write to CTL space", -1, 1 },
  2403. { BLKRDCTLINT_F, "CIM block read from CTL space", -1, 1 },
  2404. { BLKWRCTLINT_F, "CIM block write to CTL space", -1, 1 },
  2405. { SGLRDPLINT_F, "CIM single read from PL space", -1, 1 },
  2406. { SGLWRPLINT_F, "CIM single write to PL space", -1, 1 },
  2407. { BLKRDPLINT_F, "CIM block read from PL space", -1, 1 },
  2408. { BLKWRPLINT_F, "CIM block write to PL space", -1, 1 },
  2409. { REQOVRLOOKUPINT_F, "CIM request FIFO overwrite", -1, 1 },
  2410. { RSPOVRLOOKUPINT_F, "CIM response FIFO overwrite", -1, 1 },
  2411. { TIMEOUTINT_F, "CIM PIF timeout", -1, 1 },
  2412. { TIMEOUTMAINT_F, "CIM PIF MA timeout", -1, 1 },
  2413. { 0, NULL, 0, 0 }
  2414. };
  2415. int fat;
  2416. fat = csio_handle_intr_status(hw, CIM_HOST_INT_CAUSE_A,
  2417. cim_intr_info) +
  2418. csio_handle_intr_status(hw, CIM_HOST_UPACC_INT_CAUSE_A,
  2419. cim_upintr_info);
  2420. if (fat)
  2421. csio_hw_fatal_err(hw);
  2422. }
  2423. /*
  2424. * ULP RX interrupt handler.
  2425. */
  2426. static void csio_ulprx_intr_handler(struct csio_hw *hw)
  2427. {
  2428. static struct intr_info ulprx_intr_info[] = {
  2429. { 0x1800000, "ULPRX context error", -1, 1 },
  2430. { 0x7fffff, "ULPRX parity error", -1, 1 },
  2431. { 0, NULL, 0, 0 }
  2432. };
  2433. if (csio_handle_intr_status(hw, ULP_RX_INT_CAUSE_A, ulprx_intr_info))
  2434. csio_hw_fatal_err(hw);
  2435. }
  2436. /*
  2437. * ULP TX interrupt handler.
  2438. */
  2439. static void csio_ulptx_intr_handler(struct csio_hw *hw)
  2440. {
  2441. static struct intr_info ulptx_intr_info[] = {
  2442. { PBL_BOUND_ERR_CH3_F, "ULPTX channel 3 PBL out of bounds", -1,
  2443. 0 },
  2444. { PBL_BOUND_ERR_CH2_F, "ULPTX channel 2 PBL out of bounds", -1,
  2445. 0 },
  2446. { PBL_BOUND_ERR_CH1_F, "ULPTX channel 1 PBL out of bounds", -1,
  2447. 0 },
  2448. { PBL_BOUND_ERR_CH0_F, "ULPTX channel 0 PBL out of bounds", -1,
  2449. 0 },
  2450. { 0xfffffff, "ULPTX parity error", -1, 1 },
  2451. { 0, NULL, 0, 0 }
  2452. };
  2453. if (csio_handle_intr_status(hw, ULP_TX_INT_CAUSE_A, ulptx_intr_info))
  2454. csio_hw_fatal_err(hw);
  2455. }
  2456. /*
  2457. * PM TX interrupt handler.
  2458. */
  2459. static void csio_pmtx_intr_handler(struct csio_hw *hw)
  2460. {
  2461. static struct intr_info pmtx_intr_info[] = {
  2462. { PCMD_LEN_OVFL0_F, "PMTX channel 0 pcmd too large", -1, 1 },
  2463. { PCMD_LEN_OVFL1_F, "PMTX channel 1 pcmd too large", -1, 1 },
  2464. { PCMD_LEN_OVFL2_F, "PMTX channel 2 pcmd too large", -1, 1 },
  2465. { ZERO_C_CMD_ERROR_F, "PMTX 0-length pcmd", -1, 1 },
  2466. { 0xffffff0, "PMTX framing error", -1, 1 },
  2467. { OESPI_PAR_ERROR_F, "PMTX oespi parity error", -1, 1 },
  2468. { DB_OPTIONS_PAR_ERROR_F, "PMTX db_options parity error", -1,
  2469. 1 },
  2470. { ICSPI_PAR_ERROR_F, "PMTX icspi parity error", -1, 1 },
  2471. { PMTX_C_PCMD_PAR_ERROR_F, "PMTX c_pcmd parity error", -1, 1},
  2472. { 0, NULL, 0, 0 }
  2473. };
  2474. if (csio_handle_intr_status(hw, PM_TX_INT_CAUSE_A, pmtx_intr_info))
  2475. csio_hw_fatal_err(hw);
  2476. }
  2477. /*
  2478. * PM RX interrupt handler.
  2479. */
  2480. static void csio_pmrx_intr_handler(struct csio_hw *hw)
  2481. {
  2482. static struct intr_info pmrx_intr_info[] = {
  2483. { ZERO_E_CMD_ERROR_F, "PMRX 0-length pcmd", -1, 1 },
  2484. { 0x3ffff0, "PMRX framing error", -1, 1 },
  2485. { OCSPI_PAR_ERROR_F, "PMRX ocspi parity error", -1, 1 },
  2486. { DB_OPTIONS_PAR_ERROR_F, "PMRX db_options parity error", -1,
  2487. 1 },
  2488. { IESPI_PAR_ERROR_F, "PMRX iespi parity error", -1, 1 },
  2489. { PMRX_E_PCMD_PAR_ERROR_F, "PMRX e_pcmd parity error", -1, 1},
  2490. { 0, NULL, 0, 0 }
  2491. };
  2492. if (csio_handle_intr_status(hw, PM_RX_INT_CAUSE_A, pmrx_intr_info))
  2493. csio_hw_fatal_err(hw);
  2494. }
  2495. /*
  2496. * CPL switch interrupt handler.
  2497. */
  2498. static void csio_cplsw_intr_handler(struct csio_hw *hw)
  2499. {
  2500. static struct intr_info cplsw_intr_info[] = {
  2501. { CIM_OP_MAP_PERR_F, "CPLSW CIM op_map parity error", -1, 1 },
  2502. { CIM_OVFL_ERROR_F, "CPLSW CIM overflow", -1, 1 },
  2503. { TP_FRAMING_ERROR_F, "CPLSW TP framing error", -1, 1 },
  2504. { SGE_FRAMING_ERROR_F, "CPLSW SGE framing error", -1, 1 },
  2505. { CIM_FRAMING_ERROR_F, "CPLSW CIM framing error", -1, 1 },
  2506. { ZERO_SWITCH_ERROR_F, "CPLSW no-switch error", -1, 1 },
  2507. { 0, NULL, 0, 0 }
  2508. };
  2509. if (csio_handle_intr_status(hw, CPL_INTR_CAUSE_A, cplsw_intr_info))
  2510. csio_hw_fatal_err(hw);
  2511. }
  2512. /*
  2513. * LE interrupt handler.
  2514. */
  2515. static void csio_le_intr_handler(struct csio_hw *hw)
  2516. {
  2517. static struct intr_info le_intr_info[] = {
  2518. { LIPMISS_F, "LE LIP miss", -1, 0 },
  2519. { LIP0_F, "LE 0 LIP error", -1, 0 },
  2520. { PARITYERR_F, "LE parity error", -1, 1 },
  2521. { UNKNOWNCMD_F, "LE unknown command", -1, 1 },
  2522. { REQQPARERR_F, "LE request queue parity error", -1, 1 },
  2523. { 0, NULL, 0, 0 }
  2524. };
  2525. if (csio_handle_intr_status(hw, LE_DB_INT_CAUSE_A, le_intr_info))
  2526. csio_hw_fatal_err(hw);
  2527. }
  2528. /*
  2529. * MPS interrupt handler.
  2530. */
  2531. static void csio_mps_intr_handler(struct csio_hw *hw)
  2532. {
  2533. static struct intr_info mps_rx_intr_info[] = {
  2534. { 0xffffff, "MPS Rx parity error", -1, 1 },
  2535. { 0, NULL, 0, 0 }
  2536. };
  2537. static struct intr_info mps_tx_intr_info[] = {
  2538. { TPFIFO_V(TPFIFO_M), "MPS Tx TP FIFO parity error", -1, 1 },
  2539. { NCSIFIFO_F, "MPS Tx NC-SI FIFO parity error", -1, 1 },
  2540. { TXDATAFIFO_V(TXDATAFIFO_M), "MPS Tx data FIFO parity error",
  2541. -1, 1 },
  2542. { TXDESCFIFO_V(TXDESCFIFO_M), "MPS Tx desc FIFO parity error",
  2543. -1, 1 },
  2544. { BUBBLE_F, "MPS Tx underflow", -1, 1 },
  2545. { SECNTERR_F, "MPS Tx SOP/EOP error", -1, 1 },
  2546. { FRMERR_F, "MPS Tx framing error", -1, 1 },
  2547. { 0, NULL, 0, 0 }
  2548. };
  2549. static struct intr_info mps_trc_intr_info[] = {
  2550. { FILTMEM_V(FILTMEM_M), "MPS TRC filter parity error", -1, 1 },
  2551. { PKTFIFO_V(PKTFIFO_M), "MPS TRC packet FIFO parity error",
  2552. -1, 1 },
  2553. { MISCPERR_F, "MPS TRC misc parity error", -1, 1 },
  2554. { 0, NULL, 0, 0 }
  2555. };
  2556. static struct intr_info mps_stat_sram_intr_info[] = {
  2557. { 0x1fffff, "MPS statistics SRAM parity error", -1, 1 },
  2558. { 0, NULL, 0, 0 }
  2559. };
  2560. static struct intr_info mps_stat_tx_intr_info[] = {
  2561. { 0xfffff, "MPS statistics Tx FIFO parity error", -1, 1 },
  2562. { 0, NULL, 0, 0 }
  2563. };
  2564. static struct intr_info mps_stat_rx_intr_info[] = {
  2565. { 0xffffff, "MPS statistics Rx FIFO parity error", -1, 1 },
  2566. { 0, NULL, 0, 0 }
  2567. };
  2568. static struct intr_info mps_cls_intr_info[] = {
  2569. { MATCHSRAM_F, "MPS match SRAM parity error", -1, 1 },
  2570. { MATCHTCAM_F, "MPS match TCAM parity error", -1, 1 },
  2571. { HASHSRAM_F, "MPS hash SRAM parity error", -1, 1 },
  2572. { 0, NULL, 0, 0 }
  2573. };
  2574. int fat;
  2575. fat = csio_handle_intr_status(hw, MPS_RX_PERR_INT_CAUSE_A,
  2576. mps_rx_intr_info) +
  2577. csio_handle_intr_status(hw, MPS_TX_INT_CAUSE_A,
  2578. mps_tx_intr_info) +
  2579. csio_handle_intr_status(hw, MPS_TRC_INT_CAUSE_A,
  2580. mps_trc_intr_info) +
  2581. csio_handle_intr_status(hw, MPS_STAT_PERR_INT_CAUSE_SRAM_A,
  2582. mps_stat_sram_intr_info) +
  2583. csio_handle_intr_status(hw, MPS_STAT_PERR_INT_CAUSE_TX_FIFO_A,
  2584. mps_stat_tx_intr_info) +
  2585. csio_handle_intr_status(hw, MPS_STAT_PERR_INT_CAUSE_RX_FIFO_A,
  2586. mps_stat_rx_intr_info) +
  2587. csio_handle_intr_status(hw, MPS_CLS_INT_CAUSE_A,
  2588. mps_cls_intr_info);
  2589. csio_wr_reg32(hw, 0, MPS_INT_CAUSE_A);
  2590. csio_rd_reg32(hw, MPS_INT_CAUSE_A); /* flush */
  2591. if (fat)
  2592. csio_hw_fatal_err(hw);
  2593. }
  2594. #define MEM_INT_MASK (PERR_INT_CAUSE_F | ECC_CE_INT_CAUSE_F | \
  2595. ECC_UE_INT_CAUSE_F)
  2596. /*
  2597. * EDC/MC interrupt handler.
  2598. */
  2599. static void csio_mem_intr_handler(struct csio_hw *hw, int idx)
  2600. {
  2601. static const char name[3][5] = { "EDC0", "EDC1", "MC" };
  2602. unsigned int addr, cnt_addr, v;
  2603. if (idx <= MEM_EDC1) {
  2604. addr = EDC_REG(EDC_INT_CAUSE_A, idx);
  2605. cnt_addr = EDC_REG(EDC_ECC_STATUS_A, idx);
  2606. } else {
  2607. addr = MC_INT_CAUSE_A;
  2608. cnt_addr = MC_ECC_STATUS_A;
  2609. }
  2610. v = csio_rd_reg32(hw, addr) & MEM_INT_MASK;
  2611. if (v & PERR_INT_CAUSE_F)
  2612. csio_fatal(hw, "%s FIFO parity error\n", name[idx]);
  2613. if (v & ECC_CE_INT_CAUSE_F) {
  2614. uint32_t cnt = ECC_CECNT_G(csio_rd_reg32(hw, cnt_addr));
  2615. csio_wr_reg32(hw, ECC_CECNT_V(ECC_CECNT_M), cnt_addr);
  2616. csio_warn(hw, "%u %s correctable ECC data error%s\n",
  2617. cnt, name[idx], cnt > 1 ? "s" : "");
  2618. }
  2619. if (v & ECC_UE_INT_CAUSE_F)
  2620. csio_fatal(hw, "%s uncorrectable ECC data error\n", name[idx]);
  2621. csio_wr_reg32(hw, v, addr);
  2622. if (v & (PERR_INT_CAUSE_F | ECC_UE_INT_CAUSE_F))
  2623. csio_hw_fatal_err(hw);
  2624. }
  2625. /*
  2626. * MA interrupt handler.
  2627. */
  2628. static void csio_ma_intr_handler(struct csio_hw *hw)
  2629. {
  2630. uint32_t v, status = csio_rd_reg32(hw, MA_INT_CAUSE_A);
  2631. if (status & MEM_PERR_INT_CAUSE_F)
  2632. csio_fatal(hw, "MA parity error, parity status %#x\n",
  2633. csio_rd_reg32(hw, MA_PARITY_ERROR_STATUS_A));
  2634. if (status & MEM_WRAP_INT_CAUSE_F) {
  2635. v = csio_rd_reg32(hw, MA_INT_WRAP_STATUS_A);
  2636. csio_fatal(hw,
  2637. "MA address wrap-around error by client %u to address %#x\n",
  2638. MEM_WRAP_CLIENT_NUM_G(v), MEM_WRAP_ADDRESS_G(v) << 4);
  2639. }
  2640. csio_wr_reg32(hw, status, MA_INT_CAUSE_A);
  2641. csio_hw_fatal_err(hw);
  2642. }
  2643. /*
  2644. * SMB interrupt handler.
  2645. */
  2646. static void csio_smb_intr_handler(struct csio_hw *hw)
  2647. {
  2648. static struct intr_info smb_intr_info[] = {
  2649. { MSTTXFIFOPARINT_F, "SMB master Tx FIFO parity error", -1, 1 },
  2650. { MSTRXFIFOPARINT_F, "SMB master Rx FIFO parity error", -1, 1 },
  2651. { SLVFIFOPARINT_F, "SMB slave FIFO parity error", -1, 1 },
  2652. { 0, NULL, 0, 0 }
  2653. };
  2654. if (csio_handle_intr_status(hw, SMB_INT_CAUSE_A, smb_intr_info))
  2655. csio_hw_fatal_err(hw);
  2656. }
  2657. /*
  2658. * NC-SI interrupt handler.
  2659. */
  2660. static void csio_ncsi_intr_handler(struct csio_hw *hw)
  2661. {
  2662. static struct intr_info ncsi_intr_info[] = {
  2663. { CIM_DM_PRTY_ERR_F, "NC-SI CIM parity error", -1, 1 },
  2664. { MPS_DM_PRTY_ERR_F, "NC-SI MPS parity error", -1, 1 },
  2665. { TXFIFO_PRTY_ERR_F, "NC-SI Tx FIFO parity error", -1, 1 },
  2666. { RXFIFO_PRTY_ERR_F, "NC-SI Rx FIFO parity error", -1, 1 },
  2667. { 0, NULL, 0, 0 }
  2668. };
  2669. if (csio_handle_intr_status(hw, NCSI_INT_CAUSE_A, ncsi_intr_info))
  2670. csio_hw_fatal_err(hw);
  2671. }
  2672. /*
  2673. * XGMAC interrupt handler.
  2674. */
  2675. static void csio_xgmac_intr_handler(struct csio_hw *hw, int port)
  2676. {
  2677. uint32_t v = csio_rd_reg32(hw, T5_PORT_REG(port, MAC_PORT_INT_CAUSE_A));
  2678. v &= TXFIFO_PRTY_ERR_F | RXFIFO_PRTY_ERR_F;
  2679. if (!v)
  2680. return;
  2681. if (v & TXFIFO_PRTY_ERR_F)
  2682. csio_fatal(hw, "XGMAC %d Tx FIFO parity error\n", port);
  2683. if (v & RXFIFO_PRTY_ERR_F)
  2684. csio_fatal(hw, "XGMAC %d Rx FIFO parity error\n", port);
  2685. csio_wr_reg32(hw, v, T5_PORT_REG(port, MAC_PORT_INT_CAUSE_A));
  2686. csio_hw_fatal_err(hw);
  2687. }
  2688. /*
  2689. * PL interrupt handler.
  2690. */
  2691. static void csio_pl_intr_handler(struct csio_hw *hw)
  2692. {
  2693. static struct intr_info pl_intr_info[] = {
  2694. { FATALPERR_F, "T4 fatal parity error", -1, 1 },
  2695. { PERRVFID_F, "PL VFID_MAP parity error", -1, 1 },
  2696. { 0, NULL, 0, 0 }
  2697. };
  2698. if (csio_handle_intr_status(hw, PL_PL_INT_CAUSE_A, pl_intr_info))
  2699. csio_hw_fatal_err(hw);
  2700. }
  2701. /*
  2702. * csio_hw_slow_intr_handler - control path interrupt handler
  2703. * @hw: HW module
  2704. *
  2705. * Interrupt handler for non-data global interrupt events, e.g., errors.
  2706. * The designation 'slow' is because it involves register reads, while
  2707. * data interrupts typically don't involve any MMIOs.
  2708. */
  2709. int
  2710. csio_hw_slow_intr_handler(struct csio_hw *hw)
  2711. {
  2712. uint32_t cause = csio_rd_reg32(hw, PL_INT_CAUSE_A);
  2713. if (!(cause & CSIO_GLBL_INTR_MASK)) {
  2714. CSIO_INC_STATS(hw, n_plint_unexp);
  2715. return 0;
  2716. }
  2717. csio_dbg(hw, "Slow interrupt! cause: 0x%x\n", cause);
  2718. CSIO_INC_STATS(hw, n_plint_cnt);
  2719. if (cause & CIM_F)
  2720. csio_cim_intr_handler(hw);
  2721. if (cause & MPS_F)
  2722. csio_mps_intr_handler(hw);
  2723. if (cause & NCSI_F)
  2724. csio_ncsi_intr_handler(hw);
  2725. if (cause & PL_F)
  2726. csio_pl_intr_handler(hw);
  2727. if (cause & SMB_F)
  2728. csio_smb_intr_handler(hw);
  2729. if (cause & XGMAC0_F)
  2730. csio_xgmac_intr_handler(hw, 0);
  2731. if (cause & XGMAC1_F)
  2732. csio_xgmac_intr_handler(hw, 1);
  2733. if (cause & XGMAC_KR0_F)
  2734. csio_xgmac_intr_handler(hw, 2);
  2735. if (cause & XGMAC_KR1_F)
  2736. csio_xgmac_intr_handler(hw, 3);
  2737. if (cause & PCIE_F)
  2738. hw->chip_ops->chip_pcie_intr_handler(hw);
  2739. if (cause & MC_F)
  2740. csio_mem_intr_handler(hw, MEM_MC);
  2741. if (cause & EDC0_F)
  2742. csio_mem_intr_handler(hw, MEM_EDC0);
  2743. if (cause & EDC1_F)
  2744. csio_mem_intr_handler(hw, MEM_EDC1);
  2745. if (cause & LE_F)
  2746. csio_le_intr_handler(hw);
  2747. if (cause & TP_F)
  2748. csio_tp_intr_handler(hw);
  2749. if (cause & MA_F)
  2750. csio_ma_intr_handler(hw);
  2751. if (cause & PM_TX_F)
  2752. csio_pmtx_intr_handler(hw);
  2753. if (cause & PM_RX_F)
  2754. csio_pmrx_intr_handler(hw);
  2755. if (cause & ULP_RX_F)
  2756. csio_ulprx_intr_handler(hw);
  2757. if (cause & CPL_SWITCH_F)
  2758. csio_cplsw_intr_handler(hw);
  2759. if (cause & SGE_F)
  2760. csio_sge_intr_handler(hw);
  2761. if (cause & ULP_TX_F)
  2762. csio_ulptx_intr_handler(hw);
  2763. /* Clear the interrupts just processed for which we are the master. */
  2764. csio_wr_reg32(hw, cause & CSIO_GLBL_INTR_MASK, PL_INT_CAUSE_A);
  2765. csio_rd_reg32(hw, PL_INT_CAUSE_A); /* flush */
  2766. return 1;
  2767. }
  2768. /*****************************************************************************
  2769. * HW <--> mailbox interfacing routines.
  2770. ****************************************************************************/
  2771. /*
  2772. * csio_mberr_worker - Worker thread (dpc) for mailbox/error completions
  2773. *
  2774. * @data: Private data pointer.
  2775. *
  2776. * Called from worker thread context.
  2777. */
  2778. static void
  2779. csio_mberr_worker(void *data)
  2780. {
  2781. struct csio_hw *hw = (struct csio_hw *)data;
  2782. struct csio_mbm *mbm = &hw->mbm;
  2783. LIST_HEAD(cbfn_q);
  2784. struct csio_mb *mbp_next;
  2785. int rv;
  2786. del_timer_sync(&mbm->timer);
  2787. spin_lock_irq(&hw->lock);
  2788. if (list_empty(&mbm->cbfn_q)) {
  2789. spin_unlock_irq(&hw->lock);
  2790. return;
  2791. }
  2792. list_splice_tail_init(&mbm->cbfn_q, &cbfn_q);
  2793. mbm->stats.n_cbfnq = 0;
  2794. /* Try to start waiting mailboxes */
  2795. if (!list_empty(&mbm->req_q)) {
  2796. mbp_next = list_first_entry(&mbm->req_q, struct csio_mb, list);
  2797. list_del_init(&mbp_next->list);
  2798. rv = csio_mb_issue(hw, mbp_next);
  2799. if (rv != 0)
  2800. list_add_tail(&mbp_next->list, &mbm->req_q);
  2801. else
  2802. CSIO_DEC_STATS(mbm, n_activeq);
  2803. }
  2804. spin_unlock_irq(&hw->lock);
  2805. /* Now callback completions */
  2806. csio_mb_completions(hw, &cbfn_q);
  2807. }
  2808. /*
  2809. * csio_hw_mb_timer - Top-level Mailbox timeout handler.
  2810. *
  2811. * @data: private data pointer
  2812. *
  2813. **/
  2814. static void
  2815. csio_hw_mb_timer(uintptr_t data)
  2816. {
  2817. struct csio_hw *hw = (struct csio_hw *)data;
  2818. struct csio_mb *mbp = NULL;
  2819. spin_lock_irq(&hw->lock);
  2820. mbp = csio_mb_tmo_handler(hw);
  2821. spin_unlock_irq(&hw->lock);
  2822. /* Call back the function for the timed-out Mailbox */
  2823. if (mbp)
  2824. mbp->mb_cbfn(hw, mbp);
  2825. }
  2826. /*
  2827. * csio_hw_mbm_cleanup - Cleanup Mailbox module.
  2828. * @hw: HW module
  2829. *
  2830. * Called with lock held, should exit with lock held.
  2831. * Cancels outstanding mailboxes (waiting, in-flight) and gathers them
  2832. * into a local queue. Drops lock and calls the completions. Holds
  2833. * lock and returns.
  2834. */
  2835. static void
  2836. csio_hw_mbm_cleanup(struct csio_hw *hw)
  2837. {
  2838. LIST_HEAD(cbfn_q);
  2839. csio_mb_cancel_all(hw, &cbfn_q);
  2840. spin_unlock_irq(&hw->lock);
  2841. csio_mb_completions(hw, &cbfn_q);
  2842. spin_lock_irq(&hw->lock);
  2843. }
  2844. /*****************************************************************************
  2845. * Event handling
  2846. ****************************************************************************/
  2847. int
  2848. csio_enqueue_evt(struct csio_hw *hw, enum csio_evt type, void *evt_msg,
  2849. uint16_t len)
  2850. {
  2851. struct csio_evt_msg *evt_entry = NULL;
  2852. if (type >= CSIO_EVT_MAX)
  2853. return -EINVAL;
  2854. if (len > CSIO_EVT_MSG_SIZE)
  2855. return -EINVAL;
  2856. if (hw->flags & CSIO_HWF_FWEVT_STOP)
  2857. return -EINVAL;
  2858. if (list_empty(&hw->evt_free_q)) {
  2859. csio_err(hw, "Failed to alloc evt entry, msg type %d len %d\n",
  2860. type, len);
  2861. return -ENOMEM;
  2862. }
  2863. evt_entry = list_first_entry(&hw->evt_free_q,
  2864. struct csio_evt_msg, list);
  2865. list_del_init(&evt_entry->list);
  2866. /* copy event msg and queue the event */
  2867. evt_entry->type = type;
  2868. memcpy((void *)evt_entry->data, evt_msg, len);
  2869. list_add_tail(&evt_entry->list, &hw->evt_active_q);
  2870. CSIO_DEC_STATS(hw, n_evt_freeq);
  2871. CSIO_INC_STATS(hw, n_evt_activeq);
  2872. return 0;
  2873. }
  2874. static int
  2875. csio_enqueue_evt_lock(struct csio_hw *hw, enum csio_evt type, void *evt_msg,
  2876. uint16_t len, bool msg_sg)
  2877. {
  2878. struct csio_evt_msg *evt_entry = NULL;
  2879. struct csio_fl_dma_buf *fl_sg;
  2880. uint32_t off = 0;
  2881. unsigned long flags;
  2882. int n, ret = 0;
  2883. if (type >= CSIO_EVT_MAX)
  2884. return -EINVAL;
  2885. if (len > CSIO_EVT_MSG_SIZE)
  2886. return -EINVAL;
  2887. spin_lock_irqsave(&hw->lock, flags);
  2888. if (hw->flags & CSIO_HWF_FWEVT_STOP) {
  2889. ret = -EINVAL;
  2890. goto out;
  2891. }
  2892. if (list_empty(&hw->evt_free_q)) {
  2893. csio_err(hw, "Failed to alloc evt entry, msg type %d len %d\n",
  2894. type, len);
  2895. ret = -ENOMEM;
  2896. goto out;
  2897. }
  2898. evt_entry = list_first_entry(&hw->evt_free_q,
  2899. struct csio_evt_msg, list);
  2900. list_del_init(&evt_entry->list);
  2901. /* copy event msg and queue the event */
  2902. evt_entry->type = type;
  2903. /* If Payload in SG list*/
  2904. if (msg_sg) {
  2905. fl_sg = (struct csio_fl_dma_buf *) evt_msg;
  2906. for (n = 0; (n < CSIO_MAX_FLBUF_PER_IQWR && off < len); n++) {
  2907. memcpy((void *)((uintptr_t)evt_entry->data + off),
  2908. fl_sg->flbufs[n].vaddr,
  2909. fl_sg->flbufs[n].len);
  2910. off += fl_sg->flbufs[n].len;
  2911. }
  2912. } else
  2913. memcpy((void *)evt_entry->data, evt_msg, len);
  2914. list_add_tail(&evt_entry->list, &hw->evt_active_q);
  2915. CSIO_DEC_STATS(hw, n_evt_freeq);
  2916. CSIO_INC_STATS(hw, n_evt_activeq);
  2917. out:
  2918. spin_unlock_irqrestore(&hw->lock, flags);
  2919. return ret;
  2920. }
  2921. static void
  2922. csio_free_evt(struct csio_hw *hw, struct csio_evt_msg *evt_entry)
  2923. {
  2924. if (evt_entry) {
  2925. spin_lock_irq(&hw->lock);
  2926. list_del_init(&evt_entry->list);
  2927. list_add_tail(&evt_entry->list, &hw->evt_free_q);
  2928. CSIO_DEC_STATS(hw, n_evt_activeq);
  2929. CSIO_INC_STATS(hw, n_evt_freeq);
  2930. spin_unlock_irq(&hw->lock);
  2931. }
  2932. }
  2933. void
  2934. csio_evtq_flush(struct csio_hw *hw)
  2935. {
  2936. uint32_t count;
  2937. count = 30;
  2938. while (hw->flags & CSIO_HWF_FWEVT_PENDING && count--) {
  2939. spin_unlock_irq(&hw->lock);
  2940. msleep(2000);
  2941. spin_lock_irq(&hw->lock);
  2942. }
  2943. CSIO_DB_ASSERT(!(hw->flags & CSIO_HWF_FWEVT_PENDING));
  2944. }
  2945. static void
  2946. csio_evtq_stop(struct csio_hw *hw)
  2947. {
  2948. hw->flags |= CSIO_HWF_FWEVT_STOP;
  2949. }
  2950. static void
  2951. csio_evtq_start(struct csio_hw *hw)
  2952. {
  2953. hw->flags &= ~CSIO_HWF_FWEVT_STOP;
  2954. }
  2955. static void
  2956. csio_evtq_cleanup(struct csio_hw *hw)
  2957. {
  2958. struct list_head *evt_entry, *next_entry;
  2959. /* Release outstanding events from activeq to freeq*/
  2960. if (!list_empty(&hw->evt_active_q))
  2961. list_splice_tail_init(&hw->evt_active_q, &hw->evt_free_q);
  2962. hw->stats.n_evt_activeq = 0;
  2963. hw->flags &= ~CSIO_HWF_FWEVT_PENDING;
  2964. /* Freeup event entry */
  2965. list_for_each_safe(evt_entry, next_entry, &hw->evt_free_q) {
  2966. kfree(evt_entry);
  2967. CSIO_DEC_STATS(hw, n_evt_freeq);
  2968. }
  2969. hw->stats.n_evt_freeq = 0;
  2970. }
  2971. static void
  2972. csio_process_fwevtq_entry(struct csio_hw *hw, void *wr, uint32_t len,
  2973. struct csio_fl_dma_buf *flb, void *priv)
  2974. {
  2975. __u8 op;
  2976. void *msg = NULL;
  2977. uint32_t msg_len = 0;
  2978. bool msg_sg = 0;
  2979. op = ((struct rss_header *) wr)->opcode;
  2980. if (op == CPL_FW6_PLD) {
  2981. CSIO_INC_STATS(hw, n_cpl_fw6_pld);
  2982. if (!flb || !flb->totlen) {
  2983. CSIO_INC_STATS(hw, n_cpl_unexp);
  2984. return;
  2985. }
  2986. msg = (void *) flb;
  2987. msg_len = flb->totlen;
  2988. msg_sg = 1;
  2989. } else if (op == CPL_FW6_MSG || op == CPL_FW4_MSG) {
  2990. CSIO_INC_STATS(hw, n_cpl_fw6_msg);
  2991. /* skip RSS header */
  2992. msg = (void *)((uintptr_t)wr + sizeof(__be64));
  2993. msg_len = (op == CPL_FW6_MSG) ? sizeof(struct cpl_fw6_msg) :
  2994. sizeof(struct cpl_fw4_msg);
  2995. } else {
  2996. csio_warn(hw, "unexpected CPL %#x on FW event queue\n", op);
  2997. CSIO_INC_STATS(hw, n_cpl_unexp);
  2998. return;
  2999. }
  3000. /*
  3001. * Enqueue event to EventQ. Events processing happens
  3002. * in Event worker thread context
  3003. */
  3004. if (csio_enqueue_evt_lock(hw, CSIO_EVT_FW, msg,
  3005. (uint16_t)msg_len, msg_sg))
  3006. CSIO_INC_STATS(hw, n_evt_drop);
  3007. }
  3008. void
  3009. csio_evtq_worker(struct work_struct *work)
  3010. {
  3011. struct csio_hw *hw = container_of(work, struct csio_hw, evtq_work);
  3012. struct list_head *evt_entry, *next_entry;
  3013. LIST_HEAD(evt_q);
  3014. struct csio_evt_msg *evt_msg;
  3015. struct cpl_fw6_msg *msg;
  3016. struct csio_rnode *rn;
  3017. int rv = 0;
  3018. uint8_t evtq_stop = 0;
  3019. csio_dbg(hw, "event worker thread active evts#%d\n",
  3020. hw->stats.n_evt_activeq);
  3021. spin_lock_irq(&hw->lock);
  3022. while (!list_empty(&hw->evt_active_q)) {
  3023. list_splice_tail_init(&hw->evt_active_q, &evt_q);
  3024. spin_unlock_irq(&hw->lock);
  3025. list_for_each_safe(evt_entry, next_entry, &evt_q) {
  3026. evt_msg = (struct csio_evt_msg *) evt_entry;
  3027. /* Drop events if queue is STOPPED */
  3028. spin_lock_irq(&hw->lock);
  3029. if (hw->flags & CSIO_HWF_FWEVT_STOP)
  3030. evtq_stop = 1;
  3031. spin_unlock_irq(&hw->lock);
  3032. if (evtq_stop) {
  3033. CSIO_INC_STATS(hw, n_evt_drop);
  3034. goto free_evt;
  3035. }
  3036. switch (evt_msg->type) {
  3037. case CSIO_EVT_FW:
  3038. msg = (struct cpl_fw6_msg *)(evt_msg->data);
  3039. if ((msg->opcode == CPL_FW6_MSG ||
  3040. msg->opcode == CPL_FW4_MSG) &&
  3041. !msg->type) {
  3042. rv = csio_mb_fwevt_handler(hw,
  3043. msg->data);
  3044. if (!rv)
  3045. break;
  3046. /* Handle any remaining fw events */
  3047. csio_fcoe_fwevt_handler(hw,
  3048. msg->opcode, msg->data);
  3049. } else if (msg->opcode == CPL_FW6_PLD) {
  3050. csio_fcoe_fwevt_handler(hw,
  3051. msg->opcode, msg->data);
  3052. } else {
  3053. csio_warn(hw,
  3054. "Unhandled FW msg op %x type %x\n",
  3055. msg->opcode, msg->type);
  3056. CSIO_INC_STATS(hw, n_evt_drop);
  3057. }
  3058. break;
  3059. case CSIO_EVT_MBX:
  3060. csio_mberr_worker(hw);
  3061. break;
  3062. case CSIO_EVT_DEV_LOSS:
  3063. memcpy(&rn, evt_msg->data, sizeof(rn));
  3064. csio_rnode_devloss_handler(rn);
  3065. break;
  3066. default:
  3067. csio_warn(hw, "Unhandled event %x on evtq\n",
  3068. evt_msg->type);
  3069. CSIO_INC_STATS(hw, n_evt_unexp);
  3070. break;
  3071. }
  3072. free_evt:
  3073. csio_free_evt(hw, evt_msg);
  3074. }
  3075. spin_lock_irq(&hw->lock);
  3076. }
  3077. hw->flags &= ~CSIO_HWF_FWEVT_PENDING;
  3078. spin_unlock_irq(&hw->lock);
  3079. }
  3080. int
  3081. csio_fwevtq_handler(struct csio_hw *hw)
  3082. {
  3083. int rv;
  3084. if (csio_q_iqid(hw, hw->fwevt_iq_idx) == CSIO_MAX_QID) {
  3085. CSIO_INC_STATS(hw, n_int_stray);
  3086. return -EINVAL;
  3087. }
  3088. rv = csio_wr_process_iq_idx(hw, hw->fwevt_iq_idx,
  3089. csio_process_fwevtq_entry, NULL);
  3090. return rv;
  3091. }
  3092. /****************************************************************************
  3093. * Entry points
  3094. ****************************************************************************/
  3095. /* Management module */
  3096. /*
  3097. * csio_mgmt_req_lookup - Lookup the given IO req exist in Active Q.
  3098. * mgmt - mgmt module
  3099. * @io_req - io request
  3100. *
  3101. * Return - 0:if given IO Req exists in active Q.
  3102. * -EINVAL :if lookup fails.
  3103. */
  3104. int
  3105. csio_mgmt_req_lookup(struct csio_mgmtm *mgmtm, struct csio_ioreq *io_req)
  3106. {
  3107. struct list_head *tmp;
  3108. /* Lookup ioreq in the ACTIVEQ */
  3109. list_for_each(tmp, &mgmtm->active_q) {
  3110. if (io_req == (struct csio_ioreq *)tmp)
  3111. return 0;
  3112. }
  3113. return -EINVAL;
  3114. }
  3115. #define ECM_MIN_TMO 1000 /* Minimum timeout value for req */
  3116. /*
  3117. * csio_mgmts_tmo_handler - MGMT IO Timeout handler.
  3118. * @data - Event data.
  3119. *
  3120. * Return - none.
  3121. */
  3122. static void
  3123. csio_mgmt_tmo_handler(uintptr_t data)
  3124. {
  3125. struct csio_mgmtm *mgmtm = (struct csio_mgmtm *) data;
  3126. struct list_head *tmp;
  3127. struct csio_ioreq *io_req;
  3128. csio_dbg(mgmtm->hw, "Mgmt timer invoked!\n");
  3129. spin_lock_irq(&mgmtm->hw->lock);
  3130. list_for_each(tmp, &mgmtm->active_q) {
  3131. io_req = (struct csio_ioreq *) tmp;
  3132. io_req->tmo -= min_t(uint32_t, io_req->tmo, ECM_MIN_TMO);
  3133. if (!io_req->tmo) {
  3134. /* Dequeue the request from retry Q. */
  3135. tmp = csio_list_prev(tmp);
  3136. list_del_init(&io_req->sm.sm_list);
  3137. if (io_req->io_cbfn) {
  3138. /* io_req will be freed by completion handler */
  3139. io_req->wr_status = -ETIMEDOUT;
  3140. io_req->io_cbfn(mgmtm->hw, io_req);
  3141. } else {
  3142. CSIO_DB_ASSERT(0);
  3143. }
  3144. }
  3145. }
  3146. /* If retry queue is not empty, re-arm timer */
  3147. if (!list_empty(&mgmtm->active_q))
  3148. mod_timer(&mgmtm->mgmt_timer,
  3149. jiffies + msecs_to_jiffies(ECM_MIN_TMO));
  3150. spin_unlock_irq(&mgmtm->hw->lock);
  3151. }
  3152. static void
  3153. csio_mgmtm_cleanup(struct csio_mgmtm *mgmtm)
  3154. {
  3155. struct csio_hw *hw = mgmtm->hw;
  3156. struct csio_ioreq *io_req;
  3157. struct list_head *tmp;
  3158. uint32_t count;
  3159. count = 30;
  3160. /* Wait for all outstanding req to complete gracefully */
  3161. while ((!list_empty(&mgmtm->active_q)) && count--) {
  3162. spin_unlock_irq(&hw->lock);
  3163. msleep(2000);
  3164. spin_lock_irq(&hw->lock);
  3165. }
  3166. /* release outstanding req from ACTIVEQ */
  3167. list_for_each(tmp, &mgmtm->active_q) {
  3168. io_req = (struct csio_ioreq *) tmp;
  3169. tmp = csio_list_prev(tmp);
  3170. list_del_init(&io_req->sm.sm_list);
  3171. mgmtm->stats.n_active--;
  3172. if (io_req->io_cbfn) {
  3173. /* io_req will be freed by completion handler */
  3174. io_req->wr_status = -ETIMEDOUT;
  3175. io_req->io_cbfn(mgmtm->hw, io_req);
  3176. }
  3177. }
  3178. }
  3179. /*
  3180. * csio_mgmt_init - Mgmt module init entry point
  3181. * @mgmtsm - mgmt module
  3182. * @hw - HW module
  3183. *
  3184. * Initialize mgmt timer, resource wait queue, active queue,
  3185. * completion q. Allocate Egress and Ingress
  3186. * WR queues and save off the queue index returned by the WR
  3187. * module for future use. Allocate and save off mgmt reqs in the
  3188. * mgmt_req_freelist for future use. Make sure their SM is initialized
  3189. * to uninit state.
  3190. * Returns: 0 - on success
  3191. * -ENOMEM - on error.
  3192. */
  3193. static int
  3194. csio_mgmtm_init(struct csio_mgmtm *mgmtm, struct csio_hw *hw)
  3195. {
  3196. struct timer_list *timer = &mgmtm->mgmt_timer;
  3197. init_timer(timer);
  3198. timer->function = csio_mgmt_tmo_handler;
  3199. timer->data = (unsigned long)mgmtm;
  3200. INIT_LIST_HEAD(&mgmtm->active_q);
  3201. INIT_LIST_HEAD(&mgmtm->cbfn_q);
  3202. mgmtm->hw = hw;
  3203. /*mgmtm->iq_idx = hw->fwevt_iq_idx;*/
  3204. return 0;
  3205. }
  3206. /*
  3207. * csio_mgmtm_exit - MGMT module exit entry point
  3208. * @mgmtsm - mgmt module
  3209. *
  3210. * This function called during MGMT module uninit.
  3211. * Stop timers, free ioreqs allocated.
  3212. * Returns: None
  3213. *
  3214. */
  3215. static void
  3216. csio_mgmtm_exit(struct csio_mgmtm *mgmtm)
  3217. {
  3218. del_timer_sync(&mgmtm->mgmt_timer);
  3219. }
  3220. /**
  3221. * csio_hw_start - Kicks off the HW State machine
  3222. * @hw: Pointer to HW module.
  3223. *
  3224. * It is assumed that the initialization is a synchronous operation.
  3225. * So when we return afer posting the event, the HW SM should be in
  3226. * the ready state, if there were no errors during init.
  3227. */
  3228. int
  3229. csio_hw_start(struct csio_hw *hw)
  3230. {
  3231. spin_lock_irq(&hw->lock);
  3232. csio_post_event(&hw->sm, CSIO_HWE_CFG);
  3233. spin_unlock_irq(&hw->lock);
  3234. if (csio_is_hw_ready(hw))
  3235. return 0;
  3236. else
  3237. return -EINVAL;
  3238. }
  3239. int
  3240. csio_hw_stop(struct csio_hw *hw)
  3241. {
  3242. csio_post_event(&hw->sm, CSIO_HWE_PCI_REMOVE);
  3243. if (csio_is_hw_removing(hw))
  3244. return 0;
  3245. else
  3246. return -EINVAL;
  3247. }
  3248. /* Max reset retries */
  3249. #define CSIO_MAX_RESET_RETRIES 3
  3250. /**
  3251. * csio_hw_reset - Reset the hardware
  3252. * @hw: HW module.
  3253. *
  3254. * Caller should hold lock across this function.
  3255. */
  3256. int
  3257. csio_hw_reset(struct csio_hw *hw)
  3258. {
  3259. if (!csio_is_hw_master(hw))
  3260. return -EPERM;
  3261. if (hw->rst_retries >= CSIO_MAX_RESET_RETRIES) {
  3262. csio_dbg(hw, "Max hw reset attempts reached..");
  3263. return -EINVAL;
  3264. }
  3265. hw->rst_retries++;
  3266. csio_post_event(&hw->sm, CSIO_HWE_HBA_RESET);
  3267. if (csio_is_hw_ready(hw)) {
  3268. hw->rst_retries = 0;
  3269. hw->stats.n_reset_start = jiffies_to_msecs(jiffies);
  3270. return 0;
  3271. } else
  3272. return -EINVAL;
  3273. }
  3274. /*
  3275. * csio_hw_get_device_id - Caches the Adapter's vendor & device id.
  3276. * @hw: HW module.
  3277. */
  3278. static void
  3279. csio_hw_get_device_id(struct csio_hw *hw)
  3280. {
  3281. /* Is the adapter device id cached already ?*/
  3282. if (csio_is_dev_id_cached(hw))
  3283. return;
  3284. /* Get the PCI vendor & device id */
  3285. pci_read_config_word(hw->pdev, PCI_VENDOR_ID,
  3286. &hw->params.pci.vendor_id);
  3287. pci_read_config_word(hw->pdev, PCI_DEVICE_ID,
  3288. &hw->params.pci.device_id);
  3289. csio_dev_id_cached(hw);
  3290. hw->chip_id = (hw->params.pci.device_id & CSIO_HW_CHIP_MASK);
  3291. } /* csio_hw_get_device_id */
  3292. /*
  3293. * csio_hw_set_description - Set the model, description of the hw.
  3294. * @hw: HW module.
  3295. * @ven_id: PCI Vendor ID
  3296. * @dev_id: PCI Device ID
  3297. */
  3298. static void
  3299. csio_hw_set_description(struct csio_hw *hw, uint16_t ven_id, uint16_t dev_id)
  3300. {
  3301. uint32_t adap_type, prot_type;
  3302. if (ven_id == CSIO_VENDOR_ID) {
  3303. prot_type = (dev_id & CSIO_ASIC_DEVID_PROTO_MASK);
  3304. adap_type = (dev_id & CSIO_ASIC_DEVID_TYPE_MASK);
  3305. if (prot_type == CSIO_T5_FCOE_ASIC) {
  3306. memcpy(hw->hw_ver,
  3307. csio_t5_fcoe_adapters[adap_type].model_no, 16);
  3308. memcpy(hw->model_desc,
  3309. csio_t5_fcoe_adapters[adap_type].description,
  3310. 32);
  3311. } else {
  3312. char tempName[32] = "Chelsio FCoE Controller";
  3313. memcpy(hw->model_desc, tempName, 32);
  3314. }
  3315. }
  3316. } /* csio_hw_set_description */
  3317. /**
  3318. * csio_hw_init - Initialize HW module.
  3319. * @hw: Pointer to HW module.
  3320. *
  3321. * Initialize the members of the HW module.
  3322. */
  3323. int
  3324. csio_hw_init(struct csio_hw *hw)
  3325. {
  3326. int rv = -EINVAL;
  3327. uint32_t i;
  3328. uint16_t ven_id, dev_id;
  3329. struct csio_evt_msg *evt_entry;
  3330. INIT_LIST_HEAD(&hw->sm.sm_list);
  3331. csio_init_state(&hw->sm, csio_hws_uninit);
  3332. spin_lock_init(&hw->lock);
  3333. INIT_LIST_HEAD(&hw->sln_head);
  3334. /* Get the PCI vendor & device id */
  3335. csio_hw_get_device_id(hw);
  3336. strcpy(hw->name, CSIO_HW_NAME);
  3337. /* Initialize the HW chip ops T5 specific ops */
  3338. hw->chip_ops = &t5_ops;
  3339. /* Set the model & its description */
  3340. ven_id = hw->params.pci.vendor_id;
  3341. dev_id = hw->params.pci.device_id;
  3342. csio_hw_set_description(hw, ven_id, dev_id);
  3343. /* Initialize default log level */
  3344. hw->params.log_level = (uint32_t) csio_dbg_level;
  3345. csio_set_fwevt_intr_idx(hw, -1);
  3346. csio_set_nondata_intr_idx(hw, -1);
  3347. /* Init all the modules: Mailbox, WorkRequest and Transport */
  3348. if (csio_mbm_init(csio_hw_to_mbm(hw), hw, csio_hw_mb_timer))
  3349. goto err;
  3350. rv = csio_wrm_init(csio_hw_to_wrm(hw), hw);
  3351. if (rv)
  3352. goto err_mbm_exit;
  3353. rv = csio_scsim_init(csio_hw_to_scsim(hw), hw);
  3354. if (rv)
  3355. goto err_wrm_exit;
  3356. rv = csio_mgmtm_init(csio_hw_to_mgmtm(hw), hw);
  3357. if (rv)
  3358. goto err_scsim_exit;
  3359. /* Pre-allocate evtq and initialize them */
  3360. INIT_LIST_HEAD(&hw->evt_active_q);
  3361. INIT_LIST_HEAD(&hw->evt_free_q);
  3362. for (i = 0; i < csio_evtq_sz; i++) {
  3363. evt_entry = kzalloc(sizeof(struct csio_evt_msg), GFP_KERNEL);
  3364. if (!evt_entry) {
  3365. rv = -ENOMEM;
  3366. csio_err(hw, "Failed to initialize eventq");
  3367. goto err_evtq_cleanup;
  3368. }
  3369. list_add_tail(&evt_entry->list, &hw->evt_free_q);
  3370. CSIO_INC_STATS(hw, n_evt_freeq);
  3371. }
  3372. hw->dev_num = dev_num;
  3373. dev_num++;
  3374. return 0;
  3375. err_evtq_cleanup:
  3376. csio_evtq_cleanup(hw);
  3377. csio_mgmtm_exit(csio_hw_to_mgmtm(hw));
  3378. err_scsim_exit:
  3379. csio_scsim_exit(csio_hw_to_scsim(hw));
  3380. err_wrm_exit:
  3381. csio_wrm_exit(csio_hw_to_wrm(hw), hw);
  3382. err_mbm_exit:
  3383. csio_mbm_exit(csio_hw_to_mbm(hw));
  3384. err:
  3385. return rv;
  3386. }
  3387. /**
  3388. * csio_hw_exit - Un-initialize HW module.
  3389. * @hw: Pointer to HW module.
  3390. *
  3391. */
  3392. void
  3393. csio_hw_exit(struct csio_hw *hw)
  3394. {
  3395. csio_evtq_cleanup(hw);
  3396. csio_mgmtm_exit(csio_hw_to_mgmtm(hw));
  3397. csio_scsim_exit(csio_hw_to_scsim(hw));
  3398. csio_wrm_exit(csio_hw_to_wrm(hw), hw);
  3399. csio_mbm_exit(csio_hw_to_mbm(hw));
  3400. }