mac.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "hw.h"
  17. #include "hw-ops.h"
  18. #include <linux/export.h>
  19. static void ath9k_hw_set_txq_interrupts(struct ath_hw *ah,
  20. struct ath9k_tx_queue_info *qi)
  21. {
  22. ath_dbg(ath9k_hw_common(ah), INTERRUPT,
  23. "tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
  24. ah->txok_interrupt_mask, ah->txerr_interrupt_mask,
  25. ah->txdesc_interrupt_mask, ah->txeol_interrupt_mask,
  26. ah->txurn_interrupt_mask);
  27. ENABLE_REGWRITE_BUFFER(ah);
  28. REG_WRITE(ah, AR_IMR_S0,
  29. SM(ah->txok_interrupt_mask, AR_IMR_S0_QCU_TXOK)
  30. | SM(ah->txdesc_interrupt_mask, AR_IMR_S0_QCU_TXDESC));
  31. REG_WRITE(ah, AR_IMR_S1,
  32. SM(ah->txerr_interrupt_mask, AR_IMR_S1_QCU_TXERR)
  33. | SM(ah->txeol_interrupt_mask, AR_IMR_S1_QCU_TXEOL));
  34. ah->imrs2_reg &= ~AR_IMR_S2_QCU_TXURN;
  35. ah->imrs2_reg |= (ah->txurn_interrupt_mask & AR_IMR_S2_QCU_TXURN);
  36. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  37. REGWRITE_BUFFER_FLUSH(ah);
  38. }
  39. u32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q)
  40. {
  41. return REG_READ(ah, AR_QTXDP(q));
  42. }
  43. EXPORT_SYMBOL(ath9k_hw_gettxbuf);
  44. void ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp)
  45. {
  46. REG_WRITE(ah, AR_QTXDP(q), txdp);
  47. }
  48. EXPORT_SYMBOL(ath9k_hw_puttxbuf);
  49. void ath9k_hw_txstart(struct ath_hw *ah, u32 q)
  50. {
  51. ath_dbg(ath9k_hw_common(ah), QUEUE, "Enable TXE on queue: %u\n", q);
  52. REG_WRITE(ah, AR_Q_TXE, 1 << q);
  53. }
  54. EXPORT_SYMBOL(ath9k_hw_txstart);
  55. u32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q)
  56. {
  57. u32 npend;
  58. npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
  59. if (npend == 0) {
  60. if (REG_READ(ah, AR_Q_TXE) & (1 << q))
  61. npend = 1;
  62. }
  63. return npend;
  64. }
  65. EXPORT_SYMBOL(ath9k_hw_numtxpending);
  66. /**
  67. * ath9k_hw_updatetxtriglevel - adjusts the frame trigger level
  68. *
  69. * @ah: atheros hardware struct
  70. * @bIncTrigLevel: whether or not the frame trigger level should be updated
  71. *
  72. * The frame trigger level specifies the minimum number of bytes,
  73. * in units of 64 bytes, that must be DMA'ed into the PCU TX FIFO
  74. * before the PCU will initiate sending the frame on the air. This can
  75. * mean we initiate transmit before a full frame is on the PCU TX FIFO.
  76. * Resets to 0x1 (meaning 64 bytes or a full frame, whichever occurs
  77. * first)
  78. *
  79. * Caution must be taken to ensure to set the frame trigger level based
  80. * on the DMA request size. For example if the DMA request size is set to
  81. * 128 bytes the trigger level cannot exceed 6 * 64 = 384. This is because
  82. * there need to be enough space in the tx FIFO for the requested transfer
  83. * size. Hence the tx FIFO will stop with 512 - 128 = 384 bytes. If we set
  84. * the threshold to a value beyond 6, then the transmit will hang.
  85. *
  86. * Current dual stream devices have a PCU TX FIFO size of 8 KB.
  87. * Current single stream devices have a PCU TX FIFO size of 4 KB, however,
  88. * there is a hardware issue which forces us to use 2 KB instead so the
  89. * frame trigger level must not exceed 2 KB for these chipsets.
  90. */
  91. bool ath9k_hw_updatetxtriglevel(struct ath_hw *ah, bool bIncTrigLevel)
  92. {
  93. u32 txcfg, curLevel, newLevel;
  94. if (ah->tx_trig_level >= ah->config.max_txtrig_level)
  95. return false;
  96. ath9k_hw_disable_interrupts(ah);
  97. txcfg = REG_READ(ah, AR_TXCFG);
  98. curLevel = MS(txcfg, AR_FTRIG);
  99. newLevel = curLevel;
  100. if (bIncTrigLevel) {
  101. if (curLevel < ah->config.max_txtrig_level)
  102. newLevel++;
  103. } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
  104. newLevel--;
  105. if (newLevel != curLevel)
  106. REG_WRITE(ah, AR_TXCFG,
  107. (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
  108. ath9k_hw_enable_interrupts(ah);
  109. ah->tx_trig_level = newLevel;
  110. return newLevel != curLevel;
  111. }
  112. EXPORT_SYMBOL(ath9k_hw_updatetxtriglevel);
  113. void ath9k_hw_abort_tx_dma(struct ath_hw *ah)
  114. {
  115. int i, q;
  116. REG_WRITE(ah, AR_Q_TXD, AR_Q_TXD_M);
  117. REG_SET_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF);
  118. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
  119. REG_SET_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
  120. for (q = 0; q < AR_NUM_QCU; q++) {
  121. for (i = 0; i < 1000; i++) {
  122. if (i)
  123. udelay(5);
  124. if (!ath9k_hw_numtxpending(ah, q))
  125. break;
  126. }
  127. }
  128. REG_CLR_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF);
  129. REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
  130. REG_CLR_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
  131. REG_WRITE(ah, AR_Q_TXD, 0);
  132. }
  133. EXPORT_SYMBOL(ath9k_hw_abort_tx_dma);
  134. bool ath9k_hw_stop_dma_queue(struct ath_hw *ah, u32 q)
  135. {
  136. #define ATH9K_TX_STOP_DMA_TIMEOUT 1000 /* usec */
  137. #define ATH9K_TIME_QUANTUM 100 /* usec */
  138. int wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
  139. int wait;
  140. REG_WRITE(ah, AR_Q_TXD, 1 << q);
  141. for (wait = wait_time; wait != 0; wait--) {
  142. if (wait != wait_time)
  143. udelay(ATH9K_TIME_QUANTUM);
  144. if (ath9k_hw_numtxpending(ah, q) == 0)
  145. break;
  146. }
  147. REG_WRITE(ah, AR_Q_TXD, 0);
  148. return wait != 0;
  149. #undef ATH9K_TX_STOP_DMA_TIMEOUT
  150. #undef ATH9K_TIME_QUANTUM
  151. }
  152. EXPORT_SYMBOL(ath9k_hw_stop_dma_queue);
  153. void ath9k_hw_gettxintrtxqs(struct ath_hw *ah, u32 *txqs)
  154. {
  155. *txqs &= ah->intr_txqs;
  156. ah->intr_txqs &= ~(*txqs);
  157. }
  158. EXPORT_SYMBOL(ath9k_hw_gettxintrtxqs);
  159. bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
  160. const struct ath9k_tx_queue_info *qinfo)
  161. {
  162. u32 cw;
  163. struct ath_common *common = ath9k_hw_common(ah);
  164. struct ath9k_tx_queue_info *qi;
  165. qi = &ah->txq[q];
  166. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  167. ath_dbg(common, QUEUE,
  168. "Set TXQ properties, inactive queue: %u\n", q);
  169. return false;
  170. }
  171. ath_dbg(common, QUEUE, "Set queue properties for: %u\n", q);
  172. qi->tqi_ver = qinfo->tqi_ver;
  173. qi->tqi_subtype = qinfo->tqi_subtype;
  174. qi->tqi_qflags = qinfo->tqi_qflags;
  175. qi->tqi_priority = qinfo->tqi_priority;
  176. if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
  177. qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
  178. else
  179. qi->tqi_aifs = INIT_AIFS;
  180. if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
  181. cw = min(qinfo->tqi_cwmin, 1024U);
  182. qi->tqi_cwmin = 1;
  183. while (qi->tqi_cwmin < cw)
  184. qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
  185. } else
  186. qi->tqi_cwmin = qinfo->tqi_cwmin;
  187. if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
  188. cw = min(qinfo->tqi_cwmax, 1024U);
  189. qi->tqi_cwmax = 1;
  190. while (qi->tqi_cwmax < cw)
  191. qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
  192. } else
  193. qi->tqi_cwmax = INIT_CWMAX;
  194. if (qinfo->tqi_shretry != 0)
  195. qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
  196. else
  197. qi->tqi_shretry = INIT_SH_RETRY;
  198. if (qinfo->tqi_lgretry != 0)
  199. qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
  200. else
  201. qi->tqi_lgretry = INIT_LG_RETRY;
  202. qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
  203. qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
  204. qi->tqi_burstTime = qinfo->tqi_burstTime;
  205. qi->tqi_readyTime = qinfo->tqi_readyTime;
  206. switch (qinfo->tqi_subtype) {
  207. case ATH9K_WME_UPSD:
  208. if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
  209. qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
  210. break;
  211. default:
  212. break;
  213. }
  214. return true;
  215. }
  216. EXPORT_SYMBOL(ath9k_hw_set_txq_props);
  217. bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
  218. struct ath9k_tx_queue_info *qinfo)
  219. {
  220. struct ath_common *common = ath9k_hw_common(ah);
  221. struct ath9k_tx_queue_info *qi;
  222. qi = &ah->txq[q];
  223. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  224. ath_dbg(common, QUEUE,
  225. "Get TXQ properties, inactive queue: %u\n", q);
  226. return false;
  227. }
  228. qinfo->tqi_qflags = qi->tqi_qflags;
  229. qinfo->tqi_ver = qi->tqi_ver;
  230. qinfo->tqi_subtype = qi->tqi_subtype;
  231. qinfo->tqi_qflags = qi->tqi_qflags;
  232. qinfo->tqi_priority = qi->tqi_priority;
  233. qinfo->tqi_aifs = qi->tqi_aifs;
  234. qinfo->tqi_cwmin = qi->tqi_cwmin;
  235. qinfo->tqi_cwmax = qi->tqi_cwmax;
  236. qinfo->tqi_shretry = qi->tqi_shretry;
  237. qinfo->tqi_lgretry = qi->tqi_lgretry;
  238. qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
  239. qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
  240. qinfo->tqi_burstTime = qi->tqi_burstTime;
  241. qinfo->tqi_readyTime = qi->tqi_readyTime;
  242. return true;
  243. }
  244. EXPORT_SYMBOL(ath9k_hw_get_txq_props);
  245. int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
  246. const struct ath9k_tx_queue_info *qinfo)
  247. {
  248. struct ath_common *common = ath9k_hw_common(ah);
  249. struct ath9k_tx_queue_info *qi;
  250. int q;
  251. switch (type) {
  252. case ATH9K_TX_QUEUE_BEACON:
  253. q = ATH9K_NUM_TX_QUEUES - 1;
  254. break;
  255. case ATH9K_TX_QUEUE_CAB:
  256. q = ATH9K_NUM_TX_QUEUES - 2;
  257. break;
  258. case ATH9K_TX_QUEUE_PSPOLL:
  259. q = 1;
  260. break;
  261. case ATH9K_TX_QUEUE_UAPSD:
  262. q = ATH9K_NUM_TX_QUEUES - 3;
  263. break;
  264. case ATH9K_TX_QUEUE_DATA:
  265. for (q = 0; q < ATH9K_NUM_TX_QUEUES; q++)
  266. if (ah->txq[q].tqi_type ==
  267. ATH9K_TX_QUEUE_INACTIVE)
  268. break;
  269. if (q == ATH9K_NUM_TX_QUEUES) {
  270. ath_err(common, "No available TX queue\n");
  271. return -1;
  272. }
  273. break;
  274. default:
  275. ath_err(common, "Invalid TX queue type: %u\n", type);
  276. return -1;
  277. }
  278. ath_dbg(common, QUEUE, "Setup TX queue: %u\n", q);
  279. qi = &ah->txq[q];
  280. if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
  281. ath_err(common, "TX queue: %u already active\n", q);
  282. return -1;
  283. }
  284. memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
  285. qi->tqi_type = type;
  286. qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
  287. (void) ath9k_hw_set_txq_props(ah, q, qinfo);
  288. return q;
  289. }
  290. EXPORT_SYMBOL(ath9k_hw_setuptxqueue);
  291. bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
  292. {
  293. struct ath_common *common = ath9k_hw_common(ah);
  294. struct ath9k_tx_queue_info *qi;
  295. qi = &ah->txq[q];
  296. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  297. ath_dbg(common, QUEUE, "Release TXQ, inactive queue: %u\n", q);
  298. return false;
  299. }
  300. ath_dbg(common, QUEUE, "Release TX queue: %u\n", q);
  301. qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
  302. ah->txok_interrupt_mask &= ~(1 << q);
  303. ah->txerr_interrupt_mask &= ~(1 << q);
  304. ah->txdesc_interrupt_mask &= ~(1 << q);
  305. ah->txeol_interrupt_mask &= ~(1 << q);
  306. ah->txurn_interrupt_mask &= ~(1 << q);
  307. ath9k_hw_set_txq_interrupts(ah, qi);
  308. return true;
  309. }
  310. EXPORT_SYMBOL(ath9k_hw_releasetxqueue);
  311. bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
  312. {
  313. struct ath_common *common = ath9k_hw_common(ah);
  314. struct ath9k_channel *chan = ah->curchan;
  315. struct ath9k_tx_queue_info *qi;
  316. u32 cwMin, chanCwMin, value;
  317. qi = &ah->txq[q];
  318. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  319. ath_dbg(common, QUEUE, "Reset TXQ, inactive queue: %u\n", q);
  320. return true;
  321. }
  322. ath_dbg(common, QUEUE, "Reset TX queue: %u\n", q);
  323. if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
  324. if (chan && IS_CHAN_B(chan))
  325. chanCwMin = INIT_CWMIN_11B;
  326. else
  327. chanCwMin = INIT_CWMIN;
  328. for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
  329. } else
  330. cwMin = qi->tqi_cwmin;
  331. ENABLE_REGWRITE_BUFFER(ah);
  332. REG_WRITE(ah, AR_DLCL_IFS(q),
  333. SM(cwMin, AR_D_LCL_IFS_CWMIN) |
  334. SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
  335. SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
  336. REG_WRITE(ah, AR_DRETRY_LIMIT(q),
  337. SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
  338. SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
  339. SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
  340. REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
  341. if (AR_SREV_9340(ah))
  342. REG_WRITE(ah, AR_DMISC(q),
  343. AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x1);
  344. else
  345. REG_WRITE(ah, AR_DMISC(q),
  346. AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
  347. if (qi->tqi_cbrPeriod) {
  348. REG_WRITE(ah, AR_QCBRCFG(q),
  349. SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
  350. SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
  351. REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_FSP_CBR |
  352. (qi->tqi_cbrOverflowLimit ?
  353. AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
  354. }
  355. if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
  356. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  357. SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
  358. AR_Q_RDYTIMECFG_EN);
  359. }
  360. REG_WRITE(ah, AR_DCHNTIME(q),
  361. SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
  362. (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
  363. if (qi->tqi_burstTime
  364. && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE))
  365. REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_RDYTIME_EXP_POLICY);
  366. if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE)
  367. REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_POST_FR_BKOFF_DIS);
  368. REGWRITE_BUFFER_FLUSH(ah);
  369. if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
  370. REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_FRAG_BKOFF_EN);
  371. switch (qi->tqi_type) {
  372. case ATH9K_TX_QUEUE_BEACON:
  373. ENABLE_REGWRITE_BUFFER(ah);
  374. REG_SET_BIT(ah, AR_QMISC(q),
  375. AR_Q_MISC_FSP_DBA_GATED
  376. | AR_Q_MISC_BEACON_USE
  377. | AR_Q_MISC_CBR_INCR_DIS1);
  378. REG_SET_BIT(ah, AR_DMISC(q),
  379. (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  380. AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
  381. | AR_D_MISC_BEACON_USE
  382. | AR_D_MISC_POST_FR_BKOFF_DIS);
  383. REGWRITE_BUFFER_FLUSH(ah);
  384. /*
  385. * cwmin and cwmax should be 0 for beacon queue
  386. * but not for IBSS as we would create an imbalance
  387. * on beaconing fairness for participating nodes.
  388. */
  389. if (AR_SREV_9300_20_OR_LATER(ah) &&
  390. ah->opmode != NL80211_IFTYPE_ADHOC) {
  391. REG_WRITE(ah, AR_DLCL_IFS(q), SM(0, AR_D_LCL_IFS_CWMIN)
  392. | SM(0, AR_D_LCL_IFS_CWMAX)
  393. | SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
  394. }
  395. break;
  396. case ATH9K_TX_QUEUE_CAB:
  397. ENABLE_REGWRITE_BUFFER(ah);
  398. REG_SET_BIT(ah, AR_QMISC(q),
  399. AR_Q_MISC_FSP_DBA_GATED
  400. | AR_Q_MISC_CBR_INCR_DIS1
  401. | AR_Q_MISC_CBR_INCR_DIS0);
  402. value = (qi->tqi_readyTime -
  403. (ah->config.sw_beacon_response_time -
  404. ah->config.dma_beacon_response_time) -
  405. ah->config.additional_swba_backoff) * 1024;
  406. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  407. value | AR_Q_RDYTIMECFG_EN);
  408. REG_SET_BIT(ah, AR_DMISC(q),
  409. (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  410. AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
  411. REGWRITE_BUFFER_FLUSH(ah);
  412. break;
  413. case ATH9K_TX_QUEUE_PSPOLL:
  414. REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_CBR_INCR_DIS1);
  415. break;
  416. case ATH9K_TX_QUEUE_UAPSD:
  417. REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_POST_FR_BKOFF_DIS);
  418. break;
  419. default:
  420. break;
  421. }
  422. if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
  423. REG_SET_BIT(ah, AR_DMISC(q),
  424. SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
  425. AR_D_MISC_ARB_LOCKOUT_CNTRL) |
  426. AR_D_MISC_POST_FR_BKOFF_DIS);
  427. }
  428. if (AR_SREV_9300_20_OR_LATER(ah))
  429. REG_WRITE(ah, AR_Q_DESC_CRCCHK, AR_Q_DESC_CRCCHK_EN);
  430. if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
  431. ah->txok_interrupt_mask |= 1 << q;
  432. else
  433. ah->txok_interrupt_mask &= ~(1 << q);
  434. if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
  435. ah->txerr_interrupt_mask |= 1 << q;
  436. else
  437. ah->txerr_interrupt_mask &= ~(1 << q);
  438. if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
  439. ah->txdesc_interrupt_mask |= 1 << q;
  440. else
  441. ah->txdesc_interrupt_mask &= ~(1 << q);
  442. if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
  443. ah->txeol_interrupt_mask |= 1 << q;
  444. else
  445. ah->txeol_interrupt_mask &= ~(1 << q);
  446. if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
  447. ah->txurn_interrupt_mask |= 1 << q;
  448. else
  449. ah->txurn_interrupt_mask &= ~(1 << q);
  450. ath9k_hw_set_txq_interrupts(ah, qi);
  451. return true;
  452. }
  453. EXPORT_SYMBOL(ath9k_hw_resettxqueue);
  454. int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
  455. struct ath_rx_status *rs)
  456. {
  457. struct ar5416_desc ads;
  458. struct ar5416_desc *adsp = AR5416DESC(ds);
  459. u32 phyerr;
  460. if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
  461. return -EINPROGRESS;
  462. ads.u.rx = adsp->u.rx;
  463. rs->rs_status = 0;
  464. rs->rs_flags = 0;
  465. rs->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
  466. rs->rs_tstamp = ads.AR_RcvTimestamp;
  467. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) {
  468. rs->rs_rssi = ATH9K_RSSI_BAD;
  469. rs->rs_rssi_ctl0 = ATH9K_RSSI_BAD;
  470. rs->rs_rssi_ctl1 = ATH9K_RSSI_BAD;
  471. rs->rs_rssi_ctl2 = ATH9K_RSSI_BAD;
  472. rs->rs_rssi_ext0 = ATH9K_RSSI_BAD;
  473. rs->rs_rssi_ext1 = ATH9K_RSSI_BAD;
  474. rs->rs_rssi_ext2 = ATH9K_RSSI_BAD;
  475. } else {
  476. rs->rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
  477. rs->rs_rssi_ctl0 = MS(ads.ds_rxstatus0,
  478. AR_RxRSSIAnt00);
  479. rs->rs_rssi_ctl1 = MS(ads.ds_rxstatus0,
  480. AR_RxRSSIAnt01);
  481. rs->rs_rssi_ctl2 = MS(ads.ds_rxstatus0,
  482. AR_RxRSSIAnt02);
  483. rs->rs_rssi_ext0 = MS(ads.ds_rxstatus4,
  484. AR_RxRSSIAnt10);
  485. rs->rs_rssi_ext1 = MS(ads.ds_rxstatus4,
  486. AR_RxRSSIAnt11);
  487. rs->rs_rssi_ext2 = MS(ads.ds_rxstatus4,
  488. AR_RxRSSIAnt12);
  489. }
  490. if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
  491. rs->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
  492. else
  493. rs->rs_keyix = ATH9K_RXKEYIX_INVALID;
  494. rs->rs_rate = MS(ads.ds_rxstatus0, AR_RxRate);
  495. rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
  496. rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
  497. rs->rs_moreaggr =
  498. (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
  499. rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
  500. rs->rs_flags =
  501. (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
  502. rs->rs_flags |=
  503. (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
  504. if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
  505. rs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
  506. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
  507. rs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
  508. if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
  509. rs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
  510. if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
  511. /*
  512. * Treat these errors as mutually exclusive to avoid spurious
  513. * extra error reports from the hardware. If a CRC error is
  514. * reported, then decryption and MIC errors are irrelevant,
  515. * the frame is going to be dropped either way
  516. */
  517. if (ads.ds_rxstatus8 & AR_CRCErr)
  518. rs->rs_status |= ATH9K_RXERR_CRC;
  519. else if (ads.ds_rxstatus8 & AR_PHYErr) {
  520. rs->rs_status |= ATH9K_RXERR_PHY;
  521. phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
  522. rs->rs_phyerr = phyerr;
  523. } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
  524. rs->rs_status |= ATH9K_RXERR_DECRYPT;
  525. else if (ads.ds_rxstatus8 & AR_MichaelErr)
  526. rs->rs_status |= ATH9K_RXERR_MIC;
  527. }
  528. if (ads.ds_rxstatus8 & AR_KeyMiss)
  529. rs->rs_status |= ATH9K_RXERR_KEYMISS;
  530. return 0;
  531. }
  532. EXPORT_SYMBOL(ath9k_hw_rxprocdesc);
  533. /*
  534. * This can stop or re-enables RX.
  535. *
  536. * If bool is set this will kill any frame which is currently being
  537. * transferred between the MAC and baseband and also prevent any new
  538. * frames from getting started.
  539. */
  540. bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
  541. {
  542. u32 reg;
  543. if (set) {
  544. REG_SET_BIT(ah, AR_DIAG_SW,
  545. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  546. if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
  547. 0, AH_WAIT_TIMEOUT)) {
  548. REG_CLR_BIT(ah, AR_DIAG_SW,
  549. (AR_DIAG_RX_DIS |
  550. AR_DIAG_RX_ABORT));
  551. reg = REG_READ(ah, AR_OBS_BUS_1);
  552. ath_err(ath9k_hw_common(ah),
  553. "RX failed to go idle in 10 ms RXSM=0x%x\n",
  554. reg);
  555. return false;
  556. }
  557. } else {
  558. REG_CLR_BIT(ah, AR_DIAG_SW,
  559. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  560. }
  561. return true;
  562. }
  563. EXPORT_SYMBOL(ath9k_hw_setrxabort);
  564. void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
  565. {
  566. REG_WRITE(ah, AR_RXDP, rxdp);
  567. }
  568. EXPORT_SYMBOL(ath9k_hw_putrxbuf);
  569. void ath9k_hw_startpcureceive(struct ath_hw *ah, bool is_scanning)
  570. {
  571. ath9k_enable_mib_counters(ah);
  572. ath9k_ani_reset(ah, is_scanning);
  573. REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  574. }
  575. EXPORT_SYMBOL(ath9k_hw_startpcureceive);
  576. void ath9k_hw_abortpcurecv(struct ath_hw *ah)
  577. {
  578. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_ABORT | AR_DIAG_RX_DIS);
  579. ath9k_hw_disable_mib_counters(ah);
  580. }
  581. EXPORT_SYMBOL(ath9k_hw_abortpcurecv);
  582. bool ath9k_hw_stopdmarecv(struct ath_hw *ah, bool *reset)
  583. {
  584. #define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
  585. struct ath_common *common = ath9k_hw_common(ah);
  586. u32 mac_status, last_mac_status = 0;
  587. int i;
  588. /* Enable access to the DMA observation bus */
  589. REG_WRITE(ah, AR_MACMISC,
  590. ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
  591. (AR_MACMISC_MISC_OBS_BUS_1 <<
  592. AR_MACMISC_MISC_OBS_BUS_MSB_S)));
  593. REG_WRITE(ah, AR_CR, AR_CR_RXD);
  594. /* Wait for rx enable bit to go low */
  595. for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
  596. if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
  597. break;
  598. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  599. mac_status = REG_READ(ah, AR_DMADBG_7) & 0x7f0;
  600. if (mac_status == 0x1c0 && mac_status == last_mac_status) {
  601. *reset = true;
  602. break;
  603. }
  604. last_mac_status = mac_status;
  605. }
  606. udelay(AH_TIME_QUANTUM);
  607. }
  608. if (i == 0) {
  609. ath_err(common,
  610. "DMA failed to stop in %d ms AR_CR=0x%08x AR_DIAG_SW=0x%08x DMADBG_7=0x%08x\n",
  611. AH_RX_STOP_DMA_TIMEOUT / 1000,
  612. REG_READ(ah, AR_CR),
  613. REG_READ(ah, AR_DIAG_SW),
  614. REG_READ(ah, AR_DMADBG_7));
  615. return false;
  616. } else {
  617. return true;
  618. }
  619. #undef AH_RX_STOP_DMA_TIMEOUT
  620. }
  621. EXPORT_SYMBOL(ath9k_hw_stopdmarecv);
  622. int ath9k_hw_beaconq_setup(struct ath_hw *ah)
  623. {
  624. struct ath9k_tx_queue_info qi;
  625. memset(&qi, 0, sizeof(qi));
  626. qi.tqi_aifs = 1;
  627. qi.tqi_cwmin = 0;
  628. qi.tqi_cwmax = 0;
  629. /* NB: don't enable any interrupts */
  630. return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
  631. }
  632. EXPORT_SYMBOL(ath9k_hw_beaconq_setup);
  633. bool ath9k_hw_intrpend(struct ath_hw *ah)
  634. {
  635. u32 host_isr;
  636. if (AR_SREV_9100(ah))
  637. return true;
  638. host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
  639. if (((host_isr & AR_INTR_MAC_IRQ) ||
  640. (host_isr & AR_INTR_ASYNC_MASK_MCI)) &&
  641. (host_isr != AR_INTR_SPURIOUS))
  642. return true;
  643. host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  644. if ((host_isr & AR_INTR_SYNC_DEFAULT)
  645. && (host_isr != AR_INTR_SPURIOUS))
  646. return true;
  647. return false;
  648. }
  649. EXPORT_SYMBOL(ath9k_hw_intrpend);
  650. void ath9k_hw_disable_interrupts(struct ath_hw *ah)
  651. {
  652. struct ath_common *common = ath9k_hw_common(ah);
  653. if (!(ah->imask & ATH9K_INT_GLOBAL))
  654. atomic_set(&ah->intr_ref_cnt, -1);
  655. else
  656. atomic_dec(&ah->intr_ref_cnt);
  657. ath_dbg(common, INTERRUPT, "disable IER\n");
  658. REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
  659. (void) REG_READ(ah, AR_IER);
  660. if (!AR_SREV_9100(ah)) {
  661. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
  662. (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
  663. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  664. (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
  665. }
  666. }
  667. EXPORT_SYMBOL(ath9k_hw_disable_interrupts);
  668. void ath9k_hw_enable_interrupts(struct ath_hw *ah)
  669. {
  670. struct ath_common *common = ath9k_hw_common(ah);
  671. u32 sync_default = AR_INTR_SYNC_DEFAULT;
  672. u32 async_mask;
  673. if (!(ah->imask & ATH9K_INT_GLOBAL))
  674. return;
  675. if (!atomic_inc_and_test(&ah->intr_ref_cnt)) {
  676. ath_dbg(common, INTERRUPT, "Do not enable IER ref count %d\n",
  677. atomic_read(&ah->intr_ref_cnt));
  678. return;
  679. }
  680. if (AR_SREV_9340(ah))
  681. sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
  682. async_mask = AR_INTR_MAC_IRQ;
  683. if (ah->imask & ATH9K_INT_MCI)
  684. async_mask |= AR_INTR_ASYNC_MASK_MCI;
  685. ath_dbg(common, INTERRUPT, "enable IER\n");
  686. REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
  687. if (!AR_SREV_9100(ah)) {
  688. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, async_mask);
  689. REG_WRITE(ah, AR_INTR_ASYNC_MASK, async_mask);
  690. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
  691. REG_WRITE(ah, AR_INTR_SYNC_MASK, sync_default);
  692. }
  693. ath_dbg(common, INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
  694. REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
  695. }
  696. EXPORT_SYMBOL(ath9k_hw_enable_interrupts);
  697. void ath9k_hw_set_interrupts(struct ath_hw *ah)
  698. {
  699. enum ath9k_int ints = ah->imask;
  700. u32 mask, mask2;
  701. struct ath9k_hw_capabilities *pCap = &ah->caps;
  702. struct ath_common *common = ath9k_hw_common(ah);
  703. if (!(ints & ATH9K_INT_GLOBAL))
  704. ath9k_hw_disable_interrupts(ah);
  705. ath_dbg(common, INTERRUPT, "New interrupt mask 0x%x\n", ints);
  706. mask = ints & ATH9K_INT_COMMON;
  707. mask2 = 0;
  708. if (ints & ATH9K_INT_TX) {
  709. if (ah->config.tx_intr_mitigation)
  710. mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM;
  711. else {
  712. if (ah->txok_interrupt_mask)
  713. mask |= AR_IMR_TXOK;
  714. if (ah->txdesc_interrupt_mask)
  715. mask |= AR_IMR_TXDESC;
  716. }
  717. if (ah->txerr_interrupt_mask)
  718. mask |= AR_IMR_TXERR;
  719. if (ah->txeol_interrupt_mask)
  720. mask |= AR_IMR_TXEOL;
  721. }
  722. if (ints & ATH9K_INT_RX) {
  723. if (AR_SREV_9300_20_OR_LATER(ah)) {
  724. mask |= AR_IMR_RXERR | AR_IMR_RXOK_HP;
  725. if (ah->config.rx_intr_mitigation) {
  726. mask &= ~AR_IMR_RXOK_LP;
  727. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  728. } else {
  729. mask |= AR_IMR_RXOK_LP;
  730. }
  731. } else {
  732. if (ah->config.rx_intr_mitigation)
  733. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  734. else
  735. mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
  736. }
  737. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  738. mask |= AR_IMR_GENTMR;
  739. }
  740. if (ints & ATH9K_INT_GENTIMER)
  741. mask |= AR_IMR_GENTMR;
  742. if (ints & (ATH9K_INT_BMISC)) {
  743. mask |= AR_IMR_BCNMISC;
  744. if (ints & ATH9K_INT_TIM)
  745. mask2 |= AR_IMR_S2_TIM;
  746. if (ints & ATH9K_INT_DTIM)
  747. mask2 |= AR_IMR_S2_DTIM;
  748. if (ints & ATH9K_INT_DTIMSYNC)
  749. mask2 |= AR_IMR_S2_DTIMSYNC;
  750. if (ints & ATH9K_INT_CABEND)
  751. mask2 |= AR_IMR_S2_CABEND;
  752. if (ints & ATH9K_INT_TSFOOR)
  753. mask2 |= AR_IMR_S2_TSFOOR;
  754. }
  755. if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
  756. mask |= AR_IMR_BCNMISC;
  757. if (ints & ATH9K_INT_GTT)
  758. mask2 |= AR_IMR_S2_GTT;
  759. if (ints & ATH9K_INT_CST)
  760. mask2 |= AR_IMR_S2_CST;
  761. }
  762. ath_dbg(common, INTERRUPT, "new IMR 0x%x\n", mask);
  763. REG_WRITE(ah, AR_IMR, mask);
  764. ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
  765. AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
  766. AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
  767. ah->imrs2_reg |= mask2;
  768. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  769. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  770. if (ints & ATH9K_INT_TIM_TIMER)
  771. REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  772. else
  773. REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  774. }
  775. return;
  776. }
  777. EXPORT_SYMBOL(ath9k_hw_set_interrupts);