qcu.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. Queue Control Unit, DFS Control Unit Functions
  20. \********************************************/
  21. #include "ath5k.h"
  22. #include "reg.h"
  23. #include "debug.h"
  24. /******************\
  25. * Helper functions *
  26. \******************/
  27. /*
  28. * Get number of pending frames
  29. * for a specific queue [5211+]
  30. */
  31. u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue)
  32. {
  33. u32 pending;
  34. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  35. /* Return if queue is declared inactive */
  36. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  37. return false;
  38. /* XXX: How about AR5K_CFG_TXCNT ? */
  39. if (ah->ah_version == AR5K_AR5210)
  40. return false;
  41. pending = ath5k_hw_reg_read(ah, AR5K_QUEUE_STATUS(queue));
  42. pending &= AR5K_QCU_STS_FRMPENDCNT;
  43. /* It's possible to have no frames pending even if TXE
  44. * is set. To indicate that q has not stopped return
  45. * true */
  46. if (!pending && AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
  47. return true;
  48. return pending;
  49. }
  50. /*
  51. * Set a transmit queue inactive
  52. */
  53. void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
  54. {
  55. if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
  56. return;
  57. /* This queue will be skipped in further operations */
  58. ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
  59. /*For SIMR setup*/
  60. AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
  61. }
  62. /*
  63. * Make sure cw is a power of 2 minus 1 and smaller than 1024
  64. */
  65. static u16 ath5k_cw_validate(u16 cw_req)
  66. {
  67. u32 cw = 1;
  68. cw_req = min(cw_req, (u16)1023);
  69. while (cw < cw_req)
  70. cw = (cw << 1) | 1;
  71. return cw;
  72. }
  73. /*
  74. * Get properties for a transmit queue
  75. */
  76. int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
  77. struct ath5k_txq_info *queue_info)
  78. {
  79. memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
  80. return 0;
  81. }
  82. /*
  83. * Set properties for a transmit queue
  84. */
  85. int ath5k_hw_set_tx_queueprops(struct ath5k_hw *ah, int queue,
  86. const struct ath5k_txq_info *qinfo)
  87. {
  88. struct ath5k_txq_info *qi;
  89. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  90. qi = &ah->ah_txq[queue];
  91. if (qi->tqi_type == AR5K_TX_QUEUE_INACTIVE)
  92. return -EIO;
  93. /* copy and validate values */
  94. qi->tqi_type = qinfo->tqi_type;
  95. qi->tqi_subtype = qinfo->tqi_subtype;
  96. qi->tqi_flags = qinfo->tqi_flags;
  97. /*
  98. * According to the docs: Although the AIFS field is 8 bit wide,
  99. * the maximum supported value is 0xFC. Setting it higher than that
  100. * will cause the DCU to hang.
  101. */
  102. qi->tqi_aifs = min(qinfo->tqi_aifs, (u8)0xFC);
  103. qi->tqi_cw_min = ath5k_cw_validate(qinfo->tqi_cw_min);
  104. qi->tqi_cw_max = ath5k_cw_validate(qinfo->tqi_cw_max);
  105. qi->tqi_cbr_period = qinfo->tqi_cbr_period;
  106. qi->tqi_cbr_overflow_limit = qinfo->tqi_cbr_overflow_limit;
  107. qi->tqi_burst_time = qinfo->tqi_burst_time;
  108. qi->tqi_ready_time = qinfo->tqi_ready_time;
  109. /*XXX: Is this supported on 5210 ?*/
  110. /*XXX: Is this correct for AR5K_WME_AC_VI,VO ???*/
  111. if ((qinfo->tqi_type == AR5K_TX_QUEUE_DATA &&
  112. ((qinfo->tqi_subtype == AR5K_WME_AC_VI) ||
  113. (qinfo->tqi_subtype == AR5K_WME_AC_VO))) ||
  114. qinfo->tqi_type == AR5K_TX_QUEUE_UAPSD)
  115. qi->tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
  116. return 0;
  117. }
  118. /*
  119. * Initialize a transmit queue
  120. */
  121. int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
  122. struct ath5k_txq_info *queue_info)
  123. {
  124. unsigned int queue;
  125. int ret;
  126. /*
  127. * Get queue by type
  128. */
  129. /* 5210 only has 2 queues */
  130. if (ah->ah_capabilities.cap_queues.q_tx_num == 2) {
  131. switch (queue_type) {
  132. case AR5K_TX_QUEUE_DATA:
  133. queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
  134. break;
  135. case AR5K_TX_QUEUE_BEACON:
  136. case AR5K_TX_QUEUE_CAB:
  137. queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
  138. break;
  139. default:
  140. return -EINVAL;
  141. }
  142. } else {
  143. switch (queue_type) {
  144. case AR5K_TX_QUEUE_DATA:
  145. for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
  146. ah->ah_txq[queue].tqi_type !=
  147. AR5K_TX_QUEUE_INACTIVE; queue++) {
  148. if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
  149. return -EINVAL;
  150. }
  151. break;
  152. case AR5K_TX_QUEUE_UAPSD:
  153. queue = AR5K_TX_QUEUE_ID_UAPSD;
  154. break;
  155. case AR5K_TX_QUEUE_BEACON:
  156. queue = AR5K_TX_QUEUE_ID_BEACON;
  157. break;
  158. case AR5K_TX_QUEUE_CAB:
  159. queue = AR5K_TX_QUEUE_ID_CAB;
  160. break;
  161. default:
  162. return -EINVAL;
  163. }
  164. }
  165. /*
  166. * Setup internal queue structure
  167. */
  168. memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
  169. ah->ah_txq[queue].tqi_type = queue_type;
  170. if (queue_info != NULL) {
  171. queue_info->tqi_type = queue_type;
  172. ret = ath5k_hw_set_tx_queueprops(ah, queue, queue_info);
  173. if (ret)
  174. return ret;
  175. }
  176. /*
  177. * We use ah_txq_status to hold a temp value for
  178. * the Secondary interrupt mask registers on 5211+
  179. * check out ath5k_hw_reset_tx_queue
  180. */
  181. AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
  182. return queue;
  183. }
  184. /*******************************\
  185. * Single QCU/DCU initialization *
  186. \*******************************/
  187. /*
  188. * Set tx retry limits on DCU
  189. */
  190. void ath5k_hw_set_tx_retry_limits(struct ath5k_hw *ah,
  191. unsigned int queue)
  192. {
  193. /* Single data queue on AR5210 */
  194. if (ah->ah_version == AR5K_AR5210) {
  195. struct ath5k_txq_info *tq = &ah->ah_txq[queue];
  196. if (queue > 0)
  197. return;
  198. ath5k_hw_reg_write(ah,
  199. (tq->tqi_cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
  200. | AR5K_REG_SM(ah->ah_retry_long,
  201. AR5K_NODCU_RETRY_LMT_SLG_RETRY)
  202. | AR5K_REG_SM(ah->ah_retry_short,
  203. AR5K_NODCU_RETRY_LMT_SSH_RETRY)
  204. | AR5K_REG_SM(ah->ah_retry_long,
  205. AR5K_NODCU_RETRY_LMT_LG_RETRY)
  206. | AR5K_REG_SM(ah->ah_retry_short,
  207. AR5K_NODCU_RETRY_LMT_SH_RETRY),
  208. AR5K_NODCU_RETRY_LMT);
  209. /* DCU on AR5211+ */
  210. } else {
  211. ath5k_hw_reg_write(ah,
  212. AR5K_REG_SM(ah->ah_retry_long,
  213. AR5K_DCU_RETRY_LMT_RTS)
  214. | AR5K_REG_SM(ah->ah_retry_long,
  215. AR5K_DCU_RETRY_LMT_STA_RTS)
  216. | AR5K_REG_SM(max(ah->ah_retry_long, ah->ah_retry_short),
  217. AR5K_DCU_RETRY_LMT_STA_DATA),
  218. AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
  219. }
  220. }
  221. /**
  222. * ath5k_hw_reset_tx_queue - Initialize a single hw queue
  223. *
  224. * @ah The &struct ath5k_hw
  225. * @queue The hw queue number
  226. *
  227. * Set DFS properties for the given transmit queue on DCU
  228. * and configures all queue-specific parameters.
  229. */
  230. int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
  231. {
  232. struct ath5k_txq_info *tq = &ah->ah_txq[queue];
  233. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  234. tq = &ah->ah_txq[queue];
  235. /* Skip if queue inactive or if we are on AR5210
  236. * that doesn't have QCU/DCU */
  237. if ((ah->ah_version == AR5K_AR5210) ||
  238. (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE))
  239. return 0;
  240. /*
  241. * Set contention window (cw_min/cw_max)
  242. * and arbitrated interframe space (aifs)...
  243. */
  244. ath5k_hw_reg_write(ah,
  245. AR5K_REG_SM(tq->tqi_cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
  246. AR5K_REG_SM(tq->tqi_cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
  247. AR5K_REG_SM(tq->tqi_aifs, AR5K_DCU_LCL_IFS_AIFS),
  248. AR5K_QUEUE_DFS_LOCAL_IFS(queue));
  249. /*
  250. * Set tx retry limits for this queue
  251. */
  252. ath5k_hw_set_tx_retry_limits(ah, queue);
  253. /*
  254. * Set misc registers
  255. */
  256. /* Enable DCU to wait for next fragment from QCU */
  257. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  258. AR5K_DCU_MISC_FRAG_WAIT);
  259. /* On Maui and Spirit use the global seqnum on DCU */
  260. if (ah->ah_mac_version < AR5K_SREV_AR5211)
  261. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  262. AR5K_DCU_MISC_SEQNUM_CTL);
  263. /* Constant bit rate period */
  264. if (tq->tqi_cbr_period) {
  265. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
  266. AR5K_QCU_CBRCFG_INTVAL) |
  267. AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
  268. AR5K_QCU_CBRCFG_ORN_THRES),
  269. AR5K_QUEUE_CBRCFG(queue));
  270. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  271. AR5K_QCU_MISC_FRSHED_CBR);
  272. if (tq->tqi_cbr_overflow_limit)
  273. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  274. AR5K_QCU_MISC_CBR_THRES_ENABLE);
  275. }
  276. /* Ready time interval */
  277. if (tq->tqi_ready_time && (tq->tqi_type != AR5K_TX_QUEUE_CAB))
  278. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
  279. AR5K_QCU_RDYTIMECFG_INTVAL) |
  280. AR5K_QCU_RDYTIMECFG_ENABLE,
  281. AR5K_QUEUE_RDYTIMECFG(queue));
  282. if (tq->tqi_burst_time) {
  283. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
  284. AR5K_DCU_CHAN_TIME_DUR) |
  285. AR5K_DCU_CHAN_TIME_ENABLE,
  286. AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
  287. if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
  288. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  289. AR5K_QCU_MISC_RDY_VEOL_POLICY);
  290. }
  291. /* Enable/disable Post frame backoff */
  292. if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
  293. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
  294. AR5K_QUEUE_DFS_MISC(queue));
  295. /* Enable/disable fragmentation burst backoff */
  296. if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
  297. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
  298. AR5K_QUEUE_DFS_MISC(queue));
  299. /*
  300. * Set registers by queue type
  301. */
  302. switch (tq->tqi_type) {
  303. case AR5K_TX_QUEUE_BEACON:
  304. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  305. AR5K_QCU_MISC_FRSHED_DBA_GT |
  306. AR5K_QCU_MISC_CBREXP_BCN_DIS |
  307. AR5K_QCU_MISC_BCN_ENABLE);
  308. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  309. (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
  310. AR5K_DCU_MISC_ARBLOCK_CTL_S) |
  311. AR5K_DCU_MISC_ARBLOCK_IGNORE |
  312. AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
  313. AR5K_DCU_MISC_BCN_ENABLE);
  314. break;
  315. case AR5K_TX_QUEUE_CAB:
  316. /* XXX: use BCN_SENT_GT, if we can figure out how */
  317. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  318. AR5K_QCU_MISC_FRSHED_DBA_GT |
  319. AR5K_QCU_MISC_CBREXP_DIS |
  320. AR5K_QCU_MISC_CBREXP_BCN_DIS);
  321. ath5k_hw_reg_write(ah, ((tq->tqi_ready_time -
  322. (AR5K_TUNE_SW_BEACON_RESP -
  323. AR5K_TUNE_DMA_BEACON_RESP) -
  324. AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
  325. AR5K_QCU_RDYTIMECFG_ENABLE,
  326. AR5K_QUEUE_RDYTIMECFG(queue));
  327. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  328. (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
  329. AR5K_DCU_MISC_ARBLOCK_CTL_S));
  330. break;
  331. case AR5K_TX_QUEUE_UAPSD:
  332. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  333. AR5K_QCU_MISC_CBREXP_DIS);
  334. break;
  335. case AR5K_TX_QUEUE_DATA:
  336. default:
  337. break;
  338. }
  339. /* TODO: Handle frame compression */
  340. /*
  341. * Enable interrupts for this tx queue
  342. * in the secondary interrupt mask registers
  343. */
  344. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
  345. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
  346. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
  347. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
  348. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
  349. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
  350. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
  351. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
  352. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
  353. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
  354. if (tq->tqi_flags & AR5K_TXQ_FLAG_CBRORNINT_ENABLE)
  355. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_cbrorn, queue);
  356. if (tq->tqi_flags & AR5K_TXQ_FLAG_CBRURNINT_ENABLE)
  357. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_cbrurn, queue);
  358. if (tq->tqi_flags & AR5K_TXQ_FLAG_QTRIGINT_ENABLE)
  359. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_qtrig, queue);
  360. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXNOFRMINT_ENABLE)
  361. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_nofrm, queue);
  362. /* Update secondary interrupt mask registers */
  363. /* Filter out inactive queues */
  364. ah->ah_txq_imr_txok &= ah->ah_txq_status;
  365. ah->ah_txq_imr_txerr &= ah->ah_txq_status;
  366. ah->ah_txq_imr_txurn &= ah->ah_txq_status;
  367. ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
  368. ah->ah_txq_imr_txeol &= ah->ah_txq_status;
  369. ah->ah_txq_imr_cbrorn &= ah->ah_txq_status;
  370. ah->ah_txq_imr_cbrurn &= ah->ah_txq_status;
  371. ah->ah_txq_imr_qtrig &= ah->ah_txq_status;
  372. ah->ah_txq_imr_nofrm &= ah->ah_txq_status;
  373. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
  374. AR5K_SIMR0_QCU_TXOK) |
  375. AR5K_REG_SM(ah->ah_txq_imr_txdesc,
  376. AR5K_SIMR0_QCU_TXDESC),
  377. AR5K_SIMR0);
  378. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
  379. AR5K_SIMR1_QCU_TXERR) |
  380. AR5K_REG_SM(ah->ah_txq_imr_txeol,
  381. AR5K_SIMR1_QCU_TXEOL),
  382. AR5K_SIMR1);
  383. /* Update SIMR2 but don't overwrite rest simr2 settings */
  384. AR5K_REG_DISABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_QCU_TXURN);
  385. AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2,
  386. AR5K_REG_SM(ah->ah_txq_imr_txurn,
  387. AR5K_SIMR2_QCU_TXURN));
  388. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_cbrorn,
  389. AR5K_SIMR3_QCBRORN) |
  390. AR5K_REG_SM(ah->ah_txq_imr_cbrurn,
  391. AR5K_SIMR3_QCBRURN),
  392. AR5K_SIMR3);
  393. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_qtrig,
  394. AR5K_SIMR4_QTRIG), AR5K_SIMR4);
  395. /* Set TXNOFRM_QCU for the queues with TXNOFRM enabled */
  396. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_nofrm,
  397. AR5K_TXNOFRM_QCU), AR5K_TXNOFRM);
  398. /* No queue has TXNOFRM enabled, disable the interrupt
  399. * by setting AR5K_TXNOFRM to zero */
  400. if (ah->ah_txq_imr_nofrm == 0)
  401. ath5k_hw_reg_write(ah, 0, AR5K_TXNOFRM);
  402. /* Set QCU mask for this DCU to save power */
  403. AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(queue), queue);
  404. return 0;
  405. }
  406. /**************************\
  407. * Global QCU/DCU functions *
  408. \**************************/
  409. /**
  410. * ath5k_hw_set_ifs_intervals - Set global inter-frame spaces on DCU
  411. *
  412. * @ah The &struct ath5k_hw
  413. * @slot_time Slot time in us
  414. *
  415. * Sets the global IFS intervals on DCU (also works on AR5210) for
  416. * the given slot time and the current bwmode.
  417. */
  418. int ath5k_hw_set_ifs_intervals(struct ath5k_hw *ah, unsigned int slot_time)
  419. {
  420. struct ieee80211_channel *channel = ah->ah_current_channel;
  421. struct ieee80211_rate *rate;
  422. u32 ack_tx_time, eifs, eifs_clock, sifs, sifs_clock;
  423. u32 slot_time_clock = ath5k_hw_htoclock(ah, slot_time);
  424. if (slot_time < 6 || slot_time_clock > AR5K_SLOT_TIME_MAX)
  425. return -EINVAL;
  426. sifs = ath5k_hw_get_default_sifs(ah);
  427. sifs_clock = ath5k_hw_htoclock(ah, sifs - 2);
  428. /* EIFS
  429. * Txtime of ack at lowest rate + SIFS + DIFS
  430. * (DIFS = SIFS + 2 * Slot time)
  431. *
  432. * Note: HAL has some predefined values for EIFS
  433. * Turbo: (37 + 2 * 6)
  434. * Default: (74 + 2 * 9)
  435. * Half: (149 + 2 * 13)
  436. * Quarter: (298 + 2 * 21)
  437. *
  438. * (74 + 2 * 6) for AR5210 default and turbo !
  439. *
  440. * According to the formula we have
  441. * ack_tx_time = 25 for turbo and
  442. * ack_tx_time = 42.5 * clock multiplier
  443. * for default/half/quarter.
  444. *
  445. * This can't be right, 42 is what we would get
  446. * from ath5k_hw_get_frame_dur_for_bwmode or
  447. * ieee80211_generic_frame_duration for zero frame
  448. * length and without SIFS !
  449. *
  450. * Also we have different lowest rate for 802.11a
  451. */
  452. if (channel->band == IEEE80211_BAND_5GHZ)
  453. rate = &ah->sbands[IEEE80211_BAND_5GHZ].bitrates[0];
  454. else
  455. rate = &ah->sbands[IEEE80211_BAND_2GHZ].bitrates[0];
  456. ack_tx_time = ath5k_hw_get_frame_duration(ah, 10, rate, false);
  457. /* ack_tx_time includes an SIFS already */
  458. eifs = ack_tx_time + sifs + 2 * slot_time;
  459. eifs_clock = ath5k_hw_htoclock(ah, eifs);
  460. /* Set IFS settings on AR5210 */
  461. if (ah->ah_version == AR5K_AR5210) {
  462. u32 pifs, pifs_clock, difs, difs_clock;
  463. /* Set slot time */
  464. ath5k_hw_reg_write(ah, slot_time_clock, AR5K_SLOT_TIME);
  465. /* Set EIFS */
  466. eifs_clock = AR5K_REG_SM(eifs_clock, AR5K_IFS1_EIFS);
  467. /* PIFS = Slot time + SIFS */
  468. pifs = slot_time + sifs;
  469. pifs_clock = ath5k_hw_htoclock(ah, pifs);
  470. pifs_clock = AR5K_REG_SM(pifs_clock, AR5K_IFS1_PIFS);
  471. /* DIFS = SIFS + 2 * Slot time */
  472. difs = sifs + 2 * slot_time;
  473. difs_clock = ath5k_hw_htoclock(ah, difs);
  474. /* Set SIFS/DIFS */
  475. ath5k_hw_reg_write(ah, (difs_clock <<
  476. AR5K_IFS0_DIFS_S) | sifs_clock,
  477. AR5K_IFS0);
  478. /* Set PIFS/EIFS and preserve AR5K_INIT_CARR_SENSE_EN */
  479. ath5k_hw_reg_write(ah, pifs_clock | eifs_clock |
  480. (AR5K_INIT_CARR_SENSE_EN << AR5K_IFS1_CS_EN_S),
  481. AR5K_IFS1);
  482. return 0;
  483. }
  484. /* Set IFS slot time */
  485. ath5k_hw_reg_write(ah, slot_time_clock, AR5K_DCU_GBL_IFS_SLOT);
  486. /* Set EIFS interval */
  487. ath5k_hw_reg_write(ah, eifs_clock, AR5K_DCU_GBL_IFS_EIFS);
  488. /* Set SIFS interval in usecs */
  489. AR5K_REG_WRITE_BITS(ah, AR5K_DCU_GBL_IFS_MISC,
  490. AR5K_DCU_GBL_IFS_MISC_SIFS_DUR_USEC,
  491. sifs);
  492. /* Set SIFS interval in clock cycles */
  493. ath5k_hw_reg_write(ah, sifs_clock, AR5K_DCU_GBL_IFS_SIFS);
  494. return 0;
  495. }
  496. int ath5k_hw_init_queues(struct ath5k_hw *ah)
  497. {
  498. int i, ret;
  499. /* TODO: HW Compression support for data queues */
  500. /* TODO: Burst prefetch for data queues */
  501. /*
  502. * Reset queues and start beacon timers at the end of the reset routine
  503. * This also sets QCU mask on each DCU for 1:1 qcu to dcu mapping
  504. * Note: If we want we can assign multiple qcus on one dcu.
  505. */
  506. if (ah->ah_version != AR5K_AR5210)
  507. for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
  508. ret = ath5k_hw_reset_tx_queue(ah, i);
  509. if (ret) {
  510. ATH5K_ERR(ah,
  511. "failed to reset TX queue #%d\n", i);
  512. return ret;
  513. }
  514. }
  515. else
  516. /* No QCU/DCU on AR5210, just set tx
  517. * retry limits. We set IFS parameters
  518. * on ath5k_hw_set_ifs_intervals */
  519. ath5k_hw_set_tx_retry_limits(ah, 0);
  520. /* Set the turbo flag when operating on 40MHz */
  521. if (ah->ah_bwmode == AR5K_BWMODE_40MHZ)
  522. AR5K_REG_ENABLE_BITS(ah, AR5K_DCU_GBL_IFS_MISC,
  523. AR5K_DCU_GBL_IFS_MISC_TURBO_MODE);
  524. /* If we didn't set IFS timings through
  525. * ath5k_hw_set_coverage_class make sure
  526. * we set them here */
  527. if (!ah->ah_coverage_class) {
  528. unsigned int slot_time = ath5k_hw_get_default_slottime(ah);
  529. ath5k_hw_set_ifs_intervals(ah, slot_time);
  530. }
  531. return 0;
  532. }