iwl-trans.c 57 KB

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