iwl-agn-ict.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *****************************************************************************/
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/sched.h>
  32. #include <linux/gfp.h>
  33. #include <net/mac80211.h>
  34. #include "iwl-dev.h"
  35. #include "iwl-core.h"
  36. #include "iwl-agn.h"
  37. #include "iwl-helpers.h"
  38. #define ICT_COUNT (PAGE_SIZE/sizeof(u32))
  39. /* Free dram table */
  40. void iwl_free_isr_ict(struct iwl_priv *priv)
  41. {
  42. if (priv->_agn.ict_tbl_vir) {
  43. dma_free_coherent(&priv->pci_dev->dev,
  44. (sizeof(u32) * ICT_COUNT) + PAGE_SIZE,
  45. priv->_agn.ict_tbl_vir,
  46. priv->_agn.ict_tbl_dma);
  47. priv->_agn.ict_tbl_vir = NULL;
  48. }
  49. }
  50. /* allocate dram shared table it is a PAGE_SIZE aligned
  51. * also reset all data related to ICT table interrupt.
  52. */
  53. int iwl_alloc_isr_ict(struct iwl_priv *priv)
  54. {
  55. if (priv->cfg->base_params->use_isr_legacy)
  56. return 0;
  57. /* allocate shrared data table */
  58. priv->_agn.ict_tbl_vir =
  59. dma_alloc_coherent(&priv->pci_dev->dev,
  60. (sizeof(u32) * ICT_COUNT) + PAGE_SIZE,
  61. &priv->_agn.ict_tbl_dma, GFP_KERNEL);
  62. if (!priv->_agn.ict_tbl_vir)
  63. return -ENOMEM;
  64. /* align table to PAGE_SIZE boundry */
  65. priv->_agn.aligned_ict_tbl_dma = ALIGN(priv->_agn.ict_tbl_dma, PAGE_SIZE);
  66. IWL_DEBUG_ISR(priv, "ict dma addr %Lx dma aligned %Lx diff %d\n",
  67. (unsigned long long)priv->_agn.ict_tbl_dma,
  68. (unsigned long long)priv->_agn.aligned_ict_tbl_dma,
  69. (int)(priv->_agn.aligned_ict_tbl_dma - priv->_agn.ict_tbl_dma));
  70. priv->_agn.ict_tbl = priv->_agn.ict_tbl_vir +
  71. (priv->_agn.aligned_ict_tbl_dma - priv->_agn.ict_tbl_dma);
  72. IWL_DEBUG_ISR(priv, "ict vir addr %p vir aligned %p diff %d\n",
  73. priv->_agn.ict_tbl, priv->_agn.ict_tbl_vir,
  74. (int)(priv->_agn.aligned_ict_tbl_dma - priv->_agn.ict_tbl_dma));
  75. /* reset table and index to all 0 */
  76. memset(priv->_agn.ict_tbl_vir,0, (sizeof(u32) * ICT_COUNT) + PAGE_SIZE);
  77. priv->_agn.ict_index = 0;
  78. /* add periodic RX interrupt */
  79. priv->inta_mask |= CSR_INT_BIT_RX_PERIODIC;
  80. return 0;
  81. }
  82. /* Device is going up inform it about using ICT interrupt table,
  83. * also we need to tell the driver to start using ICT interrupt.
  84. */
  85. int iwl_reset_ict(struct iwl_priv *priv)
  86. {
  87. u32 val;
  88. unsigned long flags;
  89. if (!priv->_agn.ict_tbl_vir)
  90. return 0;
  91. spin_lock_irqsave(&priv->lock, flags);
  92. iwl_disable_interrupts(priv);
  93. memset(&priv->_agn.ict_tbl[0], 0, sizeof(u32) * ICT_COUNT);
  94. val = priv->_agn.aligned_ict_tbl_dma >> PAGE_SHIFT;
  95. val |= CSR_DRAM_INT_TBL_ENABLE;
  96. val |= CSR_DRAM_INIT_TBL_WRAP_CHECK;
  97. IWL_DEBUG_ISR(priv, "CSR_DRAM_INT_TBL_REG =0x%X "
  98. "aligned dma address %Lx\n",
  99. val, (unsigned long long)priv->_agn.aligned_ict_tbl_dma);
  100. iwl_write32(priv, CSR_DRAM_INT_TBL_REG, val);
  101. priv->_agn.use_ict = true;
  102. priv->_agn.ict_index = 0;
  103. iwl_write32(priv, CSR_INT, priv->inta_mask);
  104. iwl_enable_interrupts(priv);
  105. spin_unlock_irqrestore(&priv->lock, flags);
  106. return 0;
  107. }
  108. /* Device is going down disable ict interrupt usage */
  109. void iwl_disable_ict(struct iwl_priv *priv)
  110. {
  111. unsigned long flags;
  112. spin_lock_irqsave(&priv->lock, flags);
  113. priv->_agn.use_ict = false;
  114. spin_unlock_irqrestore(&priv->lock, flags);
  115. }
  116. static irqreturn_t iwl_isr(int irq, void *data)
  117. {
  118. struct iwl_priv *priv = data;
  119. u32 inta, inta_mask;
  120. unsigned long flags;
  121. #ifdef CONFIG_IWLWIFI_DEBUG
  122. u32 inta_fh;
  123. #endif
  124. if (!priv)
  125. return IRQ_NONE;
  126. spin_lock_irqsave(&priv->lock, flags);
  127. /* Disable (but don't clear!) interrupts here to avoid
  128. * back-to-back ISRs and sporadic interrupts from our NIC.
  129. * If we have something to service, the tasklet will re-enable ints.
  130. * If we *don't* have something, we'll re-enable before leaving here. */
  131. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  132. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  133. /* Discover which interrupts are active/pending */
  134. inta = iwl_read32(priv, CSR_INT);
  135. /* Ignore interrupt if there's nothing in NIC to service.
  136. * This may be due to IRQ shared with another device,
  137. * or due to sporadic interrupts thrown from our NIC. */
  138. if (!inta) {
  139. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
  140. goto none;
  141. }
  142. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  143. /* Hardware disappeared. It might have already raised
  144. * an interrupt */
  145. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  146. goto unplugged;
  147. }
  148. #ifdef CONFIG_IWLWIFI_DEBUG
  149. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  150. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  151. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, "
  152. "fh 0x%08x\n", inta, inta_mask, inta_fh);
  153. }
  154. #endif
  155. priv->_agn.inta |= inta;
  156. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  157. if (likely(inta))
  158. tasklet_schedule(&priv->irq_tasklet);
  159. else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta)
  160. iwl_enable_interrupts(priv);
  161. unplugged:
  162. spin_unlock_irqrestore(&priv->lock, flags);
  163. return IRQ_HANDLED;
  164. none:
  165. /* re-enable interrupts here since we don't have anything to service. */
  166. /* only Re-enable if diabled by irq and no schedules tasklet. */
  167. if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta)
  168. iwl_enable_interrupts(priv);
  169. spin_unlock_irqrestore(&priv->lock, flags);
  170. return IRQ_NONE;
  171. }
  172. /* interrupt handler using ict table, with this interrupt driver will
  173. * stop using INTA register to get device's interrupt, reading this register
  174. * is expensive, device will write interrupts in ICT dram table, increment
  175. * index then will fire interrupt to driver, driver will OR all ICT table
  176. * entries from current index up to table entry with 0 value. the result is
  177. * the interrupt we need to service, driver will set the entries back to 0 and
  178. * set index.
  179. */
  180. irqreturn_t iwl_isr_ict(int irq, void *data)
  181. {
  182. struct iwl_priv *priv = data;
  183. u32 inta, inta_mask;
  184. u32 val = 0;
  185. unsigned long flags;
  186. if (!priv)
  187. return IRQ_NONE;
  188. /* dram interrupt table not set yet,
  189. * use legacy interrupt.
  190. */
  191. if (!priv->_agn.use_ict)
  192. return iwl_isr(irq, data);
  193. spin_lock_irqsave(&priv->lock, flags);
  194. /* Disable (but don't clear!) interrupts here to avoid
  195. * back-to-back ISRs and sporadic interrupts from our NIC.
  196. * If we have something to service, the tasklet will re-enable ints.
  197. * If we *don't* have something, we'll re-enable before leaving here.
  198. */
  199. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  200. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  201. /* Ignore interrupt if there's nothing in NIC to service.
  202. * This may be due to IRQ shared with another device,
  203. * or due to sporadic interrupts thrown from our NIC. */
  204. if (!priv->_agn.ict_tbl[priv->_agn.ict_index]) {
  205. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
  206. goto none;
  207. }
  208. /* read all entries that not 0 start with ict_index */
  209. while (priv->_agn.ict_tbl[priv->_agn.ict_index]) {
  210. val |= le32_to_cpu(priv->_agn.ict_tbl[priv->_agn.ict_index]);
  211. IWL_DEBUG_ISR(priv, "ICT index %d value 0x%08X\n",
  212. priv->_agn.ict_index,
  213. le32_to_cpu(priv->_agn.ict_tbl[priv->_agn.ict_index]));
  214. priv->_agn.ict_tbl[priv->_agn.ict_index] = 0;
  215. priv->_agn.ict_index = iwl_queue_inc_wrap(priv->_agn.ict_index,
  216. ICT_COUNT);
  217. }
  218. /* We should not get this value, just ignore it. */
  219. if (val == 0xffffffff)
  220. val = 0;
  221. /*
  222. * this is a w/a for a h/w bug. the h/w bug may cause the Rx bit
  223. * (bit 15 before shifting it to 31) to clear when using interrupt
  224. * coalescing. fortunately, bits 18 and 19 stay set when this happens
  225. * so we use them to decide on the real state of the Rx bit.
  226. * In order words, bit 15 is set if bit 18 or bit 19 are set.
  227. */
  228. if (val & 0xC0000)
  229. val |= 0x8000;
  230. inta = (0xff & val) | ((0xff00 & val) << 16);
  231. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n",
  232. inta, inta_mask, val);
  233. inta &= priv->inta_mask;
  234. priv->_agn.inta |= inta;
  235. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  236. if (likely(inta))
  237. tasklet_schedule(&priv->irq_tasklet);
  238. else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta) {
  239. /* Allow interrupt if was disabled by this handler and
  240. * no tasklet was schedules, We should not enable interrupt,
  241. * tasklet will enable it.
  242. */
  243. iwl_enable_interrupts(priv);
  244. }
  245. spin_unlock_irqrestore(&priv->lock, flags);
  246. return IRQ_HANDLED;
  247. none:
  248. /* re-enable interrupts here since we don't have anything to service.
  249. * only Re-enable if disabled by irq.
  250. */
  251. if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta)
  252. iwl_enable_interrupts(priv);
  253. spin_unlock_irqrestore(&priv->lock, flags);
  254. return IRQ_NONE;
  255. }