qcu.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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. queue = queue_info->tqi_subtype;
  200. break;
  201. case AR5K_TX_QUEUE_UAPSD:
  202. queue = AR5K_TX_QUEUE_ID_UAPSD;
  203. break;
  204. case AR5K_TX_QUEUE_BEACON:
  205. queue = AR5K_TX_QUEUE_ID_BEACON;
  206. break;
  207. case AR5K_TX_QUEUE_CAB:
  208. queue = AR5K_TX_QUEUE_ID_CAB;
  209. break;
  210. default:
  211. return -EINVAL;
  212. }
  213. }
  214. /*
  215. * Setup internal queue structure
  216. */
  217. memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
  218. ah->ah_txq[queue].tqi_type = queue_type;
  219. if (queue_info != NULL) {
  220. queue_info->tqi_type = queue_type;
  221. ret = ath5k_hw_set_tx_queueprops(ah, queue, queue_info);
  222. if (ret)
  223. return ret;
  224. }
  225. /*
  226. * We use ah_txq_status to hold a temp value for
  227. * the Secondary interrupt mask registers on 5211+
  228. * check out ath5k_hw_reset_tx_queue
  229. */
  230. AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
  231. return queue;
  232. }
  233. /*******************************\
  234. * Single QCU/DCU initialization *
  235. \*******************************/
  236. /**
  237. * ath5k_hw_set_tx_retry_limits() - Set tx retry limits on DCU
  238. * @ah: The &struct ath5k_hw
  239. * @queue: One of enum ath5k_tx_queue_id
  240. *
  241. * This function is used when initializing a queue, to set
  242. * retry limits based on ah->ah_retry_* and the chipset used.
  243. */
  244. void
  245. ath5k_hw_set_tx_retry_limits(struct ath5k_hw *ah,
  246. unsigned int queue)
  247. {
  248. /* Single data queue on AR5210 */
  249. if (ah->ah_version == AR5K_AR5210) {
  250. struct ath5k_txq_info *tq = &ah->ah_txq[queue];
  251. if (queue > 0)
  252. return;
  253. ath5k_hw_reg_write(ah,
  254. (tq->tqi_cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
  255. | AR5K_REG_SM(ah->ah_retry_long,
  256. AR5K_NODCU_RETRY_LMT_SLG_RETRY)
  257. | AR5K_REG_SM(ah->ah_retry_short,
  258. AR5K_NODCU_RETRY_LMT_SSH_RETRY)
  259. | AR5K_REG_SM(ah->ah_retry_long,
  260. AR5K_NODCU_RETRY_LMT_LG_RETRY)
  261. | AR5K_REG_SM(ah->ah_retry_short,
  262. AR5K_NODCU_RETRY_LMT_SH_RETRY),
  263. AR5K_NODCU_RETRY_LMT);
  264. /* DCU on AR5211+ */
  265. } else {
  266. ath5k_hw_reg_write(ah,
  267. AR5K_REG_SM(ah->ah_retry_long,
  268. AR5K_DCU_RETRY_LMT_RTS)
  269. | AR5K_REG_SM(ah->ah_retry_long,
  270. AR5K_DCU_RETRY_LMT_STA_RTS)
  271. | AR5K_REG_SM(max(ah->ah_retry_long, ah->ah_retry_short),
  272. AR5K_DCU_RETRY_LMT_STA_DATA),
  273. AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
  274. }
  275. }
  276. /**
  277. * ath5k_hw_reset_tx_queue() - Initialize a single hw queue
  278. * @ah: The &struct ath5k_hw
  279. * @queue: One of enum ath5k_tx_queue_id
  280. *
  281. * Set DCF properties for the given transmit queue on DCU
  282. * and configures all queue-specific parameters.
  283. */
  284. int
  285. ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
  286. {
  287. struct ath5k_txq_info *tq = &ah->ah_txq[queue];
  288. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  289. tq = &ah->ah_txq[queue];
  290. /* Skip if queue inactive or if we are on AR5210
  291. * that doesn't have QCU/DCU */
  292. if ((ah->ah_version == AR5K_AR5210) ||
  293. (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE))
  294. return 0;
  295. /*
  296. * Set contention window (cw_min/cw_max)
  297. * and arbitrated interframe space (aifs)...
  298. */
  299. ath5k_hw_reg_write(ah,
  300. AR5K_REG_SM(tq->tqi_cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
  301. AR5K_REG_SM(tq->tqi_cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
  302. AR5K_REG_SM(tq->tqi_aifs, AR5K_DCU_LCL_IFS_AIFS),
  303. AR5K_QUEUE_DFS_LOCAL_IFS(queue));
  304. /*
  305. * Set tx retry limits for this queue
  306. */
  307. ath5k_hw_set_tx_retry_limits(ah, queue);
  308. /*
  309. * Set misc registers
  310. */
  311. /* Enable DCU to wait for next fragment from QCU */
  312. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  313. AR5K_DCU_MISC_FRAG_WAIT);
  314. /* On Maui and Spirit use the global seqnum on DCU */
  315. if (ah->ah_mac_version < AR5K_SREV_AR5211)
  316. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  317. AR5K_DCU_MISC_SEQNUM_CTL);
  318. /* Constant bit rate period */
  319. if (tq->tqi_cbr_period) {
  320. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
  321. AR5K_QCU_CBRCFG_INTVAL) |
  322. AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
  323. AR5K_QCU_CBRCFG_ORN_THRES),
  324. AR5K_QUEUE_CBRCFG(queue));
  325. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  326. AR5K_QCU_MISC_FRSHED_CBR);
  327. if (tq->tqi_cbr_overflow_limit)
  328. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  329. AR5K_QCU_MISC_CBR_THRES_ENABLE);
  330. }
  331. /* Ready time interval */
  332. if (tq->tqi_ready_time && (tq->tqi_type != AR5K_TX_QUEUE_CAB))
  333. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
  334. AR5K_QCU_RDYTIMECFG_INTVAL) |
  335. AR5K_QCU_RDYTIMECFG_ENABLE,
  336. AR5K_QUEUE_RDYTIMECFG(queue));
  337. if (tq->tqi_burst_time) {
  338. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
  339. AR5K_DCU_CHAN_TIME_DUR) |
  340. AR5K_DCU_CHAN_TIME_ENABLE,
  341. AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
  342. if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
  343. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  344. AR5K_QCU_MISC_RDY_VEOL_POLICY);
  345. }
  346. /* Enable/disable Post frame backoff */
  347. if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
  348. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
  349. AR5K_QUEUE_DFS_MISC(queue));
  350. /* Enable/disable fragmentation burst backoff */
  351. if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
  352. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
  353. AR5K_QUEUE_DFS_MISC(queue));
  354. /*
  355. * Set registers by queue type
  356. */
  357. switch (tq->tqi_type) {
  358. case AR5K_TX_QUEUE_BEACON:
  359. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  360. AR5K_QCU_MISC_FRSHED_DBA_GT |
  361. AR5K_QCU_MISC_CBREXP_BCN_DIS |
  362. AR5K_QCU_MISC_BCN_ENABLE);
  363. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  364. (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
  365. AR5K_DCU_MISC_ARBLOCK_CTL_S) |
  366. AR5K_DCU_MISC_ARBLOCK_IGNORE |
  367. AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
  368. AR5K_DCU_MISC_BCN_ENABLE);
  369. break;
  370. case AR5K_TX_QUEUE_CAB:
  371. /* XXX: use BCN_SENT_GT, if we can figure out how */
  372. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  373. AR5K_QCU_MISC_FRSHED_DBA_GT |
  374. AR5K_QCU_MISC_CBREXP_DIS |
  375. AR5K_QCU_MISC_CBREXP_BCN_DIS);
  376. ath5k_hw_reg_write(ah, ((tq->tqi_ready_time -
  377. (AR5K_TUNE_SW_BEACON_RESP -
  378. AR5K_TUNE_DMA_BEACON_RESP) -
  379. AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
  380. AR5K_QCU_RDYTIMECFG_ENABLE,
  381. AR5K_QUEUE_RDYTIMECFG(queue));
  382. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  383. (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
  384. AR5K_DCU_MISC_ARBLOCK_CTL_S));
  385. break;
  386. case AR5K_TX_QUEUE_UAPSD:
  387. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  388. AR5K_QCU_MISC_CBREXP_DIS);
  389. break;
  390. case AR5K_TX_QUEUE_DATA:
  391. default:
  392. break;
  393. }
  394. /* TODO: Handle frame compression */
  395. /*
  396. * Enable interrupts for this tx queue
  397. * in the secondary interrupt mask registers
  398. */
  399. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
  400. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
  401. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
  402. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
  403. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
  404. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
  405. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
  406. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
  407. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
  408. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
  409. if (tq->tqi_flags & AR5K_TXQ_FLAG_CBRORNINT_ENABLE)
  410. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_cbrorn, queue);
  411. if (tq->tqi_flags & AR5K_TXQ_FLAG_CBRURNINT_ENABLE)
  412. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_cbrurn, queue);
  413. if (tq->tqi_flags & AR5K_TXQ_FLAG_QTRIGINT_ENABLE)
  414. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_qtrig, queue);
  415. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXNOFRMINT_ENABLE)
  416. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_nofrm, queue);
  417. /* Update secondary interrupt mask registers */
  418. /* Filter out inactive queues */
  419. ah->ah_txq_imr_txok &= ah->ah_txq_status;
  420. ah->ah_txq_imr_txerr &= ah->ah_txq_status;
  421. ah->ah_txq_imr_txurn &= ah->ah_txq_status;
  422. ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
  423. ah->ah_txq_imr_txeol &= ah->ah_txq_status;
  424. ah->ah_txq_imr_cbrorn &= ah->ah_txq_status;
  425. ah->ah_txq_imr_cbrurn &= ah->ah_txq_status;
  426. ah->ah_txq_imr_qtrig &= ah->ah_txq_status;
  427. ah->ah_txq_imr_nofrm &= ah->ah_txq_status;
  428. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
  429. AR5K_SIMR0_QCU_TXOK) |
  430. AR5K_REG_SM(ah->ah_txq_imr_txdesc,
  431. AR5K_SIMR0_QCU_TXDESC),
  432. AR5K_SIMR0);
  433. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
  434. AR5K_SIMR1_QCU_TXERR) |
  435. AR5K_REG_SM(ah->ah_txq_imr_txeol,
  436. AR5K_SIMR1_QCU_TXEOL),
  437. AR5K_SIMR1);
  438. /* Update SIMR2 but don't overwrite rest simr2 settings */
  439. AR5K_REG_DISABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_QCU_TXURN);
  440. AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2,
  441. AR5K_REG_SM(ah->ah_txq_imr_txurn,
  442. AR5K_SIMR2_QCU_TXURN));
  443. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_cbrorn,
  444. AR5K_SIMR3_QCBRORN) |
  445. AR5K_REG_SM(ah->ah_txq_imr_cbrurn,
  446. AR5K_SIMR3_QCBRURN),
  447. AR5K_SIMR3);
  448. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_qtrig,
  449. AR5K_SIMR4_QTRIG), AR5K_SIMR4);
  450. /* Set TXNOFRM_QCU for the queues with TXNOFRM enabled */
  451. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_nofrm,
  452. AR5K_TXNOFRM_QCU), AR5K_TXNOFRM);
  453. /* No queue has TXNOFRM enabled, disable the interrupt
  454. * by setting AR5K_TXNOFRM to zero */
  455. if (ah->ah_txq_imr_nofrm == 0)
  456. ath5k_hw_reg_write(ah, 0, AR5K_TXNOFRM);
  457. /* Set QCU mask for this DCU to save power */
  458. AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(queue), queue);
  459. return 0;
  460. }
  461. /**************************\
  462. * Global QCU/DCU functions *
  463. \**************************/
  464. /**
  465. * ath5k_hw_set_ifs_intervals() - Set global inter-frame spaces on DCU
  466. * @ah: The &struct ath5k_hw
  467. * @slot_time: Slot time in us
  468. *
  469. * Sets the global IFS intervals on DCU (also works on AR5210) for
  470. * the given slot time and the current bwmode.
  471. */
  472. int ath5k_hw_set_ifs_intervals(struct ath5k_hw *ah, unsigned int slot_time)
  473. {
  474. struct ieee80211_channel *channel = ah->ah_current_channel;
  475. enum ieee80211_band band;
  476. struct ieee80211_supported_band *sband;
  477. struct ieee80211_rate *rate;
  478. u32 ack_tx_time, eifs, eifs_clock, sifs, sifs_clock;
  479. u32 slot_time_clock = ath5k_hw_htoclock(ah, slot_time);
  480. u32 rate_flags, i;
  481. if (slot_time < 6 || slot_time_clock > AR5K_SLOT_TIME_MAX)
  482. return -EINVAL;
  483. sifs = ath5k_hw_get_default_sifs(ah);
  484. sifs_clock = ath5k_hw_htoclock(ah, sifs - 2);
  485. /* EIFS
  486. * Txtime of ack at lowest rate + SIFS + DIFS
  487. * (DIFS = SIFS + 2 * Slot time)
  488. *
  489. * Note: HAL has some predefined values for EIFS
  490. * Turbo: (37 + 2 * 6)
  491. * Default: (74 + 2 * 9)
  492. * Half: (149 + 2 * 13)
  493. * Quarter: (298 + 2 * 21)
  494. *
  495. * (74 + 2 * 6) for AR5210 default and turbo !
  496. *
  497. * According to the formula we have
  498. * ack_tx_time = 25 for turbo and
  499. * ack_tx_time = 42.5 * clock multiplier
  500. * for default/half/quarter.
  501. *
  502. * This can't be right, 42 is what we would get
  503. * from ath5k_hw_get_frame_dur_for_bwmode or
  504. * ieee80211_generic_frame_duration for zero frame
  505. * length and without SIFS !
  506. *
  507. * Also we have different lowest rate for 802.11a
  508. */
  509. if (channel->band == IEEE80211_BAND_5GHZ)
  510. band = IEEE80211_BAND_5GHZ;
  511. else
  512. band = IEEE80211_BAND_2GHZ;
  513. switch (ah->ah_bwmode) {
  514. case AR5K_BWMODE_5MHZ:
  515. rate_flags = IEEE80211_RATE_SUPPORTS_5MHZ;
  516. break;
  517. case AR5K_BWMODE_10MHZ:
  518. rate_flags = IEEE80211_RATE_SUPPORTS_10MHZ;
  519. break;
  520. default:
  521. rate_flags = 0;
  522. break;
  523. }
  524. sband = &ah->sbands[band];
  525. rate = NULL;
  526. for (i = 0; i < sband->n_bitrates; i++) {
  527. if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
  528. continue;
  529. rate = &sband->bitrates[i];
  530. break;
  531. }
  532. if (WARN_ON(!rate))
  533. return -EINVAL;
  534. ack_tx_time = ath5k_hw_get_frame_duration(ah, band, 10, rate, false);
  535. /* ack_tx_time includes an SIFS already */
  536. eifs = ack_tx_time + sifs + 2 * slot_time;
  537. eifs_clock = ath5k_hw_htoclock(ah, eifs);
  538. /* Set IFS settings on AR5210 */
  539. if (ah->ah_version == AR5K_AR5210) {
  540. u32 pifs, pifs_clock, difs, difs_clock;
  541. /* Set slot time */
  542. ath5k_hw_reg_write(ah, slot_time_clock, AR5K_SLOT_TIME);
  543. /* Set EIFS */
  544. eifs_clock = AR5K_REG_SM(eifs_clock, AR5K_IFS1_EIFS);
  545. /* PIFS = Slot time + SIFS */
  546. pifs = slot_time + sifs;
  547. pifs_clock = ath5k_hw_htoclock(ah, pifs);
  548. pifs_clock = AR5K_REG_SM(pifs_clock, AR5K_IFS1_PIFS);
  549. /* DIFS = SIFS + 2 * Slot time */
  550. difs = sifs + 2 * slot_time;
  551. difs_clock = ath5k_hw_htoclock(ah, difs);
  552. /* Set SIFS/DIFS */
  553. ath5k_hw_reg_write(ah, (difs_clock <<
  554. AR5K_IFS0_DIFS_S) | sifs_clock,
  555. AR5K_IFS0);
  556. /* Set PIFS/EIFS and preserve AR5K_INIT_CARR_SENSE_EN */
  557. ath5k_hw_reg_write(ah, pifs_clock | eifs_clock |
  558. (AR5K_INIT_CARR_SENSE_EN << AR5K_IFS1_CS_EN_S),
  559. AR5K_IFS1);
  560. return 0;
  561. }
  562. /* Set IFS slot time */
  563. ath5k_hw_reg_write(ah, slot_time_clock, AR5K_DCU_GBL_IFS_SLOT);
  564. /* Set EIFS interval */
  565. ath5k_hw_reg_write(ah, eifs_clock, AR5K_DCU_GBL_IFS_EIFS);
  566. /* Set SIFS interval in usecs */
  567. AR5K_REG_WRITE_BITS(ah, AR5K_DCU_GBL_IFS_MISC,
  568. AR5K_DCU_GBL_IFS_MISC_SIFS_DUR_USEC,
  569. sifs);
  570. /* Set SIFS interval in clock cycles */
  571. ath5k_hw_reg_write(ah, sifs_clock, AR5K_DCU_GBL_IFS_SIFS);
  572. return 0;
  573. }
  574. /**
  575. * ath5k_hw_init_queues() - Initialize tx queues
  576. * @ah: The &struct ath5k_hw
  577. *
  578. * Initializes all tx queues based on information on
  579. * ah->ah_txq* set by the driver
  580. */
  581. int
  582. ath5k_hw_init_queues(struct ath5k_hw *ah)
  583. {
  584. int i, ret;
  585. /* TODO: HW Compression support for data queues */
  586. /* TODO: Burst prefetch for data queues */
  587. /*
  588. * Reset queues and start beacon timers at the end of the reset routine
  589. * This also sets QCU mask on each DCU for 1:1 qcu to dcu mapping
  590. * Note: If we want we can assign multiple qcus on one dcu.
  591. */
  592. if (ah->ah_version != AR5K_AR5210)
  593. for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
  594. ret = ath5k_hw_reset_tx_queue(ah, i);
  595. if (ret) {
  596. ATH5K_ERR(ah,
  597. "failed to reset TX queue #%d\n", i);
  598. return ret;
  599. }
  600. }
  601. else
  602. /* No QCU/DCU on AR5210, just set tx
  603. * retry limits. We set IFS parameters
  604. * on ath5k_hw_set_ifs_intervals */
  605. ath5k_hw_set_tx_retry_limits(ah, 0);
  606. /* Set the turbo flag when operating on 40MHz */
  607. if (ah->ah_bwmode == AR5K_BWMODE_40MHZ)
  608. AR5K_REG_ENABLE_BITS(ah, AR5K_DCU_GBL_IFS_MISC,
  609. AR5K_DCU_GBL_IFS_MISC_TURBO_MODE);
  610. /* If we didn't set IFS timings through
  611. * ath5k_hw_set_coverage_class make sure
  612. * we set them here */
  613. if (!ah->ah_coverage_class) {
  614. unsigned int slot_time = ath5k_hw_get_default_slottime(ah);
  615. ath5k_hw_set_ifs_intervals(ah, slot_time);
  616. }
  617. return 0;
  618. }