iwl-agn-ict.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. #ifdef CONFIG_IWLWIFI_DEBUG
  120. u32 inta_fh;
  121. #endif
  122. if (!priv)
  123. return IRQ_NONE;
  124. spin_lock(&priv->lock);
  125. /* Disable (but don't clear!) interrupts here to avoid
  126. * back-to-back ISRs and sporadic interrupts from our NIC.
  127. * If we have something to service, the tasklet will re-enable ints.
  128. * If we *don't* have something, we'll re-enable before leaving here. */
  129. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  130. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  131. /* Discover which interrupts are active/pending */
  132. inta = iwl_read32(priv, CSR_INT);
  133. /* Ignore interrupt if there's nothing in NIC to service.
  134. * This may be due to IRQ shared with another device,
  135. * or due to sporadic interrupts thrown from our NIC. */
  136. if (!inta) {
  137. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
  138. goto none;
  139. }
  140. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  141. /* Hardware disappeared. It might have already raised
  142. * an interrupt */
  143. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  144. goto unplugged;
  145. }
  146. #ifdef CONFIG_IWLWIFI_DEBUG
  147. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  148. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  149. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, "
  150. "fh 0x%08x\n", inta, inta_mask, inta_fh);
  151. }
  152. #endif
  153. priv->_agn.inta |= inta;
  154. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  155. if (likely(inta))
  156. tasklet_schedule(&priv->irq_tasklet);
  157. else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta)
  158. iwl_enable_interrupts(priv);
  159. unplugged:
  160. spin_unlock(&priv->lock);
  161. return IRQ_HANDLED;
  162. none:
  163. /* re-enable interrupts here since we don't have anything to service. */
  164. /* only Re-enable if diabled by irq and no schedules tasklet. */
  165. if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta)
  166. iwl_enable_interrupts(priv);
  167. spin_unlock(&priv->lock);
  168. return IRQ_NONE;
  169. }
  170. /* interrupt handler using ict table, with this interrupt driver will
  171. * stop using INTA register to get device's interrupt, reading this register
  172. * is expensive, device will write interrupts in ICT dram table, increment
  173. * index then will fire interrupt to driver, driver will OR all ICT table
  174. * entries from current index up to table entry with 0 value. the result is
  175. * the interrupt we need to service, driver will set the entries back to 0 and
  176. * set index.
  177. */
  178. irqreturn_t iwl_isr_ict(int irq, void *data)
  179. {
  180. struct iwl_priv *priv = data;
  181. u32 inta, inta_mask;
  182. u32 val = 0;
  183. if (!priv)
  184. return IRQ_NONE;
  185. /* dram interrupt table not set yet,
  186. * use legacy interrupt.
  187. */
  188. if (!priv->_agn.use_ict)
  189. return iwl_isr(irq, data);
  190. spin_lock(&priv->lock);
  191. /* Disable (but don't clear!) interrupts here to avoid
  192. * back-to-back ISRs and sporadic interrupts from our NIC.
  193. * If we have something to service, the tasklet will re-enable ints.
  194. * If we *don't* have something, we'll re-enable before leaving here.
  195. */
  196. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  197. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  198. /* Ignore interrupt if there's nothing in NIC to service.
  199. * This may be due to IRQ shared with another device,
  200. * or due to sporadic interrupts thrown from our NIC. */
  201. if (!priv->_agn.ict_tbl[priv->_agn.ict_index]) {
  202. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
  203. goto none;
  204. }
  205. /* read all entries that not 0 start with ict_index */
  206. while (priv->_agn.ict_tbl[priv->_agn.ict_index]) {
  207. val |= le32_to_cpu(priv->_agn.ict_tbl[priv->_agn.ict_index]);
  208. IWL_DEBUG_ISR(priv, "ICT index %d value 0x%08X\n",
  209. priv->_agn.ict_index,
  210. le32_to_cpu(priv->_agn.ict_tbl[priv->_agn.ict_index]));
  211. priv->_agn.ict_tbl[priv->_agn.ict_index] = 0;
  212. priv->_agn.ict_index = iwl_queue_inc_wrap(priv->_agn.ict_index,
  213. ICT_COUNT);
  214. }
  215. /* We should not get this value, just ignore it. */
  216. if (val == 0xffffffff)
  217. val = 0;
  218. /*
  219. * this is a w/a for a h/w bug. the h/w bug may cause the Rx bit
  220. * (bit 15 before shifting it to 31) to clear when using interrupt
  221. * coalescing. fortunately, bits 18 and 19 stay set when this happens
  222. * so we use them to decide on the real state of the Rx bit.
  223. * In order words, bit 15 is set if bit 18 or bit 19 are set.
  224. */
  225. if (val & 0xC0000)
  226. val |= 0x8000;
  227. inta = (0xff & val) | ((0xff00 & val) << 16);
  228. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n",
  229. inta, inta_mask, val);
  230. inta &= priv->inta_mask;
  231. priv->_agn.inta |= inta;
  232. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  233. if (likely(inta))
  234. tasklet_schedule(&priv->irq_tasklet);
  235. else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta) {
  236. /* Allow interrupt if was disabled by this handler and
  237. * no tasklet was schedules, We should not enable interrupt,
  238. * tasklet will enable it.
  239. */
  240. iwl_enable_interrupts(priv);
  241. }
  242. spin_unlock(&priv->lock);
  243. return IRQ_HANDLED;
  244. none:
  245. /* re-enable interrupts here since we don't have anything to service.
  246. * only Re-enable if disabled by irq.
  247. */
  248. if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta)
  249. iwl_enable_interrupts(priv);
  250. spin_unlock(&priv->lock);
  251. return IRQ_NONE;
  252. }