Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved. |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 5 | * |
| 6 | * Portions of this file are derived from the ipw3945 project, as well |
| 7 | * as portions of the ieee80211 subsystem header files. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 16 | * more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 21 | * |
| 22 | * The full GNU General Public License is included in this distribution in the |
| 23 | * file called LICENSE. |
| 24 | * |
| 25 | * Contact Information: |
| 26 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 27 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 28 | * |
| 29 | *****************************************************************************/ |
| 30 | #include <linux/sched.h> |
| 31 | #include <linux/wait.h> |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 32 | #include <linux/gfp.h> |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 33 | |
Johannes Berg | 1b29dc9 | 2012-03-06 13:30:50 -0800 | [diff] [blame] | 34 | #include "iwl-prph.h" |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 35 | #include "iwl-io.h" |
Johannes Berg | 6468a01 | 2012-05-16 19:13:54 +0200 | [diff] [blame] | 36 | #include "internal.h" |
Emmanuel Grumbach | db70f29 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 37 | #include "iwl-op-mode.h" |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 38 | |
| 39 | /****************************************************************************** |
| 40 | * |
| 41 | * RX path functions |
| 42 | * |
| 43 | ******************************************************************************/ |
| 44 | |
| 45 | /* |
| 46 | * Rx theory of operation |
| 47 | * |
| 48 | * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs), |
| 49 | * each of which point to Receive Buffers to be filled by the NIC. These get |
| 50 | * used not only for Rx frames, but for any command response or notification |
| 51 | * from the NIC. The driver and NIC manage the Rx buffers by means |
| 52 | * of indexes into the circular buffer. |
| 53 | * |
| 54 | * Rx Queue Indexes |
| 55 | * The host/firmware share two index registers for managing the Rx buffers. |
| 56 | * |
| 57 | * The READ index maps to the first position that the firmware may be writing |
| 58 | * to -- the driver can read up to (but not including) this position and get |
| 59 | * good data. |
| 60 | * The READ index is managed by the firmware once the card is enabled. |
| 61 | * |
| 62 | * The WRITE index maps to the last position the driver has read from -- the |
| 63 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 64 | * |
| 65 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 66 | * WRITE = READ. |
| 67 | * |
| 68 | * During initialization, the host sets up the READ queue position to the first |
| 69 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 70 | * |
| 71 | * When the firmware places a packet in a buffer, it will advance the READ index |
| 72 | * and fire the RX interrupt. The driver can then query the READ index and |
| 73 | * process as many packets as possible, moving the WRITE index forward as it |
| 74 | * resets the Rx queue buffers with new memory. |
| 75 | * |
| 76 | * The management in the driver is as follows: |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 77 | * + A list of pre-allocated RBDs is stored in iwl->rxq->rx_free. |
| 78 | * When the interrupt handler is called, the request is processed. |
| 79 | * The page is either stolen - transferred to the upper layer |
| 80 | * or reused - added immediately to the iwl->rxq->rx_free list. |
| 81 | * + When the page is stolen - the driver updates the matching queue's used |
| 82 | * count, detaches the RBD and transfers it to the queue used list. |
| 83 | * When there are two used RBDs - they are transferred to the allocator empty |
| 84 | * list. Work is then scheduled for the allocator to start allocating |
| 85 | * eight buffers. |
| 86 | * When there are another 6 used RBDs - they are transferred to the allocator |
| 87 | * empty list and the driver tries to claim the pre-allocated buffers and |
| 88 | * add them to iwl->rxq->rx_free. If it fails - it continues to claim them |
| 89 | * until ready. |
| 90 | * When there are 8+ buffers in the free list - either from allocation or from |
| 91 | * 8 reused unstolen pages - restock is called to update the FW and indexes. |
| 92 | * + In order to make sure the allocator always has RBDs to use for allocation |
| 93 | * the allocator has initial pool in the size of num_queues*(8-2) - the |
| 94 | * maximum missing RBDs per allocation request (request posted with 2 |
| 95 | * empty RBDs, there is no guarantee when the other 6 RBDs are supplied). |
| 96 | * The queues supplies the recycle of the rest of the RBDs. |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 97 | * + A received packet is processed and handed to the kernel network stack, |
| 98 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 99 | * + If there are no allocated buffers in iwl->rxq->rx_free, |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 100 | * the READ INDEX is not incremented and iwl->status(RX_STALLED) is set. |
| 101 | * If there were enough free buffers and RX_STALLED is set it is cleared. |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 102 | * |
| 103 | * |
| 104 | * Driver sequence: |
| 105 | * |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 106 | * iwl_rxq_alloc() Allocates rx_free |
| 107 | * iwl_pcie_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 108 | * iwl_pcie_rxq_restock. |
| 109 | * Used only during initialization. |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 110 | * iwl_pcie_rxq_restock() Moves available buffers from rx_free into Rx |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 111 | * queue, updates firmware pointers, and updates |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 112 | * the WRITE index. |
| 113 | * iwl_pcie_rx_allocator() Background work for allocating pages. |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 114 | * |
| 115 | * -- enable interrupts -- |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 116 | * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 117 | * READ INDEX, detaching the SKB from the pool. |
| 118 | * Moves the packet buffer from queue to rx_used. |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 119 | * Posts and claims requests to the allocator. |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 120 | * Calls iwl_pcie_rxq_restock to refill any empty |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 121 | * slots. |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 122 | * |
| 123 | * RBD life-cycle: |
| 124 | * |
| 125 | * Init: |
| 126 | * rxq.pool -> rxq.rx_used -> rxq.rx_free -> rxq.queue |
| 127 | * |
| 128 | * Regular Receive interrupt: |
| 129 | * Page Stolen: |
| 130 | * rxq.queue -> rxq.rx_used -> allocator.rbd_empty -> |
| 131 | * allocator.rbd_allocated -> rxq.rx_free -> rxq.queue |
| 132 | * Page not Stolen: |
| 133 | * rxq.queue -> rxq.rx_free -> rxq.queue |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 134 | * ... |
| 135 | * |
| 136 | */ |
| 137 | |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 138 | /* |
| 139 | * iwl_rxq_space - Return number of free slots available in queue. |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 140 | */ |
Johannes Berg | fecba09 | 2013-06-20 21:56:49 +0200 | [diff] [blame] | 141 | static int iwl_rxq_space(const struct iwl_rxq *rxq) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 142 | { |
Ido Yariv | 351746c | 2013-07-15 12:41:27 -0400 | [diff] [blame] | 143 | /* Make sure RX_QUEUE_SIZE is a power of 2 */ |
| 144 | BUILD_BUG_ON(RX_QUEUE_SIZE & (RX_QUEUE_SIZE - 1)); |
Johannes Berg | fecba09 | 2013-06-20 21:56:49 +0200 | [diff] [blame] | 145 | |
Ido Yariv | 351746c | 2013-07-15 12:41:27 -0400 | [diff] [blame] | 146 | /* |
| 147 | * There can be up to (RX_QUEUE_SIZE - 1) free slots, to avoid ambiguity |
| 148 | * between empty and completely full queues. |
| 149 | * The following is equivalent to modulo by RX_QUEUE_SIZE and is well |
| 150 | * defined for negative dividends. |
| 151 | */ |
| 152 | return (rxq->read - rxq->write - 1) & (RX_QUEUE_SIZE - 1); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 155 | /* |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 156 | * iwl_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 157 | */ |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 158 | static inline __le32 iwl_pcie_dma_addr2rbd_ptr(dma_addr_t dma_addr) |
| 159 | { |
| 160 | return cpu_to_le32((u32)(dma_addr >> 8)); |
| 161 | } |
| 162 | |
Emmanuel Grumbach | 49bd072d | 2012-11-18 13:14:51 +0200 | [diff] [blame] | 163 | /* |
| 164 | * iwl_pcie_rx_stop - stops the Rx DMA |
| 165 | */ |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 166 | int iwl_pcie_rx_stop(struct iwl_trans *trans) |
| 167 | { |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 168 | iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); |
| 169 | return iwl_poll_direct_bit(trans, FH_MEM_RSSR_RX_STATUS_REG, |
| 170 | FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000); |
| 171 | } |
| 172 | |
| 173 | /* |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 174 | * iwl_pcie_rxq_inc_wr_ptr - Update the write pointer for the RX queue |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 175 | */ |
Johannes Berg | 5d63f92 | 2014-02-27 11:20:07 +0100 | [diff] [blame] | 176 | static void iwl_pcie_rxq_inc_wr_ptr(struct iwl_trans *trans) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 177 | { |
Johannes Berg | 5d63f92 | 2014-02-27 11:20:07 +0100 | [diff] [blame] | 178 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 179 | struct iwl_rxq *rxq = &trans_pcie->rxq; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 180 | u32 reg; |
| 181 | |
Johannes Berg | 5d63f92 | 2014-02-27 11:20:07 +0100 | [diff] [blame] | 182 | lockdep_assert_held(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 183 | |
Eliad Peller | 5045388 | 2014-02-05 19:12:24 +0200 | [diff] [blame] | 184 | /* |
| 185 | * explicitly wake up the NIC if: |
| 186 | * 1. shadow registers aren't enabled |
| 187 | * 2. there is a chance that the NIC is asleep |
| 188 | */ |
| 189 | if (!trans->cfg->base_params->shadow_reg_enable && |
| 190 | test_bit(STATUS_TPOWER_PMI, &trans->status)) { |
| 191 | reg = iwl_read32(trans, CSR_UCODE_DRV_GP1); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 192 | |
Eliad Peller | 5045388 | 2014-02-05 19:12:24 +0200 | [diff] [blame] | 193 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 194 | IWL_DEBUG_INFO(trans, "Rx queue requesting wakeup, GP1 = 0x%x\n", |
| 195 | reg); |
| 196 | iwl_set_bit(trans, CSR_GP_CNTRL, |
| 197 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Johannes Berg | 5d63f92 | 2014-02-27 11:20:07 +0100 | [diff] [blame] | 198 | rxq->need_update = true; |
| 199 | return; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 200 | } |
| 201 | } |
Eliad Peller | 5045388 | 2014-02-05 19:12:24 +0200 | [diff] [blame] | 202 | |
| 203 | rxq->write_actual = round_down(rxq->write, 8); |
| 204 | iwl_write32(trans, FH_RSCSR_CHNL0_WPTR, rxq->write_actual); |
Johannes Berg | 5d63f92 | 2014-02-27 11:20:07 +0100 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static void iwl_pcie_rxq_check_wrptr(struct iwl_trans *trans) |
| 208 | { |
| 209 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 210 | struct iwl_rxq *rxq = &trans_pcie->rxq; |
| 211 | |
| 212 | spin_lock(&rxq->lock); |
| 213 | |
| 214 | if (!rxq->need_update) |
| 215 | goto exit_unlock; |
| 216 | |
| 217 | iwl_pcie_rxq_inc_wr_ptr(trans); |
| 218 | rxq->need_update = false; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 219 | |
| 220 | exit_unlock: |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 221 | spin_unlock(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 224 | /* |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 225 | * iwl_pcie_rxq_restock - refill RX queue from pre-allocated pool |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 226 | * |
| 227 | * If there are slots in the RX queue that need to be restocked, |
| 228 | * and we have free pre-allocated buffers, fill the ranks as much |
| 229 | * as we can, pulling from rx_free. |
| 230 | * |
| 231 | * This moves the 'write' index forward to catch up with 'processed', and |
| 232 | * also updates the memory address in the firmware to reference the new |
| 233 | * target buffer. |
| 234 | */ |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 235 | static void iwl_pcie_rxq_restock(struct iwl_trans *trans) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 236 | { |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 237 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 238 | struct iwl_rxq *rxq = &trans_pcie->rxq; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 239 | struct iwl_rx_mem_buffer *rxb; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 240 | |
Emmanuel Grumbach | 7439046 | 2012-09-09 16:58:07 +0300 | [diff] [blame] | 241 | /* |
| 242 | * If the device isn't enabled - not need to try to add buffers... |
| 243 | * This can happen when we stop the device and still have an interrupt |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 244 | * pending. We stop the APM before we sync the interrupts because we |
| 245 | * have to (see comment there). On the other hand, since the APM is |
| 246 | * stopped, we cannot access the HW (in particular not prph). |
Emmanuel Grumbach | 7439046 | 2012-09-09 16:58:07 +0300 | [diff] [blame] | 247 | * So don't try to restock if the APM has been already stopped. |
| 248 | */ |
Arik Nemtsov | eb7ff77 | 2013-12-01 12:30:38 +0200 | [diff] [blame] | 249 | if (!test_bit(STATUS_DEVICE_ENABLED, &trans->status)) |
Emmanuel Grumbach | 7439046 | 2012-09-09 16:58:07 +0300 | [diff] [blame] | 250 | return; |
| 251 | |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 252 | spin_lock(&rxq->lock); |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 253 | while ((iwl_rxq_space(rxq) > 0) && (rxq->free_count)) { |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 254 | /* The overwritten rxb must be a used one */ |
| 255 | rxb = rxq->queue[rxq->write]; |
| 256 | BUG_ON(rxb && rxb->page); |
| 257 | |
| 258 | /* Get next free Rx buffer, remove from free list */ |
Johannes Berg | e2b1930 | 2012-11-04 09:31:25 +0100 | [diff] [blame] | 259 | rxb = list_first_entry(&rxq->rx_free, struct iwl_rx_mem_buffer, |
| 260 | list); |
| 261 | list_del(&rxb->list); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 262 | |
| 263 | /* Point to Rx buffer via next RBD in circular buffer */ |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 264 | rxq->bd[rxq->write] = iwl_pcie_dma_addr2rbd_ptr(rxb->page_dma); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 265 | rxq->queue[rxq->write] = rxb; |
| 266 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 267 | rxq->free_count--; |
| 268 | } |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 269 | spin_unlock(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 270 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 271 | /* If we've added more space for the firmware to place data, tell it. |
| 272 | * Increment device's write pointer in multiples of 8. */ |
| 273 | if (rxq->write_actual != (rxq->write & ~0x7)) { |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 274 | spin_lock(&rxq->lock); |
Johannes Berg | 5d63f92 | 2014-02-27 11:20:07 +0100 | [diff] [blame] | 275 | iwl_pcie_rxq_inc_wr_ptr(trans); |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 276 | spin_unlock(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
Emmanuel Grumbach | 358a46d | 2012-09-09 16:39:18 +0300 | [diff] [blame] | 280 | /* |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 281 | * iwl_pcie_rx_alloc_page - allocates and returns a page. |
| 282 | * |
| 283 | */ |
| 284 | static struct page *iwl_pcie_rx_alloc_page(struct iwl_trans *trans, |
| 285 | gfp_t priority) |
| 286 | { |
| 287 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 288 | struct iwl_rxq *rxq = &trans_pcie->rxq; |
| 289 | struct page *page; |
| 290 | gfp_t gfp_mask = priority; |
| 291 | |
| 292 | if (rxq->free_count > RX_LOW_WATERMARK) |
| 293 | gfp_mask |= __GFP_NOWARN; |
| 294 | |
| 295 | if (trans_pcie->rx_page_order > 0) |
| 296 | gfp_mask |= __GFP_COMP; |
| 297 | |
| 298 | /* Alloc a new receive buffer */ |
| 299 | page = alloc_pages(gfp_mask, trans_pcie->rx_page_order); |
| 300 | if (!page) { |
| 301 | if (net_ratelimit()) |
| 302 | IWL_DEBUG_INFO(trans, "alloc_pages failed, order: %d\n", |
| 303 | trans_pcie->rx_page_order); |
| 304 | /* Issue an error if the hardware has consumed more than half |
| 305 | * of its free buffer list and we don't have enough |
| 306 | * pre-allocated buffers. |
| 307 | ` */ |
| 308 | if (rxq->free_count <= RX_LOW_WATERMARK && |
| 309 | iwl_rxq_space(rxq) > (RX_QUEUE_SIZE / 2) && |
| 310 | net_ratelimit()) |
| 311 | IWL_CRIT(trans, |
| 312 | "Failed to alloc_pages with GFP_KERNEL. Only %u free buffers remaining.\n", |
| 313 | rxq->free_count); |
| 314 | return NULL; |
| 315 | } |
| 316 | return page; |
| 317 | } |
| 318 | |
| 319 | /* |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 320 | * iwl_pcie_rxq_alloc_rbs - allocate a page for each used RBD |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 321 | * |
Emmanuel Grumbach | 358a46d | 2012-09-09 16:39:18 +0300 | [diff] [blame] | 322 | * A used RBD is an Rx buffer that has been given to the stack. To use it again |
| 323 | * a page must be allocated and the RBD must point to the page. This function |
| 324 | * doesn't change the HW pointer but handles the list of pages that is used by |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 325 | * iwl_pcie_rxq_restock. The latter function will update the HW to use the newly |
Emmanuel Grumbach | 358a46d | 2012-09-09 16:39:18 +0300 | [diff] [blame] | 326 | * allocated buffers. |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 327 | */ |
Emmanuel Grumbach | 255ba06 | 2015-07-11 22:30:49 +0300 | [diff] [blame] | 328 | static void iwl_pcie_rxq_alloc_rbs(struct iwl_trans *trans, gfp_t priority) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 329 | { |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 330 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 331 | struct iwl_rxq *rxq = &trans_pcie->rxq; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 332 | struct iwl_rx_mem_buffer *rxb; |
| 333 | struct page *page; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 334 | |
| 335 | while (1) { |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 336 | spin_lock(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 337 | if (list_empty(&rxq->rx_used)) { |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 338 | spin_unlock(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 339 | return; |
| 340 | } |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 341 | spin_unlock(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 342 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 343 | /* Alloc a new receive buffer */ |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 344 | page = iwl_pcie_rx_alloc_page(trans, priority); |
| 345 | if (!page) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 346 | return; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 347 | |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 348 | spin_lock(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 349 | |
| 350 | if (list_empty(&rxq->rx_used)) { |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 351 | spin_unlock(&rxq->lock); |
Johannes Berg | b2cf410 | 2012-04-09 17:46:51 -0700 | [diff] [blame] | 352 | __free_pages(page, trans_pcie->rx_page_order); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 353 | return; |
| 354 | } |
Johannes Berg | e2b1930 | 2012-11-04 09:31:25 +0100 | [diff] [blame] | 355 | rxb = list_first_entry(&rxq->rx_used, struct iwl_rx_mem_buffer, |
| 356 | list); |
| 357 | list_del(&rxb->list); |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 358 | spin_unlock(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 359 | |
| 360 | BUG_ON(rxb->page); |
| 361 | rxb->page = page; |
| 362 | /* Get physical address of the RB */ |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 363 | rxb->page_dma = |
| 364 | dma_map_page(trans->dev, page, 0, |
| 365 | PAGE_SIZE << trans_pcie->rx_page_order, |
| 366 | DMA_FROM_DEVICE); |
Johannes Berg | 7c341582 | 2012-11-04 09:29:17 +0100 | [diff] [blame] | 367 | if (dma_mapping_error(trans->dev, rxb->page_dma)) { |
| 368 | rxb->page = NULL; |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 369 | spin_lock(&rxq->lock); |
Johannes Berg | 7c341582 | 2012-11-04 09:29:17 +0100 | [diff] [blame] | 370 | list_add(&rxb->list, &rxq->rx_used); |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 371 | spin_unlock(&rxq->lock); |
Johannes Berg | 7c341582 | 2012-11-04 09:29:17 +0100 | [diff] [blame] | 372 | __free_pages(page, trans_pcie->rx_page_order); |
| 373 | return; |
| 374 | } |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 375 | /* dma address must be no more than 36 bits */ |
| 376 | BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36)); |
| 377 | /* and also 256 byte aligned! */ |
| 378 | BUG_ON(rxb->page_dma & DMA_BIT_MASK(8)); |
| 379 | |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 380 | spin_lock(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 381 | |
| 382 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 383 | rxq->free_count++; |
| 384 | |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 385 | spin_unlock(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 389 | static void iwl_pcie_rxq_free_rbs(struct iwl_trans *trans) |
| 390 | { |
| 391 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 392 | struct iwl_rxq *rxq = &trans_pcie->rxq; |
| 393 | int i; |
| 394 | |
Johannes Berg | c7df1f4 | 2013-06-20 20:59:34 +0200 | [diff] [blame] | 395 | lockdep_assert_held(&rxq->lock); |
| 396 | |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 397 | for (i = 0; i < RX_QUEUE_SIZE; i++) { |
Johannes Berg | c7df1f4 | 2013-06-20 20:59:34 +0200 | [diff] [blame] | 398 | if (!rxq->pool[i].page) |
| 399 | continue; |
| 400 | dma_unmap_page(trans->dev, rxq->pool[i].page_dma, |
| 401 | PAGE_SIZE << trans_pcie->rx_page_order, |
| 402 | DMA_FROM_DEVICE); |
| 403 | __free_pages(rxq->pool[i].page, trans_pcie->rx_page_order); |
| 404 | rxq->pool[i].page = NULL; |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
Emmanuel Grumbach | 358a46d | 2012-09-09 16:39:18 +0300 | [diff] [blame] | 408 | /* |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 409 | * iwl_pcie_rx_replenish - Move all used buffers from rx_used to rx_free |
Emmanuel Grumbach | 358a46d | 2012-09-09 16:39:18 +0300 | [diff] [blame] | 410 | * |
| 411 | * When moving to rx_free an page is allocated for the slot. |
| 412 | * |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 413 | * Also restock the Rx queue via iwl_pcie_rxq_restock. |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 414 | * This is called only during initialization |
Emmanuel Grumbach | 358a46d | 2012-09-09 16:39:18 +0300 | [diff] [blame] | 415 | */ |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 416 | static void iwl_pcie_rx_replenish(struct iwl_trans *trans) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 417 | { |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 418 | iwl_pcie_rxq_alloc_rbs(trans, GFP_KERNEL); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 419 | |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 420 | iwl_pcie_rxq_restock(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 423 | /* |
| 424 | * iwl_pcie_rx_allocator - Allocates pages in the background for RX queues |
| 425 | * |
| 426 | * Allocates for each received request 8 pages |
| 427 | * Called as a scheduled work item. |
| 428 | */ |
| 429 | static void iwl_pcie_rx_allocator(struct iwl_trans *trans) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 430 | { |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 431 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 432 | struct iwl_rb_allocator *rba = &trans_pcie->rba; |
| 433 | struct list_head local_empty; |
| 434 | int pending = atomic_xchg(&rba->req_pending, 0); |
Sara Sharon | 5f17570 | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 435 | |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 436 | IWL_DEBUG_RX(trans, "Pending allocation requests = %d\n", pending); |
| 437 | |
| 438 | /* If we were scheduled - there is at least one request */ |
| 439 | spin_lock(&rba->lock); |
| 440 | /* swap out the rba->rbd_empty to a local list */ |
| 441 | list_replace_init(&rba->rbd_empty, &local_empty); |
| 442 | spin_unlock(&rba->lock); |
| 443 | |
| 444 | while (pending) { |
| 445 | int i; |
| 446 | struct list_head local_allocated; |
| 447 | |
| 448 | INIT_LIST_HEAD(&local_allocated); |
| 449 | |
| 450 | for (i = 0; i < RX_CLAIM_REQ_ALLOC;) { |
| 451 | struct iwl_rx_mem_buffer *rxb; |
| 452 | struct page *page; |
| 453 | |
| 454 | /* List should never be empty - each reused RBD is |
| 455 | * returned to the list, and initial pool covers any |
| 456 | * possible gap between the time the page is allocated |
| 457 | * to the time the RBD is added. |
| 458 | */ |
| 459 | BUG_ON(list_empty(&local_empty)); |
| 460 | /* Get the first rxb from the rbd list */ |
| 461 | rxb = list_first_entry(&local_empty, |
| 462 | struct iwl_rx_mem_buffer, list); |
| 463 | BUG_ON(rxb->page); |
| 464 | |
| 465 | /* Alloc a new receive buffer */ |
| 466 | page = iwl_pcie_rx_alloc_page(trans, GFP_KERNEL); |
| 467 | if (!page) |
| 468 | continue; |
| 469 | rxb->page = page; |
| 470 | |
| 471 | /* Get physical address of the RB */ |
| 472 | rxb->page_dma = dma_map_page(trans->dev, page, 0, |
| 473 | PAGE_SIZE << trans_pcie->rx_page_order, |
| 474 | DMA_FROM_DEVICE); |
| 475 | if (dma_mapping_error(trans->dev, rxb->page_dma)) { |
| 476 | rxb->page = NULL; |
| 477 | __free_pages(page, trans_pcie->rx_page_order); |
| 478 | continue; |
| 479 | } |
| 480 | /* dma address must be no more than 36 bits */ |
| 481 | BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36)); |
| 482 | /* and also 256 byte aligned! */ |
| 483 | BUG_ON(rxb->page_dma & DMA_BIT_MASK(8)); |
| 484 | |
| 485 | /* move the allocated entry to the out list */ |
| 486 | list_move(&rxb->list, &local_allocated); |
| 487 | i++; |
| 488 | } |
| 489 | |
| 490 | pending--; |
| 491 | if (!pending) { |
| 492 | pending = atomic_xchg(&rba->req_pending, 0); |
| 493 | IWL_DEBUG_RX(trans, |
| 494 | "Pending allocation requests = %d\n", |
| 495 | pending); |
| 496 | } |
| 497 | |
| 498 | spin_lock(&rba->lock); |
| 499 | /* add the allocated rbds to the allocator allocated list */ |
| 500 | list_splice_tail(&local_allocated, &rba->rbd_allocated); |
| 501 | /* get more empty RBDs for current pending requests */ |
| 502 | list_splice_tail_init(&rba->rbd_empty, &local_empty); |
| 503 | spin_unlock(&rba->lock); |
| 504 | |
| 505 | atomic_inc(&rba->req_ready); |
| 506 | } |
| 507 | |
| 508 | spin_lock(&rba->lock); |
| 509 | /* return unused rbds to the allocator empty list */ |
| 510 | list_splice_tail(&local_empty, &rba->rbd_empty); |
| 511 | spin_unlock(&rba->lock); |
| 512 | } |
| 513 | |
| 514 | /* |
| 515 | * iwl_pcie_rx_allocator_get - Returns the pre-allocated pages |
| 516 | .* |
| 517 | .* Called by queue when the queue posted allocation request and |
| 518 | * has freed 8 RBDs in order to restock itself. |
| 519 | */ |
| 520 | static int iwl_pcie_rx_allocator_get(struct iwl_trans *trans, |
| 521 | struct iwl_rx_mem_buffer |
| 522 | *out[RX_CLAIM_REQ_ALLOC]) |
| 523 | { |
| 524 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 525 | struct iwl_rb_allocator *rba = &trans_pcie->rba; |
| 526 | int i; |
| 527 | |
| 528 | /* |
| 529 | * atomic_dec_if_positive returns req_ready - 1 for any scenario. |
| 530 | * If req_ready is 0 atomic_dec_if_positive will return -1 and this |
| 531 | * function will return -ENOMEM, as there are no ready requests. |
| 532 | * atomic_dec_if_positive will perofrm the *actual* decrement only if |
| 533 | * req_ready > 0, i.e. - there are ready requests and the function |
| 534 | * hands one request to the caller. |
| 535 | */ |
| 536 | if (atomic_dec_if_positive(&rba->req_ready) < 0) |
| 537 | return -ENOMEM; |
| 538 | |
| 539 | spin_lock(&rba->lock); |
| 540 | for (i = 0; i < RX_CLAIM_REQ_ALLOC; i++) { |
| 541 | /* Get next free Rx buffer, remove it from free list */ |
| 542 | out[i] = list_first_entry(&rba->rbd_allocated, |
| 543 | struct iwl_rx_mem_buffer, list); |
| 544 | list_del(&out[i]->list); |
| 545 | } |
| 546 | spin_unlock(&rba->lock); |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | static void iwl_pcie_rx_allocator_work(struct work_struct *data) |
| 552 | { |
| 553 | struct iwl_rb_allocator *rba_p = |
| 554 | container_of(data, struct iwl_rb_allocator, rx_alloc); |
| 555 | struct iwl_trans_pcie *trans_pcie = |
| 556 | container_of(rba_p, struct iwl_trans_pcie, rba); |
| 557 | |
| 558 | iwl_pcie_rx_allocator(trans_pcie->trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 561 | static int iwl_pcie_rx_alloc(struct iwl_trans *trans) |
| 562 | { |
| 563 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 564 | struct iwl_rxq *rxq = &trans_pcie->rxq; |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 565 | struct iwl_rb_allocator *rba = &trans_pcie->rba; |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 566 | struct device *dev = trans->dev; |
| 567 | |
| 568 | memset(&trans_pcie->rxq, 0, sizeof(trans_pcie->rxq)); |
| 569 | |
| 570 | spin_lock_init(&rxq->lock); |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 571 | spin_lock_init(&rba->lock); |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 572 | |
| 573 | if (WARN_ON(rxq->bd || rxq->rb_stts)) |
| 574 | return -EINVAL; |
| 575 | |
| 576 | /* Allocate the circular buffer of Read Buffer Descriptors (RBDs) */ |
| 577 | rxq->bd = dma_zalloc_coherent(dev, sizeof(__le32) * RX_QUEUE_SIZE, |
| 578 | &rxq->bd_dma, GFP_KERNEL); |
| 579 | if (!rxq->bd) |
| 580 | goto err_bd; |
| 581 | |
| 582 | /*Allocate the driver's pointer to receive buffer status */ |
| 583 | rxq->rb_stts = dma_zalloc_coherent(dev, sizeof(*rxq->rb_stts), |
| 584 | &rxq->rb_stts_dma, GFP_KERNEL); |
| 585 | if (!rxq->rb_stts) |
| 586 | goto err_rb_stts; |
| 587 | |
| 588 | return 0; |
| 589 | |
| 590 | err_rb_stts: |
| 591 | dma_free_coherent(dev, sizeof(__le32) * RX_QUEUE_SIZE, |
| 592 | rxq->bd, rxq->bd_dma); |
Johannes Berg | d21fa2d | 2013-01-08 00:25:21 +0100 | [diff] [blame] | 593 | rxq->bd_dma = 0; |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 594 | rxq->bd = NULL; |
| 595 | err_bd: |
| 596 | return -ENOMEM; |
| 597 | } |
| 598 | |
| 599 | static void iwl_pcie_rx_hw_init(struct iwl_trans *trans, struct iwl_rxq *rxq) |
| 600 | { |
| 601 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 602 | u32 rb_size; |
| 603 | const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */ |
| 604 | |
Emmanuel Grumbach | 6c4fbcb | 2015-11-10 11:57:41 +0200 | [diff] [blame] | 605 | switch (trans_pcie->rx_buf_size) { |
| 606 | case IWL_AMSDU_4K: |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 607 | rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K; |
Emmanuel Grumbach | 6c4fbcb | 2015-11-10 11:57:41 +0200 | [diff] [blame] | 608 | break; |
| 609 | case IWL_AMSDU_8K: |
| 610 | rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K; |
| 611 | break; |
| 612 | case IWL_AMSDU_12K: |
| 613 | rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K; |
| 614 | break; |
| 615 | default: |
| 616 | WARN_ON(1); |
| 617 | rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K; |
| 618 | } |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 619 | |
| 620 | /* Stop Rx DMA */ |
| 621 | iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); |
Johannes Berg | ddaf5a5 | 2013-01-08 11:25:44 +0100 | [diff] [blame] | 622 | /* reset and flush pointers */ |
| 623 | iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_RBDCB_WPTR, 0); |
| 624 | iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_FLUSH_RB_REQ, 0); |
| 625 | iwl_write_direct32(trans, FH_RSCSR_CHNL0_RDPTR, 0); |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 626 | |
| 627 | /* Reset driver's Rx queue write index */ |
| 628 | iwl_write_direct32(trans, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0); |
| 629 | |
| 630 | /* Tell device where to find RBD circular buffer in DRAM */ |
| 631 | iwl_write_direct32(trans, FH_RSCSR_CHNL0_RBDCB_BASE_REG, |
| 632 | (u32)(rxq->bd_dma >> 8)); |
| 633 | |
| 634 | /* Tell device where in DRAM to update its Rx status */ |
| 635 | iwl_write_direct32(trans, FH_RSCSR_CHNL0_STTS_WPTR_REG, |
| 636 | rxq->rb_stts_dma >> 4); |
| 637 | |
| 638 | /* Enable Rx DMA |
| 639 | * FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY is set because of HW bug in |
| 640 | * the credit mechanism in 5000 HW RX FIFO |
| 641 | * Direct rx interrupts to hosts |
Emmanuel Grumbach | 6c4fbcb | 2015-11-10 11:57:41 +0200 | [diff] [blame] | 642 | * Rx buffer size 4 or 8k or 12k |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 643 | * RB timeout 0x10 |
| 644 | * 256 RBDs |
| 645 | */ |
| 646 | iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, |
| 647 | FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL | |
| 648 | FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY | |
| 649 | FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL | |
| 650 | rb_size| |
Emmanuel Grumbach | 49bd072d | 2012-11-18 13:14:51 +0200 | [diff] [blame] | 651 | (RX_RB_TIMEOUT << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS)| |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 652 | (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS)); |
| 653 | |
| 654 | /* Set interrupt coalescing timer to default (2048 usecs) */ |
| 655 | iwl_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF); |
Emmanuel Grumbach | 6960a05 | 2013-11-11 15:23:01 +0200 | [diff] [blame] | 656 | |
| 657 | /* W/A for interrupt coalescing bug in 7260 and 3160 */ |
| 658 | if (trans->cfg->host_interrupt_operation_mode) |
| 659 | iwl_set_bit(trans, CSR_INT_COALESCING, IWL_HOST_INT_OPER_MODE); |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 660 | } |
| 661 | |
Johannes Berg | c7df1f4 | 2013-06-20 20:59:34 +0200 | [diff] [blame] | 662 | static void iwl_pcie_rx_init_rxb_lists(struct iwl_rxq *rxq) |
| 663 | { |
| 664 | int i; |
| 665 | |
| 666 | lockdep_assert_held(&rxq->lock); |
| 667 | |
| 668 | INIT_LIST_HEAD(&rxq->rx_free); |
| 669 | INIT_LIST_HEAD(&rxq->rx_used); |
| 670 | rxq->free_count = 0; |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 671 | rxq->used_count = 0; |
Johannes Berg | c7df1f4 | 2013-06-20 20:59:34 +0200 | [diff] [blame] | 672 | |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 673 | for (i = 0; i < RX_QUEUE_SIZE; i++) |
Johannes Berg | c7df1f4 | 2013-06-20 20:59:34 +0200 | [diff] [blame] | 674 | list_add(&rxq->pool[i].list, &rxq->rx_used); |
| 675 | } |
| 676 | |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 677 | static void iwl_pcie_rx_init_rba(struct iwl_rb_allocator *rba) |
| 678 | { |
| 679 | int i; |
| 680 | |
| 681 | lockdep_assert_held(&rba->lock); |
| 682 | |
| 683 | INIT_LIST_HEAD(&rba->rbd_allocated); |
| 684 | INIT_LIST_HEAD(&rba->rbd_empty); |
| 685 | |
| 686 | for (i = 0; i < RX_POOL_SIZE; i++) |
| 687 | list_add(&rba->pool[i].list, &rba->rbd_empty); |
| 688 | } |
| 689 | |
| 690 | static void iwl_pcie_rx_free_rba(struct iwl_trans *trans) |
| 691 | { |
| 692 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 693 | struct iwl_rb_allocator *rba = &trans_pcie->rba; |
| 694 | int i; |
| 695 | |
| 696 | lockdep_assert_held(&rba->lock); |
| 697 | |
| 698 | for (i = 0; i < RX_POOL_SIZE; i++) { |
| 699 | if (!rba->pool[i].page) |
| 700 | continue; |
| 701 | dma_unmap_page(trans->dev, rba->pool[i].page_dma, |
| 702 | PAGE_SIZE << trans_pcie->rx_page_order, |
| 703 | DMA_FROM_DEVICE); |
| 704 | __free_pages(rba->pool[i].page, trans_pcie->rx_page_order); |
| 705 | rba->pool[i].page = NULL; |
| 706 | } |
| 707 | } |
| 708 | |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 709 | int iwl_pcie_rx_init(struct iwl_trans *trans) |
| 710 | { |
| 711 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 712 | struct iwl_rxq *rxq = &trans_pcie->rxq; |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 713 | struct iwl_rb_allocator *rba = &trans_pcie->rba; |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 714 | int i, err; |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 715 | |
| 716 | if (!rxq->bd) { |
| 717 | err = iwl_pcie_rx_alloc(trans); |
| 718 | if (err) |
| 719 | return err; |
| 720 | } |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 721 | if (!rba->alloc_wq) |
| 722 | rba->alloc_wq = alloc_workqueue("rb_allocator", |
| 723 | WQ_HIGHPRI | WQ_UNBOUND, 1); |
| 724 | INIT_WORK(&rba->rx_alloc, iwl_pcie_rx_allocator_work); |
| 725 | |
| 726 | spin_lock(&rba->lock); |
| 727 | atomic_set(&rba->req_pending, 0); |
| 728 | atomic_set(&rba->req_ready, 0); |
| 729 | /* free all first - we might be reconfigured for a different size */ |
| 730 | iwl_pcie_rx_free_rba(trans); |
| 731 | iwl_pcie_rx_init_rba(rba); |
| 732 | spin_unlock(&rba->lock); |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 733 | |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 734 | spin_lock(&rxq->lock); |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 735 | |
Johannes Berg | c7df1f4 | 2013-06-20 20:59:34 +0200 | [diff] [blame] | 736 | /* free all first - we might be reconfigured for a different size */ |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 737 | iwl_pcie_rxq_free_rbs(trans); |
Johannes Berg | c7df1f4 | 2013-06-20 20:59:34 +0200 | [diff] [blame] | 738 | iwl_pcie_rx_init_rxb_lists(rxq); |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 739 | |
| 740 | for (i = 0; i < RX_QUEUE_SIZE; i++) |
| 741 | rxq->queue[i] = NULL; |
| 742 | |
| 743 | /* Set us so that we have processed and used all buffers, but have |
| 744 | * not restocked the Rx queue with fresh buffers */ |
| 745 | rxq->read = rxq->write = 0; |
| 746 | rxq->write_actual = 0; |
Johannes Berg | ddaf5a5 | 2013-01-08 11:25:44 +0100 | [diff] [blame] | 747 | memset(rxq->rb_stts, 0, sizeof(*rxq->rb_stts)); |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 748 | spin_unlock(&rxq->lock); |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 749 | |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 750 | iwl_pcie_rx_replenish(trans); |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 751 | |
| 752 | iwl_pcie_rx_hw_init(trans, rxq); |
| 753 | |
Johannes Berg | 5d63f92 | 2014-02-27 11:20:07 +0100 | [diff] [blame] | 754 | spin_lock(&rxq->lock); |
| 755 | iwl_pcie_rxq_inc_wr_ptr(trans); |
| 756 | spin_unlock(&rxq->lock); |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 757 | |
| 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | void iwl_pcie_rx_free(struct iwl_trans *trans) |
| 762 | { |
| 763 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 764 | struct iwl_rxq *rxq = &trans_pcie->rxq; |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 765 | struct iwl_rb_allocator *rba = &trans_pcie->rba; |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 766 | |
| 767 | /*if rxq->bd is NULL, it means that nothing has been allocated, |
| 768 | * exit now */ |
| 769 | if (!rxq->bd) { |
| 770 | IWL_DEBUG_INFO(trans, "Free NULL rx context\n"); |
| 771 | return; |
| 772 | } |
| 773 | |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 774 | cancel_work_sync(&rba->rx_alloc); |
| 775 | if (rba->alloc_wq) { |
| 776 | destroy_workqueue(rba->alloc_wq); |
| 777 | rba->alloc_wq = NULL; |
| 778 | } |
| 779 | |
| 780 | spin_lock(&rba->lock); |
| 781 | iwl_pcie_rx_free_rba(trans); |
| 782 | spin_unlock(&rba->lock); |
Johannes Berg | 0aa86df | 2012-12-27 22:58:21 +0100 | [diff] [blame] | 783 | |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 784 | spin_lock(&rxq->lock); |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 785 | iwl_pcie_rxq_free_rbs(trans); |
Emmanuel Grumbach | 51232f7 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 786 | spin_unlock(&rxq->lock); |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 787 | |
| 788 | dma_free_coherent(trans->dev, sizeof(__le32) * RX_QUEUE_SIZE, |
| 789 | rxq->bd, rxq->bd_dma); |
Johannes Berg | d21fa2d | 2013-01-08 00:25:21 +0100 | [diff] [blame] | 790 | rxq->bd_dma = 0; |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 791 | rxq->bd = NULL; |
| 792 | |
| 793 | if (rxq->rb_stts) |
| 794 | dma_free_coherent(trans->dev, |
| 795 | sizeof(struct iwl_rb_status), |
| 796 | rxq->rb_stts, rxq->rb_stts_dma); |
| 797 | else |
| 798 | IWL_DEBUG_INFO(trans, "Free rxq->rb_stts which is NULL\n"); |
Johannes Berg | d21fa2d | 2013-01-08 00:25:21 +0100 | [diff] [blame] | 799 | rxq->rb_stts_dma = 0; |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 800 | rxq->rb_stts = NULL; |
| 801 | } |
| 802 | |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 803 | /* |
| 804 | * iwl_pcie_rx_reuse_rbd - Recycle used RBDs |
| 805 | * |
| 806 | * Called when a RBD can be reused. The RBD is transferred to the allocator. |
| 807 | * When there are 2 empty RBDs - a request for allocation is posted |
| 808 | */ |
| 809 | static void iwl_pcie_rx_reuse_rbd(struct iwl_trans *trans, |
| 810 | struct iwl_rx_mem_buffer *rxb, |
| 811 | struct iwl_rxq *rxq, bool emergency) |
| 812 | { |
| 813 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 814 | struct iwl_rb_allocator *rba = &trans_pcie->rba; |
| 815 | |
| 816 | /* Move the RBD to the used list, will be moved to allocator in batches |
| 817 | * before claiming or posting a request*/ |
| 818 | list_add_tail(&rxb->list, &rxq->rx_used); |
| 819 | |
| 820 | if (unlikely(emergency)) |
| 821 | return; |
| 822 | |
| 823 | /* Count the allocator owned RBDs */ |
| 824 | rxq->used_count++; |
| 825 | |
| 826 | /* If we have RX_POST_REQ_ALLOC new released rx buffers - |
| 827 | * issue a request for allocator. Modulo RX_CLAIM_REQ_ALLOC is |
| 828 | * used for the case we failed to claim RX_CLAIM_REQ_ALLOC, |
| 829 | * after but we still need to post another request. |
| 830 | */ |
| 831 | if ((rxq->used_count % RX_CLAIM_REQ_ALLOC) == RX_POST_REQ_ALLOC) { |
| 832 | /* Move the 2 RBDs to the allocator ownership. |
| 833 | Allocator has another 6 from pool for the request completion*/ |
| 834 | spin_lock(&rba->lock); |
| 835 | list_splice_tail_init(&rxq->rx_used, &rba->rbd_empty); |
| 836 | spin_unlock(&rba->lock); |
| 837 | |
| 838 | atomic_inc(&rba->req_pending); |
| 839 | queue_work(rba->alloc_wq, &rba->rx_alloc); |
| 840 | } |
| 841 | } |
| 842 | |
Emmanuel Grumbach | 9805c446 | 2012-11-14 14:44:18 +0200 | [diff] [blame] | 843 | static void iwl_pcie_rx_handle_rb(struct iwl_trans *trans, |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 844 | struct iwl_rx_mem_buffer *rxb, |
| 845 | bool emergency) |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 846 | { |
| 847 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 848 | struct iwl_rxq *rxq = &trans_pcie->rxq; |
| 849 | struct iwl_txq *txq = &trans_pcie->txq[trans_pcie->cmd_queue]; |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 850 | bool page_stolen = false; |
Johannes Berg | b2cf410 | 2012-04-09 17:46:51 -0700 | [diff] [blame] | 851 | int max_len = PAGE_SIZE << trans_pcie->rx_page_order; |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 852 | u32 offset = 0; |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 853 | |
| 854 | if (WARN_ON(!rxb)) |
| 855 | return; |
| 856 | |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 857 | 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] | 858 | |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 859 | while (offset + sizeof(u32) + sizeof(struct iwl_cmd_header) < max_len) { |
| 860 | struct iwl_rx_packet *pkt; |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 861 | u16 sequence; |
| 862 | bool reclaim; |
Johannes Berg | f7e6469 | 2015-06-23 21:58:17 +0200 | [diff] [blame] | 863 | int index, cmd_index, len; |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 864 | struct iwl_rx_cmd_buffer rxcb = { |
| 865 | ._offset = offset, |
Emmanuel Grumbach | d13f186 | 2013-01-23 10:59:29 +0200 | [diff] [blame] | 866 | ._rx_page_order = trans_pcie->rx_page_order, |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 867 | ._page = rxb->page, |
| 868 | ._page_stolen = false, |
David S. Miller | 0d6c4a2 | 2012-05-07 23:35:40 -0400 | [diff] [blame] | 869 | .truesize = max_len, |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 870 | }; |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 871 | |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 872 | pkt = rxb_addr(&rxcb); |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 873 | |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 874 | if (pkt->len_n_flags == cpu_to_le32(FH_RSCSR_FRAME_INVALID)) |
| 875 | break; |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 876 | |
Liad Kaufman | 9243efc | 2015-03-15 17:38:22 +0200 | [diff] [blame] | 877 | IWL_DEBUG_RX(trans, |
| 878 | "cmd at offset %d: %s (0x%.2x, seq 0x%x)\n", |
| 879 | rxcb._offset, |
| 880 | get_cmd_string(trans_pcie, pkt->hdr.cmd), |
| 881 | pkt->hdr.cmd, le16_to_cpu(pkt->hdr.sequence)); |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 882 | |
Johannes Berg | 65b3034 | 2014-01-08 13:16:33 +0100 | [diff] [blame] | 883 | len = iwl_rx_packet_len(pkt); |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 884 | len += sizeof(u32); /* account for status word */ |
Johannes Berg | f042c2e | 2012-09-05 22:34:44 +0200 | [diff] [blame] | 885 | trace_iwlwifi_dev_rx(trans->dev, trans, pkt, len); |
| 886 | trace_iwlwifi_dev_rx_data(trans->dev, trans, pkt, len); |
Johannes Berg | d663ee7 | 2012-03-10 13:00:07 -0800 | [diff] [blame] | 887 | |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 888 | /* Reclaim a command buffer only if this packet is a response |
| 889 | * to a (driver-originated) command. |
| 890 | * If the packet (e.g. Rx frame) originated from uCode, |
| 891 | * there is no command buffer to reclaim. |
| 892 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 893 | * but apparently a few don't get set; catch them here. */ |
| 894 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME); |
| 895 | if (reclaim) { |
| 896 | int i; |
| 897 | |
| 898 | for (i = 0; i < trans_pcie->n_no_reclaim_cmds; i++) { |
| 899 | if (trans_pcie->no_reclaim_cmds[i] == |
| 900 | pkt->hdr.cmd) { |
| 901 | reclaim = false; |
| 902 | break; |
| 903 | } |
Johannes Berg | d663ee7 | 2012-03-10 13:00:07 -0800 | [diff] [blame] | 904 | } |
| 905 | } |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 906 | |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 907 | sequence = le16_to_cpu(pkt->hdr.sequence); |
| 908 | index = SEQ_TO_INDEX(sequence); |
| 909 | cmd_index = get_cmd_index(&txq->q, index); |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 910 | |
Johannes Berg | 1be5d8c | 2015-06-11 16:51:24 +0200 | [diff] [blame] | 911 | iwl_op_mode_rx(trans->op_mode, &trans_pcie->napi, &rxcb); |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 912 | |
Emmanuel Grumbach | 9679142 | 2012-07-24 01:58:32 +0300 | [diff] [blame] | 913 | if (reclaim) { |
Johannes Berg | 5d4185a | 2014-09-09 21:16:06 +0200 | [diff] [blame] | 914 | kzfree(txq->entries[cmd_index].free_buf); |
Johannes Berg | f4feb8a | 2012-10-19 14:24:43 +0200 | [diff] [blame] | 915 | txq->entries[cmd_index].free_buf = NULL; |
Emmanuel Grumbach | 9679142 | 2012-07-24 01:58:32 +0300 | [diff] [blame] | 916 | } |
| 917 | |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 918 | /* |
| 919 | * After here, we should always check rxcb._page_stolen, |
| 920 | * if it is true then one of the handlers took the page. |
| 921 | */ |
| 922 | |
| 923 | if (reclaim) { |
| 924 | /* Invoke any callbacks, transfer the buffer to caller, |
| 925 | * and fire off the (possibly) blocking |
| 926 | * iwl_trans_send_cmd() |
| 927 | * as we reclaim the driver command queue */ |
| 928 | if (!rxcb._page_stolen) |
Johannes Berg | f7e6469 | 2015-06-23 21:58:17 +0200 | [diff] [blame] | 929 | iwl_pcie_hcmd_complete(trans, &rxcb); |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 930 | else |
| 931 | IWL_WARN(trans, "Claim null rxb?\n"); |
| 932 | } |
| 933 | |
| 934 | page_stolen |= rxcb._page_stolen; |
| 935 | offset += ALIGN(len, FH_RSCSR_FRAME_ALIGN); |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 936 | } |
| 937 | |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 938 | /* page was stolen from us -- free our reference */ |
| 939 | if (page_stolen) { |
Johannes Berg | b2cf410 | 2012-04-09 17:46:51 -0700 | [diff] [blame] | 940 | __free_pages(rxb->page, trans_pcie->rx_page_order); |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 941 | rxb->page = NULL; |
Johannes Berg | 0c19744 | 2012-03-15 13:26:43 -0700 | [diff] [blame] | 942 | } |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 943 | |
| 944 | /* Reuse the page if possible. For notification packets and |
| 945 | * SKBs that fail to Rx correctly, add them back into the |
| 946 | * rx_free list for reuse later. */ |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 947 | if (rxb->page != NULL) { |
| 948 | rxb->page_dma = |
| 949 | dma_map_page(trans->dev, rxb->page, 0, |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 950 | PAGE_SIZE << trans_pcie->rx_page_order, |
| 951 | DMA_FROM_DEVICE); |
Johannes Berg | 7c341582 | 2012-11-04 09:29:17 +0100 | [diff] [blame] | 952 | if (dma_mapping_error(trans->dev, rxb->page_dma)) { |
| 953 | /* |
| 954 | * free the page(s) as well to not break |
| 955 | * the invariant that the items on the used |
| 956 | * list have no page(s) |
| 957 | */ |
| 958 | __free_pages(rxb->page, trans_pcie->rx_page_order); |
| 959 | rxb->page = NULL; |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 960 | iwl_pcie_rx_reuse_rbd(trans, rxb, rxq, emergency); |
Johannes Berg | 7c341582 | 2012-11-04 09:29:17 +0100 | [diff] [blame] | 961 | } else { |
| 962 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 963 | rxq->free_count++; |
| 964 | } |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 965 | } else |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 966 | iwl_pcie_rx_reuse_rbd(trans, rxb, rxq, emergency); |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 967 | } |
| 968 | |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 969 | /* |
| 970 | * iwl_pcie_rx_handle - Main entry function for receiving responses from fw |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 971 | */ |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 972 | static void iwl_pcie_rx_handle(struct iwl_trans *trans) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 973 | { |
Johannes Berg | df2f321 | 2012-03-05 11:24:40 -0800 | [diff] [blame] | 974 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 975 | struct iwl_rxq *rxq = &trans_pcie->rxq; |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 976 | u32 r, i, j, count = 0; |
| 977 | bool emergency = false; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 978 | |
Johannes Berg | f14d6b3 | 2014-03-21 13:30:03 +0100 | [diff] [blame] | 979 | restart: |
| 980 | spin_lock(&rxq->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 981 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 982 | * buffer that the driver may process (last buffer filled by ucode). */ |
Emmanuel Grumbach | 52e2a99 | 2012-11-25 14:42:25 +0200 | [diff] [blame] | 983 | r = le16_to_cpu(ACCESS_ONCE(rxq->rb_stts->closed_rb_num)) & 0x0FFF; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 984 | i = rxq->read; |
| 985 | |
| 986 | /* Rx interrupt, but nothing sent from uCode */ |
| 987 | if (i == r) |
Emmanuel Grumbach | 726f23f | 2012-05-16 22:40:49 +0200 | [diff] [blame] | 988 | IWL_DEBUG_RX(trans, "HW = SW = %d\n", r); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 989 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 990 | while (i != r) { |
Johannes Berg | 48a2d66 | 2012-03-05 11:24:39 -0800 | [diff] [blame] | 991 | struct iwl_rx_mem_buffer *rxb; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 992 | |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 993 | if (unlikely(rxq->used_count == RX_QUEUE_SIZE / 2)) |
| 994 | emergency = true; |
| 995 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 996 | rxb = rxq->queue[i]; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 997 | rxq->queue[i] = NULL; |
| 998 | |
Johannes Berg | f02d2cc | 2015-11-06 11:27:23 +0100 | [diff] [blame] | 999 | IWL_DEBUG_RX(trans, "rxbuf: HW = %d, SW = %d\n", r, i); |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 1000 | iwl_pcie_rx_handle_rb(trans, rxb, emergency); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1001 | |
| 1002 | i = (i + 1) & RX_QUEUE_MASK; |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 1003 | |
| 1004 | /* If we have RX_CLAIM_REQ_ALLOC released rx buffers - |
| 1005 | * try to claim the pre-allocated buffers from the allocator */ |
| 1006 | if (rxq->used_count >= RX_CLAIM_REQ_ALLOC) { |
| 1007 | struct iwl_rb_allocator *rba = &trans_pcie->rba; |
| 1008 | struct iwl_rx_mem_buffer *out[RX_CLAIM_REQ_ALLOC]; |
| 1009 | |
| 1010 | if (rxq->used_count % RX_CLAIM_REQ_ALLOC == 0 && |
| 1011 | !emergency) { |
| 1012 | /* Add the remaining 6 empty RBDs |
| 1013 | * for allocator use |
| 1014 | */ |
| 1015 | spin_lock(&rba->lock); |
| 1016 | list_splice_tail_init(&rxq->rx_used, |
| 1017 | &rba->rbd_empty); |
| 1018 | spin_unlock(&rba->lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1019 | } |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 1020 | |
| 1021 | /* If not ready - continue, will try to reclaim later. |
| 1022 | * No need to reschedule work - allocator exits only on |
| 1023 | * success */ |
| 1024 | if (!iwl_pcie_rx_allocator_get(trans, out)) { |
| 1025 | /* If success - then RX_CLAIM_REQ_ALLOC |
| 1026 | * buffers were retrieved and should be added |
| 1027 | * to free list */ |
| 1028 | rxq->used_count -= RX_CLAIM_REQ_ALLOC; |
| 1029 | for (j = 0; j < RX_CLAIM_REQ_ALLOC; j++) { |
| 1030 | list_add_tail(&out[j]->list, |
| 1031 | &rxq->rx_free); |
| 1032 | rxq->free_count++; |
| 1033 | } |
| 1034 | } |
| 1035 | } |
| 1036 | if (emergency) { |
| 1037 | count++; |
| 1038 | if (count == 8) { |
| 1039 | count = 0; |
| 1040 | if (rxq->used_count < RX_QUEUE_SIZE / 3) |
| 1041 | emergency = false; |
| 1042 | spin_unlock(&rxq->lock); |
| 1043 | iwl_pcie_rxq_alloc_rbs(trans, GFP_ATOMIC); |
| 1044 | spin_lock(&rxq->lock); |
| 1045 | } |
| 1046 | } |
| 1047 | /* handle restock for three cases, can be all of them at once: |
| 1048 | * - we just pulled buffers from the allocator |
| 1049 | * - we have 8+ unstolen pages accumulated |
| 1050 | * - we are in emergency and allocated buffers |
| 1051 | */ |
| 1052 | if (rxq->free_count >= RX_CLAIM_REQ_ALLOC) { |
| 1053 | rxq->read = i; |
| 1054 | spin_unlock(&rxq->lock); |
| 1055 | iwl_pcie_rxq_restock(trans); |
| 1056 | goto restart; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | /* Backtrack one entry */ |
| 1061 | rxq->read = i; |
Johannes Berg | f14d6b3 | 2014-03-21 13:30:03 +0100 | [diff] [blame] | 1062 | spin_unlock(&rxq->lock); |
| 1063 | |
Sara Sharon | 26d535a | 2015-04-28 12:56:54 +0300 | [diff] [blame] | 1064 | /* |
| 1065 | * handle a case where in emergency there are some unallocated RBDs. |
| 1066 | * those RBDs are in the used list, but are not tracked by the queue's |
| 1067 | * used_count which counts allocator owned RBDs. |
| 1068 | * unallocated emergency RBDs must be allocated on exit, otherwise |
| 1069 | * when called again the function may not be in emergency mode and |
| 1070 | * they will be handed to the allocator with no tracking in the RBD |
| 1071 | * allocator counters, which will lead to them never being claimed back |
| 1072 | * by the queue. |
| 1073 | * by allocating them here, they are now in the queue free list, and |
| 1074 | * will be restocked by the next call of iwl_pcie_rxq_restock. |
| 1075 | */ |
| 1076 | if (unlikely(emergency && count)) |
| 1077 | iwl_pcie_rxq_alloc_rbs(trans, GFP_ATOMIC); |
Emmanuel Grumbach | 255ba06 | 2015-07-11 22:30:49 +0300 | [diff] [blame] | 1078 | |
Johannes Berg | f14d6b3 | 2014-03-21 13:30:03 +0100 | [diff] [blame] | 1079 | if (trans_pcie->napi.poll) |
| 1080 | napi_gro_flush(&trans_pcie->napi, false); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 1083 | /* |
| 1084 | * iwl_pcie_irq_handle_error - called for HW or SW error interrupt from card |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 1085 | */ |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 1086 | static void iwl_pcie_irq_handle_error(struct iwl_trans *trans) |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 1087 | { |
Emmanuel Grumbach | f946b52 | 2012-10-25 17:25:52 +0200 | [diff] [blame] | 1088 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 1103323 | 2015-06-24 14:58:13 +0300 | [diff] [blame] | 1089 | int i; |
Emmanuel Grumbach | f946b52 | 2012-10-25 17:25:52 +0200 | [diff] [blame] | 1090 | |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 1091 | /* W/A for WiFi/WiMAX coex and WiMAX own the RF */ |
Emmanuel Grumbach | 035f7ff | 2012-03-26 08:57:01 -0700 | [diff] [blame] | 1092 | if (trans->cfg->internal_wimax_coex && |
Avri Altman | 95411d0 | 2015-05-11 11:04:34 +0300 | [diff] [blame] | 1093 | !trans->cfg->apmg_not_supported && |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1094 | (!(iwl_read_prph(trans, APMG_CLK_CTRL_REG) & |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 1095 | APMS_CLK_VAL_MRB_FUNC_MODE) || |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1096 | (iwl_read_prph(trans, APMG_PS_CTRL_REG) & |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 1097 | APMG_PS_CTRL_VAL_RESET_REQ))) { |
Arik Nemtsov | eb7ff77 | 2013-12-01 12:30:38 +0200 | [diff] [blame] | 1098 | clear_bit(STATUS_SYNC_HCMD_ACTIVE, &trans->status); |
Don Fry | 8a8bbdb | 2012-03-20 10:33:34 -0700 | [diff] [blame] | 1099 | iwl_op_mode_wimax_active(trans->op_mode); |
Emmanuel Grumbach | f946b52 | 2012-10-25 17:25:52 +0200 | [diff] [blame] | 1100 | wake_up(&trans_pcie->wait_command_queue); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 1101 | return; |
| 1102 | } |
| 1103 | |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 1104 | iwl_pcie_dump_csr(trans); |
Inbal Hacohen | 313b0a2 | 2013-06-24 10:35:53 +0300 | [diff] [blame] | 1105 | iwl_dump_fh(trans, NULL); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 1106 | |
Arik Nemtsov | 2a988e9 | 2013-12-01 13:50:40 +0200 | [diff] [blame] | 1107 | local_bh_disable(); |
| 1108 | /* The STATUS_FW_ERROR bit is set in this function. This must happen |
| 1109 | * before we wake up the command caller, to ensure a proper cleanup. */ |
| 1110 | iwl_trans_fw_error(trans); |
| 1111 | local_bh_enable(); |
| 1112 | |
Emmanuel Grumbach | 1103323 | 2015-06-24 14:58:13 +0300 | [diff] [blame] | 1113 | for (i = 0; i < trans->cfg->base_params->num_of_queues; i++) |
| 1114 | del_timer(&trans_pcie->txq[i].stuck_timer); |
| 1115 | |
Arik Nemtsov | eb7ff77 | 2013-12-01 12:30:38 +0200 | [diff] [blame] | 1116 | clear_bit(STATUS_SYNC_HCMD_ACTIVE, &trans->status); |
Emmanuel Grumbach | f946b52 | 2012-10-25 17:25:52 +0200 | [diff] [blame] | 1117 | wake_up(&trans_pcie->wait_command_queue); |
Emmanuel Grumbach | 7ff9470 | 2011-08-25 23:10:54 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
Emmanuel Grumbach | 7117c00 | 2013-12-11 09:20:34 +0200 | [diff] [blame] | 1120 | static u32 iwl_pcie_int_cause_non_ict(struct iwl_trans *trans) |
Emmanuel Grumbach | fc84472 | 2013-12-09 14:27:44 +0200 | [diff] [blame] | 1121 | { |
Emmanuel Grumbach | fc84472 | 2013-12-09 14:27:44 +0200 | [diff] [blame] | 1122 | u32 inta; |
| 1123 | |
Emmanuel Grumbach | 46e81af | 2014-01-14 10:33:54 +0200 | [diff] [blame] | 1124 | lockdep_assert_held(&IWL_TRANS_GET_PCIE_TRANS(trans)->irq_lock); |
Emmanuel Grumbach | fc84472 | 2013-12-09 14:27:44 +0200 | [diff] [blame] | 1125 | |
| 1126 | trace_iwlwifi_dev_irq(trans->dev); |
| 1127 | |
| 1128 | /* Discover which interrupts are active/pending */ |
| 1129 | inta = iwl_read32(trans, CSR_INT); |
| 1130 | |
Emmanuel Grumbach | fc84472 | 2013-12-09 14:27:44 +0200 | [diff] [blame] | 1131 | /* the thread will service interrupts and re-enable them */ |
Emmanuel Grumbach | fe523dc | 2013-12-11 09:24:39 +0200 | [diff] [blame] | 1132 | return inta; |
Emmanuel Grumbach | fc84472 | 2013-12-09 14:27:44 +0200 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | /* a device (PCI-E) page is 4096 bytes long */ |
| 1136 | #define ICT_SHIFT 12 |
| 1137 | #define ICT_SIZE (1 << ICT_SHIFT) |
| 1138 | #define ICT_COUNT (ICT_SIZE / sizeof(u32)) |
| 1139 | |
| 1140 | /* interrupt handler using ict table, with this interrupt driver will |
| 1141 | * stop using INTA register to get device's interrupt, reading this register |
| 1142 | * is expensive, device will write interrupts in ICT dram table, increment |
| 1143 | * index then will fire interrupt to driver, driver will OR all ICT table |
| 1144 | * entries from current index up to table entry with 0 value. the result is |
| 1145 | * the interrupt we need to service, driver will set the entries back to 0 and |
| 1146 | * set index. |
| 1147 | */ |
Emmanuel Grumbach | 7117c00 | 2013-12-11 09:20:34 +0200 | [diff] [blame] | 1148 | static u32 iwl_pcie_int_cause_ict(struct iwl_trans *trans) |
Emmanuel Grumbach | fc84472 | 2013-12-09 14:27:44 +0200 | [diff] [blame] | 1149 | { |
| 1150 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | fc84472 | 2013-12-09 14:27:44 +0200 | [diff] [blame] | 1151 | u32 inta; |
| 1152 | u32 val = 0; |
| 1153 | u32 read; |
| 1154 | |
Emmanuel Grumbach | fc84472 | 2013-12-09 14:27:44 +0200 | [diff] [blame] | 1155 | trace_iwlwifi_dev_irq(trans->dev); |
| 1156 | |
| 1157 | /* Ignore interrupt if there's nothing in NIC to service. |
| 1158 | * This may be due to IRQ shared with another device, |
| 1159 | * or due to sporadic interrupts thrown from our NIC. */ |
| 1160 | read = le32_to_cpu(trans_pcie->ict_tbl[trans_pcie->ict_index]); |
| 1161 | trace_iwlwifi_dev_ict_read(trans->dev, trans_pcie->ict_index, read); |
Emmanuel Grumbach | 7ba1faa | 2013-12-11 09:39:30 +0200 | [diff] [blame] | 1162 | if (!read) |
| 1163 | return 0; |
Emmanuel Grumbach | fc84472 | 2013-12-09 14:27:44 +0200 | [diff] [blame] | 1164 | |
| 1165 | /* |
| 1166 | * Collect all entries up to the first 0, starting from ict_index; |
| 1167 | * note we already read at ict_index. |
| 1168 | */ |
| 1169 | do { |
| 1170 | val |= read; |
| 1171 | IWL_DEBUG_ISR(trans, "ICT index %d value 0x%08X\n", |
| 1172 | trans_pcie->ict_index, read); |
| 1173 | trans_pcie->ict_tbl[trans_pcie->ict_index] = 0; |
| 1174 | trans_pcie->ict_index = |
Johannes Berg | 83f32a4 | 2014-04-24 09:57:40 +0200 | [diff] [blame] | 1175 | ((trans_pcie->ict_index + 1) & (ICT_COUNT - 1)); |
Emmanuel Grumbach | fc84472 | 2013-12-09 14:27:44 +0200 | [diff] [blame] | 1176 | |
| 1177 | read = le32_to_cpu(trans_pcie->ict_tbl[trans_pcie->ict_index]); |
| 1178 | trace_iwlwifi_dev_ict_read(trans->dev, trans_pcie->ict_index, |
| 1179 | read); |
| 1180 | } while (read); |
| 1181 | |
| 1182 | /* We should not get this value, just ignore it. */ |
| 1183 | if (val == 0xffffffff) |
| 1184 | val = 0; |
| 1185 | |
| 1186 | /* |
| 1187 | * this is a w/a for a h/w bug. the h/w bug may cause the Rx bit |
| 1188 | * (bit 15 before shifting it to 31) to clear when using interrupt |
| 1189 | * coalescing. fortunately, bits 18 and 19 stay set when this happens |
| 1190 | * so we use them to decide on the real state of the Rx bit. |
| 1191 | * In order words, bit 15 is set if bit 18 or bit 19 are set. |
| 1192 | */ |
| 1193 | if (val & 0xC0000) |
| 1194 | val |= 0x8000; |
| 1195 | |
| 1196 | inta = (0xff & val) | ((0xff00 & val) << 16); |
Emmanuel Grumbach | fe523dc | 2013-12-11 09:24:39 +0200 | [diff] [blame] | 1197 | return inta; |
Emmanuel Grumbach | fc84472 | 2013-12-09 14:27:44 +0200 | [diff] [blame] | 1198 | } |
| 1199 | |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 1200 | irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id) |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1201 | { |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 1202 | struct iwl_trans *trans = dev_id; |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 1203 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
| 1204 | struct isr_statistics *isr_stats = &trans_pcie->isr_stats; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1205 | u32 inta = 0; |
| 1206 | u32 handled = 0; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1207 | |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 1208 | lock_map_acquire(&trans->sync_cmd_lockdep_map); |
| 1209 | |
Emmanuel Grumbach | 7b70bd6 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 1210 | spin_lock(&trans_pcie->irq_lock); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1211 | |
Emmanuel Grumbach | 0fec954 | 2013-12-11 09:02:25 +0200 | [diff] [blame] | 1212 | /* dram interrupt table not set yet, |
| 1213 | * use legacy interrupt. |
| 1214 | */ |
| 1215 | if (likely(trans_pcie->use_ict)) |
Emmanuel Grumbach | 7117c00 | 2013-12-11 09:20:34 +0200 | [diff] [blame] | 1216 | inta = iwl_pcie_int_cause_ict(trans); |
Emmanuel Grumbach | 0fec954 | 2013-12-11 09:02:25 +0200 | [diff] [blame] | 1217 | else |
Emmanuel Grumbach | 7117c00 | 2013-12-11 09:20:34 +0200 | [diff] [blame] | 1218 | inta = iwl_pcie_int_cause_non_ict(trans); |
Emmanuel Grumbach | 0fec954 | 2013-12-11 09:02:25 +0200 | [diff] [blame] | 1219 | |
Emmanuel Grumbach | 7ba1faa | 2013-12-11 09:39:30 +0200 | [diff] [blame] | 1220 | if (iwl_have_debug_level(IWL_DL_ISR)) { |
| 1221 | IWL_DEBUG_ISR(trans, |
| 1222 | "ISR inta 0x%08x, enabled 0x%08x(sw), enabled(hw) 0x%08x, fh 0x%08x\n", |
| 1223 | inta, trans_pcie->inta_mask, |
| 1224 | iwl_read32(trans, CSR_INT_MASK), |
| 1225 | iwl_read32(trans, CSR_FH_INT_STATUS)); |
| 1226 | if (inta & (~trans_pcie->inta_mask)) |
| 1227 | IWL_DEBUG_ISR(trans, |
| 1228 | "We got a masked interrupt (0x%08x)\n", |
| 1229 | inta & (~trans_pcie->inta_mask)); |
| 1230 | } |
| 1231 | |
| 1232 | inta &= trans_pcie->inta_mask; |
| 1233 | |
| 1234 | /* |
| 1235 | * Ignore interrupt if there's nothing in NIC to service. |
| 1236 | * This may be due to IRQ shared with another device, |
| 1237 | * or due to sporadic interrupts thrown from our NIC. |
| 1238 | */ |
Emmanuel Grumbach | 7117c00 | 2013-12-11 09:20:34 +0200 | [diff] [blame] | 1239 | if (unlikely(!inta)) { |
Emmanuel Grumbach | 7ba1faa | 2013-12-11 09:39:30 +0200 | [diff] [blame] | 1240 | IWL_DEBUG_ISR(trans, "Ignore interrupt, inta == 0\n"); |
| 1241 | /* |
| 1242 | * Re-enable interrupts here since we don't |
| 1243 | * have anything to service |
| 1244 | */ |
| 1245 | if (test_bit(STATUS_INT_ENABLED, &trans->status)) |
| 1246 | iwl_enable_interrupts(trans); |
Emmanuel Grumbach | 7b70bd6 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 1247 | spin_unlock(&trans_pcie->irq_lock); |
Emmanuel Grumbach | 7117c00 | 2013-12-11 09:20:34 +0200 | [diff] [blame] | 1248 | lock_map_release(&trans->sync_cmd_lockdep_map); |
| 1249 | return IRQ_NONE; |
| 1250 | } |
| 1251 | |
Emmanuel Grumbach | 7ba1faa | 2013-12-11 09:39:30 +0200 | [diff] [blame] | 1252 | if (unlikely(inta == 0xFFFFFFFF || (inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
| 1253 | /* |
| 1254 | * Hardware disappeared. It might have |
| 1255 | * already raised an interrupt. |
| 1256 | */ |
| 1257 | IWL_WARN(trans, "HARDWARE GONE?? INTA == 0x%08x\n", inta); |
Emmanuel Grumbach | 7b70bd6 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 1258 | spin_unlock(&trans_pcie->irq_lock); |
Emmanuel Grumbach | 7117c00 | 2013-12-11 09:20:34 +0200 | [diff] [blame] | 1259 | goto out; |
Emmanuel Grumbach | a0f337c | 2013-12-11 09:00:03 +0200 | [diff] [blame] | 1260 | } |
| 1261 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1262 | /* Ack/clear/reset pending uCode interrupts. |
| 1263 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 1264 | */ |
| 1265 | /* There is a hardware bug in the interrupt mask function that some |
| 1266 | * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if |
| 1267 | * they are disabled in the CSR_INT_MASK register. Furthermore the |
| 1268 | * ICT interrupt handling mechanism has another bug that might cause |
| 1269 | * these unmasked interrupts fail to be detected. We workaround the |
| 1270 | * hardware bugs here by ACKing all the possible interrupts so that |
| 1271 | * interrupt coalescing can still be achieved. |
| 1272 | */ |
Emmanuel Grumbach | 7117c00 | 2013-12-11 09:20:34 +0200 | [diff] [blame] | 1273 | iwl_write32(trans, CSR_INT, inta | ~trans_pcie->inta_mask); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1274 | |
Johannes Berg | 51cd53a | 2013-06-12 09:56:51 +0200 | [diff] [blame] | 1275 | if (iwl_have_debug_level(IWL_DL_ISR)) |
Johannes Berg | 0ca24da | 2012-03-15 13:26:46 -0700 | [diff] [blame] | 1276 | IWL_DEBUG_ISR(trans, "inta 0x%08x, enabled 0x%08x\n", |
Johannes Berg | 51cd53a | 2013-06-12 09:56:51 +0200 | [diff] [blame] | 1277 | inta, iwl_read32(trans, CSR_INT_MASK)); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1278 | |
Emmanuel Grumbach | 7b70bd6 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 1279 | spin_unlock(&trans_pcie->irq_lock); |
Johannes Berg | b49ba04 | 2012-01-19 08:20:57 -0800 | [diff] [blame] | 1280 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1281 | /* Now service all interrupt bits discovered above. */ |
| 1282 | if (inta & CSR_INT_BIT_HW_ERR) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1283 | IWL_ERR(trans, "Hardware error detected. Restarting.\n"); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1284 | |
| 1285 | /* Tell the device to stop sending interrupts */ |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1286 | iwl_disable_interrupts(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1287 | |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1288 | isr_stats->hw++; |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 1289 | iwl_pcie_irq_handle_error(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1290 | |
| 1291 | handled |= CSR_INT_BIT_HW_ERR; |
| 1292 | |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 1293 | goto out; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
Johannes Berg | a8bceb3 | 2012-03-05 11:24:30 -0800 | [diff] [blame] | 1296 | if (iwl_have_debug_level(IWL_DL_ISR)) { |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1297 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
| 1298 | if (inta & CSR_INT_BIT_SCD) { |
Johannes Berg | 51cd53a | 2013-06-12 09:56:51 +0200 | [diff] [blame] | 1299 | IWL_DEBUG_ISR(trans, |
| 1300 | "Scheduler finished to transmit the frame/frames.\n"); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1301 | isr_stats->sch++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | /* Alive notification via Rx interrupt will do the real work */ |
| 1305 | if (inta & CSR_INT_BIT_ALIVE) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1306 | IWL_DEBUG_ISR(trans, "Alive interrupt\n"); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1307 | isr_stats->alive++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1308 | } |
| 1309 | } |
Johannes Berg | 51cd53a | 2013-06-12 09:56:51 +0200 | [diff] [blame] | 1310 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1311 | /* Safely ignore these bits for debug checks below */ |
| 1312 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
| 1313 | |
| 1314 | /* HW RF KILL switch toggled */ |
| 1315 | if (inta & CSR_INT_BIT_RF_KILL) { |
Johannes Berg | c9eec95 | 2012-03-06 13:30:43 -0800 | [diff] [blame] | 1316 | bool hw_rfkill; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1317 | |
Emmanuel Grumbach | 8d42551 | 2012-03-28 11:00:58 +0200 | [diff] [blame] | 1318 | hw_rfkill = iwl_is_rfkill_set(trans); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1319 | IWL_WARN(trans, "RF_KILL bit toggled to %s.\n", |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 1320 | hw_rfkill ? "disable radio" : "enable radio"); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1321 | |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1322 | isr_stats->rfkill++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1323 | |
Emmanuel Grumbach | fa9f328 | 2015-06-11 20:45:49 +0300 | [diff] [blame] | 1324 | mutex_lock(&trans_pcie->mutex); |
Johannes Berg | 14cfca7 | 2014-02-25 20:50:53 +0100 | [diff] [blame] | 1325 | iwl_trans_pcie_rf_kill(trans, hw_rfkill); |
Emmanuel Grumbach | fa9f328 | 2015-06-11 20:45:49 +0300 | [diff] [blame] | 1326 | mutex_unlock(&trans_pcie->mutex); |
Emmanuel Grumbach | f946b52 | 2012-10-25 17:25:52 +0200 | [diff] [blame] | 1327 | if (hw_rfkill) { |
Arik Nemtsov | eb7ff77 | 2013-12-01 12:30:38 +0200 | [diff] [blame] | 1328 | set_bit(STATUS_RFKILL, &trans->status); |
| 1329 | if (test_and_clear_bit(STATUS_SYNC_HCMD_ACTIVE, |
| 1330 | &trans->status)) |
Emmanuel Grumbach | f946b52 | 2012-10-25 17:25:52 +0200 | [diff] [blame] | 1331 | IWL_DEBUG_RF_KILL(trans, |
| 1332 | "Rfkill while SYNC HCMD in flight\n"); |
| 1333 | wake_up(&trans_pcie->wait_command_queue); |
| 1334 | } else { |
Arik Nemtsov | eb7ff77 | 2013-12-01 12:30:38 +0200 | [diff] [blame] | 1335 | clear_bit(STATUS_RFKILL, &trans->status); |
Emmanuel Grumbach | f946b52 | 2012-10-25 17:25:52 +0200 | [diff] [blame] | 1336 | } |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1337 | |
| 1338 | handled |= CSR_INT_BIT_RF_KILL; |
| 1339 | } |
| 1340 | |
| 1341 | /* Chip got too hot and stopped itself */ |
| 1342 | if (inta & CSR_INT_BIT_CT_KILL) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1343 | IWL_ERR(trans, "Microcode CT kill error detected.\n"); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1344 | isr_stats->ctkill++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1345 | handled |= CSR_INT_BIT_CT_KILL; |
| 1346 | } |
| 1347 | |
| 1348 | /* Error detected by uCode */ |
| 1349 | if (inta & CSR_INT_BIT_SW_ERR) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1350 | IWL_ERR(trans, "Microcode SW error detected. " |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1351 | " Restarting 0x%X.\n", inta); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1352 | isr_stats->sw++; |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 1353 | iwl_pcie_irq_handle_error(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1354 | handled |= CSR_INT_BIT_SW_ERR; |
| 1355 | } |
| 1356 | |
| 1357 | /* uCode wakes up after power-down sleep */ |
| 1358 | if (inta & CSR_INT_BIT_WAKEUP) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1359 | IWL_DEBUG_ISR(trans, "Wakeup interrupt\n"); |
Johannes Berg | 5d63f92 | 2014-02-27 11:20:07 +0100 | [diff] [blame] | 1360 | iwl_pcie_rxq_check_wrptr(trans); |
Johannes Berg | ea68f46 | 2014-02-27 14:36:55 +0100 | [diff] [blame] | 1361 | iwl_pcie_txq_check_wrptrs(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1362 | |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1363 | isr_stats->wakeup++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1364 | |
| 1365 | handled |= CSR_INT_BIT_WAKEUP; |
| 1366 | } |
| 1367 | |
| 1368 | /* All uCode command responses, including Tx command responses, |
| 1369 | * Rx "responses" (frame-received notification), and other |
| 1370 | * notifications from uCode come through here*/ |
| 1371 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX | |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 1372 | CSR_INT_BIT_RX_PERIODIC)) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1373 | IWL_DEBUG_ISR(trans, "Rx interrupt\n"); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1374 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
| 1375 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1376 | iwl_write32(trans, CSR_FH_INT_STATUS, |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1377 | CSR_FH_INT_RX_MASK); |
| 1378 | } |
| 1379 | if (inta & CSR_INT_BIT_RX_PERIODIC) { |
| 1380 | handled |= CSR_INT_BIT_RX_PERIODIC; |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1381 | iwl_write32(trans, |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1382 | CSR_INT, CSR_INT_BIT_RX_PERIODIC); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1383 | } |
| 1384 | /* Sending RX interrupt require many steps to be done in the |
| 1385 | * the device: |
| 1386 | * 1- write interrupt to current index in ICT table. |
| 1387 | * 2- dma RX frame. |
| 1388 | * 3- update RX shared data to indicate last write index. |
| 1389 | * 4- send interrupt. |
| 1390 | * This could lead to RX race, driver could receive RX interrupt |
| 1391 | * but the shared data changes does not reflect this; |
| 1392 | * periodic interrupt will detect any dangling Rx activity. |
| 1393 | */ |
| 1394 | |
| 1395 | /* Disable periodic interrupt; we use it as just a one-shot. */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1396 | iwl_write8(trans, CSR_INT_PERIODIC_REG, |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1397 | CSR_INT_PERIODIC_DIS); |
Johannes Berg | 6379103 | 2012-09-06 15:33:42 +0200 | [diff] [blame] | 1398 | |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1399 | /* |
| 1400 | * Enable periodic interrupt in 8 msec only if we received |
| 1401 | * real RX interrupt (instead of just periodic int), to catch |
| 1402 | * any dangling Rx interrupt. If it was just the periodic |
| 1403 | * interrupt, there was no dangling Rx activity, and no need |
| 1404 | * to extend the periodic interrupt; one-shot is enough. |
| 1405 | */ |
| 1406 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1407 | iwl_write8(trans, CSR_INT_PERIODIC_REG, |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 1408 | CSR_INT_PERIODIC_ENA); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1409 | |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1410 | isr_stats->rx++; |
Johannes Berg | f14d6b3 | 2014-03-21 13:30:03 +0100 | [diff] [blame] | 1411 | |
| 1412 | local_bh_disable(); |
| 1413 | iwl_pcie_rx_handle(trans); |
| 1414 | local_bh_enable(); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | /* This "Tx" DMA channel is used only for loading uCode */ |
| 1418 | if (inta & CSR_INT_BIT_FH_TX) { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1419 | iwl_write32(trans, CSR_FH_INT_STATUS, CSR_FH_INT_TX_MASK); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1420 | IWL_DEBUG_ISR(trans, "uCode load interrupt\n"); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1421 | isr_stats->tx++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1422 | handled |= CSR_INT_BIT_FH_TX; |
| 1423 | /* Wake up uCode load routine, now that load is complete */ |
Johannes Berg | 13df1aa | 2012-03-06 13:31:00 -0800 | [diff] [blame] | 1424 | trans_pcie->ucode_write_complete = true; |
| 1425 | wake_up(&trans_pcie->ucode_write_waitq); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | if (inta & ~handled) { |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1429 | IWL_ERR(trans, "Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1430 | isr_stats->unhandled++; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1431 | } |
| 1432 | |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1433 | if (inta & ~(trans_pcie->inta_mask)) { |
| 1434 | IWL_WARN(trans, "Disabled INTA bits 0x%08x were pending\n", |
| 1435 | inta & ~trans_pcie->inta_mask); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | /* Re-enable all interrupts */ |
| 1439 | /* only Re-enable if disabled by irq */ |
Arik Nemtsov | eb7ff77 | 2013-12-01 12:30:38 +0200 | [diff] [blame] | 1440 | if (test_bit(STATUS_INT_ENABLED, &trans->status)) |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1441 | iwl_enable_interrupts(trans); |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1442 | /* Re-enable RF_KILL if it occurred */ |
Stanislaw Gruszka | 8722c89 | 2012-03-07 09:52:28 -0800 | [diff] [blame] | 1443 | else if (handled & CSR_INT_BIT_RF_KILL) |
| 1444 | iwl_enable_rfkill_int(trans); |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 1445 | |
| 1446 | out: |
| 1447 | lock_map_release(&trans->sync_cmd_lockdep_map); |
| 1448 | return IRQ_HANDLED; |
Emmanuel Grumbach | ab697a9 | 2011-07-11 07:35:34 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1451 | /****************************************************************************** |
| 1452 | * |
| 1453 | * ICT functions |
| 1454 | * |
| 1455 | ******************************************************************************/ |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1456 | |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1457 | /* Free dram table */ |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 1458 | void iwl_pcie_free_ict(struct iwl_trans *trans) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1459 | { |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 1460 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1461 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1462 | if (trans_pcie->ict_tbl) { |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1463 | dma_free_coherent(trans->dev, ICT_SIZE, |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1464 | trans_pcie->ict_tbl, |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1465 | trans_pcie->ict_tbl_dma); |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1466 | trans_pcie->ict_tbl = NULL; |
| 1467 | trans_pcie->ict_tbl_dma = 0; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1468 | } |
| 1469 | } |
| 1470 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1471 | /* |
| 1472 | * allocate dram shared table, it is an aligned memory |
| 1473 | * block of ICT_SIZE. |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1474 | * also reset all data related to ICT table interrupt. |
| 1475 | */ |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 1476 | int iwl_pcie_alloc_ict(struct iwl_trans *trans) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1477 | { |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 1478 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1479 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1480 | trans_pcie->ict_tbl = |
Emmanuel Grumbach | eef3171 | 2013-12-09 09:47:46 +0200 | [diff] [blame] | 1481 | dma_zalloc_coherent(trans->dev, ICT_SIZE, |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1482 | &trans_pcie->ict_tbl_dma, |
| 1483 | GFP_KERNEL); |
| 1484 | if (!trans_pcie->ict_tbl) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1485 | return -ENOMEM; |
| 1486 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1487 | /* just an API sanity check ... it is guaranteed to be aligned */ |
| 1488 | if (WARN_ON(trans_pcie->ict_tbl_dma & (ICT_SIZE - 1))) { |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 1489 | iwl_pcie_free_ict(trans); |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1490 | return -EINVAL; |
| 1491 | } |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1492 | |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1493 | return 0; |
| 1494 | } |
| 1495 | |
| 1496 | /* Device is going up inform it about using ICT interrupt table, |
| 1497 | * also we need to tell the driver to start using ICT interrupt. |
| 1498 | */ |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 1499 | void iwl_pcie_reset_ict(struct iwl_trans *trans) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1500 | { |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 1501 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1502 | u32 val; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1503 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1504 | if (!trans_pcie->ict_tbl) |
Emmanuel Grumbach | ed6a380 | 2012-01-02 16:10:08 +0200 | [diff] [blame] | 1505 | return; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1506 | |
Emmanuel Grumbach | 7b70bd6 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 1507 | spin_lock(&trans_pcie->irq_lock); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1508 | iwl_disable_interrupts(trans); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1509 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1510 | memset(trans_pcie->ict_tbl, 0, ICT_SIZE); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1511 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1512 | val = trans_pcie->ict_tbl_dma >> ICT_SHIFT; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1513 | |
Eliad Peller | 18f5a37 | 2015-07-16 20:17:42 +0300 | [diff] [blame] | 1514 | val |= CSR_DRAM_INT_TBL_ENABLE | |
| 1515 | CSR_DRAM_INIT_TBL_WRAP_CHECK | |
| 1516 | CSR_DRAM_INIT_TBL_WRITE_POINTER; |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1517 | |
Johannes Berg | 1066713 | 2011-12-19 14:00:59 -0800 | [diff] [blame] | 1518 | 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] | 1519 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1520 | iwl_write32(trans, CSR_DRAM_INT_TBL_REG, val); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1521 | trans_pcie->use_ict = true; |
| 1522 | trans_pcie->ict_index = 0; |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 1523 | iwl_write32(trans, CSR_INT, trans_pcie->inta_mask); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1524 | iwl_enable_interrupts(trans); |
Emmanuel Grumbach | 7b70bd6 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 1525 | spin_unlock(&trans_pcie->irq_lock); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | /* Device is going down disable ict interrupt usage */ |
Emmanuel Grumbach | 990aa6d | 2012-11-14 12:39:52 +0200 | [diff] [blame] | 1529 | void iwl_pcie_disable_ict(struct iwl_trans *trans) |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1530 | { |
Johannes Berg | 20d3b64 | 2012-05-16 22:54:29 +0200 | [diff] [blame] | 1531 | struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1532 | |
Emmanuel Grumbach | 7b70bd6 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 1533 | spin_lock(&trans_pcie->irq_lock); |
Emmanuel Grumbach | 0c32576 | 2011-08-25 23:10:53 -0700 | [diff] [blame] | 1534 | trans_pcie->use_ict = false; |
Emmanuel Grumbach | 7b70bd6 | 2013-12-11 10:22:28 +0200 | [diff] [blame] | 1535 | spin_unlock(&trans_pcie->irq_lock); |
Emmanuel Grumbach | 1a361cd | 2011-07-11 07:44:57 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
Emmanuel Grumbach | 85bf9da | 2013-12-09 11:48:30 +0200 | [diff] [blame] | 1538 | irqreturn_t iwl_pcie_isr(int irq, void *data) |
| 1539 | { |
| 1540 | struct iwl_trans *trans = data; |
| 1541 | |
| 1542 | if (!trans) |
| 1543 | return IRQ_NONE; |
| 1544 | |
| 1545 | /* Disable (but don't clear!) interrupts here to avoid |
| 1546 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 1547 | * If we have something to service, the tasklet will re-enable ints. |
| 1548 | * If we *don't* have something, we'll re-enable before leaving here. |
| 1549 | */ |
| 1550 | iwl_write32(trans, CSR_INT_MASK, 0x00000000); |
| 1551 | |
Emmanuel Grumbach | a0f337c | 2013-12-11 09:00:03 +0200 | [diff] [blame] | 1552 | return IRQ_WAKE_THREAD; |
Emmanuel Grumbach | 85bf9da | 2013-12-09 11:48:30 +0200 | [diff] [blame] | 1553 | } |