blob: aa7ced4324b822406bf78dc5ee298c003923e6a2 [file] [log] [blame]
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
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/sched.h>
30#include <linux/wait.h>
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -070031#include <linux/gfp.h>
Emmanuel Grumbachab697a92011-07-11 07:35:34 -070032
33#include "iwl-dev.h"
34#include "iwl-agn.h"
35#include "iwl-core.h"
36#include "iwl-io.h"
37#include "iwl-helpers.h"
38#include "iwl-trans-int-pcie.h"
39
40/******************************************************************************
41 *
42 * RX path functions
43 *
44 ******************************************************************************/
45
46/*
47 * Rx theory of operation
48 *
49 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
50 * each of which point to Receive Buffers to be filled by the NIC. These get
51 * used not only for Rx frames, but for any command response or notification
52 * from the NIC. The driver and NIC manage the Rx buffers by means
53 * of indexes into the circular buffer.
54 *
55 * Rx Queue Indexes
56 * The host/firmware share two index registers for managing the Rx buffers.
57 *
58 * The READ index maps to the first position that the firmware may be writing
59 * to -- the driver can read up to (but not including) this position and get
60 * good data.
61 * The READ index is managed by the firmware once the card is enabled.
62 *
63 * The WRITE index maps to the last position the driver has read from -- the
64 * position preceding WRITE is the last slot the firmware can place a packet.
65 *
66 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
67 * WRITE = READ.
68 *
69 * During initialization, the host sets up the READ queue position to the first
70 * INDEX position, and WRITE to the last (READ - 1 wrapped)
71 *
72 * When the firmware places a packet in a buffer, it will advance the READ index
73 * and fire the RX interrupt. The driver can then query the READ index and
74 * process as many packets as possible, moving the WRITE index forward as it
75 * resets the Rx queue buffers with new memory.
76 *
77 * The management in the driver is as follows:
78 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
79 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
80 * to replenish the iwl->rxq->rx_free.
81 * + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the
82 * iwl->rxq is replenished and the READ INDEX is updated (updating the
83 * 'processed' and 'read' driver indexes as well)
84 * + A received packet is processed and handed to the kernel network stack,
85 * detached from the iwl->rxq. The driver 'processed' index is updated.
86 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
87 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
88 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
89 * were enough free buffers and RX_STALLED is set it is cleared.
90 *
91 *
92 * Driver sequence:
93 *
94 * iwl_rx_queue_alloc() Allocates rx_free
95 * iwl_rx_replenish() Replenishes rx_free list from rx_used, and calls
96 * iwl_rx_queue_restock
97 * iwl_rx_queue_restock() Moves available buffers from rx_free into Rx
98 * queue, updates firmware pointers, and updates
99 * the WRITE index. If insufficient rx_free buffers
100 * are available, schedules iwl_rx_replenish
101 *
102 * -- enable interrupts --
103 * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the
104 * READ INDEX, detaching the SKB from the pool.
105 * Moves the packet buffer from queue to rx_used.
106 * Calls iwl_rx_queue_restock to refill any empty
107 * slots.
108 * ...
109 *
110 */
111
112/**
113 * iwl_rx_queue_space - Return number of free slots available in queue.
114 */
115static int iwl_rx_queue_space(const struct iwl_rx_queue *q)
116{
117 int s = q->read - q->write;
118 if (s <= 0)
119 s += RX_QUEUE_SIZE;
120 /* keep some buffer to not confuse full and empty queue */
121 s -= 2;
122 if (s < 0)
123 s = 0;
124 return s;
125}
126
127/**
128 * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue
129 */
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700130void iwl_rx_queue_update_write_ptr(struct iwl_trans *trans,
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700131 struct iwl_rx_queue *q)
132{
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700133 struct iwl_priv *priv = priv(trans);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700134 unsigned long flags;
135 u32 reg;
136
137 spin_lock_irqsave(&q->lock, flags);
138
139 if (q->need_update == 0)
140 goto exit_unlock;
141
142 if (priv->cfg->base_params->shadow_reg_enable) {
143 /* shadow register enabled */
144 /* Device expects a multiple of 8 */
145 q->write_actual = (q->write & ~0x7);
146 iwl_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write_actual);
147 } else {
148 /* If power-saving is in use, make sure device is awake */
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700149 if (test_bit(STATUS_POWER_PMI, &trans->shrd->status)) {
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700150 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
151
152 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700153 IWL_DEBUG_INFO(trans,
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700154 "Rx queue requesting wakeup,"
155 " GP1 = 0x%x\n", reg);
156 iwl_set_bit(priv, CSR_GP_CNTRL,
157 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
158 goto exit_unlock;
159 }
160
161 q->write_actual = (q->write & ~0x7);
162 iwl_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
163 q->write_actual);
164
165 /* Else device is assumed to be awake */
166 } else {
167 /* Device expects a multiple of 8 */
168 q->write_actual = (q->write & ~0x7);
169 iwl_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
170 q->write_actual);
171 }
172 }
173 q->need_update = 0;
174
175 exit_unlock:
176 spin_unlock_irqrestore(&q->lock, flags);
177}
178
179/**
180 * iwlagn_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
181 */
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700182static inline __le32 iwlagn_dma_addr2rbd_ptr(dma_addr_t dma_addr)
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700183{
184 return cpu_to_le32((u32)(dma_addr >> 8));
185}
186
187/**
188 * iwlagn_rx_queue_restock - refill RX queue from pre-allocated pool
189 *
190 * If there are slots in the RX queue that need to be restocked,
191 * and we have free pre-allocated buffers, fill the ranks as much
192 * as we can, pulling from rx_free.
193 *
194 * This moves the 'write' index forward to catch up with 'processed', and
195 * also updates the memory address in the firmware to reference the new
196 * target buffer.
197 */
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700198static void iwlagn_rx_queue_restock(struct iwl_trans *trans)
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700199{
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700200 struct iwl_trans_pcie *trans_pcie =
201 IWL_TRANS_GET_PCIE_TRANS(trans);
202
203 struct iwl_rx_queue *rxq = &trans_pcie->rxq;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700204 struct list_head *element;
205 struct iwl_rx_mem_buffer *rxb;
206 unsigned long flags;
207
208 spin_lock_irqsave(&rxq->lock, flags);
209 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
210 /* The overwritten rxb must be a used one */
211 rxb = rxq->queue[rxq->write];
212 BUG_ON(rxb && rxb->page);
213
214 /* Get next free Rx buffer, remove from free list */
215 element = rxq->rx_free.next;
216 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
217 list_del(element);
218
219 /* Point to Rx buffer via next RBD in circular buffer */
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700220 rxq->bd[rxq->write] = iwlagn_dma_addr2rbd_ptr(rxb->page_dma);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700221 rxq->queue[rxq->write] = rxb;
222 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
223 rxq->free_count--;
224 }
225 spin_unlock_irqrestore(&rxq->lock, flags);
226 /* If the pre-allocated buffer pool is dropping low, schedule to
227 * refill it */
228 if (rxq->free_count <= RX_LOW_WATERMARK)
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700229 queue_work(trans->shrd->workqueue, &trans_pcie->rx_replenish);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700230
231
232 /* If we've added more space for the firmware to place data, tell it.
233 * Increment device's write pointer in multiples of 8. */
234 if (rxq->write_actual != (rxq->write & ~0x7)) {
235 spin_lock_irqsave(&rxq->lock, flags);
236 rxq->need_update = 1;
237 spin_unlock_irqrestore(&rxq->lock, flags);
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700238 iwl_rx_queue_update_write_ptr(trans, rxq);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700239 }
240}
241
242/**
243 * iwlagn_rx_replenish - Move all used packet from rx_used to rx_free
244 *
245 * When moving to rx_free an SKB is allocated for the slot.
246 *
247 * Also restock the Rx queue via iwl_rx_queue_restock.
248 * This is called as a scheduled work item (except for during initialization)
249 */
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700250static void iwlagn_rx_allocate(struct iwl_trans *trans, gfp_t priority)
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700251{
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700252 struct iwl_trans_pcie *trans_pcie =
253 IWL_TRANS_GET_PCIE_TRANS(trans);
254
255 struct iwl_rx_queue *rxq = &trans_pcie->rxq;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700256 struct list_head *element;
257 struct iwl_rx_mem_buffer *rxb;
258 struct page *page;
259 unsigned long flags;
260 gfp_t gfp_mask = priority;
261
262 while (1) {
263 spin_lock_irqsave(&rxq->lock, flags);
264 if (list_empty(&rxq->rx_used)) {
265 spin_unlock_irqrestore(&rxq->lock, flags);
266 return;
267 }
268 spin_unlock_irqrestore(&rxq->lock, flags);
269
270 if (rxq->free_count > RX_LOW_WATERMARK)
271 gfp_mask |= __GFP_NOWARN;
272
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700273 if (hw_params(trans).rx_page_order > 0)
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700274 gfp_mask |= __GFP_COMP;
275
276 /* Alloc a new receive buffer */
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700277 page = alloc_pages(gfp_mask,
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700278 hw_params(trans).rx_page_order);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700279 if (!page) {
280 if (net_ratelimit())
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700281 IWL_DEBUG_INFO(trans, "alloc_pages failed, "
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700282 "order: %d\n",
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700283 hw_params(trans).rx_page_order);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700284
285 if ((rxq->free_count <= RX_LOW_WATERMARK) &&
286 net_ratelimit())
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700287 IWL_CRIT(trans, "Failed to alloc_pages with %s."
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700288 "Only %u free buffers remaining.\n",
289 priority == GFP_ATOMIC ?
290 "GFP_ATOMIC" : "GFP_KERNEL",
291 rxq->free_count);
292 /* We don't reschedule replenish work here -- we will
293 * call the restock method and if it still needs
294 * more buffers it will schedule replenish */
295 return;
296 }
297
298 spin_lock_irqsave(&rxq->lock, flags);
299
300 if (list_empty(&rxq->rx_used)) {
301 spin_unlock_irqrestore(&rxq->lock, flags);
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700302 __free_pages(page, hw_params(trans).rx_page_order);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700303 return;
304 }
305 element = rxq->rx_used.next;
306 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
307 list_del(element);
308
309 spin_unlock_irqrestore(&rxq->lock, flags);
310
311 BUG_ON(rxb->page);
312 rxb->page = page;
313 /* Get physical address of the RB */
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700314 rxb->page_dma = dma_map_page(bus(trans)->dev, page, 0,
315 PAGE_SIZE << hw_params(trans).rx_page_order,
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700316 DMA_FROM_DEVICE);
317 /* dma address must be no more than 36 bits */
318 BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36));
319 /* and also 256 byte aligned! */
320 BUG_ON(rxb->page_dma & DMA_BIT_MASK(8));
321
322 spin_lock_irqsave(&rxq->lock, flags);
323
324 list_add_tail(&rxb->list, &rxq->rx_free);
325 rxq->free_count++;
326
327 spin_unlock_irqrestore(&rxq->lock, flags);
328 }
329}
330
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700331void iwlagn_rx_replenish(struct iwl_trans *trans)
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700332{
333 unsigned long flags;
334
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700335 iwlagn_rx_allocate(trans, GFP_KERNEL);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700336
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700337 spin_lock_irqsave(&trans->shrd->lock, flags);
338 iwlagn_rx_queue_restock(trans);
339 spin_unlock_irqrestore(&trans->shrd->lock, flags);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700340}
341
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700342static void iwlagn_rx_replenish_now(struct iwl_trans *trans)
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700343{
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700344 iwlagn_rx_allocate(trans, GFP_ATOMIC);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700345
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700346 iwlagn_rx_queue_restock(trans);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700347}
348
349void iwl_bg_rx_replenish(struct work_struct *data)
350{
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700351 struct iwl_trans_pcie *trans_pcie =
352 container_of(data, struct iwl_trans_pcie, rx_replenish);
353 struct iwl_trans *trans = trans_pcie->trans;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700354
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700355 if (test_bit(STATUS_EXIT_PENDING, &trans->shrd->status))
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700356 return;
357
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700358 mutex_lock(&trans->shrd->mutex);
359 iwlagn_rx_replenish(trans);
360 mutex_unlock(&trans->shrd->mutex);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700361}
362
363/**
364 * iwl_rx_handle - Main entry function for receiving responses from uCode
365 *
366 * Uses the priv->rx_handlers callback function array to invoke
367 * the appropriate handlers, including command responses,
368 * frame-received notifications, and other notifications.
369 */
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700370static void iwl_rx_handle(struct iwl_trans *trans)
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700371{
372 struct iwl_rx_mem_buffer *rxb;
373 struct iwl_rx_packet *pkt;
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700374 struct iwl_trans_pcie *trans_pcie =
375 IWL_TRANS_GET_PCIE_TRANS(trans);
376 struct iwl_rx_queue *rxq = &trans_pcie->rxq;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700377 u32 r, i;
378 int reclaim;
379 unsigned long flags;
380 u8 fill_rx = 0;
381 u32 count = 8;
382 int total_empty;
383
384 /* uCode's read index (stored in shared DRAM) indicates the last Rx
385 * buffer that the driver may process (last buffer filled by ucode). */
386 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
387 i = rxq->read;
388
389 /* Rx interrupt, but nothing sent from uCode */
390 if (i == r)
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700391 IWL_DEBUG_RX(trans, "r = %d, i = %d\n", r, i);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700392
393 /* calculate total frames need to be restock after handling RX */
394 total_empty = r - rxq->write_actual;
395 if (total_empty < 0)
396 total_empty += RX_QUEUE_SIZE;
397
398 if (total_empty > (RX_QUEUE_SIZE / 2))
399 fill_rx = 1;
400
401 while (i != r) {
402 int len;
403
404 rxb = rxq->queue[i];
405
406 /* If an RXB doesn't have a Rx queue slot associated with it,
407 * then a bug has been introduced in the queue refilling
408 * routines -- catch it here */
409 if (WARN_ON(rxb == NULL)) {
410 i = (i + 1) & RX_QUEUE_MASK;
411 continue;
412 }
413
414 rxq->queue[i] = NULL;
415
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700416 dma_unmap_page(bus(trans)->dev, rxb->page_dma,
417 PAGE_SIZE << hw_params(trans).rx_page_order,
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700418 DMA_FROM_DEVICE);
419 pkt = rxb_addr(rxb);
420
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700421 IWL_DEBUG_RX(trans, "r = %d, i = %d, %s, 0x%02x\n", r,
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700422 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
423
424 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
425 len += sizeof(u32); /* account for status word */
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700426 trace_iwlwifi_dev_rx(priv(trans), pkt, len);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700427
428 /* Reclaim a command buffer only if this packet is a response
429 * to a (driver-originated) command.
430 * If the packet (e.g. Rx frame) originated from uCode,
431 * there is no command buffer to reclaim.
432 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
433 * but apparently a few don't get set; catch them here. */
434 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
435 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
436 (pkt->hdr.cmd != REPLY_RX) &&
437 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
438 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
439 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
440 (pkt->hdr.cmd != REPLY_TX);
441
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700442 iwl_rx_dispatch(priv(trans), rxb);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700443
444 /*
445 * XXX: After here, we should always check rxb->page
446 * against NULL before touching it or its virtual
447 * memory (pkt). Because some rx_handler might have
448 * already taken or freed the pages.
449 */
450
451 if (reclaim) {
452 /* Invoke any callbacks, transfer the buffer to caller,
453 * and fire off the (possibly) blocking
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700454 * iwl_trans_send_cmd()
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700455 * as we reclaim the driver command queue */
456 if (rxb->page)
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700457 iwl_tx_cmd_complete(priv(trans), rxb);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700458 else
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700459 IWL_WARN(trans, "Claim null rxb?\n");
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700460 }
461
462 /* Reuse the page if possible. For notification packets and
463 * SKBs that fail to Rx correctly, add them back into the
464 * rx_free list for reuse later. */
465 spin_lock_irqsave(&rxq->lock, flags);
466 if (rxb->page != NULL) {
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700467 rxb->page_dma = dma_map_page(bus(trans)->dev, rxb->page,
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700468 0, PAGE_SIZE <<
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700469 hw_params(trans).rx_page_order,
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700470 DMA_FROM_DEVICE);
471 list_add_tail(&rxb->list, &rxq->rx_free);
472 rxq->free_count++;
473 } else
474 list_add_tail(&rxb->list, &rxq->rx_used);
475
476 spin_unlock_irqrestore(&rxq->lock, flags);
477
478 i = (i + 1) & RX_QUEUE_MASK;
479 /* If there are a lot of unused frames,
480 * restock the Rx queue so ucode wont assert. */
481 if (fill_rx) {
482 count++;
483 if (count >= 8) {
484 rxq->read = i;
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700485 iwlagn_rx_replenish_now(trans);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700486 count = 0;
487 }
488 }
489 }
490
491 /* Backtrack one entry */
492 rxq->read = i;
493 if (fill_rx)
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700494 iwlagn_rx_replenish_now(trans);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700495 else
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700496 iwlagn_rx_queue_restock(trans);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700497}
498
Emmanuel Grumbach7ff94702011-08-25 23:10:54 -0700499static const char * const desc_lookup_text[] = {
500 "OK",
501 "FAIL",
502 "BAD_PARAM",
503 "BAD_CHECKSUM",
504 "NMI_INTERRUPT_WDG",
505 "SYSASSERT",
506 "FATAL_ERROR",
507 "BAD_COMMAND",
508 "HW_ERROR_TUNE_LOCK",
509 "HW_ERROR_TEMPERATURE",
510 "ILLEGAL_CHAN_FREQ",
511 "VCC_NOT_STABLE",
512 "FH_ERROR",
513 "NMI_INTERRUPT_HOST",
514 "NMI_INTERRUPT_ACTION_PT",
515 "NMI_INTERRUPT_UNKNOWN",
516 "UCODE_VERSION_MISMATCH",
517 "HW_ERROR_ABS_LOCK",
518 "HW_ERROR_CAL_LOCK_FAIL",
519 "NMI_INTERRUPT_INST_ACTION_PT",
520 "NMI_INTERRUPT_DATA_ACTION_PT",
521 "NMI_TRM_HW_ER",
522 "NMI_INTERRUPT_TRM",
523 "NMI_INTERRUPT_BREAK_POINT",
524 "DEBUG_0",
525 "DEBUG_1",
526 "DEBUG_2",
527 "DEBUG_3",
528};
529
530static struct { char *name; u8 num; } advanced_lookup[] = {
531 { "NMI_INTERRUPT_WDG", 0x34 },
532 { "SYSASSERT", 0x35 },
533 { "UCODE_VERSION_MISMATCH", 0x37 },
534 { "BAD_COMMAND", 0x38 },
535 { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
536 { "FATAL_ERROR", 0x3D },
537 { "NMI_TRM_HW_ERR", 0x46 },
538 { "NMI_INTERRUPT_TRM", 0x4C },
539 { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
540 { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
541 { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
542 { "NMI_INTERRUPT_HOST", 0x66 },
543 { "NMI_INTERRUPT_ACTION_PT", 0x7C },
544 { "NMI_INTERRUPT_UNKNOWN", 0x84 },
545 { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
546 { "ADVANCED_SYSASSERT", 0 },
547};
548
549static const char *desc_lookup(u32 num)
550{
551 int i;
552 int max = ARRAY_SIZE(desc_lookup_text);
553
554 if (num < max)
555 return desc_lookup_text[num];
556
557 max = ARRAY_SIZE(advanced_lookup) - 1;
558 for (i = 0; i < max; i++) {
559 if (advanced_lookup[i].num == num)
560 break;
561 }
562 return advanced_lookup[i].name;
563}
564
565#define ERROR_START_OFFSET (1 * sizeof(u32))
566#define ERROR_ELEM_SIZE (7 * sizeof(u32))
567
568static void iwl_dump_nic_error_log(struct iwl_priv *priv)
569{
570 u32 base;
571 struct iwl_error_event_table table;
572
573 base = priv->device_pointers.error_event_table;
574 if (priv->ucode_type == IWL_UCODE_INIT) {
575 if (!base)
576 base = priv->init_errlog_ptr;
577 } else {
578 if (!base)
579 base = priv->inst_errlog_ptr;
580 }
581
582 if (!iwlagn_hw_valid_rtc_data_addr(base)) {
583 IWL_ERR(priv,
584 "Not valid error log pointer 0x%08X for %s uCode\n",
585 base,
586 (priv->ucode_type == IWL_UCODE_INIT)
587 ? "Init" : "RT");
588 return;
589 }
590
591 iwl_read_targ_mem_words(priv, base, &table, sizeof(table));
592
593 if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
594 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
595 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
596 priv->shrd->status, table.valid);
597 }
598
599 priv->isr_stats.err_code = table.error_id;
600
601 trace_iwlwifi_dev_ucode_error(priv, table.error_id, table.tsf_low,
602 table.data1, table.data2, table.line,
603 table.blink1, table.blink2, table.ilink1,
604 table.ilink2, table.bcon_time, table.gp1,
605 table.gp2, table.gp3, table.ucode_ver,
606 table.hw_ver, table.brd_ver);
607 IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
608 desc_lookup(table.error_id));
609 IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
610 IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
611 IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
612 IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
613 IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
614 IWL_ERR(priv, "0x%08X | data1\n", table.data1);
615 IWL_ERR(priv, "0x%08X | data2\n", table.data2);
616 IWL_ERR(priv, "0x%08X | line\n", table.line);
617 IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
618 IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
619 IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
620 IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
621 IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
622 IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
623 IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
624 IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
625 IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
626 IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
627}
628
629/**
630 * iwl_irq_handle_error - called for HW or SW error interrupt from card
631 */
632static void iwl_irq_handle_error(struct iwl_priv *priv)
633{
634 /* W/A for WiFi/WiMAX coex and WiMAX own the RF */
635 if (priv->cfg->internal_wimax_coex &&
636 (!(iwl_read_prph(priv, APMG_CLK_CTRL_REG) &
637 APMS_CLK_VAL_MRB_FUNC_MODE) ||
638 (iwl_read_prph(priv, APMG_PS_CTRL_REG) &
639 APMG_PS_CTRL_VAL_RESET_REQ))) {
640 /*
641 * Keep the restart process from trying to send host
642 * commands by clearing the ready bit.
643 */
644 clear_bit(STATUS_READY, &priv->shrd->status);
645 clear_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status);
646 wake_up_interruptible(&priv->wait_command_queue);
647 IWL_ERR(priv, "RF is used by WiMAX\n");
648 return;
649 }
650
651 IWL_ERR(priv, "Loaded firmware version: %s\n",
652 priv->hw->wiphy->fw_version);
653
654 iwl_dump_nic_error_log(priv);
655 iwl_dump_csr(priv);
656 iwl_dump_fh(priv, NULL, false);
657 iwl_dump_nic_event_log(priv, false, NULL, false);
658#ifdef CONFIG_IWLWIFI_DEBUG
659 if (iwl_get_debug_level(priv->shrd) & IWL_DL_FW_ERRORS)
660 iwl_print_rx_config_cmd(priv,
661 &priv->contexts[IWL_RXON_CTX_BSS]);
662#endif
663
664 iwlagn_fw_error(priv, false);
665}
666
667#define EVENT_START_OFFSET (4 * sizeof(u32))
668
669/**
670 * iwl_print_event_log - Dump error event log to syslog
671 *
672 */
673static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
674 u32 num_events, u32 mode,
675 int pos, char **buf, size_t bufsz)
676{
677 u32 i;
678 u32 base; /* SRAM byte address of event log header */
679 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
680 u32 ptr; /* SRAM byte address of log data */
681 u32 ev, time, data; /* event log data */
682 unsigned long reg_flags;
683
684 if (num_events == 0)
685 return pos;
686
687 base = priv->device_pointers.log_event_table;
688 if (priv->ucode_type == IWL_UCODE_INIT) {
689 if (!base)
690 base = priv->init_evtlog_ptr;
691 } else {
692 if (!base)
693 base = priv->inst_evtlog_ptr;
694 }
695
696 if (mode == 0)
697 event_size = 2 * sizeof(u32);
698 else
699 event_size = 3 * sizeof(u32);
700
701 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
702
703 /* Make sure device is powered up for SRAM reads */
704 spin_lock_irqsave(&priv->reg_lock, reg_flags);
705 iwl_grab_nic_access(priv);
706
707 /* Set starting address; reads will auto-increment */
708 iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
709 rmb();
710
711 /* "time" is actually "data" for mode 0 (no timestamp).
712 * place event id # at far right for easier visual parsing. */
713 for (i = 0; i < num_events; i++) {
714 ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
715 time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
716 if (mode == 0) {
717 /* data, ev */
718 if (bufsz) {
719 pos += scnprintf(*buf + pos, bufsz - pos,
720 "EVT_LOG:0x%08x:%04u\n",
721 time, ev);
722 } else {
723 trace_iwlwifi_dev_ucode_event(priv, 0,
724 time, ev);
725 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
726 time, ev);
727 }
728 } else {
729 data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
730 if (bufsz) {
731 pos += scnprintf(*buf + pos, bufsz - pos,
732 "EVT_LOGT:%010u:0x%08x:%04u\n",
733 time, data, ev);
734 } else {
735 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
736 time, data, ev);
737 trace_iwlwifi_dev_ucode_event(priv, time,
738 data, ev);
739 }
740 }
741 }
742
743 /* Allow device to power down */
744 iwl_release_nic_access(priv);
745 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
746 return pos;
747}
748
749/**
750 * iwl_print_last_event_logs - Dump the newest # of event log to syslog
751 */
752static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
753 u32 num_wraps, u32 next_entry,
754 u32 size, u32 mode,
755 int pos, char **buf, size_t bufsz)
756{
757 /*
758 * display the newest DEFAULT_LOG_ENTRIES entries
759 * i.e the entries just before the next ont that uCode would fill.
760 */
761 if (num_wraps) {
762 if (next_entry < size) {
763 pos = iwl_print_event_log(priv,
764 capacity - (size - next_entry),
765 size - next_entry, mode,
766 pos, buf, bufsz);
767 pos = iwl_print_event_log(priv, 0,
768 next_entry, mode,
769 pos, buf, bufsz);
770 } else
771 pos = iwl_print_event_log(priv, next_entry - size,
772 size, mode, pos, buf, bufsz);
773 } else {
774 if (next_entry < size) {
775 pos = iwl_print_event_log(priv, 0, next_entry,
776 mode, pos, buf, bufsz);
777 } else {
778 pos = iwl_print_event_log(priv, next_entry - size,
779 size, mode, pos, buf, bufsz);
780 }
781 }
782 return pos;
783}
784
785#define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
786
787int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
788 char **buf, bool display)
789{
790 u32 base; /* SRAM byte address of event log header */
791 u32 capacity; /* event log capacity in # entries */
792 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
793 u32 num_wraps; /* # times uCode wrapped to top of log */
794 u32 next_entry; /* index of next entry to be written by uCode */
795 u32 size; /* # entries that we'll print */
796 u32 logsize;
797 int pos = 0;
798 size_t bufsz = 0;
799
800 base = priv->device_pointers.log_event_table;
801 if (priv->ucode_type == IWL_UCODE_INIT) {
802 logsize = priv->init_evtlog_size;
803 if (!base)
804 base = priv->init_evtlog_ptr;
805 } else {
806 logsize = priv->inst_evtlog_size;
807 if (!base)
808 base = priv->inst_evtlog_ptr;
809 }
810
811 if (!iwlagn_hw_valid_rtc_data_addr(base)) {
812 IWL_ERR(priv,
813 "Invalid event log pointer 0x%08X for %s uCode\n",
814 base,
815 (priv->ucode_type == IWL_UCODE_INIT)
816 ? "Init" : "RT");
817 return -EINVAL;
818 }
819
820 /* event log header */
821 capacity = iwl_read_targ_mem(priv, base);
822 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
823 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
824 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
825
826 if (capacity > logsize) {
827 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
828 capacity, logsize);
829 capacity = logsize;
830 }
831
832 if (next_entry > logsize) {
833 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
834 next_entry, logsize);
835 next_entry = logsize;
836 }
837
838 size = num_wraps ? capacity : next_entry;
839
840 /* bail out if nothing in log */
841 if (size == 0) {
842 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
843 return pos;
844 }
845
846 /* enable/disable bt channel inhibition */
847 priv->bt_ch_announce = iwlagn_mod_params.bt_ch_announce;
848
849#ifdef CONFIG_IWLWIFI_DEBUG
850 if (!(iwl_get_debug_level(priv->shrd) & IWL_DL_FW_ERRORS) && !full_log)
851 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
852 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
853#else
854 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
855 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
856#endif
857 IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
858 size);
859
860#ifdef CONFIG_IWLWIFI_DEBUG
861 if (display) {
862 if (full_log)
863 bufsz = capacity * 48;
864 else
865 bufsz = size * 48;
866 *buf = kmalloc(bufsz, GFP_KERNEL);
867 if (!*buf)
868 return -ENOMEM;
869 }
870 if ((iwl_get_debug_level(priv->shrd) & IWL_DL_FW_ERRORS) || full_log) {
871 /*
872 * if uCode has wrapped back to top of log,
873 * start at the oldest entry,
874 * i.e the next one that uCode would fill.
875 */
876 if (num_wraps)
877 pos = iwl_print_event_log(priv, next_entry,
878 capacity - next_entry, mode,
879 pos, buf, bufsz);
880 /* (then/else) start at top of log */
881 pos = iwl_print_event_log(priv, 0,
882 next_entry, mode, pos, buf, bufsz);
883 } else
884 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
885 next_entry, size, mode,
886 pos, buf, bufsz);
887#else
888 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
889 next_entry, size, mode,
890 pos, buf, bufsz);
891#endif
892 return pos;
893}
894
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700895/* tasklet for iwlagn interrupt */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700896void iwl_irq_tasklet(struct iwl_trans *trans)
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700897{
898 u32 inta = 0;
899 u32 handled = 0;
900 unsigned long flags;
901 u32 i;
902#ifdef CONFIG_IWLWIFI_DEBUG
903 u32 inta_mask;
904#endif
905
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700906 struct iwl_trans_pcie *trans_pcie =
907 IWL_TRANS_GET_PCIE_TRANS(trans);
908
909 spin_lock_irqsave(&trans->shrd->lock, flags);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700910
911 /* Ack/clear/reset pending uCode interrupts.
912 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
913 */
914 /* There is a hardware bug in the interrupt mask function that some
915 * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if
916 * they are disabled in the CSR_INT_MASK register. Furthermore the
917 * ICT interrupt handling mechanism has another bug that might cause
918 * these unmasked interrupts fail to be detected. We workaround the
919 * hardware bugs here by ACKing all the possible interrupts so that
920 * interrupt coalescing can still be achieved.
921 */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700922 iwl_write32(priv(trans), CSR_INT,
923 trans_pcie->inta | ~trans_pcie->inta_mask);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700924
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700925 inta = trans_pcie->inta;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700926
927#ifdef CONFIG_IWLWIFI_DEBUG
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700928 if (iwl_get_debug_level(trans->shrd) & IWL_DL_ISR) {
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700929 /* just for debug */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700930 inta_mask = iwl_read32(priv(trans), CSR_INT_MASK);
931 IWL_DEBUG_ISR(trans, "inta 0x%08x, enabled 0x%08x\n ",
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700932 inta, inta_mask);
933 }
934#endif
935
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700936 spin_unlock_irqrestore(&trans->shrd->lock, flags);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700937
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700938 /* saved interrupt in inta variable now we can reset trans_pcie->inta */
939 trans_pcie->inta = 0;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700940
941 /* Now service all interrupt bits discovered above. */
942 if (inta & CSR_INT_BIT_HW_ERR) {
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700943 IWL_ERR(trans, "Hardware error detected. Restarting.\n");
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700944
945 /* Tell the device to stop sending interrupts */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700946 iwl_disable_interrupts(trans);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700947
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700948 priv(trans)->isr_stats.hw++;
949 iwl_irq_handle_error(priv(trans));
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700950
951 handled |= CSR_INT_BIT_HW_ERR;
952
953 return;
954 }
955
956#ifdef CONFIG_IWLWIFI_DEBUG
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700957 if (iwl_get_debug_level(trans->shrd) & (IWL_DL_ISR)) {
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700958 /* NIC fires this, but we don't use it, redundant with WAKEUP */
959 if (inta & CSR_INT_BIT_SCD) {
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700960 IWL_DEBUG_ISR(trans, "Scheduler finished to transmit "
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700961 "the frame/frames.\n");
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700962 priv(trans)->isr_stats.sch++;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700963 }
964
965 /* Alive notification via Rx interrupt will do the real work */
966 if (inta & CSR_INT_BIT_ALIVE) {
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700967 IWL_DEBUG_ISR(trans, "Alive interrupt\n");
968 priv(trans)->isr_stats.alive++;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700969 }
970 }
971#endif
972 /* Safely ignore these bits for debug checks below */
973 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
974
975 /* HW RF KILL switch toggled */
976 if (inta & CSR_INT_BIT_RF_KILL) {
977 int hw_rf_kill = 0;
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700978 if (!(iwl_read32(priv(trans), CSR_GP_CNTRL) &
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700979 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
980 hw_rf_kill = 1;
981
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700982 IWL_WARN(trans, "RF_KILL bit toggled to %s.\n",
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700983 hw_rf_kill ? "disable radio" : "enable radio");
984
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700985 priv(trans)->isr_stats.rfkill++;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700986
987 /* driver only loads ucode once setting the interface up.
988 * the driver allows loading the ucode even if the radio
989 * is killed. Hence update the killswitch state here. The
990 * rfkill handler will care about restarting if needed.
991 */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700992 if (!test_bit(STATUS_ALIVE, &trans->shrd->status)) {
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700993 if (hw_rf_kill)
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700994 set_bit(STATUS_RF_KILL_HW,
995 &trans->shrd->status);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -0700996 else
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700997 clear_bit(STATUS_RF_KILL_HW,
Emmanuel Grumbach0c325762011-08-25 23:10:53 -0700998 &trans->shrd->status);
999 wiphy_rfkill_set_hw_state(priv(trans)->hw->wiphy,
1000 hw_rf_kill);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001001 }
1002
1003 handled |= CSR_INT_BIT_RF_KILL;
1004 }
1005
1006 /* Chip got too hot and stopped itself */
1007 if (inta & CSR_INT_BIT_CT_KILL) {
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001008 IWL_ERR(trans, "Microcode CT kill error detected.\n");
1009 priv(trans)->isr_stats.ctkill++;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001010 handled |= CSR_INT_BIT_CT_KILL;
1011 }
1012
1013 /* Error detected by uCode */
1014 if (inta & CSR_INT_BIT_SW_ERR) {
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001015 IWL_ERR(trans, "Microcode SW error detected. "
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001016 " Restarting 0x%X.\n", inta);
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001017 priv(trans)->isr_stats.sw++;
1018 iwl_irq_handle_error(priv(trans));
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001019 handled |= CSR_INT_BIT_SW_ERR;
1020 }
1021
1022 /* uCode wakes up after power-down sleep */
1023 if (inta & CSR_INT_BIT_WAKEUP) {
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001024 IWL_DEBUG_ISR(trans, "Wakeup interrupt\n");
1025 iwl_rx_queue_update_write_ptr(trans, &trans_pcie->rxq);
1026 for (i = 0; i < hw_params(trans).max_txq_num; i++)
1027 iwl_txq_update_write_ptr(priv(trans),
1028 &priv(trans)->txq[i]);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001029
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001030 priv(trans)->isr_stats.wakeup++;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001031
1032 handled |= CSR_INT_BIT_WAKEUP;
1033 }
1034
1035 /* All uCode command responses, including Tx command responses,
1036 * Rx "responses" (frame-received notification), and other
1037 * notifications from uCode come through here*/
1038 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
1039 CSR_INT_BIT_RX_PERIODIC)) {
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001040 IWL_DEBUG_ISR(trans, "Rx interrupt\n");
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001041 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1042 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001043 iwl_write32(priv(trans), CSR_FH_INT_STATUS,
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001044 CSR_FH_INT_RX_MASK);
1045 }
1046 if (inta & CSR_INT_BIT_RX_PERIODIC) {
1047 handled |= CSR_INT_BIT_RX_PERIODIC;
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001048 iwl_write32(priv(trans),
1049 CSR_INT, CSR_INT_BIT_RX_PERIODIC);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001050 }
1051 /* Sending RX interrupt require many steps to be done in the
1052 * the device:
1053 * 1- write interrupt to current index in ICT table.
1054 * 2- dma RX frame.
1055 * 3- update RX shared data to indicate last write index.
1056 * 4- send interrupt.
1057 * This could lead to RX race, driver could receive RX interrupt
1058 * but the shared data changes does not reflect this;
1059 * periodic interrupt will detect any dangling Rx activity.
1060 */
1061
1062 /* Disable periodic interrupt; we use it as just a one-shot. */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001063 iwl_write8(priv(trans), CSR_INT_PERIODIC_REG,
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001064 CSR_INT_PERIODIC_DIS);
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001065 iwl_rx_handle(trans);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001066
1067 /*
1068 * Enable periodic interrupt in 8 msec only if we received
1069 * real RX interrupt (instead of just periodic int), to catch
1070 * any dangling Rx interrupt. If it was just the periodic
1071 * interrupt, there was no dangling Rx activity, and no need
1072 * to extend the periodic interrupt; one-shot is enough.
1073 */
1074 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001075 iwl_write8(priv(trans), CSR_INT_PERIODIC_REG,
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001076 CSR_INT_PERIODIC_ENA);
1077
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001078 priv(trans)->isr_stats.rx++;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001079 }
1080
1081 /* This "Tx" DMA channel is used only for loading uCode */
1082 if (inta & CSR_INT_BIT_FH_TX) {
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001083 iwl_write32(priv(trans), CSR_FH_INT_STATUS, CSR_FH_INT_TX_MASK);
1084 IWL_DEBUG_ISR(trans, "uCode load interrupt\n");
1085 priv(trans)->isr_stats.tx++;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001086 handled |= CSR_INT_BIT_FH_TX;
1087 /* Wake up uCode load routine, now that load is complete */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001088 priv(trans)->ucode_write_complete = 1;
1089 wake_up_interruptible(&priv(trans)->wait_command_queue);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001090 }
1091
1092 if (inta & ~handled) {
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001093 IWL_ERR(trans, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1094 priv(trans)->isr_stats.unhandled++;
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001095 }
1096
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001097 if (inta & ~(trans_pcie->inta_mask)) {
1098 IWL_WARN(trans, "Disabled INTA bits 0x%08x were pending\n",
1099 inta & ~trans_pcie->inta_mask);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001100 }
1101
1102 /* Re-enable all interrupts */
1103 /* only Re-enable if disabled by irq */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001104 if (test_bit(STATUS_INT_ENABLED, &trans->shrd->status))
1105 iwl_enable_interrupts(trans);
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001106 /* Re-enable RF_KILL if it occurred */
1107 else if (handled & CSR_INT_BIT_RF_KILL)
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001108 iwl_enable_rfkill_int(priv(trans));
Emmanuel Grumbachab697a92011-07-11 07:35:34 -07001109}
1110
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001111/******************************************************************************
1112 *
1113 * ICT functions
1114 *
1115 ******************************************************************************/
1116#define ICT_COUNT (PAGE_SIZE/sizeof(u32))
1117
1118/* Free dram table */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001119void iwl_free_isr_ict(struct iwl_trans *trans)
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001120{
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001121 struct iwl_trans_pcie *trans_pcie =
1122 IWL_TRANS_GET_PCIE_TRANS(trans);
1123
1124 if (trans_pcie->ict_tbl_vir) {
1125 dma_free_coherent(bus(trans)->dev,
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001126 (sizeof(u32) * ICT_COUNT) + PAGE_SIZE,
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001127 trans_pcie->ict_tbl_vir,
1128 trans_pcie->ict_tbl_dma);
1129 trans_pcie->ict_tbl_vir = NULL;
1130 memset(&trans_pcie->ict_tbl_dma, 0,
1131 sizeof(trans_pcie->ict_tbl_dma));
1132 memset(&trans_pcie->aligned_ict_tbl_dma, 0,
1133 sizeof(trans_pcie->aligned_ict_tbl_dma));
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001134 }
1135}
1136
1137
1138/* allocate dram shared table it is a PAGE_SIZE aligned
1139 * also reset all data related to ICT table interrupt.
1140 */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001141int iwl_alloc_isr_ict(struct iwl_trans *trans)
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001142{
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001143 struct iwl_trans_pcie *trans_pcie =
1144 IWL_TRANS_GET_PCIE_TRANS(trans);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001145
1146 /* allocate shrared data table */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001147 trans_pcie->ict_tbl_vir =
1148 dma_alloc_coherent(bus(trans)->dev,
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001149 (sizeof(u32) * ICT_COUNT) + PAGE_SIZE,
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001150 &trans_pcie->ict_tbl_dma, GFP_KERNEL);
1151 if (!trans_pcie->ict_tbl_vir)
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001152 return -ENOMEM;
1153
1154 /* align table to PAGE_SIZE boundary */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001155 trans_pcie->aligned_ict_tbl_dma =
1156 ALIGN(trans_pcie->ict_tbl_dma, PAGE_SIZE);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001157
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001158 IWL_DEBUG_ISR(trans, "ict dma addr %Lx dma aligned %Lx diff %d\n",
1159 (unsigned long long)trans_pcie->ict_tbl_dma,
1160 (unsigned long long)trans_pcie->aligned_ict_tbl_dma,
1161 (int)(trans_pcie->aligned_ict_tbl_dma -
1162 trans_pcie->ict_tbl_dma));
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001163
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001164 trans_pcie->ict_tbl = trans_pcie->ict_tbl_vir +
1165 (trans_pcie->aligned_ict_tbl_dma -
1166 trans_pcie->ict_tbl_dma);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001167
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001168 IWL_DEBUG_ISR(trans, "ict vir addr %p vir aligned %p diff %d\n",
1169 trans_pcie->ict_tbl, trans_pcie->ict_tbl_vir,
1170 (int)(trans_pcie->aligned_ict_tbl_dma -
1171 trans_pcie->ict_tbl_dma));
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001172
1173 /* reset table and index to all 0 */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001174 memset(trans_pcie->ict_tbl_vir, 0,
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001175 (sizeof(u32) * ICT_COUNT) + PAGE_SIZE);
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001176 trans_pcie->ict_index = 0;
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001177
1178 /* add periodic RX interrupt */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001179 trans_pcie->inta_mask |= CSR_INT_BIT_RX_PERIODIC;
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001180 return 0;
1181}
1182
1183/* Device is going up inform it about using ICT interrupt table,
1184 * also we need to tell the driver to start using ICT interrupt.
1185 */
1186int iwl_reset_ict(struct iwl_priv *priv)
1187{
1188 u32 val;
1189 unsigned long flags;
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001190 struct iwl_trans *trans = trans(priv);
1191 struct iwl_trans_pcie *trans_pcie =
1192 IWL_TRANS_GET_PCIE_TRANS(trans);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001193
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001194 if (!trans_pcie->ict_tbl_vir)
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001195 return 0;
1196
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001197 spin_lock_irqsave(&trans->shrd->lock, flags);
1198 iwl_disable_interrupts(trans);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001199
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001200 memset(&trans_pcie->ict_tbl[0], 0, sizeof(u32) * ICT_COUNT);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001201
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001202 val = trans_pcie->aligned_ict_tbl_dma >> PAGE_SHIFT;
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001203
1204 val |= CSR_DRAM_INT_TBL_ENABLE;
1205 val |= CSR_DRAM_INIT_TBL_WRAP_CHECK;
1206
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001207 IWL_DEBUG_ISR(trans, "CSR_DRAM_INT_TBL_REG =0x%X "
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001208 "aligned dma address %Lx\n",
1209 val,
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001210 (unsigned long long)trans_pcie->aligned_ict_tbl_dma);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001211
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001212 iwl_write32(priv(trans), CSR_DRAM_INT_TBL_REG, val);
1213 trans_pcie->use_ict = true;
1214 trans_pcie->ict_index = 0;
1215 iwl_write32(priv(trans), CSR_INT, trans_pcie->inta_mask);
1216 iwl_enable_interrupts(trans);
1217 spin_unlock_irqrestore(&trans->shrd->lock, flags);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001218
1219 return 0;
1220}
1221
1222/* Device is going down disable ict interrupt usage */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001223void iwl_disable_ict(struct iwl_trans *trans)
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001224{
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001225 struct iwl_trans_pcie *trans_pcie =
1226 IWL_TRANS_GET_PCIE_TRANS(trans);
1227
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001228 unsigned long flags;
1229
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001230 spin_lock_irqsave(&trans->shrd->lock, flags);
1231 trans_pcie->use_ict = false;
1232 spin_unlock_irqrestore(&trans->shrd->lock, flags);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001233}
1234
1235static irqreturn_t iwl_isr(int irq, void *data)
1236{
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001237 struct iwl_trans *trans = data;
1238 struct iwl_trans_pcie *trans_pcie;
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001239 u32 inta, inta_mask;
1240 unsigned long flags;
1241#ifdef CONFIG_IWLWIFI_DEBUG
1242 u32 inta_fh;
1243#endif
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001244 if (!trans)
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001245 return IRQ_NONE;
1246
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001247 trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1248
1249 spin_lock_irqsave(&trans->shrd->lock, flags);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001250
1251 /* Disable (but don't clear!) interrupts here to avoid
1252 * back-to-back ISRs and sporadic interrupts from our NIC.
1253 * If we have something to service, the tasklet will re-enable ints.
1254 * If we *don't* have something, we'll re-enable before leaving here. */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001255 inta_mask = iwl_read32(priv(trans), CSR_INT_MASK); /* just for debug */
1256 iwl_write32(priv(trans), CSR_INT_MASK, 0x00000000);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001257
1258 /* Discover which interrupts are active/pending */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001259 inta = iwl_read32(priv(trans), CSR_INT);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001260
1261 /* Ignore interrupt if there's nothing in NIC to service.
1262 * This may be due to IRQ shared with another device,
1263 * or due to sporadic interrupts thrown from our NIC. */
1264 if (!inta) {
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001265 IWL_DEBUG_ISR(trans, "Ignore interrupt, inta == 0\n");
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001266 goto none;
1267 }
1268
1269 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1270 /* Hardware disappeared. It might have already raised
1271 * an interrupt */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001272 IWL_WARN(trans, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001273 goto unplugged;
1274 }
1275
1276#ifdef CONFIG_IWLWIFI_DEBUG
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001277 if (iwl_get_debug_level(trans->shrd) & (IWL_DL_ISR)) {
1278 inta_fh = iwl_read32(priv(trans), CSR_FH_INT_STATUS);
1279 IWL_DEBUG_ISR(trans, "ISR inta 0x%08x, enabled 0x%08x, "
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001280 "fh 0x%08x\n", inta, inta_mask, inta_fh);
1281 }
1282#endif
1283
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001284 trans_pcie->inta |= inta;
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001285 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1286 if (likely(inta))
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001287 tasklet_schedule(&trans_pcie->irq_tasklet);
1288 else if (test_bit(STATUS_INT_ENABLED, &trans->shrd->status) &&
1289 !trans_pcie->inta)
1290 iwl_enable_interrupts(trans);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001291
1292 unplugged:
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001293 spin_unlock_irqrestore(&trans->shrd->lock, flags);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001294 return IRQ_HANDLED;
1295
1296 none:
1297 /* re-enable interrupts here since we don't have anything to service. */
1298 /* only Re-enable if disabled by irq and no schedules tasklet. */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001299 if (test_bit(STATUS_INT_ENABLED, &trans->shrd->status) &&
1300 !trans_pcie->inta)
1301 iwl_enable_interrupts(trans);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001302
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001303 spin_unlock_irqrestore(&trans->shrd->lock, flags);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001304 return IRQ_NONE;
1305}
1306
1307/* interrupt handler using ict table, with this interrupt driver will
1308 * stop using INTA register to get device's interrupt, reading this register
1309 * is expensive, device will write interrupts in ICT dram table, increment
1310 * index then will fire interrupt to driver, driver will OR all ICT table
1311 * entries from current index up to table entry with 0 value. the result is
1312 * the interrupt we need to service, driver will set the entries back to 0 and
1313 * set index.
1314 */
1315irqreturn_t iwl_isr_ict(int irq, void *data)
1316{
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001317 struct iwl_trans *trans = data;
1318 struct iwl_trans_pcie *trans_pcie;
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001319 u32 inta, inta_mask;
1320 u32 val = 0;
1321 unsigned long flags;
1322
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001323 if (!trans)
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001324 return IRQ_NONE;
1325
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001326 trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1327
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001328 /* dram interrupt table not set yet,
1329 * use legacy interrupt.
1330 */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001331 if (!trans_pcie->use_ict)
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001332 return iwl_isr(irq, data);
1333
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001334 spin_lock_irqsave(&trans->shrd->lock, flags);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001335
1336 /* Disable (but don't clear!) interrupts here to avoid
1337 * back-to-back ISRs and sporadic interrupts from our NIC.
1338 * If we have something to service, the tasklet will re-enable ints.
1339 * If we *don't* have something, we'll re-enable before leaving here.
1340 */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001341 inta_mask = iwl_read32(priv(trans), CSR_INT_MASK); /* just for debug */
1342 iwl_write32(priv(trans), CSR_INT_MASK, 0x00000000);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001343
1344
1345 /* Ignore interrupt if there's nothing in NIC to service.
1346 * This may be due to IRQ shared with another device,
1347 * or due to sporadic interrupts thrown from our NIC. */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001348 if (!trans_pcie->ict_tbl[trans_pcie->ict_index]) {
1349 IWL_DEBUG_ISR(trans, "Ignore interrupt, inta == 0\n");
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001350 goto none;
1351 }
1352
1353 /* read all entries that not 0 start with ict_index */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001354 while (trans_pcie->ict_tbl[trans_pcie->ict_index]) {
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001355
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001356 val |= le32_to_cpu(trans_pcie->ict_tbl[trans_pcie->ict_index]);
1357 IWL_DEBUG_ISR(trans, "ICT index %d value 0x%08X\n",
1358 trans_pcie->ict_index,
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001359 le32_to_cpu(
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001360 trans_pcie->ict_tbl[trans_pcie->ict_index]));
1361 trans_pcie->ict_tbl[trans_pcie->ict_index] = 0;
1362 trans_pcie->ict_index =
1363 iwl_queue_inc_wrap(trans_pcie->ict_index, ICT_COUNT);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001364
1365 }
1366
1367 /* We should not get this value, just ignore it. */
1368 if (val == 0xffffffff)
1369 val = 0;
1370
1371 /*
1372 * this is a w/a for a h/w bug. the h/w bug may cause the Rx bit
1373 * (bit 15 before shifting it to 31) to clear when using interrupt
1374 * coalescing. fortunately, bits 18 and 19 stay set when this happens
1375 * so we use them to decide on the real state of the Rx bit.
1376 * In order words, bit 15 is set if bit 18 or bit 19 are set.
1377 */
1378 if (val & 0xC0000)
1379 val |= 0x8000;
1380
1381 inta = (0xff & val) | ((0xff00 & val) << 16);
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001382 IWL_DEBUG_ISR(trans, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n",
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001383 inta, inta_mask, val);
1384
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001385 inta &= trans_pcie->inta_mask;
1386 trans_pcie->inta |= inta;
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001387
1388 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1389 if (likely(inta))
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001390 tasklet_schedule(&trans_pcie->irq_tasklet);
1391 else if (test_bit(STATUS_INT_ENABLED, &trans->shrd->status) &&
1392 !trans_pcie->inta) {
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001393 /* Allow interrupt if was disabled by this handler and
1394 * no tasklet was schedules, We should not enable interrupt,
1395 * tasklet will enable it.
1396 */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001397 iwl_enable_interrupts(trans);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001398 }
1399
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001400 spin_unlock_irqrestore(&trans->shrd->lock, flags);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001401 return IRQ_HANDLED;
1402
1403 none:
1404 /* re-enable interrupts here since we don't have anything to service.
1405 * only Re-enable if disabled by irq.
1406 */
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001407 if (test_bit(STATUS_INT_ENABLED, &trans->shrd->status) &&
1408 !trans_pcie->inta)
1409 iwl_enable_interrupts(trans);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001410
Emmanuel Grumbach0c325762011-08-25 23:10:53 -07001411 spin_unlock_irqrestore(&trans->shrd->lock, flags);
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001412 return IRQ_NONE;
1413}