mac.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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. bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
  154. const struct ath9k_tx_queue_info *qinfo)
  155. {
  156. u32 cw;
  157. struct ath_common *common = ath9k_hw_common(ah);
  158. struct ath9k_tx_queue_info *qi;
  159. qi = &ah->txq[q];
  160. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  161. ath_dbg(common, QUEUE,
  162. "Set TXQ properties, inactive queue: %u\n", q);
  163. return false;
  164. }
  165. ath_dbg(common, QUEUE, "Set queue properties for: %u\n", q);
  166. qi->tqi_ver = qinfo->tqi_ver;
  167. qi->tqi_subtype = qinfo->tqi_subtype;
  168. qi->tqi_qflags = qinfo->tqi_qflags;
  169. qi->tqi_priority = qinfo->tqi_priority;
  170. if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
  171. qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
  172. else
  173. qi->tqi_aifs = INIT_AIFS;
  174. if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
  175. cw = min(qinfo->tqi_cwmin, 1024U);
  176. qi->tqi_cwmin = 1;
  177. while (qi->tqi_cwmin < cw)
  178. qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
  179. } else
  180. qi->tqi_cwmin = qinfo->tqi_cwmin;
  181. if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
  182. cw = min(qinfo->tqi_cwmax, 1024U);
  183. qi->tqi_cwmax = 1;
  184. while (qi->tqi_cwmax < cw)
  185. qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
  186. } else
  187. qi->tqi_cwmax = INIT_CWMAX;
  188. if (qinfo->tqi_shretry != 0)
  189. qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
  190. else
  191. qi->tqi_shretry = INIT_SH_RETRY;
  192. if (qinfo->tqi_lgretry != 0)
  193. qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
  194. else
  195. qi->tqi_lgretry = INIT_LG_RETRY;
  196. qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
  197. qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
  198. qi->tqi_burstTime = qinfo->tqi_burstTime;
  199. qi->tqi_readyTime = qinfo->tqi_readyTime;
  200. switch (qinfo->tqi_subtype) {
  201. case ATH9K_WME_UPSD:
  202. if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
  203. qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
  204. break;
  205. default:
  206. break;
  207. }
  208. return true;
  209. }
  210. EXPORT_SYMBOL(ath9k_hw_set_txq_props);
  211. bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
  212. struct ath9k_tx_queue_info *qinfo)
  213. {
  214. struct ath_common *common = ath9k_hw_common(ah);
  215. struct ath9k_tx_queue_info *qi;
  216. qi = &ah->txq[q];
  217. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  218. ath_dbg(common, QUEUE,
  219. "Get TXQ properties, inactive queue: %u\n", q);
  220. return false;
  221. }
  222. qinfo->tqi_qflags = qi->tqi_qflags;
  223. qinfo->tqi_ver = qi->tqi_ver;
  224. qinfo->tqi_subtype = qi->tqi_subtype;
  225. qinfo->tqi_qflags = qi->tqi_qflags;
  226. qinfo->tqi_priority = qi->tqi_priority;
  227. qinfo->tqi_aifs = qi->tqi_aifs;
  228. qinfo->tqi_cwmin = qi->tqi_cwmin;
  229. qinfo->tqi_cwmax = qi->tqi_cwmax;
  230. qinfo->tqi_shretry = qi->tqi_shretry;
  231. qinfo->tqi_lgretry = qi->tqi_lgretry;
  232. qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
  233. qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
  234. qinfo->tqi_burstTime = qi->tqi_burstTime;
  235. qinfo->tqi_readyTime = qi->tqi_readyTime;
  236. return true;
  237. }
  238. EXPORT_SYMBOL(ath9k_hw_get_txq_props);
  239. int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
  240. const struct ath9k_tx_queue_info *qinfo)
  241. {
  242. struct ath_common *common = ath9k_hw_common(ah);
  243. struct ath9k_tx_queue_info *qi;
  244. int q;
  245. switch (type) {
  246. case ATH9K_TX_QUEUE_BEACON:
  247. q = ATH9K_NUM_TX_QUEUES - 1;
  248. break;
  249. case ATH9K_TX_QUEUE_CAB:
  250. q = ATH9K_NUM_TX_QUEUES - 2;
  251. break;
  252. case ATH9K_TX_QUEUE_PSPOLL:
  253. q = 1;
  254. break;
  255. case ATH9K_TX_QUEUE_UAPSD:
  256. q = ATH9K_NUM_TX_QUEUES - 3;
  257. break;
  258. case ATH9K_TX_QUEUE_DATA:
  259. for (q = 0; q < ATH9K_NUM_TX_QUEUES; q++)
  260. if (ah->txq[q].tqi_type ==
  261. ATH9K_TX_QUEUE_INACTIVE)
  262. break;
  263. if (q == ATH9K_NUM_TX_QUEUES) {
  264. ath_err(common, "No available TX queue\n");
  265. return -1;
  266. }
  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_channel *chan = ah->curchan;
  313. struct ath9k_tx_queue_info *qi;
  314. u32 cwMin, chanCwMin, value;
  315. qi = &ah->txq[q];
  316. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  317. ath_dbg(common, QUEUE, "Reset TXQ, inactive queue: %u\n", q);
  318. return true;
  319. }
  320. ath_dbg(common, QUEUE, "Reset TX queue: %u\n", q);
  321. if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
  322. if (chan && IS_CHAN_B(chan))
  323. chanCwMin = INIT_CWMIN_11B;
  324. else
  325. chanCwMin = INIT_CWMIN;
  326. for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
  327. } else
  328. cwMin = qi->tqi_cwmin;
  329. ENABLE_REGWRITE_BUFFER(ah);
  330. REG_WRITE(ah, AR_DLCL_IFS(q),
  331. SM(cwMin, AR_D_LCL_IFS_CWMIN) |
  332. SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
  333. SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
  334. REG_WRITE(ah, AR_DRETRY_LIMIT(q),
  335. SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
  336. SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
  337. SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
  338. REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
  339. if (AR_SREV_9340(ah))
  340. REG_WRITE(ah, AR_DMISC(q),
  341. AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x1);
  342. else
  343. REG_WRITE(ah, AR_DMISC(q),
  344. AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
  345. if (qi->tqi_cbrPeriod) {
  346. REG_WRITE(ah, AR_QCBRCFG(q),
  347. SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
  348. SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
  349. REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_FSP_CBR |
  350. (qi->tqi_cbrOverflowLimit ?
  351. AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
  352. }
  353. if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
  354. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  355. SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
  356. AR_Q_RDYTIMECFG_EN);
  357. }
  358. REG_WRITE(ah, AR_DCHNTIME(q),
  359. SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
  360. (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
  361. if (qi->tqi_burstTime
  362. && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE))
  363. REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_RDYTIME_EXP_POLICY);
  364. if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE)
  365. REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_POST_FR_BKOFF_DIS);
  366. REGWRITE_BUFFER_FLUSH(ah);
  367. if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
  368. REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_FRAG_BKOFF_EN);
  369. switch (qi->tqi_type) {
  370. case ATH9K_TX_QUEUE_BEACON:
  371. ENABLE_REGWRITE_BUFFER(ah);
  372. REG_SET_BIT(ah, AR_QMISC(q),
  373. AR_Q_MISC_FSP_DBA_GATED
  374. | AR_Q_MISC_BEACON_USE
  375. | AR_Q_MISC_CBR_INCR_DIS1);
  376. REG_SET_BIT(ah, AR_DMISC(q),
  377. (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  378. AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
  379. | AR_D_MISC_BEACON_USE
  380. | AR_D_MISC_POST_FR_BKOFF_DIS);
  381. REGWRITE_BUFFER_FLUSH(ah);
  382. /*
  383. * cwmin and cwmax should be 0 for beacon queue
  384. * but not for IBSS as we would create an imbalance
  385. * on beaconing fairness for participating nodes.
  386. */
  387. if (AR_SREV_9300_20_OR_LATER(ah) &&
  388. ah->opmode != NL80211_IFTYPE_ADHOC) {
  389. REG_WRITE(ah, AR_DLCL_IFS(q), SM(0, AR_D_LCL_IFS_CWMIN)
  390. | SM(0, AR_D_LCL_IFS_CWMAX)
  391. | SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
  392. }
  393. break;
  394. case ATH9K_TX_QUEUE_CAB:
  395. ENABLE_REGWRITE_BUFFER(ah);
  396. REG_SET_BIT(ah, AR_QMISC(q),
  397. AR_Q_MISC_FSP_DBA_GATED
  398. | AR_Q_MISC_CBR_INCR_DIS1
  399. | AR_Q_MISC_CBR_INCR_DIS0);
  400. value = (qi->tqi_readyTime -
  401. (ah->config.sw_beacon_response_time -
  402. ah->config.dma_beacon_response_time) -
  403. ah->config.additional_swba_backoff) * 1024;
  404. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  405. value | AR_Q_RDYTIMECFG_EN);
  406. REG_SET_BIT(ah, AR_DMISC(q),
  407. (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  408. AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
  409. REGWRITE_BUFFER_FLUSH(ah);
  410. break;
  411. case ATH9K_TX_QUEUE_PSPOLL:
  412. REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_CBR_INCR_DIS1);
  413. break;
  414. case ATH9K_TX_QUEUE_UAPSD:
  415. REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_POST_FR_BKOFF_DIS);
  416. break;
  417. default:
  418. break;
  419. }
  420. if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
  421. REG_SET_BIT(ah, AR_DMISC(q),
  422. SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
  423. AR_D_MISC_ARB_LOCKOUT_CNTRL) |
  424. AR_D_MISC_POST_FR_BKOFF_DIS);
  425. }
  426. if (AR_SREV_9300_20_OR_LATER(ah))
  427. REG_WRITE(ah, AR_Q_DESC_CRCCHK, AR_Q_DESC_CRCCHK_EN);
  428. ath9k_hw_clear_queue_interrupts(ah, q);
  429. if (qi->tqi_qflags & TXQ_FLAG_TXINT_ENABLE) {
  430. ah->txok_interrupt_mask |= 1 << q;
  431. ah->txerr_interrupt_mask |= 1 << q;
  432. }
  433. if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
  434. ah->txdesc_interrupt_mask |= 1 << q;
  435. if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
  436. ah->txeol_interrupt_mask |= 1 << q;
  437. if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
  438. ah->txurn_interrupt_mask |= 1 << q;
  439. ath9k_hw_set_txq_interrupts(ah, qi);
  440. return true;
  441. }
  442. EXPORT_SYMBOL(ath9k_hw_resettxqueue);
  443. int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
  444. struct ath_rx_status *rs)
  445. {
  446. struct ar5416_desc ads;
  447. struct ar5416_desc *adsp = AR5416DESC(ds);
  448. u32 phyerr;
  449. if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
  450. return -EINPROGRESS;
  451. ads.u.rx = adsp->u.rx;
  452. rs->rs_status = 0;
  453. rs->rs_flags = 0;
  454. rs->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
  455. rs->rs_tstamp = ads.AR_RcvTimestamp;
  456. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) {
  457. rs->rs_rssi = ATH9K_RSSI_BAD;
  458. rs->rs_rssi_ctl0 = ATH9K_RSSI_BAD;
  459. rs->rs_rssi_ctl1 = ATH9K_RSSI_BAD;
  460. rs->rs_rssi_ctl2 = ATH9K_RSSI_BAD;
  461. rs->rs_rssi_ext0 = ATH9K_RSSI_BAD;
  462. rs->rs_rssi_ext1 = ATH9K_RSSI_BAD;
  463. rs->rs_rssi_ext2 = ATH9K_RSSI_BAD;
  464. } else {
  465. rs->rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
  466. rs->rs_rssi_ctl0 = MS(ads.ds_rxstatus0,
  467. AR_RxRSSIAnt00);
  468. rs->rs_rssi_ctl1 = MS(ads.ds_rxstatus0,
  469. AR_RxRSSIAnt01);
  470. rs->rs_rssi_ctl2 = MS(ads.ds_rxstatus0,
  471. AR_RxRSSIAnt02);
  472. rs->rs_rssi_ext0 = MS(ads.ds_rxstatus4,
  473. AR_RxRSSIAnt10);
  474. rs->rs_rssi_ext1 = MS(ads.ds_rxstatus4,
  475. AR_RxRSSIAnt11);
  476. rs->rs_rssi_ext2 = MS(ads.ds_rxstatus4,
  477. AR_RxRSSIAnt12);
  478. }
  479. if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
  480. rs->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
  481. else
  482. rs->rs_keyix = ATH9K_RXKEYIX_INVALID;
  483. rs->rs_rate = MS(ads.ds_rxstatus0, AR_RxRate);
  484. rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
  485. rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
  486. rs->rs_moreaggr =
  487. (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
  488. rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
  489. rs->rs_flags =
  490. (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
  491. rs->rs_flags |=
  492. (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
  493. if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
  494. rs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
  495. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
  496. rs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
  497. if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
  498. rs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
  499. if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
  500. /*
  501. * Treat these errors as mutually exclusive to avoid spurious
  502. * extra error reports from the hardware. If a CRC error is
  503. * reported, then decryption and MIC errors are irrelevant,
  504. * the frame is going to be dropped either way
  505. */
  506. if (ads.ds_rxstatus8 & AR_CRCErr)
  507. rs->rs_status |= ATH9K_RXERR_CRC;
  508. else if (ads.ds_rxstatus8 & AR_PHYErr) {
  509. rs->rs_status |= ATH9K_RXERR_PHY;
  510. phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
  511. rs->rs_phyerr = phyerr;
  512. } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
  513. rs->rs_status |= ATH9K_RXERR_DECRYPT;
  514. else if (ads.ds_rxstatus8 & AR_MichaelErr)
  515. rs->rs_status |= ATH9K_RXERR_MIC;
  516. }
  517. if (ads.ds_rxstatus8 & AR_KeyMiss)
  518. rs->rs_status |= ATH9K_RXERR_KEYMISS;
  519. return 0;
  520. }
  521. EXPORT_SYMBOL(ath9k_hw_rxprocdesc);
  522. /*
  523. * This can stop or re-enables RX.
  524. *
  525. * If bool is set this will kill any frame which is currently being
  526. * transferred between the MAC and baseband and also prevent any new
  527. * frames from getting started.
  528. */
  529. bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
  530. {
  531. u32 reg;
  532. if (set) {
  533. REG_SET_BIT(ah, AR_DIAG_SW,
  534. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  535. if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
  536. 0, AH_WAIT_TIMEOUT)) {
  537. REG_CLR_BIT(ah, AR_DIAG_SW,
  538. (AR_DIAG_RX_DIS |
  539. AR_DIAG_RX_ABORT));
  540. reg = REG_READ(ah, AR_OBS_BUS_1);
  541. ath_err(ath9k_hw_common(ah),
  542. "RX failed to go idle in 10 ms RXSM=0x%x\n",
  543. reg);
  544. return false;
  545. }
  546. } else {
  547. REG_CLR_BIT(ah, AR_DIAG_SW,
  548. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  549. }
  550. return true;
  551. }
  552. EXPORT_SYMBOL(ath9k_hw_setrxabort);
  553. void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
  554. {
  555. REG_WRITE(ah, AR_RXDP, rxdp);
  556. }
  557. EXPORT_SYMBOL(ath9k_hw_putrxbuf);
  558. void ath9k_hw_startpcureceive(struct ath_hw *ah, bool is_scanning)
  559. {
  560. ath9k_enable_mib_counters(ah);
  561. ath9k_ani_reset(ah, is_scanning);
  562. REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  563. }
  564. EXPORT_SYMBOL(ath9k_hw_startpcureceive);
  565. void ath9k_hw_abortpcurecv(struct ath_hw *ah)
  566. {
  567. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_ABORT | AR_DIAG_RX_DIS);
  568. ath9k_hw_disable_mib_counters(ah);
  569. }
  570. EXPORT_SYMBOL(ath9k_hw_abortpcurecv);
  571. bool ath9k_hw_stopdmarecv(struct ath_hw *ah, bool *reset)
  572. {
  573. #define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
  574. struct ath_common *common = ath9k_hw_common(ah);
  575. u32 mac_status, last_mac_status = 0;
  576. int i;
  577. /* Enable access to the DMA observation bus */
  578. REG_WRITE(ah, AR_MACMISC,
  579. ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
  580. (AR_MACMISC_MISC_OBS_BUS_1 <<
  581. AR_MACMISC_MISC_OBS_BUS_MSB_S)));
  582. REG_WRITE(ah, AR_CR, AR_CR_RXD);
  583. /* Wait for rx enable bit to go low */
  584. for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
  585. if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
  586. break;
  587. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  588. mac_status = REG_READ(ah, AR_DMADBG_7) & 0x7f0;
  589. if (mac_status == 0x1c0 && mac_status == last_mac_status) {
  590. *reset = true;
  591. break;
  592. }
  593. last_mac_status = mac_status;
  594. }
  595. udelay(AH_TIME_QUANTUM);
  596. }
  597. if (i == 0) {
  598. ath_err(common,
  599. "DMA failed to stop in %d ms AR_CR=0x%08x AR_DIAG_SW=0x%08x DMADBG_7=0x%08x\n",
  600. AH_RX_STOP_DMA_TIMEOUT / 1000,
  601. REG_READ(ah, AR_CR),
  602. REG_READ(ah, AR_DIAG_SW),
  603. REG_READ(ah, AR_DMADBG_7));
  604. return false;
  605. } else {
  606. return true;
  607. }
  608. #undef AH_RX_STOP_DMA_TIMEOUT
  609. }
  610. EXPORT_SYMBOL(ath9k_hw_stopdmarecv);
  611. int ath9k_hw_beaconq_setup(struct ath_hw *ah)
  612. {
  613. struct ath9k_tx_queue_info qi;
  614. memset(&qi, 0, sizeof(qi));
  615. qi.tqi_aifs = 1;
  616. qi.tqi_cwmin = 0;
  617. qi.tqi_cwmax = 0;
  618. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  619. qi.tqi_qflags = TXQ_FLAG_TXINT_ENABLE;
  620. return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
  621. }
  622. EXPORT_SYMBOL(ath9k_hw_beaconq_setup);
  623. bool ath9k_hw_intrpend(struct ath_hw *ah)
  624. {
  625. u32 host_isr;
  626. if (AR_SREV_9100(ah))
  627. return true;
  628. host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
  629. if (((host_isr & AR_INTR_MAC_IRQ) ||
  630. (host_isr & AR_INTR_ASYNC_MASK_MCI)) &&
  631. (host_isr != AR_INTR_SPURIOUS))
  632. return true;
  633. host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  634. if ((host_isr & AR_INTR_SYNC_DEFAULT)
  635. && (host_isr != AR_INTR_SPURIOUS))
  636. return true;
  637. return false;
  638. }
  639. EXPORT_SYMBOL(ath9k_hw_intrpend);
  640. void ath9k_hw_disable_interrupts(struct ath_hw *ah)
  641. {
  642. struct ath_common *common = ath9k_hw_common(ah);
  643. if (!(ah->imask & ATH9K_INT_GLOBAL))
  644. atomic_set(&ah->intr_ref_cnt, -1);
  645. else
  646. atomic_dec(&ah->intr_ref_cnt);
  647. ath_dbg(common, INTERRUPT, "disable IER\n");
  648. REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
  649. (void) REG_READ(ah, AR_IER);
  650. if (!AR_SREV_9100(ah)) {
  651. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
  652. (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
  653. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  654. (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
  655. }
  656. }
  657. EXPORT_SYMBOL(ath9k_hw_disable_interrupts);
  658. void ath9k_hw_enable_interrupts(struct ath_hw *ah)
  659. {
  660. struct ath_common *common = ath9k_hw_common(ah);
  661. u32 sync_default = AR_INTR_SYNC_DEFAULT;
  662. u32 async_mask;
  663. if (!(ah->imask & ATH9K_INT_GLOBAL))
  664. return;
  665. if (!atomic_inc_and_test(&ah->intr_ref_cnt)) {
  666. ath_dbg(common, INTERRUPT, "Do not enable IER ref count %d\n",
  667. atomic_read(&ah->intr_ref_cnt));
  668. return;
  669. }
  670. if (AR_SREV_9340(ah))
  671. sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
  672. async_mask = AR_INTR_MAC_IRQ;
  673. if (ah->imask & ATH9K_INT_MCI)
  674. async_mask |= AR_INTR_ASYNC_MASK_MCI;
  675. ath_dbg(common, INTERRUPT, "enable IER\n");
  676. REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
  677. if (!AR_SREV_9100(ah)) {
  678. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, async_mask);
  679. REG_WRITE(ah, AR_INTR_ASYNC_MASK, async_mask);
  680. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
  681. REG_WRITE(ah, AR_INTR_SYNC_MASK, sync_default);
  682. }
  683. ath_dbg(common, INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
  684. REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
  685. }
  686. EXPORT_SYMBOL(ath9k_hw_enable_interrupts);
  687. void ath9k_hw_set_interrupts(struct ath_hw *ah)
  688. {
  689. enum ath9k_int ints = ah->imask;
  690. u32 mask, mask2;
  691. struct ath9k_hw_capabilities *pCap = &ah->caps;
  692. struct ath_common *common = ath9k_hw_common(ah);
  693. if (!(ints & ATH9K_INT_GLOBAL))
  694. ath9k_hw_disable_interrupts(ah);
  695. ath_dbg(common, INTERRUPT, "New interrupt mask 0x%x\n", ints);
  696. mask = ints & ATH9K_INT_COMMON;
  697. mask2 = 0;
  698. if (ints & ATH9K_INT_TX) {
  699. if (ah->config.tx_intr_mitigation)
  700. mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM;
  701. else {
  702. if (ah->txok_interrupt_mask)
  703. mask |= AR_IMR_TXOK;
  704. if (ah->txdesc_interrupt_mask)
  705. mask |= AR_IMR_TXDESC;
  706. }
  707. if (ah->txerr_interrupt_mask)
  708. mask |= AR_IMR_TXERR;
  709. if (ah->txeol_interrupt_mask)
  710. mask |= AR_IMR_TXEOL;
  711. }
  712. if (ints & ATH9K_INT_RX) {
  713. if (AR_SREV_9300_20_OR_LATER(ah)) {
  714. mask |= AR_IMR_RXERR | AR_IMR_RXOK_HP;
  715. if (ah->config.rx_intr_mitigation) {
  716. mask &= ~AR_IMR_RXOK_LP;
  717. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  718. } else {
  719. mask |= AR_IMR_RXOK_LP;
  720. }
  721. } else {
  722. if (ah->config.rx_intr_mitigation)
  723. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  724. else
  725. mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
  726. }
  727. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  728. mask |= AR_IMR_GENTMR;
  729. }
  730. if (ints & ATH9K_INT_GENTIMER)
  731. mask |= AR_IMR_GENTMR;
  732. if (ints & (ATH9K_INT_BMISC)) {
  733. mask |= AR_IMR_BCNMISC;
  734. if (ints & ATH9K_INT_TIM)
  735. mask2 |= AR_IMR_S2_TIM;
  736. if (ints & ATH9K_INT_DTIM)
  737. mask2 |= AR_IMR_S2_DTIM;
  738. if (ints & ATH9K_INT_DTIMSYNC)
  739. mask2 |= AR_IMR_S2_DTIMSYNC;
  740. if (ints & ATH9K_INT_CABEND)
  741. mask2 |= AR_IMR_S2_CABEND;
  742. if (ints & ATH9K_INT_TSFOOR)
  743. mask2 |= AR_IMR_S2_TSFOOR;
  744. }
  745. if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
  746. mask |= AR_IMR_BCNMISC;
  747. if (ints & ATH9K_INT_GTT)
  748. mask2 |= AR_IMR_S2_GTT;
  749. if (ints & ATH9K_INT_CST)
  750. mask2 |= AR_IMR_S2_CST;
  751. }
  752. ath_dbg(common, INTERRUPT, "new IMR 0x%x\n", mask);
  753. REG_WRITE(ah, AR_IMR, mask);
  754. ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
  755. AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
  756. AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
  757. ah->imrs2_reg |= mask2;
  758. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  759. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  760. if (ints & ATH9K_INT_TIM_TIMER)
  761. REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  762. else
  763. REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  764. }
  765. return;
  766. }
  767. EXPORT_SYMBOL(ath9k_hw_set_interrupts);