iwl-agn-ict.c 9.4 KB

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