dma.c 24 KB

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