trans.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607
  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. iwl_pcie_apm_init(trans);
  553. /* From now on, the op_mode will be kept updated about RF kill state */
  554. iwl_enable_rfkill_int(trans);
  555. hw_rfkill = iwl_is_rfkill_set(trans);
  556. if (hw_rfkill)
  557. set_bit(STATUS_RFKILL, &trans_pcie->status);
  558. else
  559. clear_bit(STATUS_RFKILL, &trans_pcie->status);
  560. iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rfkill);
  561. return 0;
  562. }
  563. static void iwl_trans_pcie_stop_hw(struct iwl_trans *trans,
  564. bool op_mode_leaving)
  565. {
  566. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  567. bool hw_rfkill;
  568. unsigned long flags;
  569. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  570. iwl_disable_interrupts(trans);
  571. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  572. iwl_pcie_apm_stop(trans);
  573. spin_lock_irqsave(&trans_pcie->irq_lock, flags);
  574. iwl_disable_interrupts(trans);
  575. spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
  576. iwl_pcie_disable_ict(trans);
  577. if (!op_mode_leaving) {
  578. /*
  579. * Even if we stop the HW, we still want the RF kill
  580. * interrupt
  581. */
  582. iwl_enable_rfkill_int(trans);
  583. /*
  584. * Check again since the RF kill state may have changed while
  585. * all the interrupts were disabled, in this case we couldn't
  586. * receive the RF kill interrupt and update the state in the
  587. * op_mode.
  588. */
  589. hw_rfkill = iwl_is_rfkill_set(trans);
  590. if (hw_rfkill)
  591. set_bit(STATUS_RFKILL, &trans_pcie->status);
  592. else
  593. clear_bit(STATUS_RFKILL, &trans_pcie->status);
  594. iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rfkill);
  595. }
  596. }
  597. static void iwl_trans_pcie_write8(struct iwl_trans *trans, u32 ofs, u8 val)
  598. {
  599. writeb(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  600. }
  601. static void iwl_trans_pcie_write32(struct iwl_trans *trans, u32 ofs, u32 val)
  602. {
  603. writel(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  604. }
  605. static u32 iwl_trans_pcie_read32(struct iwl_trans *trans, u32 ofs)
  606. {
  607. return readl(IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  608. }
  609. static u32 iwl_trans_pcie_read_prph(struct iwl_trans *trans, u32 reg)
  610. {
  611. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_RADDR,
  612. ((reg & 0x000FFFFF) | (3 << 24)));
  613. return iwl_trans_pcie_read32(trans, HBUS_TARG_PRPH_RDAT);
  614. }
  615. static void iwl_trans_pcie_write_prph(struct iwl_trans *trans, u32 addr,
  616. u32 val)
  617. {
  618. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_WADDR,
  619. ((addr & 0x000FFFFF) | (3 << 24)));
  620. iwl_trans_pcie_write32(trans, HBUS_TARG_PRPH_WDAT, val);
  621. }
  622. static void iwl_trans_pcie_configure(struct iwl_trans *trans,
  623. const struct iwl_trans_config *trans_cfg)
  624. {
  625. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  626. trans_pcie->cmd_queue = trans_cfg->cmd_queue;
  627. trans_pcie->cmd_fifo = trans_cfg->cmd_fifo;
  628. if (WARN_ON(trans_cfg->n_no_reclaim_cmds > MAX_NO_RECLAIM_CMDS))
  629. trans_pcie->n_no_reclaim_cmds = 0;
  630. else
  631. trans_pcie->n_no_reclaim_cmds = trans_cfg->n_no_reclaim_cmds;
  632. if (trans_pcie->n_no_reclaim_cmds)
  633. memcpy(trans_pcie->no_reclaim_cmds, trans_cfg->no_reclaim_cmds,
  634. trans_pcie->n_no_reclaim_cmds * sizeof(u8));
  635. trans_pcie->rx_buf_size_8k = trans_cfg->rx_buf_size_8k;
  636. if (trans_pcie->rx_buf_size_8k)
  637. trans_pcie->rx_page_order = get_order(8 * 1024);
  638. else
  639. trans_pcie->rx_page_order = get_order(4 * 1024);
  640. trans_pcie->wd_timeout =
  641. msecs_to_jiffies(trans_cfg->queue_watchdog_timeout);
  642. trans_pcie->command_names = trans_cfg->command_names;
  643. trans_pcie->bc_table_dword = trans_cfg->bc_table_dword;
  644. }
  645. void iwl_trans_pcie_free(struct iwl_trans *trans)
  646. {
  647. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  648. synchronize_irq(trans_pcie->pci_dev->irq);
  649. iwl_pcie_tx_free(trans);
  650. iwl_pcie_rx_free(trans);
  651. free_irq(trans_pcie->pci_dev->irq, trans);
  652. iwl_pcie_free_ict(trans);
  653. pci_disable_msi(trans_pcie->pci_dev);
  654. iounmap(trans_pcie->hw_base);
  655. pci_release_regions(trans_pcie->pci_dev);
  656. pci_disable_device(trans_pcie->pci_dev);
  657. kmem_cache_destroy(trans->dev_cmd_pool);
  658. kfree(trans);
  659. }
  660. static void iwl_trans_pcie_set_pmi(struct iwl_trans *trans, bool state)
  661. {
  662. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  663. if (state)
  664. set_bit(STATUS_TPOWER_PMI, &trans_pcie->status);
  665. else
  666. clear_bit(STATUS_TPOWER_PMI, &trans_pcie->status);
  667. }
  668. #ifdef CONFIG_PM_SLEEP
  669. static int iwl_trans_pcie_suspend(struct iwl_trans *trans)
  670. {
  671. return 0;
  672. }
  673. static int iwl_trans_pcie_resume(struct iwl_trans *trans)
  674. {
  675. bool hw_rfkill;
  676. iwl_enable_rfkill_int(trans);
  677. hw_rfkill = iwl_is_rfkill_set(trans);
  678. iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rfkill);
  679. return 0;
  680. }
  681. #endif /* CONFIG_PM_SLEEP */
  682. static bool iwl_trans_pcie_grab_nic_access(struct iwl_trans *trans, bool silent,
  683. unsigned long *flags)
  684. {
  685. int ret;
  686. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  687. spin_lock_irqsave(&trans_pcie->reg_lock, *flags);
  688. /* this bit wakes up the NIC */
  689. __iwl_trans_pcie_set_bit(trans, CSR_GP_CNTRL,
  690. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  691. /*
  692. * These bits say the device is running, and should keep running for
  693. * at least a short while (at least as long as MAC_ACCESS_REQ stays 1),
  694. * but they do not indicate that embedded SRAM is restored yet;
  695. * 3945 and 4965 have volatile SRAM, and must save/restore contents
  696. * to/from host DRAM when sleeping/waking for power-saving.
  697. * Each direction takes approximately 1/4 millisecond; with this
  698. * overhead, it's a good idea to grab and hold MAC_ACCESS_REQUEST if a
  699. * series of register accesses are expected (e.g. reading Event Log),
  700. * to keep device from sleeping.
  701. *
  702. * CSR_UCODE_DRV_GP1 register bit MAC_SLEEP == 0 indicates that
  703. * SRAM is okay/restored. We don't check that here because this call
  704. * is just for hardware register access; but GP1 MAC_SLEEP check is a
  705. * good idea before accessing 3945/4965 SRAM (e.g. reading Event Log).
  706. *
  707. * 5000 series and later (including 1000 series) have non-volatile SRAM,
  708. * and do not save/restore SRAM when power cycling.
  709. */
  710. ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
  711. CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
  712. (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
  713. CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
  714. if (unlikely(ret < 0)) {
  715. iwl_write32(trans, CSR_RESET, CSR_RESET_REG_FLAG_FORCE_NMI);
  716. if (!silent) {
  717. u32 val = iwl_read32(trans, CSR_GP_CNTRL);
  718. WARN_ONCE(1,
  719. "Timeout waiting for hardware access (CSR_GP_CNTRL 0x%08x)\n",
  720. val);
  721. spin_unlock_irqrestore(&trans_pcie->reg_lock, *flags);
  722. return false;
  723. }
  724. }
  725. /*
  726. * Fool sparse by faking we release the lock - sparse will
  727. * track nic_access anyway.
  728. */
  729. __release(&trans_pcie->reg_lock);
  730. return true;
  731. }
  732. static void iwl_trans_pcie_release_nic_access(struct iwl_trans *trans,
  733. unsigned long *flags)
  734. {
  735. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  736. lockdep_assert_held(&trans_pcie->reg_lock);
  737. /*
  738. * Fool sparse by faking we acquiring the lock - sparse will
  739. * track nic_access anyway.
  740. */
  741. __acquire(&trans_pcie->reg_lock);
  742. __iwl_trans_pcie_clear_bit(trans, CSR_GP_CNTRL,
  743. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  744. /*
  745. * Above we read the CSR_GP_CNTRL register, which will flush
  746. * any previous writes, but we need the write that clears the
  747. * MAC_ACCESS_REQ bit to be performed before any other writes
  748. * scheduled on different CPUs (after we drop reg_lock).
  749. */
  750. mmiowb();
  751. spin_unlock_irqrestore(&trans_pcie->reg_lock, *flags);
  752. }
  753. static int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr,
  754. void *buf, int dwords)
  755. {
  756. unsigned long flags;
  757. int offs, ret = 0;
  758. u32 *vals = buf;
  759. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  760. iwl_write32(trans, HBUS_TARG_MEM_RADDR, addr);
  761. for (offs = 0; offs < dwords; offs++)
  762. vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  763. iwl_trans_release_nic_access(trans, &flags);
  764. } else {
  765. ret = -EBUSY;
  766. }
  767. return ret;
  768. }
  769. static int iwl_trans_pcie_write_mem(struct iwl_trans *trans, u32 addr,
  770. const void *buf, int dwords)
  771. {
  772. unsigned long flags;
  773. int offs, ret = 0;
  774. const u32 *vals = buf;
  775. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  776. iwl_write32(trans, HBUS_TARG_MEM_WADDR, addr);
  777. for (offs = 0; offs < dwords; offs++)
  778. iwl_write32(trans, HBUS_TARG_MEM_WDAT,
  779. vals ? vals[offs] : 0);
  780. iwl_trans_release_nic_access(trans, &flags);
  781. } else {
  782. ret = -EBUSY;
  783. }
  784. return ret;
  785. }
  786. #define IWL_FLUSH_WAIT_MS 2000
  787. static int iwl_trans_pcie_wait_txq_empty(struct iwl_trans *trans)
  788. {
  789. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  790. struct iwl_txq *txq;
  791. struct iwl_queue *q;
  792. int cnt;
  793. unsigned long now = jiffies;
  794. u32 scd_sram_addr;
  795. u8 buf[16];
  796. int ret = 0;
  797. /* waiting for all the tx frames complete might take a while */
  798. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  799. if (cnt == trans_pcie->cmd_queue)
  800. continue;
  801. txq = &trans_pcie->txq[cnt];
  802. q = &txq->q;
  803. while (q->read_ptr != q->write_ptr && !time_after(jiffies,
  804. now + msecs_to_jiffies(IWL_FLUSH_WAIT_MS)))
  805. msleep(1);
  806. if (q->read_ptr != q->write_ptr) {
  807. IWL_ERR(trans,
  808. "fail to flush all tx fifo queues Q %d\n", cnt);
  809. ret = -ETIMEDOUT;
  810. break;
  811. }
  812. }
  813. if (!ret)
  814. return 0;
  815. IWL_ERR(trans, "Current SW read_ptr %d write_ptr %d\n",
  816. txq->q.read_ptr, txq->q.write_ptr);
  817. scd_sram_addr = trans_pcie->scd_base_addr +
  818. SCD_TX_STTS_QUEUE_OFFSET(txq->q.id);
  819. iwl_trans_read_mem_bytes(trans, scd_sram_addr, buf, sizeof(buf));
  820. iwl_print_hex_error(trans, buf, sizeof(buf));
  821. for (cnt = 0; cnt < FH_TCSR_CHNL_NUM; cnt++)
  822. IWL_ERR(trans, "FH TRBs(%d) = 0x%08x\n", cnt,
  823. iwl_read_direct32(trans, FH_TX_TRB_REG(cnt)));
  824. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  825. u32 status = iwl_read_prph(trans, SCD_QUEUE_STATUS_BITS(cnt));
  826. u8 fifo = (status >> SCD_QUEUE_STTS_REG_POS_TXF) & 0x7;
  827. bool active = !!(status & BIT(SCD_QUEUE_STTS_REG_POS_ACTIVE));
  828. u32 tbl_dw =
  829. iwl_trans_read_mem32(trans, trans_pcie->scd_base_addr +
  830. SCD_TRANS_TBL_OFFSET_QUEUE(cnt));
  831. if (cnt & 0x1)
  832. tbl_dw = (tbl_dw & 0xFFFF0000) >> 16;
  833. else
  834. tbl_dw = tbl_dw & 0x0000FFFF;
  835. IWL_ERR(trans,
  836. "Q %d is %sactive and mapped to fifo %d ra_tid 0x%04x [%d,%d]\n",
  837. cnt, active ? "" : "in", fifo, tbl_dw,
  838. iwl_read_prph(trans,
  839. SCD_QUEUE_RDPTR(cnt)) & (txq->q.n_bd - 1),
  840. iwl_read_prph(trans, SCD_QUEUE_WRPTR(cnt)));
  841. }
  842. return ret;
  843. }
  844. static void iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans, u32 reg,
  845. u32 mask, u32 value)
  846. {
  847. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  848. unsigned long flags;
  849. spin_lock_irqsave(&trans_pcie->reg_lock, flags);
  850. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, value);
  851. spin_unlock_irqrestore(&trans_pcie->reg_lock, flags);
  852. }
  853. static const char *get_fh_string(int cmd)
  854. {
  855. #define IWL_CMD(x) case x: return #x
  856. switch (cmd) {
  857. IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  858. IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  859. IWL_CMD(FH_RSCSR_CHNL0_WPTR);
  860. IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  861. IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  862. IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  863. IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  864. IWL_CMD(FH_TSSR_TX_STATUS_REG);
  865. IWL_CMD(FH_TSSR_TX_ERROR_REG);
  866. default:
  867. return "UNKNOWN";
  868. }
  869. #undef IWL_CMD
  870. }
  871. int iwl_pcie_dump_fh(struct iwl_trans *trans, char **buf)
  872. {
  873. int i;
  874. static const u32 fh_tbl[] = {
  875. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  876. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  877. FH_RSCSR_CHNL0_WPTR,
  878. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  879. FH_MEM_RSSR_SHARED_CTRL_REG,
  880. FH_MEM_RSSR_RX_STATUS_REG,
  881. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  882. FH_TSSR_TX_STATUS_REG,
  883. FH_TSSR_TX_ERROR_REG
  884. };
  885. #ifdef CONFIG_IWLWIFI_DEBUGFS
  886. if (buf) {
  887. int pos = 0;
  888. size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  889. *buf = kmalloc(bufsz, GFP_KERNEL);
  890. if (!*buf)
  891. return -ENOMEM;
  892. pos += scnprintf(*buf + pos, bufsz - pos,
  893. "FH register values:\n");
  894. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
  895. pos += scnprintf(*buf + pos, bufsz - pos,
  896. " %34s: 0X%08x\n",
  897. get_fh_string(fh_tbl[i]),
  898. iwl_read_direct32(trans, fh_tbl[i]));
  899. return pos;
  900. }
  901. #endif
  902. IWL_ERR(trans, "FH register values:\n");
  903. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
  904. IWL_ERR(trans, " %34s: 0X%08x\n",
  905. get_fh_string(fh_tbl[i]),
  906. iwl_read_direct32(trans, fh_tbl[i]));
  907. return 0;
  908. }
  909. static const char *get_csr_string(int cmd)
  910. {
  911. #define IWL_CMD(x) case x: return #x
  912. switch (cmd) {
  913. IWL_CMD(CSR_HW_IF_CONFIG_REG);
  914. IWL_CMD(CSR_INT_COALESCING);
  915. IWL_CMD(CSR_INT);
  916. IWL_CMD(CSR_INT_MASK);
  917. IWL_CMD(CSR_FH_INT_STATUS);
  918. IWL_CMD(CSR_GPIO_IN);
  919. IWL_CMD(CSR_RESET);
  920. IWL_CMD(CSR_GP_CNTRL);
  921. IWL_CMD(CSR_HW_REV);
  922. IWL_CMD(CSR_EEPROM_REG);
  923. IWL_CMD(CSR_EEPROM_GP);
  924. IWL_CMD(CSR_OTP_GP_REG);
  925. IWL_CMD(CSR_GIO_REG);
  926. IWL_CMD(CSR_GP_UCODE_REG);
  927. IWL_CMD(CSR_GP_DRIVER_REG);
  928. IWL_CMD(CSR_UCODE_DRV_GP1);
  929. IWL_CMD(CSR_UCODE_DRV_GP2);
  930. IWL_CMD(CSR_LED_REG);
  931. IWL_CMD(CSR_DRAM_INT_TBL_REG);
  932. IWL_CMD(CSR_GIO_CHICKEN_BITS);
  933. IWL_CMD(CSR_ANA_PLL_CFG);
  934. IWL_CMD(CSR_HW_REV_WA_REG);
  935. IWL_CMD(CSR_DBG_HPET_MEM_REG);
  936. default:
  937. return "UNKNOWN";
  938. }
  939. #undef IWL_CMD
  940. }
  941. void iwl_pcie_dump_csr(struct iwl_trans *trans)
  942. {
  943. int i;
  944. static const u32 csr_tbl[] = {
  945. CSR_HW_IF_CONFIG_REG,
  946. CSR_INT_COALESCING,
  947. CSR_INT,
  948. CSR_INT_MASK,
  949. CSR_FH_INT_STATUS,
  950. CSR_GPIO_IN,
  951. CSR_RESET,
  952. CSR_GP_CNTRL,
  953. CSR_HW_REV,
  954. CSR_EEPROM_REG,
  955. CSR_EEPROM_GP,
  956. CSR_OTP_GP_REG,
  957. CSR_GIO_REG,
  958. CSR_GP_UCODE_REG,
  959. CSR_GP_DRIVER_REG,
  960. CSR_UCODE_DRV_GP1,
  961. CSR_UCODE_DRV_GP2,
  962. CSR_LED_REG,
  963. CSR_DRAM_INT_TBL_REG,
  964. CSR_GIO_CHICKEN_BITS,
  965. CSR_ANA_PLL_CFG,
  966. CSR_HW_REV_WA_REG,
  967. CSR_DBG_HPET_MEM_REG
  968. };
  969. IWL_ERR(trans, "CSR values:\n");
  970. IWL_ERR(trans, "(2nd byte of CSR_INT_COALESCING is "
  971. "CSR_INT_PERIODIC_REG)\n");
  972. for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
  973. IWL_ERR(trans, " %25s: 0X%08x\n",
  974. get_csr_string(csr_tbl[i]),
  975. iwl_read32(trans, csr_tbl[i]));
  976. }
  977. }
  978. #ifdef CONFIG_IWLWIFI_DEBUGFS
  979. /* create and remove of files */
  980. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  981. if (!debugfs_create_file(#name, mode, parent, trans, \
  982. &iwl_dbgfs_##name##_ops)) \
  983. goto err; \
  984. } while (0)
  985. /* file operation */
  986. #define DEBUGFS_READ_FUNC(name) \
  987. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  988. char __user *user_buf, \
  989. size_t count, loff_t *ppos);
  990. #define DEBUGFS_WRITE_FUNC(name) \
  991. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  992. const char __user *user_buf, \
  993. size_t count, loff_t *ppos);
  994. #define DEBUGFS_READ_FILE_OPS(name) \
  995. DEBUGFS_READ_FUNC(name); \
  996. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  997. .read = iwl_dbgfs_##name##_read, \
  998. .open = simple_open, \
  999. .llseek = generic_file_llseek, \
  1000. };
  1001. #define DEBUGFS_WRITE_FILE_OPS(name) \
  1002. DEBUGFS_WRITE_FUNC(name); \
  1003. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  1004. .write = iwl_dbgfs_##name##_write, \
  1005. .open = simple_open, \
  1006. .llseek = generic_file_llseek, \
  1007. };
  1008. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  1009. DEBUGFS_READ_FUNC(name); \
  1010. DEBUGFS_WRITE_FUNC(name); \
  1011. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  1012. .write = iwl_dbgfs_##name##_write, \
  1013. .read = iwl_dbgfs_##name##_read, \
  1014. .open = simple_open, \
  1015. .llseek = generic_file_llseek, \
  1016. };
  1017. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  1018. char __user *user_buf,
  1019. size_t count, loff_t *ppos)
  1020. {
  1021. struct iwl_trans *trans = file->private_data;
  1022. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1023. struct iwl_txq *txq;
  1024. struct iwl_queue *q;
  1025. char *buf;
  1026. int pos = 0;
  1027. int cnt;
  1028. int ret;
  1029. size_t bufsz;
  1030. bufsz = sizeof(char) * 64 * trans->cfg->base_params->num_of_queues;
  1031. if (!trans_pcie->txq)
  1032. return -EAGAIN;
  1033. buf = kzalloc(bufsz, GFP_KERNEL);
  1034. if (!buf)
  1035. return -ENOMEM;
  1036. for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
  1037. txq = &trans_pcie->txq[cnt];
  1038. q = &txq->q;
  1039. pos += scnprintf(buf + pos, bufsz - pos,
  1040. "hwq %.2d: read=%u write=%u use=%d stop=%d\n",
  1041. cnt, q->read_ptr, q->write_ptr,
  1042. !!test_bit(cnt, trans_pcie->queue_used),
  1043. !!test_bit(cnt, trans_pcie->queue_stopped));
  1044. }
  1045. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1046. kfree(buf);
  1047. return ret;
  1048. }
  1049. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  1050. char __user *user_buf,
  1051. size_t count, loff_t *ppos)
  1052. {
  1053. struct iwl_trans *trans = file->private_data;
  1054. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1055. struct iwl_rxq *rxq = &trans_pcie->rxq;
  1056. char buf[256];
  1057. int pos = 0;
  1058. const size_t bufsz = sizeof(buf);
  1059. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  1060. rxq->read);
  1061. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  1062. rxq->write);
  1063. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  1064. rxq->free_count);
  1065. if (rxq->rb_stts) {
  1066. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  1067. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  1068. } else {
  1069. pos += scnprintf(buf + pos, bufsz - pos,
  1070. "closed_rb_num: Not Allocated\n");
  1071. }
  1072. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1073. }
  1074. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  1075. char __user *user_buf,
  1076. size_t count, loff_t *ppos)
  1077. {
  1078. struct iwl_trans *trans = file->private_data;
  1079. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1080. struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
  1081. int pos = 0;
  1082. char *buf;
  1083. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  1084. ssize_t ret;
  1085. buf = kzalloc(bufsz, GFP_KERNEL);
  1086. if (!buf)
  1087. return -ENOMEM;
  1088. pos += scnprintf(buf + pos, bufsz - pos,
  1089. "Interrupt Statistics Report:\n");
  1090. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  1091. isr_stats->hw);
  1092. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  1093. isr_stats->sw);
  1094. if (isr_stats->sw || isr_stats->hw) {
  1095. pos += scnprintf(buf + pos, bufsz - pos,
  1096. "\tLast Restarting Code: 0x%X\n",
  1097. isr_stats->err_code);
  1098. }
  1099. #ifdef CONFIG_IWLWIFI_DEBUG
  1100. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  1101. isr_stats->sch);
  1102. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  1103. isr_stats->alive);
  1104. #endif
  1105. pos += scnprintf(buf + pos, bufsz - pos,
  1106. "HW RF KILL switch toggled:\t %u\n", isr_stats->rfkill);
  1107. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  1108. isr_stats->ctkill);
  1109. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  1110. isr_stats->wakeup);
  1111. pos += scnprintf(buf + pos, bufsz - pos,
  1112. "Rx command responses:\t\t %u\n", isr_stats->rx);
  1113. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  1114. isr_stats->tx);
  1115. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  1116. isr_stats->unhandled);
  1117. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1118. kfree(buf);
  1119. return ret;
  1120. }
  1121. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  1122. const char __user *user_buf,
  1123. size_t count, loff_t *ppos)
  1124. {
  1125. struct iwl_trans *trans = file->private_data;
  1126. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1127. struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
  1128. char buf[8];
  1129. int buf_size;
  1130. u32 reset_flag;
  1131. memset(buf, 0, sizeof(buf));
  1132. buf_size = min(count, sizeof(buf) - 1);
  1133. if (copy_from_user(buf, user_buf, buf_size))
  1134. return -EFAULT;
  1135. if (sscanf(buf, "%x", &reset_flag) != 1)
  1136. return -EFAULT;
  1137. if (reset_flag == 0)
  1138. memset(isr_stats, 0, sizeof(*isr_stats));
  1139. return count;
  1140. }
  1141. static ssize_t iwl_dbgfs_csr_write(struct file *file,
  1142. const char __user *user_buf,
  1143. size_t count, loff_t *ppos)
  1144. {
  1145. struct iwl_trans *trans = file->private_data;
  1146. char buf[8];
  1147. int buf_size;
  1148. int csr;
  1149. memset(buf, 0, sizeof(buf));
  1150. buf_size = min(count, sizeof(buf) - 1);
  1151. if (copy_from_user(buf, user_buf, buf_size))
  1152. return -EFAULT;
  1153. if (sscanf(buf, "%d", &csr) != 1)
  1154. return -EFAULT;
  1155. iwl_pcie_dump_csr(trans);
  1156. return count;
  1157. }
  1158. static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
  1159. char __user *user_buf,
  1160. size_t count, loff_t *ppos)
  1161. {
  1162. struct iwl_trans *trans = file->private_data;
  1163. char *buf = NULL;
  1164. int pos = 0;
  1165. ssize_t ret = -EFAULT;
  1166. ret = pos = iwl_pcie_dump_fh(trans, &buf);
  1167. if (buf) {
  1168. ret = simple_read_from_buffer(user_buf,
  1169. count, ppos, buf, pos);
  1170. kfree(buf);
  1171. }
  1172. return ret;
  1173. }
  1174. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  1175. DEBUGFS_READ_FILE_OPS(fh_reg);
  1176. DEBUGFS_READ_FILE_OPS(rx_queue);
  1177. DEBUGFS_READ_FILE_OPS(tx_queue);
  1178. DEBUGFS_WRITE_FILE_OPS(csr);
  1179. /*
  1180. * Create the debugfs files and directories
  1181. *
  1182. */
  1183. static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
  1184. struct dentry *dir)
  1185. {
  1186. DEBUGFS_ADD_FILE(rx_queue, dir, S_IRUSR);
  1187. DEBUGFS_ADD_FILE(tx_queue, dir, S_IRUSR);
  1188. DEBUGFS_ADD_FILE(interrupt, dir, S_IWUSR | S_IRUSR);
  1189. DEBUGFS_ADD_FILE(csr, dir, S_IWUSR);
  1190. DEBUGFS_ADD_FILE(fh_reg, dir, S_IRUSR);
  1191. return 0;
  1192. err:
  1193. IWL_ERR(trans, "failed to create the trans debugfs entry\n");
  1194. return -ENOMEM;
  1195. }
  1196. #else
  1197. static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
  1198. struct dentry *dir)
  1199. {
  1200. return 0;
  1201. }
  1202. #endif /*CONFIG_IWLWIFI_DEBUGFS */
  1203. static const struct iwl_trans_ops trans_ops_pcie = {
  1204. .start_hw = iwl_trans_pcie_start_hw,
  1205. .stop_hw = iwl_trans_pcie_stop_hw,
  1206. .fw_alive = iwl_trans_pcie_fw_alive,
  1207. .start_fw = iwl_trans_pcie_start_fw,
  1208. .stop_device = iwl_trans_pcie_stop_device,
  1209. .d3_suspend = iwl_trans_pcie_d3_suspend,
  1210. .d3_resume = iwl_trans_pcie_d3_resume,
  1211. .send_cmd = iwl_trans_pcie_send_hcmd,
  1212. .tx = iwl_trans_pcie_tx,
  1213. .reclaim = iwl_trans_pcie_reclaim,
  1214. .txq_disable = iwl_trans_pcie_txq_disable,
  1215. .txq_enable = iwl_trans_pcie_txq_enable,
  1216. .dbgfs_register = iwl_trans_pcie_dbgfs_register,
  1217. .wait_tx_queue_empty = iwl_trans_pcie_wait_txq_empty,
  1218. #ifdef CONFIG_PM_SLEEP
  1219. .suspend = iwl_trans_pcie_suspend,
  1220. .resume = iwl_trans_pcie_resume,
  1221. #endif
  1222. .write8 = iwl_trans_pcie_write8,
  1223. .write32 = iwl_trans_pcie_write32,
  1224. .read32 = iwl_trans_pcie_read32,
  1225. .read_prph = iwl_trans_pcie_read_prph,
  1226. .write_prph = iwl_trans_pcie_write_prph,
  1227. .read_mem = iwl_trans_pcie_read_mem,
  1228. .write_mem = iwl_trans_pcie_write_mem,
  1229. .configure = iwl_trans_pcie_configure,
  1230. .set_pmi = iwl_trans_pcie_set_pmi,
  1231. .grab_nic_access = iwl_trans_pcie_grab_nic_access,
  1232. .release_nic_access = iwl_trans_pcie_release_nic_access,
  1233. .set_bits_mask = iwl_trans_pcie_set_bits_mask,
  1234. };
  1235. struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
  1236. const struct pci_device_id *ent,
  1237. const struct iwl_cfg *cfg)
  1238. {
  1239. struct iwl_trans_pcie *trans_pcie;
  1240. struct iwl_trans *trans;
  1241. u16 pci_cmd;
  1242. int err;
  1243. trans = kzalloc(sizeof(struct iwl_trans) +
  1244. sizeof(struct iwl_trans_pcie), GFP_KERNEL);
  1245. if (!trans)
  1246. return NULL;
  1247. trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1248. trans->ops = &trans_ops_pcie;
  1249. trans->cfg = cfg;
  1250. trans_lockdep_init(trans);
  1251. trans_pcie->trans = trans;
  1252. spin_lock_init(&trans_pcie->irq_lock);
  1253. spin_lock_init(&trans_pcie->reg_lock);
  1254. init_waitqueue_head(&trans_pcie->ucode_write_waitq);
  1255. /* W/A - seems to solve weird behavior. We need to remove this if we
  1256. * don't want to stay in L1 all the time. This wastes a lot of power */
  1257. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  1258. PCIE_LINK_STATE_CLKPM);
  1259. if (pci_enable_device(pdev)) {
  1260. err = -ENODEV;
  1261. goto out_no_pci;
  1262. }
  1263. pci_set_master(pdev);
  1264. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  1265. if (!err)
  1266. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  1267. if (err) {
  1268. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1269. if (!err)
  1270. err = pci_set_consistent_dma_mask(pdev,
  1271. DMA_BIT_MASK(32));
  1272. /* both attempts failed: */
  1273. if (err) {
  1274. dev_err(&pdev->dev, "No suitable DMA available\n");
  1275. goto out_pci_disable_device;
  1276. }
  1277. }
  1278. err = pci_request_regions(pdev, DRV_NAME);
  1279. if (err) {
  1280. dev_err(&pdev->dev, "pci_request_regions failed\n");
  1281. goto out_pci_disable_device;
  1282. }
  1283. trans_pcie->hw_base = pci_ioremap_bar(pdev, 0);
  1284. if (!trans_pcie->hw_base) {
  1285. dev_err(&pdev->dev, "pci_ioremap_bar failed\n");
  1286. err = -ENODEV;
  1287. goto out_pci_release_regions;
  1288. }
  1289. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  1290. * PCI Tx retries from interfering with C3 CPU state */
  1291. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  1292. err = pci_enable_msi(pdev);
  1293. if (err) {
  1294. dev_err(&pdev->dev, "pci_enable_msi failed(0X%x)\n", err);
  1295. /* enable rfkill interrupt: hw bug w/a */
  1296. pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
  1297. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  1298. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  1299. pci_write_config_word(pdev, PCI_COMMAND, pci_cmd);
  1300. }
  1301. }
  1302. trans->dev = &pdev->dev;
  1303. trans_pcie->pci_dev = pdev;
  1304. trans->hw_rev = iwl_read32(trans, CSR_HW_REV);
  1305. trans->hw_id = (pdev->device << 16) + pdev->subsystem_device;
  1306. snprintf(trans->hw_id_str, sizeof(trans->hw_id_str),
  1307. "PCI ID: 0x%04X:0x%04X", pdev->device, pdev->subsystem_device);
  1308. /* Initialize the wait queue for commands */
  1309. init_waitqueue_head(&trans_pcie->wait_command_queue);
  1310. snprintf(trans->dev_cmd_pool_name, sizeof(trans->dev_cmd_pool_name),
  1311. "iwl_cmd_pool:%s", dev_name(trans->dev));
  1312. trans->dev_cmd_headroom = 0;
  1313. trans->dev_cmd_pool =
  1314. kmem_cache_create(trans->dev_cmd_pool_name,
  1315. sizeof(struct iwl_device_cmd)
  1316. + trans->dev_cmd_headroom,
  1317. sizeof(void *),
  1318. SLAB_HWCACHE_ALIGN,
  1319. NULL);
  1320. if (!trans->dev_cmd_pool)
  1321. goto out_pci_disable_msi;
  1322. trans_pcie->inta_mask = CSR_INI_SET_MASK;
  1323. if (iwl_pcie_alloc_ict(trans))
  1324. goto out_free_cmd_pool;
  1325. if (request_threaded_irq(pdev->irq, iwl_pcie_isr_ict,
  1326. iwl_pcie_irq_handler,
  1327. IRQF_SHARED, DRV_NAME, trans)) {
  1328. IWL_ERR(trans, "Error allocating IRQ %d\n", pdev->irq);
  1329. goto out_free_ict;
  1330. }
  1331. return trans;
  1332. out_free_ict:
  1333. iwl_pcie_free_ict(trans);
  1334. out_free_cmd_pool:
  1335. kmem_cache_destroy(trans->dev_cmd_pool);
  1336. out_pci_disable_msi:
  1337. pci_disable_msi(pdev);
  1338. out_pci_release_regions:
  1339. pci_release_regions(pdev);
  1340. out_pci_disable_device:
  1341. pci_disable_device(pdev);
  1342. out_no_pci:
  1343. kfree(trans);
  1344. return NULL;
  1345. }