dma.c 18 KB

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