csio_hw.c 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975
  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 (reject_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 (reject_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. }