iwl-trans-pcie.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081
  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 - 2012 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called LICENSE.GPL.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2005 - 2012 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/bitops.h>
  68. #include <linux/gfp.h>
  69. #include "iwl-trans.h"
  70. #include "iwl-trans-pcie-int.h"
  71. #include "iwl-csr.h"
  72. #include "iwl-prph.h"
  73. #include "iwl-shared.h"
  74. #include "iwl-eeprom.h"
  75. #include "iwl-agn-hw.h"
  76. static int iwl_trans_rx_alloc(struct iwl_trans *trans)
  77. {
  78. struct iwl_trans_pcie *trans_pcie =
  79. IWL_TRANS_GET_PCIE_TRANS(trans);
  80. struct iwl_rx_queue *rxq = &trans_pcie->rxq;
  81. struct device *dev = trans->dev;
  82. memset(&trans_pcie->rxq, 0, sizeof(trans_pcie->rxq));
  83. spin_lock_init(&rxq->lock);
  84. if (WARN_ON(rxq->bd || rxq->rb_stts))
  85. return -EINVAL;
  86. /* Allocate the circular buffer of Read Buffer Descriptors (RBDs) */
  87. rxq->bd = dma_zalloc_coherent(dev, sizeof(__le32) * RX_QUEUE_SIZE,
  88. &rxq->bd_dma, GFP_KERNEL);
  89. if (!rxq->bd)
  90. goto err_bd;
  91. /*Allocate the driver's pointer to receive buffer status */
  92. rxq->rb_stts = dma_zalloc_coherent(dev, sizeof(*rxq->rb_stts),
  93. &rxq->rb_stts_dma, GFP_KERNEL);
  94. if (!rxq->rb_stts)
  95. goto err_rb_stts;
  96. return 0;
  97. err_rb_stts:
  98. dma_free_coherent(dev, sizeof(__le32) * RX_QUEUE_SIZE,
  99. rxq->bd, rxq->bd_dma);
  100. memset(&rxq->bd_dma, 0, sizeof(rxq->bd_dma));
  101. rxq->bd = NULL;
  102. err_bd:
  103. return -ENOMEM;
  104. }
  105. static void iwl_trans_rxq_free_rx_bufs(struct iwl_trans *trans)
  106. {
  107. struct iwl_trans_pcie *trans_pcie =
  108. IWL_TRANS_GET_PCIE_TRANS(trans);
  109. struct iwl_rx_queue *rxq = &trans_pcie->rxq;
  110. int i;
  111. /* Fill the rx_used queue with _all_ of the Rx buffers */
  112. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  113. /* In the reset function, these buffers may have been allocated
  114. * to an SKB, so we need to unmap and free potential storage */
  115. if (rxq->pool[i].page != NULL) {
  116. dma_unmap_page(trans->dev, rxq->pool[i].page_dma,
  117. PAGE_SIZE << hw_params(trans).rx_page_order,
  118. DMA_FROM_DEVICE);
  119. __free_pages(rxq->pool[i].page,
  120. hw_params(trans).rx_page_order);
  121. rxq->pool[i].page = NULL;
  122. }
  123. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  124. }
  125. }
  126. static void iwl_trans_rx_hw_init(struct iwl_trans *trans,
  127. struct iwl_rx_queue *rxq)
  128. {
  129. u32 rb_size;
  130. const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
  131. u32 rb_timeout = RX_RB_TIMEOUT; /* FIXME: RX_RB_TIMEOUT for all devices? */
  132. if (iwlagn_mod_params.amsdu_size_8K)
  133. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
  134. else
  135. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
  136. /* Stop Rx DMA */
  137. iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  138. /* Reset driver's Rx queue write index */
  139. iwl_write_direct32(trans, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
  140. /* Tell device where to find RBD circular buffer in DRAM */
  141. iwl_write_direct32(trans, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  142. (u32)(rxq->bd_dma >> 8));
  143. /* Tell device where in DRAM to update its Rx status */
  144. iwl_write_direct32(trans, FH_RSCSR_CHNL0_STTS_WPTR_REG,
  145. rxq->rb_stts_dma >> 4);
  146. /* Enable Rx DMA
  147. * FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY is set because of HW bug in
  148. * the credit mechanism in 5000 HW RX FIFO
  149. * Direct rx interrupts to hosts
  150. * Rx buffer size 4 or 8k
  151. * RB timeout 0x10
  152. * 256 RBDs
  153. */
  154. iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG,
  155. FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
  156. FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY |
  157. FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
  158. FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK |
  159. rb_size|
  160. (rb_timeout << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS)|
  161. (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS));
  162. /* Set interrupt coalescing timer to default (2048 usecs) */
  163. iwl_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF);
  164. }
  165. static int iwl_rx_init(struct iwl_trans *trans)
  166. {
  167. struct iwl_trans_pcie *trans_pcie =
  168. IWL_TRANS_GET_PCIE_TRANS(trans);
  169. struct iwl_rx_queue *rxq = &trans_pcie->rxq;
  170. int i, err;
  171. unsigned long flags;
  172. if (!rxq->bd) {
  173. err = iwl_trans_rx_alloc(trans);
  174. if (err)
  175. return err;
  176. }
  177. spin_lock_irqsave(&rxq->lock, flags);
  178. INIT_LIST_HEAD(&rxq->rx_free);
  179. INIT_LIST_HEAD(&rxq->rx_used);
  180. iwl_trans_rxq_free_rx_bufs(trans);
  181. for (i = 0; i < RX_QUEUE_SIZE; i++)
  182. rxq->queue[i] = NULL;
  183. /* Set us so that we have processed and used all buffers, but have
  184. * not restocked the Rx queue with fresh buffers */
  185. rxq->read = rxq->write = 0;
  186. rxq->write_actual = 0;
  187. rxq->free_count = 0;
  188. spin_unlock_irqrestore(&rxq->lock, flags);
  189. iwlagn_rx_replenish(trans);
  190. iwl_trans_rx_hw_init(trans, rxq);
  191. spin_lock_irqsave(&trans->shrd->lock, flags);
  192. rxq->need_update = 1;
  193. iwl_rx_queue_update_write_ptr(trans, rxq);
  194. spin_unlock_irqrestore(&trans->shrd->lock, flags);
  195. return 0;
  196. }
  197. static void iwl_trans_pcie_rx_free(struct iwl_trans *trans)
  198. {
  199. struct iwl_trans_pcie *trans_pcie =
  200. IWL_TRANS_GET_PCIE_TRANS(trans);
  201. struct iwl_rx_queue *rxq = &trans_pcie->rxq;
  202. unsigned long flags;
  203. /*if rxq->bd is NULL, it means that nothing has been allocated,
  204. * exit now */
  205. if (!rxq->bd) {
  206. IWL_DEBUG_INFO(trans, "Free NULL rx context\n");
  207. return;
  208. }
  209. spin_lock_irqsave(&rxq->lock, flags);
  210. iwl_trans_rxq_free_rx_bufs(trans);
  211. spin_unlock_irqrestore(&rxq->lock, flags);
  212. dma_free_coherent(trans->dev, sizeof(__le32) * RX_QUEUE_SIZE,
  213. rxq->bd, rxq->bd_dma);
  214. memset(&rxq->bd_dma, 0, sizeof(rxq->bd_dma));
  215. rxq->bd = NULL;
  216. if (rxq->rb_stts)
  217. dma_free_coherent(trans->dev,
  218. sizeof(struct iwl_rb_status),
  219. rxq->rb_stts, rxq->rb_stts_dma);
  220. else
  221. IWL_DEBUG_INFO(trans, "Free rxq->rb_stts which is NULL\n");
  222. memset(&rxq->rb_stts_dma, 0, sizeof(rxq->rb_stts_dma));
  223. rxq->rb_stts = NULL;
  224. }
  225. static int iwl_trans_rx_stop(struct iwl_trans *trans)
  226. {
  227. /* stop Rx DMA */
  228. iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  229. return iwl_poll_direct_bit(trans, FH_MEM_RSSR_RX_STATUS_REG,
  230. FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
  231. }
  232. static inline int iwlagn_alloc_dma_ptr(struct iwl_trans *trans,
  233. struct iwl_dma_ptr *ptr, size_t size)
  234. {
  235. if (WARN_ON(ptr->addr))
  236. return -EINVAL;
  237. ptr->addr = dma_alloc_coherent(trans->dev, size,
  238. &ptr->dma, GFP_KERNEL);
  239. if (!ptr->addr)
  240. return -ENOMEM;
  241. ptr->size = size;
  242. return 0;
  243. }
  244. static inline void iwlagn_free_dma_ptr(struct iwl_trans *trans,
  245. struct iwl_dma_ptr *ptr)
  246. {
  247. if (unlikely(!ptr->addr))
  248. return;
  249. dma_free_coherent(trans->dev, ptr->size, ptr->addr, ptr->dma);
  250. memset(ptr, 0, sizeof(*ptr));
  251. }
  252. static int iwl_trans_txq_alloc(struct iwl_trans *trans,
  253. struct iwl_tx_queue *txq, int slots_num,
  254. u32 txq_id)
  255. {
  256. size_t tfd_sz = sizeof(struct iwl_tfd) * TFD_QUEUE_SIZE_MAX;
  257. int i;
  258. if (WARN_ON(txq->meta || txq->cmd || txq->skbs || txq->tfds))
  259. return -EINVAL;
  260. txq->q.n_window = slots_num;
  261. txq->meta = kcalloc(slots_num, sizeof(txq->meta[0]), GFP_KERNEL);
  262. txq->cmd = kcalloc(slots_num, sizeof(txq->cmd[0]), GFP_KERNEL);
  263. if (!txq->meta || !txq->cmd)
  264. goto error;
  265. if (txq_id == trans->shrd->cmd_queue)
  266. for (i = 0; i < slots_num; i++) {
  267. txq->cmd[i] = kmalloc(sizeof(struct iwl_device_cmd),
  268. GFP_KERNEL);
  269. if (!txq->cmd[i])
  270. goto error;
  271. }
  272. /* Alloc driver data array and TFD circular buffer */
  273. /* Driver private data, only for Tx (not command) queues,
  274. * not shared with device. */
  275. if (txq_id != trans->shrd->cmd_queue) {
  276. txq->skbs = kcalloc(TFD_QUEUE_SIZE_MAX, sizeof(txq->skbs[0]),
  277. GFP_KERNEL);
  278. if (!txq->skbs) {
  279. IWL_ERR(trans, "kmalloc for auxiliary BD "
  280. "structures failed\n");
  281. goto error;
  282. }
  283. } else {
  284. txq->skbs = NULL;
  285. }
  286. /* Circular buffer of transmit frame descriptors (TFDs),
  287. * shared with device */
  288. txq->tfds = dma_alloc_coherent(trans->dev, tfd_sz,
  289. &txq->q.dma_addr, GFP_KERNEL);
  290. if (!txq->tfds) {
  291. IWL_ERR(trans, "dma_alloc_coherent(%zd) failed\n", tfd_sz);
  292. goto error;
  293. }
  294. txq->q.id = txq_id;
  295. return 0;
  296. error:
  297. kfree(txq->skbs);
  298. txq->skbs = NULL;
  299. /* since txq->cmd has been zeroed,
  300. * all non allocated cmd[i] will be NULL */
  301. if (txq->cmd && txq_id == trans->shrd->cmd_queue)
  302. for (i = 0; i < slots_num; i++)
  303. kfree(txq->cmd[i]);
  304. kfree(txq->meta);
  305. kfree(txq->cmd);
  306. txq->meta = NULL;
  307. txq->cmd = NULL;
  308. return -ENOMEM;
  309. }
  310. static int iwl_trans_txq_init(struct iwl_trans *trans, struct iwl_tx_queue *txq,
  311. int slots_num, u32 txq_id)
  312. {
  313. int ret;
  314. txq->need_update = 0;
  315. memset(txq->meta, 0, sizeof(txq->meta[0]) * slots_num);
  316. /*
  317. * For the default queues 0-3, set up the swq_id
  318. * already -- all others need to get one later
  319. * (if they need one at all).
  320. */
  321. if (txq_id < 4)
  322. iwl_set_swq_id(txq, txq_id, txq_id);
  323. /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
  324. * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
  325. BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
  326. /* Initialize queue's high/low-water marks, and head/tail indexes */
  327. ret = iwl_queue_init(&txq->q, TFD_QUEUE_SIZE_MAX, slots_num,
  328. txq_id);
  329. if (ret)
  330. return ret;
  331. /*
  332. * Tell nic where to find circular buffer of Tx Frame Descriptors for
  333. * given Tx queue, and enable the DMA channel used for that queue.
  334. * Circular buffer (TFD queue in DRAM) physical base address */
  335. iwl_write_direct32(trans, FH_MEM_CBBC_QUEUE(txq_id),
  336. txq->q.dma_addr >> 8);
  337. return 0;
  338. }
  339. /**
  340. * iwl_tx_queue_unmap - Unmap any remaining DMA mappings and free skb's
  341. */
  342. static void iwl_tx_queue_unmap(struct iwl_trans *trans, int txq_id)
  343. {
  344. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  345. struct iwl_tx_queue *txq = &trans_pcie->txq[txq_id];
  346. struct iwl_queue *q = &txq->q;
  347. enum dma_data_direction dma_dir;
  348. unsigned long flags;
  349. spinlock_t *lock;
  350. if (!q->n_bd)
  351. return;
  352. /* In the command queue, all the TBs are mapped as BIDI
  353. * so unmap them as such.
  354. */
  355. if (txq_id == trans->shrd->cmd_queue) {
  356. dma_dir = DMA_BIDIRECTIONAL;
  357. lock = &trans->hcmd_lock;
  358. } else {
  359. dma_dir = DMA_TO_DEVICE;
  360. lock = &trans->shrd->sta_lock;
  361. }
  362. spin_lock_irqsave(lock, flags);
  363. while (q->write_ptr != q->read_ptr) {
  364. /* The read_ptr needs to bound by q->n_window */
  365. iwlagn_txq_free_tfd(trans, txq, get_cmd_index(q, q->read_ptr),
  366. dma_dir);
  367. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd);
  368. }
  369. spin_unlock_irqrestore(lock, flags);
  370. }
  371. /**
  372. * iwl_tx_queue_free - Deallocate DMA queue.
  373. * @txq: Transmit queue to deallocate.
  374. *
  375. * Empty queue by removing and destroying all BD's.
  376. * Free all buffers.
  377. * 0-fill, but do not free "txq" descriptor structure.
  378. */
  379. static void iwl_tx_queue_free(struct iwl_trans *trans, int txq_id)
  380. {
  381. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  382. struct iwl_tx_queue *txq = &trans_pcie->txq[txq_id];
  383. struct device *dev = trans->dev;
  384. int i;
  385. if (WARN_ON(!txq))
  386. return;
  387. iwl_tx_queue_unmap(trans, txq_id);
  388. /* De-alloc array of command/tx buffers */
  389. if (txq_id == trans->shrd->cmd_queue)
  390. for (i = 0; i < txq->q.n_window; i++)
  391. kfree(txq->cmd[i]);
  392. /* De-alloc circular buffer of TFDs */
  393. if (txq->q.n_bd) {
  394. dma_free_coherent(dev, sizeof(struct iwl_tfd) *
  395. txq->q.n_bd, txq->tfds, txq->q.dma_addr);
  396. memset(&txq->q.dma_addr, 0, sizeof(txq->q.dma_addr));
  397. }
  398. /* De-alloc array of per-TFD driver data */
  399. kfree(txq->skbs);
  400. txq->skbs = NULL;
  401. /* deallocate arrays */
  402. kfree(txq->cmd);
  403. kfree(txq->meta);
  404. txq->cmd = NULL;
  405. txq->meta = NULL;
  406. /* 0-fill queue descriptor structure */
  407. memset(txq, 0, sizeof(*txq));
  408. }
  409. /**
  410. * iwl_trans_tx_free - Free TXQ Context
  411. *
  412. * Destroy all TX DMA queues and structures
  413. */
  414. static void iwl_trans_pcie_tx_free(struct iwl_trans *trans)
  415. {
  416. int txq_id;
  417. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  418. /* Tx queues */
  419. if (trans_pcie->txq) {
  420. for (txq_id = 0;
  421. txq_id < hw_params(trans).max_txq_num; txq_id++)
  422. iwl_tx_queue_free(trans, txq_id);
  423. }
  424. kfree(trans_pcie->txq);
  425. trans_pcie->txq = NULL;
  426. iwlagn_free_dma_ptr(trans, &trans_pcie->kw);
  427. iwlagn_free_dma_ptr(trans, &trans_pcie->scd_bc_tbls);
  428. }
  429. /**
  430. * iwl_trans_tx_alloc - allocate TX context
  431. * Allocate all Tx DMA structures and initialize them
  432. *
  433. * @param priv
  434. * @return error code
  435. */
  436. static int iwl_trans_tx_alloc(struct iwl_trans *trans)
  437. {
  438. int ret;
  439. int txq_id, slots_num;
  440. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  441. u16 scd_bc_tbls_size = hw_params(trans).max_txq_num *
  442. sizeof(struct iwlagn_scd_bc_tbl);
  443. /*It is not allowed to alloc twice, so warn when this happens.
  444. * We cannot rely on the previous allocation, so free and fail */
  445. if (WARN_ON(trans_pcie->txq)) {
  446. ret = -EINVAL;
  447. goto error;
  448. }
  449. ret = iwlagn_alloc_dma_ptr(trans, &trans_pcie->scd_bc_tbls,
  450. scd_bc_tbls_size);
  451. if (ret) {
  452. IWL_ERR(trans, "Scheduler BC Table allocation failed\n");
  453. goto error;
  454. }
  455. /* Alloc keep-warm buffer */
  456. ret = iwlagn_alloc_dma_ptr(trans, &trans_pcie->kw, IWL_KW_SIZE);
  457. if (ret) {
  458. IWL_ERR(trans, "Keep Warm allocation failed\n");
  459. goto error;
  460. }
  461. trans_pcie->txq = kcalloc(hw_params(trans).max_txq_num,
  462. sizeof(struct iwl_tx_queue), GFP_KERNEL);
  463. if (!trans_pcie->txq) {
  464. IWL_ERR(trans, "Not enough memory for txq\n");
  465. ret = ENOMEM;
  466. goto error;
  467. }
  468. /* Alloc and init all Tx queues, including the command queue (#4/#9) */
  469. for (txq_id = 0; txq_id < hw_params(trans).max_txq_num; txq_id++) {
  470. slots_num = (txq_id == trans->shrd->cmd_queue) ?
  471. TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  472. ret = iwl_trans_txq_alloc(trans, &trans_pcie->txq[txq_id],
  473. slots_num, txq_id);
  474. if (ret) {
  475. IWL_ERR(trans, "Tx %d queue alloc failed\n", txq_id);
  476. goto error;
  477. }
  478. }
  479. return 0;
  480. error:
  481. iwl_trans_pcie_tx_free(trans);
  482. return ret;
  483. }
  484. static int iwl_tx_init(struct iwl_trans *trans)
  485. {
  486. int ret;
  487. int txq_id, slots_num;
  488. unsigned long flags;
  489. bool alloc = false;
  490. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  491. if (!trans_pcie->txq) {
  492. ret = iwl_trans_tx_alloc(trans);
  493. if (ret)
  494. goto error;
  495. alloc = true;
  496. }
  497. spin_lock_irqsave(&trans->shrd->lock, flags);
  498. /* Turn off all Tx DMA fifos */
  499. iwl_write_prph(trans, SCD_TXFACT, 0);
  500. /* Tell NIC where to find the "keep warm" buffer */
  501. iwl_write_direct32(trans, FH_KW_MEM_ADDR_REG,
  502. trans_pcie->kw.dma >> 4);
  503. spin_unlock_irqrestore(&trans->shrd->lock, flags);
  504. /* Alloc and init all Tx queues, including the command queue (#4/#9) */
  505. for (txq_id = 0; txq_id < hw_params(trans).max_txq_num; txq_id++) {
  506. slots_num = (txq_id == trans->shrd->cmd_queue) ?
  507. TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  508. ret = iwl_trans_txq_init(trans, &trans_pcie->txq[txq_id],
  509. slots_num, txq_id);
  510. if (ret) {
  511. IWL_ERR(trans, "Tx %d queue init failed\n", txq_id);
  512. goto error;
  513. }
  514. }
  515. return 0;
  516. error:
  517. /*Upon error, free only if we allocated something */
  518. if (alloc)
  519. iwl_trans_pcie_tx_free(trans);
  520. return ret;
  521. }
  522. static void iwl_set_pwr_vmain(struct iwl_trans *trans)
  523. {
  524. /*
  525. * (for documentation purposes)
  526. * to set power to V_AUX, do:
  527. if (pci_pme_capable(priv->pci_dev, PCI_D3cold))
  528. iwl_set_bits_mask_prph(trans, APMG_PS_CTRL_REG,
  529. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  530. ~APMG_PS_CTRL_MSK_PWR_SRC);
  531. */
  532. iwl_set_bits_mask_prph(trans, APMG_PS_CTRL_REG,
  533. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  534. ~APMG_PS_CTRL_MSK_PWR_SRC);
  535. }
  536. static int iwl_nic_init(struct iwl_trans *trans)
  537. {
  538. unsigned long flags;
  539. /* nic_init */
  540. spin_lock_irqsave(&trans->shrd->lock, flags);
  541. iwl_apm_init(priv(trans));
  542. /* Set interrupt coalescing calibration timer to default (512 usecs) */
  543. iwl_write8(trans, CSR_INT_COALESCING,
  544. IWL_HOST_INT_CALIB_TIMEOUT_DEF);
  545. spin_unlock_irqrestore(&trans->shrd->lock, flags);
  546. iwl_set_pwr_vmain(trans);
  547. iwl_nic_config(priv(trans));
  548. #ifndef CONFIG_IWLWIFI_IDI
  549. /* Allocate the RX queue, or reset if it is already allocated */
  550. iwl_rx_init(trans);
  551. #endif
  552. /* Allocate or reset and init all Tx and Command queues */
  553. if (iwl_tx_init(trans))
  554. return -ENOMEM;
  555. if (hw_params(trans).shadow_reg_enable) {
  556. /* enable shadow regs in HW */
  557. iwl_set_bit(trans, CSR_MAC_SHADOW_REG_CTRL,
  558. 0x800FFFFF);
  559. }
  560. set_bit(STATUS_INIT, &trans->shrd->status);
  561. return 0;
  562. }
  563. #define HW_READY_TIMEOUT (50)
  564. /* Note: returns poll_bit return value, which is >= 0 if success */
  565. static int iwl_set_hw_ready(struct iwl_trans *trans)
  566. {
  567. int ret;
  568. iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
  569. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  570. /* See if we got it */
  571. ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG,
  572. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  573. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  574. HW_READY_TIMEOUT);
  575. IWL_DEBUG_INFO(trans, "hardware%s ready\n", ret < 0 ? " not" : "");
  576. return ret;
  577. }
  578. /* Note: returns standard 0/-ERROR code */
  579. static int iwl_prepare_card_hw(struct iwl_trans *trans)
  580. {
  581. int ret;
  582. IWL_DEBUG_INFO(trans, "iwl_trans_prepare_card_hw enter\n");
  583. ret = iwl_set_hw_ready(trans);
  584. /* If the card is ready, exit 0 */
  585. if (ret >= 0)
  586. return 0;
  587. /* If HW is not ready, prepare the conditions to check again */
  588. iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
  589. CSR_HW_IF_CONFIG_REG_PREPARE);
  590. ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG,
  591. ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
  592. CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
  593. if (ret < 0)
  594. return ret;
  595. /* HW should be ready by now, check again. */
  596. ret = iwl_set_hw_ready(trans);
  597. if (ret >= 0)
  598. return 0;
  599. return ret;
  600. }
  601. #define IWL_AC_UNSET -1
  602. struct queue_to_fifo_ac {
  603. s8 fifo, ac;
  604. };
  605. static const struct queue_to_fifo_ac iwlagn_default_queue_to_tx_fifo[] = {
  606. { IWL_TX_FIFO_VO, IEEE80211_AC_VO, },
  607. { IWL_TX_FIFO_VI, IEEE80211_AC_VI, },
  608. { IWL_TX_FIFO_BE, IEEE80211_AC_BE, },
  609. { IWL_TX_FIFO_BK, IEEE80211_AC_BK, },
  610. { IWLAGN_CMD_FIFO_NUM, IWL_AC_UNSET, },
  611. { IWL_TX_FIFO_UNUSED, IWL_AC_UNSET, },
  612. { IWL_TX_FIFO_UNUSED, IWL_AC_UNSET, },
  613. { IWL_TX_FIFO_UNUSED, IWL_AC_UNSET, },
  614. { IWL_TX_FIFO_UNUSED, IWL_AC_UNSET, },
  615. { IWL_TX_FIFO_UNUSED, IWL_AC_UNSET, },
  616. { IWL_TX_FIFO_UNUSED, IWL_AC_UNSET, },
  617. };
  618. static const struct queue_to_fifo_ac iwlagn_ipan_queue_to_tx_fifo[] = {
  619. { IWL_TX_FIFO_VO, IEEE80211_AC_VO, },
  620. { IWL_TX_FIFO_VI, IEEE80211_AC_VI, },
  621. { IWL_TX_FIFO_BE, IEEE80211_AC_BE, },
  622. { IWL_TX_FIFO_BK, IEEE80211_AC_BK, },
  623. { IWL_TX_FIFO_BK_IPAN, IEEE80211_AC_BK, },
  624. { IWL_TX_FIFO_BE_IPAN, IEEE80211_AC_BE, },
  625. { IWL_TX_FIFO_VI_IPAN, IEEE80211_AC_VI, },
  626. { IWL_TX_FIFO_VO_IPAN, IEEE80211_AC_VO, },
  627. { IWL_TX_FIFO_BE_IPAN, 2, },
  628. { IWLAGN_CMD_FIFO_NUM, IWL_AC_UNSET, },
  629. { IWL_TX_FIFO_AUX, IWL_AC_UNSET, },
  630. };
  631. static const u8 iwlagn_bss_ac_to_fifo[] = {
  632. IWL_TX_FIFO_VO,
  633. IWL_TX_FIFO_VI,
  634. IWL_TX_FIFO_BE,
  635. IWL_TX_FIFO_BK,
  636. };
  637. static const u8 iwlagn_bss_ac_to_queue[] = {
  638. 0, 1, 2, 3,
  639. };
  640. static const u8 iwlagn_pan_ac_to_fifo[] = {
  641. IWL_TX_FIFO_VO_IPAN,
  642. IWL_TX_FIFO_VI_IPAN,
  643. IWL_TX_FIFO_BE_IPAN,
  644. IWL_TX_FIFO_BK_IPAN,
  645. };
  646. static const u8 iwlagn_pan_ac_to_queue[] = {
  647. 7, 6, 5, 4,
  648. };
  649. static int iwl_trans_pcie_start_device(struct iwl_trans *trans)
  650. {
  651. int ret;
  652. struct iwl_trans_pcie *trans_pcie =
  653. IWL_TRANS_GET_PCIE_TRANS(trans);
  654. trans->shrd->ucode_owner = IWL_OWNERSHIP_DRIVER;
  655. trans_pcie->ac_to_queue[IWL_RXON_CTX_BSS] = iwlagn_bss_ac_to_queue;
  656. trans_pcie->ac_to_queue[IWL_RXON_CTX_PAN] = iwlagn_pan_ac_to_queue;
  657. trans_pcie->ac_to_fifo[IWL_RXON_CTX_BSS] = iwlagn_bss_ac_to_fifo;
  658. trans_pcie->ac_to_fifo[IWL_RXON_CTX_PAN] = iwlagn_pan_ac_to_fifo;
  659. trans_pcie->mcast_queue[IWL_RXON_CTX_BSS] = 0;
  660. trans_pcie->mcast_queue[IWL_RXON_CTX_PAN] = IWL_IPAN_MCAST_QUEUE;
  661. if ((hw_params(trans).sku & EEPROM_SKU_CAP_AMT_ENABLE) &&
  662. iwl_prepare_card_hw(trans)) {
  663. IWL_WARN(trans, "Exit HW not ready\n");
  664. return -EIO;
  665. }
  666. /* If platform's RF_KILL switch is NOT set to KILL */
  667. if (iwl_read32(trans, CSR_GP_CNTRL) &
  668. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  669. clear_bit(STATUS_RF_KILL_HW, &trans->shrd->status);
  670. else
  671. set_bit(STATUS_RF_KILL_HW, &trans->shrd->status);
  672. if (iwl_is_rfkill(trans->shrd)) {
  673. iwl_set_hw_rfkill_state(priv(trans), true);
  674. iwl_enable_interrupts(trans);
  675. return -ERFKILL;
  676. }
  677. iwl_write32(trans, CSR_INT, 0xFFFFFFFF);
  678. ret = iwl_nic_init(trans);
  679. if (ret) {
  680. IWL_ERR(trans, "Unable to init nic\n");
  681. return ret;
  682. }
  683. /* make sure rfkill handshake bits are cleared */
  684. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  685. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR,
  686. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  687. /* clear (again), then enable host interrupts */
  688. iwl_write32(trans, CSR_INT, 0xFFFFFFFF);
  689. iwl_enable_interrupts(trans);
  690. /* really make sure rfkill handshake bits are cleared */
  691. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  692. iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  693. return 0;
  694. }
  695. /*
  696. * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask
  697. * must be called under priv->shrd->lock and mac access
  698. */
  699. static void iwl_trans_txq_set_sched(struct iwl_trans *trans, u32 mask)
  700. {
  701. iwl_write_prph(trans, SCD_TXFACT, mask);
  702. }
  703. static void iwl_tx_start(struct iwl_trans *trans)
  704. {
  705. const struct queue_to_fifo_ac *queue_to_fifo;
  706. struct iwl_trans_pcie *trans_pcie =
  707. IWL_TRANS_GET_PCIE_TRANS(trans);
  708. u32 a;
  709. unsigned long flags;
  710. int i, chan;
  711. u32 reg_val;
  712. spin_lock_irqsave(&trans->shrd->lock, flags);
  713. trans_pcie->scd_base_addr =
  714. iwl_read_prph(trans, SCD_SRAM_BASE_ADDR);
  715. a = trans_pcie->scd_base_addr + SCD_CONTEXT_MEM_LOWER_BOUND;
  716. /* reset conext data memory */
  717. for (; a < trans_pcie->scd_base_addr + SCD_CONTEXT_MEM_UPPER_BOUND;
  718. a += 4)
  719. iwl_write_targ_mem(trans, a, 0);
  720. /* reset tx status memory */
  721. for (; a < trans_pcie->scd_base_addr + SCD_TX_STTS_MEM_UPPER_BOUND;
  722. a += 4)
  723. iwl_write_targ_mem(trans, a, 0);
  724. for (; a < trans_pcie->scd_base_addr +
  725. SCD_TRANS_TBL_OFFSET_QUEUE(hw_params(trans).max_txq_num);
  726. a += 4)
  727. iwl_write_targ_mem(trans, a, 0);
  728. iwl_write_prph(trans, SCD_DRAM_BASE_ADDR,
  729. trans_pcie->scd_bc_tbls.dma >> 10);
  730. /* Enable DMA channel */
  731. for (chan = 0; chan < FH_TCSR_CHNL_NUM ; chan++)
  732. iwl_write_direct32(trans, FH_TCSR_CHNL_TX_CONFIG_REG(chan),
  733. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  734. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  735. /* Update FH chicken bits */
  736. reg_val = iwl_read_direct32(trans, FH_TX_CHICKEN_BITS_REG);
  737. iwl_write_direct32(trans, FH_TX_CHICKEN_BITS_REG,
  738. reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  739. iwl_write_prph(trans, SCD_QUEUECHAIN_SEL,
  740. SCD_QUEUECHAIN_SEL_ALL(trans));
  741. iwl_write_prph(trans, SCD_AGGR_SEL, 0);
  742. /* initiate the queues */
  743. for (i = 0; i < hw_params(trans).max_txq_num; i++) {
  744. iwl_write_prph(trans, SCD_QUEUE_RDPTR(i), 0);
  745. iwl_write_direct32(trans, HBUS_TARG_WRPTR, 0 | (i << 8));
  746. iwl_write_targ_mem(trans, trans_pcie->scd_base_addr +
  747. SCD_CONTEXT_QUEUE_OFFSET(i), 0);
  748. iwl_write_targ_mem(trans, trans_pcie->scd_base_addr +
  749. SCD_CONTEXT_QUEUE_OFFSET(i) +
  750. sizeof(u32),
  751. ((SCD_WIN_SIZE <<
  752. SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  753. SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  754. ((SCD_FRAME_LIMIT <<
  755. SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  756. SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  757. }
  758. iwl_write_prph(trans, SCD_INTERRUPT_MASK,
  759. IWL_MASK(0, hw_params(trans).max_txq_num));
  760. /* Activate all Tx DMA/FIFO channels */
  761. iwl_trans_txq_set_sched(trans, IWL_MASK(0, 7));
  762. /* map queues to FIFOs */
  763. if (trans->shrd->valid_contexts != BIT(IWL_RXON_CTX_BSS))
  764. queue_to_fifo = iwlagn_ipan_queue_to_tx_fifo;
  765. else
  766. queue_to_fifo = iwlagn_default_queue_to_tx_fifo;
  767. iwl_trans_set_wr_ptrs(trans, trans->shrd->cmd_queue, 0);
  768. /* make sure all queue are not stopped */
  769. memset(&trans_pcie->queue_stopped[0], 0,
  770. sizeof(trans_pcie->queue_stopped));
  771. for (i = 0; i < 4; i++)
  772. atomic_set(&trans_pcie->queue_stop_count[i], 0);
  773. /* reset to 0 to enable all the queue first */
  774. trans_pcie->txq_ctx_active_msk = 0;
  775. BUILD_BUG_ON(ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo) <
  776. IWLAGN_FIRST_AMPDU_QUEUE);
  777. BUILD_BUG_ON(ARRAY_SIZE(iwlagn_ipan_queue_to_tx_fifo) <
  778. IWLAGN_FIRST_AMPDU_QUEUE);
  779. for (i = 0; i < IWLAGN_FIRST_AMPDU_QUEUE; i++) {
  780. int fifo = queue_to_fifo[i].fifo;
  781. int ac = queue_to_fifo[i].ac;
  782. iwl_txq_ctx_activate(trans_pcie, i);
  783. if (fifo == IWL_TX_FIFO_UNUSED)
  784. continue;
  785. if (ac != IWL_AC_UNSET)
  786. iwl_set_swq_id(&trans_pcie->txq[i], ac, i);
  787. iwl_trans_tx_queue_set_status(trans, &trans_pcie->txq[i],
  788. fifo, 0);
  789. }
  790. spin_unlock_irqrestore(&trans->shrd->lock, flags);
  791. /* Enable L1-Active */
  792. iwl_clear_bits_prph(trans, APMG_PCIDEV_STT_REG,
  793. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  794. }
  795. static void iwl_trans_pcie_fw_alive(struct iwl_trans *trans)
  796. {
  797. iwl_reset_ict(trans);
  798. iwl_tx_start(trans);
  799. }
  800. /**
  801. * iwlagn_txq_ctx_stop - Stop all Tx DMA channels
  802. */
  803. static int iwl_trans_tx_stop(struct iwl_trans *trans)
  804. {
  805. int ch, txq_id;
  806. unsigned long flags;
  807. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  808. /* Turn off all Tx DMA fifos */
  809. spin_lock_irqsave(&trans->shrd->lock, flags);
  810. iwl_trans_txq_set_sched(trans, 0);
  811. /* Stop each Tx DMA channel, and wait for it to be idle */
  812. for (ch = 0; ch < FH_TCSR_CHNL_NUM; ch++) {
  813. iwl_write_direct32(trans,
  814. FH_TCSR_CHNL_TX_CONFIG_REG(ch), 0x0);
  815. if (iwl_poll_direct_bit(trans, FH_TSSR_TX_STATUS_REG,
  816. FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch),
  817. 1000))
  818. IWL_ERR(trans, "Failing on timeout while stopping"
  819. " DMA channel %d [0x%08x]", ch,
  820. iwl_read_direct32(trans,
  821. FH_TSSR_TX_STATUS_REG));
  822. }
  823. spin_unlock_irqrestore(&trans->shrd->lock, flags);
  824. if (!trans_pcie->txq) {
  825. IWL_WARN(trans, "Stopping tx queues that aren't allocated...");
  826. return 0;
  827. }
  828. /* Unmap DMA from host system and free skb's */
  829. for (txq_id = 0; txq_id < hw_params(trans).max_txq_num; txq_id++)
  830. iwl_tx_queue_unmap(trans, txq_id);
  831. return 0;
  832. }
  833. static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
  834. {
  835. unsigned long flags;
  836. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  837. /* tell the device to stop sending interrupts */
  838. spin_lock_irqsave(&trans->shrd->lock, flags);
  839. iwl_disable_interrupts(trans);
  840. spin_unlock_irqrestore(&trans->shrd->lock, flags);
  841. /* device going down, Stop using ICT table */
  842. iwl_disable_ict(trans);
  843. /*
  844. * If a HW restart happens during firmware loading,
  845. * then the firmware loading might call this function
  846. * and later it might be called again due to the
  847. * restart. So don't process again if the device is
  848. * already dead.
  849. */
  850. if (test_bit(STATUS_DEVICE_ENABLED, &trans->shrd->status)) {
  851. iwl_trans_tx_stop(trans);
  852. #ifndef CONFIG_IWLWIFI_IDI
  853. iwl_trans_rx_stop(trans);
  854. #endif
  855. /* Power-down device's busmaster DMA clocks */
  856. iwl_write_prph(trans, APMG_CLK_DIS_REG,
  857. APMG_CLK_VAL_DMA_CLK_RQT);
  858. udelay(5);
  859. }
  860. /* Make sure (redundant) we've released our request to stay awake */
  861. iwl_clear_bit(trans, CSR_GP_CNTRL,
  862. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  863. /* Stop the device, and put it in low power state */
  864. iwl_apm_stop(priv(trans));
  865. /* Upon stop, the APM issues an interrupt if HW RF kill is set.
  866. * Clean again the interrupt here
  867. */
  868. spin_lock_irqsave(&trans->shrd->lock, flags);
  869. iwl_disable_interrupts(trans);
  870. spin_unlock_irqrestore(&trans->shrd->lock, flags);
  871. /* wait to make sure we flush pending tasklet*/
  872. synchronize_irq(trans->irq);
  873. tasklet_kill(&trans_pcie->irq_tasklet);
  874. /* stop and reset the on-board processor */
  875. iwl_write32(trans, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  876. }
  877. static int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
  878. struct iwl_device_cmd *dev_cmd, enum iwl_rxon_context_id ctx,
  879. u8 sta_id, u8 tid)
  880. {
  881. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  882. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  883. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  884. struct iwl_tx_cmd *tx_cmd = (struct iwl_tx_cmd *) dev_cmd->payload;
  885. struct iwl_cmd_meta *out_meta;
  886. struct iwl_tx_queue *txq;
  887. struct iwl_queue *q;
  888. dma_addr_t phys_addr = 0;
  889. dma_addr_t txcmd_phys;
  890. dma_addr_t scratch_phys;
  891. u16 len, firstlen, secondlen;
  892. u8 wait_write_ptr = 0;
  893. u8 txq_id;
  894. bool is_agg = false;
  895. __le16 fc = hdr->frame_control;
  896. u8 hdr_len = ieee80211_hdrlen(fc);
  897. u16 __maybe_unused wifi_seq;
  898. /*
  899. * Send this frame after DTIM -- there's a special queue
  900. * reserved for this for contexts that support AP mode.
  901. */
  902. if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
  903. txq_id = trans_pcie->mcast_queue[ctx];
  904. /*
  905. * The microcode will clear the more data
  906. * bit in the last frame it transmits.
  907. */
  908. hdr->frame_control |=
  909. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  910. } else if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)
  911. txq_id = IWL_AUX_QUEUE;
  912. else
  913. txq_id =
  914. trans_pcie->ac_to_queue[ctx][skb_get_queue_mapping(skb)];
  915. /* aggregation is on for this <sta,tid> */
  916. if (info->flags & IEEE80211_TX_CTL_AMPDU) {
  917. WARN_ON(tid >= IWL_MAX_TID_COUNT);
  918. txq_id = trans_pcie->agg_txq[sta_id][tid];
  919. is_agg = true;
  920. }
  921. txq = &trans_pcie->txq[txq_id];
  922. q = &txq->q;
  923. /* In AGG mode, the index in the ring must correspond to the WiFi
  924. * sequence number. This is a HW requirements to help the SCD to parse
  925. * the BA.
  926. * Check here that the packets are in the right place on the ring.
  927. */
  928. #ifdef CONFIG_IWLWIFI_DEBUG
  929. wifi_seq = SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
  930. WARN_ONCE(is_agg && ((wifi_seq & 0xff) != q->write_ptr),
  931. "Q: %d WiFi Seq %d tfdNum %d",
  932. txq_id, wifi_seq, q->write_ptr);
  933. #endif
  934. /* Set up driver data for this TFD */
  935. txq->skbs[q->write_ptr] = skb;
  936. txq->cmd[q->write_ptr] = dev_cmd;
  937. dev_cmd->hdr.cmd = REPLY_TX;
  938. dev_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  939. INDEX_TO_SEQ(q->write_ptr)));
  940. /* Set up first empty entry in queue's array of Tx/cmd buffers */
  941. out_meta = &txq->meta[q->write_ptr];
  942. /*
  943. * Use the first empty entry in this queue's command buffer array
  944. * to contain the Tx command and MAC header concatenated together
  945. * (payload data will be in another buffer).
  946. * Size of this varies, due to varying MAC header length.
  947. * If end is not dword aligned, we'll have 2 extra bytes at the end
  948. * of the MAC header (device reads on dword boundaries).
  949. * We'll tell device about this padding later.
  950. */
  951. len = sizeof(struct iwl_tx_cmd) +
  952. sizeof(struct iwl_cmd_header) + hdr_len;
  953. firstlen = (len + 3) & ~3;
  954. /* Tell NIC about any 2-byte padding after MAC header */
  955. if (firstlen != len)
  956. tx_cmd->tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
  957. /* Physical address of this Tx command's header (not MAC header!),
  958. * within command buffer array. */
  959. txcmd_phys = dma_map_single(trans->dev,
  960. &dev_cmd->hdr, firstlen,
  961. DMA_BIDIRECTIONAL);
  962. if (unlikely(dma_mapping_error(trans->dev, txcmd_phys)))
  963. return -1;
  964. dma_unmap_addr_set(out_meta, mapping, txcmd_phys);
  965. dma_unmap_len_set(out_meta, len, firstlen);
  966. if (!ieee80211_has_morefrags(fc)) {
  967. txq->need_update = 1;
  968. } else {
  969. wait_write_ptr = 1;
  970. txq->need_update = 0;
  971. }
  972. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  973. * if any (802.11 null frames have no payload). */
  974. secondlen = skb->len - hdr_len;
  975. if (secondlen > 0) {
  976. phys_addr = dma_map_single(trans->dev, skb->data + hdr_len,
  977. secondlen, DMA_TO_DEVICE);
  978. if (unlikely(dma_mapping_error(trans->dev, phys_addr))) {
  979. dma_unmap_single(trans->dev,
  980. dma_unmap_addr(out_meta, mapping),
  981. dma_unmap_len(out_meta, len),
  982. DMA_BIDIRECTIONAL);
  983. return -1;
  984. }
  985. }
  986. /* Attach buffers to TFD */
  987. iwlagn_txq_attach_buf_to_tfd(trans, txq, txcmd_phys, firstlen, 1);
  988. if (secondlen > 0)
  989. iwlagn_txq_attach_buf_to_tfd(trans, txq, phys_addr,
  990. secondlen, 0);
  991. scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) +
  992. offsetof(struct iwl_tx_cmd, scratch);
  993. /* take back ownership of DMA buffer to enable update */
  994. dma_sync_single_for_cpu(trans->dev, txcmd_phys, firstlen,
  995. DMA_BIDIRECTIONAL);
  996. tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys);
  997. tx_cmd->dram_msb_ptr = iwl_get_dma_hi_addr(scratch_phys);
  998. IWL_DEBUG_TX(trans, "sequence nr = 0X%x\n",
  999. le16_to_cpu(dev_cmd->hdr.sequence));
  1000. IWL_DEBUG_TX(trans, "tx_flags = 0X%x\n", le32_to_cpu(tx_cmd->tx_flags));
  1001. iwl_print_hex_dump(trans, IWL_DL_TX, (u8 *)tx_cmd, sizeof(*tx_cmd));
  1002. iwl_print_hex_dump(trans, IWL_DL_TX, (u8 *)tx_cmd->hdr, hdr_len);
  1003. /* Set up entry for this TFD in Tx byte-count array */
  1004. iwl_trans_txq_update_byte_cnt_tbl(trans, txq, le16_to_cpu(tx_cmd->len));
  1005. dma_sync_single_for_device(trans->dev, txcmd_phys, firstlen,
  1006. DMA_BIDIRECTIONAL);
  1007. trace_iwlwifi_dev_tx(priv(trans),
  1008. &((struct iwl_tfd *)txq->tfds)[txq->q.write_ptr],
  1009. sizeof(struct iwl_tfd),
  1010. &dev_cmd->hdr, firstlen,
  1011. skb->data + hdr_len, secondlen);
  1012. /* Tell device the write index *just past* this latest filled TFD */
  1013. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  1014. iwl_txq_update_write_ptr(trans, txq);
  1015. /*
  1016. * At this point the frame is "transmitted" successfully
  1017. * and we will get a TX status notification eventually,
  1018. * regardless of the value of ret. "ret" only indicates
  1019. * whether or not we should update the write pointer.
  1020. */
  1021. if (iwl_queue_space(q) < q->high_mark) {
  1022. if (wait_write_ptr) {
  1023. txq->need_update = 1;
  1024. iwl_txq_update_write_ptr(trans, txq);
  1025. } else {
  1026. iwl_stop_queue(trans, txq, "Queue is full");
  1027. }
  1028. }
  1029. return 0;
  1030. }
  1031. static void iwl_trans_pcie_kick_nic(struct iwl_trans *trans)
  1032. {
  1033. /* Remove all resets to allow NIC to operate */
  1034. iwl_write32(trans, CSR_RESET, 0);
  1035. }
  1036. static int iwl_trans_pcie_start_hw(struct iwl_trans *trans)
  1037. {
  1038. struct iwl_trans_pcie *trans_pcie =
  1039. IWL_TRANS_GET_PCIE_TRANS(trans);
  1040. int err;
  1041. trans_pcie->inta_mask = CSR_INI_SET_MASK;
  1042. if (!trans_pcie->irq_requested) {
  1043. tasklet_init(&trans_pcie->irq_tasklet, (void (*)(unsigned long))
  1044. iwl_irq_tasklet, (unsigned long)trans);
  1045. iwl_alloc_isr_ict(trans);
  1046. err = request_irq(trans->irq, iwl_isr_ict, IRQF_SHARED,
  1047. DRV_NAME, trans);
  1048. if (err) {
  1049. IWL_ERR(trans, "Error allocating IRQ %d\n",
  1050. trans->irq);
  1051. goto error;
  1052. }
  1053. INIT_WORK(&trans_pcie->rx_replenish, iwl_bg_rx_replenish);
  1054. trans_pcie->irq_requested = true;
  1055. }
  1056. err = iwl_prepare_card_hw(trans);
  1057. if (err) {
  1058. IWL_ERR(trans, "Error while preparing HW: %d", err);
  1059. goto error;
  1060. }
  1061. return err;
  1062. error:
  1063. iwl_free_isr_ict(trans);
  1064. tasklet_kill(&trans_pcie->irq_tasklet);
  1065. return err;
  1066. }
  1067. static int iwl_trans_pcie_reclaim(struct iwl_trans *trans, int sta_id, int tid,
  1068. int txq_id, int ssn, u32 status,
  1069. struct sk_buff_head *skbs)
  1070. {
  1071. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1072. struct iwl_tx_queue *txq = &trans_pcie->txq[txq_id];
  1073. /* n_bd is usually 256 => n_bd - 1 = 0xff */
  1074. int tfd_num = ssn & (txq->q.n_bd - 1);
  1075. int freed = 0;
  1076. txq->time_stamp = jiffies;
  1077. if (unlikely(txq_id >= IWLAGN_FIRST_AMPDU_QUEUE &&
  1078. txq_id != trans_pcie->agg_txq[sta_id][tid])) {
  1079. /*
  1080. * FIXME: this is a uCode bug which need to be addressed,
  1081. * log the information and return for now.
  1082. * Since it is can possibly happen very often and in order
  1083. * not to fill the syslog, don't use IWL_ERR or IWL_WARN
  1084. */
  1085. IWL_DEBUG_TX_QUEUES(trans, "Bad queue mapping txq_id %d, "
  1086. "agg_txq[sta_id[tid] %d", txq_id,
  1087. trans_pcie->agg_txq[sta_id][tid]);
  1088. return 1;
  1089. }
  1090. if (txq->q.read_ptr != tfd_num) {
  1091. IWL_DEBUG_TX_REPLY(trans, "[Q %d | AC %d] %d -> %d (%d)\n",
  1092. txq_id, iwl_get_queue_ac(txq), txq->q.read_ptr,
  1093. tfd_num, ssn);
  1094. freed = iwl_tx_queue_reclaim(trans, txq_id, tfd_num, skbs);
  1095. if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
  1096. (!txq->sched_retry ||
  1097. status != TX_STATUS_FAIL_PASSIVE_NO_RX))
  1098. iwl_wake_queue(trans, txq, "Packets reclaimed");
  1099. }
  1100. return 0;
  1101. }
  1102. static void iwl_trans_pcie_write8(struct iwl_trans *trans, u32 ofs, u8 val)
  1103. {
  1104. iowrite8(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  1105. }
  1106. static void iwl_trans_pcie_write32(struct iwl_trans *trans, u32 ofs, u32 val)
  1107. {
  1108. iowrite32(val, IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  1109. }
  1110. static u32 iwl_trans_pcie_read32(struct iwl_trans *trans, u32 ofs)
  1111. {
  1112. u32 val = ioread32(IWL_TRANS_GET_PCIE_TRANS(trans)->hw_base + ofs);
  1113. return val;
  1114. }
  1115. static void iwl_trans_pcie_free(struct iwl_trans *trans)
  1116. {
  1117. struct iwl_trans_pcie *trans_pcie =
  1118. IWL_TRANS_GET_PCIE_TRANS(trans);
  1119. iwl_calib_free_results(trans);
  1120. iwl_trans_pcie_tx_free(trans);
  1121. #ifndef CONFIG_IWLWIFI_IDI
  1122. iwl_trans_pcie_rx_free(trans);
  1123. #endif
  1124. if (trans_pcie->irq_requested == true) {
  1125. free_irq(trans->irq, trans);
  1126. iwl_free_isr_ict(trans);
  1127. }
  1128. pci_disable_msi(trans_pcie->pci_dev);
  1129. pci_iounmap(trans_pcie->pci_dev, trans_pcie->hw_base);
  1130. pci_release_regions(trans_pcie->pci_dev);
  1131. pci_disable_device(trans_pcie->pci_dev);
  1132. trans->shrd->trans = NULL;
  1133. kfree(trans);
  1134. }
  1135. #ifdef CONFIG_PM_SLEEP
  1136. static int iwl_trans_pcie_suspend(struct iwl_trans *trans)
  1137. {
  1138. /*
  1139. * This function is called when system goes into suspend state
  1140. * mac80211 will call iwlagn_mac_stop() from the mac80211 suspend
  1141. * function first but since iwlagn_mac_stop() has no knowledge of
  1142. * who the caller is,
  1143. * it will not call apm_ops.stop() to stop the DMA operation.
  1144. * Calling apm_ops.stop here to make sure we stop the DMA.
  1145. *
  1146. * But of course ... if we have configured WoWLAN then we did other
  1147. * things already :-)
  1148. */
  1149. if (!trans->shrd->wowlan) {
  1150. iwl_apm_stop(priv(trans));
  1151. } else {
  1152. iwl_disable_interrupts(trans);
  1153. iwl_clear_bit(trans, CSR_GP_CNTRL,
  1154. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  1155. }
  1156. return 0;
  1157. }
  1158. static int iwl_trans_pcie_resume(struct iwl_trans *trans)
  1159. {
  1160. bool hw_rfkill = false;
  1161. iwl_enable_interrupts(trans);
  1162. if (!(iwl_read32(trans, CSR_GP_CNTRL) &
  1163. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  1164. hw_rfkill = true;
  1165. if (hw_rfkill)
  1166. set_bit(STATUS_RF_KILL_HW, &trans->shrd->status);
  1167. else
  1168. clear_bit(STATUS_RF_KILL_HW, &trans->shrd->status);
  1169. iwl_set_hw_rfkill_state(priv(trans), hw_rfkill);
  1170. return 0;
  1171. }
  1172. #endif /* CONFIG_PM_SLEEP */
  1173. static void iwl_trans_pcie_wake_any_queue(struct iwl_trans *trans,
  1174. enum iwl_rxon_context_id ctx,
  1175. const char *msg)
  1176. {
  1177. u8 ac, txq_id;
  1178. struct iwl_trans_pcie *trans_pcie =
  1179. IWL_TRANS_GET_PCIE_TRANS(trans);
  1180. for (ac = 0; ac < AC_NUM; ac++) {
  1181. txq_id = trans_pcie->ac_to_queue[ctx][ac];
  1182. IWL_DEBUG_TX_QUEUES(trans, "Queue Status: Q[%d] %s\n",
  1183. ac,
  1184. (atomic_read(&trans_pcie->queue_stop_count[ac]) > 0)
  1185. ? "stopped" : "awake");
  1186. iwl_wake_queue(trans, &trans_pcie->txq[txq_id], msg);
  1187. }
  1188. }
  1189. static void iwl_trans_pcie_stop_queue(struct iwl_trans *trans, int txq_id,
  1190. const char *msg)
  1191. {
  1192. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1193. iwl_stop_queue(trans, &trans_pcie->txq[txq_id], msg);
  1194. }
  1195. #define IWL_FLUSH_WAIT_MS 2000
  1196. static int iwl_trans_pcie_wait_tx_queue_empty(struct iwl_trans *trans)
  1197. {
  1198. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1199. struct iwl_tx_queue *txq;
  1200. struct iwl_queue *q;
  1201. int cnt;
  1202. unsigned long now = jiffies;
  1203. int ret = 0;
  1204. /* waiting for all the tx frames complete might take a while */
  1205. for (cnt = 0; cnt < hw_params(trans).max_txq_num; cnt++) {
  1206. if (cnt == trans->shrd->cmd_queue)
  1207. continue;
  1208. txq = &trans_pcie->txq[cnt];
  1209. q = &txq->q;
  1210. while (q->read_ptr != q->write_ptr && !time_after(jiffies,
  1211. now + msecs_to_jiffies(IWL_FLUSH_WAIT_MS)))
  1212. msleep(1);
  1213. if (q->read_ptr != q->write_ptr) {
  1214. IWL_ERR(trans, "fail to flush all tx fifo queues\n");
  1215. ret = -ETIMEDOUT;
  1216. break;
  1217. }
  1218. }
  1219. return ret;
  1220. }
  1221. /*
  1222. * On every watchdog tick we check (latest) time stamp. If it does not
  1223. * change during timeout period and queue is not empty we reset firmware.
  1224. */
  1225. static int iwl_trans_pcie_check_stuck_queue(struct iwl_trans *trans, int cnt)
  1226. {
  1227. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1228. struct iwl_tx_queue *txq = &trans_pcie->txq[cnt];
  1229. struct iwl_queue *q = &txq->q;
  1230. unsigned long timeout;
  1231. if (q->read_ptr == q->write_ptr) {
  1232. txq->time_stamp = jiffies;
  1233. return 0;
  1234. }
  1235. timeout = txq->time_stamp +
  1236. msecs_to_jiffies(hw_params(trans).wd_timeout);
  1237. if (time_after(jiffies, timeout)) {
  1238. IWL_ERR(trans, "Queue %d stuck for %u ms.\n", q->id,
  1239. hw_params(trans).wd_timeout);
  1240. IWL_ERR(trans, "Current SW read_ptr %d write_ptr %d\n",
  1241. q->read_ptr, q->write_ptr);
  1242. IWL_ERR(trans, "Current HW read_ptr %d write_ptr %d\n",
  1243. iwl_read_prph(trans, SCD_QUEUE_RDPTR(cnt))
  1244. & (TFD_QUEUE_SIZE_MAX - 1),
  1245. iwl_read_prph(trans, SCD_QUEUE_WRPTR(cnt)));
  1246. return 1;
  1247. }
  1248. return 0;
  1249. }
  1250. static const char *get_fh_string(int cmd)
  1251. {
  1252. switch (cmd) {
  1253. IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  1254. IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  1255. IWL_CMD(FH_RSCSR_CHNL0_WPTR);
  1256. IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  1257. IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  1258. IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  1259. IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  1260. IWL_CMD(FH_TSSR_TX_STATUS_REG);
  1261. IWL_CMD(FH_TSSR_TX_ERROR_REG);
  1262. default:
  1263. return "UNKNOWN";
  1264. }
  1265. }
  1266. int iwl_dump_fh(struct iwl_trans *trans, char **buf, bool display)
  1267. {
  1268. int i;
  1269. #ifdef CONFIG_IWLWIFI_DEBUG
  1270. int pos = 0;
  1271. size_t bufsz = 0;
  1272. #endif
  1273. static const u32 fh_tbl[] = {
  1274. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  1275. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  1276. FH_RSCSR_CHNL0_WPTR,
  1277. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  1278. FH_MEM_RSSR_SHARED_CTRL_REG,
  1279. FH_MEM_RSSR_RX_STATUS_REG,
  1280. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  1281. FH_TSSR_TX_STATUS_REG,
  1282. FH_TSSR_TX_ERROR_REG
  1283. };
  1284. #ifdef CONFIG_IWLWIFI_DEBUG
  1285. if (display) {
  1286. bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  1287. *buf = kmalloc(bufsz, GFP_KERNEL);
  1288. if (!*buf)
  1289. return -ENOMEM;
  1290. pos += scnprintf(*buf + pos, bufsz - pos,
  1291. "FH register values:\n");
  1292. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1293. pos += scnprintf(*buf + pos, bufsz - pos,
  1294. " %34s: 0X%08x\n",
  1295. get_fh_string(fh_tbl[i]),
  1296. iwl_read_direct32(trans, fh_tbl[i]));
  1297. }
  1298. return pos;
  1299. }
  1300. #endif
  1301. IWL_ERR(trans, "FH register values:\n");
  1302. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1303. IWL_ERR(trans, " %34s: 0X%08x\n",
  1304. get_fh_string(fh_tbl[i]),
  1305. iwl_read_direct32(trans, fh_tbl[i]));
  1306. }
  1307. return 0;
  1308. }
  1309. static const char *get_csr_string(int cmd)
  1310. {
  1311. switch (cmd) {
  1312. IWL_CMD(CSR_HW_IF_CONFIG_REG);
  1313. IWL_CMD(CSR_INT_COALESCING);
  1314. IWL_CMD(CSR_INT);
  1315. IWL_CMD(CSR_INT_MASK);
  1316. IWL_CMD(CSR_FH_INT_STATUS);
  1317. IWL_CMD(CSR_GPIO_IN);
  1318. IWL_CMD(CSR_RESET);
  1319. IWL_CMD(CSR_GP_CNTRL);
  1320. IWL_CMD(CSR_HW_REV);
  1321. IWL_CMD(CSR_EEPROM_REG);
  1322. IWL_CMD(CSR_EEPROM_GP);
  1323. IWL_CMD(CSR_OTP_GP_REG);
  1324. IWL_CMD(CSR_GIO_REG);
  1325. IWL_CMD(CSR_GP_UCODE_REG);
  1326. IWL_CMD(CSR_GP_DRIVER_REG);
  1327. IWL_CMD(CSR_UCODE_DRV_GP1);
  1328. IWL_CMD(CSR_UCODE_DRV_GP2);
  1329. IWL_CMD(CSR_LED_REG);
  1330. IWL_CMD(CSR_DRAM_INT_TBL_REG);
  1331. IWL_CMD(CSR_GIO_CHICKEN_BITS);
  1332. IWL_CMD(CSR_ANA_PLL_CFG);
  1333. IWL_CMD(CSR_HW_REV_WA_REG);
  1334. IWL_CMD(CSR_DBG_HPET_MEM_REG);
  1335. default:
  1336. return "UNKNOWN";
  1337. }
  1338. }
  1339. void iwl_dump_csr(struct iwl_trans *trans)
  1340. {
  1341. int i;
  1342. static const u32 csr_tbl[] = {
  1343. CSR_HW_IF_CONFIG_REG,
  1344. CSR_INT_COALESCING,
  1345. CSR_INT,
  1346. CSR_INT_MASK,
  1347. CSR_FH_INT_STATUS,
  1348. CSR_GPIO_IN,
  1349. CSR_RESET,
  1350. CSR_GP_CNTRL,
  1351. CSR_HW_REV,
  1352. CSR_EEPROM_REG,
  1353. CSR_EEPROM_GP,
  1354. CSR_OTP_GP_REG,
  1355. CSR_GIO_REG,
  1356. CSR_GP_UCODE_REG,
  1357. CSR_GP_DRIVER_REG,
  1358. CSR_UCODE_DRV_GP1,
  1359. CSR_UCODE_DRV_GP2,
  1360. CSR_LED_REG,
  1361. CSR_DRAM_INT_TBL_REG,
  1362. CSR_GIO_CHICKEN_BITS,
  1363. CSR_ANA_PLL_CFG,
  1364. CSR_HW_REV_WA_REG,
  1365. CSR_DBG_HPET_MEM_REG
  1366. };
  1367. IWL_ERR(trans, "CSR values:\n");
  1368. IWL_ERR(trans, "(2nd byte of CSR_INT_COALESCING is "
  1369. "CSR_INT_PERIODIC_REG)\n");
  1370. for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
  1371. IWL_ERR(trans, " %25s: 0X%08x\n",
  1372. get_csr_string(csr_tbl[i]),
  1373. iwl_read32(trans, csr_tbl[i]));
  1374. }
  1375. }
  1376. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1377. /* create and remove of files */
  1378. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  1379. if (!debugfs_create_file(#name, mode, parent, trans, \
  1380. &iwl_dbgfs_##name##_ops)) \
  1381. return -ENOMEM; \
  1382. } while (0)
  1383. /* file operation */
  1384. #define DEBUGFS_READ_FUNC(name) \
  1385. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  1386. char __user *user_buf, \
  1387. size_t count, loff_t *ppos);
  1388. #define DEBUGFS_WRITE_FUNC(name) \
  1389. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  1390. const char __user *user_buf, \
  1391. size_t count, loff_t *ppos);
  1392. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  1393. {
  1394. file->private_data = inode->i_private;
  1395. return 0;
  1396. }
  1397. #define DEBUGFS_READ_FILE_OPS(name) \
  1398. DEBUGFS_READ_FUNC(name); \
  1399. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  1400. .read = iwl_dbgfs_##name##_read, \
  1401. .open = iwl_dbgfs_open_file_generic, \
  1402. .llseek = generic_file_llseek, \
  1403. };
  1404. #define DEBUGFS_WRITE_FILE_OPS(name) \
  1405. DEBUGFS_WRITE_FUNC(name); \
  1406. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  1407. .write = iwl_dbgfs_##name##_write, \
  1408. .open = iwl_dbgfs_open_file_generic, \
  1409. .llseek = generic_file_llseek, \
  1410. };
  1411. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  1412. DEBUGFS_READ_FUNC(name); \
  1413. DEBUGFS_WRITE_FUNC(name); \
  1414. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  1415. .write = iwl_dbgfs_##name##_write, \
  1416. .read = iwl_dbgfs_##name##_read, \
  1417. .open = iwl_dbgfs_open_file_generic, \
  1418. .llseek = generic_file_llseek, \
  1419. };
  1420. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  1421. char __user *user_buf,
  1422. size_t count, loff_t *ppos)
  1423. {
  1424. struct iwl_trans *trans = file->private_data;
  1425. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1426. struct iwl_tx_queue *txq;
  1427. struct iwl_queue *q;
  1428. char *buf;
  1429. int pos = 0;
  1430. int cnt;
  1431. int ret;
  1432. const size_t bufsz = sizeof(char) * 64 * hw_params(trans).max_txq_num;
  1433. if (!trans_pcie->txq) {
  1434. IWL_ERR(trans, "txq not ready\n");
  1435. return -EAGAIN;
  1436. }
  1437. buf = kzalloc(bufsz, GFP_KERNEL);
  1438. if (!buf)
  1439. return -ENOMEM;
  1440. for (cnt = 0; cnt < hw_params(trans).max_txq_num; cnt++) {
  1441. txq = &trans_pcie->txq[cnt];
  1442. q = &txq->q;
  1443. pos += scnprintf(buf + pos, bufsz - pos,
  1444. "hwq %.2d: read=%u write=%u stop=%d"
  1445. " swq_id=%#.2x (ac %d/hwq %d)\n",
  1446. cnt, q->read_ptr, q->write_ptr,
  1447. !!test_bit(cnt, trans_pcie->queue_stopped),
  1448. txq->swq_id, txq->swq_id & 3,
  1449. (txq->swq_id >> 2) & 0x1f);
  1450. if (cnt >= 4)
  1451. continue;
  1452. /* for the ACs, display the stop count too */
  1453. pos += scnprintf(buf + pos, bufsz - pos,
  1454. " stop-count: %d\n",
  1455. atomic_read(&trans_pcie->queue_stop_count[cnt]));
  1456. }
  1457. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1458. kfree(buf);
  1459. return ret;
  1460. }
  1461. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  1462. char __user *user_buf,
  1463. size_t count, loff_t *ppos) {
  1464. struct iwl_trans *trans = file->private_data;
  1465. struct iwl_trans_pcie *trans_pcie =
  1466. IWL_TRANS_GET_PCIE_TRANS(trans);
  1467. struct iwl_rx_queue *rxq = &trans_pcie->rxq;
  1468. char buf[256];
  1469. int pos = 0;
  1470. const size_t bufsz = sizeof(buf);
  1471. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  1472. rxq->read);
  1473. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  1474. rxq->write);
  1475. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  1476. rxq->free_count);
  1477. if (rxq->rb_stts) {
  1478. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  1479. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  1480. } else {
  1481. pos += scnprintf(buf + pos, bufsz - pos,
  1482. "closed_rb_num: Not Allocated\n");
  1483. }
  1484. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1485. }
  1486. static ssize_t iwl_dbgfs_log_event_read(struct file *file,
  1487. char __user *user_buf,
  1488. size_t count, loff_t *ppos)
  1489. {
  1490. struct iwl_trans *trans = file->private_data;
  1491. char *buf;
  1492. int pos = 0;
  1493. ssize_t ret = -ENOMEM;
  1494. ret = pos = iwl_dump_nic_event_log(trans, true, &buf, true);
  1495. if (buf) {
  1496. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1497. kfree(buf);
  1498. }
  1499. return ret;
  1500. }
  1501. static ssize_t iwl_dbgfs_log_event_write(struct file *file,
  1502. const char __user *user_buf,
  1503. size_t count, loff_t *ppos)
  1504. {
  1505. struct iwl_trans *trans = file->private_data;
  1506. u32 event_log_flag;
  1507. char buf[8];
  1508. int buf_size;
  1509. memset(buf, 0, sizeof(buf));
  1510. buf_size = min(count, sizeof(buf) - 1);
  1511. if (copy_from_user(buf, user_buf, buf_size))
  1512. return -EFAULT;
  1513. if (sscanf(buf, "%d", &event_log_flag) != 1)
  1514. return -EFAULT;
  1515. if (event_log_flag == 1)
  1516. iwl_dump_nic_event_log(trans, true, NULL, false);
  1517. return count;
  1518. }
  1519. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  1520. char __user *user_buf,
  1521. size_t count, loff_t *ppos) {
  1522. struct iwl_trans *trans = file->private_data;
  1523. struct iwl_trans_pcie *trans_pcie =
  1524. IWL_TRANS_GET_PCIE_TRANS(trans);
  1525. struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
  1526. int pos = 0;
  1527. char *buf;
  1528. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  1529. ssize_t ret;
  1530. buf = kzalloc(bufsz, GFP_KERNEL);
  1531. if (!buf) {
  1532. IWL_ERR(trans, "Can not allocate Buffer\n");
  1533. return -ENOMEM;
  1534. }
  1535. pos += scnprintf(buf + pos, bufsz - pos,
  1536. "Interrupt Statistics Report:\n");
  1537. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  1538. isr_stats->hw);
  1539. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  1540. isr_stats->sw);
  1541. if (isr_stats->sw || isr_stats->hw) {
  1542. pos += scnprintf(buf + pos, bufsz - pos,
  1543. "\tLast Restarting Code: 0x%X\n",
  1544. isr_stats->err_code);
  1545. }
  1546. #ifdef CONFIG_IWLWIFI_DEBUG
  1547. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  1548. isr_stats->sch);
  1549. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  1550. isr_stats->alive);
  1551. #endif
  1552. pos += scnprintf(buf + pos, bufsz - pos,
  1553. "HW RF KILL switch toggled:\t %u\n", isr_stats->rfkill);
  1554. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  1555. isr_stats->ctkill);
  1556. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  1557. isr_stats->wakeup);
  1558. pos += scnprintf(buf + pos, bufsz - pos,
  1559. "Rx command responses:\t\t %u\n", isr_stats->rx);
  1560. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  1561. isr_stats->tx);
  1562. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  1563. isr_stats->unhandled);
  1564. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1565. kfree(buf);
  1566. return ret;
  1567. }
  1568. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  1569. const char __user *user_buf,
  1570. size_t count, loff_t *ppos)
  1571. {
  1572. struct iwl_trans *trans = file->private_data;
  1573. struct iwl_trans_pcie *trans_pcie =
  1574. IWL_TRANS_GET_PCIE_TRANS(trans);
  1575. struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
  1576. char buf[8];
  1577. int buf_size;
  1578. u32 reset_flag;
  1579. memset(buf, 0, sizeof(buf));
  1580. buf_size = min(count, sizeof(buf) - 1);
  1581. if (copy_from_user(buf, user_buf, buf_size))
  1582. return -EFAULT;
  1583. if (sscanf(buf, "%x", &reset_flag) != 1)
  1584. return -EFAULT;
  1585. if (reset_flag == 0)
  1586. memset(isr_stats, 0, sizeof(*isr_stats));
  1587. return count;
  1588. }
  1589. static ssize_t iwl_dbgfs_csr_write(struct file *file,
  1590. const char __user *user_buf,
  1591. size_t count, loff_t *ppos)
  1592. {
  1593. struct iwl_trans *trans = file->private_data;
  1594. char buf[8];
  1595. int buf_size;
  1596. int csr;
  1597. memset(buf, 0, sizeof(buf));
  1598. buf_size = min(count, sizeof(buf) - 1);
  1599. if (copy_from_user(buf, user_buf, buf_size))
  1600. return -EFAULT;
  1601. if (sscanf(buf, "%d", &csr) != 1)
  1602. return -EFAULT;
  1603. iwl_dump_csr(trans);
  1604. return count;
  1605. }
  1606. static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
  1607. char __user *user_buf,
  1608. size_t count, loff_t *ppos)
  1609. {
  1610. struct iwl_trans *trans = file->private_data;
  1611. char *buf;
  1612. int pos = 0;
  1613. ssize_t ret = -EFAULT;
  1614. ret = pos = iwl_dump_fh(trans, &buf, true);
  1615. if (buf) {
  1616. ret = simple_read_from_buffer(user_buf,
  1617. count, ppos, buf, pos);
  1618. kfree(buf);
  1619. }
  1620. return ret;
  1621. }
  1622. DEBUGFS_READ_WRITE_FILE_OPS(log_event);
  1623. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  1624. DEBUGFS_READ_FILE_OPS(fh_reg);
  1625. DEBUGFS_READ_FILE_OPS(rx_queue);
  1626. DEBUGFS_READ_FILE_OPS(tx_queue);
  1627. DEBUGFS_WRITE_FILE_OPS(csr);
  1628. /*
  1629. * Create the debugfs files and directories
  1630. *
  1631. */
  1632. static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
  1633. struct dentry *dir)
  1634. {
  1635. DEBUGFS_ADD_FILE(rx_queue, dir, S_IRUSR);
  1636. DEBUGFS_ADD_FILE(tx_queue, dir, S_IRUSR);
  1637. DEBUGFS_ADD_FILE(log_event, dir, S_IWUSR | S_IRUSR);
  1638. DEBUGFS_ADD_FILE(interrupt, dir, S_IWUSR | S_IRUSR);
  1639. DEBUGFS_ADD_FILE(csr, dir, S_IWUSR);
  1640. DEBUGFS_ADD_FILE(fh_reg, dir, S_IRUSR);
  1641. return 0;
  1642. }
  1643. #else
  1644. static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
  1645. struct dentry *dir)
  1646. { return 0; }
  1647. #endif /*CONFIG_IWLWIFI_DEBUGFS */
  1648. const struct iwl_trans_ops trans_ops_pcie = {
  1649. .start_hw = iwl_trans_pcie_start_hw,
  1650. .fw_alive = iwl_trans_pcie_fw_alive,
  1651. .start_device = iwl_trans_pcie_start_device,
  1652. .stop_device = iwl_trans_pcie_stop_device,
  1653. .wake_any_queue = iwl_trans_pcie_wake_any_queue,
  1654. .send_cmd = iwl_trans_pcie_send_cmd,
  1655. .tx = iwl_trans_pcie_tx,
  1656. .reclaim = iwl_trans_pcie_reclaim,
  1657. .tx_agg_disable = iwl_trans_pcie_tx_agg_disable,
  1658. .tx_agg_alloc = iwl_trans_pcie_tx_agg_alloc,
  1659. .tx_agg_setup = iwl_trans_pcie_tx_agg_setup,
  1660. .kick_nic = iwl_trans_pcie_kick_nic,
  1661. .free = iwl_trans_pcie_free,
  1662. .stop_queue = iwl_trans_pcie_stop_queue,
  1663. .dbgfs_register = iwl_trans_pcie_dbgfs_register,
  1664. .wait_tx_queue_empty = iwl_trans_pcie_wait_tx_queue_empty,
  1665. .check_stuck_queue = iwl_trans_pcie_check_stuck_queue,
  1666. #ifdef CONFIG_PM_SLEEP
  1667. .suspend = iwl_trans_pcie_suspend,
  1668. .resume = iwl_trans_pcie_resume,
  1669. #endif
  1670. .write8 = iwl_trans_pcie_write8,
  1671. .write32 = iwl_trans_pcie_write32,
  1672. .read32 = iwl_trans_pcie_read32,
  1673. };
  1674. /* PCI registers */
  1675. #define PCI_CFG_RETRY_TIMEOUT 0x041
  1676. struct iwl_trans *iwl_trans_pcie_alloc(struct iwl_shared *shrd,
  1677. struct pci_dev *pdev,
  1678. const struct pci_device_id *ent)
  1679. {
  1680. struct iwl_trans_pcie *trans_pcie;
  1681. struct iwl_trans *trans;
  1682. u16 pci_cmd;
  1683. int err;
  1684. trans = kzalloc(sizeof(struct iwl_trans) +
  1685. sizeof(struct iwl_trans_pcie), GFP_KERNEL);
  1686. if (WARN_ON(!trans))
  1687. return NULL;
  1688. trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  1689. trans->ops = &trans_ops_pcie;
  1690. trans->shrd = shrd;
  1691. trans_pcie->trans = trans;
  1692. spin_lock_init(&trans->hcmd_lock);
  1693. /* W/A - seems to solve weird behavior. We need to remove this if we
  1694. * don't want to stay in L1 all the time. This wastes a lot of power */
  1695. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  1696. PCIE_LINK_STATE_CLKPM);
  1697. if (pci_enable_device(pdev)) {
  1698. err = -ENODEV;
  1699. goto out_no_pci;
  1700. }
  1701. pci_set_master(pdev);
  1702. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  1703. if (!err)
  1704. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  1705. if (err) {
  1706. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1707. if (!err)
  1708. err = pci_set_consistent_dma_mask(pdev,
  1709. DMA_BIT_MASK(32));
  1710. /* both attempts failed: */
  1711. if (err) {
  1712. dev_printk(KERN_ERR, &pdev->dev,
  1713. "No suitable DMA available.\n");
  1714. goto out_pci_disable_device;
  1715. }
  1716. }
  1717. err = pci_request_regions(pdev, DRV_NAME);
  1718. if (err) {
  1719. dev_printk(KERN_ERR, &pdev->dev, "pci_request_regions failed");
  1720. goto out_pci_disable_device;
  1721. }
  1722. trans_pcie->hw_base = pci_iomap(pdev, 0, 0);
  1723. if (!trans_pcie->hw_base) {
  1724. dev_printk(KERN_ERR, &pdev->dev, "pci_iomap failed");
  1725. err = -ENODEV;
  1726. goto out_pci_release_regions;
  1727. }
  1728. dev_printk(KERN_INFO, &pdev->dev,
  1729. "pci_resource_len = 0x%08llx\n",
  1730. (unsigned long long) pci_resource_len(pdev, 0));
  1731. dev_printk(KERN_INFO, &pdev->dev,
  1732. "pci_resource_base = %p\n", trans_pcie->hw_base);
  1733. dev_printk(KERN_INFO, &pdev->dev,
  1734. "HW Revision ID = 0x%X\n", pdev->revision);
  1735. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  1736. * PCI Tx retries from interfering with C3 CPU state */
  1737. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  1738. err = pci_enable_msi(pdev);
  1739. if (err)
  1740. dev_printk(KERN_ERR, &pdev->dev,
  1741. "pci_enable_msi failed(0X%x)", err);
  1742. trans->dev = &pdev->dev;
  1743. trans->irq = pdev->irq;
  1744. trans_pcie->pci_dev = pdev;
  1745. /* TODO: Move this away, not needed if not MSI */
  1746. /* enable rfkill interrupt: hw bug w/a */
  1747. pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
  1748. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  1749. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  1750. pci_write_config_word(pdev, PCI_COMMAND, pci_cmd);
  1751. }
  1752. return trans;
  1753. out_pci_release_regions:
  1754. pci_release_regions(pdev);
  1755. out_pci_disable_device:
  1756. pci_disable_device(pdev);
  1757. out_no_pci:
  1758. kfree(trans);
  1759. return NULL;
  1760. }