dma.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  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. * TODO: Needs testing, i think it's related to bmiss...
  398. */
  399. int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
  400. {
  401. u32 trigger_level, imr;
  402. int ret = -EIO;
  403. /*
  404. * Disable interrupts by setting the mask
  405. */
  406. imr = ath5k_hw_set_imr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
  407. trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
  408. AR5K_TXCFG_TXFULL);
  409. if (!increase) {
  410. if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
  411. goto done;
  412. } else
  413. trigger_level +=
  414. ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
  415. /*
  416. * Update trigger level on success
  417. */
  418. if (ah->ah_version == AR5K_AR5210)
  419. ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
  420. else
  421. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  422. AR5K_TXCFG_TXFULL, trigger_level);
  423. ret = 0;
  424. done:
  425. /*
  426. * Restore interrupt mask
  427. */
  428. ath5k_hw_set_imr(ah, imr);
  429. return ret;
  430. }
  431. /*******************\
  432. * Interrupt masking *
  433. \*******************/
  434. /**
  435. * ath5k_hw_is_intr_pending - Check if we have pending interrupts
  436. *
  437. * @ah: The &struct ath5k_hw
  438. *
  439. * Check if we have pending interrupts to process. Returns 1 if we
  440. * have pending interrupts and 0 if we haven't.
  441. */
  442. bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
  443. {
  444. return ath5k_hw_reg_read(ah, AR5K_INTPEND) == 1 ? 1 : 0;
  445. }
  446. /**
  447. * ath5k_hw_get_isr - Get interrupt status
  448. *
  449. * @ah: The @struct ath5k_hw
  450. * @interrupt_mask: Driver's interrupt mask used to filter out
  451. * interrupts in sw.
  452. *
  453. * This function is used inside our interrupt handler to determine the reason
  454. * for the interrupt by reading Primary Interrupt Status Register. Returns an
  455. * abstract interrupt status mask which is mostly ISR with some uncommon bits
  456. * being mapped on some standard non hw-specific positions
  457. * (check out &ath5k_int).
  458. *
  459. * NOTE: We use read-and-clear register, so after this function is called ISR
  460. * is zeroed.
  461. */
  462. int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
  463. {
  464. u32 data;
  465. /*
  466. * Read interrupt status from the Interrupt Status register
  467. * on 5210
  468. */
  469. if (ah->ah_version == AR5K_AR5210) {
  470. data = ath5k_hw_reg_read(ah, AR5K_ISR);
  471. if (unlikely(data == AR5K_INT_NOCARD)) {
  472. *interrupt_mask = data;
  473. return -ENODEV;
  474. }
  475. } else {
  476. /*
  477. * Read interrupt status from Interrupt
  478. * Status Register shadow copy (Read And Clear)
  479. *
  480. * Note: PISR/SISR Not available on 5210
  481. */
  482. data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
  483. if (unlikely(data == AR5K_INT_NOCARD)) {
  484. *interrupt_mask = data;
  485. return -ENODEV;
  486. }
  487. }
  488. /*
  489. * Get abstract interrupt mask (driver-compatible)
  490. */
  491. *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
  492. if (ah->ah_version != AR5K_AR5210) {
  493. u32 sisr2 = ath5k_hw_reg_read(ah, AR5K_RAC_SISR2);
  494. /*HIU = Host Interface Unit (PCI etc)*/
  495. if (unlikely(data & (AR5K_ISR_HIUERR)))
  496. *interrupt_mask |= AR5K_INT_FATAL;
  497. /*Beacon Not Ready*/
  498. if (unlikely(data & (AR5K_ISR_BNR)))
  499. *interrupt_mask |= AR5K_INT_BNR;
  500. if (unlikely(sisr2 & (AR5K_SISR2_SSERR |
  501. AR5K_SISR2_DPERR |
  502. AR5K_SISR2_MCABT)))
  503. *interrupt_mask |= AR5K_INT_FATAL;
  504. if (data & AR5K_ISR_TIM)
  505. *interrupt_mask |= AR5K_INT_TIM;
  506. if (data & AR5K_ISR_BCNMISC) {
  507. if (sisr2 & AR5K_SISR2_TIM)
  508. *interrupt_mask |= AR5K_INT_TIM;
  509. if (sisr2 & AR5K_SISR2_DTIM)
  510. *interrupt_mask |= AR5K_INT_DTIM;
  511. if (sisr2 & AR5K_SISR2_DTIM_SYNC)
  512. *interrupt_mask |= AR5K_INT_DTIM_SYNC;
  513. if (sisr2 & AR5K_SISR2_BCN_TIMEOUT)
  514. *interrupt_mask |= AR5K_INT_BCN_TIMEOUT;
  515. if (sisr2 & AR5K_SISR2_CAB_TIMEOUT)
  516. *interrupt_mask |= AR5K_INT_CAB_TIMEOUT;
  517. }
  518. if (data & AR5K_ISR_RXDOPPLER)
  519. *interrupt_mask |= AR5K_INT_RX_DOPPLER;
  520. if (data & AR5K_ISR_QCBRORN) {
  521. *interrupt_mask |= AR5K_INT_QCBRORN;
  522. ah->ah_txq_isr |= AR5K_REG_MS(
  523. ath5k_hw_reg_read(ah, AR5K_RAC_SISR3),
  524. AR5K_SISR3_QCBRORN);
  525. }
  526. if (data & AR5K_ISR_QCBRURN) {
  527. *interrupt_mask |= AR5K_INT_QCBRURN;
  528. ah->ah_txq_isr |= AR5K_REG_MS(
  529. ath5k_hw_reg_read(ah, AR5K_RAC_SISR3),
  530. AR5K_SISR3_QCBRURN);
  531. }
  532. if (data & AR5K_ISR_QTRIG) {
  533. *interrupt_mask |= AR5K_INT_QTRIG;
  534. ah->ah_txq_isr |= AR5K_REG_MS(
  535. ath5k_hw_reg_read(ah, AR5K_RAC_SISR4),
  536. AR5K_SISR4_QTRIG);
  537. }
  538. if (data & AR5K_ISR_TXOK)
  539. ah->ah_txq_isr |= AR5K_REG_MS(
  540. ath5k_hw_reg_read(ah, AR5K_RAC_SISR0),
  541. AR5K_SISR0_QCU_TXOK);
  542. if (data & AR5K_ISR_TXDESC)
  543. ah->ah_txq_isr |= AR5K_REG_MS(
  544. ath5k_hw_reg_read(ah, AR5K_RAC_SISR0),
  545. AR5K_SISR0_QCU_TXDESC);
  546. if (data & AR5K_ISR_TXERR)
  547. ah->ah_txq_isr |= AR5K_REG_MS(
  548. ath5k_hw_reg_read(ah, AR5K_RAC_SISR1),
  549. AR5K_SISR1_QCU_TXERR);
  550. if (data & AR5K_ISR_TXEOL)
  551. ah->ah_txq_isr |= AR5K_REG_MS(
  552. ath5k_hw_reg_read(ah, AR5K_RAC_SISR1),
  553. AR5K_SISR1_QCU_TXEOL);
  554. if (data & AR5K_ISR_TXURN)
  555. ah->ah_txq_isr |= AR5K_REG_MS(
  556. ath5k_hw_reg_read(ah, AR5K_RAC_SISR2),
  557. AR5K_SISR2_QCU_TXURN);
  558. } else {
  559. if (unlikely(data & (AR5K_ISR_SSERR | AR5K_ISR_MCABT
  560. | AR5K_ISR_HIUERR | AR5K_ISR_DPERR)))
  561. *interrupt_mask |= AR5K_INT_FATAL;
  562. /*
  563. * XXX: BMISS interrupts may occur after association.
  564. * I found this on 5210 code but it needs testing. If this is
  565. * true we should disable them before assoc and re-enable them
  566. * after a successful assoc + some jiffies.
  567. interrupt_mask &= ~AR5K_INT_BMISS;
  568. */
  569. }
  570. /*
  571. * In case we didn't handle anything,
  572. * print the register value.
  573. */
  574. if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
  575. ATH5K_PRINTF("ISR: 0x%08x IMR: 0x%08x\n", data, ah->ah_imr);
  576. return 0;
  577. }
  578. /**
  579. * ath5k_hw_set_imr - Set interrupt mask
  580. *
  581. * @ah: The &struct ath5k_hw
  582. * @new_mask: The new interrupt mask to be set
  583. *
  584. * Set the interrupt mask in hw to save interrupts. We do that by mapping
  585. * ath5k_int bits to hw-specific bits to remove abstraction and writing
  586. * Interrupt Mask Register.
  587. */
  588. enum ath5k_int ath5k_hw_set_imr(struct ath5k_hw *ah, enum ath5k_int new_mask)
  589. {
  590. enum ath5k_int old_mask, int_mask;
  591. old_mask = ah->ah_imr;
  592. /*
  593. * Disable card interrupts to prevent any race conditions
  594. * (they will be re-enabled afterwards if AR5K_INT GLOBAL
  595. * is set again on the new mask).
  596. */
  597. if (old_mask & AR5K_INT_GLOBAL) {
  598. ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
  599. ath5k_hw_reg_read(ah, AR5K_IER);
  600. }
  601. /*
  602. * Add additional, chipset-dependent interrupt mask flags
  603. * and write them to the IMR (interrupt mask register).
  604. */
  605. int_mask = new_mask & AR5K_INT_COMMON;
  606. if (ah->ah_version != AR5K_AR5210) {
  607. /* Preserve per queue TXURN interrupt mask */
  608. u32 simr2 = ath5k_hw_reg_read(ah, AR5K_SIMR2)
  609. & AR5K_SIMR2_QCU_TXURN;
  610. if (new_mask & AR5K_INT_FATAL) {
  611. int_mask |= AR5K_IMR_HIUERR;
  612. simr2 |= (AR5K_SIMR2_MCABT | AR5K_SIMR2_SSERR
  613. | AR5K_SIMR2_DPERR);
  614. }
  615. /*Beacon Not Ready*/
  616. if (new_mask & AR5K_INT_BNR)
  617. int_mask |= AR5K_INT_BNR;
  618. if (new_mask & AR5K_INT_TIM)
  619. int_mask |= AR5K_IMR_TIM;
  620. if (new_mask & AR5K_INT_TIM)
  621. simr2 |= AR5K_SISR2_TIM;
  622. if (new_mask & AR5K_INT_DTIM)
  623. simr2 |= AR5K_SISR2_DTIM;
  624. if (new_mask & AR5K_INT_DTIM_SYNC)
  625. simr2 |= AR5K_SISR2_DTIM_SYNC;
  626. if (new_mask & AR5K_INT_BCN_TIMEOUT)
  627. simr2 |= AR5K_SISR2_BCN_TIMEOUT;
  628. if (new_mask & AR5K_INT_CAB_TIMEOUT)
  629. simr2 |= AR5K_SISR2_CAB_TIMEOUT;
  630. if (new_mask & AR5K_INT_RX_DOPPLER)
  631. int_mask |= AR5K_IMR_RXDOPPLER;
  632. /* Note: Per queue interrupt masks
  633. * are set via ath5k_hw_reset_tx_queue() (qcu.c) */
  634. ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
  635. ath5k_hw_reg_write(ah, simr2, AR5K_SIMR2);
  636. } else {
  637. if (new_mask & AR5K_INT_FATAL)
  638. int_mask |= (AR5K_IMR_SSERR | AR5K_IMR_MCABT
  639. | AR5K_IMR_HIUERR | AR5K_IMR_DPERR);
  640. ath5k_hw_reg_write(ah, int_mask, AR5K_IMR);
  641. }
  642. /* If RXNOFRM interrupt is masked disable it
  643. * by setting AR5K_RXNOFRM to zero */
  644. if (!(new_mask & AR5K_INT_RXNOFRM))
  645. ath5k_hw_reg_write(ah, 0, AR5K_RXNOFRM);
  646. /* Store new interrupt mask */
  647. ah->ah_imr = new_mask;
  648. /* ..re-enable interrupts if AR5K_INT_GLOBAL is set */
  649. if (new_mask & AR5K_INT_GLOBAL) {
  650. ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
  651. ath5k_hw_reg_read(ah, AR5K_IER);
  652. }
  653. return old_mask;
  654. }
  655. /********************\
  656. Init/Stop functions
  657. \********************/
  658. /**
  659. * ath5k_hw_dma_init - Initialize DMA unit
  660. *
  661. * @ah: The &struct ath5k_hw
  662. *
  663. * Set DMA size and pre-enable interrupts
  664. * (driver handles tx/rx buffer setup and
  665. * dma start/stop)
  666. *
  667. * XXX: Save/restore RXDP/TXDP registers ?
  668. */
  669. void ath5k_hw_dma_init(struct ath5k_hw *ah)
  670. {
  671. /*
  672. * Set Rx/Tx DMA Configuration
  673. *
  674. * Set standard DMA size (128). Note that
  675. * a DMA size of 512 causes rx overruns and tx errors
  676. * on pci-e cards (tested on 5424 but since rx overruns
  677. * also occur on 5416/5418 with madwifi we set 128
  678. * for all PCI-E cards to be safe).
  679. *
  680. * XXX: need to check 5210 for this
  681. * TODO: Check out tx trigger level, it's always 64 on dumps but I
  682. * guess we can tweak it and see how it goes ;-)
  683. */
  684. if (ah->ah_version != AR5K_AR5210) {
  685. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  686. AR5K_TXCFG_SDMAMR, AR5K_DMASIZE_128B);
  687. AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
  688. AR5K_RXCFG_SDMAMW, AR5K_DMASIZE_128B);
  689. }
  690. /* Pre-enable interrupts on 5211/5212*/
  691. if (ah->ah_version != AR5K_AR5210)
  692. ath5k_hw_set_imr(ah, ah->ah_imr);
  693. }
  694. /**
  695. * ath5k_hw_dma_stop - stop DMA unit
  696. *
  697. * @ah: The &struct ath5k_hw
  698. *
  699. * Stop tx/rx DMA and interrupts. Returns
  700. * -EBUSY if tx or rx dma failed to stop.
  701. *
  702. * XXX: Sometimes DMA unit hangs and we have
  703. * stuck frames on tx queues, only a reset
  704. * can fix that.
  705. */
  706. int ath5k_hw_dma_stop(struct ath5k_hw *ah)
  707. {
  708. int i, qmax, err;
  709. err = 0;
  710. /* Disable interrupts */
  711. ath5k_hw_set_imr(ah, 0);
  712. /* Stop rx dma */
  713. err = ath5k_hw_stop_rx_dma(ah);
  714. if (err)
  715. return err;
  716. /* Clear any pending interrupts
  717. * and disable tx dma */
  718. if (ah->ah_version != AR5K_AR5210) {
  719. ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
  720. qmax = AR5K_NUM_TX_QUEUES;
  721. } else {
  722. /* PISR/SISR Not available on 5210 */
  723. ath5k_hw_reg_read(ah, AR5K_ISR);
  724. qmax = AR5K_NUM_TX_QUEUES_NOQCU;
  725. }
  726. for (i = 0; i < qmax; i++) {
  727. err = ath5k_hw_stop_tx_dma(ah, i);
  728. /* -EINVAL -> queue inactive */
  729. if (err && err != -EINVAL)
  730. return err;
  731. }
  732. return 0;
  733. }