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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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 gPXE, 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. unsigned int queue;
  51. int ret;
  52. /* We only use one queue */
  53. queue = 0;
  54. /*
  55. * Setup internal queue structure
  56. */
  57. memset(&ah->ah_txq, 0, sizeof(struct ath5k_txq_info));
  58. ah->ah_txq.tqi_type = queue_type;
  59. if (queue_info != NULL) {
  60. queue_info->tqi_type = queue_type;
  61. ret = ath5k_hw_set_tx_queueprops(ah, queue_info);
  62. if (ret)
  63. return ret;
  64. }
  65. /*
  66. * We use ah_txq_status to hold a temp value for
  67. * the Secondary interrupt mask registers on 5211+
  68. * check out ath5k_hw_reset_tx_queue
  69. */
  70. AR5K_Q_ENABLE_BITS(ah->ah_txq_status, 0);
  71. return 0;
  72. }
  73. /*
  74. * Set a transmit queue inactive
  75. */
  76. void ath5k_hw_release_tx_queue(struct ath5k_hw *ah)
  77. {
  78. /* This queue will be skipped in further operations */
  79. ah->ah_txq.tqi_type = AR5K_TX_QUEUE_INACTIVE;
  80. /*For SIMR setup*/
  81. AR5K_Q_DISABLE_BITS(ah->ah_txq_status, 0);
  82. }
  83. /*
  84. * Set DFS properties for a transmit queue on DCU
  85. */
  86. int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah)
  87. {
  88. u32 cw_min, cw_max, retry_lg, retry_sh;
  89. struct ath5k_txq_info *tq = &ah->ah_txq;
  90. const int queue = 0;
  91. tq = &ah->ah_txq;
  92. if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
  93. return 0;
  94. if (ah->ah_version == AR5K_AR5210) {
  95. /* Only handle data queues, others will be ignored */
  96. if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
  97. return 0;
  98. /* Set Slot time */
  99. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  100. AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
  101. AR5K_SLOT_TIME);
  102. /* Set ACK_CTS timeout */
  103. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  104. AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
  105. AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
  106. /* Set Transmit Latency */
  107. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  108. AR5K_INIT_TRANSMIT_LATENCY_TURBO :
  109. AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
  110. /* Set IFS0 */
  111. if (ah->ah_turbo) {
  112. ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
  113. (ah->ah_aifs + tq->tqi_aifs) *
  114. AR5K_INIT_SLOT_TIME_TURBO) <<
  115. AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
  116. AR5K_IFS0);
  117. } else {
  118. ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
  119. (ah->ah_aifs + tq->tqi_aifs) *
  120. AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
  121. AR5K_INIT_SIFS, AR5K_IFS0);
  122. }
  123. /* Set IFS1 */
  124. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  125. AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
  126. AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
  127. /* Set AR5K_PHY_SETTLING */
  128. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  129. (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
  130. | 0x38 :
  131. (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
  132. | 0x1C,
  133. AR5K_PHY_SETTLING);
  134. /* Set Frame Control Register */
  135. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  136. (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
  137. AR5K_PHY_TURBO_SHORT | 0x2020) :
  138. (AR5K_PHY_FRAME_CTL_INI | 0x1020),
  139. AR5K_PHY_FRAME_CTL_5210);
  140. }
  141. /*
  142. * Calculate cwmin/max by channel mode
  143. */
  144. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
  145. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
  146. ah->ah_aifs = AR5K_TUNE_AIFS;
  147. /*XR is only supported on 5212*/
  148. if (IS_CHAN_XR(ah->ah_current_channel) &&
  149. ah->ah_version == AR5K_AR5212) {
  150. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
  151. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
  152. ah->ah_aifs = AR5K_TUNE_AIFS_XR;
  153. /*B mode is not supported on 5210*/
  154. } else if (IS_CHAN_B(ah->ah_current_channel) &&
  155. ah->ah_version != AR5K_AR5210) {
  156. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
  157. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
  158. ah->ah_aifs = AR5K_TUNE_AIFS_11B;
  159. }
  160. cw_min = 1;
  161. while (cw_min < ah->ah_cw_min)
  162. cw_min = (cw_min << 1) | 1;
  163. cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
  164. ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
  165. cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
  166. ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
  167. /*
  168. * Calculate and set retry limits
  169. */
  170. if (ah->ah_software_retry) {
  171. /* XXX Need to test this */
  172. retry_lg = ah->ah_limit_tx_retries;
  173. retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
  174. AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
  175. } else {
  176. retry_lg = AR5K_INIT_LG_RETRY;
  177. retry_sh = AR5K_INIT_SH_RETRY;
  178. }
  179. /*No QCU/DCU [5210]*/
  180. if (ah->ah_version == AR5K_AR5210) {
  181. ath5k_hw_reg_write(ah,
  182. (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
  183. | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
  184. AR5K_NODCU_RETRY_LMT_SLG_RETRY)
  185. | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
  186. AR5K_NODCU_RETRY_LMT_SSH_RETRY)
  187. | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
  188. | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
  189. AR5K_NODCU_RETRY_LMT);
  190. } else {
  191. /*QCU/DCU [5211+]*/
  192. ath5k_hw_reg_write(ah,
  193. AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
  194. AR5K_DCU_RETRY_LMT_SLG_RETRY) |
  195. AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
  196. AR5K_DCU_RETRY_LMT_SSH_RETRY) |
  197. AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
  198. AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
  199. AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
  200. /*===Rest is also for QCU/DCU only [5211+]===*/
  201. /*
  202. * Set initial content window (cw_min/cw_max)
  203. * and arbitrated interframe space (aifs)...
  204. */
  205. ath5k_hw_reg_write(ah,
  206. AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
  207. AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
  208. AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
  209. AR5K_DCU_LCL_IFS_AIFS),
  210. AR5K_QUEUE_DFS_LOCAL_IFS(queue));
  211. /*
  212. * Set misc registers
  213. */
  214. /* Enable DCU early termination for this queue */
  215. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  216. AR5K_QCU_MISC_DCU_EARLY);
  217. /* Enable DCU to wait for next fragment from QCU */
  218. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  219. AR5K_DCU_MISC_FRAG_WAIT);
  220. /* On Maui and Spirit use the global seqnum on DCU */
  221. if (ah->ah_mac_version < AR5K_SREV_AR5211)
  222. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  223. AR5K_DCU_MISC_SEQNUM_CTL);
  224. if (tq->tqi_cbr_period) {
  225. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
  226. AR5K_QCU_CBRCFG_INTVAL) |
  227. AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
  228. AR5K_QCU_CBRCFG_ORN_THRES),
  229. AR5K_QUEUE_CBRCFG(queue));
  230. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  231. AR5K_QCU_MISC_FRSHED_CBR);
  232. if (tq->tqi_cbr_overflow_limit)
  233. AR5K_REG_ENABLE_BITS(ah,
  234. AR5K_QUEUE_MISC(queue),
  235. AR5K_QCU_MISC_CBR_THRES_ENABLE);
  236. }
  237. if (tq->tqi_ready_time &&
  238. (tq->tqi_type != AR5K_TX_QUEUE_ID_CAB))
  239. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
  240. AR5K_QCU_RDYTIMECFG_INTVAL) |
  241. AR5K_QCU_RDYTIMECFG_ENABLE,
  242. AR5K_QUEUE_RDYTIMECFG(queue));
  243. if (tq->tqi_burst_time) {
  244. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
  245. AR5K_DCU_CHAN_TIME_DUR) |
  246. AR5K_DCU_CHAN_TIME_ENABLE,
  247. AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
  248. if (tq->tqi_flags
  249. & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
  250. AR5K_REG_ENABLE_BITS(ah,
  251. AR5K_QUEUE_MISC(queue),
  252. AR5K_QCU_MISC_RDY_VEOL_POLICY);
  253. }
  254. if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
  255. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
  256. AR5K_QUEUE_DFS_MISC(queue));
  257. if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
  258. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
  259. AR5K_QUEUE_DFS_MISC(queue));
  260. /* TODO: Handle frame compression */
  261. /*
  262. * Enable interrupts for this tx queue
  263. * in the secondary interrupt mask registers
  264. */
  265. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
  266. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
  267. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
  268. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
  269. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
  270. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
  271. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
  272. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
  273. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
  274. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
  275. if (tq->tqi_flags & AR5K_TXQ_FLAG_CBRORNINT_ENABLE)
  276. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_cbrorn, queue);
  277. if (tq->tqi_flags & AR5K_TXQ_FLAG_CBRURNINT_ENABLE)
  278. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_cbrurn, queue);
  279. if (tq->tqi_flags & AR5K_TXQ_FLAG_QTRIGINT_ENABLE)
  280. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_qtrig, queue);
  281. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXNOFRMINT_ENABLE)
  282. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_nofrm, queue);
  283. /* Update secondary interrupt mask registers */
  284. /* Filter out inactive queues */
  285. ah->ah_txq_imr_txok &= ah->ah_txq_status;
  286. ah->ah_txq_imr_txerr &= ah->ah_txq_status;
  287. ah->ah_txq_imr_txurn &= ah->ah_txq_status;
  288. ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
  289. ah->ah_txq_imr_txeol &= ah->ah_txq_status;
  290. ah->ah_txq_imr_cbrorn &= ah->ah_txq_status;
  291. ah->ah_txq_imr_cbrurn &= ah->ah_txq_status;
  292. ah->ah_txq_imr_qtrig &= ah->ah_txq_status;
  293. ah->ah_txq_imr_nofrm &= ah->ah_txq_status;
  294. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
  295. AR5K_SIMR0_QCU_TXOK) |
  296. AR5K_REG_SM(ah->ah_txq_imr_txdesc,
  297. AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
  298. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
  299. AR5K_SIMR1_QCU_TXERR) |
  300. AR5K_REG_SM(ah->ah_txq_imr_txeol,
  301. AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
  302. /* Update simr2 but don't overwrite rest simr2 settings */
  303. AR5K_REG_DISABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_QCU_TXURN);
  304. AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2,
  305. AR5K_REG_SM(ah->ah_txq_imr_txurn,
  306. AR5K_SIMR2_QCU_TXURN));
  307. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_cbrorn,
  308. AR5K_SIMR3_QCBRORN) |
  309. AR5K_REG_SM(ah->ah_txq_imr_cbrurn,
  310. AR5K_SIMR3_QCBRURN), AR5K_SIMR3);
  311. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_qtrig,
  312. AR5K_SIMR4_QTRIG), AR5K_SIMR4);
  313. /* Set TXNOFRM_QCU for the queues with TXNOFRM enabled */
  314. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_nofrm,
  315. AR5K_TXNOFRM_QCU), AR5K_TXNOFRM);
  316. /* No queue has TXNOFRM enabled, disable the interrupt
  317. * by setting AR5K_TXNOFRM to zero */
  318. if (ah->ah_txq_imr_nofrm == 0)
  319. ath5k_hw_reg_write(ah, 0, AR5K_TXNOFRM);
  320. /* Set QCU mask for this DCU to save power */
  321. AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(queue), queue);
  322. }
  323. return 0;
  324. }
  325. /*
  326. * Set slot time on DCU
  327. */
  328. int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
  329. {
  330. if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
  331. return -EINVAL;
  332. if (ah->ah_version == AR5K_AR5210)
  333. ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
  334. ah->ah_turbo), AR5K_SLOT_TIME);
  335. else
  336. ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
  337. return 0;
  338. }