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