dma.c 24 KB

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