dma.c 21 KB

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