dma.c 18 KB

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