trans.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2007 - 2015 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <ilw@linux.intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2005 - 2015 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include <linux/pci.h>
  66. #include <linux/pci-aspm.h>
  67. #include <linux/interrupt.h>
  68. #include <linux/debugfs.h>
  69. #include <linux/sched.h>
  70. #include <linux/bitops.h>
  71. #include <linux/gfp.h>
  72. #include <linux/vmalloc.h>
  73. #include "iwl-drv.h"
  74. #include "iwl-trans.h"
  75. #include "iwl-csr.h"
  76. #include "iwl-prph.h"
  77. #include "iwl-scd.h"
  78. #include "iwl-agn-hw.h"
  79. #include "iwl-fw-error-dump.h"
  80. #include "internal.h"
  81. #include "iwl-fh.h"
  82. /* extended range in FW SRAM */
  83. #define IWL_FW_MEM_EXTENDED_START 0x40000
  84. #define IWL_FW_MEM_EXTENDED_END 0x57FFF
  85. static void iwl_pcie_free_fw_monitor(struct iwl_trans *trans)
  86. {
  87. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  88. if (!trans_pcie->fw_mon_page)
  89. return;
  90. dma_unmap_page(trans->dev, trans_pcie->fw_mon_phys,
  91. trans_pcie->fw_mon_size, DMA_FROM_DEVICE);
  92. __free_pages(trans_pcie->fw_mon_page,
  93. get_order(trans_pcie->fw_mon_size));
  94. trans_pcie->fw_mon_page = NULL;
  95. trans_pcie->fw_mon_phys = 0;
  96. trans_pcie->fw_mon_size = 0;
  97. }
  98. static void iwl_pcie_alloc_fw_monitor(struct iwl_trans *trans)
  99. {
  100. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  101. struct page *page = NULL;
  102. dma_addr_t phys;
  103. u32 size;
  104. u8 power;
  105. if (trans_pcie->fw_mon_page) {
  106. dma_sync_single_for_device(trans->dev, trans_pcie->fw_mon_phys,
  107. trans_pcie->fw_mon_size,
  108. DMA_FROM_DEVICE);
  109. return;
  110. }
  111. phys = 0;
  112. for (power = 26; power >= 11; power--) {
  113. int order;
  114. size = BIT(power);
  115. order = get_order(size);
  116. page = alloc_pages(__GFP_COMP | __GFP_NOWARN | __GFP_ZERO,
  117. order);
  118. if (!page)
  119. continue;
  120. phys = dma_map_page(trans->dev, page, 0, PAGE_SIZE << order,
  121. DMA_FROM_DEVICE);
  122. if (dma_mapping_error(trans->dev, phys)) {
  123. __free_pages(page, order);
  124. page = NULL;
  125. continue;
  126. }
  127. IWL_INFO(trans,
  128. "Allocated 0x%08x bytes (order %d) for firmware monitor.\n",
  129. size, order);
  130. break;
  131. }
  132. if (WARN_ON_ONCE(!page))
  133. return;
  134. trans_pcie->fw_mon_page = page;
  135. trans_pcie->fw_mon_phys = phys;
  136. trans_pcie->fw_mon_size = size;
  137. }
  138. static u32 iwl_trans_pcie_read_shr(struct iwl_trans *trans, u32 reg)
  139. {
  140. iwl_write32(trans, HEEP_CTRL_WRD_PCIEX_CTRL_REG,
  141. ((reg & 0x0000ffff) | (2 << 28)));
  142. return iwl_read32(trans, HEEP_CTRL_WRD_PCIEX_DATA_REG);
  143. }
  144. static void iwl_trans_pcie_write_shr(struct iwl_trans *trans, u32 reg, u32 val)
  145. {
  146. iwl_write32(trans, HEEP_CTRL_WRD_PCIEX_DATA_REG, val);
  147. iwl_write32(trans, HEEP_CTRL_WRD_PCIEX_CTRL_REG,
  148. ((reg & 0x0000ffff) | (3 << 28)));
  149. }
  150. static void iwl_pcie_set_pwr(struct iwl_trans *trans, bool vaux)
  151. {
  152. if (vaux && pci_pme_capable(to_pci_dev(trans->dev), PCI_D3cold))
  153. iwl_set_bits_mask_prph(trans, APMG_PS_CTRL_REG,
  154. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  155. ~APMG_PS_CTRL_MSK_PWR_SRC);
  156. else
  157. iwl_set_bits_mask_prph(trans, APMG_PS_CTRL_REG,
  158. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  159. ~APMG_PS_CTRL_MSK_PWR_SRC);
  160. }
  161. /* PCI registers */
  162. #define PCI_CFG_RETRY_TIMEOUT 0x041
  163. static void iwl_pcie_apm_config(struct iwl_trans *trans)
  164. {
  165. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  166. u16 lctl;
  167. u16 cap;
  168. /*
  169. * HW bug W/A for instability in PCIe bus L0S->L1 transition.
  170. * Check if BIOS (or OS) enabled L1-ASPM on this device.
  171. * If so (likely), disable L0S, so device moves directly L0->L1;
  172. * costs negligible amount of power savings.
  173. * If not (unlikely), enable L0S, so there is at least some
  174. * power savings, even without L1.
  175. */
  176. pcie_capability_read_word(trans_pcie->pci_dev, PCI_EXP_LNKCTL, &lctl);
  177. if (lctl & PCI_EXP_LNKCTL_ASPM_L1)
  178. iwl_set_bit(trans, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  179. else
  180. iwl_clear_bit(trans, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  181. trans->pm_support = !(lctl & PCI_EXP_LNKCTL_ASPM_L0S);
  182. pcie_capability_read_word(trans_pcie->pci_dev, PCI_EXP_DEVCTL2, &cap);
  183. trans->ltr_enabled = cap & PCI_EXP_DEVCTL2_LTR_EN;
  184. dev_info(trans->dev, "L1 %sabled - LTR %sabled\n",
  185. (lctl & PCI_EXP_LNKCTL_ASPM_L1) ? "En" : "Dis",
  186. trans->ltr_enabled ? "En" : "Dis");
  187. }
  188. /*
  189. * Start up NIC's basic functionality after it has been reset
  190. * (e.g. after platform boot, or shutdown via iwl_pcie_apm_stop())
  191. * NOTE: This does not load uCode nor start the embedded processor
  192. */
  193. static int iwl_pcie_apm_init(struct iwl_trans *trans)
  194. {
  195. int ret = 0;
  196. IWL_DEBUG_INFO(trans, "Init card's basic functions\n");
  197. /*
  198. * Use "set_bit" below rather than "write", to preserve any hardware
  199. * bits already set by default after reset.
  200. */
  201. /* Disable L0S exit timer (platform NMI Work/Around) */
  202. if (trans->cfg->device_family != IWL_DEVICE_FAMILY_8000)
  203. iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS,
  204. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  205. /*
  206. * Disable L0s without affecting L1;
  207. * don't wait for ICH L0s (ICH bug W/A)
  208. */
  209. iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS,
  210. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  211. /* Set FH wait threshold to maximum (HW error during stress W/A) */
  212. iwl_set_bit(trans, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
  213. /*
  214. * Enable HAP INTA (interrupt from management bus) to
  215. * wake device's PCI Express link L1a -> L0s
  216. */
  217. iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
  218. CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
  219. iwl_pcie_apm_config(trans);
  220. /* Configure analog phase-lock-loop before activating to D0A */
  221. if (trans->cfg->base_params->pll_cfg_val)
  222. iwl_set_bit(trans, CSR_ANA_PLL_CFG,
  223. trans->cfg->base_params->pll_cfg_val);
  224. /*
  225. * Set "initialization complete" bit to move adapter from
  226. * D0U* --> D0A* (powered-up active) state.
  227. */
  228. iwl_set_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  229. /*
  230. * Wait for clock stabilization; once stabilized, access to
  231. * device-internal resources is supported, e.g. iwl_write_prph()
  232. * and accesses to uCode SRAM.
  233. */
  234. ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
  235. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  236. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  237. if (ret < 0) {
  238. IWL_DEBUG_INFO(trans, "Failed to init the card\n");
  239. goto out;
  240. }
  241. if (trans->cfg->host_interrupt_operation_mode) {
  242. /*
  243. * This is a bit of an abuse - This is needed for 7260 / 3160
  244. * only check host_interrupt_operation_mode even if this is
  245. * not related to host_interrupt_operation_mode.
  246. *
  247. * Enable the oscillator to count wake up time for L1 exit. This
  248. * consumes slightly more power (100uA) - but allows to be sure
  249. * that we wake up from L1 on time.
  250. *
  251. * This looks weird: read twice the same register, discard the
  252. * value, set a bit, and yet again, read that same register
  253. * just to discard the value. But that's the way the hardware
  254. * seems to like it.
  255. */
  256. iwl_read_prph(trans, OSC_CLK);
  257. iwl_read_prph(trans, OSC_CLK);
  258. iwl_set_bits_prph(trans, OSC_CLK, OSC_CLK_FORCE_CONTROL);
  259. iwl_read_prph(trans, OSC_CLK);
  260. iwl_read_prph(trans, OSC_CLK);
  261. }
  262. /*
  263. * Enable DMA clock and wait for it to stabilize.
  264. *
  265. * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0"
  266. * bits do not disable clocks. This preserves any hardware
  267. * bits already set by default in "CLK_CTRL_REG" after reset.
  268. */
  269. if (trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  270. iwl_write_prph(trans, APMG_CLK_EN_REG,
  271. APMG_CLK_VAL_DMA_CLK_RQT);
  272. udelay(20);
  273. /* Disable L1-Active */
  274. iwl_set_bits_prph(trans, APMG_PCIDEV_STT_REG,
  275. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  276. /* Clear the interrupt in APMG if the NIC is in RFKILL */
  277. iwl_write_prph(trans, APMG_RTC_INT_STT_REG,
  278. APMG_RTC_INT_STT_RFKILL);
  279. }
  280. set_bit(STATUS_DEVICE_ENABLED, &trans->status);
  281. out:
  282. return ret;
  283. }
  284. /*
  285. * Enable LP XTAL to avoid HW bug where device may consume much power if
  286. * FW is not loaded after device reset. LP XTAL is disabled by default
  287. * after device HW reset. Do it only if XTAL is fed by internal source.
  288. * Configure device's "persistence" mode to avoid resetting XTAL again when
  289. * SHRD_HW_RST occurs in S3.
  290. */
  291. static void iwl_pcie_apm_lp_xtal_enable(struct iwl_trans *trans)
  292. {
  293. int ret;
  294. u32 apmg_gp1_reg;
  295. u32 apmg_xtal_cfg_reg;
  296. u32 dl_cfg_reg;
  297. /* Force XTAL ON */
  298. __iwl_trans_pcie_set_bit(trans, CSR_GP_CNTRL,
  299. CSR_GP_CNTRL_REG_FLAG_XTAL_ON);
  300. /* Reset entire device - do controller reset (results in SHRD_HW_RST) */
  301. iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  302. udelay(10);
  303. /*
  304. * Set "initialization complete" bit to move adapter from
  305. * D0U* --> D0A* (powered-up active) state.
  306. */
  307. iwl_set_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  308. /*
  309. * Wait for clock stabilization; once stabilized, access to
  310. * device-internal resources is possible.
  311. */
  312. ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
  313. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  314. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  315. 25000);
  316. if (WARN_ON(ret < 0)) {
  317. IWL_ERR(trans, "Access time out - failed to enable LP XTAL\n");
  318. /* Release XTAL ON request */
  319. __iwl_trans_pcie_clear_bit(trans, CSR_GP_CNTRL,
  320. CSR_GP_CNTRL_REG_FLAG_XTAL_ON);
  321. return;
  322. }
  323. /*
  324. * Clear "disable persistence" to avoid LP XTAL resetting when
  325. * SHRD_HW_RST is applied in S3.
  326. */
  327. iwl_clear_bits_prph(trans, APMG_PCIDEV_STT_REG,
  328. APMG_PCIDEV_STT_VAL_PERSIST_DIS);
  329. /*
  330. * Force APMG XTAL to be active to prevent its disabling by HW
  331. * caused by APMG idle state.
  332. */
  333. apmg_xtal_cfg_reg = iwl_trans_pcie_read_shr(trans,
  334. SHR_APMG_XTAL_CFG_REG);
  335. iwl_trans_pcie_write_shr(trans, SHR_APMG_XTAL_CFG_REG,
  336. apmg_xtal_cfg_reg |
  337. SHR_APMG_XTAL_CFG_XTAL_ON_REQ);
  338. /*
  339. * Reset entire device again - do controller reset (results in
  340. * SHRD_HW_RST). Turn MAC off before proceeding.
  341. */
  342. iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  343. udelay(10);
  344. /* Enable LP XTAL by indirect access through CSR */
  345. apmg_gp1_reg = iwl_trans_pcie_read_shr(trans, SHR_APMG_GP1_REG);
  346. iwl_trans_pcie_write_shr(trans, SHR_APMG_GP1_REG, apmg_gp1_reg |
  347. SHR_APMG_GP1_WF_XTAL_LP_EN |
  348. SHR_APMG_GP1_CHICKEN_BIT_SELECT);
  349. /* Clear delay line clock power up */
  350. dl_cfg_reg = iwl_trans_pcie_read_shr(trans, SHR_APMG_DL_CFG_REG);
  351. iwl_trans_pcie_write_shr(trans, SHR_APMG_DL_CFG_REG, dl_cfg_reg &
  352. ~SHR_APMG_DL_CFG_DL_CLOCK_POWER_UP);
  353. /*
  354. * Enable persistence mode to avoid LP XTAL resetting when
  355. * SHRD_HW_RST is applied in S3.
  356. */
  357. iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
  358. CSR_HW_IF_CONFIG_REG_PERSIST_MODE);
  359. /*
  360. * Clear "initialization complete" bit to move adapter from
  361. * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
  362. */
  363. iwl_clear_bit(trans, CSR_GP_CNTRL,
  364. CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  365. /* Activates XTAL resources monitor */
  366. __iwl_trans_pcie_set_bit(trans, CSR_MONITOR_CFG_REG,
  367. CSR_MONITOR_XTAL_RESOURCES);
  368. /* Release XTAL ON request */
  369. __iwl_trans_pcie_clear_bit(trans, CSR_GP_CNTRL,
  370. CSR_GP_CNTRL_REG_FLAG_XTAL_ON);
  371. udelay(10);
  372. /* Release APMG XTAL */
  373. iwl_trans_pcie_write_shr(trans, SHR_APMG_XTAL_CFG_REG,
  374. apmg_xtal_cfg_reg &
  375. ~SHR_APMG_XTAL_CFG_XTAL_ON_REQ);
  376. }
  377. static int iwl_pcie_apm_stop_master(struct iwl_trans *trans)
  378. {
  379. int ret = 0;
  380. /* stop device's busmaster DMA activity */
  381. iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  382. ret = iwl_poll_bit(trans, CSR_RESET,
  383. CSR_RESET_REG_FLAG_MASTER_DISABLED,
  384. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  385. if (ret < 0)
  386. IWL_WARN(trans, "Master Disable Timed Out, 100 usec\n");
  387. IWL_DEBUG_INFO(trans, "stop master\n");
  388. return ret;
  389. }
  390. static void iwl_pcie_apm_stop(struct iwl_trans *trans, bool op_mode_leave)
  391. {
  392. IWL_DEBUG_INFO(trans, "Stop card, put in low power state\n");
  393. if (op_mode_leave) {
  394. if (!test_bit(STATUS_DEVICE_ENABLED, &trans->status))
  395. iwl_pcie_apm_init(trans);
  396. /* inform ME that we are leaving */
  397. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_7000)
  398. iwl_set_bits_prph(trans, APMG_PCIDEV_STT_REG,
  399. APMG_PCIDEV_STT_VAL_WAKE_ME);
  400. else if (trans->cfg->device_family == IWL_DEVICE_FAMILY_8000)
  401. iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
  402. CSR_HW_IF_CONFIG_REG_PREPARE |
  403. CSR_HW_IF_CONFIG_REG_ENABLE_PME);
  404. mdelay(5);
  405. }
  406. clear_bit(STATUS_DEVICE_ENABLED, &trans->status);
  407. /* Stop device's DMA activity */
  408. iwl_pcie_apm_stop_master(trans);
  409. if (trans->cfg->lp_xtal_workaround) {
  410. iwl_pcie_apm_lp_xtal_enable(trans);
  411. return;
  412. }
  413. /* Reset the entire device */
  414. iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  415. udelay(10);
  416. /*
  417. * Clear "initialization complete" bit to move adapter from
  418. * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
  419. */
  420. iwl_clear_bit(trans, CSR_GP_CNTRL,
  421. CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  422. }
  423. static int iwl_pcie_nic_init(struct iwl_trans *trans)
  424. {
  425. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  426. /* nic_init */
  427. spin_lock(&trans_pcie->irq_lock);
  428. iwl_pcie_apm_init(trans);
  429. spin_unlock(&trans_pcie->irq_lock);
  430. if (trans->cfg->device_family != IWL_DEVICE_FAMILY_8000)
  431. iwl_pcie_set_pwr(trans, false);
  432. iwl_op_mode_nic_config(trans->op_mode);
  433. /* Allocate the RX queue, or reset if it is already allocated */
  434. iwl_pcie_rx_init(trans);
  435. /* Allocate or reset and init all Tx and Command queues */
  436. if (iwl_pcie_tx_init(trans))
  437. return -ENOMEM;
  438. if (trans->cfg->base_params->shadow_reg_enable) {
  439. /* enable shadow regs in HW */
  440. iwl_set_bit(trans, CSR_MAC_SHADOW_REG_CTRL, 0x800FFFFF);
  441. IWL_DEBUG_INFO(trans, "Enabling shadow registers in device\n");
  442. }
  443. return 0;
  444. }
  445. #define HW_READY_TIMEOUT (50)
  446. /* Note: returns poll_bit return value, which is >= 0 if success */
  447. static int iwl_pcie_set_hw_ready(struct iwl_trans *trans)
  448. {
  449. int ret;
  450. iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
  451. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  452. /* See if we got it */
  453. ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG,
  454. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  455. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  456. HW_READY_TIMEOUT);
  457. if (ret >= 0)
  458. iwl_set_bit(trans, CSR_MBOX_SET_REG, CSR_MBOX_SET_REG_OS_ALIVE);
  459. IWL_DEBUG_INFO(trans, "hardware%s ready\n", ret < 0 ? " not" : "");
  460. return ret;
  461. }
  462. /* Note: returns standard 0/-ERROR code */
  463. static int iwl_pcie_prepare_card_hw(struct iwl_trans *trans)
  464. {
  465. int ret;
  466. int t = 0;
  467. int iter;
  468. IWL_DEBUG_INFO(trans, "iwl_trans_prepare_card_hw enter\n");
  469. ret = iwl_pcie_set_hw_ready(trans);
  470. /* If the card is ready, exit 0 */
  471. if (ret >= 0)
  472. return 0;
  473. for (iter = 0; iter < 10; iter++) {
  474. /* If HW is not ready, prepare the conditions to check again */
  475. iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
  476. CSR_HW_IF_CONFIG_REG_PREPARE);
  477. do {
  478. ret = iwl_pcie_set_hw_ready(trans);
  479. if (ret >= 0)
  480. return 0;
  481. usleep_range(200, 1000);
  482. t += 200;
  483. } while (t < 150000);
  484. msleep(25);
  485. }
  486. IWL_ERR(trans, "Couldn't prepare the card\n");
  487. return ret;
  488. }
  489. /*
  490. * ucode
  491. */
  492. static int iwl_pcie_load_firmware_chunk(struct iwl_trans *trans, u32 dst_addr,
  493. dma_addr_t phy_addr, u32 byte_cnt)
  494. {
  495. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  496. int ret;
  497. trans_pcie->ucode_write_complete = false;
  498. iwl_write_direct32(trans,
  499. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  500. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
  501. iwl_write_direct32(trans,
  502. FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL),
  503. dst_addr);
  504. iwl_write_direct32(trans,
  505. FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
  506. phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
  507. iwl_write_direct32(trans,
  508. FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL),
  509. (iwl_get_dma_hi_addr(phy_addr)
  510. << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt);
  511. iwl_write_direct32(trans,
  512. FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
  513. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
  514. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
  515. FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
  516. iwl_write_direct32(trans,
  517. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  518. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  519. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE |
  520. FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
  521. ret = wait_event_timeout(trans_pcie->ucode_write_waitq,
  522. trans_pcie->ucode_write_complete, 5 * HZ);
  523. if (!ret) {
  524. IWL_ERR(trans, "Failed to load firmware chunk!\n");
  525. return -ETIMEDOUT;
  526. }
  527. return 0;
  528. }
  529. static int iwl_pcie_load_section(struct iwl_trans *trans, u8 section_num,
  530. const struct fw_desc *section)
  531. {
  532. u8 *v_addr;
  533. dma_addr_t p_addr;
  534. u32 offset, chunk_sz = min_t(u32, FH_MEM_TB_MAX_LENGTH, section->len);
  535. int ret = 0;
  536. IWL_DEBUG_FW(trans, "[%d] uCode section being loaded...\n",
  537. section_num);
  538. v_addr = dma_alloc_coherent(trans->dev, chunk_sz, &p_addr,
  539. GFP_KERNEL | __GFP_NOWARN);
  540. if (!v_addr) {
  541. IWL_DEBUG_INFO(trans, "Falling back to small chunks of DMA\n");
  542. chunk_sz = PAGE_SIZE;
  543. v_addr = dma_alloc_coherent(trans->dev, chunk_sz,
  544. &p_addr, GFP_KERNEL);
  545. if (!v_addr)
  546. return -ENOMEM;
  547. }
  548. for (offset = 0; offset < section->len; offset += chunk_sz) {
  549. u32 copy_size, dst_addr;
  550. bool extended_addr = false;
  551. copy_size = min_t(u32, chunk_sz, section->len - offset);
  552. dst_addr = section->offset + offset;
  553. if (dst_addr >= IWL_FW_MEM_EXTENDED_START &&
  554. dst_addr <= IWL_FW_MEM_EXTENDED_END)
  555. extended_addr = true;
  556. if (extended_addr)
  557. iwl_set_bits_prph(trans, LMPM_CHICK,
  558. LMPM_CHICK_EXTENDED_ADDR_SPACE);
  559. memcpy(v_addr, (u8 *)section->data + offset, copy_size);
  560. ret = iwl_pcie_load_firmware_chunk(trans, dst_addr, p_addr,
  561. copy_size);
  562. if (extended_addr)
  563. iwl_clear_bits_prph(trans, LMPM_CHICK,
  564. LMPM_CHICK_EXTENDED_ADDR_SPACE);
  565. if (ret) {
  566. IWL_ERR(trans,
  567. "Could not load the [%d] uCode section\n",
  568. section_num);
  569. break;
  570. }
  571. }
  572. dma_free_coherent(trans->dev, chunk_sz, v_addr, p_addr);
  573. return ret;
  574. }
  575. /*
  576. * Driver Takes the ownership on secure machine before FW load
  577. * and prevent race with the BT load.
  578. * W/A for ROM bug. (should be remove in the next Si step)
  579. */
  580. static int iwl_pcie_rsa_race_bug_wa(struct iwl_trans *trans)
  581. {
  582. u32 val, loop = 1000;
  583. /*
  584. * Check the RSA semaphore is accessible.
  585. * If the HW isn't locked and the rsa semaphore isn't accessible,
  586. * we are in trouble.
  587. */
  588. val = iwl_read_prph(trans, PREG_AUX_BUS_WPROT_0);
  589. if (val & (BIT(1) | BIT(17))) {
  590. IWL_INFO(trans,
  591. "can't access the RSA semaphore it is write protected\n");
  592. return 0;
  593. }
  594. /* take ownership on the AUX IF */
  595. iwl_write_prph(trans, WFPM_CTRL_REG, WFPM_AUX_CTL_AUX_IF_MAC_OWNER_MSK);
  596. iwl_write_prph(trans, AUX_MISC_MASTER1_EN, AUX_MISC_MASTER1_EN_SBE_MSK);
  597. do {
  598. iwl_write_prph(trans, AUX_MISC_MASTER1_SMPHR_STATUS, 0x1);
  599. val = iwl_read_prph(trans, AUX_MISC_MASTER1_SMPHR_STATUS);
  600. if (val == 0x1) {
  601. iwl_write_prph(trans, RSA_ENABLE, 0);
  602. return 0;
  603. }
  604. udelay(10);
  605. loop--;
  606. } while (loop > 0);
  607. IWL_ERR(trans, "Failed to take ownership on secure machine\n");
  608. return -EIO;
  609. }
  610. static int iwl_pcie_load_cpu_sections_8000(struct iwl_trans *trans,
  611. const struct fw_img *image,
  612. int cpu,
  613. int *first_ucode_section)
  614. {
  615. int shift_param;
  616. int i, ret = 0, sec_num = 0x1;
  617. u32 val, last_read_idx = 0;
  618. if (cpu == 1) {
  619. shift_param = 0;
  620. *first_ucode_section = 0;
  621. } else {
  622. shift_param = 16;
  623. (*first_ucode_section)++;
  624. }
  625. for (i = *first_ucode_section; i < IWL_UCODE_SECTION_MAX; i++) {
  626. last_read_idx = i;
  627. if (!image->sec[i].data ||
  628. image->sec[i].offset == CPU1_CPU2_SEPARATOR_SECTION) {
  629. IWL_DEBUG_FW(trans,
  630. "Break since Data not valid or Empty section, sec = %d\n",
  631. i);
  632. break;
  633. }
  634. ret = iwl_pcie_load_section(trans, i, &image->sec[i]);
  635. if (ret)
  636. return ret;
  637. /* Notify the ucode of the loaded section number and status */
  638. val = iwl_read_direct32(trans, FH_UCODE_LOAD_STATUS);
  639. val = val | (sec_num << shift_param);
  640. iwl_write_direct32(trans, FH_UCODE_LOAD_STATUS, val);
  641. sec_num = (sec_num << 1) | 0x1;
  642. }
  643. *first_ucode_section = last_read_idx;
  644. if (cpu == 1)
  645. iwl_write_direct32(trans, FH_UCODE_LOAD_STATUS, 0xFFFF);
  646. else
  647. iwl_write_direct32(trans, FH_UCODE_LOAD_STATUS, 0xFFFFFFFF);
  648. return 0;
  649. }
  650. static int iwl_pcie_load_cpu_sections(struct iwl_trans *trans,
  651. const struct fw_img *image,
  652. int cpu,
  653. int *first_ucode_section)
  654. {
  655. int shift_param;
  656. int i, ret = 0;
  657. u32 last_read_idx = 0;
  658. if (cpu == 1) {
  659. shift_param = 0;
  660. *first_ucode_section = 0;
  661. } else {
  662. shift_param = 16;
  663. (*first_ucode_section)++;
  664. }
  665. for (i = *first_ucode_section; i < IWL_UCODE_SECTION_MAX; i++) {
  666. last_read_idx = i;
  667. if (!image->sec[i].data ||
  668. image->sec[i].offset == CPU1_CPU2_SEPARATOR_SECTION) {
  669. IWL_DEBUG_FW(trans,
  670. "Break since Data not valid or Empty section, sec = %d\n",
  671. i);
  672. break;
  673. }
  674. ret = iwl_pcie_load_section(trans, i, &image->sec[i]);
  675. if (ret)
  676. return ret;
  677. }
  678. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_8000)
  679. iwl_set_bits_prph(trans,
  680. CSR_UCODE_LOAD_STATUS_ADDR,
  681. (LMPM_CPU_UCODE_LOADING_COMPLETED |
  682. LMPM_CPU_HDRS_LOADING_COMPLETED |
  683. LMPM_CPU_UCODE_LOADING_STARTED) <<
  684. shift_param);
  685. *first_ucode_section = last_read_idx;
  686. return 0;
  687. }
  688. static void iwl_pcie_apply_destination(struct iwl_trans *trans)
  689. {
  690. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  691. const struct iwl_fw_dbg_dest_tlv *dest = trans->dbg_dest_tlv;
  692. int i;
  693. if (dest->version)
  694. IWL_ERR(trans,
  695. "DBG DEST version is %d - expect issues\n",
  696. dest->version);
  697. IWL_INFO(trans, "Applying debug destination %s\n",
  698. get_fw_dbg_mode_string(dest->monitor_mode));
  699. if (dest->monitor_mode == EXTERNAL_MODE)
  700. iwl_pcie_alloc_fw_monitor(trans);
  701. else
  702. IWL_WARN(trans, "PCI should have external buffer debug\n");
  703. for (i = 0; i < trans->dbg_dest_reg_num; i++) {
  704. u32 addr = le32_to_cpu(dest->reg_ops[i].addr);
  705. u32 val = le32_to_cpu(dest->reg_ops[i].val);
  706. switch (dest->reg_ops[i].op) {
  707. case CSR_ASSIGN:
  708. iwl_write32(trans, addr, val);
  709. break;
  710. case CSR_SETBIT:
  711. iwl_set_bit(trans, addr, BIT(val));
  712. break;
  713. case CSR_CLEARBIT:
  714. iwl_clear_bit(trans, addr, BIT(val));
  715. break;
  716. case PRPH_ASSIGN:
  717. iwl_write_prph(trans, addr, val);
  718. break;
  719. case PRPH_SETBIT:
  720. iwl_set_bits_prph(trans, addr, BIT(val));
  721. break;
  722. case PRPH_CLEARBIT:
  723. iwl_clear_bits_prph(trans, addr, BIT(val));
  724. break;
  725. default:
  726. IWL_ERR(trans, "FW debug - unknown OP %d\n",
  727. dest->reg_ops[i].op);
  728. break;
  729. }
  730. }
  731. if (dest->monitor_mode == EXTERNAL_MODE && trans_pcie->fw_mon_size) {
  732. iwl_write_prph(trans, le32_to_cpu(dest->base_reg),
  733. trans_pcie->fw_mon_phys >> dest->base_shift);
  734. iwl_write_prph(trans, le32_to_cpu(dest->end_reg),
  735. (trans_pcie->fw_mon_phys +
  736. trans_pcie->fw_mon_size) >> dest->end_shift);
  737. }
  738. }
  739. static int iwl_pcie_load_given_ucode(struct iwl_trans *trans,
  740. const struct fw_img *image)
  741. {
  742. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  743. int ret = 0;
  744. int first_ucode_section;
  745. IWL_DEBUG_FW(trans, "working with %s CPU\n",
  746. image->is_dual_cpus ? "Dual" : "Single");
  747. /* load to FW the binary non secured sections of CPU1 */
  748. ret = iwl_pcie_load_cpu_sections(trans, image, 1, &first_ucode_section);
  749. if (ret)
  750. return ret;
  751. if (image->is_dual_cpus) {
  752. /* set CPU2 header address */
  753. iwl_write_prph(trans,
  754. LMPM_SECURE_UCODE_LOAD_CPU2_HDR_ADDR,
  755. LMPM_SECURE_CPU2_HDR_MEM_SPACE);
  756. /* load to FW the binary sections of CPU2 */
  757. ret = iwl_pcie_load_cpu_sections(trans, image, 2,
  758. &first_ucode_section);
  759. if (ret)
  760. return ret;
  761. }
  762. /* supported for 7000 only for the moment */
  763. if (iwlwifi_mod_params.fw_monitor &&
  764. trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
  765. iwl_pcie_alloc_fw_monitor(trans);
  766. if (trans_pcie->fw_mon_size) {
  767. iwl_write_prph(trans, MON_BUFF_BASE_ADDR,
  768. trans_pcie->fw_mon_phys >> 4);
  769. iwl_write_prph(trans, MON_BUFF_END_ADDR,
  770. (trans_pcie->fw_mon_phys +
  771. trans_pcie->fw_mon_size) >> 4);
  772. }
  773. } else if (trans->dbg_dest_tlv) {
  774. iwl_pcie_apply_destination(trans);
  775. }
  776. /* release CPU reset */
  777. iwl_write32(trans, CSR_RESET, 0);
  778. return 0;
  779. }
  780. static int iwl_pcie_load_given_ucode_8000(struct iwl_trans *trans,
  781. const struct fw_img *image)
  782. {
  783. int ret = 0;
  784. int first_ucode_section;
  785. IWL_DEBUG_FW(trans, "working with %s CPU\n",
  786. image->is_dual_cpus ? "Dual" : "Single");
  787. if (trans->dbg_dest_tlv)
  788. iwl_pcie_apply_destination(trans);
  789. /* TODO: remove in the next Si step */
  790. ret = iwl_pcie_rsa_race_bug_wa(trans);
  791. if (ret)
  792. return ret;
  793. /* configure the ucode to be ready to get the secured image */
  794. /* release CPU reset */
  795. iwl_write_prph(trans, RELEASE_CPU_RESET, RELEASE_CPU_RESET_BIT);
  796. /* load to FW the binary Secured sections of CPU1 */
  797. ret = iwl_pcie_load_cpu_sections_8000(trans, image, 1,
  798. &first_ucode_section);
  799. if (ret)
  800. return ret;
  801. /* load to FW the binary sections of CPU2 */
  802. ret = iwl_pcie_load_cpu_sections_8000(trans, image, 2,
  803. &first_ucode_section);
  804. if (ret)
  805. return ret;
  806. return 0;
  807. }
  808. static int iwl_trans_pcie_start_fw(struct iwl_trans *trans,
  809. const struct fw_img *fw, bool run_in_rfkill)
  810. {
  811. int ret;
  812. bool hw_rfkill;
  813. /* This may fail if AMT took ownership of the device */
  814. if (iwl_pcie_prepare_card_hw(trans)) {
  815. IWL_WARN(trans, "Exit HW not ready\n");
  816. return -EIO;
  817. }
  818. iwl_enable_rfkill_int(trans);
  819. /* If platform's RF_KILL switch is NOT set to KILL */
  820. hw_rfkill = iwl_is_rfkill_set(trans);
  821. if (hw_rfkill)
  822. set_bit(STATUS_RFKILL, &trans->status);
  823. else
  824. clear_bit(STATUS_RFKILL, &trans->status);
  825. iwl_trans_pcie_rf_kill(trans, hw_rfkill);
  826. if (hw_rfkill && !run_in_rfkill)
  827. return -ERFKILL;
  828. iwl_write32(trans, CSR_INT, 0xFFFFFFFF);
  829. ret = iwl_pcie_nic_init(trans);
  830. if (ret) {
  831. IWL_ERR(trans, "Unable to init nic\n");
  832. return ret;
  833. }
  834. /* make sure rfkill handshake bits are cleared */
  835. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  836. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR,
  837. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  838. /* clear (again), then enable host interrupts */
  839. iwl_write32(trans, CSR_INT, 0xFFFFFFFF);
  840. iwl_enable_interrupts(trans);
  841. /* really make sure rfkill handshake bits are cleared */
  842. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  843. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  844. /* Load the given image to the HW */
  845. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_8000)
  846. return iwl_pcie_load_given_ucode_8000(trans, fw);
  847. else
  848. return iwl_pcie_load_given_ucode(trans, fw);
  849. }
  850. static void iwl_trans_pcie_fw_alive(struct iwl_trans *trans, u32 scd_addr)
  851. {
  852. iwl_pcie_reset_ict(trans);
  853. iwl_pcie_tx_start(trans, scd_addr);
  854. }
  855. static void iwl_trans_pcie_stop_device(struct iwl_trans *trans, bool low_power)
  856. {
  857. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  858. bool hw_rfkill, was_hw_rfkill;
  859. was_hw_rfkill = iwl_is_rfkill_set(trans);
  860. /* tell the device to stop sending interrupts */
  861. spin_lock(&trans_pcie->irq_lock);
  862. iwl_disable_interrupts(trans);
  863. spin_unlock(&trans_pcie->irq_lock);
  864. /* device going down, Stop using ICT table */
  865. iwl_pcie_disable_ict(trans);
  866. /*
  867. * If a HW restart happens during firmware loading,
  868. * then the firmware loading might call this function
  869. * and later it might be called again due to the
  870. * restart. So don't process again if the device is
  871. * already dead.
  872. */
  873. if (test_and_clear_bit(STATUS_DEVICE_ENABLED, &trans->status)) {
  874. IWL_DEBUG_INFO(trans, "DEVICE_ENABLED bit was set and is now cleared\n");
  875. iwl_pcie_tx_stop(trans);
  876. iwl_pcie_rx_stop(trans);
  877. /* Power-down device's busmaster DMA clocks */
  878. if (trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  879. iwl_write_prph(trans, APMG_CLK_DIS_REG,
  880. APMG_CLK_VAL_DMA_CLK_RQT);
  881. udelay(5);
  882. }
  883. }
  884. /* Make sure (redundant) we've released our request to stay awake */
  885. iwl_clear_bit(trans, CSR_GP_CNTRL,
  886. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  887. /* Stop the device, and put it in low power state */
  888. iwl_pcie_apm_stop(trans, false);
  889. /* stop and reset the on-board processor */
  890. iwl_write32(trans, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  891. udelay(20);
  892. /*
  893. * Upon stop, the APM issues an interrupt if HW RF kill is set.
  894. * This is a bug in certain verions of the hardware.
  895. * Certain devices also keep sending HW RF kill interrupt all
  896. * the time, unless the interrupt is ACKed even if the interrupt
  897. * should be masked. Re-ACK all the interrupts here.
  898. */
  899. spin_lock(&trans_pcie->irq_lock);
  900. iwl_disable_interrupts(trans);
  901. spin_unlock(&trans_pcie->irq_lock);
  902. /* clear all status bits */
  903. clear_bit(STATUS_SYNC_HCMD_ACTIVE, &trans->status);
  904. clear_bit(STATUS_INT_ENABLED, &trans->status);
  905. clear_bit(STATUS_TPOWER_PMI, &trans->status);
  906. clear_bit(STATUS_RFKILL, &trans->status);
  907. /*
  908. * Even if we stop the HW, we still want the RF kill
  909. * interrupt
  910. */
  911. iwl_enable_rfkill_int(trans);
  912. /*
  913. * Check again since the RF kill state may have changed while
  914. * all the interrupts were disabled, in this case we couldn't
  915. * receive the RF kill interrupt and update the state in the
  916. * op_mode.
  917. * Don't call the op_mode if the rkfill state hasn't changed.
  918. * This allows the op_mode to call stop_device from the rfkill
  919. * notification without endless recursion. Under very rare
  920. * circumstances, we might have a small recursion if the rfkill
  921. * state changed exactly now while we were called from stop_device.
  922. * This is very unlikely but can happen and is supported.
  923. */
  924. hw_rfkill = iwl_is_rfkill_set(trans);
  925. if (hw_rfkill)
  926. set_bit(STATUS_RFKILL, &trans->status);
  927. else
  928. clear_bit(STATUS_RFKILL, &trans->status);
  929. if (hw_rfkill != was_hw_rfkill)
  930. iwl_trans_pcie_rf_kill(trans, hw_rfkill);
  931. /* re-take ownership to prevent other users from stealing the deivce */
  932. iwl_pcie_prepare_card_hw(trans);
  933. }
  934. void iwl_trans_pcie_rf_kill(struct iwl_trans *trans, bool state)
  935. {
  936. if (iwl_op_mode_hw_rf_kill(trans->op_mode, state))
  937. iwl_trans_pcie_stop_device(trans, true);
  938. }
  939. static void iwl_trans_pcie_d3_suspend(struct iwl_trans *trans, bool test)
  940. {
  941. iwl_disable_interrupts(trans);
  942. /*
  943. * in testing mode, the host stays awake and the
  944. * hardware won't be reset (not even partially)
  945. */
  946. if (test)
  947. return;
  948. iwl_pcie_disable_ict(trans);
  949. iwl_clear_bit(trans, CSR_GP_CNTRL,
  950. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  951. iwl_clear_bit(trans, CSR_GP_CNTRL,
  952. CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  953. /*
  954. * reset TX queues -- some of their registers reset during S3
  955. * so if we don't reset everything here the D3 image would try
  956. * to execute some invalid memory upon resume
  957. */
  958. iwl_trans_pcie_tx_reset(trans);
  959. iwl_pcie_set_pwr(trans, true);
  960. }
  961. static int iwl_trans_pcie_d3_resume(struct iwl_trans *trans,
  962. enum iwl_d3_status *status,
  963. bool test)
  964. {
  965. u32 val;
  966. int ret;
  967. if (test) {
  968. iwl_enable_interrupts(trans);
  969. *status = IWL_D3_STATUS_ALIVE;
  970. return 0;
  971. }
  972. /*
  973. * Also enables interrupts - none will happen as the device doesn't
  974. * know we're waking it up, only when the opmode actually tells it
  975. * after this call.
  976. */
  977. iwl_pcie_reset_ict(trans);
  978. iwl_set_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  979. iwl_set_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  980. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_8000)
  981. udelay(2);
  982. ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
  983. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  984. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  985. 25000);
  986. if (ret < 0) {
  987. IWL_ERR(trans, "Failed to resume the device (mac ready)\n");
  988. return ret;
  989. }
  990. iwl_pcie_set_pwr(trans, false);
  991. iwl_trans_pcie_tx_reset(trans);
  992. ret = iwl_pcie_rx_init(trans);
  993. if (ret) {
  994. IWL_ERR(trans, "Failed to resume the device (RX reset)\n");
  995. return ret;
  996. }
  997. val = iwl_read32(trans, CSR_RESET);
  998. if (val & CSR_RESET_REG_FLAG_NEVO_RESET)
  999. *status = IWL_D3_STATUS_RESET;
  1000. else
  1001. *status = IWL_D3_STATUS_ALIVE;
  1002. return 0;
  1003. }
  1004. static int iwl_trans_pcie_start_hw(struct iwl_trans *trans, bool low_power)
  1005. {
  1006. bool hw_rfkill;
  1007. int err;
  1008. err = iwl_pcie_prepare_card_hw(trans);
  1009. if (err) {
  1010. IWL_ERR(trans, "Error while preparing HW: %d\n", err);
  1011. return err;
  1012. }
  1013. /* Reset the entire device */
  1014. iwl_write32(trans, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  1015. usleep_range(10, 15);
  1016. iwl_pcie_apm_init(trans);
  1017. /* From now on, the op_mode will be kept updated about RF kill state */
  1018. iwl_enable_rfkill_int(trans);
  1019. hw_rfkill = iwl_is_rfkill_set(trans);
  1020. if (hw_rfkill)
  1021. set_bit(STATUS_RFKILL, &trans->status);
  1022. else
  1023. clear_bit(STATUS_RFKILL, &trans->status);
  1024. iwl_trans_pcie_rf_kill(trans, hw_rfkill);
  1025. return 0;
  1026. }
  1027. static void iwl_trans_pcie_op_mode_leave(struct iwl_trans *trans)
  1028. {
  1029. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1030. /* disable interrupts - don't enable HW RF kill interrupt */
  1031. spin_lock(&trans_pcie->irq_lock);
  1032. iwl_disable_interrupts(trans);
  1033. spin_unlock(&trans_pcie->irq_lock);
  1034. iwl_pcie_apm_stop(trans, true);
  1035. spin_lock(&trans_pcie->irq_lock);
  1036. iwl_disable_interrupts(trans);
  1037. spin_unlock(&trans_pcie->irq_lock);
  1038. iwl_pcie_disable_ict(trans);
  1039. }
  1040. static void iwl_trans_pcie_write8(struct iwl_trans *trans, u32 ofs, u8 val)
  1041. {
  1042. writeb(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  1043. }
  1044. static void iwl_trans_pcie_write32(struct iwl_trans *trans, u32 ofs, u32 val)
  1045. {
  1046. writel(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  1047. }
  1048. static u32 iwl_trans_pcie_read32(struct iwl_trans *trans, u32 ofs)
  1049. {
  1050. return readl(IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  1051. }
  1052. static u32 iwl_trans_pcie_read_prph(struct iwl_trans *trans, u32 reg)
  1053. {
  1054. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_RADDR,
  1055. ((reg & 0x000FFFFF) | (3 << 24)));
  1056. return iwl_trans_pcie_read32(trans, HBUS_TARG_PRPH_RDAT);
  1057. }
  1058. static void iwl_trans_pcie_write_prph(struct iwl_trans *trans, u32 addr,
  1059. u32 val)
  1060. {
  1061. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_WADDR,
  1062. ((addr & 0x000FFFFF) | (3 << 24)));
  1063. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_WDAT, val);
  1064. }
  1065. static int iwl_pcie_dummy_napi_poll(struct napi_struct *napi, int budget)
  1066. {
  1067. WARN_ON(1);
  1068. return 0;
  1069. }
  1070. static void iwl_trans_pcie_configure(struct iwl_trans *trans,
  1071. const struct iwl_trans_config *trans_cfg)
  1072. {
  1073. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1074. trans_pcie->cmd_queue = trans_cfg->cmd_queue;
  1075. trans_pcie->cmd_fifo = trans_cfg->cmd_fifo;
  1076. trans_pcie->cmd_q_wdg_timeout = trans_cfg->cmd_q_wdg_timeout;
  1077. if (WARN_ON(trans_cfg->n_no_reclaim_cmds > MAX_NO_RECLAIM_CMDS))
  1078. trans_pcie->n_no_reclaim_cmds = 0;
  1079. else
  1080. trans_pcie->n_no_reclaim_cmds = trans_cfg->n_no_reclaim_cmds;
  1081. if (trans_pcie->n_no_reclaim_cmds)
  1082. memcpy(trans_pcie->no_reclaim_cmds, trans_cfg->no_reclaim_cmds,
  1083. trans_pcie->n_no_reclaim_cmds * sizeof(u8));
  1084. trans_pcie->rx_buf_size_8k = trans_cfg->rx_buf_size_8k;
  1085. if (trans_pcie->rx_buf_size_8k)
  1086. trans_pcie->rx_page_order = get_order(8 * 1024);
  1087. else
  1088. trans_pcie->rx_page_order = get_order(4 * 1024);
  1089. trans_pcie->command_names = trans_cfg->command_names;
  1090. trans_pcie->bc_table_dword = trans_cfg->bc_table_dword;
  1091. trans_pcie->scd_set_active = trans_cfg->scd_set_active;
  1092. /* init ref_count to 1 (should be cleared when ucode is loaded) */
  1093. trans_pcie->ref_count = 1;
  1094. /* Initialize NAPI here - it should be before registering to mac80211
  1095. * in the opmode but after the HW struct is allocated.
  1096. * As this function may be called again in some corner cases don't
  1097. * do anything if NAPI was already initialized.
  1098. */
  1099. if (!trans_pcie->napi.poll && trans->op_mode->ops->napi_add) {
  1100. init_dummy_netdev(&trans_pcie->napi_dev);
  1101. iwl_op_mode_napi_add(trans->op_mode, &trans_pcie->napi,
  1102. &trans_pcie->napi_dev,
  1103. iwl_pcie_dummy_napi_poll, 64);
  1104. }
  1105. }
  1106. void iwl_trans_pcie_free(struct iwl_trans *trans)
  1107. {
  1108. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1109. synchronize_irq(trans_pcie->pci_dev->irq);
  1110. iwl_pcie_tx_free(trans);
  1111. iwl_pcie_rx_free(trans);
  1112. free_irq(trans_pcie->pci_dev->irq, trans);
  1113. iwl_pcie_free_ict(trans);
  1114. pci_disable_msi(trans_pcie->pci_dev);
  1115. iounmap(trans_pcie->hw_base);
  1116. pci_release_regions(trans_pcie->pci_dev);
  1117. pci_disable_device(trans_pcie->pci_dev);
  1118. kmem_cache_destroy(trans->dev_cmd_pool);
  1119. if (trans_pcie->napi.poll)
  1120. netif_napi_del(&trans_pcie->napi);
  1121. iwl_pcie_free_fw_monitor(trans);
  1122. kfree(trans);
  1123. }
  1124. static void iwl_trans_pcie_set_pmi(struct iwl_trans *trans, bool state)
  1125. {
  1126. if (state)
  1127. set_bit(STATUS_TPOWER_PMI, &trans->status);
  1128. else
  1129. clear_bit(STATUS_TPOWER_PMI, &trans->status);
  1130. }
  1131. static bool iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent,
  1132. unsigned long *flags)
  1133. {
  1134. int ret;
  1135. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1136. spin_lock_irqsave(&trans_pcie->reg_lock, *flags);
  1137. if (trans_pcie->cmd_hold_nic_awake)
  1138. goto out;
  1139. /* this bit wakes up the NIC */
  1140. __iwl_trans_pcie_set_bit(trans, CSR_GP_CNTRL,
  1141. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  1142. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_8000)
  1143. udelay(2);
  1144. /*
  1145. * These bits say the device is running, and should keep running for
  1146. * at least a short while (at least as long as MAC_ACCESS_REQ stays 1),
  1147. * but they do not indicate that embedded SRAM is restored yet;
  1148. * 3945 and 4965 have volatile SRAM, and must save/restore contents
  1149. * to/from host DRAM when sleeping/waking for power-saving.
  1150. * Each direction takes approximately 1/4 millisecond; with this
  1151. * overhead, it's a good idea to grab and hold MAC_ACCESS_REQUEST if a
  1152. * series of register accesses are expected (e.g. reading Event Log),
  1153. * to keep device from sleeping.
  1154. *
  1155. * CSR_UCODE_DRV_GP1 register bit MAC_SLEEP == 0 indicates that
  1156. * SRAM is okay/restored. We don't check that here because this call
  1157. * is just for hardware register access; but GP1 MAC_SLEEP check is a
  1158. * good idea before accessing 3945/4965 SRAM (e.g. reading Event Log).
  1159. *
  1160. * 5000 series and later (including 1000 series) have non-volatile SRAM,
  1161. * and do not save/restore SRAM when power cycling.
  1162. */
  1163. ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
  1164. CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
  1165. (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
  1166. CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
  1167. if (unlikely(ret < 0)) {
  1168. iwl_write32(trans, CSR_RESET, CSR_RESET_REG_FLAG_FORCE_NMI);
  1169. if (!silent) {
  1170. u32 val = iwl_read32(trans, CSR_GP_CNTRL);
  1171. WARN_ONCE(1,
  1172. "Timeout waiting for hardware access (CSR_GP_CNTRL 0x%08x)\n",
  1173. val);
  1174. spin_unlock_irqrestore(&trans_pcie->reg_lock, *flags);
  1175. return false;
  1176. }
  1177. }
  1178. out:
  1179. /*
  1180. * Fool sparse by faking we release the lock - sparse will
  1181. * track nic_access anyway.
  1182. */
  1183. __release(&trans_pcie->reg_lock);
  1184. return true;
  1185. }
  1186. static void iwl_trans_pcie_release_nic_access(struct iwl_trans *trans,
  1187. unsigned long *flags)
  1188. {
  1189. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1190. lockdep_assert_held(&trans_pcie->reg_lock);
  1191. /*
  1192. * Fool sparse by faking we acquiring the lock - sparse will
  1193. * track nic_access anyway.
  1194. */
  1195. __acquire(&trans_pcie->reg_lock);
  1196. if (trans_pcie->cmd_hold_nic_awake)
  1197. goto out;
  1198. __iwl_trans_pcie_clear_bit(trans, CSR_GP_CNTRL,
  1199. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  1200. /*
  1201. * Above we read the CSR_GP_CNTRL register, which will flush
  1202. * any previous writes, but we need the write that clears the
  1203. * MAC_ACCESS_REQ bit to be performed before any other writes
  1204. * scheduled on different CPUs (after we drop reg_lock).
  1205. */
  1206. mmiowb();
  1207. out:
  1208. spin_unlock_irqrestore(&trans_pcie->reg_lock, *flags);
  1209. }
  1210. static int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr,
  1211. void *buf, int dwords)
  1212. {
  1213. unsigned long flags;
  1214. int offs, ret = 0;
  1215. u32 *vals = buf;
  1216. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  1217. iwl_write32(trans, HBUS_TARG_MEM_RADDR, addr);
  1218. for (offs = 0; offs < dwords; offs++)
  1219. vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1220. iwl_trans_release_nic_access(trans, &flags);
  1221. } else {
  1222. ret = -EBUSY;
  1223. }
  1224. return ret;
  1225. }
  1226. static int iwl_trans_pcie_write_mem(struct iwl_trans *trans, u32 addr,
  1227. const void *buf, int dwords)
  1228. {
  1229. unsigned long flags;
  1230. int offs, ret = 0;
  1231. const u32 *vals = buf;
  1232. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  1233. iwl_write32(trans, HBUS_TARG_MEM_WADDR, addr);
  1234. for (offs = 0; offs < dwords; offs++)
  1235. iwl_write32(trans, HBUS_TARG_MEM_WDAT,
  1236. vals ? vals[offs] : 0);
  1237. iwl_trans_release_nic_access(trans, &flags);
  1238. } else {
  1239. ret = -EBUSY;
  1240. }
  1241. return ret;
  1242. }
  1243. static void iwl_trans_pcie_freeze_txq_timer(struct iwl_trans *trans,
  1244. unsigned long txqs,
  1245. bool freeze)
  1246. {
  1247. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1248. int queue;
  1249. for_each_set_bit(queue, &txqs, BITS_PER_LONG) {
  1250. struct iwl_txq *txq = &trans_pcie->txq[queue];
  1251. unsigned long now;
  1252. spin_lock_bh(&txq->lock);
  1253. now = jiffies;
  1254. if (txq->frozen == freeze)
  1255. goto next_queue;
  1256. IWL_DEBUG_TX_QUEUES(trans, "%s TXQ %d\n",
  1257. freeze ? "Freezing" : "Waking", queue);
  1258. txq->frozen = freeze;
  1259. if (txq->q.read_ptr == txq->q.write_ptr)
  1260. goto next_queue;
  1261. if (freeze) {
  1262. if (unlikely(time_after(now,
  1263. txq->stuck_timer.expires))) {
  1264. /*
  1265. * The timer should have fired, maybe it is
  1266. * spinning right now on the lock.
  1267. */
  1268. goto next_queue;
  1269. }
  1270. /* remember how long until the timer fires */
  1271. txq->frozen_expiry_remainder =
  1272. txq->stuck_timer.expires - now;
  1273. del_timer(&txq->stuck_timer);
  1274. goto next_queue;
  1275. }
  1276. /*
  1277. * Wake a non-empty queue -> arm timer with the
  1278. * remainder before it froze
  1279. */
  1280. mod_timer(&txq->stuck_timer,
  1281. now + txq->frozen_expiry_remainder);
  1282. next_queue:
  1283. spin_unlock_bh(&txq->lock);
  1284. }
  1285. }
  1286. #define IWL_FLUSH_WAIT_MS 2000
  1287. static int iwl_trans_pcie_wait_txq_empty(struct iwl_trans *trans, u32 txq_bm)
  1288. {
  1289. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1290. struct iwl_txq *txq;
  1291. struct iwl_queue *q;
  1292. int cnt;
  1293. unsigned long now = jiffies;
  1294. u32 scd_sram_addr;
  1295. u8 buf[16];
  1296. int ret = 0;
  1297. /* waiting for all the tx frames complete might take a while */
  1298. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  1299. u8 wr_ptr;
  1300. if (cnt == trans_pcie->cmd_queue)
  1301. continue;
  1302. if (!test_bit(cnt, trans_pcie->queue_used))
  1303. continue;
  1304. if (!(BIT(cnt) & txq_bm))
  1305. continue;
  1306. IWL_DEBUG_TX_QUEUES(trans, "Emptying queue %d...\n", cnt);
  1307. txq = &trans_pcie->txq[cnt];
  1308. q = &txq->q;
  1309. wr_ptr = ACCESS_ONCE(q->write_ptr);
  1310. while (q->read_ptr != ACCESS_ONCE(q->write_ptr) &&
  1311. !time_after(jiffies,
  1312. now + msecs_to_jiffies(IWL_FLUSH_WAIT_MS))) {
  1313. u8 write_ptr = ACCESS_ONCE(q->write_ptr);
  1314. if (WARN_ONCE(wr_ptr != write_ptr,
  1315. "WR pointer moved while flushing %d -> %d\n",
  1316. wr_ptr, write_ptr))
  1317. return -ETIMEDOUT;
  1318. msleep(1);
  1319. }
  1320. if (q->read_ptr != q->write_ptr) {
  1321. IWL_ERR(trans,
  1322. "fail to flush all tx fifo queues Q %d\n", cnt);
  1323. ret = -ETIMEDOUT;
  1324. break;
  1325. }
  1326. IWL_DEBUG_TX_QUEUES(trans, "Queue %d is now empty.\n", cnt);
  1327. }
  1328. if (!ret)
  1329. return 0;
  1330. IWL_ERR(trans, "Current SW read_ptr %d write_ptr %d\n",
  1331. txq->q.read_ptr, txq->q.write_ptr);
  1332. scd_sram_addr = trans_pcie->scd_base_addr +
  1333. SCD_TX_STTS_QUEUE_OFFSET(txq->q.id);
  1334. iwl_trans_read_mem_bytes(trans, scd_sram_addr, buf, sizeof(buf));
  1335. iwl_print_hex_error(trans, buf, sizeof(buf));
  1336. for (cnt = 0; cnt < FH_TCSR_CHNL_NUM; cnt++)
  1337. IWL_ERR(trans, "FH TRBs(%d) = 0x%08x\n", cnt,
  1338. iwl_read_direct32(trans, FH_TX_TRB_REG(cnt)));
  1339. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  1340. u32 status = iwl_read_prph(trans, SCD_QUEUE_STATUS_BITS(cnt));
  1341. u8 fifo = (status >> SCD_QUEUE_STTS_REG_POS_TXF) & 0x7;
  1342. bool active = !!(status & BIT(SCD_QUEUE_STTS_REG_POS_ACTIVE));
  1343. u32 tbl_dw =
  1344. iwl_trans_read_mem32(trans, trans_pcie->scd_base_addr +
  1345. SCD_TRANS_TBL_OFFSET_QUEUE(cnt));
  1346. if (cnt & 0x1)
  1347. tbl_dw = (tbl_dw & 0xFFFF0000) >> 16;
  1348. else
  1349. tbl_dw = tbl_dw & 0x0000FFFF;
  1350. IWL_ERR(trans,
  1351. "Q %d is %sactive and mapped to fifo %d ra_tid 0x%04x [%d,%d]\n",
  1352. cnt, active ? "" : "in", fifo, tbl_dw,
  1353. iwl_read_prph(trans, SCD_QUEUE_RDPTR(cnt)) &
  1354. (TFD_QUEUE_SIZE_MAX - 1),
  1355. iwl_read_prph(trans, SCD_QUEUE_WRPTR(cnt)));
  1356. }
  1357. return ret;
  1358. }
  1359. static void iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans, u32 reg,
  1360. u32 mask, u32 value)
  1361. {
  1362. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1363. unsigned long flags;
  1364. spin_lock_irqsave(&trans_pcie->reg_lock, flags);
  1365. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, value);
  1366. spin_unlock_irqrestore(&trans_pcie->reg_lock, flags);
  1367. }
  1368. void iwl_trans_pcie_ref(struct iwl_trans *trans)
  1369. {
  1370. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1371. unsigned long flags;
  1372. if (iwlwifi_mod_params.d0i3_disable)
  1373. return;
  1374. spin_lock_irqsave(&trans_pcie->ref_lock, flags);
  1375. IWL_DEBUG_RPM(trans, "ref_counter: %d\n", trans_pcie->ref_count);
  1376. trans_pcie->ref_count++;
  1377. spin_unlock_irqrestore(&trans_pcie->ref_lock, flags);
  1378. }
  1379. void iwl_trans_pcie_unref(struct iwl_trans *trans)
  1380. {
  1381. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1382. unsigned long flags;
  1383. if (iwlwifi_mod_params.d0i3_disable)
  1384. return;
  1385. spin_lock_irqsave(&trans_pcie->ref_lock, flags);
  1386. IWL_DEBUG_RPM(trans, "ref_counter: %d\n", trans_pcie->ref_count);
  1387. if (WARN_ON_ONCE(trans_pcie->ref_count == 0)) {
  1388. spin_unlock_irqrestore(&trans_pcie->ref_lock, flags);
  1389. return;
  1390. }
  1391. trans_pcie->ref_count--;
  1392. spin_unlock_irqrestore(&trans_pcie->ref_lock, flags);
  1393. }
  1394. static const char *get_csr_string(int cmd)
  1395. {
  1396. #define IWL_CMD(x) case x: return #x
  1397. switch (cmd) {
  1398. IWL_CMD(CSR_HW_IF_CONFIG_REG);
  1399. IWL_CMD(CSR_INT_COALESCING);
  1400. IWL_CMD(CSR_INT);
  1401. IWL_CMD(CSR_INT_MASK);
  1402. IWL_CMD(CSR_FH_INT_STATUS);
  1403. IWL_CMD(CSR_GPIO_IN);
  1404. IWL_CMD(CSR_RESET);
  1405. IWL_CMD(CSR_GP_CNTRL);
  1406. IWL_CMD(CSR_HW_REV);
  1407. IWL_CMD(CSR_EEPROM_REG);
  1408. IWL_CMD(CSR_EEPROM_GP);
  1409. IWL_CMD(CSR_OTP_GP_REG);
  1410. IWL_CMD(CSR_GIO_REG);
  1411. IWL_CMD(CSR_GP_UCODE_REG);
  1412. IWL_CMD(CSR_GP_DRIVER_REG);
  1413. IWL_CMD(CSR_UCODE_DRV_GP1);
  1414. IWL_CMD(CSR_UCODE_DRV_GP2);
  1415. IWL_CMD(CSR_LED_REG);
  1416. IWL_CMD(CSR_DRAM_INT_TBL_REG);
  1417. IWL_CMD(CSR_GIO_CHICKEN_BITS);
  1418. IWL_CMD(CSR_ANA_PLL_CFG);
  1419. IWL_CMD(CSR_HW_REV_WA_REG);
  1420. IWL_CMD(CSR_MONITOR_STATUS_REG);
  1421. IWL_CMD(CSR_DBG_HPET_MEM_REG);
  1422. default:
  1423. return "UNKNOWN";
  1424. }
  1425. #undef IWL_CMD
  1426. }
  1427. void iwl_pcie_dump_csr(struct iwl_trans *trans)
  1428. {
  1429. int i;
  1430. static const u32 csr_tbl[] = {
  1431. CSR_HW_IF_CONFIG_REG,
  1432. CSR_INT_COALESCING,
  1433. CSR_INT,
  1434. CSR_INT_MASK,
  1435. CSR_FH_INT_STATUS,
  1436. CSR_GPIO_IN,
  1437. CSR_RESET,
  1438. CSR_GP_CNTRL,
  1439. CSR_HW_REV,
  1440. CSR_EEPROM_REG,
  1441. CSR_EEPROM_GP,
  1442. CSR_OTP_GP_REG,
  1443. CSR_GIO_REG,
  1444. CSR_GP_UCODE_REG,
  1445. CSR_GP_DRIVER_REG,
  1446. CSR_UCODE_DRV_GP1,
  1447. CSR_UCODE_DRV_GP2,
  1448. CSR_LED_REG,
  1449. CSR_DRAM_INT_TBL_REG,
  1450. CSR_GIO_CHICKEN_BITS,
  1451. CSR_ANA_PLL_CFG,
  1452. CSR_MONITOR_STATUS_REG,
  1453. CSR_HW_REV_WA_REG,
  1454. CSR_DBG_HPET_MEM_REG
  1455. };
  1456. IWL_ERR(trans, "CSR values:\n");
  1457. IWL_ERR(trans, "(2nd byte of CSR_INT_COALESCING is "
  1458. "CSR_INT_PERIODIC_REG)\n");
  1459. for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
  1460. IWL_ERR(trans, " %25s: 0X%08x\n",
  1461. get_csr_string(csr_tbl[i]),
  1462. iwl_read32(trans, csr_tbl[i]));
  1463. }
  1464. }
  1465. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1466. /* create and remove of files */
  1467. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  1468. if (!debugfs_create_file(#name, mode, parent, trans, \
  1469. &iwl_dbgfs_##name##_ops)) \
  1470. goto err; \
  1471. } while (0)
  1472. /* file operation */
  1473. #define DEBUGFS_READ_FILE_OPS(name) \
  1474. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  1475. .read = iwl_dbgfs_##name##_read, \
  1476. .open = simple_open, \
  1477. .llseek = generic_file_llseek, \
  1478. };
  1479. #define DEBUGFS_WRITE_FILE_OPS(name) \
  1480. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  1481. .write = iwl_dbgfs_##name##_write, \
  1482. .open = simple_open, \
  1483. .llseek = generic_file_llseek, \
  1484. };
  1485. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  1486. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  1487. .write = iwl_dbgfs_##name##_write, \
  1488. .read = iwl_dbgfs_##name##_read, \
  1489. .open = simple_open, \
  1490. .llseek = generic_file_llseek, \
  1491. };
  1492. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  1493. char __user *user_buf,
  1494. size_t count, loff_t *ppos)
  1495. {
  1496. struct iwl_trans *trans = file->private_data;
  1497. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1498. struct iwl_txq *txq;
  1499. struct iwl_queue *q;
  1500. char *buf;
  1501. int pos = 0;
  1502. int cnt;
  1503. int ret;
  1504. size_t bufsz;
  1505. bufsz = sizeof(char) * 75 * trans->cfg->base_params->num_of_queues;
  1506. if (!trans_pcie->txq)
  1507. return -EAGAIN;
  1508. buf = kzalloc(bufsz, GFP_KERNEL);
  1509. if (!buf)
  1510. return -ENOMEM;
  1511. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  1512. txq = &trans_pcie->txq[cnt];
  1513. q = &txq->q;
  1514. pos += scnprintf(buf + pos, bufsz - pos,
  1515. "hwq %.2d: read=%u write=%u use=%d stop=%d need_update=%d frozen=%d%s\n",
  1516. cnt, q->read_ptr, q->write_ptr,
  1517. !!test_bit(cnt, trans_pcie->queue_used),
  1518. !!test_bit(cnt, trans_pcie->queue_stopped),
  1519. txq->need_update, txq->frozen,
  1520. (cnt == trans_pcie->cmd_queue ? " HCMD" : ""));
  1521. }
  1522. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1523. kfree(buf);
  1524. return ret;
  1525. }
  1526. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  1527. char __user *user_buf,
  1528. size_t count, loff_t *ppos)
  1529. {
  1530. struct iwl_trans *trans = file->private_data;
  1531. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1532. struct iwl_rxq *rxq = &trans_pcie->rxq;
  1533. char buf[256];
  1534. int pos = 0;
  1535. const size_t bufsz = sizeof(buf);
  1536. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  1537. rxq->read);
  1538. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  1539. rxq->write);
  1540. pos += scnprintf(buf + pos, bufsz - pos, "write_actual: %u\n",
  1541. rxq->write_actual);
  1542. pos += scnprintf(buf + pos, bufsz - pos, "need_update: %d\n",
  1543. rxq->need_update);
  1544. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  1545. rxq->free_count);
  1546. if (rxq->rb_stts) {
  1547. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  1548. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  1549. } else {
  1550. pos += scnprintf(buf + pos, bufsz - pos,
  1551. "closed_rb_num: Not Allocated\n");
  1552. }
  1553. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1554. }
  1555. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  1556. char __user *user_buf,
  1557. size_t count, loff_t *ppos)
  1558. {
  1559. struct iwl_trans *trans = file->private_data;
  1560. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1561. struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
  1562. int pos = 0;
  1563. char *buf;
  1564. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  1565. ssize_t ret;
  1566. buf = kzalloc(bufsz, GFP_KERNEL);
  1567. if (!buf)
  1568. return -ENOMEM;
  1569. pos += scnprintf(buf + pos, bufsz - pos,
  1570. "Interrupt Statistics Report:\n");
  1571. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  1572. isr_stats->hw);
  1573. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  1574. isr_stats->sw);
  1575. if (isr_stats->sw || isr_stats->hw) {
  1576. pos += scnprintf(buf + pos, bufsz - pos,
  1577. "\tLast Restarting Code: 0x%X\n",
  1578. isr_stats->err_code);
  1579. }
  1580. #ifdef CONFIG_IWLWIFI_DEBUG
  1581. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  1582. isr_stats->sch);
  1583. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  1584. isr_stats->alive);
  1585. #endif
  1586. pos += scnprintf(buf + pos, bufsz - pos,
  1587. "HW RF KILL switch toggled:\t %u\n", isr_stats->rfkill);
  1588. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  1589. isr_stats->ctkill);
  1590. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  1591. isr_stats->wakeup);
  1592. pos += scnprintf(buf + pos, bufsz - pos,
  1593. "Rx command responses:\t\t %u\n", isr_stats->rx);
  1594. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  1595. isr_stats->tx);
  1596. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  1597. isr_stats->unhandled);
  1598. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1599. kfree(buf);
  1600. return ret;
  1601. }
  1602. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  1603. const char __user *user_buf,
  1604. size_t count, loff_t *ppos)
  1605. {
  1606. struct iwl_trans *trans = file->private_data;
  1607. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1608. struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
  1609. char buf[8];
  1610. int buf_size;
  1611. u32 reset_flag;
  1612. memset(buf, 0, sizeof(buf));
  1613. buf_size = min(count, sizeof(buf) - 1);
  1614. if (copy_from_user(buf, user_buf, buf_size))
  1615. return -EFAULT;
  1616. if (sscanf(buf, "%x", &reset_flag) != 1)
  1617. return -EFAULT;
  1618. if (reset_flag == 0)
  1619. memset(isr_stats, 0, sizeof(*isr_stats));
  1620. return count;
  1621. }
  1622. static ssize_t iwl_dbgfs_csr_write(struct file *file,
  1623. const char __user *user_buf,
  1624. size_t count, loff_t *ppos)
  1625. {
  1626. struct iwl_trans *trans = file->private_data;
  1627. char buf[8];
  1628. int buf_size;
  1629. int csr;
  1630. memset(buf, 0, sizeof(buf));
  1631. buf_size = min(count, sizeof(buf) - 1);
  1632. if (copy_from_user(buf, user_buf, buf_size))
  1633. return -EFAULT;
  1634. if (sscanf(buf, "%d", &csr) != 1)
  1635. return -EFAULT;
  1636. iwl_pcie_dump_csr(trans);
  1637. return count;
  1638. }
  1639. static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
  1640. char __user *user_buf,
  1641. size_t count, loff_t *ppos)
  1642. {
  1643. struct iwl_trans *trans = file->private_data;
  1644. char *buf = NULL;
  1645. ssize_t ret;
  1646. ret = iwl_dump_fh(trans, &buf);
  1647. if (ret < 0)
  1648. return ret;
  1649. if (!buf)
  1650. return -EINVAL;
  1651. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  1652. kfree(buf);
  1653. return ret;
  1654. }
  1655. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  1656. DEBUGFS_READ_FILE_OPS(fh_reg);
  1657. DEBUGFS_READ_FILE_OPS(rx_queue);
  1658. DEBUGFS_READ_FILE_OPS(tx_queue);
  1659. DEBUGFS_WRITE_FILE_OPS(csr);
  1660. /*
  1661. * Create the debugfs files and directories
  1662. *
  1663. */
  1664. static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
  1665. struct dentry *dir)
  1666. {
  1667. DEBUGFS_ADD_FILE(rx_queue, dir, S_IRUSR);
  1668. DEBUGFS_ADD_FILE(tx_queue, dir, S_IRUSR);
  1669. DEBUGFS_ADD_FILE(interrupt, dir, S_IWUSR | S_IRUSR);
  1670. DEBUGFS_ADD_FILE(csr, dir, S_IWUSR);
  1671. DEBUGFS_ADD_FILE(fh_reg, dir, S_IRUSR);
  1672. return 0;
  1673. err:
  1674. IWL_ERR(trans, "failed to create the trans debugfs entry\n");
  1675. return -ENOMEM;
  1676. }
  1677. #else
  1678. static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
  1679. struct dentry *dir)
  1680. {
  1681. return 0;
  1682. }
  1683. #endif /*CONFIG_IWLWIFI_DEBUGFS */
  1684. static u32 iwl_trans_pcie_get_cmdlen(struct iwl_tfd *tfd)
  1685. {
  1686. u32 cmdlen = 0;
  1687. int i;
  1688. for (i = 0; i < IWL_NUM_OF_TBS; i++)
  1689. cmdlen += iwl_pcie_tfd_tb_get_len(tfd, i);
  1690. return cmdlen;
  1691. }
  1692. static const struct {
  1693. u32 start, end;
  1694. } iwl_prph_dump_addr[] = {
  1695. { .start = 0x00a00000, .end = 0x00a00000 },
  1696. { .start = 0x00a0000c, .end = 0x00a00024 },
  1697. { .start = 0x00a0002c, .end = 0x00a0003c },
  1698. { .start = 0x00a00410, .end = 0x00a00418 },
  1699. { .start = 0x00a00420, .end = 0x00a00420 },
  1700. { .start = 0x00a00428, .end = 0x00a00428 },
  1701. { .start = 0x00a00430, .end = 0x00a0043c },
  1702. { .start = 0x00a00444, .end = 0x00a00444 },
  1703. { .start = 0x00a004c0, .end = 0x00a004cc },
  1704. { .start = 0x00a004d8, .end = 0x00a004d8 },
  1705. { .start = 0x00a004e0, .end = 0x00a004f0 },
  1706. { .start = 0x00a00840, .end = 0x00a00840 },
  1707. { .start = 0x00a00850, .end = 0x00a00858 },
  1708. { .start = 0x00a01004, .end = 0x00a01008 },
  1709. { .start = 0x00a01010, .end = 0x00a01010 },
  1710. { .start = 0x00a01018, .end = 0x00a01018 },
  1711. { .start = 0x00a01024, .end = 0x00a01024 },
  1712. { .start = 0x00a0102c, .end = 0x00a01034 },
  1713. { .start = 0x00a0103c, .end = 0x00a01040 },
  1714. { .start = 0x00a01048, .end = 0x00a01094 },
  1715. { .start = 0x00a01c00, .end = 0x00a01c20 },
  1716. { .start = 0x00a01c58, .end = 0x00a01c58 },
  1717. { .start = 0x00a01c7c, .end = 0x00a01c7c },
  1718. { .start = 0x00a01c28, .end = 0x00a01c54 },
  1719. { .start = 0x00a01c5c, .end = 0x00a01c5c },
  1720. { .start = 0x00a01c60, .end = 0x00a01cdc },
  1721. { .start = 0x00a01ce0, .end = 0x00a01d0c },
  1722. { .start = 0x00a01d18, .end = 0x00a01d20 },
  1723. { .start = 0x00a01d2c, .end = 0x00a01d30 },
  1724. { .start = 0x00a01d40, .end = 0x00a01d5c },
  1725. { .start = 0x00a01d80, .end = 0x00a01d80 },
  1726. { .start = 0x00a01d98, .end = 0x00a01d9c },
  1727. { .start = 0x00a01da8, .end = 0x00a01da8 },
  1728. { .start = 0x00a01db8, .end = 0x00a01df4 },
  1729. { .start = 0x00a01dc0, .end = 0x00a01dfc },
  1730. { .start = 0x00a01e00, .end = 0x00a01e2c },
  1731. { .start = 0x00a01e40, .end = 0x00a01e60 },
  1732. { .start = 0x00a01e68, .end = 0x00a01e6c },
  1733. { .start = 0x00a01e74, .end = 0x00a01e74 },
  1734. { .start = 0x00a01e84, .end = 0x00a01e90 },
  1735. { .start = 0x00a01e9c, .end = 0x00a01ec4 },
  1736. { .start = 0x00a01ed0, .end = 0x00a01ee0 },
  1737. { .start = 0x00a01f00, .end = 0x00a01f1c },
  1738. { .start = 0x00a01f44, .end = 0x00a01ffc },
  1739. { .start = 0x00a02000, .end = 0x00a02048 },
  1740. { .start = 0x00a02068, .end = 0x00a020f0 },
  1741. { .start = 0x00a02100, .end = 0x00a02118 },
  1742. { .start = 0x00a02140, .end = 0x00a0214c },
  1743. { .start = 0x00a02168, .end = 0x00a0218c },
  1744. { .start = 0x00a021c0, .end = 0x00a021c0 },
  1745. { .start = 0x00a02400, .end = 0x00a02410 },
  1746. { .start = 0x00a02418, .end = 0x00a02420 },
  1747. { .start = 0x00a02428, .end = 0x00a0242c },
  1748. { .start = 0x00a02434, .end = 0x00a02434 },
  1749. { .start = 0x00a02440, .end = 0x00a02460 },
  1750. { .start = 0x00a02468, .end = 0x00a024b0 },
  1751. { .start = 0x00a024c8, .end = 0x00a024cc },
  1752. { .start = 0x00a02500, .end = 0x00a02504 },
  1753. { .start = 0x00a0250c, .end = 0x00a02510 },
  1754. { .start = 0x00a02540, .end = 0x00a02554 },
  1755. { .start = 0x00a02580, .end = 0x00a025f4 },
  1756. { .start = 0x00a02600, .end = 0x00a0260c },
  1757. { .start = 0x00a02648, .end = 0x00a02650 },
  1758. { .start = 0x00a02680, .end = 0x00a02680 },
  1759. { .start = 0x00a026c0, .end = 0x00a026d0 },
  1760. { .start = 0x00a02700, .end = 0x00a0270c },
  1761. { .start = 0x00a02804, .end = 0x00a02804 },
  1762. { .start = 0x00a02818, .end = 0x00a0281c },
  1763. { .start = 0x00a02c00, .end = 0x00a02db4 },
  1764. { .start = 0x00a02df4, .end = 0x00a02fb0 },
  1765. { .start = 0x00a03000, .end = 0x00a03014 },
  1766. { .start = 0x00a0301c, .end = 0x00a0302c },
  1767. { .start = 0x00a03034, .end = 0x00a03038 },
  1768. { .start = 0x00a03040, .end = 0x00a03048 },
  1769. { .start = 0x00a03060, .end = 0x00a03068 },
  1770. { .start = 0x00a03070, .end = 0x00a03074 },
  1771. { .start = 0x00a0307c, .end = 0x00a0307c },
  1772. { .start = 0x00a03080, .end = 0x00a03084 },
  1773. { .start = 0x00a0308c, .end = 0x00a03090 },
  1774. { .start = 0x00a03098, .end = 0x00a03098 },
  1775. { .start = 0x00a030a0, .end = 0x00a030a0 },
  1776. { .start = 0x00a030a8, .end = 0x00a030b4 },
  1777. { .start = 0x00a030bc, .end = 0x00a030bc },
  1778. { .start = 0x00a030c0, .end = 0x00a0312c },
  1779. { .start = 0x00a03c00, .end = 0x00a03c5c },
  1780. { .start = 0x00a04400, .end = 0x00a04454 },
  1781. { .start = 0x00a04460, .end = 0x00a04474 },
  1782. { .start = 0x00a044c0, .end = 0x00a044ec },
  1783. { .start = 0x00a04500, .end = 0x00a04504 },
  1784. { .start = 0x00a04510, .end = 0x00a04538 },
  1785. { .start = 0x00a04540, .end = 0x00a04548 },
  1786. { .start = 0x00a04560, .end = 0x00a0457c },
  1787. { .start = 0x00a04590, .end = 0x00a04598 },
  1788. { .start = 0x00a045c0, .end = 0x00a045f4 },
  1789. };
  1790. static u32 iwl_trans_pcie_dump_prph(struct iwl_trans *trans,
  1791. struct iwl_fw_error_dump_data **data)
  1792. {
  1793. struct iwl_fw_error_dump_prph *prph;
  1794. unsigned long flags;
  1795. u32 prph_len = 0, i;
  1796. if (!iwl_trans_grab_nic_access(trans, false, &flags))
  1797. return 0;
  1798. for (i = 0; i < ARRAY_SIZE(iwl_prph_dump_addr); i++) {
  1799. /* The range includes both boundaries */
  1800. int num_bytes_in_chunk = iwl_prph_dump_addr[i].end -
  1801. iwl_prph_dump_addr[i].start + 4;
  1802. int reg;
  1803. __le32 *val;
  1804. prph_len += sizeof(**data) + sizeof(*prph) + num_bytes_in_chunk;
  1805. (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH);
  1806. (*data)->len = cpu_to_le32(sizeof(*prph) +
  1807. num_bytes_in_chunk);
  1808. prph = (void *)(*data)->data;
  1809. prph->prph_start = cpu_to_le32(iwl_prph_dump_addr[i].start);
  1810. val = (void *)prph->data;
  1811. for (reg = iwl_prph_dump_addr[i].start;
  1812. reg <= iwl_prph_dump_addr[i].end;
  1813. reg += 4)
  1814. *val++ = cpu_to_le32(iwl_trans_pcie_read_prph(trans,
  1815. reg));
  1816. *data = iwl_fw_error_next_data(*data);
  1817. }
  1818. iwl_trans_release_nic_access(trans, &flags);
  1819. return prph_len;
  1820. }
  1821. #define IWL_CSR_TO_DUMP (0x250)
  1822. static u32 iwl_trans_pcie_dump_csr(struct iwl_trans *trans,
  1823. struct iwl_fw_error_dump_data **data)
  1824. {
  1825. u32 csr_len = sizeof(**data) + IWL_CSR_TO_DUMP;
  1826. __le32 *val;
  1827. int i;
  1828. (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_CSR);
  1829. (*data)->len = cpu_to_le32(IWL_CSR_TO_DUMP);
  1830. val = (void *)(*data)->data;
  1831. for (i = 0; i < IWL_CSR_TO_DUMP; i += 4)
  1832. *val++ = cpu_to_le32(iwl_trans_pcie_read32(trans, i));
  1833. *data = iwl_fw_error_next_data(*data);
  1834. return csr_len;
  1835. }
  1836. static u32 iwl_trans_pcie_fh_regs_dump(struct iwl_trans *trans,
  1837. struct iwl_fw_error_dump_data **data)
  1838. {
  1839. u32 fh_regs_len = FH_MEM_UPPER_BOUND - FH_MEM_LOWER_BOUND;
  1840. unsigned long flags;
  1841. __le32 *val;
  1842. int i;
  1843. if (!iwl_trans_grab_nic_access(trans, false, &flags))
  1844. return 0;
  1845. (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_FH_REGS);
  1846. (*data)->len = cpu_to_le32(fh_regs_len);
  1847. val = (void *)(*data)->data;
  1848. for (i = FH_MEM_LOWER_BOUND; i < FH_MEM_UPPER_BOUND; i += sizeof(u32))
  1849. *val++ = cpu_to_le32(iwl_trans_pcie_read32(trans, i));
  1850. iwl_trans_release_nic_access(trans, &flags);
  1851. *data = iwl_fw_error_next_data(*data);
  1852. return sizeof(**data) + fh_regs_len;
  1853. }
  1854. static
  1855. struct iwl_trans_dump_data *iwl_trans_pcie_dump_data(struct iwl_trans *trans)
  1856. {
  1857. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1858. struct iwl_fw_error_dump_data *data;
  1859. struct iwl_txq *cmdq = &trans_pcie->txq[trans_pcie->cmd_queue];
  1860. struct iwl_fw_error_dump_txcmd *txcmd;
  1861. struct iwl_trans_dump_data *dump_data;
  1862. u32 len;
  1863. u32 monitor_len;
  1864. int i, ptr;
  1865. /* transport dump header */
  1866. len = sizeof(*dump_data);
  1867. /* host commands */
  1868. len += sizeof(*data) +
  1869. cmdq->q.n_window * (sizeof(*txcmd) + TFD_MAX_PAYLOAD_SIZE);
  1870. /* CSR registers */
  1871. len += sizeof(*data) + IWL_CSR_TO_DUMP;
  1872. /* PRPH registers */
  1873. for (i = 0; i < ARRAY_SIZE(iwl_prph_dump_addr); i++) {
  1874. /* The range includes both boundaries */
  1875. int num_bytes_in_chunk = iwl_prph_dump_addr[i].end -
  1876. iwl_prph_dump_addr[i].start + 4;
  1877. len += sizeof(*data) + sizeof(struct iwl_fw_error_dump_prph) +
  1878. num_bytes_in_chunk;
  1879. }
  1880. /* FH registers */
  1881. len += sizeof(*data) + (FH_MEM_UPPER_BOUND - FH_MEM_LOWER_BOUND);
  1882. /* FW monitor */
  1883. if (trans_pcie->fw_mon_page) {
  1884. len += sizeof(*data) + sizeof(struct iwl_fw_error_dump_fw_mon) +
  1885. trans_pcie->fw_mon_size;
  1886. monitor_len = trans_pcie->fw_mon_size;
  1887. } else if (trans->dbg_dest_tlv) {
  1888. u32 base, end;
  1889. base = le32_to_cpu(trans->dbg_dest_tlv->base_reg);
  1890. end = le32_to_cpu(trans->dbg_dest_tlv->end_reg);
  1891. base = iwl_read_prph(trans, base) <<
  1892. trans->dbg_dest_tlv->base_shift;
  1893. end = iwl_read_prph(trans, end) <<
  1894. trans->dbg_dest_tlv->end_shift;
  1895. /* Make "end" point to the actual end */
  1896. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_8000)
  1897. end += (1 << trans->dbg_dest_tlv->end_shift);
  1898. monitor_len = end - base;
  1899. len += sizeof(*data) + sizeof(struct iwl_fw_error_dump_fw_mon) +
  1900. monitor_len;
  1901. } else {
  1902. monitor_len = 0;
  1903. }
  1904. dump_data = vzalloc(len);
  1905. if (!dump_data)
  1906. return NULL;
  1907. len = 0;
  1908. data = (void *)dump_data->data;
  1909. data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXCMD);
  1910. txcmd = (void *)data->data;
  1911. spin_lock_bh(&cmdq->lock);
  1912. ptr = cmdq->q.write_ptr;
  1913. for (i = 0; i < cmdq->q.n_window; i++) {
  1914. u8 idx = get_cmd_index(&cmdq->q, ptr);
  1915. u32 caplen, cmdlen;
  1916. cmdlen = iwl_trans_pcie_get_cmdlen(&cmdq->tfds[ptr]);
  1917. caplen = min_t(u32, TFD_MAX_PAYLOAD_SIZE, cmdlen);
  1918. if (cmdlen) {
  1919. len += sizeof(*txcmd) + caplen;
  1920. txcmd->cmdlen = cpu_to_le32(cmdlen);
  1921. txcmd->caplen = cpu_to_le32(caplen);
  1922. memcpy(txcmd->data, cmdq->entries[idx].cmd, caplen);
  1923. txcmd = (void *)((u8 *)txcmd->data + caplen);
  1924. }
  1925. ptr = iwl_queue_dec_wrap(ptr);
  1926. }
  1927. spin_unlock_bh(&cmdq->lock);
  1928. data->len = cpu_to_le32(len);
  1929. len += sizeof(*data);
  1930. data = iwl_fw_error_next_data(data);
  1931. len += iwl_trans_pcie_dump_prph(trans, &data);
  1932. len += iwl_trans_pcie_dump_csr(trans, &data);
  1933. len += iwl_trans_pcie_fh_regs_dump(trans, &data);
  1934. /* data is already pointing to the next section */
  1935. if ((trans_pcie->fw_mon_page &&
  1936. trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) ||
  1937. trans->dbg_dest_tlv) {
  1938. struct iwl_fw_error_dump_fw_mon *fw_mon_data;
  1939. u32 base, write_ptr, wrap_cnt;
  1940. /* If there was a dest TLV - use the values from there */
  1941. if (trans->dbg_dest_tlv) {
  1942. write_ptr =
  1943. le32_to_cpu(trans->dbg_dest_tlv->write_ptr_reg);
  1944. wrap_cnt = le32_to_cpu(trans->dbg_dest_tlv->wrap_count);
  1945. base = le32_to_cpu(trans->dbg_dest_tlv->base_reg);
  1946. } else {
  1947. base = MON_BUFF_BASE_ADDR;
  1948. write_ptr = MON_BUFF_WRPTR;
  1949. wrap_cnt = MON_BUFF_CYCLE_CNT;
  1950. }
  1951. data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_FW_MONITOR);
  1952. fw_mon_data = (void *)data->data;
  1953. fw_mon_data->fw_mon_wr_ptr =
  1954. cpu_to_le32(iwl_read_prph(trans, write_ptr));
  1955. fw_mon_data->fw_mon_cycle_cnt =
  1956. cpu_to_le32(iwl_read_prph(trans, wrap_cnt));
  1957. fw_mon_data->fw_mon_base_ptr =
  1958. cpu_to_le32(iwl_read_prph(trans, base));
  1959. len += sizeof(*data) + sizeof(*fw_mon_data);
  1960. if (trans_pcie->fw_mon_page) {
  1961. data->len = cpu_to_le32(trans_pcie->fw_mon_size +
  1962. sizeof(*fw_mon_data));
  1963. /*
  1964. * The firmware is now asserted, it won't write anything
  1965. * to the buffer. CPU can take ownership to fetch the
  1966. * data. The buffer will be handed back to the device
  1967. * before the firmware will be restarted.
  1968. */
  1969. dma_sync_single_for_cpu(trans->dev,
  1970. trans_pcie->fw_mon_phys,
  1971. trans_pcie->fw_mon_size,
  1972. DMA_FROM_DEVICE);
  1973. memcpy(fw_mon_data->data,
  1974. page_address(trans_pcie->fw_mon_page),
  1975. trans_pcie->fw_mon_size);
  1976. len += trans_pcie->fw_mon_size;
  1977. } else {
  1978. /* If we are here then the buffer is internal */
  1979. /*
  1980. * Update pointers to reflect actual values after
  1981. * shifting
  1982. */
  1983. base = iwl_read_prph(trans, base) <<
  1984. trans->dbg_dest_tlv->base_shift;
  1985. iwl_trans_read_mem(trans, base, fw_mon_data->data,
  1986. monitor_len / sizeof(u32));
  1987. data->len = cpu_to_le32(sizeof(*fw_mon_data) +
  1988. monitor_len);
  1989. len += monitor_len;
  1990. }
  1991. }
  1992. dump_data->len = len;
  1993. return dump_data;
  1994. }
  1995. static const struct iwl_trans_ops trans_ops_pcie = {
  1996. .start_hw = iwl_trans_pcie_start_hw,
  1997. .op_mode_leave = iwl_trans_pcie_op_mode_leave,
  1998. .fw_alive = iwl_trans_pcie_fw_alive,
  1999. .start_fw = iwl_trans_pcie_start_fw,
  2000. .stop_device = iwl_trans_pcie_stop_device,
  2001. .d3_suspend = iwl_trans_pcie_d3_suspend,
  2002. .d3_resume = iwl_trans_pcie_d3_resume,
  2003. .send_cmd = iwl_trans_pcie_send_hcmd,
  2004. .tx = iwl_trans_pcie_tx,
  2005. .reclaim = iwl_trans_pcie_reclaim,
  2006. .txq_disable = iwl_trans_pcie_txq_disable,
  2007. .txq_enable = iwl_trans_pcie_txq_enable,
  2008. .dbgfs_register = iwl_trans_pcie_dbgfs_register,
  2009. .wait_tx_queue_empty = iwl_trans_pcie_wait_txq_empty,
  2010. .freeze_txq_timer = iwl_trans_pcie_freeze_txq_timer,
  2011. .write8 = iwl_trans_pcie_write8,
  2012. .write32 = iwl_trans_pcie_write32,
  2013. .read32 = iwl_trans_pcie_read32,
  2014. .read_prph = iwl_trans_pcie_read_prph,
  2015. .write_prph = iwl_trans_pcie_write_prph,
  2016. .read_mem = iwl_trans_pcie_read_mem,
  2017. .write_mem = iwl_trans_pcie_write_mem,
  2018. .configure = iwl_trans_pcie_configure,
  2019. .set_pmi = iwl_trans_pcie_set_pmi,
  2020. .grab_nic_access = iwl_trans_pcie_grab_nic_access,
  2021. .release_nic_access = iwl_trans_pcie_release_nic_access,
  2022. .set_bits_mask = iwl_trans_pcie_set_bits_mask,
  2023. .ref = iwl_trans_pcie_ref,
  2024. .unref = iwl_trans_pcie_unref,
  2025. .dump_data = iwl_trans_pcie_dump_data,
  2026. };
  2027. struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
  2028. const struct pci_device_id *ent,
  2029. const struct iwl_cfg *cfg)
  2030. {
  2031. struct iwl_trans_pcie *trans_pcie;
  2032. struct iwl_trans *trans;
  2033. u16 pci_cmd;
  2034. int err;
  2035. trans = kzalloc(sizeof(struct iwl_trans) +
  2036. sizeof(struct iwl_trans_pcie), GFP_KERNEL);
  2037. if (!trans) {
  2038. err = -ENOMEM;
  2039. goto out;
  2040. }
  2041. trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  2042. trans->ops = &trans_ops_pcie;
  2043. trans->cfg = cfg;
  2044. trans_lockdep_init(trans);
  2045. trans_pcie->trans = trans;
  2046. spin_lock_init(&trans_pcie->irq_lock);
  2047. spin_lock_init(&trans_pcie->reg_lock);
  2048. spin_lock_init(&trans_pcie->ref_lock);
  2049. init_waitqueue_head(&trans_pcie->ucode_write_waitq);
  2050. err = pci_enable_device(pdev);
  2051. if (err)
  2052. goto out_no_pci;
  2053. if (!cfg->base_params->pcie_l1_allowed) {
  2054. /*
  2055. * W/A - seems to solve weird behavior. We need to remove this
  2056. * if we don't want to stay in L1 all the time. This wastes a
  2057. * lot of power.
  2058. */
  2059. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
  2060. PCIE_LINK_STATE_L1 |
  2061. PCIE_LINK_STATE_CLKPM);
  2062. }
  2063. pci_set_master(pdev);
  2064. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  2065. if (!err)
  2066. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  2067. if (err) {
  2068. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2069. if (!err)
  2070. err = pci_set_consistent_dma_mask(pdev,
  2071. DMA_BIT_MASK(32));
  2072. /* both attempts failed: */
  2073. if (err) {
  2074. dev_err(&pdev->dev, "No suitable DMA available\n");
  2075. goto out_pci_disable_device;
  2076. }
  2077. }
  2078. err = pci_request_regions(pdev, DRV_NAME);
  2079. if (err) {
  2080. dev_err(&pdev->dev, "pci_request_regions failed\n");
  2081. goto out_pci_disable_device;
  2082. }
  2083. trans_pcie->hw_base = pci_ioremap_bar(pdev, 0);
  2084. if (!trans_pcie->hw_base) {
  2085. dev_err(&pdev->dev, "pci_ioremap_bar failed\n");
  2086. err = -ENODEV;
  2087. goto out_pci_release_regions;
  2088. }
  2089. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  2090. * PCI Tx retries from interfering with C3 CPU state */
  2091. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  2092. trans->dev = &pdev->dev;
  2093. trans_pcie->pci_dev = pdev;
  2094. iwl_disable_interrupts(trans);
  2095. err = pci_enable_msi(pdev);
  2096. if (err) {
  2097. dev_err(&pdev->dev, "pci_enable_msi failed(0X%x)\n", err);
  2098. /* enable rfkill interrupt: hw bug w/a */
  2099. pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
  2100. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  2101. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  2102. pci_write_config_word(pdev, PCI_COMMAND, pci_cmd);
  2103. }
  2104. }
  2105. trans->hw_rev = iwl_read32(trans, CSR_HW_REV);
  2106. /*
  2107. * In the 8000 HW family the format of the 4 bytes of CSR_HW_REV have
  2108. * changed, and now the revision step also includes bit 0-1 (no more
  2109. * "dash" value). To keep hw_rev backwards compatible - we'll store it
  2110. * in the old format.
  2111. */
  2112. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_8000) {
  2113. unsigned long flags;
  2114. int ret;
  2115. trans->hw_rev = (trans->hw_rev & 0xfff0) |
  2116. (CSR_HW_REV_STEP(trans->hw_rev << 2) << 2);
  2117. /*
  2118. * in-order to recognize C step driver should read chip version
  2119. * id located at the AUX bus MISC address space.
  2120. */
  2121. iwl_set_bit(trans, CSR_GP_CNTRL,
  2122. CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  2123. udelay(2);
  2124. ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
  2125. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  2126. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  2127. 25000);
  2128. if (ret < 0) {
  2129. IWL_DEBUG_INFO(trans, "Failed to wake up the nic\n");
  2130. goto out_pci_disable_msi;
  2131. }
  2132. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  2133. u32 hw_step;
  2134. hw_step = __iwl_read_prph(trans, WFPM_CTRL_REG);
  2135. hw_step |= ENABLE_WFPM;
  2136. __iwl_write_prph(trans, WFPM_CTRL_REG, hw_step);
  2137. hw_step = __iwl_read_prph(trans, AUX_MISC_REG);
  2138. hw_step = (hw_step >> HW_STEP_LOCATION_BITS) & 0xF;
  2139. if (hw_step == 0x3)
  2140. trans->hw_rev = (trans->hw_rev & 0xFFFFFFF3) |
  2141. (SILICON_C_STEP << 2);
  2142. iwl_trans_release_nic_access(trans, &flags);
  2143. }
  2144. }
  2145. trans->hw_id = (pdev->device << 16) + pdev->subsystem_device;
  2146. snprintf(trans->hw_id_str, sizeof(trans->hw_id_str),
  2147. "PCI ID: 0x%04X:0x%04X", pdev->device, pdev->subsystem_device);
  2148. /* Initialize the wait queue for commands */
  2149. init_waitqueue_head(&trans_pcie->wait_command_queue);
  2150. snprintf(trans->dev_cmd_pool_name, sizeof(trans->dev_cmd_pool_name),
  2151. "iwl_cmd_pool:%s", dev_name(trans->dev));
  2152. trans->dev_cmd_headroom = 0;
  2153. trans->dev_cmd_pool =
  2154. kmem_cache_create(trans->dev_cmd_pool_name,
  2155. sizeof(struct iwl_device_cmd)
  2156. + trans->dev_cmd_headroom,
  2157. sizeof(void *),
  2158. SLAB_HWCACHE_ALIGN,
  2159. NULL);
  2160. if (!trans->dev_cmd_pool) {
  2161. err = -ENOMEM;
  2162. goto out_pci_disable_msi;
  2163. }
  2164. if (iwl_pcie_alloc_ict(trans))
  2165. goto out_free_cmd_pool;
  2166. err = request_threaded_irq(pdev->irq, iwl_pcie_isr,
  2167. iwl_pcie_irq_handler,
  2168. IRQF_SHARED, DRV_NAME, trans);
  2169. if (err) {
  2170. IWL_ERR(trans, "Error allocating IRQ %d\n", pdev->irq);
  2171. goto out_free_ict;
  2172. }
  2173. trans_pcie->inta_mask = CSR_INI_SET_MASK;
  2174. trans->d0i3_mode = IWL_D0I3_MODE_ON_SUSPEND;
  2175. return trans;
  2176. out_free_ict:
  2177. iwl_pcie_free_ict(trans);
  2178. out_free_cmd_pool:
  2179. kmem_cache_destroy(trans->dev_cmd_pool);
  2180. out_pci_disable_msi:
  2181. pci_disable_msi(pdev);
  2182. out_pci_release_regions:
  2183. pci_release_regions(pdev);
  2184. out_pci_disable_device:
  2185. pci_disable_device(pdev);
  2186. out_no_pci:
  2187. kfree(trans);
  2188. out:
  2189. return ERR_PTR(err);
  2190. }