You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath5k_dma.c 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
  3. * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
  4. *
  5. * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
  6. *
  7. * Permission to use, copy, modify, and distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. *
  19. */
  20. FILE_LICENCE ( MIT );
  21. /*************************************\
  22. * DMA and interrupt masking functions *
  23. \*************************************/
  24. /*
  25. * dma.c - DMA and interrupt masking functions
  26. *
  27. * Here we setup descriptor pointers (rxdp/txdp) start/stop dma engine and
  28. * handle queue setup for 5210 chipset (rest are handled on qcu.c).
  29. * Also we setup interrupt mask register (IMR) and read the various iterrupt
  30. * status registers (ISR).
  31. *
  32. * TODO: Handle SISR on 5211+ and introduce a function to return the queue
  33. * number that resulted the interrupt.
  34. */
  35. #include <unistd.h>
  36. #include "ath5k.h"
  37. #include "reg.h"
  38. #include "base.h"
  39. /*********\
  40. * Receive *
  41. \*********/
  42. /**
  43. * ath5k_hw_start_rx_dma - Start DMA receive
  44. *
  45. * @ah: The &struct ath5k_hw
  46. */
  47. void ath5k_hw_start_rx_dma(struct ath5k_hw *ah)
  48. {
  49. ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
  50. ath5k_hw_reg_read(ah, AR5K_CR);
  51. }
  52. /**
  53. * ath5k_hw_stop_rx_dma - Stop DMA receive
  54. *
  55. * @ah: The &struct ath5k_hw
  56. */
  57. int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
  58. {
  59. unsigned int i;
  60. ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
  61. /*
  62. * It may take some time to disable the DMA receive unit
  63. */
  64. for (i = 1000; i > 0 &&
  65. (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
  66. i--)
  67. udelay(10);
  68. return i ? 0 : -EBUSY;
  69. }
  70. /**
  71. * ath5k_hw_get_rxdp - Get RX Descriptor's address
  72. *
  73. * @ah: The &struct ath5k_hw
  74. *
  75. * XXX: Is RXDP read and clear ?
  76. */
  77. u32 ath5k_hw_get_rxdp(struct ath5k_hw *ah)
  78. {
  79. return ath5k_hw_reg_read(ah, AR5K_RXDP);
  80. }
  81. /**
  82. * ath5k_hw_set_rxdp - Set RX Descriptor's address
  83. *
  84. * @ah: The &struct ath5k_hw
  85. * @phys_addr: RX descriptor address
  86. *
  87. * XXX: Should we check if rx is enabled before setting rxdp ?
  88. */
  89. void ath5k_hw_set_rxdp(struct ath5k_hw *ah, u32 phys_addr)
  90. {
  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. /* Return if queue is declared inactive */
  115. if (ah->ah_txq.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. /* Assume always a data queue */
  120. tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
  121. /* Start queue */
  122. ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
  123. ath5k_hw_reg_read(ah, AR5K_CR);
  124. } else {
  125. /* Return if queue is disabled */
  126. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
  127. return -EIO;
  128. /* Start queue */
  129. AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
  130. }
  131. return 0;
  132. }
  133. /**
  134. * ath5k_hw_stop_tx_dma - Stop DMA transmit on a specific queue
  135. *
  136. * @ah: The &struct ath5k_hw
  137. * @queue: The hw queue number
  138. *
  139. * Stop DMA transmit on a specific hw queue and drain queue so we don't
  140. * have any pending frames. Returns -EBUSY if we still have pending frames,
  141. * -EINVAL if queue number is out of range.
  142. *
  143. */
  144. int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
  145. {
  146. unsigned int i = 40;
  147. u32 tx_queue, pending;
  148. /* Return if queue is declared inactive */
  149. if (ah->ah_txq.tqi_type == AR5K_TX_QUEUE_INACTIVE)
  150. return -EIO;
  151. if (ah->ah_version == AR5K_AR5210) {
  152. tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
  153. /* Assume a data queue */
  154. tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
  155. /* Stop queue */
  156. ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
  157. ath5k_hw_reg_read(ah, AR5K_CR);
  158. } else {
  159. /*
  160. * Schedule TX disable and wait until queue is empty
  161. */
  162. AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
  163. /*Check for pending frames*/
  164. do {
  165. pending = ath5k_hw_reg_read(ah,
  166. AR5K_QUEUE_STATUS(queue)) &
  167. AR5K_QCU_STS_FRMPENDCNT;
  168. udelay(100);
  169. } while (--i && pending);
  170. /* For 2413+ order PCU to drop packets using
  171. * QUIET mechanism */
  172. if (ah->ah_mac_version >= (AR5K_SREV_AR2414 >> 4) && pending) {
  173. /* Set periodicity and duration */
  174. ath5k_hw_reg_write(ah,
  175. AR5K_REG_SM(100, AR5K_QUIET_CTL2_QT_PER)|
  176. AR5K_REG_SM(10, AR5K_QUIET_CTL2_QT_DUR),
  177. AR5K_QUIET_CTL2);
  178. /* Enable quiet period for current TSF */
  179. ath5k_hw_reg_write(ah,
  180. AR5K_QUIET_CTL1_QT_EN |
  181. AR5K_REG_SM(ath5k_hw_reg_read(ah,
  182. AR5K_TSF_L32_5211) >> 10,
  183. AR5K_QUIET_CTL1_NEXT_QT_TSF),
  184. AR5K_QUIET_CTL1);
  185. /* Force channel idle high */
  186. AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5211,
  187. AR5K_DIAG_SW_CHANEL_IDLE_HIGH);
  188. /* Wait a while and disable mechanism */
  189. udelay(200);
  190. AR5K_REG_DISABLE_BITS(ah, AR5K_QUIET_CTL1,
  191. AR5K_QUIET_CTL1_QT_EN);
  192. /* Re-check for pending frames */
  193. i = 40;
  194. do {
  195. pending = ath5k_hw_reg_read(ah,
  196. AR5K_QUEUE_STATUS(queue)) &
  197. AR5K_QCU_STS_FRMPENDCNT;
  198. udelay(100);
  199. } while (--i && pending);
  200. AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW_5211,
  201. AR5K_DIAG_SW_CHANEL_IDLE_HIGH);
  202. }
  203. /* Clear register */
  204. ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
  205. if (pending)
  206. return -EBUSY;
  207. }
  208. /* TODO: Check for success on 5210 else return error */
  209. return 0;
  210. }
  211. /**
  212. * ath5k_hw_get_txdp - Get TX Descriptor's address for a specific queue
  213. *
  214. * @ah: The &struct ath5k_hw
  215. * @queue: The hw queue number
  216. *
  217. * Get TX descriptor's address for a specific queue. For 5210 we ignore
  218. * the queue number and use tx queue type since we only have 2 queues.
  219. * We use TXDP0 for normal data queue and TXDP1 for beacon queue.
  220. * For newer chips with QCU/DCU we just read the corresponding TXDP register.
  221. *
  222. * XXX: Is TXDP read and clear ?
  223. */
  224. u32 ath5k_hw_get_txdp(struct ath5k_hw *ah, unsigned int queue)
  225. {
  226. u16 tx_reg;
  227. /*
  228. * Get the transmit queue descriptor pointer from the selected queue
  229. */
  230. /*5210 doesn't have QCU*/
  231. if (ah->ah_version == AR5K_AR5210) {
  232. /* Assume a data queue */
  233. tx_reg = AR5K_NOQCU_TXDP0;
  234. } else {
  235. tx_reg = AR5K_QUEUE_TXDP(queue);
  236. }
  237. return ath5k_hw_reg_read(ah, tx_reg);
  238. }
  239. /**
  240. * ath5k_hw_set_txdp - Set TX Descriptor's address for a specific queue
  241. *
  242. * @ah: The &struct ath5k_hw
  243. * @queue: The hw queue number
  244. *
  245. * Set TX descriptor's address for a specific queue. For 5210 we ignore
  246. * the queue number and we use tx queue type since we only have 2 queues
  247. * so as above we use TXDP0 for normal data queue and TXDP1 for beacon queue.
  248. * For newer chips with QCU/DCU we just set the corresponding TXDP register.
  249. * Returns -EINVAL if queue type is invalid for 5210 and -EIO if queue is still
  250. * active.
  251. */
  252. int ath5k_hw_set_txdp(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
  253. {
  254. u16 tx_reg;
  255. /*
  256. * Set the transmit queue descriptor pointer register by type
  257. * on 5210
  258. */
  259. if (ah->ah_version == AR5K_AR5210) {
  260. /* Assume a data queue */
  261. tx_reg = AR5K_NOQCU_TXDP0;
  262. } else {
  263. /*
  264. * Set the transmit queue descriptor pointer for
  265. * the selected queue on QCU for 5211+
  266. * (this won't work if the queue is still active)
  267. */
  268. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
  269. return -EIO;
  270. tx_reg = AR5K_QUEUE_TXDP(queue);
  271. }
  272. /* Set descriptor pointer */
  273. ath5k_hw_reg_write(ah, phys_addr, tx_reg);
  274. return 0;
  275. }
  276. /**
  277. * ath5k_hw_update_tx_triglevel - Update tx trigger level
  278. *
  279. * @ah: The &struct ath5k_hw
  280. * @increase: Flag to force increase of trigger level
  281. *
  282. * This function increases/decreases the tx trigger level for the tx fifo
  283. * buffer (aka FIFO threshold) that is used to indicate when PCU flushes
  284. * the buffer and transmits it's data. Lowering this results sending small
  285. * frames more quickly but can lead to tx underruns, raising it a lot can
  286. * result other problems (i think bmiss is related). Right now we start with
  287. * the lowest possible (64Bytes) and if we get tx underrun we increase it using
  288. * the increase flag. Returns -EIO if we have have reached maximum/minimum.
  289. *
  290. * XXX: Link this with tx DMA size ?
  291. * XXX: Use it to save interrupts ?
  292. * TODO: Needs testing, i think it's related to bmiss...
  293. */
  294. int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, int increase)
  295. {
  296. u32 trigger_level, imr;
  297. int ret = -EIO;
  298. /*
  299. * Disable interrupts by setting the mask
  300. */
  301. imr = ath5k_hw_set_imr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
  302. trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
  303. AR5K_TXCFG_TXFULL);
  304. if (!increase) {
  305. if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
  306. goto done;
  307. } else
  308. trigger_level +=
  309. ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
  310. /*
  311. * Update trigger level on success
  312. */
  313. if (ah->ah_version == AR5K_AR5210)
  314. ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
  315. else
  316. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  317. AR5K_TXCFG_TXFULL, trigger_level);
  318. ret = 0;
  319. done:
  320. /*
  321. * Restore interrupt mask
  322. */
  323. ath5k_hw_set_imr(ah, imr);
  324. return ret;
  325. }
  326. /*******************\
  327. * Interrupt masking *
  328. \*******************/
  329. /**
  330. * ath5k_hw_is_intr_pending - Check if we have pending interrupts
  331. *
  332. * @ah: The &struct ath5k_hw
  333. *
  334. * Check if we have pending interrupts to process. Returns 1 if we
  335. * have pending interrupts and 0 if we haven't.
  336. */
  337. int ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
  338. {
  339. return ath5k_hw_reg_read(ah, AR5K_INTPEND) == 1 ? 1 : 0;
  340. }
  341. /**
  342. * ath5k_hw_get_isr - Get interrupt status
  343. *
  344. * @ah: The @struct ath5k_hw
  345. * @interrupt_mask: Driver's interrupt mask used to filter out
  346. * interrupts in sw.
  347. *
  348. * This function is used inside our interrupt handler to determine the reason
  349. * for the interrupt by reading Primary Interrupt Status Register. Returns an
  350. * abstract interrupt status mask which is mostly ISR with some uncommon bits
  351. * being mapped on some standard non hw-specific positions
  352. * (check out &ath5k_int).
  353. *
  354. * NOTE: We use read-and-clear register, so after this function is called ISR
  355. * is zeroed.
  356. */
  357. int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
  358. {
  359. u32 data;
  360. /*
  361. * Read interrupt status from the Interrupt Status register
  362. * on 5210
  363. */
  364. if (ah->ah_version == AR5K_AR5210) {
  365. data = ath5k_hw_reg_read(ah, AR5K_ISR);
  366. if (data == AR5K_INT_NOCARD) {
  367. *interrupt_mask = data;
  368. return -ENODEV;
  369. }
  370. } else {
  371. /*
  372. * Read interrupt status from Interrupt
  373. * Status Register shadow copy (Read And Clear)
  374. *
  375. * Note: PISR/SISR Not available on 5210
  376. */
  377. data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
  378. if (data == AR5K_INT_NOCARD) {
  379. *interrupt_mask = data;
  380. return -ENODEV;
  381. }
  382. }
  383. /*
  384. * Get abstract interrupt mask (driver-compatible)
  385. */
  386. *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
  387. if (ah->ah_version != AR5K_AR5210) {
  388. u32 sisr2 = ath5k_hw_reg_read(ah, AR5K_RAC_SISR2);
  389. /*HIU = Host Interface Unit (PCI etc)*/
  390. if (data & (AR5K_ISR_HIUERR))
  391. *interrupt_mask |= AR5K_INT_FATAL;
  392. /*Beacon Not Ready*/
  393. if (data & (AR5K_ISR_BNR))
  394. *interrupt_mask |= AR5K_INT_BNR;
  395. if (sisr2 & (AR5K_SISR2_SSERR | AR5K_SISR2_DPERR |
  396. AR5K_SISR2_MCABT))
  397. *interrupt_mask |= AR5K_INT_FATAL;
  398. if (data & AR5K_ISR_TIM)
  399. *interrupt_mask |= AR5K_INT_TIM;
  400. if (data & AR5K_ISR_BCNMISC) {
  401. if (sisr2 & AR5K_SISR2_TIM)
  402. *interrupt_mask |= AR5K_INT_TIM;
  403. if (sisr2 & AR5K_SISR2_DTIM)
  404. *interrupt_mask |= AR5K_INT_DTIM;
  405. if (sisr2 & AR5K_SISR2_DTIM_SYNC)
  406. *interrupt_mask |= AR5K_INT_DTIM_SYNC;
  407. if (sisr2 & AR5K_SISR2_BCN_TIMEOUT)
  408. *interrupt_mask |= AR5K_INT_BCN_TIMEOUT;
  409. if (sisr2 & AR5K_SISR2_CAB_TIMEOUT)
  410. *interrupt_mask |= AR5K_INT_CAB_TIMEOUT;
  411. }
  412. if (data & AR5K_ISR_RXDOPPLER)
  413. *interrupt_mask |= AR5K_INT_RX_DOPPLER;
  414. if (data & AR5K_ISR_QCBRORN) {
  415. *interrupt_mask |= AR5K_INT_QCBRORN;
  416. ah->ah_txq_isr |= AR5K_REG_MS(
  417. ath5k_hw_reg_read(ah, AR5K_RAC_SISR3),
  418. AR5K_SISR3_QCBRORN);
  419. }
  420. if (data & AR5K_ISR_QCBRURN) {
  421. *interrupt_mask |= AR5K_INT_QCBRURN;
  422. ah->ah_txq_isr |= AR5K_REG_MS(
  423. ath5k_hw_reg_read(ah, AR5K_RAC_SISR3),
  424. AR5K_SISR3_QCBRURN);
  425. }
  426. if (data & AR5K_ISR_QTRIG) {
  427. *interrupt_mask |= AR5K_INT_QTRIG;
  428. ah->ah_txq_isr |= AR5K_REG_MS(
  429. ath5k_hw_reg_read(ah, AR5K_RAC_SISR4),
  430. AR5K_SISR4_QTRIG);
  431. }
  432. if (data & AR5K_ISR_TXOK)
  433. ah->ah_txq_isr |= AR5K_REG_MS(
  434. ath5k_hw_reg_read(ah, AR5K_RAC_SISR0),
  435. AR5K_SISR0_QCU_TXOK);
  436. if (data & AR5K_ISR_TXDESC)
  437. ah->ah_txq_isr |= AR5K_REG_MS(
  438. ath5k_hw_reg_read(ah, AR5K_RAC_SISR0),
  439. AR5K_SISR0_QCU_TXDESC);
  440. if (data & AR5K_ISR_TXERR)
  441. ah->ah_txq_isr |= AR5K_REG_MS(
  442. ath5k_hw_reg_read(ah, AR5K_RAC_SISR1),
  443. AR5K_SISR1_QCU_TXERR);
  444. if (data & AR5K_ISR_TXEOL)
  445. ah->ah_txq_isr |= AR5K_REG_MS(
  446. ath5k_hw_reg_read(ah, AR5K_RAC_SISR1),
  447. AR5K_SISR1_QCU_TXEOL);
  448. if (data & AR5K_ISR_TXURN)
  449. ah->ah_txq_isr |= AR5K_REG_MS(
  450. ath5k_hw_reg_read(ah, AR5K_RAC_SISR2),
  451. AR5K_SISR2_QCU_TXURN);
  452. } else {
  453. if (data & (AR5K_ISR_SSERR | AR5K_ISR_MCABT |
  454. AR5K_ISR_HIUERR | AR5K_ISR_DPERR))
  455. *interrupt_mask |= AR5K_INT_FATAL;
  456. /*
  457. * XXX: BMISS interrupts may occur after association.
  458. * I found this on 5210 code but it needs testing. If this is
  459. * true we should disable them before assoc and re-enable them
  460. * after a successful assoc + some jiffies.
  461. interrupt_mask &= ~AR5K_INT_BMISS;
  462. */
  463. }
  464. return 0;
  465. }
  466. /**
  467. * ath5k_hw_set_imr - Set interrupt mask
  468. *
  469. * @ah: The &struct ath5k_hw
  470. * @new_mask: The new interrupt mask to be set
  471. *
  472. * Set the interrupt mask in hw to save interrupts. We do that by mapping
  473. * ath5k_int bits to hw-specific bits to remove abstraction and writing
  474. * Interrupt Mask Register.
  475. */
  476. enum ath5k_int ath5k_hw_set_imr(struct ath5k_hw *ah, enum ath5k_int new_mask)
  477. {
  478. enum ath5k_int old_mask, int_mask;
  479. old_mask = ah->ah_imr;
  480. /*
  481. * Disable card interrupts to prevent any race conditions
  482. * (they will be re-enabled afterwards if AR5K_INT GLOBAL
  483. * is set again on the new mask).
  484. */
  485. if (old_mask & AR5K_INT_GLOBAL) {
  486. ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
  487. ath5k_hw_reg_read(ah, AR5K_IER);
  488. }
  489. /*
  490. * Add additional, chipset-dependent interrupt mask flags
  491. * and write them to the IMR (interrupt mask register).
  492. */
  493. int_mask = new_mask & AR5K_INT_COMMON;
  494. if (ah->ah_version != AR5K_AR5210) {
  495. /* Preserve per queue TXURN interrupt mask */
  496. u32 simr2 = ath5k_hw_reg_read(ah, AR5K_SIMR2)
  497. & AR5K_SIMR2_QCU_TXURN;
  498. if (new_mask & AR5K_INT_FATAL) {
  499. int_mask |= AR5K_IMR_HIUERR;
  500. simr2 |= (AR5K_SIMR2_MCABT | AR5K_SIMR2_SSERR
  501. | AR5K_SIMR2_DPERR);
  502. }
  503. /*Beacon Not Ready*/
  504. if (new_mask & AR5K_INT_BNR)
  505. int_mask |= AR5K_INT_BNR;
  506. if (new_mask & AR5K_INT_TIM)
  507. int_mask |= AR5K_IMR_TIM;
  508. if (new_mask & AR5K_INT_TIM)
  509. simr2 |= AR5K_SISR2_TIM;
  510. if (new_mask & AR5K_INT_DTIM)
  511. simr2 |= AR5K_SISR2_DTIM;
  512. if (new_mask & AR5K_INT_DTIM_SYNC)
  513. simr2 |= AR5K_SISR2_DTIM_SYNC;
  514. if (new_mask & AR5K_INT_BCN_TIMEOUT)
  515. simr2 |= AR5K_SISR2_BCN_TIMEOUT;
  516. if (new_mask & AR5K_INT_CAB_TIMEOUT)
  517. simr2 |= AR5K_SISR2_CAB_TIMEOUT;
  518. if (new_mask & AR5K_INT_RX_DOPPLER)
  519. int_mask |= AR5K_IMR_RXDOPPLER;
  520. /* Note: Per queue interrupt masks
  521. * are set via reset_tx_queue (qcu.c) */
  522. ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
  523. ath5k_hw_reg_write(ah, simr2, AR5K_SIMR2);
  524. } else {
  525. if (new_mask & AR5K_INT_FATAL)
  526. int_mask |= (AR5K_IMR_SSERR | AR5K_IMR_MCABT
  527. | AR5K_IMR_HIUERR | AR5K_IMR_DPERR);
  528. ath5k_hw_reg_write(ah, int_mask, AR5K_IMR);
  529. }
  530. /* If RXNOFRM interrupt is masked disable it
  531. * by setting AR5K_RXNOFRM to zero */
  532. if (!(new_mask & AR5K_INT_RXNOFRM))
  533. ath5k_hw_reg_write(ah, 0, AR5K_RXNOFRM);
  534. /* Store new interrupt mask */
  535. ah->ah_imr = new_mask;
  536. /* ..re-enable interrupts if AR5K_INT_GLOBAL is set */
  537. if (new_mask & AR5K_INT_GLOBAL) {
  538. ath5k_hw_reg_write(ah, ah->ah_ier, AR5K_IER);
  539. ath5k_hw_reg_read(ah, AR5K_IER);
  540. }
  541. return old_mask;
  542. }