mac.c 26 KB

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