mac.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  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 maxdelay = 1000;
  116. int i, q;
  117. if (ah->curchan) {
  118. if (IS_CHAN_HALF_RATE(ah->curchan))
  119. maxdelay *= 2;
  120. else if (IS_CHAN_QUARTER_RATE(ah->curchan))
  121. maxdelay *= 4;
  122. }
  123. REG_WRITE(ah, AR_Q_TXD, AR_Q_TXD_M);
  124. REG_SET_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF);
  125. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
  126. REG_SET_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
  127. for (q = 0; q < AR_NUM_QCU; q++) {
  128. for (i = 0; i < maxdelay; i++) {
  129. if (i)
  130. udelay(5);
  131. if (!ath9k_hw_numtxpending(ah, q))
  132. break;
  133. }
  134. }
  135. REG_CLR_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF);
  136. REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
  137. REG_CLR_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
  138. REG_WRITE(ah, AR_Q_TXD, 0);
  139. }
  140. EXPORT_SYMBOL(ath9k_hw_abort_tx_dma);
  141. bool ath9k_hw_stop_dma_queue(struct ath_hw *ah, u32 q)
  142. {
  143. #define ATH9K_TX_STOP_DMA_TIMEOUT 1000 /* usec */
  144. #define ATH9K_TIME_QUANTUM 100 /* usec */
  145. int wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
  146. int wait;
  147. REG_WRITE(ah, AR_Q_TXD, 1 << q);
  148. for (wait = wait_time; wait != 0; wait--) {
  149. if (wait != wait_time)
  150. udelay(ATH9K_TIME_QUANTUM);
  151. if (ath9k_hw_numtxpending(ah, q) == 0)
  152. break;
  153. }
  154. REG_WRITE(ah, AR_Q_TXD, 0);
  155. return wait != 0;
  156. #undef ATH9K_TX_STOP_DMA_TIMEOUT
  157. #undef ATH9K_TIME_QUANTUM
  158. }
  159. EXPORT_SYMBOL(ath9k_hw_stop_dma_queue);
  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, QUEUE,
  169. "Set TXQ properties, inactive queue: %u\n", q);
  170. return false;
  171. }
  172. ath_dbg(common, 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, 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. q = qinfo->tqi_subtype;
  267. break;
  268. default:
  269. ath_err(common, "Invalid TX queue type: %u\n", type);
  270. return -1;
  271. }
  272. ath_dbg(common, QUEUE, "Setup TX queue: %u\n", q);
  273. qi = &ah->txq[q];
  274. if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
  275. ath_err(common, "TX queue: %u already active\n", q);
  276. return -1;
  277. }
  278. memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
  279. qi->tqi_type = type;
  280. qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
  281. (void) ath9k_hw_set_txq_props(ah, q, qinfo);
  282. return q;
  283. }
  284. EXPORT_SYMBOL(ath9k_hw_setuptxqueue);
  285. static void ath9k_hw_clear_queue_interrupts(struct ath_hw *ah, u32 q)
  286. {
  287. ah->txok_interrupt_mask &= ~(1 << q);
  288. ah->txerr_interrupt_mask &= ~(1 << q);
  289. ah->txdesc_interrupt_mask &= ~(1 << q);
  290. ah->txeol_interrupt_mask &= ~(1 << q);
  291. ah->txurn_interrupt_mask &= ~(1 << q);
  292. }
  293. bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
  294. {
  295. struct ath_common *common = ath9k_hw_common(ah);
  296. struct ath9k_tx_queue_info *qi;
  297. qi = &ah->txq[q];
  298. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  299. ath_dbg(common, QUEUE, "Release TXQ, inactive queue: %u\n", q);
  300. return false;
  301. }
  302. ath_dbg(common, QUEUE, "Release TX queue: %u\n", q);
  303. qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
  304. ath9k_hw_clear_queue_interrupts(ah, q);
  305. ath9k_hw_set_txq_interrupts(ah, qi);
  306. return true;
  307. }
  308. EXPORT_SYMBOL(ath9k_hw_releasetxqueue);
  309. bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
  310. {
  311. struct ath_common *common = ath9k_hw_common(ah);
  312. struct ath9k_tx_queue_info *qi;
  313. u32 cwMin, chanCwMin, value;
  314. qi = &ah->txq[q];
  315. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  316. ath_dbg(common, QUEUE, "Reset TXQ, inactive queue: %u\n", q);
  317. return true;
  318. }
  319. ath_dbg(common, QUEUE, "Reset TX queue: %u\n", q);
  320. if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
  321. chanCwMin = INIT_CWMIN;
  322. for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
  323. } else
  324. cwMin = qi->tqi_cwmin;
  325. ENABLE_REGWRITE_BUFFER(ah);
  326. REG_WRITE(ah, AR_DLCL_IFS(q),
  327. SM(cwMin, AR_D_LCL_IFS_CWMIN) |
  328. SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
  329. SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
  330. REG_WRITE(ah, AR_DRETRY_LIMIT(q),
  331. SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
  332. SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
  333. SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
  334. REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
  335. if (AR_SREV_9340(ah) && !AR_SREV_9340_13_OR_LATER(ah))
  336. REG_WRITE(ah, AR_DMISC(q),
  337. AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x1);
  338. else
  339. REG_WRITE(ah, AR_DMISC(q),
  340. AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
  341. if (qi->tqi_cbrPeriod) {
  342. REG_WRITE(ah, AR_QCBRCFG(q),
  343. SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
  344. SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
  345. REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_FSP_CBR |
  346. (qi->tqi_cbrOverflowLimit ?
  347. AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
  348. }
  349. if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
  350. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  351. SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
  352. AR_Q_RDYTIMECFG_EN);
  353. }
  354. REG_WRITE(ah, AR_DCHNTIME(q),
  355. SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
  356. (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
  357. if (qi->tqi_burstTime
  358. && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE))
  359. REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_RDYTIME_EXP_POLICY);
  360. if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE)
  361. REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_POST_FR_BKOFF_DIS);
  362. REGWRITE_BUFFER_FLUSH(ah);
  363. if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
  364. REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_FRAG_BKOFF_EN);
  365. switch (qi->tqi_type) {
  366. case ATH9K_TX_QUEUE_BEACON:
  367. ENABLE_REGWRITE_BUFFER(ah);
  368. REG_SET_BIT(ah, AR_QMISC(q),
  369. AR_Q_MISC_FSP_DBA_GATED
  370. | AR_Q_MISC_BEACON_USE
  371. | AR_Q_MISC_CBR_INCR_DIS1);
  372. REG_SET_BIT(ah, AR_DMISC(q),
  373. (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  374. AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
  375. | AR_D_MISC_BEACON_USE
  376. | AR_D_MISC_POST_FR_BKOFF_DIS);
  377. REGWRITE_BUFFER_FLUSH(ah);
  378. /*
  379. * cwmin and cwmax should be 0 for beacon queue
  380. * but not for IBSS as we would create an imbalance
  381. * on beaconing fairness for participating nodes.
  382. */
  383. if (AR_SREV_9300_20_OR_LATER(ah) &&
  384. ah->opmode != NL80211_IFTYPE_ADHOC) {
  385. REG_WRITE(ah, AR_DLCL_IFS(q), SM(0, AR_D_LCL_IFS_CWMIN)
  386. | SM(0, AR_D_LCL_IFS_CWMAX)
  387. | SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
  388. }
  389. break;
  390. case ATH9K_TX_QUEUE_CAB:
  391. ENABLE_REGWRITE_BUFFER(ah);
  392. REG_SET_BIT(ah, AR_QMISC(q),
  393. AR_Q_MISC_FSP_DBA_GATED
  394. | AR_Q_MISC_CBR_INCR_DIS1
  395. | AR_Q_MISC_CBR_INCR_DIS0);
  396. value = (qi->tqi_readyTime -
  397. (ah->config.sw_beacon_response_time -
  398. ah->config.dma_beacon_response_time)) * 1024;
  399. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  400. value | AR_Q_RDYTIMECFG_EN);
  401. REG_SET_BIT(ah, AR_DMISC(q),
  402. (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  403. AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
  404. REGWRITE_BUFFER_FLUSH(ah);
  405. break;
  406. case ATH9K_TX_QUEUE_PSPOLL:
  407. REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_CBR_INCR_DIS1);
  408. break;
  409. case ATH9K_TX_QUEUE_UAPSD:
  410. REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_POST_FR_BKOFF_DIS);
  411. break;
  412. default:
  413. break;
  414. }
  415. if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
  416. REG_SET_BIT(ah, AR_DMISC(q),
  417. SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
  418. AR_D_MISC_ARB_LOCKOUT_CNTRL) |
  419. AR_D_MISC_POST_FR_BKOFF_DIS);
  420. }
  421. if (AR_SREV_9300_20_OR_LATER(ah))
  422. REG_WRITE(ah, AR_Q_DESC_CRCCHK, AR_Q_DESC_CRCCHK_EN);
  423. ath9k_hw_clear_queue_interrupts(ah, q);
  424. if (qi->tqi_qflags & TXQ_FLAG_TXINT_ENABLE) {
  425. ah->txok_interrupt_mask |= 1 << q;
  426. ah->txerr_interrupt_mask |= 1 << q;
  427. }
  428. if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
  429. ah->txdesc_interrupt_mask |= 1 << q;
  430. if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
  431. ah->txeol_interrupt_mask |= 1 << q;
  432. if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
  433. ah->txurn_interrupt_mask |= 1 << q;
  434. ath9k_hw_set_txq_interrupts(ah, qi);
  435. return true;
  436. }
  437. EXPORT_SYMBOL(ath9k_hw_resettxqueue);
  438. int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
  439. struct ath_rx_status *rs)
  440. {
  441. struct ar5416_desc ads;
  442. struct ar5416_desc *adsp = AR5416DESC(ds);
  443. u32 phyerr;
  444. if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
  445. return -EINPROGRESS;
  446. ads.u.rx = adsp->u.rx;
  447. rs->rs_status = 0;
  448. rs->rs_flags = 0;
  449. rs->enc_flags = 0;
  450. rs->bw = RATE_INFO_BW_20;
  451. rs->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
  452. rs->rs_tstamp = ads.AR_RcvTimestamp;
  453. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) {
  454. rs->rs_rssi = ATH9K_RSSI_BAD;
  455. rs->rs_rssi_ctl[0] = ATH9K_RSSI_BAD;
  456. rs->rs_rssi_ctl[1] = ATH9K_RSSI_BAD;
  457. rs->rs_rssi_ctl[2] = ATH9K_RSSI_BAD;
  458. rs->rs_rssi_ext[0] = ATH9K_RSSI_BAD;
  459. rs->rs_rssi_ext[1] = ATH9K_RSSI_BAD;
  460. rs->rs_rssi_ext[2] = ATH9K_RSSI_BAD;
  461. } else {
  462. rs->rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
  463. rs->rs_rssi_ctl[0] = MS(ads.ds_rxstatus0,
  464. AR_RxRSSIAnt00);
  465. rs->rs_rssi_ctl[1] = MS(ads.ds_rxstatus0,
  466. AR_RxRSSIAnt01);
  467. rs->rs_rssi_ctl[2] = MS(ads.ds_rxstatus0,
  468. AR_RxRSSIAnt02);
  469. rs->rs_rssi_ext[0] = MS(ads.ds_rxstatus4,
  470. AR_RxRSSIAnt10);
  471. rs->rs_rssi_ext[1] = MS(ads.ds_rxstatus4,
  472. AR_RxRSSIAnt11);
  473. rs->rs_rssi_ext[2] = MS(ads.ds_rxstatus4,
  474. AR_RxRSSIAnt12);
  475. }
  476. if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
  477. rs->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
  478. else
  479. rs->rs_keyix = ATH9K_RXKEYIX_INVALID;
  480. rs->rs_rate = MS(ads.ds_rxstatus0, AR_RxRate);
  481. rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
  482. rs->rs_firstaggr = (ads.ds_rxstatus8 & AR_RxFirstAggr) ? 1 : 0;
  483. rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
  484. rs->rs_moreaggr = (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
  485. rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
  486. /* directly mapped flags for ieee80211_rx_status */
  487. rs->enc_flags |=
  488. (ads.ds_rxstatus3 & AR_GI) ? RX_ENC_FLAG_SHORT_GI : 0;
  489. rs->bw = (ads.ds_rxstatus3 & AR_2040) ? RATE_INFO_BW_40 :
  490. RATE_INFO_BW_20;
  491. if (AR_SREV_9280_20_OR_LATER(ah))
  492. rs->enc_flags |=
  493. (ads.ds_rxstatus3 & AR_STBC) ?
  494. /* we can only Nss=1 STBC */
  495. (1 << RX_ENC_FLAG_STBC_SHIFT) : 0;
  496. if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
  497. rs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
  498. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
  499. rs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
  500. if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
  501. rs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
  502. if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
  503. /*
  504. * Treat these errors as mutually exclusive to avoid spurious
  505. * extra error reports from the hardware. If a CRC error is
  506. * reported, then decryption and MIC errors are irrelevant,
  507. * the frame is going to be dropped either way
  508. */
  509. if (ads.ds_rxstatus8 & AR_PHYErr) {
  510. rs->rs_status |= ATH9K_RXERR_PHY;
  511. phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
  512. rs->rs_phyerr = phyerr;
  513. } else if (ads.ds_rxstatus8 & AR_CRCErr)
  514. rs->rs_status |= ATH9K_RXERR_CRC;
  515. else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
  516. rs->rs_status |= ATH9K_RXERR_DECRYPT;
  517. else if (ads.ds_rxstatus8 & AR_MichaelErr)
  518. rs->rs_status |= ATH9K_RXERR_MIC;
  519. } else {
  520. if (ads.ds_rxstatus8 &
  521. (AR_CRCErr | AR_PHYErr | AR_DecryptCRCErr | AR_MichaelErr))
  522. rs->rs_status |= ATH9K_RXERR_CORRUPT_DESC;
  523. /* Only up to MCS16 supported, everything above is invalid */
  524. if (rs->rs_rate >= 0x90)
  525. rs->rs_status |= ATH9K_RXERR_CORRUPT_DESC;
  526. }
  527. if (ads.ds_rxstatus8 & AR_KeyMiss)
  528. rs->rs_status |= ATH9K_RXERR_KEYMISS;
  529. return 0;
  530. }
  531. EXPORT_SYMBOL(ath9k_hw_rxprocdesc);
  532. /*
  533. * This can stop or re-enables RX.
  534. *
  535. * If bool is set this will kill any frame which is currently being
  536. * transferred between the MAC and baseband and also prevent any new
  537. * frames from getting started.
  538. */
  539. bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
  540. {
  541. u32 reg;
  542. if (set) {
  543. REG_SET_BIT(ah, AR_DIAG_SW,
  544. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  545. if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
  546. 0, AH_WAIT_TIMEOUT)) {
  547. REG_CLR_BIT(ah, AR_DIAG_SW,
  548. (AR_DIAG_RX_DIS |
  549. AR_DIAG_RX_ABORT));
  550. reg = REG_READ(ah, AR_OBS_BUS_1);
  551. ath_err(ath9k_hw_common(ah),
  552. "RX failed to go idle in 10 ms RXSM=0x%x\n",
  553. reg);
  554. return false;
  555. }
  556. } else {
  557. REG_CLR_BIT(ah, AR_DIAG_SW,
  558. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  559. }
  560. return true;
  561. }
  562. EXPORT_SYMBOL(ath9k_hw_setrxabort);
  563. void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
  564. {
  565. REG_WRITE(ah, AR_RXDP, rxdp);
  566. }
  567. EXPORT_SYMBOL(ath9k_hw_putrxbuf);
  568. void ath9k_hw_startpcureceive(struct ath_hw *ah, bool is_scanning)
  569. {
  570. ath9k_enable_mib_counters(ah);
  571. ath9k_ani_reset(ah, is_scanning);
  572. REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  573. }
  574. EXPORT_SYMBOL(ath9k_hw_startpcureceive);
  575. void ath9k_hw_abortpcurecv(struct ath_hw *ah)
  576. {
  577. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_ABORT | AR_DIAG_RX_DIS);
  578. ath9k_hw_disable_mib_counters(ah);
  579. }
  580. EXPORT_SYMBOL(ath9k_hw_abortpcurecv);
  581. bool ath9k_hw_stopdmarecv(struct ath_hw *ah, bool *reset)
  582. {
  583. #define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
  584. struct ath_common *common = ath9k_hw_common(ah);
  585. u32 mac_status, last_mac_status = 0;
  586. int i;
  587. /* Enable access to the DMA observation bus */
  588. REG_WRITE(ah, AR_MACMISC,
  589. ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
  590. (AR_MACMISC_MISC_OBS_BUS_1 <<
  591. AR_MACMISC_MISC_OBS_BUS_MSB_S)));
  592. REG_WRITE(ah, AR_CR, AR_CR_RXD);
  593. /* Wait for rx enable bit to go low */
  594. for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
  595. if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
  596. break;
  597. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  598. mac_status = REG_READ(ah, AR_DMADBG_7) & 0x7f0;
  599. if (mac_status == 0x1c0 && mac_status == last_mac_status) {
  600. *reset = true;
  601. break;
  602. }
  603. last_mac_status = mac_status;
  604. }
  605. udelay(AH_TIME_QUANTUM);
  606. }
  607. if (i == 0) {
  608. ath_err(common,
  609. "DMA failed to stop in %d ms AR_CR=0x%08x AR_DIAG_SW=0x%08x DMADBG_7=0x%08x\n",
  610. AH_RX_STOP_DMA_TIMEOUT / 1000,
  611. REG_READ(ah, AR_CR),
  612. REG_READ(ah, AR_DIAG_SW),
  613. REG_READ(ah, AR_DMADBG_7));
  614. return false;
  615. } else {
  616. return true;
  617. }
  618. #undef AH_RX_STOP_DMA_TIMEOUT
  619. }
  620. EXPORT_SYMBOL(ath9k_hw_stopdmarecv);
  621. int ath9k_hw_beaconq_setup(struct ath_hw *ah)
  622. {
  623. struct ath9k_tx_queue_info qi;
  624. memset(&qi, 0, sizeof(qi));
  625. qi.tqi_aifs = 1;
  626. qi.tqi_cwmin = 0;
  627. qi.tqi_cwmax = 0;
  628. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  629. qi.tqi_qflags = TXQ_FLAG_TXINT_ENABLE;
  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_kill_interrupts(struct ath_hw *ah)
  651. {
  652. struct ath_common *common = ath9k_hw_common(ah);
  653. ath_dbg(common, INTERRUPT, "disable IER\n");
  654. REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
  655. (void) REG_READ(ah, AR_IER);
  656. if (!AR_SREV_9100(ah)) {
  657. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
  658. (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
  659. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  660. (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
  661. }
  662. }
  663. EXPORT_SYMBOL(ath9k_hw_kill_interrupts);
  664. void ath9k_hw_disable_interrupts(struct ath_hw *ah)
  665. {
  666. if (!(ah->imask & ATH9K_INT_GLOBAL))
  667. atomic_set(&ah->intr_ref_cnt, -1);
  668. else
  669. atomic_dec(&ah->intr_ref_cnt);
  670. ath9k_hw_kill_interrupts(ah);
  671. }
  672. EXPORT_SYMBOL(ath9k_hw_disable_interrupts);
  673. static void __ath9k_hw_enable_interrupts(struct ath_hw *ah)
  674. {
  675. struct ath_common *common = ath9k_hw_common(ah);
  676. u32 sync_default = AR_INTR_SYNC_DEFAULT;
  677. u32 async_mask;
  678. if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah) ||
  679. AR_SREV_9561(ah))
  680. sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
  681. async_mask = AR_INTR_MAC_IRQ;
  682. if (ah->imask & ATH9K_INT_MCI)
  683. async_mask |= AR_INTR_ASYNC_MASK_MCI;
  684. ath_dbg(common, INTERRUPT, "enable IER\n");
  685. REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
  686. if (!AR_SREV_9100(ah)) {
  687. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, async_mask);
  688. REG_WRITE(ah, AR_INTR_ASYNC_MASK, async_mask);
  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, INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
  693. REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
  694. if (ah->msi_enabled) {
  695. u32 _msi_reg = 0;
  696. u32 i = 0;
  697. u32 msi_pend_addr_mask = AR_PCIE_MSI_HW_INT_PENDING_ADDR_MSI_64;
  698. ath_dbg(ath9k_hw_common(ah), INTERRUPT,
  699. "Enabling MSI, msi_mask=0x%X\n", ah->msi_mask);
  700. REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, ah->msi_mask);
  701. REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, ah->msi_mask);
  702. ath_dbg(ath9k_hw_common(ah), INTERRUPT,
  703. "AR_INTR_PRIO_ASYNC_ENABLE=0x%X, AR_INTR_PRIO_ASYNC_MASK=0x%X\n",
  704. REG_READ(ah, AR_INTR_PRIO_ASYNC_ENABLE),
  705. REG_READ(ah, AR_INTR_PRIO_ASYNC_MASK));
  706. if (ah->msi_reg == 0)
  707. ah->msi_reg = REG_READ(ah, AR_PCIE_MSI);
  708. ath_dbg(ath9k_hw_common(ah), INTERRUPT,
  709. "AR_PCIE_MSI=0x%X, ah->msi_reg = 0x%X\n",
  710. AR_PCIE_MSI, ah->msi_reg);
  711. i = 0;
  712. do {
  713. REG_WRITE(ah, AR_PCIE_MSI,
  714. (ah->msi_reg | AR_PCIE_MSI_ENABLE)
  715. & msi_pend_addr_mask);
  716. _msi_reg = REG_READ(ah, AR_PCIE_MSI);
  717. i++;
  718. } while ((_msi_reg & AR_PCIE_MSI_ENABLE) == 0 && i < 200);
  719. if (i >= 200)
  720. ath_err(ath9k_hw_common(ah),
  721. "%s: _msi_reg = 0x%X\n",
  722. __func__, _msi_reg);
  723. }
  724. }
  725. void ath9k_hw_resume_interrupts(struct ath_hw *ah)
  726. {
  727. struct ath_common *common = ath9k_hw_common(ah);
  728. if (!(ah->imask & ATH9K_INT_GLOBAL))
  729. return;
  730. if (atomic_read(&ah->intr_ref_cnt) != 0) {
  731. ath_dbg(common, INTERRUPT, "Do not enable IER ref count %d\n",
  732. atomic_read(&ah->intr_ref_cnt));
  733. return;
  734. }
  735. __ath9k_hw_enable_interrupts(ah);
  736. }
  737. EXPORT_SYMBOL(ath9k_hw_resume_interrupts);
  738. void ath9k_hw_enable_interrupts(struct ath_hw *ah)
  739. {
  740. struct ath_common *common = ath9k_hw_common(ah);
  741. if (!(ah->imask & ATH9K_INT_GLOBAL))
  742. return;
  743. if (!atomic_inc_and_test(&ah->intr_ref_cnt)) {
  744. ath_dbg(common, INTERRUPT, "Do not enable IER ref count %d\n",
  745. atomic_read(&ah->intr_ref_cnt));
  746. return;
  747. }
  748. __ath9k_hw_enable_interrupts(ah);
  749. }
  750. EXPORT_SYMBOL(ath9k_hw_enable_interrupts);
  751. void ath9k_hw_set_interrupts(struct ath_hw *ah)
  752. {
  753. enum ath9k_int ints = ah->imask;
  754. u32 mask, mask2;
  755. struct ath9k_hw_capabilities *pCap = &ah->caps;
  756. struct ath_common *common = ath9k_hw_common(ah);
  757. if (!(ints & ATH9K_INT_GLOBAL))
  758. ath9k_hw_disable_interrupts(ah);
  759. if (ah->msi_enabled) {
  760. ath_dbg(common, INTERRUPT, "Clearing AR_INTR_PRIO_ASYNC_ENABLE\n");
  761. REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
  762. REG_READ(ah, AR_INTR_PRIO_ASYNC_ENABLE);
  763. }
  764. ath_dbg(common, INTERRUPT, "New interrupt mask 0x%x\n", ints);
  765. mask = ints & ATH9K_INT_COMMON;
  766. mask2 = 0;
  767. ah->msi_mask = 0;
  768. if (ints & ATH9K_INT_TX) {
  769. ah->msi_mask |= AR_INTR_PRIO_TX;
  770. if (ah->config.tx_intr_mitigation)
  771. mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM;
  772. else {
  773. if (ah->txok_interrupt_mask)
  774. mask |= AR_IMR_TXOK;
  775. if (ah->txdesc_interrupt_mask)
  776. mask |= AR_IMR_TXDESC;
  777. }
  778. if (ah->txerr_interrupt_mask)
  779. mask |= AR_IMR_TXERR;
  780. if (ah->txeol_interrupt_mask)
  781. mask |= AR_IMR_TXEOL;
  782. }
  783. if (ints & ATH9K_INT_RX) {
  784. ah->msi_mask |= AR_INTR_PRIO_RXLP | AR_INTR_PRIO_RXHP;
  785. if (AR_SREV_9300_20_OR_LATER(ah)) {
  786. mask |= AR_IMR_RXERR | AR_IMR_RXOK_HP;
  787. if (ah->config.rx_intr_mitigation) {
  788. mask &= ~AR_IMR_RXOK_LP;
  789. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  790. } else {
  791. mask |= AR_IMR_RXOK_LP;
  792. }
  793. } else {
  794. if (ah->config.rx_intr_mitigation)
  795. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  796. else
  797. mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
  798. }
  799. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  800. mask |= AR_IMR_GENTMR;
  801. }
  802. if (ints & ATH9K_INT_GENTIMER)
  803. mask |= AR_IMR_GENTMR;
  804. if (ints & (ATH9K_INT_BMISC)) {
  805. mask |= AR_IMR_BCNMISC;
  806. if (ints & ATH9K_INT_TIM)
  807. mask2 |= AR_IMR_S2_TIM;
  808. if (ints & ATH9K_INT_DTIM)
  809. mask2 |= AR_IMR_S2_DTIM;
  810. if (ints & ATH9K_INT_DTIMSYNC)
  811. mask2 |= AR_IMR_S2_DTIMSYNC;
  812. if (ints & ATH9K_INT_CABEND)
  813. mask2 |= AR_IMR_S2_CABEND;
  814. if (ints & ATH9K_INT_TSFOOR)
  815. mask2 |= AR_IMR_S2_TSFOOR;
  816. }
  817. if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
  818. mask |= AR_IMR_BCNMISC;
  819. if (ints & ATH9K_INT_GTT)
  820. mask2 |= AR_IMR_S2_GTT;
  821. if (ints & ATH9K_INT_CST)
  822. mask2 |= AR_IMR_S2_CST;
  823. }
  824. if (ah->config.hw_hang_checks & HW_BB_WATCHDOG) {
  825. if (ints & ATH9K_INT_BB_WATCHDOG) {
  826. mask |= AR_IMR_BCNMISC;
  827. mask2 |= AR_IMR_S2_BB_WATCHDOG;
  828. }
  829. }
  830. ath_dbg(common, INTERRUPT, "new IMR 0x%x\n", mask);
  831. REG_WRITE(ah, AR_IMR, mask);
  832. ah->imrs2_reg &= ~(AR_IMR_S2_TIM |
  833. AR_IMR_S2_DTIM |
  834. AR_IMR_S2_DTIMSYNC |
  835. AR_IMR_S2_CABEND |
  836. AR_IMR_S2_CABTO |
  837. AR_IMR_S2_TSFOOR |
  838. AR_IMR_S2_GTT |
  839. AR_IMR_S2_CST);
  840. if (ah->config.hw_hang_checks & HW_BB_WATCHDOG) {
  841. if (ints & ATH9K_INT_BB_WATCHDOG)
  842. ah->imrs2_reg &= ~AR_IMR_S2_BB_WATCHDOG;
  843. }
  844. ah->imrs2_reg |= mask2;
  845. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  846. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  847. if (ints & ATH9K_INT_TIM_TIMER)
  848. REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  849. else
  850. REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  851. }
  852. return;
  853. }
  854. EXPORT_SYMBOL(ath9k_hw_set_interrupts);
  855. #define ATH9K_HW_MAX_DCU 10
  856. #define ATH9K_HW_SLICE_PER_DCU 16
  857. #define ATH9K_HW_BIT_IN_SLICE 16
  858. void ath9k_hw_set_tx_filter(struct ath_hw *ah, u8 destidx, bool set)
  859. {
  860. int dcu_idx;
  861. u32 filter;
  862. for (dcu_idx = 0; dcu_idx < 10; dcu_idx++) {
  863. filter = SM(set, AR_D_TXBLK_WRITE_COMMAND);
  864. filter |= SM(dcu_idx, AR_D_TXBLK_WRITE_DCU);
  865. filter |= SM((destidx / ATH9K_HW_SLICE_PER_DCU),
  866. AR_D_TXBLK_WRITE_SLICE);
  867. filter |= BIT(destidx % ATH9K_HW_BIT_IN_SLICE);
  868. ath_dbg(ath9k_hw_common(ah), PS,
  869. "DCU%d staid %d set %d txfilter %08x\n",
  870. dcu_idx, destidx, set, filter);
  871. REG_WRITE(ah, AR_D_TXBLK_BASE, filter);
  872. }
  873. }
  874. EXPORT_SYMBOL(ath9k_hw_set_tx_filter);