trans.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  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 COPYING.
  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, chunk_sz = section->len;
  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, chunk_sz, &p_addr,
  345. GFP_KERNEL | __GFP_NOWARN);
  346. if (!v_addr) {
  347. IWL_DEBUG_INFO(trans, "Falling back to small chunks of DMA\n");
  348. chunk_sz = PAGE_SIZE;
  349. v_addr = dma_alloc_coherent(trans->dev, chunk_sz,
  350. &p_addr, GFP_KERNEL);
  351. if (!v_addr)
  352. return -ENOMEM;
  353. }
  354. for (offset = 0; offset < section->len; offset += chunk_sz) {
  355. u32 copy_size;
  356. copy_size = min_t(u32, chunk_sz, section->len - offset);
  357. memcpy(v_addr, (u8 *)section->data + offset, copy_size);
  358. ret = iwl_pcie_load_firmware_chunk(trans,
  359. section->offset + offset,
  360. p_addr, copy_size);
  361. if (ret) {
  362. IWL_ERR(trans,
  363. "Could not load the [%d] uCode section\n",
  364. section_num);
  365. break;
  366. }
  367. }
  368. dma_free_coherent(trans->dev, chunk_sz, v_addr, p_addr);
  369. return ret;
  370. }
  371. static int iwl_pcie_load_given_ucode(struct iwl_trans *trans,
  372. const struct fw_img *image)
  373. {
  374. int i, ret = 0;
  375. for (i = 0; i < IWL_UCODE_SECTION_MAX; i++) {
  376. if (!image->sec[i].data)
  377. break;
  378. ret = iwl_pcie_load_section(trans, i, &image->sec[i]);
  379. if (ret)
  380. return ret;
  381. }
  382. /* Remove all resets to allow NIC to operate */
  383. iwl_write32(trans, CSR_RESET, 0);
  384. return 0;
  385. }
  386. static int iwl_trans_pcie_start_fw(struct iwl_trans *trans,
  387. const struct fw_img *fw, bool run_in_rfkill)
  388. {
  389. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  390. int ret;
  391. bool hw_rfkill;
  392. /* This may fail if AMT took ownership of the device */
  393. if (iwl_pcie_prepare_card_hw(trans)) {
  394. IWL_WARN(trans, "Exit HW not ready\n");
  395. return -EIO;
  396. }
  397. clear_bit(STATUS_FW_ERROR, &trans_pcie->status);
  398. iwl_enable_rfkill_int(trans);
  399. /* If platform's RF_KILL switch is NOT set to KILL */
  400. hw_rfkill = iwl_is_rfkill_set(trans);
  401. if (hw_rfkill)
  402. set_bit(STATUS_RFKILL, &trans_pcie->status);
  403. else
  404. clear_bit(STATUS_RFKILL, &trans_pcie->status);
  405. iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rfkill);
  406. if (hw_rfkill && !run_in_rfkill)
  407. return -ERFKILL;
  408. iwl_write32(trans, CSR_INT, 0xFFFFFFFF);
  409. ret = iwl_pcie_nic_init(trans);
  410. if (ret) {
  411. IWL_ERR(trans, "Unable to init nic\n");
  412. return ret;
  413. }
  414. /* 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,
  417. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  418. /* clear (again), then enable host interrupts */
  419. iwl_write32(trans, CSR_INT, 0xFFFFFFFF);
  420. iwl_enable_interrupts(trans);
  421. /* really make sure rfkill handshake bits are cleared */
  422. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  423. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  424. /* Load the given image to the HW */
  425. return iwl_pcie_load_given_ucode(trans, fw);
  426. }
  427. static void iwl_trans_pcie_fw_alive(struct iwl_trans *trans, u32 scd_addr)
  428. {
  429. iwl_pcie_reset_ict(trans);
  430. iwl_pcie_tx_start(trans, scd_addr);
  431. }
  432. static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
  433. {
  434. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  435. unsigned long flags;
  436. /* tell the device to stop sending interrupts */
  437. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  438. iwl_disable_interrupts(trans);
  439. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  440. /* device going down, Stop using ICT table */
  441. iwl_pcie_disable_ict(trans);
  442. /*
  443. * If a HW restart happens during firmware loading,
  444. * then the firmware loading might call this function
  445. * and later it might be called again due to the
  446. * restart. So don't process again if the device is
  447. * already dead.
  448. */
  449. if (test_bit(STATUS_DEVICE_ENABLED, &trans_pcie->status)) {
  450. iwl_pcie_tx_stop(trans);
  451. iwl_pcie_rx_stop(trans);
  452. /* Power-down device's busmaster DMA clocks */
  453. iwl_write_prph(trans, APMG_CLK_DIS_REG,
  454. APMG_CLK_VAL_DMA_CLK_RQT);
  455. udelay(5);
  456. }
  457. /* Make sure (redundant) we've released our request to stay awake */
  458. iwl_clear_bit(trans, CSR_GP_CNTRL,
  459. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  460. /* Stop the device, and put it in low power state */
  461. iwl_pcie_apm_stop(trans);
  462. /* Upon stop, the APM issues an interrupt if HW RF kill is set.
  463. * Clean again the interrupt here
  464. */
  465. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  466. iwl_disable_interrupts(trans);
  467. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  468. iwl_enable_rfkill_int(trans);
  469. /* stop and reset the on-board processor */
  470. iwl_write32(trans, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  471. /* clear all status bits */
  472. clear_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status);
  473. clear_bit(STATUS_INT_ENABLED, &trans_pcie->status);
  474. clear_bit(STATUS_DEVICE_ENABLED, &trans_pcie->status);
  475. clear_bit(STATUS_TPOWER_PMI, &trans_pcie->status);
  476. clear_bit(STATUS_RFKILL, &trans_pcie->status);
  477. }
  478. static void iwl_trans_pcie_d3_suspend(struct iwl_trans *trans, bool test)
  479. {
  480. iwl_disable_interrupts(trans);
  481. /*
  482. * in testing mode, the host stays awake and the
  483. * hardware won't be reset (not even partially)
  484. */
  485. if (test)
  486. return;
  487. iwl_pcie_disable_ict(trans);
  488. iwl_clear_bit(trans, CSR_GP_CNTRL,
  489. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  490. iwl_clear_bit(trans, CSR_GP_CNTRL,
  491. CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  492. /*
  493. * reset TX queues -- some of their registers reset during S3
  494. * so if we don't reset everything here the D3 image would try
  495. * to execute some invalid memory upon resume
  496. */
  497. iwl_trans_pcie_tx_reset(trans);
  498. iwl_pcie_set_pwr(trans, true);
  499. }
  500. static int iwl_trans_pcie_d3_resume(struct iwl_trans *trans,
  501. enum iwl_d3_status *status,
  502. bool test)
  503. {
  504. u32 val;
  505. int ret;
  506. if (test) {
  507. iwl_enable_interrupts(trans);
  508. *status = IWL_D3_STATUS_ALIVE;
  509. return 0;
  510. }
  511. iwl_pcie_set_pwr(trans, false);
  512. val = iwl_read32(trans, CSR_RESET);
  513. if (val & CSR_RESET_REG_FLAG_NEVO_RESET) {
  514. *status = IWL_D3_STATUS_RESET;
  515. return 0;
  516. }
  517. /*
  518. * Also enables interrupts - none will happen as the device doesn't
  519. * know we're waking it up, only when the opmode actually tells it
  520. * after this call.
  521. */
  522. iwl_pcie_reset_ict(trans);
  523. iwl_set_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  524. iwl_set_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  525. ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
  526. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  527. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  528. 25000);
  529. if (ret) {
  530. IWL_ERR(trans, "Failed to resume the device (mac ready)\n");
  531. return ret;
  532. }
  533. iwl_trans_pcie_tx_reset(trans);
  534. ret = iwl_pcie_rx_init(trans);
  535. if (ret) {
  536. IWL_ERR(trans, "Failed to resume the device (RX reset)\n");
  537. return ret;
  538. }
  539. *status = IWL_D3_STATUS_ALIVE;
  540. return 0;
  541. }
  542. static int iwl_trans_pcie_start_hw(struct iwl_trans *trans)
  543. {
  544. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  545. bool hw_rfkill;
  546. int err;
  547. err = iwl_pcie_prepare_card_hw(trans);
  548. if (err) {
  549. IWL_ERR(trans, "Error while preparing HW: %d\n", err);
  550. return err;
  551. }
  552. /* Reset the entire device */
  553. iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  554. usleep_range(10, 15);
  555. iwl_pcie_apm_init(trans);
  556. /* From now on, the op_mode will be kept updated about RF kill state */
  557. iwl_enable_rfkill_int(trans);
  558. hw_rfkill = iwl_is_rfkill_set(trans);
  559. if (hw_rfkill)
  560. set_bit(STATUS_RFKILL, &trans_pcie->status);
  561. else
  562. clear_bit(STATUS_RFKILL, &trans_pcie->status);
  563. iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rfkill);
  564. return 0;
  565. }
  566. static void iwl_trans_pcie_stop_hw(struct iwl_trans *trans,
  567. bool op_mode_leaving)
  568. {
  569. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  570. bool hw_rfkill;
  571. unsigned long flags;
  572. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  573. iwl_disable_interrupts(trans);
  574. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  575. iwl_pcie_apm_stop(trans);
  576. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  577. iwl_disable_interrupts(trans);
  578. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  579. iwl_pcie_disable_ict(trans);
  580. if (!op_mode_leaving) {
  581. /*
  582. * Even if we stop the HW, we still want the RF kill
  583. * interrupt
  584. */
  585. iwl_enable_rfkill_int(trans);
  586. /*
  587. * Check again since the RF kill state may have changed while
  588. * all the interrupts were disabled, in this case we couldn't
  589. * receive the RF kill interrupt and update the state in the
  590. * op_mode.
  591. */
  592. hw_rfkill = iwl_is_rfkill_set(trans);
  593. if (hw_rfkill)
  594. set_bit(STATUS_RFKILL, &trans_pcie->status);
  595. else
  596. clear_bit(STATUS_RFKILL, &trans_pcie->status);
  597. iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rfkill);
  598. }
  599. }
  600. static void iwl_trans_pcie_write8(struct iwl_trans *trans, u32 ofs, u8 val)
  601. {
  602. writeb(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  603. }
  604. static void iwl_trans_pcie_write32(struct iwl_trans *trans, u32 ofs, u32 val)
  605. {
  606. writel(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  607. }
  608. static u32 iwl_trans_pcie_read32(struct iwl_trans *trans, u32 ofs)
  609. {
  610. return readl(IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  611. }
  612. static u32 iwl_trans_pcie_read_prph(struct iwl_trans *trans, u32 reg)
  613. {
  614. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_RADDR,
  615. ((reg & 0x000FFFFF) | (3 << 24)));
  616. return iwl_trans_pcie_read32(trans, HBUS_TARG_PRPH_RDAT);
  617. }
  618. static void iwl_trans_pcie_write_prph(struct iwl_trans *trans, u32 addr,
  619. u32 val)
  620. {
  621. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_WADDR,
  622. ((addr & 0x000FFFFF) | (3 << 24)));
  623. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_WDAT, val);
  624. }
  625. static void iwl_trans_pcie_configure(struct iwl_trans *trans,
  626. const struct iwl_trans_config *trans_cfg)
  627. {
  628. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  629. trans_pcie->cmd_queue = trans_cfg->cmd_queue;
  630. trans_pcie->cmd_fifo = trans_cfg->cmd_fifo;
  631. if (WARN_ON(trans_cfg->n_no_reclaim_cmds > MAX_NO_RECLAIM_CMDS))
  632. trans_pcie->n_no_reclaim_cmds = 0;
  633. else
  634. trans_pcie->n_no_reclaim_cmds = trans_cfg->n_no_reclaim_cmds;
  635. if (trans_pcie->n_no_reclaim_cmds)
  636. memcpy(trans_pcie->no_reclaim_cmds, trans_cfg->no_reclaim_cmds,
  637. trans_pcie->n_no_reclaim_cmds * sizeof(u8));
  638. trans_pcie->rx_buf_size_8k = trans_cfg->rx_buf_size_8k;
  639. if (trans_pcie->rx_buf_size_8k)
  640. trans_pcie->rx_page_order = get_order(8 * 1024);
  641. else
  642. trans_pcie->rx_page_order = get_order(4 * 1024);
  643. trans_pcie->wd_timeout =
  644. msecs_to_jiffies(trans_cfg->queue_watchdog_timeout);
  645. trans_pcie->command_names = trans_cfg->command_names;
  646. trans_pcie->bc_table_dword = trans_cfg->bc_table_dword;
  647. }
  648. void iwl_trans_pcie_free(struct iwl_trans *trans)
  649. {
  650. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  651. synchronize_irq(trans_pcie->pci_dev->irq);
  652. iwl_pcie_tx_free(trans);
  653. iwl_pcie_rx_free(trans);
  654. free_irq(trans_pcie->pci_dev->irq, trans);
  655. iwl_pcie_free_ict(trans);
  656. pci_disable_msi(trans_pcie->pci_dev);
  657. iounmap(trans_pcie->hw_base);
  658. pci_release_regions(trans_pcie->pci_dev);
  659. pci_disable_device(trans_pcie->pci_dev);
  660. kmem_cache_destroy(trans->dev_cmd_pool);
  661. kfree(trans);
  662. }
  663. static void iwl_trans_pcie_set_pmi(struct iwl_trans *trans, bool state)
  664. {
  665. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  666. if (state)
  667. set_bit(STATUS_TPOWER_PMI, &trans_pcie->status);
  668. else
  669. clear_bit(STATUS_TPOWER_PMI, &trans_pcie->status);
  670. }
  671. #ifdef CONFIG_PM_SLEEP
  672. static int iwl_trans_pcie_suspend(struct iwl_trans *trans)
  673. {
  674. return 0;
  675. }
  676. static int iwl_trans_pcie_resume(struct iwl_trans *trans)
  677. {
  678. bool hw_rfkill;
  679. iwl_enable_rfkill_int(trans);
  680. hw_rfkill = iwl_is_rfkill_set(trans);
  681. iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rfkill);
  682. return 0;
  683. }
  684. #endif /* CONFIG_PM_SLEEP */
  685. static bool iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent,
  686. unsigned long *flags)
  687. {
  688. int ret;
  689. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  690. spin_lock_irqsave(&trans_pcie->reg_lock, *flags);
  691. /* this bit wakes up the NIC */
  692. __iwl_trans_pcie_set_bit(trans, CSR_GP_CNTRL,
  693. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  694. /*
  695. * These bits say the device is running, and should keep running for
  696. * at least a short while (at least as long as MAC_ACCESS_REQ stays 1),
  697. * but they do not indicate that embedded SRAM is restored yet;
  698. * 3945 and 4965 have volatile SRAM, and must save/restore contents
  699. * to/from host DRAM when sleeping/waking for power-saving.
  700. * Each direction takes approximately 1/4 millisecond; with this
  701. * overhead, it's a good idea to grab and hold MAC_ACCESS_REQUEST if a
  702. * series of register accesses are expected (e.g. reading Event Log),
  703. * to keep device from sleeping.
  704. *
  705. * CSR_UCODE_DRV_GP1 register bit MAC_SLEEP == 0 indicates that
  706. * SRAM is okay/restored. We don't check that here because this call
  707. * is just for hardware register access; but GP1 MAC_SLEEP check is a
  708. * good idea before accessing 3945/4965 SRAM (e.g. reading Event Log).
  709. *
  710. * 5000 series and later (including 1000 series) have non-volatile SRAM,
  711. * and do not save/restore SRAM when power cycling.
  712. */
  713. ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
  714. CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
  715. (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
  716. CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
  717. if (unlikely(ret < 0)) {
  718. iwl_write32(trans, CSR_RESET, CSR_RESET_REG_FLAG_FORCE_NMI);
  719. if (!silent) {
  720. u32 val = iwl_read32(trans, CSR_GP_CNTRL);
  721. WARN_ONCE(1,
  722. "Timeout waiting for hardware access (CSR_GP_CNTRL 0x%08x)\n",
  723. val);
  724. spin_unlock_irqrestore(&trans_pcie->reg_lock, *flags);
  725. return false;
  726. }
  727. }
  728. /*
  729. * Fool sparse by faking we release the lock - sparse will
  730. * track nic_access anyway.
  731. */
  732. __release(&trans_pcie->reg_lock);
  733. return true;
  734. }
  735. static void iwl_trans_pcie_release_nic_access(struct iwl_trans *trans,
  736. unsigned long *flags)
  737. {
  738. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  739. lockdep_assert_held(&trans_pcie->reg_lock);
  740. /*
  741. * Fool sparse by faking we acquiring the lock - sparse will
  742. * track nic_access anyway.
  743. */
  744. __acquire(&trans_pcie->reg_lock);
  745. __iwl_trans_pcie_clear_bit(trans, CSR_GP_CNTRL,
  746. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  747. /*
  748. * Above we read the CSR_GP_CNTRL register, which will flush
  749. * any previous writes, but we need the write that clears the
  750. * MAC_ACCESS_REQ bit to be performed before any other writes
  751. * scheduled on different CPUs (after we drop reg_lock).
  752. */
  753. mmiowb();
  754. spin_unlock_irqrestore(&trans_pcie->reg_lock, *flags);
  755. }
  756. static int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr,
  757. void *buf, int dwords)
  758. {
  759. unsigned long flags;
  760. int offs, ret = 0;
  761. u32 *vals = buf;
  762. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  763. iwl_write32(trans, HBUS_TARG_MEM_RADDR, addr);
  764. for (offs = 0; offs < dwords; offs++)
  765. vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  766. iwl_trans_release_nic_access(trans, &flags);
  767. } else {
  768. ret = -EBUSY;
  769. }
  770. return ret;
  771. }
  772. static int iwl_trans_pcie_write_mem(struct iwl_trans *trans, u32 addr,
  773. const void *buf, int dwords)
  774. {
  775. unsigned long flags;
  776. int offs, ret = 0;
  777. const u32 *vals = buf;
  778. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  779. iwl_write32(trans, HBUS_TARG_MEM_WADDR, addr);
  780. for (offs = 0; offs < dwords; offs++)
  781. iwl_write32(trans, HBUS_TARG_MEM_WDAT,
  782. vals ? vals[offs] : 0);
  783. iwl_trans_release_nic_access(trans, &flags);
  784. } else {
  785. ret = -EBUSY;
  786. }
  787. return ret;
  788. }
  789. #define IWL_FLUSH_WAIT_MS 2000
  790. static int iwl_trans_pcie_wait_txq_empty(struct iwl_trans *trans)
  791. {
  792. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  793. struct iwl_txq *txq;
  794. struct iwl_queue *q;
  795. int cnt;
  796. unsigned long now = jiffies;
  797. u32 scd_sram_addr;
  798. u8 buf[16];
  799. int ret = 0;
  800. /* waiting for all the tx frames complete might take a while */
  801. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  802. if (cnt == trans_pcie->cmd_queue)
  803. continue;
  804. txq = &trans_pcie->txq[cnt];
  805. q = &txq->q;
  806. while (q->read_ptr != q->write_ptr && !time_after(jiffies,
  807. now + msecs_to_jiffies(IWL_FLUSH_WAIT_MS)))
  808. msleep(1);
  809. if (q->read_ptr != q->write_ptr) {
  810. IWL_ERR(trans,
  811. "fail to flush all tx fifo queues Q %d\n", cnt);
  812. ret = -ETIMEDOUT;
  813. break;
  814. }
  815. }
  816. if (!ret)
  817. return 0;
  818. IWL_ERR(trans, "Current SW read_ptr %d write_ptr %d\n",
  819. txq->q.read_ptr, txq->q.write_ptr);
  820. scd_sram_addr = trans_pcie->scd_base_addr +
  821. SCD_TX_STTS_QUEUE_OFFSET(txq->q.id);
  822. iwl_trans_read_mem_bytes(trans, scd_sram_addr, buf, sizeof(buf));
  823. iwl_print_hex_error(trans, buf, sizeof(buf));
  824. for (cnt = 0; cnt < FH_TCSR_CHNL_NUM; cnt++)
  825. IWL_ERR(trans, "FH TRBs(%d) = 0x%08x\n", cnt,
  826. iwl_read_direct32(trans, FH_TX_TRB_REG(cnt)));
  827. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  828. u32 status = iwl_read_prph(trans, SCD_QUEUE_STATUS_BITS(cnt));
  829. u8 fifo = (status >> SCD_QUEUE_STTS_REG_POS_TXF) & 0x7;
  830. bool active = !!(status & BIT(SCD_QUEUE_STTS_REG_POS_ACTIVE));
  831. u32 tbl_dw =
  832. iwl_trans_read_mem32(trans, trans_pcie->scd_base_addr +
  833. SCD_TRANS_TBL_OFFSET_QUEUE(cnt));
  834. if (cnt & 0x1)
  835. tbl_dw = (tbl_dw & 0xFFFF0000) >> 16;
  836. else
  837. tbl_dw = tbl_dw & 0x0000FFFF;
  838. IWL_ERR(trans,
  839. "Q %d is %sactive and mapped to fifo %d ra_tid 0x%04x [%d,%d]\n",
  840. cnt, active ? "" : "in", fifo, tbl_dw,
  841. iwl_read_prph(trans,
  842. SCD_QUEUE_RDPTR(cnt)) & (txq->q.n_bd - 1),
  843. iwl_read_prph(trans, SCD_QUEUE_WRPTR(cnt)));
  844. }
  845. return ret;
  846. }
  847. static void iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans, u32 reg,
  848. u32 mask, u32 value)
  849. {
  850. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  851. unsigned long flags;
  852. spin_lock_irqsave(&trans_pcie->reg_lock, flags);
  853. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, value);
  854. spin_unlock_irqrestore(&trans_pcie->reg_lock, flags);
  855. }
  856. static const char *get_fh_string(int cmd)
  857. {
  858. #define IWL_CMD(x) case x: return #x
  859. switch (cmd) {
  860. IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  861. IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  862. IWL_CMD(FH_RSCSR_CHNL0_WPTR);
  863. IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  864. IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  865. IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  866. IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  867. IWL_CMD(FH_TSSR_TX_STATUS_REG);
  868. IWL_CMD(FH_TSSR_TX_ERROR_REG);
  869. default:
  870. return "UNKNOWN";
  871. }
  872. #undef IWL_CMD
  873. }
  874. int iwl_pcie_dump_fh(struct iwl_trans *trans, char **buf)
  875. {
  876. int i;
  877. static const u32 fh_tbl[] = {
  878. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  879. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  880. FH_RSCSR_CHNL0_WPTR,
  881. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  882. FH_MEM_RSSR_SHARED_CTRL_REG,
  883. FH_MEM_RSSR_RX_STATUS_REG,
  884. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  885. FH_TSSR_TX_STATUS_REG,
  886. FH_TSSR_TX_ERROR_REG
  887. };
  888. #ifdef CONFIG_IWLWIFI_DEBUGFS
  889. if (buf) {
  890. int pos = 0;
  891. size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  892. *buf = kmalloc(bufsz, GFP_KERNEL);
  893. if (!*buf)
  894. return -ENOMEM;
  895. pos += scnprintf(*buf + pos, bufsz - pos,
  896. "FH register values:\n");
  897. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
  898. pos += scnprintf(*buf + pos, bufsz - pos,
  899. " %34s: 0X%08x\n",
  900. get_fh_string(fh_tbl[i]),
  901. iwl_read_direct32(trans, fh_tbl[i]));
  902. return pos;
  903. }
  904. #endif
  905. IWL_ERR(trans, "FH register values:\n");
  906. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
  907. IWL_ERR(trans, " %34s: 0X%08x\n",
  908. get_fh_string(fh_tbl[i]),
  909. iwl_read_direct32(trans, fh_tbl[i]));
  910. return 0;
  911. }
  912. static const char *get_csr_string(int cmd)
  913. {
  914. #define IWL_CMD(x) case x: return #x
  915. switch (cmd) {
  916. IWL_CMD(CSR_HW_IF_CONFIG_REG);
  917. IWL_CMD(CSR_INT_COALESCING);
  918. IWL_CMD(CSR_INT);
  919. IWL_CMD(CSR_INT_MASK);
  920. IWL_CMD(CSR_FH_INT_STATUS);
  921. IWL_CMD(CSR_GPIO_IN);
  922. IWL_CMD(CSR_RESET);
  923. IWL_CMD(CSR_GP_CNTRL);
  924. IWL_CMD(CSR_HW_REV);
  925. IWL_CMD(CSR_EEPROM_REG);
  926. IWL_CMD(CSR_EEPROM_GP);
  927. IWL_CMD(CSR_OTP_GP_REG);
  928. IWL_CMD(CSR_GIO_REG);
  929. IWL_CMD(CSR_GP_UCODE_REG);
  930. IWL_CMD(CSR_GP_DRIVER_REG);
  931. IWL_CMD(CSR_UCODE_DRV_GP1);
  932. IWL_CMD(CSR_UCODE_DRV_GP2);
  933. IWL_CMD(CSR_LED_REG);
  934. IWL_CMD(CSR_DRAM_INT_TBL_REG);
  935. IWL_CMD(CSR_GIO_CHICKEN_BITS);
  936. IWL_CMD(CSR_ANA_PLL_CFG);
  937. IWL_CMD(CSR_HW_REV_WA_REG);
  938. IWL_CMD(CSR_DBG_HPET_MEM_REG);
  939. default:
  940. return "UNKNOWN";
  941. }
  942. #undef IWL_CMD
  943. }
  944. void iwl_pcie_dump_csr(struct iwl_trans *trans)
  945. {
  946. int i;
  947. static const u32 csr_tbl[] = {
  948. CSR_HW_IF_CONFIG_REG,
  949. CSR_INT_COALESCING,
  950. CSR_INT,
  951. CSR_INT_MASK,
  952. CSR_FH_INT_STATUS,
  953. CSR_GPIO_IN,
  954. CSR_RESET,
  955. CSR_GP_CNTRL,
  956. CSR_HW_REV,
  957. CSR_EEPROM_REG,
  958. CSR_EEPROM_GP,
  959. CSR_OTP_GP_REG,
  960. CSR_GIO_REG,
  961. CSR_GP_UCODE_REG,
  962. CSR_GP_DRIVER_REG,
  963. CSR_UCODE_DRV_GP1,
  964. CSR_UCODE_DRV_GP2,
  965. CSR_LED_REG,
  966. CSR_DRAM_INT_TBL_REG,
  967. CSR_GIO_CHICKEN_BITS,
  968. CSR_ANA_PLL_CFG,
  969. CSR_HW_REV_WA_REG,
  970. CSR_DBG_HPET_MEM_REG
  971. };
  972. IWL_ERR(trans, "CSR values:\n");
  973. IWL_ERR(trans, "(2nd byte of CSR_INT_COALESCING is "
  974. "CSR_INT_PERIODIC_REG)\n");
  975. for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
  976. IWL_ERR(trans, " %25s: 0X%08x\n",
  977. get_csr_string(csr_tbl[i]),
  978. iwl_read32(trans, csr_tbl[i]));
  979. }
  980. }
  981. #ifdef CONFIG_IWLWIFI_DEBUGFS
  982. /* create and remove of files */
  983. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  984. if (!debugfs_create_file(#name, mode, parent, trans, \
  985. &iwl_dbgfs_##name##_ops)) \
  986. goto err; \
  987. } while (0)
  988. /* file operation */
  989. #define DEBUGFS_READ_FUNC(name) \
  990. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  991. char __user *user_buf, \
  992. size_t count, loff_t *ppos);
  993. #define DEBUGFS_WRITE_FUNC(name) \
  994. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  995. const char __user *user_buf, \
  996. size_t count, loff_t *ppos);
  997. #define DEBUGFS_READ_FILE_OPS(name) \
  998. DEBUGFS_READ_FUNC(name); \
  999. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  1000. .read = iwl_dbgfs_##name##_read, \
  1001. .open = simple_open, \
  1002. .llseek = generic_file_llseek, \
  1003. };
  1004. #define DEBUGFS_WRITE_FILE_OPS(name) \
  1005. DEBUGFS_WRITE_FUNC(name); \
  1006. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  1007. .write = iwl_dbgfs_##name##_write, \
  1008. .open = simple_open, \
  1009. .llseek = generic_file_llseek, \
  1010. };
  1011. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  1012. DEBUGFS_READ_FUNC(name); \
  1013. DEBUGFS_WRITE_FUNC(name); \
  1014. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  1015. .write = iwl_dbgfs_##name##_write, \
  1016. .read = iwl_dbgfs_##name##_read, \
  1017. .open = simple_open, \
  1018. .llseek = generic_file_llseek, \
  1019. };
  1020. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  1021. char __user *user_buf,
  1022. size_t count, loff_t *ppos)
  1023. {
  1024. struct iwl_trans *trans = file->private_data;
  1025. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1026. struct iwl_txq *txq;
  1027. struct iwl_queue *q;
  1028. char *buf;
  1029. int pos = 0;
  1030. int cnt;
  1031. int ret;
  1032. size_t bufsz;
  1033. bufsz = sizeof(char) * 64 * trans->cfg->base_params->num_of_queues;
  1034. if (!trans_pcie->txq)
  1035. return -EAGAIN;
  1036. buf = kzalloc(bufsz, GFP_KERNEL);
  1037. if (!buf)
  1038. return -ENOMEM;
  1039. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  1040. txq = &trans_pcie->txq[cnt];
  1041. q = &txq->q;
  1042. pos += scnprintf(buf + pos, bufsz - pos,
  1043. "hwq %.2d: read=%u write=%u use=%d stop=%d\n",
  1044. cnt, q->read_ptr, q->write_ptr,
  1045. !!test_bit(cnt, trans_pcie->queue_used),
  1046. !!test_bit(cnt, trans_pcie->queue_stopped));
  1047. }
  1048. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1049. kfree(buf);
  1050. return ret;
  1051. }
  1052. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  1053. char __user *user_buf,
  1054. size_t count, loff_t *ppos)
  1055. {
  1056. struct iwl_trans *trans = file->private_data;
  1057. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1058. struct iwl_rxq *rxq = &trans_pcie->rxq;
  1059. char buf[256];
  1060. int pos = 0;
  1061. const size_t bufsz = sizeof(buf);
  1062. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  1063. rxq->read);
  1064. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  1065. rxq->write);
  1066. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  1067. rxq->free_count);
  1068. if (rxq->rb_stts) {
  1069. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  1070. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  1071. } else {
  1072. pos += scnprintf(buf + pos, bufsz - pos,
  1073. "closed_rb_num: Not Allocated\n");
  1074. }
  1075. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1076. }
  1077. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  1078. char __user *user_buf,
  1079. size_t count, loff_t *ppos)
  1080. {
  1081. struct iwl_trans *trans = file->private_data;
  1082. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1083. struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
  1084. int pos = 0;
  1085. char *buf;
  1086. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  1087. ssize_t ret;
  1088. buf = kzalloc(bufsz, GFP_KERNEL);
  1089. if (!buf)
  1090. return -ENOMEM;
  1091. pos += scnprintf(buf + pos, bufsz - pos,
  1092. "Interrupt Statistics Report:\n");
  1093. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  1094. isr_stats->hw);
  1095. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  1096. isr_stats->sw);
  1097. if (isr_stats->sw || isr_stats->hw) {
  1098. pos += scnprintf(buf + pos, bufsz - pos,
  1099. "\tLast Restarting Code: 0x%X\n",
  1100. isr_stats->err_code);
  1101. }
  1102. #ifdef CONFIG_IWLWIFI_DEBUG
  1103. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  1104. isr_stats->sch);
  1105. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  1106. isr_stats->alive);
  1107. #endif
  1108. pos += scnprintf(buf + pos, bufsz - pos,
  1109. "HW RF KILL switch toggled:\t %u\n", isr_stats->rfkill);
  1110. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  1111. isr_stats->ctkill);
  1112. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  1113. isr_stats->wakeup);
  1114. pos += scnprintf(buf + pos, bufsz - pos,
  1115. "Rx command responses:\t\t %u\n", isr_stats->rx);
  1116. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  1117. isr_stats->tx);
  1118. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  1119. isr_stats->unhandled);
  1120. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1121. kfree(buf);
  1122. return ret;
  1123. }
  1124. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  1125. const char __user *user_buf,
  1126. size_t count, loff_t *ppos)
  1127. {
  1128. struct iwl_trans *trans = file->private_data;
  1129. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1130. struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
  1131. char buf[8];
  1132. int buf_size;
  1133. u32 reset_flag;
  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, "%x", &reset_flag) != 1)
  1139. return -EFAULT;
  1140. if (reset_flag == 0)
  1141. memset(isr_stats, 0, sizeof(*isr_stats));
  1142. return count;
  1143. }
  1144. static ssize_t iwl_dbgfs_csr_write(struct file *file,
  1145. const char __user *user_buf,
  1146. size_t count, loff_t *ppos)
  1147. {
  1148. struct iwl_trans *trans = file->private_data;
  1149. char buf[8];
  1150. int buf_size;
  1151. int csr;
  1152. memset(buf, 0, sizeof(buf));
  1153. buf_size = min(count, sizeof(buf) - 1);
  1154. if (copy_from_user(buf, user_buf, buf_size))
  1155. return -EFAULT;
  1156. if (sscanf(buf, "%d", &csr) != 1)
  1157. return -EFAULT;
  1158. iwl_pcie_dump_csr(trans);
  1159. return count;
  1160. }
  1161. static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
  1162. char __user *user_buf,
  1163. size_t count, loff_t *ppos)
  1164. {
  1165. struct iwl_trans *trans = file->private_data;
  1166. char *buf = NULL;
  1167. int pos = 0;
  1168. ssize_t ret = -EFAULT;
  1169. ret = pos = iwl_pcie_dump_fh(trans, &buf);
  1170. if (buf) {
  1171. ret = simple_read_from_buffer(user_buf,
  1172. count, ppos, buf, pos);
  1173. kfree(buf);
  1174. }
  1175. return ret;
  1176. }
  1177. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  1178. DEBUGFS_READ_FILE_OPS(fh_reg);
  1179. DEBUGFS_READ_FILE_OPS(rx_queue);
  1180. DEBUGFS_READ_FILE_OPS(tx_queue);
  1181. DEBUGFS_WRITE_FILE_OPS(csr);
  1182. /*
  1183. * Create the debugfs files and directories
  1184. *
  1185. */
  1186. static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
  1187. struct dentry *dir)
  1188. {
  1189. DEBUGFS_ADD_FILE(rx_queue, dir, S_IRUSR);
  1190. DEBUGFS_ADD_FILE(tx_queue, dir, S_IRUSR);
  1191. DEBUGFS_ADD_FILE(interrupt, dir, S_IWUSR | S_IRUSR);
  1192. DEBUGFS_ADD_FILE(csr, dir, S_IWUSR);
  1193. DEBUGFS_ADD_FILE(fh_reg, dir, S_IRUSR);
  1194. return 0;
  1195. err:
  1196. IWL_ERR(trans, "failed to create the trans debugfs entry\n");
  1197. return -ENOMEM;
  1198. }
  1199. #else
  1200. static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
  1201. struct dentry *dir)
  1202. {
  1203. return 0;
  1204. }
  1205. #endif /*CONFIG_IWLWIFI_DEBUGFS */
  1206. static const struct iwl_trans_ops trans_ops_pcie = {
  1207. .start_hw = iwl_trans_pcie_start_hw,
  1208. .stop_hw = iwl_trans_pcie_stop_hw,
  1209. .fw_alive = iwl_trans_pcie_fw_alive,
  1210. .start_fw = iwl_trans_pcie_start_fw,
  1211. .stop_device = iwl_trans_pcie_stop_device,
  1212. .d3_suspend = iwl_trans_pcie_d3_suspend,
  1213. .d3_resume = iwl_trans_pcie_d3_resume,
  1214. .send_cmd = iwl_trans_pcie_send_hcmd,
  1215. .tx = iwl_trans_pcie_tx,
  1216. .reclaim = iwl_trans_pcie_reclaim,
  1217. .txq_disable = iwl_trans_pcie_txq_disable,
  1218. .txq_enable = iwl_trans_pcie_txq_enable,
  1219. .dbgfs_register = iwl_trans_pcie_dbgfs_register,
  1220. .wait_tx_queue_empty = iwl_trans_pcie_wait_txq_empty,
  1221. #ifdef CONFIG_PM_SLEEP
  1222. .suspend = iwl_trans_pcie_suspend,
  1223. .resume = iwl_trans_pcie_resume,
  1224. #endif
  1225. .write8 = iwl_trans_pcie_write8,
  1226. .write32 = iwl_trans_pcie_write32,
  1227. .read32 = iwl_trans_pcie_read32,
  1228. .read_prph = iwl_trans_pcie_read_prph,
  1229. .write_prph = iwl_trans_pcie_write_prph,
  1230. .read_mem = iwl_trans_pcie_read_mem,
  1231. .write_mem = iwl_trans_pcie_write_mem,
  1232. .configure = iwl_trans_pcie_configure,
  1233. .set_pmi = iwl_trans_pcie_set_pmi,
  1234. .grab_nic_access = iwl_trans_pcie_grab_nic_access,
  1235. .release_nic_access = iwl_trans_pcie_release_nic_access,
  1236. .set_bits_mask = iwl_trans_pcie_set_bits_mask,
  1237. };
  1238. struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
  1239. const struct pci_device_id *ent,
  1240. const struct iwl_cfg *cfg)
  1241. {
  1242. struct iwl_trans_pcie *trans_pcie;
  1243. struct iwl_trans *trans;
  1244. u16 pci_cmd;
  1245. int err;
  1246. trans = kzalloc(sizeof(struct iwl_trans) +
  1247. sizeof(struct iwl_trans_pcie), GFP_KERNEL);
  1248. if (!trans)
  1249. return NULL;
  1250. trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1251. trans->ops = &trans_ops_pcie;
  1252. trans->cfg = cfg;
  1253. trans_lockdep_init(trans);
  1254. trans_pcie->trans = trans;
  1255. spin_lock_init(&trans_pcie->irq_lock);
  1256. spin_lock_init(&trans_pcie->reg_lock);
  1257. init_waitqueue_head(&trans_pcie->ucode_write_waitq);
  1258. /* W/A - seems to solve weird behavior. We need to remove this if we
  1259. * don't want to stay in L1 all the time. This wastes a lot of power */
  1260. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  1261. PCIE_LINK_STATE_CLKPM);
  1262. if (pci_enable_device(pdev)) {
  1263. err = -ENODEV;
  1264. goto out_no_pci;
  1265. }
  1266. pci_set_master(pdev);
  1267. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  1268. if (!err)
  1269. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  1270. if (err) {
  1271. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1272. if (!err)
  1273. err = pci_set_consistent_dma_mask(pdev,
  1274. DMA_BIT_MASK(32));
  1275. /* both attempts failed: */
  1276. if (err) {
  1277. dev_err(&pdev->dev, "No suitable DMA available\n");
  1278. goto out_pci_disable_device;
  1279. }
  1280. }
  1281. err = pci_request_regions(pdev, DRV_NAME);
  1282. if (err) {
  1283. dev_err(&pdev->dev, "pci_request_regions failed\n");
  1284. goto out_pci_disable_device;
  1285. }
  1286. trans_pcie->hw_base = pci_ioremap_bar(pdev, 0);
  1287. if (!trans_pcie->hw_base) {
  1288. dev_err(&pdev->dev, "pci_ioremap_bar failed\n");
  1289. err = -ENODEV;
  1290. goto out_pci_release_regions;
  1291. }
  1292. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  1293. * PCI Tx retries from interfering with C3 CPU state */
  1294. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  1295. err = pci_enable_msi(pdev);
  1296. if (err) {
  1297. dev_err(&pdev->dev, "pci_enable_msi failed(0X%x)\n", err);
  1298. /* enable rfkill interrupt: hw bug w/a */
  1299. pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
  1300. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  1301. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  1302. pci_write_config_word(pdev, PCI_COMMAND, pci_cmd);
  1303. }
  1304. }
  1305. trans->dev = &pdev->dev;
  1306. trans_pcie->pci_dev = pdev;
  1307. trans->hw_rev = iwl_read32(trans, CSR_HW_REV);
  1308. trans->hw_id = (pdev->device << 16) + pdev->subsystem_device;
  1309. snprintf(trans->hw_id_str, sizeof(trans->hw_id_str),
  1310. "PCI ID: 0x%04X:0x%04X", pdev->device, pdev->subsystem_device);
  1311. /* Initialize the wait queue for commands */
  1312. init_waitqueue_head(&trans_pcie->wait_command_queue);
  1313. snprintf(trans->dev_cmd_pool_name, sizeof(trans->dev_cmd_pool_name),
  1314. "iwl_cmd_pool:%s", dev_name(trans->dev));
  1315. trans->dev_cmd_headroom = 0;
  1316. trans->dev_cmd_pool =
  1317. kmem_cache_create(trans->dev_cmd_pool_name,
  1318. sizeof(struct iwl_device_cmd)
  1319. + trans->dev_cmd_headroom,
  1320. sizeof(void *),
  1321. SLAB_HWCACHE_ALIGN,
  1322. NULL);
  1323. if (!trans->dev_cmd_pool)
  1324. goto out_pci_disable_msi;
  1325. trans_pcie->inta_mask = CSR_INI_SET_MASK;
  1326. if (iwl_pcie_alloc_ict(trans))
  1327. goto out_free_cmd_pool;
  1328. if (request_threaded_irq(pdev->irq, iwl_pcie_isr_ict,
  1329. iwl_pcie_irq_handler,
  1330. IRQF_SHARED, DRV_NAME, trans)) {
  1331. IWL_ERR(trans, "Error allocating IRQ %d\n", pdev->irq);
  1332. goto out_free_ict;
  1333. }
  1334. return trans;
  1335. out_free_ict:
  1336. iwl_pcie_free_ict(trans);
  1337. out_free_cmd_pool:
  1338. kmem_cache_destroy(trans->dev_cmd_pool);
  1339. out_pci_disable_msi:
  1340. pci_disable_msi(pdev);
  1341. out_pci_release_regions:
  1342. pci_release_regions(pdev);
  1343. out_pci_disable_device:
  1344. pci_disable_device(pdev);
  1345. out_no_pci:
  1346. kfree(trans);
  1347. return NULL;
  1348. }