dma.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. * DMA and interrupt masking functions *
  20. \*************************************/
  21. /*
  22. * dma.c - DMA and interrupt masking functions
  23. *
  24. * Here we setup descriptor pointers (rxdp/txdp) start/stop dma engine and
  25. * handle queue setup for 5210 chipset (rest are handled on qcu.c).
  26. * Also we setup interrupt mask register (IMR) and read the various iterrupt
  27. * status registers (ISR).
  28. *
  29. * TODO: Handle SISR on 5211+ and introduce a function to return the queue
  30. * number that resulted the interrupt.
  31. */
  32. #include "ath5k.h"
  33. #include "reg.h"
  34. #include "debug.h"
  35. #include "base.h"
  36. /*********\
  37. * Receive *
  38. \*********/
  39. /**
  40. * ath5k_hw_start_rx_dma - Start DMA receive
  41. *
  42. * @ah: The &struct ath5k_hw
  43. */
  44. void ath5k_hw_start_rx_dma(struct ath5k_hw *ah)
  45. {
  46. ATH5K_TRACE(ah->ah_sc);
  47. ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
  48. ath5k_hw_reg_read(ah, AR5K_CR);
  49. }
  50. /**
  51. * ath5k_hw_stop_rx_dma - Stop DMA receive
  52. *
  53. * @ah: The &struct ath5k_hw
  54. */
  55. int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
  56. {
  57. unsigned int i;
  58. ATH5K_TRACE(ah->ah_sc);
  59. ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
  60. /*
  61. * It may take some time to disable the DMA receive unit
  62. */
  63. for (i = 1000; i > 0 &&
  64. (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
  65. i--)
  66. udelay(10);
  67. return i ? 0 : -EBUSY;
  68. }
  69. /**
  70. * ath5k_hw_get_rxdp - Get RX Descriptor's address
  71. *
  72. * @ah: The &struct ath5k_hw
  73. */
  74. u32 ath5k_hw_get_rxdp(struct ath5k_hw *ah)
  75. {
  76. return ath5k_hw_reg_read(ah, AR5K_RXDP);
  77. }
  78. /**
  79. * ath5k_hw_set_rxdp - Set RX Descriptor's address
  80. *
  81. * @ah: The &struct ath5k_hw
  82. * @phys_addr: RX descriptor address
  83. *
  84. * XXX: Should we check if rx is enabled before setting rxdp ?
  85. */
  86. void ath5k_hw_set_rxdp(struct ath5k_hw *ah, u32 phys_addr)
  87. {
  88. ATH5K_TRACE(ah->ah_sc);
  89. ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
  90. }
  91. /**********\
  92. * Transmit *
  93. \**********/
  94. /**
  95. * ath5k_hw_start_tx_dma - Start DMA transmit for a specific queue
  96. *
  97. * @ah: The &struct ath5k_hw
  98. * @queue: The hw queue number
  99. *
  100. * Start DMA transmit for a specific queue and since 5210 doesn't have
  101. * QCU/DCU, set up queue parameters for 5210 here based on queue type (one
  102. * queue for normal data and one queue for beacons). For queue setup
  103. * on newer chips check out qcu.c. Returns -EINVAL if queue number is out
  104. * of range or if queue is already disabled.
  105. *
  106. * NOTE: Must be called after setting up tx control descriptor for that
  107. * queue (see below).
  108. */
  109. int ath5k_hw_start_tx_dma(struct ath5k_hw *ah, unsigned int queue)
  110. {
  111. u32 tx_queue;
  112. ATH5K_TRACE(ah->ah_sc);
  113. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  114. /* Return if queue is declared inactive */
  115. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  116. return -EIO;
  117. if (ah->ah_version == AR5K_AR5210) {
  118. tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
  119. /*
  120. * Set the queue by type on 5210
  121. */
  122. switch (ah->ah_txq[queue].tqi_type) {
  123. case AR5K_TX_QUEUE_DATA:
  124. tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
  125. break;
  126. case AR5K_TX_QUEUE_BEACON:
  127. tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
  128. ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
  129. AR5K_BSR);
  130. break;
  131. case AR5K_TX_QUEUE_CAB:
  132. tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
  133. ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
  134. AR5K_BCR_BDMAE, AR5K_BSR);
  135. break;
  136. default:
  137. return -EINVAL;
  138. }
  139. /* Start queue */
  140. ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
  141. ath5k_hw_reg_read(ah, AR5K_CR);
  142. } else {
  143. /* Return if queue is disabled */
  144. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
  145. return -EIO;
  146. /* Start queue */
  147. AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
  148. }
  149. return 0;
  150. }
  151. /**
  152. * ath5k_hw_stop_tx_dma - Stop DMA transmit on a specific queue
  153. *
  154. * @ah: The &struct ath5k_hw
  155. * @queue: The hw queue number
  156. *
  157. * Stop DMA transmit on a specific hw queue and drain queue so we don't
  158. * have any pending frames. Returns -EBUSY if we still have pending frames,
  159. * -EINVAL if queue number is out of range.
  160. *
  161. */
  162. int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
  163. {
  164. unsigned int i = 40;
  165. u32 tx_queue, pending;
  166. ATH5K_TRACE(ah->ah_sc);
  167. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  168. /* Return if queue is declared inactive */
  169. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  170. return -EIO;
  171. if (ah->ah_version == AR5K_AR5210) {
  172. tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
  173. /*
  174. * Set by queue type
  175. */
  176. switch (ah->ah_txq[queue].tqi_type) {
  177. case AR5K_TX_QUEUE_DATA:
  178. tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
  179. break;
  180. case AR5K_TX_QUEUE_BEACON:
  181. case AR5K_TX_QUEUE_CAB:
  182. /* XXX Fix me... */
  183. tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
  184. ath5k_hw_reg_write(ah, 0, AR5K_BSR);
  185. break;
  186. default:
  187. return -EINVAL;
  188. }
  189. /* Stop queue */
  190. ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
  191. ath5k_hw_reg_read(ah, AR5K_CR);
  192. } else {
  193. /*
  194. * Schedule TX disable and wait until queue is empty
  195. */
  196. AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
  197. /*Check for pending frames*/
  198. do {
  199. pending = ath5k_hw_reg_read(ah,
  200. AR5K_QUEUE_STATUS(queue)) &
  201. AR5K_QCU_STS_FRMPENDCNT;
  202. udelay(100);
  203. } while (--i && pending);
  204. /* For 2413+ order PCU to drop packets using
  205. * QUIET mechanism */
  206. if (ah->ah_mac_version >= (AR5K_SREV_AR2414 >> 4) &&
  207. pending){
  208. /* Set periodicity and duration */
  209. ath5k_hw_reg_write(ah,
  210. AR5K_REG_SM(100, AR5K_QUIET_CTL2_QT_PER)|
  211. AR5K_REG_SM(10, AR5K_QUIET_CTL2_QT_DUR),
  212. AR5K_QUIET_CTL2);
  213. /* Enable quiet period for current TSF */
  214. ath5k_hw_reg_write(ah,
  215. AR5K_QUIET_CTL1_QT_EN |
  216. AR5K_REG_SM(ath5k_hw_reg_read(ah,
  217. AR5K_TSF_L32_5211) >> 10,
  218. AR5K_QUIET_CTL1_NEXT_QT_TSF),
  219. AR5K_QUIET_CTL1);
  220. /* Force channel idle high */
  221. AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5211,
  222. AR5K_DIAG_SW_CHANEL_IDLE_HIGH);
  223. /* Wait a while and disable mechanism */
  224. udelay(200);
  225. AR5K_REG_DISABLE_BITS(ah, AR5K_QUIET_CTL1,
  226. AR5K_QUIET_CTL1_QT_EN);
  227. /* Re-check for pending frames */
  228. i = 40;
  229. do {
  230. pending = ath5k_hw_reg_read(ah,
  231. AR5K_QUEUE_STATUS(queue)) &
  232. AR5K_QCU_STS_FRMPENDCNT;
  233. udelay(100);
  234. } while (--i && pending);
  235. AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW_5211,
  236. AR5K_DIAG_SW_CHANEL_IDLE_HIGH);
  237. }
  238. /* Clear register */
  239. ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
  240. if (pending)
  241. return -EBUSY;
  242. }
  243. /* TODO: Check for success on 5210 else return error */
  244. return 0;
  245. }
  246. /**
  247. * ath5k_hw_get_txdp - Get TX Descriptor's address for a specific queue
  248. *
  249. * @ah: The &struct ath5k_hw
  250. * @queue: The hw queue number
  251. *
  252. * Get TX descriptor's address for a specific queue. For 5210 we ignore
  253. * the queue number and use tx queue type since we only have 2 queues.
  254. * We use TXDP0 for normal data queue and TXDP1 for beacon queue.
  255. * For newer chips with QCU/DCU we just read the corresponding TXDP register.
  256. *
  257. * XXX: Is TXDP read and clear ?
  258. */
  259. u32 ath5k_hw_get_txdp(struct ath5k_hw *ah, unsigned int queue)
  260. {
  261. u16 tx_reg;
  262. ATH5K_TRACE(ah->ah_sc);
  263. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  264. /*
  265. * Get the transmit queue descriptor pointer from the selected queue
  266. */
  267. /*5210 doesn't have QCU*/
  268. if (ah->ah_version == AR5K_AR5210) {
  269. switch (ah->ah_txq[queue].tqi_type) {
  270. case AR5K_TX_QUEUE_DATA:
  271. tx_reg = AR5K_NOQCU_TXDP0;
  272. break;
  273. case AR5K_TX_QUEUE_BEACON:
  274. case AR5K_TX_QUEUE_CAB:
  275. tx_reg = AR5K_NOQCU_TXDP1;
  276. break;
  277. default:
  278. return 0xffffffff;
  279. }
  280. } else {
  281. tx_reg = AR5K_QUEUE_TXDP(queue);
  282. }
  283. return ath5k_hw_reg_read(ah, tx_reg);
  284. }
  285. /**
  286. * ath5k_hw_set_txdp - Set TX Descriptor's address for a specific queue
  287. *
  288. * @ah: The &struct ath5k_hw
  289. * @queue: The hw queue number
  290. *
  291. * Set TX descriptor's address for a specific queue. For 5210 we ignore
  292. * the queue number and we use tx queue type since we only have 2 queues
  293. * so as above we use TXDP0 for normal data queue and TXDP1 for beacon queue.
  294. * For newer chips with QCU/DCU we just set the corresponding TXDP register.
  295. * Returns -EINVAL if queue type is invalid for 5210 and -EIO if queue is still
  296. * active.
  297. */
  298. int ath5k_hw_set_txdp(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
  299. {
  300. u16 tx_reg;
  301. ATH5K_TRACE(ah->ah_sc);
  302. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  303. /*
  304. * Set the transmit queue descriptor pointer register by type
  305. * on 5210
  306. */
  307. if (ah->ah_version == AR5K_AR5210) {
  308. switch (ah->ah_txq[queue].tqi_type) {
  309. case AR5K_TX_QUEUE_DATA:
  310. tx_reg = AR5K_NOQCU_TXDP0;
  311. break;
  312. case AR5K_TX_QUEUE_BEACON:
  313. case AR5K_TX_QUEUE_CAB:
  314. tx_reg = AR5K_NOQCU_TXDP1;
  315. break;
  316. default:
  317. return -EINVAL;
  318. }
  319. } else {
  320. /*
  321. * Set the transmit queue descriptor pointer for
  322. * the selected queue on QCU for 5211+
  323. * (this won't work if the queue is still active)
  324. */
  325. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
  326. return -EIO;
  327. tx_reg = AR5K_QUEUE_TXDP(queue);
  328. }
  329. /* Set descriptor pointer */
  330. ath5k_hw_reg_write(ah, phys_addr, tx_reg);
  331. return 0;
  332. }
  333. /**
  334. * ath5k_hw_update_tx_triglevel - Update tx trigger level
  335. *
  336. * @ah: The &struct ath5k_hw
  337. * @increase: Flag to force increase of trigger level
  338. *
  339. * This function increases/decreases the tx trigger level for the tx fifo
  340. * buffer (aka FIFO threshold) that is used to indicate when PCU flushes
  341. * the buffer and transmits it's data. Lowering this results sending small
  342. * frames more quickly but can lead to tx underruns, raising it a lot can
  343. * result other problems (i think bmiss is related). Right now we start with
  344. * the lowest possible (64Bytes) and if we get tx underrun we increase it using
  345. * the increase flag. Returns -EIO if we have have reached maximum/minimum.
  346. *
  347. * XXX: Link this with tx DMA size ?
  348. * XXX: Use it to save interrupts ?
  349. * TODO: Needs testing, i think it's related to bmiss...
  350. */
  351. int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
  352. {
  353. u32 trigger_level, imr;
  354. int ret = -EIO;
  355. ATH5K_TRACE(ah->ah_sc);
  356. /*
  357. * Disable interrupts by setting the mask
  358. */
  359. imr = ath5k_hw_set_imr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
  360. trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
  361. AR5K_TXCFG_TXFULL);
  362. if (!increase) {
  363. if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
  364. goto done;
  365. } else
  366. trigger_level +=
  367. ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
  368. /*
  369. * Update trigger level on success
  370. */
  371. if (ah->ah_version == AR5K_AR5210)
  372. ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
  373. else
  374. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  375. AR5K_TXCFG_TXFULL, trigger_level);
  376. ret = 0;
  377. done:
  378. /*
  379. * Restore interrupt mask
  380. */
  381. ath5k_hw_set_imr(ah, imr);
  382. return ret;
  383. }
  384. /*******************\
  385. * Interrupt masking *
  386. \*******************/
  387. /**
  388. * ath5k_hw_is_intr_pending - Check if we have pending interrupts
  389. *
  390. * @ah: The &struct ath5k_hw
  391. *
  392. * Check if we have pending interrupts to process. Returns 1 if we
  393. * have pending interrupts and 0 if we haven't.
  394. */
  395. bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
  396. {
  397. ATH5K_TRACE(ah->ah_sc);
  398. return ath5k_hw_reg_read(ah, AR5K_INTPEND) == 1 ? 1 : 0;
  399. }
  400. /**
  401. * ath5k_hw_get_isr - Get interrupt status
  402. *
  403. * @ah: The @struct ath5k_hw
  404. * @interrupt_mask: Driver's interrupt mask used to filter out
  405. * interrupts in sw.
  406. *
  407. * This function is used inside our interrupt handler to determine the reason
  408. * for the interrupt by reading Primary Interrupt Status Register. Returns an
  409. * abstract interrupt status mask which is mostly ISR with some uncommon bits
  410. * being mapped on some standard non hw-specific positions
  411. * (check out &ath5k_int).
  412. *
  413. * NOTE: We use read-and-clear register, so after this function is called ISR
  414. * is zeroed.
  415. */
  416. int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
  417. {
  418. u32 data;
  419. ATH5K_TRACE(ah->ah_sc);
  420. /*
  421. * Read interrupt status from the Interrupt Status register
  422. * on 5210
  423. */
  424. if (ah->ah_version == AR5K_AR5210) {
  425. data = ath5k_hw_reg_read(ah, AR5K_ISR);
  426. if (unlikely(data == AR5K_INT_NOCARD)) {
  427. *interrupt_mask = data;
  428. return -ENODEV;
  429. }
  430. } else {
  431. /*
  432. * Read interrupt status from Interrupt
  433. * Status Register shadow copy (Read And Clear)
  434. *
  435. * Note: PISR/SISR Not available on 5210
  436. */
  437. data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
  438. if (unlikely(data == AR5K_INT_NOCARD)) {
  439. *interrupt_mask = data;
  440. return -ENODEV;
  441. }
  442. }
  443. /*
  444. * Get abstract interrupt mask (driver-compatible)
  445. */
  446. *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
  447. if (ah->ah_version != AR5K_AR5210) {
  448. u32 sisr2 = ath5k_hw_reg_read(ah, AR5K_RAC_SISR2);
  449. /*HIU = Host Interface Unit (PCI etc)*/
  450. if (unlikely(data & (AR5K_ISR_HIUERR)))
  451. *interrupt_mask |= AR5K_INT_FATAL;
  452. /*Beacon Not Ready*/
  453. if (unlikely(data & (AR5K_ISR_BNR)))
  454. *interrupt_mask |= AR5K_INT_BNR;
  455. if (unlikely(sisr2 & (AR5K_SISR2_SSERR |
  456. AR5K_SISR2_DPERR |
  457. AR5K_SISR2_MCABT)))
  458. *interrupt_mask |= AR5K_INT_FATAL;
  459. if (data & AR5K_ISR_TIM)
  460. *interrupt_mask |= AR5K_INT_TIM;
  461. if (data & AR5K_ISR_BCNMISC) {
  462. if (sisr2 & AR5K_SISR2_TIM)
  463. *interrupt_mask |= AR5K_INT_TIM;
  464. if (sisr2 & AR5K_SISR2_DTIM)
  465. *interrupt_mask |= AR5K_INT_DTIM;
  466. if (sisr2 & AR5K_SISR2_DTIM_SYNC)
  467. *interrupt_mask |= AR5K_INT_DTIM_SYNC;
  468. if (sisr2 & AR5K_SISR2_BCN_TIMEOUT)
  469. *interrupt_mask |= AR5K_INT_BCN_TIMEOUT;
  470. if (sisr2 & AR5K_SISR2_CAB_TIMEOUT)
  471. *interrupt_mask |= AR5K_INT_CAB_TIMEOUT;
  472. }
  473. if (data & AR5K_ISR_RXDOPPLER)
  474. *interrupt_mask |= AR5K_INT_RX_DOPPLER;
  475. if (data & AR5K_ISR_QCBRORN) {
  476. *interrupt_mask |= AR5K_INT_QCBRORN;
  477. ah->ah_txq_isr |= AR5K_REG_MS(
  478. ath5k_hw_reg_read(ah, AR5K_RAC_SISR3),
  479. AR5K_SISR3_QCBRORN);
  480. }
  481. if (data & AR5K_ISR_QCBRURN) {
  482. *interrupt_mask |= AR5K_INT_QCBRURN;
  483. ah->ah_txq_isr |= AR5K_REG_MS(
  484. ath5k_hw_reg_read(ah, AR5K_RAC_SISR3),
  485. AR5K_SISR3_QCBRURN);
  486. }
  487. if (data & AR5K_ISR_QTRIG) {
  488. *interrupt_mask |= AR5K_INT_QTRIG;
  489. ah->ah_txq_isr |= AR5K_REG_MS(
  490. ath5k_hw_reg_read(ah, AR5K_RAC_SISR4),
  491. AR5K_SISR4_QTRIG);
  492. }
  493. if (data & AR5K_ISR_TXOK)
  494. ah->ah_txq_isr |= AR5K_REG_MS(
  495. ath5k_hw_reg_read(ah, AR5K_RAC_SISR0),
  496. AR5K_SISR0_QCU_TXOK);
  497. if (data & AR5K_ISR_TXDESC)
  498. ah->ah_txq_isr |= AR5K_REG_MS(
  499. ath5k_hw_reg_read(ah, AR5K_RAC_SISR0),
  500. AR5K_SISR0_QCU_TXDESC);
  501. if (data & AR5K_ISR_TXERR)
  502. ah->ah_txq_isr |= AR5K_REG_MS(
  503. ath5k_hw_reg_read(ah, AR5K_RAC_SISR1),
  504. AR5K_SISR1_QCU_TXERR);
  505. if (data & AR5K_ISR_TXEOL)
  506. ah->ah_txq_isr |= AR5K_REG_MS(
  507. ath5k_hw_reg_read(ah, AR5K_RAC_SISR1),
  508. AR5K_SISR1_QCU_TXEOL);
  509. if (data & AR5K_ISR_TXURN)
  510. ah->ah_txq_isr |= AR5K_REG_MS(
  511. ath5k_hw_reg_read(ah, AR5K_RAC_SISR2),
  512. AR5K_SISR2_QCU_TXURN);
  513. } else {
  514. if (unlikely(data & (AR5K_ISR_SSERR | AR5K_ISR_MCABT
  515. | AR5K_ISR_HIUERR | AR5K_ISR_DPERR)))
  516. *interrupt_mask |= AR5K_INT_FATAL;
  517. /*
  518. * XXX: BMISS interrupts may occur after association.
  519. * I found this on 5210 code but it needs testing. If this is
  520. * true we should disable them before assoc and re-enable them
  521. * after a successful assoc + some jiffies.
  522. interrupt_mask &= ~AR5K_INT_BMISS;
  523. */
  524. }
  525. /*
  526. * In case we didn't handle anything,
  527. * print the register value.
  528. */
  529. if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
  530. ATH5K_PRINTF("ISR: 0x%08x IMR: 0x%08x\n", data, ah->ah_imr);
  531. return 0;
  532. }
  533. /**
  534. * ath5k_hw_set_imr - Set interrupt mask
  535. *
  536. * @ah: The &struct ath5k_hw
  537. * @new_mask: The new interrupt mask to be set
  538. *
  539. * Set the interrupt mask in hw to save interrupts. We do that by mapping
  540. * ath5k_int bits to hw-specific bits to remove abstraction and writing
  541. * Interrupt Mask Register.
  542. */
  543. enum ath5k_int ath5k_hw_set_imr(struct ath5k_hw *ah, enum ath5k_int new_mask)
  544. {
  545. enum ath5k_int old_mask, int_mask;
  546. old_mask = ah->ah_imr;
  547. /*
  548. * Disable card interrupts to prevent any race conditions
  549. * (they will be re-enabled afterwards if AR5K_INT GLOBAL
  550. * is set again on the new mask).
  551. */
  552. if (old_mask & AR5K_INT_GLOBAL) {
  553. ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
  554. ath5k_hw_reg_read(ah, AR5K_IER);
  555. }
  556. /*
  557. * Add additional, chipset-dependent interrupt mask flags
  558. * and write them to the IMR (interrupt mask register).
  559. */
  560. int_mask = new_mask & AR5K_INT_COMMON;
  561. if (ah->ah_version != AR5K_AR5210) {
  562. /* Preserve per queue TXURN interrupt mask */
  563. u32 simr2 = ath5k_hw_reg_read(ah, AR5K_SIMR2)
  564. & AR5K_SIMR2_QCU_TXURN;
  565. if (new_mask & AR5K_INT_FATAL) {
  566. int_mask |= AR5K_IMR_HIUERR;
  567. simr2 |= (AR5K_SIMR2_MCABT | AR5K_SIMR2_SSERR
  568. | AR5K_SIMR2_DPERR);
  569. }
  570. /*Beacon Not Ready*/
  571. if (new_mask & AR5K_INT_BNR)
  572. int_mask |= AR5K_INT_BNR;
  573. if (new_mask & AR5K_INT_TIM)
  574. int_mask |= AR5K_IMR_TIM;
  575. if (new_mask & AR5K_INT_TIM)
  576. simr2 |= AR5K_SISR2_TIM;
  577. if (new_mask & AR5K_INT_DTIM)
  578. simr2 |= AR5K_SISR2_DTIM;
  579. if (new_mask & AR5K_INT_DTIM_SYNC)
  580. simr2 |= AR5K_SISR2_DTIM_SYNC;
  581. if (new_mask & AR5K_INT_BCN_TIMEOUT)
  582. simr2 |= AR5K_SISR2_BCN_TIMEOUT;
  583. if (new_mask & AR5K_INT_CAB_TIMEOUT)
  584. simr2 |= AR5K_SISR2_CAB_TIMEOUT;
  585. if (new_mask & AR5K_INT_RX_DOPPLER)
  586. int_mask |= AR5K_IMR_RXDOPPLER;
  587. /* Note: Per queue interrupt masks
  588. * are set via reset_tx_queue (qcu.c) */
  589. ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
  590. ath5k_hw_reg_write(ah, simr2, AR5K_SIMR2);
  591. } else {
  592. if (new_mask & AR5K_INT_FATAL)
  593. int_mask |= (AR5K_IMR_SSERR | AR5K_IMR_MCABT
  594. | AR5K_IMR_HIUERR | AR5K_IMR_DPERR);
  595. ath5k_hw_reg_write(ah, int_mask, AR5K_IMR);
  596. }
  597. /* If RXNOFRM interrupt is masked disable it
  598. * by setting AR5K_RXNOFRM to zero */
  599. if (!(new_mask & AR5K_INT_RXNOFRM))
  600. ath5k_hw_reg_write(ah, 0, AR5K_RXNOFRM);
  601. /* Store new interrupt mask */
  602. ah->ah_imr = new_mask;
  603. /* ..re-enable interrupts if AR5K_INT_GLOBAL is set */
  604. if (new_mask & AR5K_INT_GLOBAL) {
  605. ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
  606. ath5k_hw_reg_read(ah, AR5K_IER);
  607. }
  608. return old_mask;
  609. }