iwl-agn-ict.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 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->bus.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. /* allocate shrared data table */
  56. priv->_agn.ict_tbl_vir =
  57. dma_alloc_coherent(priv->bus.dev,
  58. (sizeof(u32) * ICT_COUNT) + PAGE_SIZE,
  59. &priv->_agn.ict_tbl_dma, GFP_KERNEL);
  60. if (!priv->_agn.ict_tbl_vir)
  61. return -ENOMEM;
  62. /* align table to PAGE_SIZE boundary */
  63. priv->_agn.aligned_ict_tbl_dma = ALIGN(priv->_agn.ict_tbl_dma, PAGE_SIZE);
  64. IWL_DEBUG_ISR(priv, "ict dma addr %Lx dma aligned %Lx diff %d\n",
  65. (unsigned long long)priv->_agn.ict_tbl_dma,
  66. (unsigned long long)priv->_agn.aligned_ict_tbl_dma,
  67. (int)(priv->_agn.aligned_ict_tbl_dma - priv->_agn.ict_tbl_dma));
  68. priv->_agn.ict_tbl = priv->_agn.ict_tbl_vir +
  69. (priv->_agn.aligned_ict_tbl_dma - priv->_agn.ict_tbl_dma);
  70. IWL_DEBUG_ISR(priv, "ict vir addr %p vir aligned %p diff %d\n",
  71. priv->_agn.ict_tbl, priv->_agn.ict_tbl_vir,
  72. (int)(priv->_agn.aligned_ict_tbl_dma - priv->_agn.ict_tbl_dma));
  73. /* reset table and index to all 0 */
  74. memset(priv->_agn.ict_tbl_vir,0, (sizeof(u32) * ICT_COUNT) + PAGE_SIZE);
  75. priv->_agn.ict_index = 0;
  76. /* add periodic RX interrupt */
  77. priv->inta_mask |= CSR_INT_BIT_RX_PERIODIC;
  78. return 0;
  79. }
  80. /* Device is going up inform it about using ICT interrupt table,
  81. * also we need to tell the driver to start using ICT interrupt.
  82. */
  83. int iwl_reset_ict(struct iwl_priv *priv)
  84. {
  85. u32 val;
  86. unsigned long flags;
  87. if (!priv->_agn.ict_tbl_vir)
  88. return 0;
  89. spin_lock_irqsave(&priv->lock, flags);
  90. iwl_disable_interrupts(priv);
  91. memset(&priv->_agn.ict_tbl[0], 0, sizeof(u32) * ICT_COUNT);
  92. val = priv->_agn.aligned_ict_tbl_dma >> PAGE_SHIFT;
  93. val |= CSR_DRAM_INT_TBL_ENABLE;
  94. val |= CSR_DRAM_INIT_TBL_WRAP_CHECK;
  95. IWL_DEBUG_ISR(priv, "CSR_DRAM_INT_TBL_REG =0x%X "
  96. "aligned dma address %Lx\n",
  97. val, (unsigned long long)priv->_agn.aligned_ict_tbl_dma);
  98. iwl_write32(priv, CSR_DRAM_INT_TBL_REG, val);
  99. priv->_agn.use_ict = true;
  100. priv->_agn.ict_index = 0;
  101. iwl_write32(priv, CSR_INT, priv->inta_mask);
  102. iwl_enable_interrupts(priv);
  103. spin_unlock_irqrestore(&priv->lock, flags);
  104. return 0;
  105. }
  106. /* Device is going down disable ict interrupt usage */
  107. void iwl_disable_ict(struct iwl_priv *priv)
  108. {
  109. unsigned long flags;
  110. spin_lock_irqsave(&priv->lock, flags);
  111. priv->_agn.use_ict = false;
  112. spin_unlock_irqrestore(&priv->lock, flags);
  113. }
  114. static irqreturn_t iwl_isr(int irq, void *data)
  115. {
  116. struct iwl_priv *priv = data;
  117. u32 inta, inta_mask;
  118. unsigned long flags;
  119. #ifdef CONFIG_IWLWIFI_DEBUG
  120. u32 inta_fh;
  121. #endif
  122. if (!priv)
  123. return IRQ_NONE;
  124. spin_lock_irqsave(&priv->lock, flags);
  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_irqrestore(&priv->lock, flags);
  161. return IRQ_HANDLED;
  162. none:
  163. /* re-enable interrupts here since we don't have anything to service. */
  164. /* only Re-enable if disabled 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_irqrestore(&priv->lock, flags);
  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. unsigned long flags;
  184. if (!priv)
  185. return IRQ_NONE;
  186. /* dram interrupt table not set yet,
  187. * use legacy interrupt.
  188. */
  189. if (!priv->_agn.use_ict)
  190. return iwl_isr(irq, data);
  191. spin_lock_irqsave(&priv->lock, flags);
  192. /* Disable (but don't clear!) interrupts here to avoid
  193. * back-to-back ISRs and sporadic interrupts from our NIC.
  194. * If we have something to service, the tasklet will re-enable ints.
  195. * If we *don't* have something, we'll re-enable before leaving here.
  196. */
  197. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  198. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  199. /* Ignore interrupt if there's nothing in NIC to service.
  200. * This may be due to IRQ shared with another device,
  201. * or due to sporadic interrupts thrown from our NIC. */
  202. if (!priv->_agn.ict_tbl[priv->_agn.ict_index]) {
  203. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
  204. goto none;
  205. }
  206. /* read all entries that not 0 start with ict_index */
  207. while (priv->_agn.ict_tbl[priv->_agn.ict_index]) {
  208. val |= le32_to_cpu(priv->_agn.ict_tbl[priv->_agn.ict_index]);
  209. IWL_DEBUG_ISR(priv, "ICT index %d value 0x%08X\n",
  210. priv->_agn.ict_index,
  211. le32_to_cpu(priv->_agn.ict_tbl[priv->_agn.ict_index]));
  212. priv->_agn.ict_tbl[priv->_agn.ict_index] = 0;
  213. priv->_agn.ict_index = iwl_queue_inc_wrap(priv->_agn.ict_index,
  214. ICT_COUNT);
  215. }
  216. /* We should not get this value, just ignore it. */
  217. if (val == 0xffffffff)
  218. val = 0;
  219. /*
  220. * this is a w/a for a h/w bug. the h/w bug may cause the Rx bit
  221. * (bit 15 before shifting it to 31) to clear when using interrupt
  222. * coalescing. fortunately, bits 18 and 19 stay set when this happens
  223. * so we use them to decide on the real state of the Rx bit.
  224. * In order words, bit 15 is set if bit 18 or bit 19 are set.
  225. */
  226. if (val & 0xC0000)
  227. val |= 0x8000;
  228. inta = (0xff & val) | ((0xff00 & val) << 16);
  229. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n",
  230. inta, inta_mask, val);
  231. inta &= priv->inta_mask;
  232. priv->_agn.inta |= inta;
  233. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  234. if (likely(inta))
  235. tasklet_schedule(&priv->irq_tasklet);
  236. else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta) {
  237. /* Allow interrupt if was disabled by this handler and
  238. * no tasklet was schedules, We should not enable interrupt,
  239. * tasklet will enable it.
  240. */
  241. iwl_enable_interrupts(priv);
  242. }
  243. spin_unlock_irqrestore(&priv->lock, flags);
  244. return IRQ_HANDLED;
  245. none:
  246. /* re-enable interrupts here since we don't have anything to service.
  247. * only Re-enable if disabled by irq.
  248. */
  249. if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta)
  250. iwl_enable_interrupts(priv);
  251. spin_unlock_irqrestore(&priv->lock, flags);
  252. return IRQ_NONE;
  253. }