qcu.c 18 KB

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