Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org> |
| 3 | * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com> |
| 4 | * |
| 5 | * Permission to use, copy, modify, and distribute this software for any |
| 6 | * purpose with or without fee is hereby granted, provided that the above |
| 7 | * copyright notice and this permission notice appear in all copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | /*************************************\ |
| 20 | * DMA and interrupt masking functions * |
| 21 | \*************************************/ |
| 22 | |
| 23 | /* |
| 24 | * dma.c - DMA and interrupt masking functions |
| 25 | * |
| 26 | * Here we setup descriptor pointers (rxdp/txdp) start/stop dma engine and |
| 27 | * handle queue setup for 5210 chipset (rest are handled on qcu.c). |
| 28 | * Also we setup interrupt mask register (IMR) and read the various iterrupt |
| 29 | * status registers (ISR). |
| 30 | * |
| 31 | * TODO: Handle SISR on 5211+ and introduce a function to return the queue |
| 32 | * number that resulted the interrupt. |
| 33 | */ |
| 34 | |
| 35 | #include "ath5k.h" |
| 36 | #include "reg.h" |
| 37 | #include "debug.h" |
| 38 | #include "base.h" |
| 39 | |
Nick Kossifidis | 9320b5c | 2010-11-23 20:36:45 +0200 | [diff] [blame] | 40 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 41 | /*********\ |
| 42 | * Receive * |
| 43 | \*********/ |
| 44 | |
| 45 | /** |
| 46 | * ath5k_hw_start_rx_dma - Start DMA receive |
| 47 | * |
| 48 | * @ah: The &struct ath5k_hw |
| 49 | */ |
| 50 | void ath5k_hw_start_rx_dma(struct ath5k_hw *ah) |
| 51 | { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 52 | ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR); |
| 53 | ath5k_hw_reg_read(ah, AR5K_CR); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * ath5k_hw_stop_rx_dma - Stop DMA receive |
| 58 | * |
| 59 | * @ah: The &struct ath5k_hw |
| 60 | */ |
| 61 | int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah) |
| 62 | { |
| 63 | unsigned int i; |
| 64 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 65 | ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR); |
| 66 | |
| 67 | /* |
| 68 | * It may take some time to disable the DMA receive unit |
| 69 | */ |
Nick Kossifidis | 509a106 | 2008-09-29 01:23:07 +0300 | [diff] [blame] | 70 | for (i = 1000; i > 0 && |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 71 | (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0; |
| 72 | i--) |
Nick Kossifidis | b3a28e6 | 2010-11-23 20:47:31 +0200 | [diff] [blame] | 73 | udelay(100); |
| 74 | |
| 75 | if (i) |
| 76 | ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_DMA, |
| 77 | "failed to stop RX DMA !\n"); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 78 | |
| 79 | return i ? 0 : -EBUSY; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * ath5k_hw_get_rxdp - Get RX Descriptor's address |
| 84 | * |
| 85 | * @ah: The &struct ath5k_hw |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 86 | */ |
| 87 | u32 ath5k_hw_get_rxdp(struct ath5k_hw *ah) |
| 88 | { |
| 89 | return ath5k_hw_reg_read(ah, AR5K_RXDP); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * ath5k_hw_set_rxdp - Set RX Descriptor's address |
| 94 | * |
| 95 | * @ah: The &struct ath5k_hw |
| 96 | * @phys_addr: RX descriptor address |
| 97 | * |
| 98 | * XXX: Should we check if rx is enabled before setting rxdp ? |
| 99 | */ |
| 100 | void ath5k_hw_set_rxdp(struct ath5k_hw *ah, u32 phys_addr) |
| 101 | { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 102 | ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | /**********\ |
| 107 | * Transmit * |
| 108 | \**********/ |
| 109 | |
| 110 | /** |
| 111 | * ath5k_hw_start_tx_dma - Start DMA transmit for a specific queue |
| 112 | * |
| 113 | * @ah: The &struct ath5k_hw |
| 114 | * @queue: The hw queue number |
| 115 | * |
| 116 | * Start DMA transmit for a specific queue and since 5210 doesn't have |
| 117 | * QCU/DCU, set up queue parameters for 5210 here based on queue type (one |
| 118 | * queue for normal data and one queue for beacons). For queue setup |
| 119 | * on newer chips check out qcu.c. Returns -EINVAL if queue number is out |
| 120 | * of range or if queue is already disabled. |
| 121 | * |
| 122 | * NOTE: Must be called after setting up tx control descriptor for that |
| 123 | * queue (see below). |
| 124 | */ |
| 125 | int ath5k_hw_start_tx_dma(struct ath5k_hw *ah, unsigned int queue) |
| 126 | { |
| 127 | u32 tx_queue; |
| 128 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 129 | AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num); |
| 130 | |
| 131 | /* Return if queue is declared inactive */ |
| 132 | if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE) |
Nick Kossifidis | d41174f | 2010-11-23 20:41:15 +0200 | [diff] [blame] | 133 | return -EINVAL; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 134 | |
| 135 | if (ah->ah_version == AR5K_AR5210) { |
| 136 | tx_queue = ath5k_hw_reg_read(ah, AR5K_CR); |
| 137 | |
| 138 | /* |
| 139 | * Set the queue by type on 5210 |
| 140 | */ |
| 141 | switch (ah->ah_txq[queue].tqi_type) { |
| 142 | case AR5K_TX_QUEUE_DATA: |
| 143 | tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0; |
| 144 | break; |
| 145 | case AR5K_TX_QUEUE_BEACON: |
| 146 | tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1; |
| 147 | ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE, |
| 148 | AR5K_BSR); |
| 149 | break; |
| 150 | case AR5K_TX_QUEUE_CAB: |
| 151 | tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1; |
| 152 | ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V | |
| 153 | AR5K_BCR_BDMAE, AR5K_BSR); |
| 154 | break; |
| 155 | default: |
| 156 | return -EINVAL; |
| 157 | } |
| 158 | /* Start queue */ |
| 159 | ath5k_hw_reg_write(ah, tx_queue, AR5K_CR); |
| 160 | ath5k_hw_reg_read(ah, AR5K_CR); |
| 161 | } else { |
| 162 | /* Return if queue is disabled */ |
| 163 | if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue)) |
| 164 | return -EIO; |
| 165 | |
| 166 | /* Start queue */ |
| 167 | AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue); |
| 168 | } |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * ath5k_hw_stop_tx_dma - Stop DMA transmit on a specific queue |
| 175 | * |
| 176 | * @ah: The &struct ath5k_hw |
| 177 | * @queue: The hw queue number |
| 178 | * |
| 179 | * Stop DMA transmit on a specific hw queue and drain queue so we don't |
| 180 | * have any pending frames. Returns -EBUSY if we still have pending frames, |
Nick Kossifidis | d41174f | 2010-11-23 20:41:15 +0200 | [diff] [blame] | 181 | * -EINVAL if queue number is out of range or inactive. |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 182 | * |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 183 | */ |
| 184 | int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue) |
| 185 | { |
Nick Kossifidis | 509a106 | 2008-09-29 01:23:07 +0300 | [diff] [blame] | 186 | unsigned int i = 40; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 187 | u32 tx_queue, pending; |
| 188 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 189 | AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num); |
| 190 | |
| 191 | /* Return if queue is declared inactive */ |
| 192 | if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE) |
Nick Kossifidis | d41174f | 2010-11-23 20:41:15 +0200 | [diff] [blame] | 193 | return -EINVAL; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 194 | |
| 195 | if (ah->ah_version == AR5K_AR5210) { |
| 196 | tx_queue = ath5k_hw_reg_read(ah, AR5K_CR); |
| 197 | |
| 198 | /* |
| 199 | * Set by queue type |
| 200 | */ |
| 201 | switch (ah->ah_txq[queue].tqi_type) { |
| 202 | case AR5K_TX_QUEUE_DATA: |
| 203 | tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0; |
| 204 | break; |
| 205 | case AR5K_TX_QUEUE_BEACON: |
| 206 | case AR5K_TX_QUEUE_CAB: |
| 207 | /* XXX Fix me... */ |
| 208 | tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1; |
| 209 | ath5k_hw_reg_write(ah, 0, AR5K_BSR); |
| 210 | break; |
| 211 | default: |
| 212 | return -EINVAL; |
| 213 | } |
| 214 | |
| 215 | /* Stop queue */ |
| 216 | ath5k_hw_reg_write(ah, tx_queue, AR5K_CR); |
| 217 | ath5k_hw_reg_read(ah, AR5K_CR); |
| 218 | } else { |
Nick Kossifidis | f7317ba | 2010-11-23 20:50:16 +0200 | [diff] [blame^] | 219 | |
| 220 | /* |
| 221 | * Enable DCU early termination to quickly |
| 222 | * flush any pending frames from QCU |
| 223 | */ |
| 224 | AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue), |
| 225 | AR5K_QCU_MISC_DCU_EARLY); |
| 226 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 227 | /* |
| 228 | * Schedule TX disable and wait until queue is empty |
| 229 | */ |
| 230 | AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue); |
| 231 | |
Nick Kossifidis | b3a28e6 | 2010-11-23 20:47:31 +0200 | [diff] [blame] | 232 | /* Wait for queue to stop */ |
| 233 | for (i = 1000; i > 0 && |
| 234 | (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue) != 0); |
| 235 | i--) |
| 236 | udelay(100); |
| 237 | |
| 238 | if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue)) |
| 239 | ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_DMA, |
| 240 | "queue %i didn't stop !\n", queue); |
| 241 | |
| 242 | /* Check for pending frames */ |
| 243 | i = 1000; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 244 | do { |
| 245 | pending = ath5k_hw_reg_read(ah, |
| 246 | AR5K_QUEUE_STATUS(queue)) & |
| 247 | AR5K_QCU_STS_FRMPENDCNT; |
| 248 | udelay(100); |
| 249 | } while (--i && pending); |
| 250 | |
Nick Kossifidis | 509a106 | 2008-09-29 01:23:07 +0300 | [diff] [blame] | 251 | /* For 2413+ order PCU to drop packets using |
| 252 | * QUIET mechanism */ |
| 253 | if (ah->ah_mac_version >= (AR5K_SREV_AR2414 >> 4) && |
| 254 | pending){ |
| 255 | /* Set periodicity and duration */ |
| 256 | ath5k_hw_reg_write(ah, |
| 257 | AR5K_REG_SM(100, AR5K_QUIET_CTL2_QT_PER)| |
| 258 | AR5K_REG_SM(10, AR5K_QUIET_CTL2_QT_DUR), |
| 259 | AR5K_QUIET_CTL2); |
| 260 | |
| 261 | /* Enable quiet period for current TSF */ |
| 262 | ath5k_hw_reg_write(ah, |
| 263 | AR5K_QUIET_CTL1_QT_EN | |
| 264 | AR5K_REG_SM(ath5k_hw_reg_read(ah, |
| 265 | AR5K_TSF_L32_5211) >> 10, |
| 266 | AR5K_QUIET_CTL1_NEXT_QT_TSF), |
| 267 | AR5K_QUIET_CTL1); |
| 268 | |
| 269 | /* Force channel idle high */ |
| 270 | AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5211, |
Bruno Randolf | eada7ca | 2010-09-27 13:02:40 +0900 | [diff] [blame] | 271 | AR5K_DIAG_SW_CHANNEL_IDLE_HIGH); |
Nick Kossifidis | 509a106 | 2008-09-29 01:23:07 +0300 | [diff] [blame] | 272 | |
| 273 | /* Wait a while and disable mechanism */ |
Nick Kossifidis | b3a28e6 | 2010-11-23 20:47:31 +0200 | [diff] [blame] | 274 | udelay(400); |
Nick Kossifidis | 509a106 | 2008-09-29 01:23:07 +0300 | [diff] [blame] | 275 | AR5K_REG_DISABLE_BITS(ah, AR5K_QUIET_CTL1, |
| 276 | AR5K_QUIET_CTL1_QT_EN); |
| 277 | |
| 278 | /* Re-check for pending frames */ |
Nick Kossifidis | b3a28e6 | 2010-11-23 20:47:31 +0200 | [diff] [blame] | 279 | i = 100; |
Nick Kossifidis | 509a106 | 2008-09-29 01:23:07 +0300 | [diff] [blame] | 280 | do { |
| 281 | pending = ath5k_hw_reg_read(ah, |
| 282 | AR5K_QUEUE_STATUS(queue)) & |
| 283 | AR5K_QCU_STS_FRMPENDCNT; |
| 284 | udelay(100); |
| 285 | } while (--i && pending); |
| 286 | |
| 287 | AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW_5211, |
Bruno Randolf | eada7ca | 2010-09-27 13:02:40 +0900 | [diff] [blame] | 288 | AR5K_DIAG_SW_CHANNEL_IDLE_HIGH); |
Nick Kossifidis | b3a28e6 | 2010-11-23 20:47:31 +0200 | [diff] [blame] | 289 | |
| 290 | if (pending) |
| 291 | ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_DMA, |
| 292 | "quiet mechanism didn't work q:%i !\n", |
| 293 | queue); |
Nick Kossifidis | 509a106 | 2008-09-29 01:23:07 +0300 | [diff] [blame] | 294 | } |
| 295 | |
Nick Kossifidis | f7317ba | 2010-11-23 20:50:16 +0200 | [diff] [blame^] | 296 | /* |
| 297 | * Disable DCU early termination |
| 298 | */ |
| 299 | AR5K_REG_DISABLE_BITS(ah, AR5K_QUEUE_MISC(queue), |
| 300 | AR5K_QCU_MISC_DCU_EARLY); |
| 301 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 302 | /* Clear register */ |
| 303 | ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD); |
Nick Kossifidis | b3a28e6 | 2010-11-23 20:47:31 +0200 | [diff] [blame] | 304 | if (pending) { |
| 305 | ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_DMA, |
| 306 | "tx dma didn't stop (q:%i, frm:%i) !\n", |
| 307 | queue, pending); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 308 | return -EBUSY; |
Nick Kossifidis | b3a28e6 | 2010-11-23 20:47:31 +0200 | [diff] [blame] | 309 | } |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 310 | } |
| 311 | |
Nick Kossifidis | 509a106 | 2008-09-29 01:23:07 +0300 | [diff] [blame] | 312 | /* TODO: Check for success on 5210 else return error */ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * ath5k_hw_get_txdp - Get TX Descriptor's address for a specific queue |
| 318 | * |
| 319 | * @ah: The &struct ath5k_hw |
| 320 | * @queue: The hw queue number |
| 321 | * |
| 322 | * Get TX descriptor's address for a specific queue. For 5210 we ignore |
| 323 | * the queue number and use tx queue type since we only have 2 queues. |
| 324 | * We use TXDP0 for normal data queue and TXDP1 for beacon queue. |
| 325 | * For newer chips with QCU/DCU we just read the corresponding TXDP register. |
| 326 | * |
| 327 | * XXX: Is TXDP read and clear ? |
| 328 | */ |
| 329 | u32 ath5k_hw_get_txdp(struct ath5k_hw *ah, unsigned int queue) |
| 330 | { |
| 331 | u16 tx_reg; |
| 332 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 333 | AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num); |
| 334 | |
| 335 | /* |
| 336 | * Get the transmit queue descriptor pointer from the selected queue |
| 337 | */ |
| 338 | /*5210 doesn't have QCU*/ |
| 339 | if (ah->ah_version == AR5K_AR5210) { |
| 340 | switch (ah->ah_txq[queue].tqi_type) { |
| 341 | case AR5K_TX_QUEUE_DATA: |
| 342 | tx_reg = AR5K_NOQCU_TXDP0; |
| 343 | break; |
| 344 | case AR5K_TX_QUEUE_BEACON: |
| 345 | case AR5K_TX_QUEUE_CAB: |
| 346 | tx_reg = AR5K_NOQCU_TXDP1; |
| 347 | break; |
| 348 | default: |
| 349 | return 0xffffffff; |
| 350 | } |
| 351 | } else { |
| 352 | tx_reg = AR5K_QUEUE_TXDP(queue); |
| 353 | } |
| 354 | |
| 355 | return ath5k_hw_reg_read(ah, tx_reg); |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * ath5k_hw_set_txdp - Set TX Descriptor's address for a specific queue |
| 360 | * |
| 361 | * @ah: The &struct ath5k_hw |
| 362 | * @queue: The hw queue number |
| 363 | * |
| 364 | * Set TX descriptor's address for a specific queue. For 5210 we ignore |
| 365 | * the queue number and we use tx queue type since we only have 2 queues |
| 366 | * so as above we use TXDP0 for normal data queue and TXDP1 for beacon queue. |
| 367 | * For newer chips with QCU/DCU we just set the corresponding TXDP register. |
| 368 | * Returns -EINVAL if queue type is invalid for 5210 and -EIO if queue is still |
| 369 | * active. |
| 370 | */ |
| 371 | int ath5k_hw_set_txdp(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr) |
| 372 | { |
| 373 | u16 tx_reg; |
| 374 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 375 | AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num); |
| 376 | |
| 377 | /* |
| 378 | * Set the transmit queue descriptor pointer register by type |
| 379 | * on 5210 |
| 380 | */ |
| 381 | if (ah->ah_version == AR5K_AR5210) { |
| 382 | switch (ah->ah_txq[queue].tqi_type) { |
| 383 | case AR5K_TX_QUEUE_DATA: |
| 384 | tx_reg = AR5K_NOQCU_TXDP0; |
| 385 | break; |
| 386 | case AR5K_TX_QUEUE_BEACON: |
| 387 | case AR5K_TX_QUEUE_CAB: |
| 388 | tx_reg = AR5K_NOQCU_TXDP1; |
| 389 | break; |
| 390 | default: |
| 391 | return -EINVAL; |
| 392 | } |
| 393 | } else { |
| 394 | /* |
| 395 | * Set the transmit queue descriptor pointer for |
| 396 | * the selected queue on QCU for 5211+ |
| 397 | * (this won't work if the queue is still active) |
| 398 | */ |
| 399 | if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue)) |
| 400 | return -EIO; |
| 401 | |
| 402 | tx_reg = AR5K_QUEUE_TXDP(queue); |
| 403 | } |
| 404 | |
| 405 | /* Set descriptor pointer */ |
| 406 | ath5k_hw_reg_write(ah, phys_addr, tx_reg); |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * ath5k_hw_update_tx_triglevel - Update tx trigger level |
| 413 | * |
| 414 | * @ah: The &struct ath5k_hw |
| 415 | * @increase: Flag to force increase of trigger level |
| 416 | * |
| 417 | * This function increases/decreases the tx trigger level for the tx fifo |
| 418 | * buffer (aka FIFO threshold) that is used to indicate when PCU flushes |
Bob Copeland | a180a13 | 2010-08-15 13:03:12 -0400 | [diff] [blame] | 419 | * the buffer and transmits its data. Lowering this results sending small |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 420 | * frames more quickly but can lead to tx underruns, raising it a lot can |
| 421 | * result other problems (i think bmiss is related). Right now we start with |
| 422 | * the lowest possible (64Bytes) and if we get tx underrun we increase it using |
Bob Copeland | a180a13 | 2010-08-15 13:03:12 -0400 | [diff] [blame] | 423 | * the increase flag. Returns -EIO if we have reached maximum/minimum. |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 424 | * |
| 425 | * XXX: Link this with tx DMA size ? |
| 426 | * XXX: Use it to save interrupts ? |
| 427 | * TODO: Needs testing, i think it's related to bmiss... |
| 428 | */ |
| 429 | int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase) |
| 430 | { |
| 431 | u32 trigger_level, imr; |
| 432 | int ret = -EIO; |
| 433 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 434 | /* |
| 435 | * Disable interrupts by setting the mask |
| 436 | */ |
| 437 | imr = ath5k_hw_set_imr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL); |
| 438 | |
| 439 | trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG), |
| 440 | AR5K_TXCFG_TXFULL); |
| 441 | |
| 442 | if (!increase) { |
| 443 | if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES) |
| 444 | goto done; |
| 445 | } else |
| 446 | trigger_level += |
| 447 | ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2); |
| 448 | |
| 449 | /* |
| 450 | * Update trigger level on success |
| 451 | */ |
| 452 | if (ah->ah_version == AR5K_AR5210) |
| 453 | ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL); |
| 454 | else |
| 455 | AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG, |
| 456 | AR5K_TXCFG_TXFULL, trigger_level); |
| 457 | |
| 458 | ret = 0; |
| 459 | |
| 460 | done: |
| 461 | /* |
| 462 | * Restore interrupt mask |
| 463 | */ |
| 464 | ath5k_hw_set_imr(ah, imr); |
| 465 | |
| 466 | return ret; |
| 467 | } |
| 468 | |
Nick Kossifidis | 9320b5c | 2010-11-23 20:36:45 +0200 | [diff] [blame] | 469 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 470 | /*******************\ |
| 471 | * Interrupt masking * |
| 472 | \*******************/ |
| 473 | |
| 474 | /** |
| 475 | * ath5k_hw_is_intr_pending - Check if we have pending interrupts |
| 476 | * |
| 477 | * @ah: The &struct ath5k_hw |
| 478 | * |
| 479 | * Check if we have pending interrupts to process. Returns 1 if we |
| 480 | * have pending interrupts and 0 if we haven't. |
| 481 | */ |
| 482 | bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah) |
| 483 | { |
Nick Kossifidis | 509a106 | 2008-09-29 01:23:07 +0300 | [diff] [blame] | 484 | return ath5k_hw_reg_read(ah, AR5K_INTPEND) == 1 ? 1 : 0; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | /** |
| 488 | * ath5k_hw_get_isr - Get interrupt status |
| 489 | * |
| 490 | * @ah: The @struct ath5k_hw |
| 491 | * @interrupt_mask: Driver's interrupt mask used to filter out |
| 492 | * interrupts in sw. |
| 493 | * |
| 494 | * This function is used inside our interrupt handler to determine the reason |
| 495 | * for the interrupt by reading Primary Interrupt Status Register. Returns an |
| 496 | * abstract interrupt status mask which is mostly ISR with some uncommon bits |
| 497 | * being mapped on some standard non hw-specific positions |
| 498 | * (check out &ath5k_int). |
| 499 | * |
| 500 | * NOTE: We use read-and-clear register, so after this function is called ISR |
| 501 | * is zeroed. |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 502 | */ |
| 503 | int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask) |
| 504 | { |
| 505 | u32 data; |
| 506 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 507 | /* |
| 508 | * Read interrupt status from the Interrupt Status register |
| 509 | * on 5210 |
| 510 | */ |
| 511 | if (ah->ah_version == AR5K_AR5210) { |
| 512 | data = ath5k_hw_reg_read(ah, AR5K_ISR); |
| 513 | if (unlikely(data == AR5K_INT_NOCARD)) { |
| 514 | *interrupt_mask = data; |
| 515 | return -ENODEV; |
| 516 | } |
| 517 | } else { |
| 518 | /* |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 519 | * Read interrupt status from Interrupt |
| 520 | * Status Register shadow copy (Read And Clear) |
| 521 | * |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 522 | * Note: PISR/SISR Not available on 5210 |
| 523 | */ |
| 524 | data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR); |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 525 | if (unlikely(data == AR5K_INT_NOCARD)) { |
| 526 | *interrupt_mask = data; |
| 527 | return -ENODEV; |
| 528 | } |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /* |
| 532 | * Get abstract interrupt mask (driver-compatible) |
| 533 | */ |
| 534 | *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr; |
| 535 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 536 | if (ah->ah_version != AR5K_AR5210) { |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 537 | u32 sisr2 = ath5k_hw_reg_read(ah, AR5K_RAC_SISR2); |
| 538 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 539 | /*HIU = Host Interface Unit (PCI etc)*/ |
| 540 | if (unlikely(data & (AR5K_ISR_HIUERR))) |
| 541 | *interrupt_mask |= AR5K_INT_FATAL; |
| 542 | |
| 543 | /*Beacon Not Ready*/ |
| 544 | if (unlikely(data & (AR5K_ISR_BNR))) |
| 545 | *interrupt_mask |= AR5K_INT_BNR; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 546 | |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 547 | if (unlikely(sisr2 & (AR5K_SISR2_SSERR | |
| 548 | AR5K_SISR2_DPERR | |
| 549 | AR5K_SISR2_MCABT))) |
| 550 | *interrupt_mask |= AR5K_INT_FATAL; |
| 551 | |
| 552 | if (data & AR5K_ISR_TIM) |
| 553 | *interrupt_mask |= AR5K_INT_TIM; |
| 554 | |
| 555 | if (data & AR5K_ISR_BCNMISC) { |
| 556 | if (sisr2 & AR5K_SISR2_TIM) |
| 557 | *interrupt_mask |= AR5K_INT_TIM; |
| 558 | if (sisr2 & AR5K_SISR2_DTIM) |
| 559 | *interrupt_mask |= AR5K_INT_DTIM; |
| 560 | if (sisr2 & AR5K_SISR2_DTIM_SYNC) |
| 561 | *interrupt_mask |= AR5K_INT_DTIM_SYNC; |
| 562 | if (sisr2 & AR5K_SISR2_BCN_TIMEOUT) |
| 563 | *interrupt_mask |= AR5K_INT_BCN_TIMEOUT; |
| 564 | if (sisr2 & AR5K_SISR2_CAB_TIMEOUT) |
| 565 | *interrupt_mask |= AR5K_INT_CAB_TIMEOUT; |
| 566 | } |
| 567 | |
| 568 | if (data & AR5K_ISR_RXDOPPLER) |
| 569 | *interrupt_mask |= AR5K_INT_RX_DOPPLER; |
| 570 | if (data & AR5K_ISR_QCBRORN) { |
| 571 | *interrupt_mask |= AR5K_INT_QCBRORN; |
| 572 | ah->ah_txq_isr |= AR5K_REG_MS( |
| 573 | ath5k_hw_reg_read(ah, AR5K_RAC_SISR3), |
| 574 | AR5K_SISR3_QCBRORN); |
| 575 | } |
| 576 | if (data & AR5K_ISR_QCBRURN) { |
| 577 | *interrupt_mask |= AR5K_INT_QCBRURN; |
| 578 | ah->ah_txq_isr |= AR5K_REG_MS( |
| 579 | ath5k_hw_reg_read(ah, AR5K_RAC_SISR3), |
| 580 | AR5K_SISR3_QCBRURN); |
| 581 | } |
| 582 | if (data & AR5K_ISR_QTRIG) { |
| 583 | *interrupt_mask |= AR5K_INT_QTRIG; |
| 584 | ah->ah_txq_isr |= AR5K_REG_MS( |
| 585 | ath5k_hw_reg_read(ah, AR5K_RAC_SISR4), |
| 586 | AR5K_SISR4_QTRIG); |
| 587 | } |
| 588 | |
| 589 | if (data & AR5K_ISR_TXOK) |
| 590 | ah->ah_txq_isr |= AR5K_REG_MS( |
| 591 | ath5k_hw_reg_read(ah, AR5K_RAC_SISR0), |
| 592 | AR5K_SISR0_QCU_TXOK); |
| 593 | |
| 594 | if (data & AR5K_ISR_TXDESC) |
| 595 | ah->ah_txq_isr |= AR5K_REG_MS( |
| 596 | ath5k_hw_reg_read(ah, AR5K_RAC_SISR0), |
| 597 | AR5K_SISR0_QCU_TXDESC); |
| 598 | |
| 599 | if (data & AR5K_ISR_TXERR) |
| 600 | ah->ah_txq_isr |= AR5K_REG_MS( |
| 601 | ath5k_hw_reg_read(ah, AR5K_RAC_SISR1), |
| 602 | AR5K_SISR1_QCU_TXERR); |
| 603 | |
| 604 | if (data & AR5K_ISR_TXEOL) |
| 605 | ah->ah_txq_isr |= AR5K_REG_MS( |
| 606 | ath5k_hw_reg_read(ah, AR5K_RAC_SISR1), |
| 607 | AR5K_SISR1_QCU_TXEOL); |
| 608 | |
| 609 | if (data & AR5K_ISR_TXURN) |
| 610 | ah->ah_txq_isr |= AR5K_REG_MS( |
| 611 | ath5k_hw_reg_read(ah, AR5K_RAC_SISR2), |
| 612 | AR5K_SISR2_QCU_TXURN); |
| 613 | } else { |
| 614 | if (unlikely(data & (AR5K_ISR_SSERR | AR5K_ISR_MCABT |
| 615 | | AR5K_ISR_HIUERR | AR5K_ISR_DPERR))) |
| 616 | *interrupt_mask |= AR5K_INT_FATAL; |
| 617 | |
| 618 | /* |
| 619 | * XXX: BMISS interrupts may occur after association. |
| 620 | * I found this on 5210 code but it needs testing. If this is |
| 621 | * true we should disable them before assoc and re-enable them |
Coly Li | 73ac36e | 2009-01-07 18:09:16 -0800 | [diff] [blame] | 622 | * after a successful assoc + some jiffies. |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 623 | interrupt_mask &= ~AR5K_INT_BMISS; |
| 624 | */ |
| 625 | } |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 626 | |
| 627 | /* |
| 628 | * In case we didn't handle anything, |
| 629 | * print the register value. |
| 630 | */ |
| 631 | if (unlikely(*interrupt_mask == 0 && net_ratelimit())) |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 632 | ATH5K_PRINTF("ISR: 0x%08x IMR: 0x%08x\n", data, ah->ah_imr); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 633 | |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * ath5k_hw_set_imr - Set interrupt mask |
| 639 | * |
| 640 | * @ah: The &struct ath5k_hw |
| 641 | * @new_mask: The new interrupt mask to be set |
| 642 | * |
| 643 | * Set the interrupt mask in hw to save interrupts. We do that by mapping |
| 644 | * ath5k_int bits to hw-specific bits to remove abstraction and writing |
| 645 | * Interrupt Mask Register. |
| 646 | */ |
| 647 | enum ath5k_int ath5k_hw_set_imr(struct ath5k_hw *ah, enum ath5k_int new_mask) |
| 648 | { |
| 649 | enum ath5k_int old_mask, int_mask; |
| 650 | |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 651 | old_mask = ah->ah_imr; |
| 652 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 653 | /* |
| 654 | * Disable card interrupts to prevent any race conditions |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 655 | * (they will be re-enabled afterwards if AR5K_INT GLOBAL |
| 656 | * is set again on the new mask). |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 657 | */ |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 658 | if (old_mask & AR5K_INT_GLOBAL) { |
| 659 | ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER); |
| 660 | ath5k_hw_reg_read(ah, AR5K_IER); |
| 661 | } |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 662 | |
| 663 | /* |
| 664 | * Add additional, chipset-dependent interrupt mask flags |
| 665 | * and write them to the IMR (interrupt mask register). |
| 666 | */ |
| 667 | int_mask = new_mask & AR5K_INT_COMMON; |
| 668 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 669 | if (ah->ah_version != AR5K_AR5210) { |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 670 | /* Preserve per queue TXURN interrupt mask */ |
| 671 | u32 simr2 = ath5k_hw_reg_read(ah, AR5K_SIMR2) |
| 672 | & AR5K_SIMR2_QCU_TXURN; |
| 673 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 674 | if (new_mask & AR5K_INT_FATAL) { |
| 675 | int_mask |= AR5K_IMR_HIUERR; |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 676 | simr2 |= (AR5K_SIMR2_MCABT | AR5K_SIMR2_SSERR |
| 677 | | AR5K_SIMR2_DPERR); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 678 | } |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 679 | |
| 680 | /*Beacon Not Ready*/ |
| 681 | if (new_mask & AR5K_INT_BNR) |
| 682 | int_mask |= AR5K_INT_BNR; |
| 683 | |
| 684 | if (new_mask & AR5K_INT_TIM) |
| 685 | int_mask |= AR5K_IMR_TIM; |
| 686 | |
| 687 | if (new_mask & AR5K_INT_TIM) |
| 688 | simr2 |= AR5K_SISR2_TIM; |
| 689 | if (new_mask & AR5K_INT_DTIM) |
| 690 | simr2 |= AR5K_SISR2_DTIM; |
| 691 | if (new_mask & AR5K_INT_DTIM_SYNC) |
| 692 | simr2 |= AR5K_SISR2_DTIM_SYNC; |
| 693 | if (new_mask & AR5K_INT_BCN_TIMEOUT) |
| 694 | simr2 |= AR5K_SISR2_BCN_TIMEOUT; |
| 695 | if (new_mask & AR5K_INT_CAB_TIMEOUT) |
| 696 | simr2 |= AR5K_SISR2_CAB_TIMEOUT; |
| 697 | |
| 698 | if (new_mask & AR5K_INT_RX_DOPPLER) |
| 699 | int_mask |= AR5K_IMR_RXDOPPLER; |
| 700 | |
| 701 | /* Note: Per queue interrupt masks |
| 702 | * are set via reset_tx_queue (qcu.c) */ |
| 703 | ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR); |
| 704 | ath5k_hw_reg_write(ah, simr2, AR5K_SIMR2); |
| 705 | |
| 706 | } else { |
| 707 | if (new_mask & AR5K_INT_FATAL) |
| 708 | int_mask |= (AR5K_IMR_SSERR | AR5K_IMR_MCABT |
| 709 | | AR5K_IMR_HIUERR | AR5K_IMR_DPERR); |
| 710 | |
| 711 | ath5k_hw_reg_write(ah, int_mask, AR5K_IMR); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 712 | } |
| 713 | |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 714 | /* If RXNOFRM interrupt is masked disable it |
| 715 | * by setting AR5K_RXNOFRM to zero */ |
| 716 | if (!(new_mask & AR5K_INT_RXNOFRM)) |
| 717 | ath5k_hw_reg_write(ah, 0, AR5K_RXNOFRM); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 718 | |
| 719 | /* Store new interrupt mask */ |
| 720 | ah->ah_imr = new_mask; |
| 721 | |
Nick Kossifidis | 4c674c6 | 2008-10-26 20:40:25 +0200 | [diff] [blame] | 722 | /* ..re-enable interrupts if AR5K_INT_GLOBAL is set */ |
| 723 | if (new_mask & AR5K_INT_GLOBAL) { |
| 724 | ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER); |
| 725 | ath5k_hw_reg_read(ah, AR5K_IER); |
| 726 | } |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 727 | |
| 728 | return old_mask; |
| 729 | } |
| 730 | |
Nick Kossifidis | 9320b5c | 2010-11-23 20:36:45 +0200 | [diff] [blame] | 731 | |
| 732 | /********************\ |
| 733 | Init/Stop functions |
| 734 | \********************/ |
| 735 | |
| 736 | /** |
| 737 | * ath5k_hw_dma_init - Initialize DMA unit |
| 738 | * |
| 739 | * @ah: The &struct ath5k_hw |
| 740 | * |
| 741 | * Set DMA size and pre-enable interrupts |
| 742 | * (driver handles tx/rx buffer setup and |
| 743 | * dma start/stop) |
| 744 | * |
| 745 | * XXX: Save/restore RXDP/TXDP registers ? |
| 746 | */ |
| 747 | void ath5k_hw_dma_init(struct ath5k_hw *ah) |
| 748 | { |
| 749 | /* |
| 750 | * Set Rx/Tx DMA Configuration |
| 751 | * |
| 752 | * Set standard DMA size (128). Note that |
| 753 | * a DMA size of 512 causes rx overruns and tx errors |
| 754 | * on pci-e cards (tested on 5424 but since rx overruns |
| 755 | * also occur on 5416/5418 with madwifi we set 128 |
| 756 | * for all PCI-E cards to be safe). |
| 757 | * |
| 758 | * XXX: need to check 5210 for this |
| 759 | * TODO: Check out tx triger level, it's always 64 on dumps but I |
| 760 | * guess we can tweak it and see how it goes ;-) |
| 761 | */ |
| 762 | if (ah->ah_version != AR5K_AR5210) { |
| 763 | AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG, |
| 764 | AR5K_TXCFG_SDMAMR, AR5K_DMASIZE_128B); |
| 765 | AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG, |
| 766 | AR5K_RXCFG_SDMAMW, AR5K_DMASIZE_128B); |
| 767 | } |
| 768 | |
| 769 | /* Pre-enable interrupts on 5211/5212*/ |
| 770 | if (ah->ah_version != AR5K_AR5210) |
| 771 | ath5k_hw_set_imr(ah, ah->ah_imr); |
| 772 | |
| 773 | } |
Nick Kossifidis | d41174f | 2010-11-23 20:41:15 +0200 | [diff] [blame] | 774 | |
| 775 | /** |
| 776 | * ath5k_hw_dma_stop - stop DMA unit |
| 777 | * |
| 778 | * @ah: The &struct ath5k_hw |
| 779 | * |
| 780 | * Stop tx/rx DMA and interrupts. Returns |
| 781 | * -EBUSY if tx or rx dma failed to stop. |
| 782 | * |
| 783 | * XXX: Sometimes DMA unit hangs and we have |
| 784 | * stuck frames on tx queues, only a reset |
| 785 | * can fix that. |
| 786 | */ |
| 787 | int ath5k_hw_dma_stop(struct ath5k_hw *ah) |
| 788 | { |
| 789 | int i, qmax, err; |
| 790 | err = 0; |
| 791 | |
| 792 | /* Disable interrupts */ |
| 793 | ath5k_hw_set_imr(ah, 0); |
| 794 | |
| 795 | /* Stop rx dma */ |
| 796 | err = ath5k_hw_stop_rx_dma(ah); |
| 797 | if (err) |
| 798 | return err; |
| 799 | |
| 800 | /* Clear any pending interrupts |
| 801 | * and disable tx dma */ |
| 802 | if (ah->ah_version != AR5K_AR5210) { |
| 803 | ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR); |
| 804 | qmax = AR5K_NUM_TX_QUEUES; |
| 805 | } else { |
| 806 | /* PISR/SISR Not available on 5210 */ |
| 807 | ath5k_hw_reg_read(ah, AR5K_ISR); |
| 808 | qmax = AR5K_NUM_TX_QUEUES_NOQCU; |
| 809 | } |
| 810 | |
| 811 | for (i = 0; i < qmax; i++) { |
| 812 | err = ath5k_hw_stop_tx_dma(ah, i); |
| 813 | /* -EINVAL -> queue inactive */ |
| 814 | if (err != -EINVAL) |
| 815 | return err; |
| 816 | } |
| 817 | |
| 818 | return err; |
| 819 | } |