You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath5k_qcu.c 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*
  2. * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
  3. * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
  4. *
  5. * Lightly modified for iPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
  6. *
  7. * Permission to use, copy, modify, and distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. *
  19. */
  20. FILE_LICENCE ( MIT );
  21. /********************************************\
  22. Queue Control Unit, DFS Control Unit Functions
  23. \********************************************/
  24. #include "ath5k.h"
  25. #include "reg.h"
  26. #include "base.h"
  27. /*
  28. * Set properties for a transmit queue
  29. */
  30. int ath5k_hw_set_tx_queueprops(struct ath5k_hw *ah,
  31. const struct ath5k_txq_info *queue_info)
  32. {
  33. if (ah->ah_txq.tqi_type == AR5K_TX_QUEUE_INACTIVE)
  34. return -EIO;
  35. memcpy(&ah->ah_txq, queue_info, sizeof(struct ath5k_txq_info));
  36. /*XXX: Is this supported on 5210 ?*/
  37. if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
  38. ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
  39. (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
  40. queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
  41. ah->ah_txq.tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
  42. return 0;
  43. }
  44. /*
  45. * Initialize a transmit queue
  46. */
  47. int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
  48. struct ath5k_txq_info *queue_info)
  49. {
  50. int ret;
  51. /*
  52. * Setup internal queue structure
  53. */
  54. memset(&ah->ah_txq, 0, sizeof(struct ath5k_txq_info));
  55. ah->ah_txq.tqi_type = queue_type;
  56. if (queue_info != NULL) {
  57. queue_info->tqi_type = queue_type;
  58. ret = ath5k_hw_set_tx_queueprops(ah, queue_info);
  59. if (ret)
  60. return ret;
  61. }
  62. /*
  63. * We use ah_txq_status to hold a temp value for
  64. * the Secondary interrupt mask registers on 5211+
  65. * check out ath5k_hw_reset_tx_queue
  66. */
  67. AR5K_Q_ENABLE_BITS(ah->ah_txq_status, 0);
  68. return 0;
  69. }
  70. /*
  71. * Set a transmit queue inactive
  72. */
  73. void ath5k_hw_release_tx_queue(struct ath5k_hw *ah)
  74. {
  75. /* This queue will be skipped in further operations */
  76. ah->ah_txq.tqi_type = AR5K_TX_QUEUE_INACTIVE;
  77. /*For SIMR setup*/
  78. AR5K_Q_DISABLE_BITS(ah->ah_txq_status, 0);
  79. }
  80. /*
  81. * Set DFS properties for a transmit queue on DCU
  82. */
  83. int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah)
  84. {
  85. u32 cw_min, cw_max, retry_lg, retry_sh;
  86. struct ath5k_txq_info *tq = &ah->ah_txq;
  87. const int queue = 0;
  88. tq = &ah->ah_txq;
  89. if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
  90. return 0;
  91. if (ah->ah_version == AR5K_AR5210) {
  92. /* Only handle data queues, others will be ignored */
  93. if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
  94. return 0;
  95. /* Set Slot time */
  96. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  97. AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
  98. AR5K_SLOT_TIME);
  99. /* Set ACK_CTS timeout */
  100. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  101. AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
  102. AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
  103. /* Set Transmit Latency */
  104. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  105. AR5K_INIT_TRANSMIT_LATENCY_TURBO :
  106. AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
  107. /* Set IFS0 */
  108. if (ah->ah_turbo) {
  109. ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
  110. (ah->ah_aifs + tq->tqi_aifs) *
  111. AR5K_INIT_SLOT_TIME_TURBO) <<
  112. AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
  113. AR5K_IFS0);
  114. } else {
  115. ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
  116. (ah->ah_aifs + tq->tqi_aifs) *
  117. AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
  118. AR5K_INIT_SIFS, AR5K_IFS0);
  119. }
  120. /* Set IFS1 */
  121. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  122. AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
  123. AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
  124. /* Set AR5K_PHY_SETTLING */
  125. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  126. (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
  127. | 0x38 :
  128. (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
  129. | 0x1C,
  130. AR5K_PHY_SETTLING);
  131. /* Set Frame Control Register */
  132. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  133. (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
  134. AR5K_PHY_TURBO_SHORT | 0x2020) :
  135. (AR5K_PHY_FRAME_CTL_INI | 0x1020),
  136. AR5K_PHY_FRAME_CTL_5210);
  137. }
  138. /*
  139. * Calculate cwmin/max by channel mode
  140. */
  141. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
  142. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
  143. ah->ah_aifs = AR5K_TUNE_AIFS;
  144. /*XR is only supported on 5212*/
  145. if (IS_CHAN_XR(ah->ah_current_channel) &&
  146. ah->ah_version == AR5K_AR5212) {
  147. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
  148. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
  149. ah->ah_aifs = AR5K_TUNE_AIFS_XR;
  150. /*B mode is not supported on 5210*/
  151. } else if (IS_CHAN_B(ah->ah_current_channel) &&
  152. ah->ah_version != AR5K_AR5210) {
  153. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
  154. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
  155. ah->ah_aifs = AR5K_TUNE_AIFS_11B;
  156. }
  157. cw_min = 1;
  158. while (cw_min < ah->ah_cw_min)
  159. cw_min = (cw_min << 1) | 1;
  160. cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
  161. ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
  162. cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
  163. ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
  164. /*
  165. * Calculate and set retry limits
  166. */
  167. if (ah->ah_software_retry) {
  168. /* XXX Need to test this */
  169. retry_lg = ah->ah_limit_tx_retries;
  170. retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
  171. AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
  172. } else {
  173. retry_lg = AR5K_INIT_LG_RETRY;
  174. retry_sh = AR5K_INIT_SH_RETRY;
  175. }
  176. /*No QCU/DCU [5210]*/
  177. if (ah->ah_version == AR5K_AR5210) {
  178. ath5k_hw_reg_write(ah,
  179. (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
  180. | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
  181. AR5K_NODCU_RETRY_LMT_SLG_RETRY)
  182. | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
  183. AR5K_NODCU_RETRY_LMT_SSH_RETRY)
  184. | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
  185. | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
  186. AR5K_NODCU_RETRY_LMT);
  187. } else {
  188. /*QCU/DCU [5211+]*/
  189. ath5k_hw_reg_write(ah,
  190. AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
  191. AR5K_DCU_RETRY_LMT_SLG_RETRY) |
  192. AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
  193. AR5K_DCU_RETRY_LMT_SSH_RETRY) |
  194. AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
  195. AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
  196. AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
  197. /*===Rest is also for QCU/DCU only [5211+]===*/
  198. /*
  199. * Set initial content window (cw_min/cw_max)
  200. * and arbitrated interframe space (aifs)...
  201. */
  202. ath5k_hw_reg_write(ah,
  203. AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
  204. AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
  205. AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
  206. AR5K_DCU_LCL_IFS_AIFS),
  207. AR5K_QUEUE_DFS_LOCAL_IFS(queue));
  208. /*
  209. * Set misc registers
  210. */
  211. /* Enable DCU early termination for this queue */
  212. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  213. AR5K_QCU_MISC_DCU_EARLY);
  214. /* Enable DCU to wait for next fragment from QCU */
  215. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  216. AR5K_DCU_MISC_FRAG_WAIT);
  217. /* On Maui and Spirit use the global seqnum on DCU */
  218. if (ah->ah_mac_version < AR5K_SREV_AR5211)
  219. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  220. AR5K_DCU_MISC_SEQNUM_CTL);
  221. if (tq->tqi_cbr_period) {
  222. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
  223. AR5K_QCU_CBRCFG_INTVAL) |
  224. AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
  225. AR5K_QCU_CBRCFG_ORN_THRES),
  226. AR5K_QUEUE_CBRCFG(queue));
  227. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  228. AR5K_QCU_MISC_FRSHED_CBR);
  229. if (tq->tqi_cbr_overflow_limit)
  230. AR5K_REG_ENABLE_BITS(ah,
  231. AR5K_QUEUE_MISC(queue),
  232. AR5K_QCU_MISC_CBR_THRES_ENABLE);
  233. }
  234. if (tq->tqi_ready_time &&
  235. (tq->tqi_type != AR5K_TX_QUEUE_CAB))
  236. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
  237. AR5K_QCU_RDYTIMECFG_INTVAL) |
  238. AR5K_QCU_RDYTIMECFG_ENABLE,
  239. AR5K_QUEUE_RDYTIMECFG(queue));
  240. if (tq->tqi_burst_time) {
  241. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
  242. AR5K_DCU_CHAN_TIME_DUR) |
  243. AR5K_DCU_CHAN_TIME_ENABLE,
  244. AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
  245. if (tq->tqi_flags
  246. & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
  247. AR5K_REG_ENABLE_BITS(ah,
  248. AR5K_QUEUE_MISC(queue),
  249. AR5K_QCU_MISC_RDY_VEOL_POLICY);
  250. }
  251. if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
  252. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
  253. AR5K_QUEUE_DFS_MISC(queue));
  254. if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
  255. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
  256. AR5K_QUEUE_DFS_MISC(queue));
  257. /* TODO: Handle frame compression */
  258. /*
  259. * Enable interrupts for this tx queue
  260. * in the secondary interrupt mask registers
  261. */
  262. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
  263. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
  264. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
  265. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
  266. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
  267. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
  268. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
  269. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
  270. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
  271. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
  272. if (tq->tqi_flags & AR5K_TXQ_FLAG_CBRORNINT_ENABLE)
  273. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_cbrorn, queue);
  274. if (tq->tqi_flags & AR5K_TXQ_FLAG_CBRURNINT_ENABLE)
  275. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_cbrurn, queue);
  276. if (tq->tqi_flags & AR5K_TXQ_FLAG_QTRIGINT_ENABLE)
  277. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_qtrig, queue);
  278. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXNOFRMINT_ENABLE)
  279. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_nofrm, queue);
  280. /* Update secondary interrupt mask registers */
  281. /* Filter out inactive queues */
  282. ah->ah_txq_imr_txok &= ah->ah_txq_status;
  283. ah->ah_txq_imr_txerr &= ah->ah_txq_status;
  284. ah->ah_txq_imr_txurn &= ah->ah_txq_status;
  285. ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
  286. ah->ah_txq_imr_txeol &= ah->ah_txq_status;
  287. ah->ah_txq_imr_cbrorn &= ah->ah_txq_status;
  288. ah->ah_txq_imr_cbrurn &= ah->ah_txq_status;
  289. ah->ah_txq_imr_qtrig &= ah->ah_txq_status;
  290. ah->ah_txq_imr_nofrm &= ah->ah_txq_status;
  291. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
  292. AR5K_SIMR0_QCU_TXOK) |
  293. AR5K_REG_SM(ah->ah_txq_imr_txdesc,
  294. AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
  295. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
  296. AR5K_SIMR1_QCU_TXERR) |
  297. AR5K_REG_SM(ah->ah_txq_imr_txeol,
  298. AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
  299. /* Update simr2 but don't overwrite rest simr2 settings */
  300. AR5K_REG_DISABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_QCU_TXURN);
  301. AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2,
  302. AR5K_REG_SM(ah->ah_txq_imr_txurn,
  303. AR5K_SIMR2_QCU_TXURN));
  304. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_cbrorn,
  305. AR5K_SIMR3_QCBRORN) |
  306. AR5K_REG_SM(ah->ah_txq_imr_cbrurn,
  307. AR5K_SIMR3_QCBRURN), AR5K_SIMR3);
  308. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_qtrig,
  309. AR5K_SIMR4_QTRIG), AR5K_SIMR4);
  310. /* Set TXNOFRM_QCU for the queues with TXNOFRM enabled */
  311. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_nofrm,
  312. AR5K_TXNOFRM_QCU), AR5K_TXNOFRM);
  313. /* No queue has TXNOFRM enabled, disable the interrupt
  314. * by setting AR5K_TXNOFRM to zero */
  315. if (ah->ah_txq_imr_nofrm == 0)
  316. ath5k_hw_reg_write(ah, 0, AR5K_TXNOFRM);
  317. /* Set QCU mask for this DCU to save power */
  318. AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(queue), queue);
  319. }
  320. return 0;
  321. }
  322. /*
  323. * Set slot time on DCU
  324. */
  325. int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
  326. {
  327. if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
  328. return -EINVAL;
  329. if (ah->ah_version == AR5K_AR5210)
  330. ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
  331. ah->ah_turbo), AR5K_SLOT_TIME);
  332. else
  333. ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
  334. return 0;
  335. }