mac.c 25 KB

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