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