dma.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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. * 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. 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_get_txdp - Get TX Descriptor's address for a specific queue
  280. *
  281. * @ah: The &struct ath5k_hw
  282. * @queue: The hw queue number
  283. *
  284. * Get TX descriptor's address for a specific queue. For 5210 we ignore
  285. * the queue number and use tx queue type since we only have 2 queues.
  286. * We use TXDP0 for normal data queue and TXDP1 for beacon queue.
  287. * For newer chips with QCU/DCU we just read the corresponding TXDP register.
  288. *
  289. * XXX: Is TXDP read and clear ?
  290. */
  291. u32 ath5k_hw_get_txdp(struct ath5k_hw *ah, unsigned int queue)
  292. {
  293. u16 tx_reg;
  294. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  295. /*
  296. * Get the transmit queue descriptor pointer from the selected queue
  297. */
  298. /*5210 doesn't have QCU*/
  299. if (ah->ah_version == AR5K_AR5210) {
  300. switch (ah->ah_txq[queue].tqi_type) {
  301. case AR5K_TX_QUEUE_DATA:
  302. tx_reg = AR5K_NOQCU_TXDP0;
  303. break;
  304. case AR5K_TX_QUEUE_BEACON:
  305. case AR5K_TX_QUEUE_CAB:
  306. tx_reg = AR5K_NOQCU_TXDP1;
  307. break;
  308. default:
  309. return 0xffffffff;
  310. }
  311. } else {
  312. tx_reg = AR5K_QUEUE_TXDP(queue);
  313. }
  314. return ath5k_hw_reg_read(ah, tx_reg);
  315. }
  316. /**
  317. * ath5k_hw_set_txdp - Set TX Descriptor's address for a specific queue
  318. *
  319. * @ah: The &struct ath5k_hw
  320. * @queue: The hw queue number
  321. *
  322. * Set TX descriptor's address for a specific queue. For 5210 we ignore
  323. * the queue number and we use tx queue type since we only have 2 queues
  324. * so as above we use TXDP0 for normal data queue and TXDP1 for beacon queue.
  325. * For newer chips with QCU/DCU we just set the corresponding TXDP register.
  326. * Returns -EINVAL if queue type is invalid for 5210 and -EIO if queue is still
  327. * active.
  328. */
  329. int ath5k_hw_set_txdp(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
  330. {
  331. u16 tx_reg;
  332. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  333. /*
  334. * Set the transmit queue descriptor pointer register by type
  335. * on 5210
  336. */
  337. if (ah->ah_version == AR5K_AR5210) {
  338. switch (ah->ah_txq[queue].tqi_type) {
  339. case AR5K_TX_QUEUE_DATA:
  340. tx_reg = AR5K_NOQCU_TXDP0;
  341. break;
  342. case AR5K_TX_QUEUE_BEACON:
  343. case AR5K_TX_QUEUE_CAB:
  344. tx_reg = AR5K_NOQCU_TXDP1;
  345. break;
  346. default:
  347. return -EINVAL;
  348. }
  349. } else {
  350. /*
  351. * Set the transmit queue descriptor pointer for
  352. * the selected queue on QCU for 5211+
  353. * (this won't work if the queue is still active)
  354. */
  355. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
  356. return -EIO;
  357. tx_reg = AR5K_QUEUE_TXDP(queue);
  358. }
  359. /* Set descriptor pointer */
  360. ath5k_hw_reg_write(ah, phys_addr, tx_reg);
  361. return 0;
  362. }
  363. /**
  364. * ath5k_hw_update_tx_triglevel - Update tx trigger level
  365. *
  366. * @ah: The &struct ath5k_hw
  367. * @increase: Flag to force increase of trigger level
  368. *
  369. * This function increases/decreases the tx trigger level for the tx fifo
  370. * buffer (aka FIFO threshold) that is used to indicate when PCU flushes
  371. * the buffer and transmits its data. Lowering this results sending small
  372. * frames more quickly but can lead to tx underruns, raising it a lot can
  373. * result other problems (i think bmiss is related). Right now we start with
  374. * the lowest possible (64Bytes) and if we get tx underrun we increase it using
  375. * the increase flag. Returns -EIO if we have reached maximum/minimum.
  376. *
  377. * XXX: Link this with tx DMA size ?
  378. * XXX: Use it to save interrupts ?
  379. * TODO: Needs testing, i think it's related to bmiss...
  380. */
  381. int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
  382. {
  383. u32 trigger_level, imr;
  384. int ret = -EIO;
  385. /*
  386. * Disable interrupts by setting the mask
  387. */
  388. imr = ath5k_hw_set_imr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
  389. trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
  390. AR5K_TXCFG_TXFULL);
  391. if (!increase) {
  392. if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
  393. goto done;
  394. } else
  395. trigger_level +=
  396. ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
  397. /*
  398. * Update trigger level on success
  399. */
  400. if (ah->ah_version == AR5K_AR5210)
  401. ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
  402. else
  403. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  404. AR5K_TXCFG_TXFULL, trigger_level);
  405. ret = 0;
  406. done:
  407. /*
  408. * Restore interrupt mask
  409. */
  410. ath5k_hw_set_imr(ah, imr);
  411. return ret;
  412. }
  413. /*******************\
  414. * Interrupt masking *
  415. \*******************/
  416. /**
  417. * ath5k_hw_is_intr_pending - Check if we have pending interrupts
  418. *
  419. * @ah: The &struct ath5k_hw
  420. *
  421. * Check if we have pending interrupts to process. Returns 1 if we
  422. * have pending interrupts and 0 if we haven't.
  423. */
  424. bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
  425. {
  426. return ath5k_hw_reg_read(ah, AR5K_INTPEND) == 1 ? 1 : 0;
  427. }
  428. /**
  429. * ath5k_hw_get_isr - Get interrupt status
  430. *
  431. * @ah: The @struct ath5k_hw
  432. * @interrupt_mask: Driver's interrupt mask used to filter out
  433. * interrupts in sw.
  434. *
  435. * This function is used inside our interrupt handler to determine the reason
  436. * for the interrupt by reading Primary Interrupt Status Register. Returns an
  437. * abstract interrupt status mask which is mostly ISR with some uncommon bits
  438. * being mapped on some standard non hw-specific positions
  439. * (check out &ath5k_int).
  440. *
  441. * NOTE: We use read-and-clear register, so after this function is called ISR
  442. * is zeroed.
  443. */
  444. int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
  445. {
  446. u32 data;
  447. /*
  448. * Read interrupt status from the Interrupt Status register
  449. * on 5210
  450. */
  451. if (ah->ah_version == AR5K_AR5210) {
  452. data = ath5k_hw_reg_read(ah, AR5K_ISR);
  453. if (unlikely(data == AR5K_INT_NOCARD)) {
  454. *interrupt_mask = data;
  455. return -ENODEV;
  456. }
  457. } else {
  458. /*
  459. * Read interrupt status from Interrupt
  460. * Status Register shadow copy (Read And Clear)
  461. *
  462. * Note: PISR/SISR Not available on 5210
  463. */
  464. data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
  465. if (unlikely(data == AR5K_INT_NOCARD)) {
  466. *interrupt_mask = data;
  467. return -ENODEV;
  468. }
  469. }
  470. /*
  471. * Get abstract interrupt mask (driver-compatible)
  472. */
  473. *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
  474. if (ah->ah_version != AR5K_AR5210) {
  475. u32 sisr2 = ath5k_hw_reg_read(ah, AR5K_RAC_SISR2);
  476. /*HIU = Host Interface Unit (PCI etc)*/
  477. if (unlikely(data & (AR5K_ISR_HIUERR)))
  478. *interrupt_mask |= AR5K_INT_FATAL;
  479. /*Beacon Not Ready*/
  480. if (unlikely(data & (AR5K_ISR_BNR)))
  481. *interrupt_mask |= AR5K_INT_BNR;
  482. if (unlikely(sisr2 & (AR5K_SISR2_SSERR |
  483. AR5K_SISR2_DPERR |
  484. AR5K_SISR2_MCABT)))
  485. *interrupt_mask |= AR5K_INT_FATAL;
  486. if (data & AR5K_ISR_TIM)
  487. *interrupt_mask |= AR5K_INT_TIM;
  488. if (data & AR5K_ISR_BCNMISC) {
  489. if (sisr2 & AR5K_SISR2_TIM)
  490. *interrupt_mask |= AR5K_INT_TIM;
  491. if (sisr2 & AR5K_SISR2_DTIM)
  492. *interrupt_mask |= AR5K_INT_DTIM;
  493. if (sisr2 & AR5K_SISR2_DTIM_SYNC)
  494. *interrupt_mask |= AR5K_INT_DTIM_SYNC;
  495. if (sisr2 & AR5K_SISR2_BCN_TIMEOUT)
  496. *interrupt_mask |= AR5K_INT_BCN_TIMEOUT;
  497. if (sisr2 & AR5K_SISR2_CAB_TIMEOUT)
  498. *interrupt_mask |= AR5K_INT_CAB_TIMEOUT;
  499. }
  500. if (data & AR5K_ISR_RXDOPPLER)
  501. *interrupt_mask |= AR5K_INT_RX_DOPPLER;
  502. if (data & AR5K_ISR_QCBRORN) {
  503. *interrupt_mask |= AR5K_INT_QCBRORN;
  504. ah->ah_txq_isr |= AR5K_REG_MS(
  505. ath5k_hw_reg_read(ah, AR5K_RAC_SISR3),
  506. AR5K_SISR3_QCBRORN);
  507. }
  508. if (data & AR5K_ISR_QCBRURN) {
  509. *interrupt_mask |= AR5K_INT_QCBRURN;
  510. ah->ah_txq_isr |= AR5K_REG_MS(
  511. ath5k_hw_reg_read(ah, AR5K_RAC_SISR3),
  512. AR5K_SISR3_QCBRURN);
  513. }
  514. if (data & AR5K_ISR_QTRIG) {
  515. *interrupt_mask |= AR5K_INT_QTRIG;
  516. ah->ah_txq_isr |= AR5K_REG_MS(
  517. ath5k_hw_reg_read(ah, AR5K_RAC_SISR4),
  518. AR5K_SISR4_QTRIG);
  519. }
  520. if (data & AR5K_ISR_TXOK)
  521. ah->ah_txq_isr |= AR5K_REG_MS(
  522. ath5k_hw_reg_read(ah, AR5K_RAC_SISR0),
  523. AR5K_SISR0_QCU_TXOK);
  524. if (data & AR5K_ISR_TXDESC)
  525. ah->ah_txq_isr |= AR5K_REG_MS(
  526. ath5k_hw_reg_read(ah, AR5K_RAC_SISR0),
  527. AR5K_SISR0_QCU_TXDESC);
  528. if (data & AR5K_ISR_TXERR)
  529. ah->ah_txq_isr |= AR5K_REG_MS(
  530. ath5k_hw_reg_read(ah, AR5K_RAC_SISR1),
  531. AR5K_SISR1_QCU_TXERR);
  532. if (data & AR5K_ISR_TXEOL)
  533. ah->ah_txq_isr |= AR5K_REG_MS(
  534. ath5k_hw_reg_read(ah, AR5K_RAC_SISR1),
  535. AR5K_SISR1_QCU_TXEOL);
  536. if (data & AR5K_ISR_TXURN)
  537. ah->ah_txq_isr |= AR5K_REG_MS(
  538. ath5k_hw_reg_read(ah, AR5K_RAC_SISR2),
  539. AR5K_SISR2_QCU_TXURN);
  540. } else {
  541. if (unlikely(data & (AR5K_ISR_SSERR | AR5K_ISR_MCABT
  542. | AR5K_ISR_HIUERR | AR5K_ISR_DPERR)))
  543. *interrupt_mask |= AR5K_INT_FATAL;
  544. /*
  545. * XXX: BMISS interrupts may occur after association.
  546. * I found this on 5210 code but it needs testing. If this is
  547. * true we should disable them before assoc and re-enable them
  548. * after a successful assoc + some jiffies.
  549. interrupt_mask &= ~AR5K_INT_BMISS;
  550. */
  551. }
  552. /*
  553. * In case we didn't handle anything,
  554. * print the register value.
  555. */
  556. if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
  557. ATH5K_PRINTF("ISR: 0x%08x IMR: 0x%08x\n", data, ah->ah_imr);
  558. return 0;
  559. }
  560. /**
  561. * ath5k_hw_set_imr - Set interrupt mask
  562. *
  563. * @ah: The &struct ath5k_hw
  564. * @new_mask: The new interrupt mask to be set
  565. *
  566. * Set the interrupt mask in hw to save interrupts. We do that by mapping
  567. * ath5k_int bits to hw-specific bits to remove abstraction and writing
  568. * Interrupt Mask Register.
  569. */
  570. enum ath5k_int ath5k_hw_set_imr(struct ath5k_hw *ah, enum ath5k_int new_mask)
  571. {
  572. enum ath5k_int old_mask, int_mask;
  573. old_mask = ah->ah_imr;
  574. /*
  575. * Disable card interrupts to prevent any race conditions
  576. * (they will be re-enabled afterwards if AR5K_INT GLOBAL
  577. * is set again on the new mask).
  578. */
  579. if (old_mask & AR5K_INT_GLOBAL) {
  580. ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
  581. ath5k_hw_reg_read(ah, AR5K_IER);
  582. }
  583. /*
  584. * Add additional, chipset-dependent interrupt mask flags
  585. * and write them to the IMR (interrupt mask register).
  586. */
  587. int_mask = new_mask & AR5K_INT_COMMON;
  588. if (ah->ah_version != AR5K_AR5210) {
  589. /* Preserve per queue TXURN interrupt mask */
  590. u32 simr2 = ath5k_hw_reg_read(ah, AR5K_SIMR2)
  591. & AR5K_SIMR2_QCU_TXURN;
  592. if (new_mask & AR5K_INT_FATAL) {
  593. int_mask |= AR5K_IMR_HIUERR;
  594. simr2 |= (AR5K_SIMR2_MCABT | AR5K_SIMR2_SSERR
  595. | AR5K_SIMR2_DPERR);
  596. }
  597. /*Beacon Not Ready*/
  598. if (new_mask & AR5K_INT_BNR)
  599. int_mask |= AR5K_INT_BNR;
  600. if (new_mask & AR5K_INT_TIM)
  601. int_mask |= AR5K_IMR_TIM;
  602. if (new_mask & AR5K_INT_TIM)
  603. simr2 |= AR5K_SISR2_TIM;
  604. if (new_mask & AR5K_INT_DTIM)
  605. simr2 |= AR5K_SISR2_DTIM;
  606. if (new_mask & AR5K_INT_DTIM_SYNC)
  607. simr2 |= AR5K_SISR2_DTIM_SYNC;
  608. if (new_mask & AR5K_INT_BCN_TIMEOUT)
  609. simr2 |= AR5K_SISR2_BCN_TIMEOUT;
  610. if (new_mask & AR5K_INT_CAB_TIMEOUT)
  611. simr2 |= AR5K_SISR2_CAB_TIMEOUT;
  612. if (new_mask & AR5K_INT_RX_DOPPLER)
  613. int_mask |= AR5K_IMR_RXDOPPLER;
  614. /* Note: Per queue interrupt masks
  615. * are set via reset_tx_queue (qcu.c) */
  616. ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
  617. ath5k_hw_reg_write(ah, simr2, AR5K_SIMR2);
  618. } else {
  619. if (new_mask & AR5K_INT_FATAL)
  620. int_mask |= (AR5K_IMR_SSERR | AR5K_IMR_MCABT
  621. | AR5K_IMR_HIUERR | AR5K_IMR_DPERR);
  622. ath5k_hw_reg_write(ah, int_mask, AR5K_IMR);
  623. }
  624. /* If RXNOFRM interrupt is masked disable it
  625. * by setting AR5K_RXNOFRM to zero */
  626. if (!(new_mask & AR5K_INT_RXNOFRM))
  627. ath5k_hw_reg_write(ah, 0, AR5K_RXNOFRM);
  628. /* Store new interrupt mask */
  629. ah->ah_imr = new_mask;
  630. /* ..re-enable interrupts if AR5K_INT_GLOBAL is set */
  631. if (new_mask & AR5K_INT_GLOBAL) {
  632. ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
  633. ath5k_hw_reg_read(ah, AR5K_IER);
  634. }
  635. return old_mask;
  636. }
  637. /********************\
  638. Init/Stop functions
  639. \********************/
  640. /**
  641. * ath5k_hw_dma_init - Initialize DMA unit
  642. *
  643. * @ah: The &struct ath5k_hw
  644. *
  645. * Set DMA size and pre-enable interrupts
  646. * (driver handles tx/rx buffer setup and
  647. * dma start/stop)
  648. *
  649. * XXX: Save/restore RXDP/TXDP registers ?
  650. */
  651. void ath5k_hw_dma_init(struct ath5k_hw *ah)
  652. {
  653. /*
  654. * Set Rx/Tx DMA Configuration
  655. *
  656. * Set standard DMA size (128). Note that
  657. * a DMA size of 512 causes rx overruns and tx errors
  658. * on pci-e cards (tested on 5424 but since rx overruns
  659. * also occur on 5416/5418 with madwifi we set 128
  660. * for all PCI-E cards to be safe).
  661. *
  662. * XXX: need to check 5210 for this
  663. * TODO: Check out tx triger level, it's always 64 on dumps but I
  664. * guess we can tweak it and see how it goes ;-)
  665. */
  666. if (ah->ah_version != AR5K_AR5210) {
  667. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  668. AR5K_TXCFG_SDMAMR, AR5K_DMASIZE_128B);
  669. AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
  670. AR5K_RXCFG_SDMAMW, AR5K_DMASIZE_128B);
  671. }
  672. /* Pre-enable interrupts on 5211/5212*/
  673. if (ah->ah_version != AR5K_AR5210)
  674. ath5k_hw_set_imr(ah, ah->ah_imr);
  675. }
  676. /**
  677. * ath5k_hw_dma_stop - stop DMA unit
  678. *
  679. * @ah: The &struct ath5k_hw
  680. *
  681. * Stop tx/rx DMA and interrupts. Returns
  682. * -EBUSY if tx or rx dma failed to stop.
  683. *
  684. * XXX: Sometimes DMA unit hangs and we have
  685. * stuck frames on tx queues, only a reset
  686. * can fix that.
  687. */
  688. int ath5k_hw_dma_stop(struct ath5k_hw *ah)
  689. {
  690. int i, qmax, err;
  691. err = 0;
  692. /* Disable interrupts */
  693. ath5k_hw_set_imr(ah, 0);
  694. /* Stop rx dma */
  695. err = ath5k_hw_stop_rx_dma(ah);
  696. if (err)
  697. return err;
  698. /* Clear any pending interrupts
  699. * and disable tx dma */
  700. if (ah->ah_version != AR5K_AR5210) {
  701. ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
  702. qmax = AR5K_NUM_TX_QUEUES;
  703. } else {
  704. /* PISR/SISR Not available on 5210 */
  705. ath5k_hw_reg_read(ah, AR5K_ISR);
  706. qmax = AR5K_NUM_TX_QUEUES_NOQCU;
  707. }
  708. for (i = 0; i < qmax; i++) {
  709. err = ath5k_hw_stop_tx_dma(ah, i);
  710. /* -EINVAL -> queue inactive */
  711. if (err != -EINVAL)
  712. return err;
  713. }
  714. return err;
  715. }