qcu.c 20 KB

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