trans.c 45 KB

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