blob: 4c5395eae95613d4784293eb0feee56a1d0f6502 [file] [log] [blame]
Johannes Berga1175122010-01-21 06:21:10 -08001/******************************************************************************
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
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/etherdevice.h>
32#include <linux/sched.h>
33#include <net/mac80211.h>
34
35#include "iwl-dev.h"
36#include "iwl-core.h"
37#include "iwl-agn.h"
38#include "iwl-helpers.h"
39
40#define ICT_COUNT (PAGE_SIZE/sizeof(u32))
41
42/* Free dram table */
43void iwl_free_isr_ict(struct iwl_priv *priv)
44{
Johannes Berga4c8b2a62010-01-21 06:25:54 -080045 if (priv->_agn.ict_tbl_vir) {
Johannes Berga1175122010-01-21 06:21:10 -080046 dma_free_coherent(&priv->pci_dev->dev,
47 (sizeof(u32) * ICT_COUNT) + PAGE_SIZE,
Johannes Berga4c8b2a62010-01-21 06:25:54 -080048 priv->_agn.ict_tbl_vir,
49 priv->_agn.ict_tbl_dma);
50 priv->_agn.ict_tbl_vir = NULL;
Johannes Berga1175122010-01-21 06:21:10 -080051 }
52}
53
54
55/* allocate dram shared table it is a PAGE_SIZE aligned
56 * also reset all data related to ICT table interrupt.
57 */
58int iwl_alloc_isr_ict(struct iwl_priv *priv)
59{
60
61 if (priv->cfg->use_isr_legacy)
62 return 0;
63 /* allocate shrared data table */
Johannes Berga4c8b2a62010-01-21 06:25:54 -080064 priv->_agn.ict_tbl_vir =
65 dma_alloc_coherent(&priv->pci_dev->dev,
66 (sizeof(u32) * ICT_COUNT) + PAGE_SIZE,
67 &priv->_agn.ict_tbl_dma, GFP_KERNEL);
68 if (!priv->_agn.ict_tbl_vir)
Johannes Berga1175122010-01-21 06:21:10 -080069 return -ENOMEM;
70
71 /* align table to PAGE_SIZE boundry */
Johannes Berga4c8b2a62010-01-21 06:25:54 -080072 priv->_agn.aligned_ict_tbl_dma = ALIGN(priv->_agn.ict_tbl_dma, PAGE_SIZE);
Johannes Berga1175122010-01-21 06:21:10 -080073
74 IWL_DEBUG_ISR(priv, "ict dma addr %Lx dma aligned %Lx diff %d\n",
Johannes Berga4c8b2a62010-01-21 06:25:54 -080075 (unsigned long long)priv->_agn.ict_tbl_dma,
76 (unsigned long long)priv->_agn.aligned_ict_tbl_dma,
77 (int)(priv->_agn.aligned_ict_tbl_dma - priv->_agn.ict_tbl_dma));
Johannes Berga1175122010-01-21 06:21:10 -080078
Johannes Berga4c8b2a62010-01-21 06:25:54 -080079 priv->_agn.ict_tbl = priv->_agn.ict_tbl_vir +
80 (priv->_agn.aligned_ict_tbl_dma - priv->_agn.ict_tbl_dma);
Johannes Berga1175122010-01-21 06:21:10 -080081
82 IWL_DEBUG_ISR(priv, "ict vir addr %p vir aligned %p diff %d\n",
Johannes Berga4c8b2a62010-01-21 06:25:54 -080083 priv->_agn.ict_tbl, priv->_agn.ict_tbl_vir,
84 (int)(priv->_agn.aligned_ict_tbl_dma - priv->_agn.ict_tbl_dma));
Johannes Berga1175122010-01-21 06:21:10 -080085
86 /* reset table and index to all 0 */
Johannes Berga4c8b2a62010-01-21 06:25:54 -080087 memset(priv->_agn.ict_tbl_vir,0, (sizeof(u32) * ICT_COUNT) + PAGE_SIZE);
88 priv->_agn.ict_index = 0;
Johannes Berga1175122010-01-21 06:21:10 -080089
90 /* add periodic RX interrupt */
91 priv->inta_mask |= CSR_INT_BIT_RX_PERIODIC;
92 return 0;
93}
94
95/* Device is going up inform it about using ICT interrupt table,
96 * also we need to tell the driver to start using ICT interrupt.
97 */
98int iwl_reset_ict(struct iwl_priv *priv)
99{
100 u32 val;
101 unsigned long flags;
102
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800103 if (!priv->_agn.ict_tbl_vir)
Johannes Berga1175122010-01-21 06:21:10 -0800104 return 0;
105
106 spin_lock_irqsave(&priv->lock, flags);
107 iwl_disable_interrupts(priv);
108
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800109 memset(&priv->_agn.ict_tbl[0], 0, sizeof(u32) * ICT_COUNT);
Johannes Berga1175122010-01-21 06:21:10 -0800110
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800111 val = priv->_agn.aligned_ict_tbl_dma >> PAGE_SHIFT;
Johannes Berga1175122010-01-21 06:21:10 -0800112
113 val |= CSR_DRAM_INT_TBL_ENABLE;
114 val |= CSR_DRAM_INIT_TBL_WRAP_CHECK;
115
116 IWL_DEBUG_ISR(priv, "CSR_DRAM_INT_TBL_REG =0x%X "
117 "aligned dma address %Lx\n",
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800118 val, (unsigned long long)priv->_agn.aligned_ict_tbl_dma);
Johannes Berga1175122010-01-21 06:21:10 -0800119
120 iwl_write32(priv, CSR_DRAM_INT_TBL_REG, val);
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800121 priv->_agn.use_ict = true;
122 priv->_agn.ict_index = 0;
Johannes Berga1175122010-01-21 06:21:10 -0800123 iwl_write32(priv, CSR_INT, priv->inta_mask);
124 iwl_enable_interrupts(priv);
125 spin_unlock_irqrestore(&priv->lock, flags);
126
127 return 0;
128}
129
130/* Device is going down disable ict interrupt usage */
131void iwl_disable_ict(struct iwl_priv *priv)
132{
133 unsigned long flags;
134
135 spin_lock_irqsave(&priv->lock, flags);
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800136 priv->_agn.use_ict = false;
Johannes Berga1175122010-01-21 06:21:10 -0800137 spin_unlock_irqrestore(&priv->lock, flags);
138}
139
140static irqreturn_t iwl_isr(int irq, void *data)
141{
142 struct iwl_priv *priv = data;
143 u32 inta, inta_mask;
144#ifdef CONFIG_IWLWIFI_DEBUG
145 u32 inta_fh;
146#endif
147 if (!priv)
148 return IRQ_NONE;
149
150 spin_lock(&priv->lock);
151
152 /* Disable (but don't clear!) interrupts here to avoid
153 * back-to-back ISRs and sporadic interrupts from our NIC.
154 * If we have something to service, the tasklet will re-enable ints.
155 * If we *don't* have something, we'll re-enable before leaving here. */
156 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
157 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
158
159 /* Discover which interrupts are active/pending */
160 inta = iwl_read32(priv, CSR_INT);
161
162 /* Ignore interrupt if there's nothing in NIC to service.
163 * This may be due to IRQ shared with another device,
164 * or due to sporadic interrupts thrown from our NIC. */
165 if (!inta) {
166 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
167 goto none;
168 }
169
170 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
171 /* Hardware disappeared. It might have already raised
172 * an interrupt */
173 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
174 goto unplugged;
175 }
176
177#ifdef CONFIG_IWLWIFI_DEBUG
178 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
179 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
180 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, "
181 "fh 0x%08x\n", inta, inta_mask, inta_fh);
182 }
183#endif
184
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800185 priv->_agn.inta |= inta;
Johannes Berga1175122010-01-21 06:21:10 -0800186 /* iwl_irq_tasklet() will service interrupts and re-enable them */
187 if (likely(inta))
188 tasklet_schedule(&priv->irq_tasklet);
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800189 else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta)
Johannes Berga1175122010-01-21 06:21:10 -0800190 iwl_enable_interrupts(priv);
191
192 unplugged:
193 spin_unlock(&priv->lock);
194 return IRQ_HANDLED;
195
196 none:
197 /* re-enable interrupts here since we don't have anything to service. */
198 /* only Re-enable if diabled by irq and no schedules tasklet. */
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800199 if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta)
Johannes Berga1175122010-01-21 06:21:10 -0800200 iwl_enable_interrupts(priv);
201
202 spin_unlock(&priv->lock);
203 return IRQ_NONE;
204}
205
206/* interrupt handler using ict table, with this interrupt driver will
207 * stop using INTA register to get device's interrupt, reading this register
208 * is expensive, device will write interrupts in ICT dram table, increment
209 * index then will fire interrupt to driver, driver will OR all ICT table
210 * entries from current index up to table entry with 0 value. the result is
211 * the interrupt we need to service, driver will set the entries back to 0 and
212 * set index.
213 */
214irqreturn_t iwl_isr_ict(int irq, void *data)
215{
216 struct iwl_priv *priv = data;
217 u32 inta, inta_mask;
218 u32 val = 0;
219
220 if (!priv)
221 return IRQ_NONE;
222
223 /* dram interrupt table not set yet,
224 * use legacy interrupt.
225 */
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800226 if (!priv->_agn.use_ict)
Johannes Berga1175122010-01-21 06:21:10 -0800227 return iwl_isr(irq, data);
228
229 spin_lock(&priv->lock);
230
231 /* Disable (but don't clear!) interrupts here to avoid
232 * back-to-back ISRs and sporadic interrupts from our NIC.
233 * If we have something to service, the tasklet will re-enable ints.
234 * If we *don't* have something, we'll re-enable before leaving here.
235 */
236 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
237 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
238
239
240 /* Ignore interrupt if there's nothing in NIC to service.
241 * This may be due to IRQ shared with another device,
242 * or due to sporadic interrupts thrown from our NIC. */
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800243 if (!priv->_agn.ict_tbl[priv->_agn.ict_index]) {
Johannes Berga1175122010-01-21 06:21:10 -0800244 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
245 goto none;
246 }
247
248 /* read all entries that not 0 start with ict_index */
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800249 while (priv->_agn.ict_tbl[priv->_agn.ict_index]) {
Johannes Berga1175122010-01-21 06:21:10 -0800250
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800251 val |= le32_to_cpu(priv->_agn.ict_tbl[priv->_agn.ict_index]);
Johannes Berga1175122010-01-21 06:21:10 -0800252 IWL_DEBUG_ISR(priv, "ICT index %d value 0x%08X\n",
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800253 priv->_agn.ict_index,
254 le32_to_cpu(priv->_agn.ict_tbl[priv->_agn.ict_index]));
255 priv->_agn.ict_tbl[priv->_agn.ict_index] = 0;
256 priv->_agn.ict_index = iwl_queue_inc_wrap(priv->_agn.ict_index,
Johannes Berga1175122010-01-21 06:21:10 -0800257 ICT_COUNT);
258
259 }
260
261 /* We should not get this value, just ignore it. */
262 if (val == 0xffffffff)
263 val = 0;
264
265 /*
266 * this is a w/a for a h/w bug. the h/w bug may cause the Rx bit
267 * (bit 15 before shifting it to 31) to clear when using interrupt
268 * coalescing. fortunately, bits 18 and 19 stay set when this happens
269 * so we use them to decide on the real state of the Rx bit.
270 * In order words, bit 15 is set if bit 18 or bit 19 are set.
271 */
272 if (val & 0xC0000)
273 val |= 0x8000;
274
275 inta = (0xff & val) | ((0xff00 & val) << 16);
276 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n",
277 inta, inta_mask, val);
278
279 inta &= priv->inta_mask;
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800280 priv->_agn.inta |= inta;
Johannes Berga1175122010-01-21 06:21:10 -0800281
282 /* iwl_irq_tasklet() will service interrupts and re-enable them */
283 if (likely(inta))
284 tasklet_schedule(&priv->irq_tasklet);
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800285 else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta) {
Johannes Berga1175122010-01-21 06:21:10 -0800286 /* Allow interrupt if was disabled by this handler and
287 * no tasklet was schedules, We should not enable interrupt,
288 * tasklet will enable it.
289 */
290 iwl_enable_interrupts(priv);
291 }
292
293 spin_unlock(&priv->lock);
294 return IRQ_HANDLED;
295
296 none:
297 /* re-enable interrupts here since we don't have anything to service.
298 * only Re-enable if disabled by irq.
299 */
Johannes Berga4c8b2a62010-01-21 06:25:54 -0800300 if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta)
Johannes Berga1175122010-01-21 06:21:10 -0800301 iwl_enable_interrupts(priv);
302
303 spin_unlock(&priv->lock);
304 return IRQ_NONE;
305}