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