mac.c 26 KB

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