Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wey-Yi Guy | fb4961d | 2012-01-06 13:16:33 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 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 Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 31 | #include <linux/gfp.h> |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 32 | |
Emmanuel Grumbach | 522376d | 2011-09-06 09:31:19 -0700 | [diff] [blame] | 33 | /*TODO: Remove include to iwl-core.h*/ |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 34 | #include "iwl-core.h" |
| 35 | #include "iwl-io.h" |
Johannes Berg | c17d068 | 2011-09-15 11:46:42 -0700 | [diff] [blame] | 36 | #include "iwl-trans-pcie-int.h" |
Don Fry | 8655112 | 2012-02-07 14:03:55 -0800 | [diff] [blame] | 37 | #include "iwl-wifi.h" |
Emmanuel Grumbach | db70f29 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 38 | #include "iwl-op-mode.h" |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 39 | |
Gregory Greenman | a591697 | 2012-01-10 19:22:56 +0200 | [diff] [blame] | 40 | #ifdef CONFIG_IWLWIFI_IDI |
| 41 | #include "iwl-amfh.h" |
| 42 | #endif |
| 43 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 44 | /****************************************************************************** |
| 45 | * |
| 46 | * RX path functions |
| 47 | * |
| 48 | ******************************************************************************/ |
| 49 | |
| 50 | /* |
| 51 | * Rx theory of operation |
| 52 | * |
| 53 | * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs), |
| 54 | * each of which point to Receive Buffers to be filled by the NIC. These get |
| 55 | * used not only for Rx frames, but for any command response or notification |
| 56 | * from the NIC. The driver and NIC manage the Rx buffers by means |
| 57 | * of indexes into the circular buffer. |
| 58 | * |
| 59 | * Rx Queue Indexes |
| 60 | * The host/firmware share two index registers for managing the Rx buffers. |
| 61 | * |
| 62 | * The READ index maps to the first position that the firmware may be writing |
| 63 | * to -- the driver can read up to (but not including) this position and get |
| 64 | * good data. |
| 65 | * The READ index is managed by the firmware once the card is enabled. |
| 66 | * |
| 67 | * The WRITE index maps to the last position the driver has read from -- the |
| 68 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 69 | * |
| 70 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 71 | * WRITE = READ. |
| 72 | * |
| 73 | * During initialization, the host sets up the READ queue position to the first |
| 74 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 75 | * |
| 76 | * When the firmware places a packet in a buffer, it will advance the READ index |
| 77 | * and fire the RX interrupt. The driver can then query the READ index and |
| 78 | * process as many packets as possible, moving the WRITE index forward as it |
| 79 | * resets the Rx queue buffers with new memory. |
| 80 | * |
| 81 | * The management in the driver is as follows: |
| 82 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 83 | * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled |
| 84 | * to replenish the iwl->rxq->rx_free. |
| 85 | * + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the |
| 86 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 87 | * 'processed' and 'read' driver indexes as well) |
| 88 | * + A received packet is processed and handed to the kernel network stack, |
| 89 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 90 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 91 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 92 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 93 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 94 | * |
| 95 | * |
| 96 | * Driver sequence: |
| 97 | * |
| 98 | * iwl_rx_queue_alloc() Allocates rx_free |
| 99 | * iwl_rx_replenish() Replenishes rx_free list from rx_used, and calls |
| 100 | * iwl_rx_queue_restock |
| 101 | * iwl_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 102 | * queue, updates firmware pointers, and updates |
| 103 | * the WRITE index. If insufficient rx_free buffers |
| 104 | * are available, schedules iwl_rx_replenish |
| 105 | * |
| 106 | * -- enable interrupts -- |
| 107 | * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the |
| 108 | * READ INDEX, detaching the SKB from the pool. |
| 109 | * Moves the packet buffer from queue to rx_used. |
| 110 | * Calls iwl_rx_queue_restock to refill any empty |
| 111 | * slots. |
| 112 | * ... |
| 113 | * |
| 114 | */ |
| 115 | |
| 116 | /** |
| 117 | * iwl_rx_queue_space - Return number of free slots available in queue. |
| 118 | */ |
| 119 | static int iwl_rx_queue_space(const struct iwl_rx_queue *q) |
| 120 | { |
| 121 | int s = q->read - q->write; |
| 122 | if (s <= 0) |
| 123 | s += RX_QUEUE_SIZE; |
| 124 | /* keep some buffer to not confuse full and empty queue */ |
| 125 | s -= 2; |
| 126 | if (s < 0) |
| 127 | s = 0; |
| 128 | return s; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue |
| 133 | */ |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 134 | void iwl_rx_queue_update_write_ptr(struct iwl_trans *trans, |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 135 | struct iwl_rx_queue *q) |
| 136 | { |
| 137 | unsigned long flags; |
| 138 | u32 reg; |
| 139 | |
| 140 | spin_lock_irqsave(&q->lock, flags); |
| 141 | |
| 142 | if (q->need_update == 0) |
| 143 | goto exit_unlock; |
| 144 | |
Emmanuel Grumbach | fd65693 | 2011-08-25 23:11:19 -0700 | [diff] [blame] | 145 | if (hw_params(trans).shadow_reg_enable) { |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 146 | /* shadow register enabled */ |
| 147 | /* Device expects a multiple of 8 */ |
| 148 | q->write_actual = (q->write & ~0x7); |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 149 | iwl_write32(trans, FH_RSCSR_CHNL0_WPTR, q->write_actual); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 150 | } else { |
| 151 | /* If power-saving is in use, make sure device is awake */ |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 152 | if (test_bit(STATUS_POWER_PMI, &trans->shrd->status)) { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 153 | reg = iwl_read32(trans, CSR_UCODE_DRV_GP1); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 154 | |
| 155 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 156 | IWL_DEBUG_INFO(trans, |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 157 | "Rx queue requesting wakeup," |
| 158 | " GP1 = 0x%x\n", reg); |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 159 | iwl_set_bit(trans, CSR_GP_CNTRL, |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 160 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 161 | goto exit_unlock; |
| 162 | } |
| 163 | |
| 164 | q->write_actual = (q->write & ~0x7); |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 165 | iwl_write_direct32(trans, FH_RSCSR_CHNL0_WPTR, |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 166 | q->write_actual); |
| 167 | |
| 168 | /* Else device is assumed to be awake */ |
| 169 | } else { |
| 170 | /* Device expects a multiple of 8 */ |
| 171 | q->write_actual = (q->write & ~0x7); |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 172 | iwl_write_direct32(trans, FH_RSCSR_CHNL0_WPTR, |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 173 | q->write_actual); |
| 174 | } |
| 175 | } |
| 176 | q->need_update = 0; |
| 177 | |
| 178 | exit_unlock: |
| 179 | spin_unlock_irqrestore(&q->lock, flags); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * iwlagn_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr |
| 184 | */ |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 185 | static inline __le32 iwlagn_dma_addr2rbd_ptr(dma_addr_t dma_addr) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 186 | { |
| 187 | return cpu_to_le32((u32)(dma_addr >> 8)); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * iwlagn_rx_queue_restock - refill RX queue from pre-allocated pool |
| 192 | * |
| 193 | * If there are slots in the RX queue that need to be restocked, |
| 194 | * and we have free pre-allocated buffers, fill the ranks as much |
| 195 | * as we can, pulling from rx_free. |
| 196 | * |
| 197 | * This moves the 'write' index forward to catch up with 'processed', and |
| 198 | * also updates the memory address in the firmware to reference the new |
| 199 | * target buffer. |
| 200 | */ |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 201 | static void iwlagn_rx_queue_restock(struct iwl_trans *trans) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 202 | { |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 203 | struct iwl_trans_pcie *trans_pcie = |
| 204 | IWL_TRANS_GET_PCIE_TRANS(trans); |
| 205 | |
| 206 | struct iwl_rx_queue *rxq = &trans_pcie->rxq; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 207 | struct list_head *element; |
| 208 | struct iwl_rx_mem_buffer *rxb; |
| 209 | unsigned long flags; |
| 210 | |
| 211 | spin_lock_irqsave(&rxq->lock, flags); |
| 212 | while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
| 213 | /* The overwritten rxb must be a used one */ |
| 214 | rxb = rxq->queue[rxq->write]; |
| 215 | BUG_ON(rxb && rxb->page); |
| 216 | |
| 217 | /* Get next free Rx buffer, remove from free list */ |
| 218 | element = rxq->rx_free.next; |
| 219 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
| 220 | list_del(element); |
| 221 | |
| 222 | /* Point to Rx buffer via next RBD in circular buffer */ |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 223 | rxq->bd[rxq->write] = iwlagn_dma_addr2rbd_ptr(rxb->page_dma); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 224 | rxq->queue[rxq->write] = rxb; |
| 225 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 226 | rxq->free_count--; |
| 227 | } |
| 228 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 229 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 230 | * refill it */ |
| 231 | if (rxq->free_count <= RX_LOW_WATERMARK) |
Johannes Berg | 1ee158d | 2012-02-17 10:07:44 -0800 | [diff] [blame] | 232 | schedule_work(&trans_pcie->rx_replenish); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 233 | |
| 234 | |
| 235 | /* If we've added more space for the firmware to place data, tell it. |
| 236 | * Increment device's write pointer in multiples of 8. */ |
| 237 | if (rxq->write_actual != (rxq->write & ~0x7)) { |
| 238 | spin_lock_irqsave(&rxq->lock, flags); |
| 239 | rxq->need_update = 1; |
| 240 | spin_unlock_irqrestore(&rxq->lock, flags); |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 241 | iwl_rx_queue_update_write_ptr(trans, rxq); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * iwlagn_rx_replenish - Move all used packet from rx_used to rx_free |
| 247 | * |
| 248 | * When moving to rx_free an SKB is allocated for the slot. |
| 249 | * |
| 250 | * Also restock the Rx queue via iwl_rx_queue_restock. |
| 251 | * This is called as a scheduled work item (except for during initialization) |
| 252 | */ |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 253 | static void iwlagn_rx_allocate(struct iwl_trans *trans, gfp_t priority) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 254 | { |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 255 | struct iwl_trans_pcie *trans_pcie = |
| 256 | IWL_TRANS_GET_PCIE_TRANS(trans); |
| 257 | |
| 258 | struct iwl_rx_queue *rxq = &trans_pcie->rxq; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 259 | struct list_head *element; |
| 260 | struct iwl_rx_mem_buffer *rxb; |
| 261 | struct page *page; |
| 262 | unsigned long flags; |
| 263 | gfp_t gfp_mask = priority; |
| 264 | |
| 265 | while (1) { |
| 266 | spin_lock_irqsave(&rxq->lock, flags); |
| 267 | if (list_empty(&rxq->rx_used)) { |
| 268 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 269 | return; |
| 270 | } |
| 271 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 272 | |
| 273 | if (rxq->free_count > RX_LOW_WATERMARK) |
| 274 | gfp_mask |= __GFP_NOWARN; |
| 275 | |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 276 | if (hw_params(trans).rx_page_order > 0) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 277 | gfp_mask |= __GFP_COMP; |
| 278 | |
| 279 | /* Alloc a new receive buffer */ |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 280 | page = alloc_pages(gfp_mask, |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 281 | hw_params(trans).rx_page_order); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 282 | if (!page) { |
| 283 | if (net_ratelimit()) |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 284 | IWL_DEBUG_INFO(trans, "alloc_pages failed, " |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 285 | "order: %d\n", |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 286 | hw_params(trans).rx_page_order); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 287 | |
| 288 | if ((rxq->free_count <= RX_LOW_WATERMARK) && |
| 289 | net_ratelimit()) |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 290 | IWL_CRIT(trans, "Failed to alloc_pages with %s." |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 291 | "Only %u free buffers remaining.\n", |
| 292 | priority == GFP_ATOMIC ? |
| 293 | "GFP_ATOMIC" : "GFP_KERNEL", |
| 294 | rxq->free_count); |
| 295 | /* We don't reschedule replenish work here -- we will |
| 296 | * call the restock method and if it still needs |
| 297 | * more buffers it will schedule replenish */ |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | spin_lock_irqsave(&rxq->lock, flags); |
| 302 | |
| 303 | if (list_empty(&rxq->rx_used)) { |
| 304 | spin_unlock_irqrestore(&rxq->lock, flags); |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 305 | __free_pages(page, hw_params(trans).rx_page_order); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 306 | return; |
| 307 | } |
| 308 | element = rxq->rx_used.next; |
| 309 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
| 310 | list_del(element); |
| 311 | |
| 312 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 313 | |
| 314 | BUG_ON(rxb->page); |
| 315 | rxb->page = page; |
| 316 | /* Get physical address of the RB */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 317 | rxb->page_dma = dma_map_page(trans->dev, page, 0, |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 318 | PAGE_SIZE << hw_params(trans).rx_page_order, |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 319 | DMA_FROM_DEVICE); |
| 320 | /* dma address must be no more than 36 bits */ |
| 321 | BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36)); |
| 322 | /* and also 256 byte aligned! */ |
| 323 | BUG_ON(rxb->page_dma & DMA_BIT_MASK(8)); |
| 324 | |
| 325 | spin_lock_irqsave(&rxq->lock, flags); |
| 326 | |
| 327 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 328 | rxq->free_count++; |
| 329 | |
| 330 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 331 | } |
| 332 | } |
| 333 | |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 334 | void iwlagn_rx_replenish(struct iwl_trans *trans) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 335 | { |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 336 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 337 | unsigned long flags; |
| 338 | |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 339 | iwlagn_rx_allocate(trans, GFP_KERNEL); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 340 | |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 341 | spin_lock_irqsave(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 342 | iwlagn_rx_queue_restock(trans); |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 343 | spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 346 | static void iwlagn_rx_replenish_now(struct iwl_trans *trans) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 347 | { |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 348 | iwlagn_rx_allocate(trans, GFP_ATOMIC); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 349 | |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 350 | iwlagn_rx_queue_restock(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | void iwl_bg_rx_replenish(struct work_struct *data) |
| 354 | { |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 355 | struct iwl_trans_pcie *trans_pcie = |
| 356 | container_of(data, struct iwl_trans_pcie, rx_replenish); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 357 | |
Johannes Berg | 1ee158d | 2012-02-17 10:07:44 -0800 | [diff] [blame] | 358 | iwlagn_rx_replenish(trans_pcie->trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 361 | static void iwl_rx_handle_rxbuf(struct iwl_trans *trans, |
| 362 | struct iwl_rx_mem_buffer *rxb) |
| 363 | { |
| 364 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 365 | struct iwl_rx_queue *rxq = &trans_pcie->rxq; |
| 366 | struct iwl_tx_queue *txq = &trans_pcie->txq[trans->shrd->cmd_queue]; |
| 367 | struct iwl_device_cmd *cmd; |
| 368 | unsigned long flags; |
| 369 | int len, err; |
| 370 | u16 sequence; |
| 371 | struct iwl_rx_cmd_buffer rxcb; |
| 372 | struct iwl_rx_packet *pkt; |
| 373 | bool reclaim; |
| 374 | int index, cmd_index; |
| 375 | |
| 376 | if (WARN_ON(!rxb)) |
| 377 | return; |
| 378 | |
| 379 | dma_unmap_page(trans->dev, rxb->page_dma, |
| 380 | PAGE_SIZE << hw_params(trans).rx_page_order, |
| 381 | DMA_FROM_DEVICE); |
| 382 | |
| 383 | rxcb._page = rxb->page; |
| 384 | pkt = rxb_addr(&rxcb); |
| 385 | |
| 386 | IWL_DEBUG_RX(trans, "%s, 0x%02x\n", |
| 387 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 388 | |
| 389 | |
| 390 | len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
| 391 | len += sizeof(u32); /* account for status word */ |
| 392 | trace_iwlwifi_dev_rx(priv(trans), pkt, len); |
| 393 | |
| 394 | /* Reclaim a command buffer only if this packet is a response |
| 395 | * to a (driver-originated) command. |
| 396 | * If the packet (e.g. Rx frame) originated from uCode, |
| 397 | * there is no command buffer to reclaim. |
| 398 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 399 | * but apparently a few don't get set; catch them here. */ |
| 400 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 401 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
| 402 | (pkt->hdr.cmd != REPLY_RX) && |
| 403 | (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) && |
| 404 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
| 405 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 406 | (pkt->hdr.cmd != REPLY_TX); |
| 407 | |
| 408 | sequence = le16_to_cpu(pkt->hdr.sequence); |
| 409 | index = SEQ_TO_INDEX(sequence); |
| 410 | cmd_index = get_cmd_index(&txq->q, index); |
| 411 | |
| 412 | if (reclaim) |
| 413 | cmd = txq->cmd[cmd_index]; |
| 414 | else |
| 415 | cmd = NULL; |
| 416 | |
| 417 | /* warn if this is cmd response / notification and the uCode |
| 418 | * didn't set the SEQ_RX_FRAME for a frame that is |
| 419 | * uCode-originated |
| 420 | * If you saw this code after the second half of 2012, then |
| 421 | * please remove it |
| 422 | */ |
| 423 | WARN(pkt->hdr.cmd != REPLY_TX && reclaim == false && |
| 424 | (!(pkt->hdr.sequence & SEQ_RX_FRAME)), |
| 425 | "reclaim is false, SEQ_RX_FRAME unset: %s\n", |
| 426 | get_cmd_string(pkt->hdr.cmd)); |
| 427 | |
| 428 | err = iwl_op_mode_rx(trans->op_mode, &rxcb, cmd); |
| 429 | |
| 430 | /* |
| 431 | * XXX: After here, we should always check rxcb._page |
| 432 | * against NULL before touching it or its virtual |
| 433 | * memory (pkt). Because some rx_handler might have |
| 434 | * already taken or freed the pages. |
| 435 | */ |
| 436 | |
| 437 | if (reclaim) { |
| 438 | /* Invoke any callbacks, transfer the buffer to caller, |
| 439 | * and fire off the (possibly) blocking |
| 440 | * iwl_trans_send_cmd() |
| 441 | * as we reclaim the driver command queue */ |
| 442 | if (rxcb._page) |
| 443 | iwl_tx_cmd_complete(trans, &rxcb, err); |
| 444 | else |
| 445 | IWL_WARN(trans, "Claim null rxb?\n"); |
| 446 | } |
| 447 | |
| 448 | /* page was stolen from us */ |
| 449 | if (rxcb._page == NULL) |
| 450 | rxb->page = NULL; |
| 451 | |
| 452 | /* Reuse the page if possible. For notification packets and |
| 453 | * SKBs that fail to Rx correctly, add them back into the |
| 454 | * rx_free list for reuse later. */ |
| 455 | spin_lock_irqsave(&rxq->lock, flags); |
| 456 | if (rxb->page != NULL) { |
| 457 | rxb->page_dma = |
| 458 | dma_map_page(trans->dev, rxb->page, 0, |
| 459 | PAGE_SIZE << hw_params(trans).rx_page_order, |
| 460 | DMA_FROM_DEVICE); |
| 461 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 462 | rxq->free_count++; |
| 463 | } else |
| 464 | list_add_tail(&rxb->list, &rxq->rx_used); |
| 465 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 466 | } |
| 467 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 468 | /** |
| 469 | * iwl_rx_handle - Main entry function for receiving responses from uCode |
| 470 | * |
| 471 | * Uses the priv->rx_handlers callback function array to invoke |
| 472 | * the appropriate handlers, including command responses, |
| 473 | * frame-received notifications, and other notifications. |
| 474 | */ |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 475 | static void iwl_rx_handle(struct iwl_trans *trans) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 476 | { |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 477 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 478 | struct iwl_rx_queue *rxq = &trans_pcie->rxq; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 479 | u32 r, i; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 480 | u8 fill_rx = 0; |
| 481 | u32 count = 8; |
| 482 | int total_empty; |
| 483 | |
| 484 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 485 | * buffer that the driver may process (last buffer filled by ucode). */ |
| 486 | r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF; |
| 487 | i = rxq->read; |
| 488 | |
| 489 | /* Rx interrupt, but nothing sent from uCode */ |
| 490 | if (i == r) |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 491 | IWL_DEBUG_RX(trans, "r = %d, i = %d\n", r, i); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 492 | |
| 493 | /* calculate total frames need to be restock after handling RX */ |
| 494 | total_empty = r - rxq->write_actual; |
| 495 | if (total_empty < 0) |
| 496 | total_empty += RX_QUEUE_SIZE; |
| 497 | |
| 498 | if (total_empty > (RX_QUEUE_SIZE / 2)) |
| 499 | fill_rx = 1; |
| 500 | |
| 501 | while (i != r) { |
Johannes Berg | 48a2d66 | 2012-03-05 11:24:39 -0800 | [diff] [blame] | 502 | struct iwl_rx_mem_buffer *rxb; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 503 | |
| 504 | rxb = rxq->queue[i]; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 505 | rxq->queue[i] = NULL; |
| 506 | |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 507 | IWL_DEBUG_RX(trans, "rxbuf: r = %d, i = %d (%p)\n", rxb); |
Johannes Berg | 48a2d66 | 2012-03-05 11:24:39 -0800 | [diff] [blame] | 508 | |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 509 | iwl_rx_handle_rxbuf(trans, rxb); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 510 | |
| 511 | i = (i + 1) & RX_QUEUE_MASK; |
| 512 | /* If there are a lot of unused frames, |
| 513 | * restock the Rx queue so ucode wont assert. */ |
| 514 | if (fill_rx) { |
| 515 | count++; |
| 516 | if (count >= 8) { |
| 517 | rxq->read = i; |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 518 | iwlagn_rx_replenish_now(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 519 | count = 0; |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | /* Backtrack one entry */ |
| 525 | rxq->read = i; |
| 526 | if (fill_rx) |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 527 | iwlagn_rx_replenish_now(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 528 | else |
Emmanuel Grumbach | 5a878bf | 2011-08-25 23:10:51 -0700 | [diff] [blame] | 529 | iwlagn_rx_queue_restock(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 532 | static const char * const desc_lookup_text[] = { |
| 533 | "OK", |
| 534 | "FAIL", |
| 535 | "BAD_PARAM", |
| 536 | "BAD_CHECKSUM", |
| 537 | "NMI_INTERRUPT_WDG", |
| 538 | "SYSASSERT", |
| 539 | "FATAL_ERROR", |
| 540 | "BAD_COMMAND", |
| 541 | "HW_ERROR_TUNE_LOCK", |
| 542 | "HW_ERROR_TEMPERATURE", |
| 543 | "ILLEGAL_CHAN_FREQ", |
| 544 | "VCC_NOT_STABLE", |
| 545 | "FH_ERROR", |
| 546 | "NMI_INTERRUPT_HOST", |
| 547 | "NMI_INTERRUPT_ACTION_PT", |
| 548 | "NMI_INTERRUPT_UNKNOWN", |
| 549 | "UCODE_VERSION_MISMATCH", |
| 550 | "HW_ERROR_ABS_LOCK", |
| 551 | "HW_ERROR_CAL_LOCK_FAIL", |
| 552 | "NMI_INTERRUPT_INST_ACTION_PT", |
| 553 | "NMI_INTERRUPT_DATA_ACTION_PT", |
| 554 | "NMI_TRM_HW_ER", |
| 555 | "NMI_INTERRUPT_TRM", |
| 556 | "NMI_INTERRUPT_BREAK_POINT", |
| 557 | "DEBUG_0", |
| 558 | "DEBUG_1", |
| 559 | "DEBUG_2", |
| 560 | "DEBUG_3", |
| 561 | }; |
| 562 | |
| 563 | static struct { char *name; u8 num; } advanced_lookup[] = { |
| 564 | { "NMI_INTERRUPT_WDG", 0x34 }, |
| 565 | { "SYSASSERT", 0x35 }, |
| 566 | { "UCODE_VERSION_MISMATCH", 0x37 }, |
| 567 | { "BAD_COMMAND", 0x38 }, |
| 568 | { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C }, |
| 569 | { "FATAL_ERROR", 0x3D }, |
| 570 | { "NMI_TRM_HW_ERR", 0x46 }, |
| 571 | { "NMI_INTERRUPT_TRM", 0x4C }, |
| 572 | { "NMI_INTERRUPT_BREAK_POINT", 0x54 }, |
| 573 | { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C }, |
| 574 | { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 }, |
| 575 | { "NMI_INTERRUPT_HOST", 0x66 }, |
| 576 | { "NMI_INTERRUPT_ACTION_PT", 0x7C }, |
| 577 | { "NMI_INTERRUPT_UNKNOWN", 0x84 }, |
| 578 | { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 }, |
| 579 | { "ADVANCED_SYSASSERT", 0 }, |
| 580 | }; |
| 581 | |
| 582 | static const char *desc_lookup(u32 num) |
| 583 | { |
| 584 | int i; |
| 585 | int max = ARRAY_SIZE(desc_lookup_text); |
| 586 | |
| 587 | if (num < max) |
| 588 | return desc_lookup_text[num]; |
| 589 | |
| 590 | max = ARRAY_SIZE(advanced_lookup) - 1; |
| 591 | for (i = 0; i < max; i++) { |
| 592 | if (advanced_lookup[i].num == num) |
| 593 | break; |
| 594 | } |
| 595 | return advanced_lookup[i].name; |
| 596 | } |
| 597 | |
| 598 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 599 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 600 | |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 601 | static void iwl_dump_nic_error_log(struct iwl_trans *trans) |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 602 | { |
| 603 | u32 base; |
| 604 | struct iwl_error_event_table table; |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 605 | struct iwl_trans_pcie *trans_pcie = |
| 606 | IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 607 | |
Don Fry | ae6130f | 2011-11-30 16:12:59 -0800 | [diff] [blame] | 608 | base = trans->shrd->device_pointers.error_event_table; |
Don Fry | 3d6acef | 2011-11-28 17:05:01 -0800 | [diff] [blame] | 609 | if (trans->shrd->ucode_type == IWL_UCODE_INIT) { |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 610 | if (!base) |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame^] | 611 | base = trans->shrd->fw->init_errlog_ptr; |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 612 | } else { |
| 613 | if (!base) |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame^] | 614 | base = trans->shrd->fw->inst_errlog_ptr; |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | if (!iwlagn_hw_valid_rtc_data_addr(base)) { |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 618 | IWL_ERR(trans, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 619 | "Not valid error log pointer 0x%08X for %s uCode\n", |
| 620 | base, |
Don Fry | 3d6acef | 2011-11-28 17:05:01 -0800 | [diff] [blame] | 621 | (trans->shrd->ucode_type == IWL_UCODE_INIT) |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 622 | ? "Init" : "RT"); |
| 623 | return; |
| 624 | } |
| 625 | |
Don Fry | 8655112 | 2012-02-07 14:03:55 -0800 | [diff] [blame] | 626 | iwl_read_targ_mem_words(trans, base, &table, sizeof(table)); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 627 | |
| 628 | if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) { |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 629 | IWL_ERR(trans, "Start IWL Error Log Dump:\n"); |
| 630 | IWL_ERR(trans, "Status: 0x%08lX, count: %d\n", |
| 631 | trans->shrd->status, table.valid); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 634 | trans_pcie->isr_stats.err_code = table.error_id; |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 635 | |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame^] | 636 | trace_iwlwifi_dev_ucode_error(priv(trans), table.error_id, table.tsf_low, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 637 | table.data1, table.data2, table.line, |
| 638 | table.blink1, table.blink2, table.ilink1, |
| 639 | table.ilink2, table.bcon_time, table.gp1, |
| 640 | table.gp2, table.gp3, table.ucode_ver, |
| 641 | table.hw_ver, table.brd_ver); |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 642 | IWL_ERR(trans, "0x%08X | %-28s\n", table.error_id, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 643 | desc_lookup(table.error_id)); |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 644 | IWL_ERR(trans, "0x%08X | uPc\n", table.pc); |
| 645 | IWL_ERR(trans, "0x%08X | branchlink1\n", table.blink1); |
| 646 | IWL_ERR(trans, "0x%08X | branchlink2\n", table.blink2); |
| 647 | IWL_ERR(trans, "0x%08X | interruptlink1\n", table.ilink1); |
| 648 | IWL_ERR(trans, "0x%08X | interruptlink2\n", table.ilink2); |
| 649 | IWL_ERR(trans, "0x%08X | data1\n", table.data1); |
| 650 | IWL_ERR(trans, "0x%08X | data2\n", table.data2); |
| 651 | IWL_ERR(trans, "0x%08X | line\n", table.line); |
| 652 | IWL_ERR(trans, "0x%08X | beacon time\n", table.bcon_time); |
| 653 | IWL_ERR(trans, "0x%08X | tsf low\n", table.tsf_low); |
| 654 | IWL_ERR(trans, "0x%08X | tsf hi\n", table.tsf_hi); |
| 655 | IWL_ERR(trans, "0x%08X | time gp1\n", table.gp1); |
| 656 | IWL_ERR(trans, "0x%08X | time gp2\n", table.gp2); |
| 657 | IWL_ERR(trans, "0x%08X | time gp3\n", table.gp3); |
| 658 | IWL_ERR(trans, "0x%08X | uCode version\n", table.ucode_ver); |
| 659 | IWL_ERR(trans, "0x%08X | hw version\n", table.hw_ver); |
| 660 | IWL_ERR(trans, "0x%08X | board version\n", table.brd_ver); |
| 661 | IWL_ERR(trans, "0x%08X | hcmd\n", table.hcmd); |
Wey-Yi Guy | d332f59 | 2011-11-30 12:32:42 -0800 | [diff] [blame] | 662 | |
| 663 | IWL_ERR(trans, "0x%08X | isr0\n", table.isr0); |
| 664 | IWL_ERR(trans, "0x%08X | isr1\n", table.isr1); |
| 665 | IWL_ERR(trans, "0x%08X | isr2\n", table.isr2); |
| 666 | IWL_ERR(trans, "0x%08X | isr3\n", table.isr3); |
| 667 | IWL_ERR(trans, "0x%08X | isr4\n", table.isr4); |
| 668 | IWL_ERR(trans, "0x%08X | isr_pref\n", table.isr_pref); |
| 669 | IWL_ERR(trans, "0x%08X | wait_event\n", table.wait_event); |
| 670 | IWL_ERR(trans, "0x%08X | l2p_control\n", table.l2p_control); |
| 671 | IWL_ERR(trans, "0x%08X | l2p_duration\n", table.l2p_duration); |
| 672 | IWL_ERR(trans, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid); |
| 673 | IWL_ERR(trans, "0x%08X | l2p_addr_match\n", table.l2p_addr_match); |
| 674 | IWL_ERR(trans, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel); |
| 675 | IWL_ERR(trans, "0x%08X | timestamp\n", table.u_timestamp); |
| 676 | IWL_ERR(trans, "0x%08X | flow_handler\n", table.flow_handler); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | /** |
| 680 | * iwl_irq_handle_error - called for HW or SW error interrupt from card |
| 681 | */ |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 682 | static void iwl_irq_handle_error(struct iwl_trans *trans) |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 683 | { |
| 684 | /* W/A for WiFi/WiMAX coex and WiMAX own the RF */ |
Emmanuel Grumbach | ff6e75c | 2012-02-12 15:21:08 +0200 | [diff] [blame] | 685 | if (cfg(trans)->internal_wimax_coex && |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 686 | (!(iwl_read_prph(trans, APMG_CLK_CTRL_REG) & |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 687 | APMS_CLK_VAL_MRB_FUNC_MODE) || |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 688 | (iwl_read_prph(trans, APMG_PS_CTRL_REG) & |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 689 | APMG_PS_CTRL_VAL_RESET_REQ))) { |
| 690 | /* |
| 691 | * Keep the restart process from trying to send host |
| 692 | * commands by clearing the ready bit. |
| 693 | */ |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 694 | clear_bit(STATUS_READY, &trans->shrd->status); |
| 695 | clear_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status); |
Emmanuel Grumbach | ff6e75c | 2012-02-12 15:21:08 +0200 | [diff] [blame] | 696 | wake_up(&trans->shrd->wait_command_queue); |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 697 | IWL_ERR(trans, "RF is used by WiMAX\n"); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 698 | return; |
| 699 | } |
| 700 | |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 701 | IWL_ERR(trans, "Loaded firmware version: %s\n", |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame^] | 702 | trans->shrd->fw->fw_version); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 703 | |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 704 | iwl_dump_nic_error_log(trans); |
| 705 | iwl_dump_csr(trans); |
| 706 | iwl_dump_fh(trans, NULL, false); |
| 707 | iwl_dump_nic_event_log(trans, false, NULL, false); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 708 | |
Emmanuel Grumbach | bcb9321 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 709 | iwl_op_mode_nic_error(trans->op_mode); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 713 | |
| 714 | /** |
| 715 | * iwl_print_event_log - Dump error event log to syslog |
| 716 | * |
| 717 | */ |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 718 | static int iwl_print_event_log(struct iwl_trans *trans, u32 start_idx, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 719 | u32 num_events, u32 mode, |
| 720 | int pos, char **buf, size_t bufsz) |
| 721 | { |
| 722 | u32 i; |
| 723 | u32 base; /* SRAM byte address of event log header */ |
| 724 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 725 | u32 ptr; /* SRAM byte address of log data */ |
| 726 | u32 ev, time, data; /* event log data */ |
| 727 | unsigned long reg_flags; |
| 728 | |
| 729 | if (num_events == 0) |
| 730 | return pos; |
| 731 | |
Don Fry | ae6130f | 2011-11-30 16:12:59 -0800 | [diff] [blame] | 732 | base = trans->shrd->device_pointers.log_event_table; |
Don Fry | 3d6acef | 2011-11-28 17:05:01 -0800 | [diff] [blame] | 733 | if (trans->shrd->ucode_type == IWL_UCODE_INIT) { |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 734 | if (!base) |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame^] | 735 | base = trans->shrd->fw->init_evtlog_ptr; |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 736 | } else { |
| 737 | if (!base) |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame^] | 738 | base = trans->shrd->fw->inst_evtlog_ptr; |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | if (mode == 0) |
| 742 | event_size = 2 * sizeof(u32); |
| 743 | else |
| 744 | event_size = 3 * sizeof(u32); |
| 745 | |
| 746 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 747 | |
| 748 | /* Make sure device is powered up for SRAM reads */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 749 | spin_lock_irqsave(&trans->reg_lock, reg_flags); |
| 750 | iwl_grab_nic_access(trans); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 751 | |
| 752 | /* Set starting address; reads will auto-increment */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 753 | iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 754 | rmb(); |
| 755 | |
| 756 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 757 | * place event id # at far right for easier visual parsing. */ |
| 758 | for (i = 0; i < num_events; i++) { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 759 | ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT); |
| 760 | time = iwl_read32(trans, HBUS_TARG_MEM_RDAT); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 761 | if (mode == 0) { |
| 762 | /* data, ev */ |
| 763 | if (bufsz) { |
| 764 | pos += scnprintf(*buf + pos, bufsz - pos, |
| 765 | "EVT_LOG:0x%08x:%04u\n", |
| 766 | time, ev); |
| 767 | } else { |
Don Fry | 8655112 | 2012-02-07 14:03:55 -0800 | [diff] [blame] | 768 | trace_iwlwifi_dev_ucode_event(priv(trans), 0, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 769 | time, ev); |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 770 | IWL_ERR(trans, "EVT_LOG:0x%08x:%04u\n", |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 771 | time, ev); |
| 772 | } |
| 773 | } else { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 774 | data = iwl_read32(trans, HBUS_TARG_MEM_RDAT); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 775 | if (bufsz) { |
| 776 | pos += scnprintf(*buf + pos, bufsz - pos, |
| 777 | "EVT_LOGT:%010u:0x%08x:%04u\n", |
| 778 | time, data, ev); |
| 779 | } else { |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 780 | IWL_ERR(trans, "EVT_LOGT:%010u:0x%08x:%04u\n", |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 781 | time, data, ev); |
Don Fry | 8655112 | 2012-02-07 14:03:55 -0800 | [diff] [blame] | 782 | trace_iwlwifi_dev_ucode_event(priv(trans), time, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 783 | data, ev); |
| 784 | } |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | /* Allow device to power down */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 789 | iwl_release_nic_access(trans); |
| 790 | spin_unlock_irqrestore(&trans->reg_lock, reg_flags); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 791 | return pos; |
| 792 | } |
| 793 | |
| 794 | /** |
| 795 | * iwl_print_last_event_logs - Dump the newest # of event log to syslog |
| 796 | */ |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 797 | static int iwl_print_last_event_logs(struct iwl_trans *trans, u32 capacity, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 798 | u32 num_wraps, u32 next_entry, |
| 799 | u32 size, u32 mode, |
| 800 | int pos, char **buf, size_t bufsz) |
| 801 | { |
| 802 | /* |
| 803 | * display the newest DEFAULT_LOG_ENTRIES entries |
| 804 | * i.e the entries just before the next ont that uCode would fill. |
| 805 | */ |
| 806 | if (num_wraps) { |
| 807 | if (next_entry < size) { |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 808 | pos = iwl_print_event_log(trans, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 809 | capacity - (size - next_entry), |
| 810 | size - next_entry, mode, |
| 811 | pos, buf, bufsz); |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 812 | pos = iwl_print_event_log(trans, 0, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 813 | next_entry, mode, |
| 814 | pos, buf, bufsz); |
| 815 | } else |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 816 | pos = iwl_print_event_log(trans, next_entry - size, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 817 | size, mode, pos, buf, bufsz); |
| 818 | } else { |
| 819 | if (next_entry < size) { |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 820 | pos = iwl_print_event_log(trans, 0, next_entry, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 821 | mode, pos, buf, bufsz); |
| 822 | } else { |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 823 | pos = iwl_print_event_log(trans, next_entry - size, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 824 | size, mode, pos, buf, bufsz); |
| 825 | } |
| 826 | } |
| 827 | return pos; |
| 828 | } |
| 829 | |
| 830 | #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20) |
| 831 | |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 832 | int iwl_dump_nic_event_log(struct iwl_trans *trans, bool full_log, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 833 | char **buf, bool display) |
| 834 | { |
| 835 | u32 base; /* SRAM byte address of event log header */ |
| 836 | u32 capacity; /* event log capacity in # entries */ |
| 837 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 838 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 839 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 840 | u32 size; /* # entries that we'll print */ |
| 841 | u32 logsize; |
| 842 | int pos = 0; |
| 843 | size_t bufsz = 0; |
| 844 | |
Don Fry | ae6130f | 2011-11-30 16:12:59 -0800 | [diff] [blame] | 845 | base = trans->shrd->device_pointers.log_event_table; |
Don Fry | 3d6acef | 2011-11-28 17:05:01 -0800 | [diff] [blame] | 846 | if (trans->shrd->ucode_type == IWL_UCODE_INIT) { |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame^] | 847 | logsize = trans->shrd->fw->init_evtlog_size; |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 848 | if (!base) |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame^] | 849 | base = trans->shrd->fw->init_evtlog_ptr; |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 850 | } else { |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame^] | 851 | logsize = trans->shrd->fw->inst_evtlog_size; |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 852 | if (!base) |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame^] | 853 | base = trans->shrd->fw->inst_evtlog_ptr; |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | if (!iwlagn_hw_valid_rtc_data_addr(base)) { |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 857 | IWL_ERR(trans, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 858 | "Invalid event log pointer 0x%08X for %s uCode\n", |
| 859 | base, |
Don Fry | 3d6acef | 2011-11-28 17:05:01 -0800 | [diff] [blame] | 860 | (trans->shrd->ucode_type == IWL_UCODE_INIT) |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 861 | ? "Init" : "RT"); |
| 862 | return -EINVAL; |
| 863 | } |
| 864 | |
| 865 | /* event log header */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 866 | capacity = iwl_read_targ_mem(trans, base); |
| 867 | mode = iwl_read_targ_mem(trans, base + (1 * sizeof(u32))); |
| 868 | num_wraps = iwl_read_targ_mem(trans, base + (2 * sizeof(u32))); |
| 869 | next_entry = iwl_read_targ_mem(trans, base + (3 * sizeof(u32))); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 870 | |
| 871 | if (capacity > logsize) { |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 872 | IWL_ERR(trans, "Log capacity %d is bogus, limit to %d " |
| 873 | "entries\n", capacity, logsize); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 874 | capacity = logsize; |
| 875 | } |
| 876 | |
| 877 | if (next_entry > logsize) { |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 878 | IWL_ERR(trans, "Log write index %d is bogus, limit to %d\n", |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 879 | next_entry, logsize); |
| 880 | next_entry = logsize; |
| 881 | } |
| 882 | |
| 883 | size = num_wraps ? capacity : next_entry; |
| 884 | |
| 885 | /* bail out if nothing in log */ |
| 886 | if (size == 0) { |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 887 | IWL_ERR(trans, "Start IWL Event Log Dump: nothing in log\n"); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 888 | return pos; |
| 889 | } |
| 890 | |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 891 | #ifdef CONFIG_IWLWIFI_DEBUG |
Johannes Berg | a8bceb3 | 2012-03-05 11:24:30 -0800 | [diff] [blame] | 892 | if (!(iwl_have_debug_level(IWL_DL_FW_ERRORS)) && !full_log) |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 893 | size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES) |
| 894 | ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size; |
| 895 | #else |
| 896 | size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES) |
| 897 | ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size; |
| 898 | #endif |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 899 | IWL_ERR(trans, "Start IWL Event Log Dump: display last %u entries\n", |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 900 | size); |
| 901 | |
| 902 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 903 | if (display) { |
| 904 | if (full_log) |
| 905 | bufsz = capacity * 48; |
| 906 | else |
| 907 | bufsz = size * 48; |
| 908 | *buf = kmalloc(bufsz, GFP_KERNEL); |
| 909 | if (!*buf) |
| 910 | return -ENOMEM; |
| 911 | } |
Johannes Berg | a8bceb3 | 2012-03-05 11:24:30 -0800 | [diff] [blame] | 912 | if (iwl_have_debug_level(IWL_DL_FW_ERRORS) || full_log) { |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 913 | /* |
| 914 | * if uCode has wrapped back to top of log, |
| 915 | * start at the oldest entry, |
| 916 | * i.e the next one that uCode would fill. |
| 917 | */ |
| 918 | if (num_wraps) |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 919 | pos = iwl_print_event_log(trans, next_entry, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 920 | capacity - next_entry, mode, |
| 921 | pos, buf, bufsz); |
| 922 | /* (then/else) start at top of log */ |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 923 | pos = iwl_print_event_log(trans, 0, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 924 | next_entry, mode, pos, buf, bufsz); |
| 925 | } else |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 926 | pos = iwl_print_last_event_logs(trans, capacity, num_wraps, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 927 | next_entry, size, mode, |
| 928 | pos, buf, bufsz); |
| 929 | #else |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 930 | pos = iwl_print_last_event_logs(trans, capacity, num_wraps, |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 931 | next_entry, size, mode, |
| 932 | pos, buf, bufsz); |
| 933 | #endif |
| 934 | return pos; |
| 935 | } |
| 936 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 937 | /* tasklet for iwlagn interrupt */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 938 | void iwl_irq_tasklet(struct iwl_trans *trans) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 939 | { |
| 940 | u32 inta = 0; |
| 941 | u32 handled = 0; |
| 942 | unsigned long flags; |
| 943 | u32 i; |
| 944 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 945 | u32 inta_mask; |
| 946 | #endif |
| 947 | |
Emmanuel Grumbach | 3e10cae | 2011-09-06 09:31:18 -0700 | [diff] [blame] | 948 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 949 | struct isr_statistics *isr_stats = &trans_pcie->isr_stats; |
| 950 | |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 951 | |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 952 | spin_lock_irqsave(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 953 | |
| 954 | /* Ack/clear/reset pending uCode interrupts. |
| 955 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 956 | */ |
| 957 | /* There is a hardware bug in the interrupt mask function that some |
| 958 | * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if |
| 959 | * they are disabled in the CSR_INT_MASK register. Furthermore the |
| 960 | * ICT interrupt handling mechanism has another bug that might cause |
| 961 | * these unmasked interrupts fail to be detected. We workaround the |
| 962 | * hardware bugs here by ACKing all the possible interrupts so that |
| 963 | * interrupt coalescing can still be achieved. |
| 964 | */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 965 | iwl_write32(trans, CSR_INT, |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 966 | trans_pcie->inta | ~trans_pcie->inta_mask); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 967 | |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 968 | inta = trans_pcie->inta; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 969 | |
| 970 | #ifdef CONFIG_IWLWIFI_DEBUG |
Johannes Berg | a8bceb3 | 2012-03-05 11:24:30 -0800 | [diff] [blame] | 971 | if (iwl_have_debug_level(IWL_DL_ISR)) { |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 972 | /* just for debug */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 973 | inta_mask = iwl_read32(trans, CSR_INT_MASK); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 974 | IWL_DEBUG_ISR(trans, "inta 0x%08x, enabled 0x%08x\n ", |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 975 | inta, inta_mask); |
| 976 | } |
| 977 | #endif |
| 978 | |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 979 | /* saved interrupt in inta variable now we can reset trans_pcie->inta */ |
| 980 | trans_pcie->inta = 0; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 981 | |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 982 | spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); |
Johannes Berg | b49ba04 | 2012-01-19 08:20:57 -0800 | [diff] [blame] | 983 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 984 | /* Now service all interrupt bits discovered above. */ |
| 985 | if (inta & CSR_INT_BIT_HW_ERR) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 986 | IWL_ERR(trans, "Hardware error detected. Restarting.\n"); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 987 | |
| 988 | /* Tell the device to stop sending interrupts */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 989 | iwl_disable_interrupts(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 990 | |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 991 | isr_stats->hw++; |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 992 | iwl_irq_handle_error(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 993 | |
| 994 | handled |= CSR_INT_BIT_HW_ERR; |
| 995 | |
| 996 | return; |
| 997 | } |
| 998 | |
| 999 | #ifdef CONFIG_IWLWIFI_DEBUG |
Johannes Berg | a8bceb3 | 2012-03-05 11:24:30 -0800 | [diff] [blame] | 1000 | if (iwl_have_debug_level(IWL_DL_ISR)) { |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1001 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
| 1002 | if (inta & CSR_INT_BIT_SCD) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1003 | IWL_DEBUG_ISR(trans, "Scheduler finished to transmit " |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1004 | "the frame/frames.\n"); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1005 | isr_stats->sch++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /* Alive notification via Rx interrupt will do the real work */ |
| 1009 | if (inta & CSR_INT_BIT_ALIVE) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1010 | IWL_DEBUG_ISR(trans, "Alive interrupt\n"); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1011 | isr_stats->alive++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1012 | } |
| 1013 | } |
| 1014 | #endif |
| 1015 | /* Safely ignore these bits for debug checks below */ |
| 1016 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
| 1017 | |
| 1018 | /* HW RF KILL switch toggled */ |
| 1019 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 1020 | int hw_rf_kill = 0; |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1021 | if (!(iwl_read32(trans, CSR_GP_CNTRL) & |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1022 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 1023 | hw_rf_kill = 1; |
| 1024 | |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1025 | IWL_WARN(trans, "RF_KILL bit toggled to %s.\n", |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1026 | hw_rf_kill ? "disable radio" : "enable radio"); |
| 1027 | |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1028 | isr_stats->rfkill++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1029 | |
| 1030 | /* driver only loads ucode once setting the interface up. |
| 1031 | * the driver allows loading the ucode even if the radio |
| 1032 | * is killed. Hence update the killswitch state here. The |
| 1033 | * rfkill handler will care about restarting if needed. |
| 1034 | */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1035 | if (!test_bit(STATUS_ALIVE, &trans->shrd->status)) { |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1036 | if (hw_rf_kill) |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1037 | set_bit(STATUS_RF_KILL_HW, |
| 1038 | &trans->shrd->status); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1039 | else |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 1040 | clear_bit(STATUS_RF_KILL_HW, |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1041 | &trans->shrd->status); |
Emmanuel Grumbach | 7120d98 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1042 | iwl_op_mode_hw_rf_kill(trans->op_mode, hw_rf_kill); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | handled |= CSR_INT_BIT_RF_KILL; |
| 1046 | } |
| 1047 | |
| 1048 | /* Chip got too hot and stopped itself */ |
| 1049 | if (inta & CSR_INT_BIT_CT_KILL) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1050 | IWL_ERR(trans, "Microcode CT kill error detected.\n"); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1051 | isr_stats->ctkill++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1052 | handled |= CSR_INT_BIT_CT_KILL; |
| 1053 | } |
| 1054 | |
| 1055 | /* Error detected by uCode */ |
| 1056 | if (inta & CSR_INT_BIT_SW_ERR) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1057 | IWL_ERR(trans, "Microcode SW error detected. " |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1058 | " Restarting 0x%X.\n", inta); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1059 | isr_stats->sw++; |
Emmanuel Grumbach | 6bb7884 | 2011-08-25 23:11:09 -0700 | [diff] [blame] | 1060 | iwl_irq_handle_error(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1061 | handled |= CSR_INT_BIT_SW_ERR; |
| 1062 | } |
| 1063 | |
| 1064 | /* uCode wakes up after power-down sleep */ |
| 1065 | if (inta & CSR_INT_BIT_WAKEUP) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1066 | IWL_DEBUG_ISR(trans, "Wakeup interrupt\n"); |
| 1067 | iwl_rx_queue_update_write_ptr(trans, &trans_pcie->rxq); |
| 1068 | for (i = 0; i < hw_params(trans).max_txq_num; i++) |
Emmanuel Grumbach | fd65693 | 2011-08-25 23:11:19 -0700 | [diff] [blame] | 1069 | iwl_txq_update_write_ptr(trans, |
Emmanuel Grumbach | 8ad71be | 2011-08-25 23:11:32 -0700 | [diff] [blame] | 1070 | &trans_pcie->txq[i]); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1071 | |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1072 | isr_stats->wakeup++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1073 | |
| 1074 | handled |= CSR_INT_BIT_WAKEUP; |
| 1075 | } |
| 1076 | |
| 1077 | /* All uCode command responses, including Tx command responses, |
| 1078 | * Rx "responses" (frame-received notification), and other |
| 1079 | * notifications from uCode come through here*/ |
| 1080 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX | |
| 1081 | CSR_INT_BIT_RX_PERIODIC)) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1082 | IWL_DEBUG_ISR(trans, "Rx interrupt\n"); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1083 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
| 1084 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1085 | iwl_write32(trans, CSR_FH_INT_STATUS, |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1086 | CSR_FH_INT_RX_MASK); |
| 1087 | } |
| 1088 | if (inta & CSR_INT_BIT_RX_PERIODIC) { |
| 1089 | handled |= CSR_INT_BIT_RX_PERIODIC; |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1090 | iwl_write32(trans, |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1091 | CSR_INT, CSR_INT_BIT_RX_PERIODIC); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1092 | } |
| 1093 | /* Sending RX interrupt require many steps to be done in the |
| 1094 | * the device: |
| 1095 | * 1- write interrupt to current index in ICT table. |
| 1096 | * 2- dma RX frame. |
| 1097 | * 3- update RX shared data to indicate last write index. |
| 1098 | * 4- send interrupt. |
| 1099 | * This could lead to RX race, driver could receive RX interrupt |
| 1100 | * but the shared data changes does not reflect this; |
| 1101 | * periodic interrupt will detect any dangling Rx activity. |
| 1102 | */ |
| 1103 | |
| 1104 | /* Disable periodic interrupt; we use it as just a one-shot. */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1105 | iwl_write8(trans, CSR_INT_PERIODIC_REG, |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1106 | CSR_INT_PERIODIC_DIS); |
Gregory Greenman | a591697 | 2012-01-10 19:22:56 +0200 | [diff] [blame] | 1107 | #ifdef CONFIG_IWLWIFI_IDI |
| 1108 | iwl_amfh_rx_handler(); |
| 1109 | #else |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1110 | iwl_rx_handle(trans); |
Gregory Greenman | a591697 | 2012-01-10 19:22:56 +0200 | [diff] [blame] | 1111 | #endif |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1112 | /* |
| 1113 | * Enable periodic interrupt in 8 msec only if we received |
| 1114 | * real RX interrupt (instead of just periodic int), to catch |
| 1115 | * any dangling Rx interrupt. If it was just the periodic |
| 1116 | * interrupt, there was no dangling Rx activity, and no need |
| 1117 | * to extend the periodic interrupt; one-shot is enough. |
| 1118 | */ |
| 1119 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1120 | iwl_write8(trans, CSR_INT_PERIODIC_REG, |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1121 | CSR_INT_PERIODIC_ENA); |
| 1122 | |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1123 | isr_stats->rx++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | /* This "Tx" DMA channel is used only for loading uCode */ |
| 1127 | if (inta & CSR_INT_BIT_FH_TX) { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1128 | iwl_write32(trans, CSR_FH_INT_STATUS, CSR_FH_INT_TX_MASK); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1129 | IWL_DEBUG_ISR(trans, "uCode load interrupt\n"); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1130 | isr_stats->tx++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1131 | handled |= CSR_INT_BIT_FH_TX; |
| 1132 | /* Wake up uCode load routine, now that load is complete */ |
Don Fry | 5703ddb | 2011-11-10 06:55:07 -0800 | [diff] [blame] | 1133 | trans->ucode_write_complete = 1; |
Johannes Berg | effd4d9 | 2011-09-15 11:46:52 -0700 | [diff] [blame] | 1134 | wake_up(&trans->shrd->wait_command_queue); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | if (inta & ~handled) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1138 | IWL_ERR(trans, "Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1139 | isr_stats->unhandled++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1142 | if (inta & ~(trans_pcie->inta_mask)) { |
| 1143 | IWL_WARN(trans, "Disabled INTA bits 0x%08x were pending\n", |
| 1144 | inta & ~trans_pcie->inta_mask); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | /* Re-enable all interrupts */ |
| 1148 | /* only Re-enable if disabled by irq */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1149 | if (test_bit(STATUS_INT_ENABLED, &trans->shrd->status)) |
| 1150 | iwl_enable_interrupts(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1151 | /* Re-enable RF_KILL if it occurred */ |
Emmanuel Grumbach | 1df06bd | 2012-01-09 16:35:08 +0200 | [diff] [blame] | 1152 | else if (handled & CSR_INT_BIT_RF_KILL) { |
| 1153 | IWL_DEBUG_ISR(trans, "Enabling rfkill interrupt\n"); |
| 1154 | iwl_write32(trans, CSR_INT_MASK, CSR_INT_BIT_RF_KILL); |
| 1155 | } |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1158 | /****************************************************************************** |
| 1159 | * |
| 1160 | * ICT functions |
| 1161 | * |
| 1162 | ******************************************************************************/ |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1163 | |
| 1164 | /* a device (PCI-E) page is 4096 bytes long */ |
| 1165 | #define ICT_SHIFT 12 |
| 1166 | #define ICT_SIZE (1 << ICT_SHIFT) |
| 1167 | #define ICT_COUNT (ICT_SIZE / sizeof(u32)) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1168 | |
| 1169 | /* Free dram table */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1170 | void iwl_free_isr_ict(struct iwl_trans *trans) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1171 | { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1172 | struct iwl_trans_pcie *trans_pcie = |
| 1173 | IWL_TRANS_GET_PCIE_TRANS(trans); |
| 1174 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1175 | if (trans_pcie->ict_tbl) { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1176 | dma_free_coherent(trans->dev, ICT_SIZE, |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1177 | trans_pcie->ict_tbl, |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1178 | trans_pcie->ict_tbl_dma); |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1179 | trans_pcie->ict_tbl = NULL; |
| 1180 | trans_pcie->ict_tbl_dma = 0; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1185 | /* |
| 1186 | * allocate dram shared table, it is an aligned memory |
| 1187 | * block of ICT_SIZE. |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1188 | * also reset all data related to ICT table interrupt. |
| 1189 | */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1190 | int iwl_alloc_isr_ict(struct iwl_trans *trans) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1191 | { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1192 | struct iwl_trans_pcie *trans_pcie = |
| 1193 | IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1194 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1195 | trans_pcie->ict_tbl = |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1196 | dma_alloc_coherent(trans->dev, ICT_SIZE, |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1197 | &trans_pcie->ict_tbl_dma, |
| 1198 | GFP_KERNEL); |
| 1199 | if (!trans_pcie->ict_tbl) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1200 | return -ENOMEM; |
| 1201 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1202 | /* just an API sanity check ... it is guaranteed to be aligned */ |
| 1203 | if (WARN_ON(trans_pcie->ict_tbl_dma & (ICT_SIZE - 1))) { |
| 1204 | iwl_free_isr_ict(trans); |
| 1205 | return -EINVAL; |
| 1206 | } |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1207 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1208 | IWL_DEBUG_ISR(trans, "ict dma addr %Lx\n", |
| 1209 | (unsigned long long)trans_pcie->ict_tbl_dma); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1210 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1211 | IWL_DEBUG_ISR(trans, "ict vir addr %p\n", trans_pcie->ict_tbl); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1212 | |
| 1213 | /* reset table and index to all 0 */ |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1214 | memset(trans_pcie->ict_tbl, 0, ICT_SIZE); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1215 | trans_pcie->ict_index = 0; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1216 | |
| 1217 | /* add periodic RX interrupt */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1218 | trans_pcie->inta_mask |= CSR_INT_BIT_RX_PERIODIC; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1219 | return 0; |
| 1220 | } |
| 1221 | |
| 1222 | /* Device is going up inform it about using ICT interrupt table, |
| 1223 | * also we need to tell the driver to start using ICT interrupt. |
| 1224 | */ |
Emmanuel Grumbach | ed6a380 | 2012-01-02 16:10:08 +0200 | [diff] [blame] | 1225 | void iwl_reset_ict(struct iwl_trans *trans) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1226 | { |
| 1227 | u32 val; |
| 1228 | unsigned long flags; |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1229 | struct iwl_trans_pcie *trans_pcie = |
| 1230 | IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1231 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1232 | if (!trans_pcie->ict_tbl) |
Emmanuel Grumbach | ed6a380 | 2012-01-02 16:10:08 +0200 | [diff] [blame] | 1233 | return; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1234 | |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 1235 | spin_lock_irqsave(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1236 | iwl_disable_interrupts(trans); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1237 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1238 | memset(trans_pcie->ict_tbl, 0, ICT_SIZE); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1239 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1240 | val = trans_pcie->ict_tbl_dma >> ICT_SHIFT; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1241 | |
| 1242 | val |= CSR_DRAM_INT_TBL_ENABLE; |
| 1243 | val |= CSR_DRAM_INIT_TBL_WRAP_CHECK; |
| 1244 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1245 | IWL_DEBUG_ISR(trans, "CSR_DRAM_INT_TBL_REG =0x%x\n", val); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1246 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1247 | iwl_write32(trans, CSR_DRAM_INT_TBL_REG, val); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1248 | trans_pcie->use_ict = true; |
| 1249 | trans_pcie->ict_index = 0; |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1250 | iwl_write32(trans, CSR_INT, trans_pcie->inta_mask); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1251 | iwl_enable_interrupts(trans); |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 1252 | spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | /* Device is going down disable ict interrupt usage */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1256 | void iwl_disable_ict(struct iwl_trans *trans) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1257 | { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1258 | struct iwl_trans_pcie *trans_pcie = |
| 1259 | IWL_TRANS_GET_PCIE_TRANS(trans); |
| 1260 | |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1261 | unsigned long flags; |
| 1262 | |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 1263 | spin_lock_irqsave(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1264 | trans_pcie->use_ict = false; |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 1265 | spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | static irqreturn_t iwl_isr(int irq, void *data) |
| 1269 | { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1270 | struct iwl_trans *trans = data; |
| 1271 | struct iwl_trans_pcie *trans_pcie; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1272 | u32 inta, inta_mask; |
| 1273 | unsigned long flags; |
| 1274 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 1275 | u32 inta_fh; |
| 1276 | #endif |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1277 | if (!trans) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1278 | return IRQ_NONE; |
| 1279 | |
Johannes Berg | b80667e | 2011-12-09 07:26:13 -0800 | [diff] [blame] | 1280 | trace_iwlwifi_dev_irq(priv(trans)); |
| 1281 | |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1282 | trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 1283 | |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 1284 | spin_lock_irqsave(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1285 | |
| 1286 | /* Disable (but don't clear!) interrupts here to avoid |
| 1287 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 1288 | * If we have something to service, the tasklet will re-enable ints. |
| 1289 | * If we *don't* have something, we'll re-enable before leaving here. */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1290 | inta_mask = iwl_read32(trans, CSR_INT_MASK); /* just for debug */ |
| 1291 | iwl_write32(trans, CSR_INT_MASK, 0x00000000); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1292 | |
| 1293 | /* Discover which interrupts are active/pending */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1294 | inta = iwl_read32(trans, CSR_INT); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1295 | |
| 1296 | /* Ignore interrupt if there's nothing in NIC to service. |
| 1297 | * This may be due to IRQ shared with another device, |
| 1298 | * or due to sporadic interrupts thrown from our NIC. */ |
| 1299 | if (!inta) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1300 | IWL_DEBUG_ISR(trans, "Ignore interrupt, inta == 0\n"); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1301 | goto none; |
| 1302 | } |
| 1303 | |
| 1304 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
| 1305 | /* Hardware disappeared. It might have already raised |
| 1306 | * an interrupt */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1307 | IWL_WARN(trans, "HARDWARE GONE?? INTA == 0x%08x\n", inta); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1308 | goto unplugged; |
| 1309 | } |
| 1310 | |
| 1311 | #ifdef CONFIG_IWLWIFI_DEBUG |
Johannes Berg | a8bceb3 | 2012-03-05 11:24:30 -0800 | [diff] [blame] | 1312 | if (iwl_have_debug_level(IWL_DL_ISR)) { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1313 | inta_fh = iwl_read32(trans, CSR_FH_INT_STATUS); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1314 | IWL_DEBUG_ISR(trans, "ISR inta 0x%08x, enabled 0x%08x, " |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1315 | "fh 0x%08x\n", inta, inta_mask, inta_fh); |
| 1316 | } |
| 1317 | #endif |
| 1318 | |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1319 | trans_pcie->inta |= inta; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1320 | /* iwl_irq_tasklet() will service interrupts and re-enable them */ |
| 1321 | if (likely(inta)) |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1322 | tasklet_schedule(&trans_pcie->irq_tasklet); |
| 1323 | else if (test_bit(STATUS_INT_ENABLED, &trans->shrd->status) && |
| 1324 | !trans_pcie->inta) |
| 1325 | iwl_enable_interrupts(trans); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1326 | |
| 1327 | unplugged: |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 1328 | spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1329 | return IRQ_HANDLED; |
| 1330 | |
| 1331 | none: |
| 1332 | /* re-enable interrupts here since we don't have anything to service. */ |
| 1333 | /* only Re-enable if disabled by irq and no schedules tasklet. */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1334 | if (test_bit(STATUS_INT_ENABLED, &trans->shrd->status) && |
| 1335 | !trans_pcie->inta) |
| 1336 | iwl_enable_interrupts(trans); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1337 | |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 1338 | spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1339 | return IRQ_NONE; |
| 1340 | } |
| 1341 | |
| 1342 | /* interrupt handler using ict table, with this interrupt driver will |
| 1343 | * stop using INTA register to get device's interrupt, reading this register |
| 1344 | * is expensive, device will write interrupts in ICT dram table, increment |
| 1345 | * index then will fire interrupt to driver, driver will OR all ICT table |
| 1346 | * entries from current index up to table entry with 0 value. the result is |
| 1347 | * the interrupt we need to service, driver will set the entries back to 0 and |
| 1348 | * set index. |
| 1349 | */ |
| 1350 | irqreturn_t iwl_isr_ict(int irq, void *data) |
| 1351 | { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1352 | struct iwl_trans *trans = data; |
| 1353 | struct iwl_trans_pcie *trans_pcie; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1354 | u32 inta, inta_mask; |
| 1355 | u32 val = 0; |
Johannes Berg | b80667e | 2011-12-09 07:26:13 -0800 | [diff] [blame] | 1356 | u32 read; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1357 | unsigned long flags; |
| 1358 | |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1359 | if (!trans) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1360 | return IRQ_NONE; |
| 1361 | |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1362 | trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 1363 | |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1364 | /* dram interrupt table not set yet, |
| 1365 | * use legacy interrupt. |
| 1366 | */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1367 | if (!trans_pcie->use_ict) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1368 | return iwl_isr(irq, data); |
| 1369 | |
Johannes Berg | b80667e | 2011-12-09 07:26:13 -0800 | [diff] [blame] | 1370 | trace_iwlwifi_dev_irq(priv(trans)); |
| 1371 | |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 1372 | spin_lock_irqsave(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1373 | |
| 1374 | /* Disable (but don't clear!) interrupts here to avoid |
| 1375 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 1376 | * If we have something to service, the tasklet will re-enable ints. |
| 1377 | * If we *don't* have something, we'll re-enable before leaving here. |
| 1378 | */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1379 | inta_mask = iwl_read32(trans, CSR_INT_MASK); /* just for debug */ |
| 1380 | iwl_write32(trans, CSR_INT_MASK, 0x00000000); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1381 | |
| 1382 | |
| 1383 | /* Ignore interrupt if there's nothing in NIC to service. |
| 1384 | * This may be due to IRQ shared with another device, |
| 1385 | * or due to sporadic interrupts thrown from our NIC. */ |
Johannes Berg | b80667e | 2011-12-09 07:26:13 -0800 | [diff] [blame] | 1386 | read = le32_to_cpu(trans_pcie->ict_tbl[trans_pcie->ict_index]); |
| 1387 | trace_iwlwifi_dev_ict_read(priv(trans), trans_pcie->ict_index, read); |
| 1388 | if (!read) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1389 | IWL_DEBUG_ISR(trans, "Ignore interrupt, inta == 0\n"); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1390 | goto none; |
| 1391 | } |
| 1392 | |
Johannes Berg | b80667e | 2011-12-09 07:26:13 -0800 | [diff] [blame] | 1393 | /* |
| 1394 | * Collect all entries up to the first 0, starting from ict_index; |
| 1395 | * note we already read at ict_index. |
| 1396 | */ |
| 1397 | do { |
| 1398 | val |= read; |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1399 | IWL_DEBUG_ISR(trans, "ICT index %d value 0x%08X\n", |
Johannes Berg | b80667e | 2011-12-09 07:26:13 -0800 | [diff] [blame] | 1400 | trans_pcie->ict_index, read); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1401 | trans_pcie->ict_tbl[trans_pcie->ict_index] = 0; |
| 1402 | trans_pcie->ict_index = |
| 1403 | iwl_queue_inc_wrap(trans_pcie->ict_index, ICT_COUNT); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1404 | |
Johannes Berg | b80667e | 2011-12-09 07:26:13 -0800 | [diff] [blame] | 1405 | read = le32_to_cpu(trans_pcie->ict_tbl[trans_pcie->ict_index]); |
| 1406 | trace_iwlwifi_dev_ict_read(priv(trans), trans_pcie->ict_index, |
| 1407 | read); |
| 1408 | } while (read); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1409 | |
| 1410 | /* We should not get this value, just ignore it. */ |
| 1411 | if (val == 0xffffffff) |
| 1412 | val = 0; |
| 1413 | |
| 1414 | /* |
| 1415 | * this is a w/a for a h/w bug. the h/w bug may cause the Rx bit |
| 1416 | * (bit 15 before shifting it to 31) to clear when using interrupt |
| 1417 | * coalescing. fortunately, bits 18 and 19 stay set when this happens |
| 1418 | * so we use them to decide on the real state of the Rx bit. |
| 1419 | * In order words, bit 15 is set if bit 18 or bit 19 are set. |
| 1420 | */ |
| 1421 | if (val & 0xC0000) |
| 1422 | val |= 0x8000; |
| 1423 | |
| 1424 | inta = (0xff & val) | ((0xff00 & val) << 16); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1425 | IWL_DEBUG_ISR(trans, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n", |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1426 | inta, inta_mask, val); |
| 1427 | |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1428 | inta &= trans_pcie->inta_mask; |
| 1429 | trans_pcie->inta |= inta; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1430 | |
| 1431 | /* iwl_irq_tasklet() will service interrupts and re-enable them */ |
| 1432 | if (likely(inta)) |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1433 | tasklet_schedule(&trans_pcie->irq_tasklet); |
| 1434 | else if (test_bit(STATUS_INT_ENABLED, &trans->shrd->status) && |
Johannes Berg | b80667e | 2011-12-09 07:26:13 -0800 | [diff] [blame] | 1435 | !trans_pcie->inta) { |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1436 | /* Allow interrupt if was disabled by this handler and |
| 1437 | * no tasklet was schedules, We should not enable interrupt, |
| 1438 | * tasklet will enable it. |
| 1439 | */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1440 | iwl_enable_interrupts(trans); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 1443 | spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1444 | return IRQ_HANDLED; |
| 1445 | |
| 1446 | none: |
| 1447 | /* re-enable interrupts here since we don't have anything to service. |
| 1448 | * only Re-enable if disabled by irq. |
| 1449 | */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1450 | if (test_bit(STATUS_INT_ENABLED, &trans->shrd->status) && |
Johannes Berg | b80667e | 2011-12-09 07:26:13 -0800 | [diff] [blame] | 1451 | !trans_pcie->inta) |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1452 | iwl_enable_interrupts(trans); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1453 | |
Johannes Berg | 7b11488 | 2012-02-05 13:55:11 -0800 | [diff] [blame] | 1454 | spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1455 | return IRQ_NONE; |
| 1456 | } |