iwl-trans.c 46 KB

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