dma.c 21 KB

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