trans.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  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 - 2013 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called LICENSE.GPL.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #include <linux/pci.h>
  64. #include <linux/pci-aspm.h>
  65. #include <linux/interrupt.h>
  66. #include <linux/debugfs.h>
  67. #include <linux/sched.h>
  68. #include <linux/bitops.h>
  69. #include <linux/gfp.h>
  70. #include "iwl-drv.h"
  71. #include "iwl-trans.h"
  72. #include "iwl-csr.h"
  73. #include "iwl-prph.h"
  74. #include "iwl-agn-hw.h"
  75. #include "internal.h"
  76. static void __iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans,
  77. u32 reg, u32 mask, u32 value)
  78. {
  79. u32 v;
  80. #ifdef CONFIG_IWLWIFI_DEBUG
  81. WARN_ON_ONCE(value & ~mask);
  82. #endif
  83. v = iwl_read32(trans, reg);
  84. v &= ~mask;
  85. v |= value;
  86. iwl_write32(trans, reg, v);
  87. }
  88. static inline void __iwl_trans_pcie_clear_bit(struct iwl_trans *trans,
  89. u32 reg, u32 mask)
  90. {
  91. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, 0);
  92. }
  93. static inline void __iwl_trans_pcie_set_bit(struct iwl_trans *trans,
  94. u32 reg, u32 mask)
  95. {
  96. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, mask);
  97. }
  98. static void iwl_pcie_set_pwr(struct iwl_trans *trans, bool vaux)
  99. {
  100. if (vaux && pci_pme_capable(to_pci_dev(trans->dev), PCI_D3cold))
  101. iwl_set_bits_mask_prph(trans, APMG_PS_CTRL_REG,
  102. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  103. ~APMG_PS_CTRL_MSK_PWR_SRC);
  104. else
  105. iwl_set_bits_mask_prph(trans, APMG_PS_CTRL_REG,
  106. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  107. ~APMG_PS_CTRL_MSK_PWR_SRC);
  108. }
  109. /* PCI registers */
  110. #define PCI_CFG_RETRY_TIMEOUT 0x041
  111. static void iwl_pcie_apm_config(struct iwl_trans *trans)
  112. {
  113. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  114. u16 lctl;
  115. /*
  116. * HW bug W/A for instability in PCIe bus L0S->L1 transition.
  117. * Check if BIOS (or OS) enabled L1-ASPM on this device.
  118. * If so (likely), disable L0S, so device moves directly L0->L1;
  119. * costs negligible amount of power savings.
  120. * If not (unlikely), enable L0S, so there is at least some
  121. * power savings, even without L1.
  122. */
  123. pcie_capability_read_word(trans_pcie->pci_dev, PCI_EXP_LNKCTL, &lctl);
  124. if (lctl & PCI_EXP_LNKCTL_ASPM_L1) {
  125. /* L1-ASPM enabled; disable(!) L0S */
  126. iwl_set_bit(trans, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  127. dev_info(trans->dev, "L1 Enabled; Disabling L0S\n");
  128. } else {
  129. /* L1-ASPM disabled; enable(!) L0S */
  130. iwl_clear_bit(trans, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  131. dev_info(trans->dev, "L1 Disabled; Enabling L0S\n");
  132. }
  133. trans->pm_support = !(lctl & PCI_EXP_LNKCTL_ASPM_L0S);
  134. }
  135. /*
  136. * Start up NIC's basic functionality after it has been reset
  137. * (e.g. after platform boot, or shutdown via iwl_pcie_apm_stop())
  138. * NOTE: This does not load uCode nor start the embedded processor
  139. */
  140. static int iwl_pcie_apm_init(struct iwl_trans *trans)
  141. {
  142. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  143. int ret = 0;
  144. IWL_DEBUG_INFO(trans, "Init card's basic functions\n");
  145. /*
  146. * Use "set_bit" below rather than "write", to preserve any hardware
  147. * bits already set by default after reset.
  148. */
  149. /* Disable L0S exit timer (platform NMI Work/Around) */
  150. iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS,
  151. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  152. /*
  153. * Disable L0s without affecting L1;
  154. * don't wait for ICH L0s (ICH bug W/A)
  155. */
  156. iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS,
  157. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  158. /* Set FH wait threshold to maximum (HW error during stress W/A) */
  159. iwl_set_bit(trans, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
  160. /*
  161. * Enable HAP INTA (interrupt from management bus) to
  162. * wake device's PCI Express link L1a -> L0s
  163. */
  164. iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
  165. CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
  166. iwl_pcie_apm_config(trans);
  167. /* Configure analog phase-lock-loop before activating to D0A */
  168. if (trans->cfg->base_params->pll_cfg_val)
  169. iwl_set_bit(trans, CSR_ANA_PLL_CFG,
  170. trans->cfg->base_params->pll_cfg_val);
  171. /*
  172. * Set "initialization complete" bit to move adapter from
  173. * D0U* --> D0A* (powered-up active) state.
  174. */
  175. iwl_set_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  176. /*
  177. * Wait for clock stabilization; once stabilized, access to
  178. * device-internal resources is supported, e.g. iwl_write_prph()
  179. * and accesses to uCode SRAM.
  180. */
  181. ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
  182. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  183. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  184. if (ret < 0) {
  185. IWL_DEBUG_INFO(trans, "Failed to init the card\n");
  186. goto out;
  187. }
  188. /*
  189. * Enable DMA clock and wait for it to stabilize.
  190. *
  191. * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
  192. * do not disable clocks. This preserves any hardware bits already
  193. * set by default in "CLK_CTRL_REG" after reset.
  194. */
  195. iwl_write_prph(trans, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  196. udelay(20);
  197. /* Disable L1-Active */
  198. iwl_set_bits_prph(trans, APMG_PCIDEV_STT_REG,
  199. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  200. set_bit(STATUS_DEVICE_ENABLED, &trans_pcie->status);
  201. out:
  202. return ret;
  203. }
  204. static int iwl_pcie_apm_stop_master(struct iwl_trans *trans)
  205. {
  206. int ret = 0;
  207. /* stop device's busmaster DMA activity */
  208. iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  209. ret = iwl_poll_bit(trans, CSR_RESET,
  210. CSR_RESET_REG_FLAG_MASTER_DISABLED,
  211. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  212. if (ret)
  213. IWL_WARN(trans, "Master Disable Timed Out, 100 usec\n");
  214. IWL_DEBUG_INFO(trans, "stop master\n");
  215. return ret;
  216. }
  217. static void iwl_pcie_apm_stop(struct iwl_trans *trans)
  218. {
  219. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  220. IWL_DEBUG_INFO(trans, "Stop card, put in low power state\n");
  221. clear_bit(STATUS_DEVICE_ENABLED, &trans_pcie->status);
  222. /* Stop device's DMA activity */
  223. iwl_pcie_apm_stop_master(trans);
  224. /* Reset the entire device */
  225. iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  226. udelay(10);
  227. /*
  228. * Clear "initialization complete" bit to move adapter from
  229. * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
  230. */
  231. iwl_clear_bit(trans, CSR_GP_CNTRL,
  232. CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  233. }
  234. static int iwl_pcie_nic_init(struct iwl_trans *trans)
  235. {
  236. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  237. unsigned long flags;
  238. /* nic_init */
  239. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  240. iwl_pcie_apm_init(trans);
  241. /* Set interrupt coalescing calibration timer to default (512 usecs) */
  242. iwl_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_CALIB_TIMEOUT_DEF);
  243. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  244. iwl_pcie_set_pwr(trans, false);
  245. iwl_op_mode_nic_config(trans->op_mode);
  246. /* Allocate the RX queue, or reset if it is already allocated */
  247. iwl_pcie_rx_init(trans);
  248. /* Allocate or reset and init all Tx and Command queues */
  249. if (iwl_pcie_tx_init(trans))
  250. return -ENOMEM;
  251. if (trans->cfg->base_params->shadow_reg_enable) {
  252. /* enable shadow regs in HW */
  253. iwl_set_bit(trans, CSR_MAC_SHADOW_REG_CTRL, 0x800FFFFF);
  254. IWL_DEBUG_INFO(trans, "Enabling shadow registers in device\n");
  255. }
  256. return 0;
  257. }
  258. #define HW_READY_TIMEOUT (50)
  259. /* Note: returns poll_bit return value, which is >= 0 if success */
  260. static int iwl_pcie_set_hw_ready(struct iwl_trans *trans)
  261. {
  262. int ret;
  263. iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
  264. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  265. /* See if we got it */
  266. ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG,
  267. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  268. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  269. HW_READY_TIMEOUT);
  270. IWL_DEBUG_INFO(trans, "hardware%s ready\n", ret < 0 ? " not" : "");
  271. return ret;
  272. }
  273. /* Note: returns standard 0/-ERROR code */
  274. static int iwl_pcie_prepare_card_hw(struct iwl_trans *trans)
  275. {
  276. int ret;
  277. int t = 0;
  278. IWL_DEBUG_INFO(trans, "iwl_trans_prepare_card_hw enter\n");
  279. ret = iwl_pcie_set_hw_ready(trans);
  280. /* If the card is ready, exit 0 */
  281. if (ret >= 0)
  282. return 0;
  283. /* If HW is not ready, prepare the conditions to check again */
  284. iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
  285. CSR_HW_IF_CONFIG_REG_PREPARE);
  286. do {
  287. ret = iwl_pcie_set_hw_ready(trans);
  288. if (ret >= 0)
  289. return 0;
  290. usleep_range(200, 1000);
  291. t += 200;
  292. } while (t < 150000);
  293. return ret;
  294. }
  295. /*
  296. * ucode
  297. */
  298. static int iwl_pcie_load_firmware_chunk(struct iwl_trans *trans, u32 dst_addr,
  299. dma_addr_t phy_addr, u32 byte_cnt)
  300. {
  301. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  302. int ret;
  303. trans_pcie->ucode_write_complete = false;
  304. iwl_write_direct32(trans,
  305. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  306. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
  307. iwl_write_direct32(trans,
  308. FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL),
  309. dst_addr);
  310. iwl_write_direct32(trans,
  311. FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
  312. phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
  313. iwl_write_direct32(trans,
  314. FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL),
  315. (iwl_get_dma_hi_addr(phy_addr)
  316. << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt);
  317. iwl_write_direct32(trans,
  318. FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
  319. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
  320. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
  321. FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
  322. iwl_write_direct32(trans,
  323. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  324. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  325. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE |
  326. FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
  327. ret = wait_event_timeout(trans_pcie->ucode_write_waitq,
  328. trans_pcie->ucode_write_complete, 5 * HZ);
  329. if (!ret) {
  330. IWL_ERR(trans, "Failed to load firmware chunk!\n");
  331. return -ETIMEDOUT;
  332. }
  333. return 0;
  334. }
  335. static int iwl_pcie_load_section(struct iwl_trans *trans, u8 section_num,
  336. const struct fw_desc *section)
  337. {
  338. u8 *v_addr;
  339. dma_addr_t p_addr;
  340. u32 offset;
  341. int ret = 0;
  342. IWL_DEBUG_FW(trans, "[%d] uCode section being loaded...\n",
  343. section_num);
  344. v_addr = dma_alloc_coherent(trans->dev, PAGE_SIZE, &p_addr, GFP_KERNEL);
  345. if (!v_addr)
  346. return -ENOMEM;
  347. for (offset = 0; offset < section->len; offset += PAGE_SIZE) {
  348. u32 copy_size;
  349. copy_size = min_t(u32, PAGE_SIZE, section->len - offset);
  350. memcpy(v_addr, (u8 *)section->data + offset, copy_size);
  351. ret = iwl_pcie_load_firmware_chunk(trans,
  352. section->offset + offset,
  353. p_addr, copy_size);
  354. if (ret) {
  355. IWL_ERR(trans,
  356. "Could not load the [%d] uCode section\n",
  357. section_num);
  358. break;
  359. }
  360. }
  361. dma_free_coherent(trans->dev, PAGE_SIZE, v_addr, p_addr);
  362. return ret;
  363. }
  364. static int iwl_pcie_load_given_ucode(struct iwl_trans *trans,
  365. const struct fw_img *image)
  366. {
  367. int i, ret = 0;
  368. for (i = 0; i < IWL_UCODE_SECTION_MAX; i++) {
  369. if (!image->sec[i].data)
  370. break;
  371. ret = iwl_pcie_load_section(trans, i, &image->sec[i]);
  372. if (ret)
  373. return ret;
  374. }
  375. /* Remove all resets to allow NIC to operate */
  376. iwl_write32(trans, CSR_RESET, 0);
  377. return 0;
  378. }
  379. static int iwl_trans_pcie_start_fw(struct iwl_trans *trans,
  380. const struct fw_img *fw, bool run_in_rfkill)
  381. {
  382. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  383. int ret;
  384. bool hw_rfkill;
  385. /* This may fail if AMT took ownership of the device */
  386. if (iwl_pcie_prepare_card_hw(trans)) {
  387. IWL_WARN(trans, "Exit HW not ready\n");
  388. return -EIO;
  389. }
  390. clear_bit(STATUS_FW_ERROR, &trans_pcie->status);
  391. iwl_enable_rfkill_int(trans);
  392. /* If platform's RF_KILL switch is NOT set to KILL */
  393. hw_rfkill = iwl_is_rfkill_set(trans);
  394. if (hw_rfkill)
  395. set_bit(STATUS_RFKILL, &trans_pcie->status);
  396. else
  397. clear_bit(STATUS_RFKILL, &trans_pcie->status);
  398. iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rfkill);
  399. if (hw_rfkill && !run_in_rfkill)
  400. return -ERFKILL;
  401. iwl_write32(trans, CSR_INT, 0xFFFFFFFF);
  402. ret = iwl_pcie_nic_init(trans);
  403. if (ret) {
  404. IWL_ERR(trans, "Unable to init nic\n");
  405. return ret;
  406. }
  407. /* make sure rfkill handshake bits are cleared */
  408. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  409. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR,
  410. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  411. /* clear (again), then enable host interrupts */
  412. iwl_write32(trans, CSR_INT, 0xFFFFFFFF);
  413. iwl_enable_interrupts(trans);
  414. /* really make sure rfkill handshake bits are cleared */
  415. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  416. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  417. /* Load the given image to the HW */
  418. return iwl_pcie_load_given_ucode(trans, fw);
  419. }
  420. static void iwl_trans_pcie_fw_alive(struct iwl_trans *trans, u32 scd_addr)
  421. {
  422. iwl_pcie_reset_ict(trans);
  423. iwl_pcie_tx_start(trans, scd_addr);
  424. }
  425. static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
  426. {
  427. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  428. unsigned long flags;
  429. /* tell the device to stop sending interrupts */
  430. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  431. iwl_disable_interrupts(trans);
  432. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  433. /* device going down, Stop using ICT table */
  434. iwl_pcie_disable_ict(trans);
  435. /*
  436. * If a HW restart happens during firmware loading,
  437. * then the firmware loading might call this function
  438. * and later it might be called again due to the
  439. * restart. So don't process again if the device is
  440. * already dead.
  441. */
  442. if (test_bit(STATUS_DEVICE_ENABLED, &trans_pcie->status)) {
  443. iwl_pcie_tx_stop(trans);
  444. iwl_pcie_rx_stop(trans);
  445. /* Power-down device's busmaster DMA clocks */
  446. iwl_write_prph(trans, APMG_CLK_DIS_REG,
  447. APMG_CLK_VAL_DMA_CLK_RQT);
  448. udelay(5);
  449. }
  450. /* Make sure (redundant) we've released our request to stay awake */
  451. iwl_clear_bit(trans, CSR_GP_CNTRL,
  452. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  453. /* Stop the device, and put it in low power state */
  454. iwl_pcie_apm_stop(trans);
  455. /* Upon stop, the APM issues an interrupt if HW RF kill is set.
  456. * Clean again the interrupt here
  457. */
  458. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  459. iwl_disable_interrupts(trans);
  460. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  461. iwl_enable_rfkill_int(trans);
  462. /* stop and reset the on-board processor */
  463. iwl_write32(trans, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  464. /* clear all status bits */
  465. clear_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status);
  466. clear_bit(STATUS_INT_ENABLED, &trans_pcie->status);
  467. clear_bit(STATUS_DEVICE_ENABLED, &trans_pcie->status);
  468. clear_bit(STATUS_TPOWER_PMI, &trans_pcie->status);
  469. clear_bit(STATUS_RFKILL, &trans_pcie->status);
  470. }
  471. static void iwl_trans_pcie_d3_suspend(struct iwl_trans *trans)
  472. {
  473. /* let the ucode operate on its own */
  474. iwl_write32(trans, CSR_UCODE_DRV_GP1_SET,
  475. CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
  476. iwl_disable_interrupts(trans);
  477. iwl_pcie_disable_ict(trans);
  478. iwl_clear_bit(trans, CSR_GP_CNTRL,
  479. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  480. iwl_clear_bit(trans, CSR_GP_CNTRL,
  481. CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  482. /*
  483. * reset TX queues -- some of their registers reset during S3
  484. * so if we don't reset everything here the D3 image would try
  485. * to execute some invalid memory upon resume
  486. */
  487. iwl_trans_pcie_tx_reset(trans);
  488. iwl_pcie_set_pwr(trans, true);
  489. }
  490. static int iwl_trans_pcie_d3_resume(struct iwl_trans *trans,
  491. enum iwl_d3_status *status)
  492. {
  493. u32 val;
  494. int ret;
  495. iwl_pcie_set_pwr(trans, false);
  496. val = iwl_read32(trans, CSR_RESET);
  497. if (val & CSR_RESET_REG_FLAG_NEVO_RESET) {
  498. *status = IWL_D3_STATUS_RESET;
  499. return 0;
  500. }
  501. /*
  502. * Also enables interrupts - none will happen as the device doesn't
  503. * know we're waking it up, only when the opmode actually tells it
  504. * after this call.
  505. */
  506. iwl_pcie_reset_ict(trans);
  507. iwl_set_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  508. iwl_set_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  509. ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
  510. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  511. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  512. 25000);
  513. if (ret) {
  514. IWL_ERR(trans, "Failed to resume the device (mac ready)\n");
  515. return ret;
  516. }
  517. iwl_trans_pcie_tx_reset(trans);
  518. ret = iwl_pcie_rx_init(trans);
  519. if (ret) {
  520. IWL_ERR(trans, "Failed to resume the device (RX reset)\n");
  521. return ret;
  522. }
  523. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR,
  524. CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
  525. *status = IWL_D3_STATUS_ALIVE;
  526. return 0;
  527. }
  528. static int iwl_trans_pcie_start_hw(struct iwl_trans *trans)
  529. {
  530. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  531. bool hw_rfkill;
  532. int err;
  533. err = iwl_pcie_prepare_card_hw(trans);
  534. if (err) {
  535. IWL_ERR(trans, "Error while preparing HW: %d\n", err);
  536. return err;
  537. }
  538. iwl_pcie_apm_init(trans);
  539. /* From now on, the op_mode will be kept updated about RF kill state */
  540. iwl_enable_rfkill_int(trans);
  541. hw_rfkill = iwl_is_rfkill_set(trans);
  542. if (hw_rfkill)
  543. set_bit(STATUS_RFKILL, &trans_pcie->status);
  544. else
  545. clear_bit(STATUS_RFKILL, &trans_pcie->status);
  546. iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rfkill);
  547. return 0;
  548. }
  549. static void iwl_trans_pcie_stop_hw(struct iwl_trans *trans,
  550. bool op_mode_leaving)
  551. {
  552. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  553. bool hw_rfkill;
  554. unsigned long flags;
  555. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  556. iwl_disable_interrupts(trans);
  557. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  558. iwl_pcie_apm_stop(trans);
  559. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  560. iwl_disable_interrupts(trans);
  561. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  562. iwl_pcie_disable_ict(trans);
  563. if (!op_mode_leaving) {
  564. /*
  565. * Even if we stop the HW, we still want the RF kill
  566. * interrupt
  567. */
  568. iwl_enable_rfkill_int(trans);
  569. /*
  570. * Check again since the RF kill state may have changed while
  571. * all the interrupts were disabled, in this case we couldn't
  572. * receive the RF kill interrupt and update the state in the
  573. * op_mode.
  574. */
  575. hw_rfkill = iwl_is_rfkill_set(trans);
  576. if (hw_rfkill)
  577. set_bit(STATUS_RFKILL, &trans_pcie->status);
  578. else
  579. clear_bit(STATUS_RFKILL, &trans_pcie->status);
  580. iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rfkill);
  581. }
  582. }
  583. static void iwl_trans_pcie_write8(struct iwl_trans *trans, u32 ofs, u8 val)
  584. {
  585. writeb(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  586. }
  587. static void iwl_trans_pcie_write32(struct iwl_trans *trans, u32 ofs, u32 val)
  588. {
  589. writel(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  590. }
  591. static u32 iwl_trans_pcie_read32(struct iwl_trans *trans, u32 ofs)
  592. {
  593. return readl(IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  594. }
  595. static u32 iwl_trans_pcie_read_prph(struct iwl_trans *trans, u32 reg)
  596. {
  597. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
  598. return iwl_trans_pcie_read32(trans, HBUS_TARG_PRPH_RDAT);
  599. }
  600. static void iwl_trans_pcie_write_prph(struct iwl_trans *trans, u32 addr,
  601. u32 val)
  602. {
  603. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_WADDR,
  604. ((addr & 0x0000FFFF) | (3 << 24)));
  605. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_WDAT, val);
  606. }
  607. static void iwl_trans_pcie_configure(struct iwl_trans *trans,
  608. const struct iwl_trans_config *trans_cfg)
  609. {
  610. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  611. trans_pcie->cmd_queue = trans_cfg->cmd_queue;
  612. trans_pcie->cmd_fifo = trans_cfg->cmd_fifo;
  613. if (WARN_ON(trans_cfg->n_no_reclaim_cmds > MAX_NO_RECLAIM_CMDS))
  614. trans_pcie->n_no_reclaim_cmds = 0;
  615. else
  616. trans_pcie->n_no_reclaim_cmds = trans_cfg->n_no_reclaim_cmds;
  617. if (trans_pcie->n_no_reclaim_cmds)
  618. memcpy(trans_pcie->no_reclaim_cmds, trans_cfg->no_reclaim_cmds,
  619. trans_pcie->n_no_reclaim_cmds * sizeof(u8));
  620. trans_pcie->rx_buf_size_8k = trans_cfg->rx_buf_size_8k;
  621. if (trans_pcie->rx_buf_size_8k)
  622. trans_pcie->rx_page_order = get_order(8 * 1024);
  623. else
  624. trans_pcie->rx_page_order = get_order(4 * 1024);
  625. trans_pcie->wd_timeout =
  626. msecs_to_jiffies(trans_cfg->queue_watchdog_timeout);
  627. trans_pcie->command_names = trans_cfg->command_names;
  628. trans_pcie->bc_table_dword = trans_cfg->bc_table_dword;
  629. }
  630. void iwl_trans_pcie_free(struct iwl_trans *trans)
  631. {
  632. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  633. synchronize_irq(trans_pcie->pci_dev->irq);
  634. iwl_pcie_tx_free(trans);
  635. iwl_pcie_rx_free(trans);
  636. free_irq(trans_pcie->pci_dev->irq, trans);
  637. iwl_pcie_free_ict(trans);
  638. pci_disable_msi(trans_pcie->pci_dev);
  639. iounmap(trans_pcie->hw_base);
  640. pci_release_regions(trans_pcie->pci_dev);
  641. pci_disable_device(trans_pcie->pci_dev);
  642. kmem_cache_destroy(trans->dev_cmd_pool);
  643. kfree(trans);
  644. }
  645. static void iwl_trans_pcie_set_pmi(struct iwl_trans *trans, bool state)
  646. {
  647. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  648. if (state)
  649. set_bit(STATUS_TPOWER_PMI, &trans_pcie->status);
  650. else
  651. clear_bit(STATUS_TPOWER_PMI, &trans_pcie->status);
  652. }
  653. #ifdef CONFIG_PM_SLEEP
  654. static int iwl_trans_pcie_suspend(struct iwl_trans *trans)
  655. {
  656. return 0;
  657. }
  658. static int iwl_trans_pcie_resume(struct iwl_trans *trans)
  659. {
  660. bool hw_rfkill;
  661. iwl_enable_rfkill_int(trans);
  662. hw_rfkill = iwl_is_rfkill_set(trans);
  663. iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rfkill);
  664. return 0;
  665. }
  666. #endif /* CONFIG_PM_SLEEP */
  667. static bool iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent,
  668. unsigned long *flags)
  669. {
  670. int ret;
  671. struct iwl_trans_pcie *pcie_trans = IWL_TRANS_GET_PCIE_TRANS(trans);
  672. spin_lock_irqsave(&pcie_trans->reg_lock, *flags);
  673. /* this bit wakes up the NIC */
  674. __iwl_trans_pcie_set_bit(trans, CSR_GP_CNTRL,
  675. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  676. /*
  677. * These bits say the device is running, and should keep running for
  678. * at least a short while (at least as long as MAC_ACCESS_REQ stays 1),
  679. * but they do not indicate that embedded SRAM is restored yet;
  680. * 3945 and 4965 have volatile SRAM, and must save/restore contents
  681. * to/from host DRAM when sleeping/waking for power-saving.
  682. * Each direction takes approximately 1/4 millisecond; with this
  683. * overhead, it's a good idea to grab and hold MAC_ACCESS_REQUEST if a
  684. * series of register accesses are expected (e.g. reading Event Log),
  685. * to keep device from sleeping.
  686. *
  687. * CSR_UCODE_DRV_GP1 register bit MAC_SLEEP == 0 indicates that
  688. * SRAM is okay/restored. We don't check that here because this call
  689. * is just for hardware register access; but GP1 MAC_SLEEP check is a
  690. * good idea before accessing 3945/4965 SRAM (e.g. reading Event Log).
  691. *
  692. * 5000 series and later (including 1000 series) have non-volatile SRAM,
  693. * and do not save/restore SRAM when power cycling.
  694. */
  695. ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
  696. CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
  697. (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
  698. CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
  699. if (unlikely(ret < 0)) {
  700. iwl_write32(trans, CSR_RESET, CSR_RESET_REG_FLAG_FORCE_NMI);
  701. if (!silent) {
  702. u32 val = iwl_read32(trans, CSR_GP_CNTRL);
  703. WARN_ONCE(1,
  704. "Timeout waiting for hardware access (CSR_GP_CNTRL 0x%08x)\n",
  705. val);
  706. spin_unlock_irqrestore(&pcie_trans->reg_lock, *flags);
  707. return false;
  708. }
  709. }
  710. /*
  711. * Fool sparse by faking we release the lock - sparse will
  712. * track nic_access anyway.
  713. */
  714. __release(&pcie_trans->reg_lock);
  715. return true;
  716. }
  717. static void iwl_trans_pcie_release_nic_access(struct iwl_trans *trans,
  718. unsigned long *flags)
  719. {
  720. struct iwl_trans_pcie *pcie_trans = IWL_TRANS_GET_PCIE_TRANS(trans);
  721. lockdep_assert_held(&pcie_trans->reg_lock);
  722. /*
  723. * Fool sparse by faking we acquiring the lock - sparse will
  724. * track nic_access anyway.
  725. */
  726. __acquire(&pcie_trans->reg_lock);
  727. __iwl_trans_pcie_clear_bit(trans, CSR_GP_CNTRL,
  728. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  729. /*
  730. * Above we read the CSR_GP_CNTRL register, which will flush
  731. * any previous writes, but we need the write that clears the
  732. * MAC_ACCESS_REQ bit to be performed before any other writes
  733. * scheduled on different CPUs (after we drop reg_lock).
  734. */
  735. mmiowb();
  736. spin_unlock_irqrestore(&pcie_trans->reg_lock, *flags);
  737. }
  738. static int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr,
  739. void *buf, int dwords)
  740. {
  741. unsigned long flags;
  742. int offs, ret = 0;
  743. u32 *vals = buf;
  744. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  745. iwl_write32(trans, HBUS_TARG_MEM_RADDR, addr);
  746. for (offs = 0; offs < dwords; offs++)
  747. vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  748. iwl_trans_release_nic_access(trans, &flags);
  749. } else {
  750. ret = -EBUSY;
  751. }
  752. return ret;
  753. }
  754. static int iwl_trans_pcie_write_mem(struct iwl_trans *trans, u32 addr,
  755. void *buf, int dwords)
  756. {
  757. unsigned long flags;
  758. int offs, ret = 0;
  759. u32 *vals = buf;
  760. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  761. iwl_write32(trans, HBUS_TARG_MEM_WADDR, addr);
  762. for (offs = 0; offs < dwords; offs++)
  763. iwl_write32(trans, HBUS_TARG_MEM_WDAT,
  764. vals ? vals[offs] : 0);
  765. iwl_trans_release_nic_access(trans, &flags);
  766. } else {
  767. ret = -EBUSY;
  768. }
  769. return ret;
  770. }
  771. #define IWL_FLUSH_WAIT_MS 2000
  772. static int iwl_trans_pcie_wait_txq_empty(struct iwl_trans *trans)
  773. {
  774. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  775. struct iwl_txq *txq;
  776. struct iwl_queue *q;
  777. int cnt;
  778. unsigned long now = jiffies;
  779. u32 scd_sram_addr;
  780. u8 buf[16];
  781. int ret = 0;
  782. /* waiting for all the tx frames complete might take a while */
  783. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  784. if (cnt == trans_pcie->cmd_queue)
  785. continue;
  786. txq = &trans_pcie->txq[cnt];
  787. q = &txq->q;
  788. while (q->read_ptr != q->write_ptr && !time_after(jiffies,
  789. now + msecs_to_jiffies(IWL_FLUSH_WAIT_MS)))
  790. msleep(1);
  791. if (q->read_ptr != q->write_ptr) {
  792. IWL_ERR(trans,
  793. "fail to flush all tx fifo queues Q %d\n", cnt);
  794. ret = -ETIMEDOUT;
  795. break;
  796. }
  797. }
  798. if (!ret)
  799. return 0;
  800. IWL_ERR(trans, "Current SW read_ptr %d write_ptr %d\n",
  801. txq->q.read_ptr, txq->q.write_ptr);
  802. scd_sram_addr = trans_pcie->scd_base_addr +
  803. SCD_TX_STTS_QUEUE_OFFSET(txq->q.id);
  804. iwl_trans_read_mem_bytes(trans, scd_sram_addr, buf, sizeof(buf));
  805. iwl_print_hex_error(trans, buf, sizeof(buf));
  806. for (cnt = 0; cnt < FH_TCSR_CHNL_NUM; cnt++)
  807. IWL_ERR(trans, "FH TRBs(%d) = 0x%08x\n", cnt,
  808. iwl_read_direct32(trans, FH_TX_TRB_REG(cnt)));
  809. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  810. u32 status = iwl_read_prph(trans, SCD_QUEUE_STATUS_BITS(cnt));
  811. u8 fifo = (status >> SCD_QUEUE_STTS_REG_POS_TXF) & 0x7;
  812. bool active = !!(status & BIT(SCD_QUEUE_STTS_REG_POS_ACTIVE));
  813. u32 tbl_dw =
  814. iwl_trans_read_mem32(trans, trans_pcie->scd_base_addr +
  815. SCD_TRANS_TBL_OFFSET_QUEUE(cnt));
  816. if (cnt & 0x1)
  817. tbl_dw = (tbl_dw & 0xFFFF0000) >> 16;
  818. else
  819. tbl_dw = tbl_dw & 0x0000FFFF;
  820. IWL_ERR(trans,
  821. "Q %d is %sactive and mapped to fifo %d ra_tid 0x%04x [%d,%d]\n",
  822. cnt, active ? "" : "in", fifo, tbl_dw,
  823. iwl_read_prph(trans,
  824. SCD_QUEUE_RDPTR(cnt)) & (txq->q.n_bd - 1),
  825. iwl_read_prph(trans, SCD_QUEUE_WRPTR(cnt)));
  826. }
  827. return ret;
  828. }
  829. static void iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans, u32 reg,
  830. u32 mask, u32 value)
  831. {
  832. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  833. unsigned long flags;
  834. spin_lock_irqsave(&trans_pcie->reg_lock, flags);
  835. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, value);
  836. spin_unlock_irqrestore(&trans_pcie->reg_lock, flags);
  837. }
  838. static const char *get_fh_string(int cmd)
  839. {
  840. #define IWL_CMD(x) case x: return #x
  841. switch (cmd) {
  842. IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  843. IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  844. IWL_CMD(FH_RSCSR_CHNL0_WPTR);
  845. IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  846. IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  847. IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  848. IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  849. IWL_CMD(FH_TSSR_TX_STATUS_REG);
  850. IWL_CMD(FH_TSSR_TX_ERROR_REG);
  851. default:
  852. return "UNKNOWN";
  853. }
  854. #undef IWL_CMD
  855. }
  856. int iwl_pcie_dump_fh(struct iwl_trans *trans, char **buf)
  857. {
  858. int i;
  859. static const u32 fh_tbl[] = {
  860. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  861. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  862. FH_RSCSR_CHNL0_WPTR,
  863. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  864. FH_MEM_RSSR_SHARED_CTRL_REG,
  865. FH_MEM_RSSR_RX_STATUS_REG,
  866. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  867. FH_TSSR_TX_STATUS_REG,
  868. FH_TSSR_TX_ERROR_REG
  869. };
  870. #ifdef CONFIG_IWLWIFI_DEBUGFS
  871. if (buf) {
  872. int pos = 0;
  873. size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  874. *buf = kmalloc(bufsz, GFP_KERNEL);
  875. if (!*buf)
  876. return -ENOMEM;
  877. pos += scnprintf(*buf + pos, bufsz - pos,
  878. "FH register values:\n");
  879. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
  880. pos += scnprintf(*buf + pos, bufsz - pos,
  881. " %34s: 0X%08x\n",
  882. get_fh_string(fh_tbl[i]),
  883. iwl_read_direct32(trans, fh_tbl[i]));
  884. return pos;
  885. }
  886. #endif
  887. IWL_ERR(trans, "FH register values:\n");
  888. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
  889. IWL_ERR(trans, " %34s: 0X%08x\n",
  890. get_fh_string(fh_tbl[i]),
  891. iwl_read_direct32(trans, fh_tbl[i]));
  892. return 0;
  893. }
  894. static const char *get_csr_string(int cmd)
  895. {
  896. #define IWL_CMD(x) case x: return #x
  897. switch (cmd) {
  898. IWL_CMD(CSR_HW_IF_CONFIG_REG);
  899. IWL_CMD(CSR_INT_COALESCING);
  900. IWL_CMD(CSR_INT);
  901. IWL_CMD(CSR_INT_MASK);
  902. IWL_CMD(CSR_FH_INT_STATUS);
  903. IWL_CMD(CSR_GPIO_IN);
  904. IWL_CMD(CSR_RESET);
  905. IWL_CMD(CSR_GP_CNTRL);
  906. IWL_CMD(CSR_HW_REV);
  907. IWL_CMD(CSR_EEPROM_REG);
  908. IWL_CMD(CSR_EEPROM_GP);
  909. IWL_CMD(CSR_OTP_GP_REG);
  910. IWL_CMD(CSR_GIO_REG);
  911. IWL_CMD(CSR_GP_UCODE_REG);
  912. IWL_CMD(CSR_GP_DRIVER_REG);
  913. IWL_CMD(CSR_UCODE_DRV_GP1);
  914. IWL_CMD(CSR_UCODE_DRV_GP2);
  915. IWL_CMD(CSR_LED_REG);
  916. IWL_CMD(CSR_DRAM_INT_TBL_REG);
  917. IWL_CMD(CSR_GIO_CHICKEN_BITS);
  918. IWL_CMD(CSR_ANA_PLL_CFG);
  919. IWL_CMD(CSR_HW_REV_WA_REG);
  920. IWL_CMD(CSR_DBG_HPET_MEM_REG);
  921. default:
  922. return "UNKNOWN";
  923. }
  924. #undef IWL_CMD
  925. }
  926. void iwl_pcie_dump_csr(struct iwl_trans *trans)
  927. {
  928. int i;
  929. static const u32 csr_tbl[] = {
  930. CSR_HW_IF_CONFIG_REG,
  931. CSR_INT_COALESCING,
  932. CSR_INT,
  933. CSR_INT_MASK,
  934. CSR_FH_INT_STATUS,
  935. CSR_GPIO_IN,
  936. CSR_RESET,
  937. CSR_GP_CNTRL,
  938. CSR_HW_REV,
  939. CSR_EEPROM_REG,
  940. CSR_EEPROM_GP,
  941. CSR_OTP_GP_REG,
  942. CSR_GIO_REG,
  943. CSR_GP_UCODE_REG,
  944. CSR_GP_DRIVER_REG,
  945. CSR_UCODE_DRV_GP1,
  946. CSR_UCODE_DRV_GP2,
  947. CSR_LED_REG,
  948. CSR_DRAM_INT_TBL_REG,
  949. CSR_GIO_CHICKEN_BITS,
  950. CSR_ANA_PLL_CFG,
  951. CSR_HW_REV_WA_REG,
  952. CSR_DBG_HPET_MEM_REG
  953. };
  954. IWL_ERR(trans, "CSR values:\n");
  955. IWL_ERR(trans, "(2nd byte of CSR_INT_COALESCING is "
  956. "CSR_INT_PERIODIC_REG)\n");
  957. for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
  958. IWL_ERR(trans, " %25s: 0X%08x\n",
  959. get_csr_string(csr_tbl[i]),
  960. iwl_read32(trans, csr_tbl[i]));
  961. }
  962. }
  963. #ifdef CONFIG_IWLWIFI_DEBUGFS
  964. /* create and remove of files */
  965. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  966. if (!debugfs_create_file(#name, mode, parent, trans, \
  967. &iwl_dbgfs_##name##_ops)) \
  968. goto err; \
  969. } while (0)
  970. /* file operation */
  971. #define DEBUGFS_READ_FUNC(name) \
  972. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  973. char __user *user_buf, \
  974. size_t count, loff_t *ppos);
  975. #define DEBUGFS_WRITE_FUNC(name) \
  976. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  977. const char __user *user_buf, \
  978. size_t count, loff_t *ppos);
  979. #define DEBUGFS_READ_FILE_OPS(name) \
  980. DEBUGFS_READ_FUNC(name); \
  981. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  982. .read = iwl_dbgfs_##name##_read, \
  983. .open = simple_open, \
  984. .llseek = generic_file_llseek, \
  985. };
  986. #define DEBUGFS_WRITE_FILE_OPS(name) \
  987. DEBUGFS_WRITE_FUNC(name); \
  988. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  989. .write = iwl_dbgfs_##name##_write, \
  990. .open = simple_open, \
  991. .llseek = generic_file_llseek, \
  992. };
  993. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  994. DEBUGFS_READ_FUNC(name); \
  995. DEBUGFS_WRITE_FUNC(name); \
  996. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  997. .write = iwl_dbgfs_##name##_write, \
  998. .read = iwl_dbgfs_##name##_read, \
  999. .open = simple_open, \
  1000. .llseek = generic_file_llseek, \
  1001. };
  1002. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  1003. char __user *user_buf,
  1004. size_t count, loff_t *ppos)
  1005. {
  1006. struct iwl_trans *trans = file->private_data;
  1007. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1008. struct iwl_txq *txq;
  1009. struct iwl_queue *q;
  1010. char *buf;
  1011. int pos = 0;
  1012. int cnt;
  1013. int ret;
  1014. size_t bufsz;
  1015. bufsz = sizeof(char) * 64 * trans->cfg->base_params->num_of_queues;
  1016. if (!trans_pcie->txq)
  1017. return -EAGAIN;
  1018. buf = kzalloc(bufsz, GFP_KERNEL);
  1019. if (!buf)
  1020. return -ENOMEM;
  1021. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  1022. txq = &trans_pcie->txq[cnt];
  1023. q = &txq->q;
  1024. pos += scnprintf(buf + pos, bufsz - pos,
  1025. "hwq %.2d: read=%u write=%u use=%d stop=%d\n",
  1026. cnt, q->read_ptr, q->write_ptr,
  1027. !!test_bit(cnt, trans_pcie->queue_used),
  1028. !!test_bit(cnt, trans_pcie->queue_stopped));
  1029. }
  1030. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1031. kfree(buf);
  1032. return ret;
  1033. }
  1034. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  1035. char __user *user_buf,
  1036. size_t count, loff_t *ppos)
  1037. {
  1038. struct iwl_trans *trans = file->private_data;
  1039. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1040. struct iwl_rxq *rxq = &trans_pcie->rxq;
  1041. char buf[256];
  1042. int pos = 0;
  1043. const size_t bufsz = sizeof(buf);
  1044. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  1045. rxq->read);
  1046. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  1047. rxq->write);
  1048. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  1049. rxq->free_count);
  1050. if (rxq->rb_stts) {
  1051. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  1052. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  1053. } else {
  1054. pos += scnprintf(buf + pos, bufsz - pos,
  1055. "closed_rb_num: Not Allocated\n");
  1056. }
  1057. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1058. }
  1059. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  1060. char __user *user_buf,
  1061. size_t count, loff_t *ppos)
  1062. {
  1063. struct iwl_trans *trans = file->private_data;
  1064. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1065. struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
  1066. int pos = 0;
  1067. char *buf;
  1068. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  1069. ssize_t ret;
  1070. buf = kzalloc(bufsz, GFP_KERNEL);
  1071. if (!buf)
  1072. return -ENOMEM;
  1073. pos += scnprintf(buf + pos, bufsz - pos,
  1074. "Interrupt Statistics Report:\n");
  1075. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  1076. isr_stats->hw);
  1077. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  1078. isr_stats->sw);
  1079. if (isr_stats->sw || isr_stats->hw) {
  1080. pos += scnprintf(buf + pos, bufsz - pos,
  1081. "\tLast Restarting Code: 0x%X\n",
  1082. isr_stats->err_code);
  1083. }
  1084. #ifdef CONFIG_IWLWIFI_DEBUG
  1085. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  1086. isr_stats->sch);
  1087. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  1088. isr_stats->alive);
  1089. #endif
  1090. pos += scnprintf(buf + pos, bufsz - pos,
  1091. "HW RF KILL switch toggled:\t %u\n", isr_stats->rfkill);
  1092. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  1093. isr_stats->ctkill);
  1094. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  1095. isr_stats->wakeup);
  1096. pos += scnprintf(buf + pos, bufsz - pos,
  1097. "Rx command responses:\t\t %u\n", isr_stats->rx);
  1098. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  1099. isr_stats->tx);
  1100. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  1101. isr_stats->unhandled);
  1102. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1103. kfree(buf);
  1104. return ret;
  1105. }
  1106. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  1107. const char __user *user_buf,
  1108. size_t count, loff_t *ppos)
  1109. {
  1110. struct iwl_trans *trans = file->private_data;
  1111. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1112. struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
  1113. char buf[8];
  1114. int buf_size;
  1115. u32 reset_flag;
  1116. memset(buf, 0, sizeof(buf));
  1117. buf_size = min(count, sizeof(buf) - 1);
  1118. if (copy_from_user(buf, user_buf, buf_size))
  1119. return -EFAULT;
  1120. if (sscanf(buf, "%x", &reset_flag) != 1)
  1121. return -EFAULT;
  1122. if (reset_flag == 0)
  1123. memset(isr_stats, 0, sizeof(*isr_stats));
  1124. return count;
  1125. }
  1126. static ssize_t iwl_dbgfs_csr_write(struct file *file,
  1127. const char __user *user_buf,
  1128. size_t count, loff_t *ppos)
  1129. {
  1130. struct iwl_trans *trans = file->private_data;
  1131. char buf[8];
  1132. int buf_size;
  1133. int csr;
  1134. memset(buf, 0, sizeof(buf));
  1135. buf_size = min(count, sizeof(buf) - 1);
  1136. if (copy_from_user(buf, user_buf, buf_size))
  1137. return -EFAULT;
  1138. if (sscanf(buf, "%d", &csr) != 1)
  1139. return -EFAULT;
  1140. iwl_pcie_dump_csr(trans);
  1141. return count;
  1142. }
  1143. static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
  1144. char __user *user_buf,
  1145. size_t count, loff_t *ppos)
  1146. {
  1147. struct iwl_trans *trans = file->private_data;
  1148. char *buf = NULL;
  1149. int pos = 0;
  1150. ssize_t ret = -EFAULT;
  1151. ret = pos = iwl_pcie_dump_fh(trans, &buf);
  1152. if (buf) {
  1153. ret = simple_read_from_buffer(user_buf,
  1154. count, ppos, buf, pos);
  1155. kfree(buf);
  1156. }
  1157. return ret;
  1158. }
  1159. static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
  1160. const char __user *user_buf,
  1161. size_t count, loff_t *ppos)
  1162. {
  1163. struct iwl_trans *trans = file->private_data;
  1164. if (!trans->op_mode)
  1165. return -EAGAIN;
  1166. local_bh_disable();
  1167. iwl_op_mode_nic_error(trans->op_mode);
  1168. local_bh_enable();
  1169. return count;
  1170. }
  1171. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  1172. DEBUGFS_READ_FILE_OPS(fh_reg);
  1173. DEBUGFS_READ_FILE_OPS(rx_queue);
  1174. DEBUGFS_READ_FILE_OPS(tx_queue);
  1175. DEBUGFS_WRITE_FILE_OPS(csr);
  1176. DEBUGFS_WRITE_FILE_OPS(fw_restart);
  1177. /*
  1178. * Create the debugfs files and directories
  1179. *
  1180. */
  1181. static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
  1182. struct dentry *dir)
  1183. {
  1184. DEBUGFS_ADD_FILE(rx_queue, dir, S_IRUSR);
  1185. DEBUGFS_ADD_FILE(tx_queue, dir, S_IRUSR);
  1186. DEBUGFS_ADD_FILE(interrupt, dir, S_IWUSR | S_IRUSR);
  1187. DEBUGFS_ADD_FILE(csr, dir, S_IWUSR);
  1188. DEBUGFS_ADD_FILE(fh_reg, dir, S_IRUSR);
  1189. DEBUGFS_ADD_FILE(fw_restart, dir, S_IWUSR);
  1190. return 0;
  1191. err:
  1192. IWL_ERR(trans, "failed to create the trans debugfs entry\n");
  1193. return -ENOMEM;
  1194. }
  1195. #else
  1196. static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
  1197. struct dentry *dir)
  1198. {
  1199. return 0;
  1200. }
  1201. #endif /*CONFIG_IWLWIFI_DEBUGFS */
  1202. static const struct iwl_trans_ops trans_ops_pcie = {
  1203. .start_hw = iwl_trans_pcie_start_hw,
  1204. .stop_hw = iwl_trans_pcie_stop_hw,
  1205. .fw_alive = iwl_trans_pcie_fw_alive,
  1206. .start_fw = iwl_trans_pcie_start_fw,
  1207. .stop_device = iwl_trans_pcie_stop_device,
  1208. .d3_suspend = iwl_trans_pcie_d3_suspend,
  1209. .d3_resume = iwl_trans_pcie_d3_resume,
  1210. .send_cmd = iwl_trans_pcie_send_hcmd,
  1211. .tx = iwl_trans_pcie_tx,
  1212. .reclaim = iwl_trans_pcie_reclaim,
  1213. .txq_disable = iwl_trans_pcie_txq_disable,
  1214. .txq_enable = iwl_trans_pcie_txq_enable,
  1215. .dbgfs_register = iwl_trans_pcie_dbgfs_register,
  1216. .wait_tx_queue_empty = iwl_trans_pcie_wait_txq_empty,
  1217. #ifdef CONFIG_PM_SLEEP
  1218. .suspend = iwl_trans_pcie_suspend,
  1219. .resume = iwl_trans_pcie_resume,
  1220. #endif
  1221. .write8 = iwl_trans_pcie_write8,
  1222. .write32 = iwl_trans_pcie_write32,
  1223. .read32 = iwl_trans_pcie_read32,
  1224. .read_prph = iwl_trans_pcie_read_prph,
  1225. .write_prph = iwl_trans_pcie_write_prph,
  1226. .read_mem = iwl_trans_pcie_read_mem,
  1227. .write_mem = iwl_trans_pcie_write_mem,
  1228. .configure = iwl_trans_pcie_configure,
  1229. .set_pmi = iwl_trans_pcie_set_pmi,
  1230. .grab_nic_access = iwl_trans_pcie_grab_nic_access,
  1231. .release_nic_access = iwl_trans_pcie_release_nic_access,
  1232. .set_bits_mask = iwl_trans_pcie_set_bits_mask,
  1233. };
  1234. struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
  1235. const struct pci_device_id *ent,
  1236. const struct iwl_cfg *cfg)
  1237. {
  1238. struct iwl_trans_pcie *trans_pcie;
  1239. struct iwl_trans *trans;
  1240. u16 pci_cmd;
  1241. int err;
  1242. trans = kzalloc(sizeof(struct iwl_trans) +
  1243. sizeof(struct iwl_trans_pcie), GFP_KERNEL);
  1244. if (!trans)
  1245. return NULL;
  1246. trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1247. trans->ops = &trans_ops_pcie;
  1248. trans->cfg = cfg;
  1249. trans_lockdep_init(trans);
  1250. trans_pcie->trans = trans;
  1251. spin_lock_init(&trans_pcie->irq_lock);
  1252. spin_lock_init(&trans_pcie->reg_lock);
  1253. init_waitqueue_head(&trans_pcie->ucode_write_waitq);
  1254. /* W/A - seems to solve weird behavior. We need to remove this if we
  1255. * don't want to stay in L1 all the time. This wastes a lot of power */
  1256. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  1257. PCIE_LINK_STATE_CLKPM);
  1258. if (pci_enable_device(pdev)) {
  1259. err = -ENODEV;
  1260. goto out_no_pci;
  1261. }
  1262. pci_set_master(pdev);
  1263. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  1264. if (!err)
  1265. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  1266. if (err) {
  1267. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1268. if (!err)
  1269. err = pci_set_consistent_dma_mask(pdev,
  1270. DMA_BIT_MASK(32));
  1271. /* both attempts failed: */
  1272. if (err) {
  1273. dev_err(&pdev->dev, "No suitable DMA available\n");
  1274. goto out_pci_disable_device;
  1275. }
  1276. }
  1277. err = pci_request_regions(pdev, DRV_NAME);
  1278. if (err) {
  1279. dev_err(&pdev->dev, "pci_request_regions failed\n");
  1280. goto out_pci_disable_device;
  1281. }
  1282. trans_pcie->hw_base = pci_ioremap_bar(pdev, 0);
  1283. if (!trans_pcie->hw_base) {
  1284. dev_err(&pdev->dev, "pci_ioremap_bar failed\n");
  1285. err = -ENODEV;
  1286. goto out_pci_release_regions;
  1287. }
  1288. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  1289. * PCI Tx retries from interfering with C3 CPU state */
  1290. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  1291. err = pci_enable_msi(pdev);
  1292. if (err) {
  1293. dev_err(&pdev->dev, "pci_enable_msi failed(0X%x)\n", err);
  1294. /* enable rfkill interrupt: hw bug w/a */
  1295. pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
  1296. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  1297. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  1298. pci_write_config_word(pdev, PCI_COMMAND, pci_cmd);
  1299. }
  1300. }
  1301. trans->dev = &pdev->dev;
  1302. trans_pcie->pci_dev = pdev;
  1303. trans->hw_rev = iwl_read32(trans, CSR_HW_REV);
  1304. trans->hw_id = (pdev->device << 16) + pdev->subsystem_device;
  1305. snprintf(trans->hw_id_str, sizeof(trans->hw_id_str),
  1306. "PCI ID: 0x%04X:0x%04X", pdev->device, pdev->subsystem_device);
  1307. /* Initialize the wait queue for commands */
  1308. init_waitqueue_head(&trans_pcie->wait_command_queue);
  1309. snprintf(trans->dev_cmd_pool_name, sizeof(trans->dev_cmd_pool_name),
  1310. "iwl_cmd_pool:%s", dev_name(trans->dev));
  1311. trans->dev_cmd_headroom = 0;
  1312. trans->dev_cmd_pool =
  1313. kmem_cache_create(trans->dev_cmd_pool_name,
  1314. sizeof(struct iwl_device_cmd)
  1315. + trans->dev_cmd_headroom,
  1316. sizeof(void *),
  1317. SLAB_HWCACHE_ALIGN,
  1318. NULL);
  1319. if (!trans->dev_cmd_pool)
  1320. goto out_pci_disable_msi;
  1321. trans_pcie->inta_mask = CSR_INI_SET_MASK;
  1322. if (iwl_pcie_alloc_ict(trans))
  1323. goto out_free_cmd_pool;
  1324. if (request_threaded_irq(pdev->irq, iwl_pcie_isr_ict,
  1325. iwl_pcie_irq_handler,
  1326. IRQF_SHARED, DRV_NAME, trans)) {
  1327. IWL_ERR(trans, "Error allocating IRQ %d\n", pdev->irq);
  1328. goto out_free_ict;
  1329. }
  1330. return trans;
  1331. out_free_ict:
  1332. iwl_pcie_free_ict(trans);
  1333. out_free_cmd_pool:
  1334. kmem_cache_destroy(trans->dev_cmd_pool);
  1335. out_pci_disable_msi:
  1336. pci_disable_msi(pdev);
  1337. out_pci_release_regions:
  1338. pci_release_regions(pdev);
  1339. out_pci_disable_device:
  1340. pci_disable_device(pdev);
  1341. out_no_pci:
  1342. kfree(trans);
  1343. return NULL;
  1344. }