mac.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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 "ath9k.h"
  17. static void ath9k_hw_set_txq_interrupts(struct ath_hw *ah,
  18. struct ath9k_tx_queue_info *qi)
  19. {
  20. DPRINTF(ah->ah_sc, 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. REG_RMW_FIELD(ah, AR_IMR_S2,
  32. AR_IMR_S2_QCU_TXURN, ah->txurn_interrupt_mask);
  33. }
  34. u32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q)
  35. {
  36. return REG_READ(ah, AR_QTXDP(q));
  37. }
  38. bool ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp)
  39. {
  40. REG_WRITE(ah, AR_QTXDP(q), txdp);
  41. return true;
  42. }
  43. bool ath9k_hw_txstart(struct ath_hw *ah, u32 q)
  44. {
  45. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q);
  46. REG_WRITE(ah, AR_Q_TXE, 1 << q);
  47. return true;
  48. }
  49. u32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q)
  50. {
  51. u32 npend;
  52. npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
  53. if (npend == 0) {
  54. if (REG_READ(ah, AR_Q_TXE) & (1 << q))
  55. npend = 1;
  56. }
  57. return npend;
  58. }
  59. bool ath9k_hw_updatetxtriglevel(struct ath_hw *ah, bool bIncTrigLevel)
  60. {
  61. u32 txcfg, curLevel, newLevel;
  62. enum ath9k_int omask;
  63. if (ah->tx_trig_level >= MAX_TX_FIFO_THRESHOLD)
  64. return false;
  65. omask = ath9k_hw_set_interrupts(ah, ah->mask_reg & ~ATH9K_INT_GLOBAL);
  66. txcfg = REG_READ(ah, AR_TXCFG);
  67. curLevel = MS(txcfg, AR_FTRIG);
  68. newLevel = curLevel;
  69. if (bIncTrigLevel) {
  70. if (curLevel < MAX_TX_FIFO_THRESHOLD)
  71. newLevel++;
  72. } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
  73. newLevel--;
  74. if (newLevel != curLevel)
  75. REG_WRITE(ah, AR_TXCFG,
  76. (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
  77. ath9k_hw_set_interrupts(ah, omask);
  78. ah->tx_trig_level = newLevel;
  79. return newLevel != curLevel;
  80. }
  81. bool ath9k_hw_stoptxdma(struct ath_hw *ah, u32 q)
  82. {
  83. #define ATH9K_TX_STOP_DMA_TIMEOUT 4000 /* usec */
  84. #define ATH9K_TIME_QUANTUM 100 /* usec */
  85. struct ath9k_hw_capabilities *pCap = &ah->caps;
  86. struct ath9k_tx_queue_info *qi;
  87. u32 tsfLow, j, wait;
  88. u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
  89. if (q >= pCap->total_queues) {
  90. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
  91. return false;
  92. }
  93. qi = &ah->txq[q];
  94. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  95. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
  96. return false;
  97. }
  98. REG_WRITE(ah, AR_Q_TXD, 1 << q);
  99. for (wait = wait_time; wait != 0; wait--) {
  100. if (ath9k_hw_numtxpending(ah, q) == 0)
  101. break;
  102. udelay(ATH9K_TIME_QUANTUM);
  103. }
  104. if (ath9k_hw_numtxpending(ah, q)) {
  105. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
  106. "%s: Num of pending TX Frames %d on Q %d\n",
  107. __func__, ath9k_hw_numtxpending(ah, q), q);
  108. for (j = 0; j < 2; j++) {
  109. tsfLow = REG_READ(ah, AR_TSF_L32);
  110. REG_WRITE(ah, AR_QUIET2,
  111. SM(10, AR_QUIET2_QUIET_DUR));
  112. REG_WRITE(ah, AR_QUIET_PERIOD, 100);
  113. REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
  114. REG_SET_BIT(ah, AR_TIMER_MODE,
  115. AR_QUIET_TIMER_EN);
  116. if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10))
  117. break;
  118. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
  119. "TSF have moved while trying to set "
  120. "quiet time TSF: 0x%08x\n", tsfLow);
  121. }
  122. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
  123. udelay(200);
  124. REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);
  125. wait = wait_time;
  126. while (ath9k_hw_numtxpending(ah, q)) {
  127. if ((--wait) == 0) {
  128. DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
  129. "Failed to stop Tx DMA in 100 "
  130. "msec after killing last frame\n");
  131. break;
  132. }
  133. udelay(ATH9K_TIME_QUANTUM);
  134. }
  135. REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
  136. }
  137. REG_WRITE(ah, AR_Q_TXD, 0);
  138. return wait != 0;
  139. #undef ATH9K_TX_STOP_DMA_TIMEOUT
  140. #undef ATH9K_TIME_QUANTUM
  141. }
  142. bool ath9k_hw_filltxdesc(struct ath_hw *ah, struct ath_desc *ds,
  143. u32 segLen, bool firstSeg,
  144. bool lastSeg, const struct ath_desc *ds0)
  145. {
  146. struct ar5416_desc *ads = AR5416DESC(ds);
  147. if (firstSeg) {
  148. ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
  149. } else if (lastSeg) {
  150. ads->ds_ctl0 = 0;
  151. ads->ds_ctl1 = segLen;
  152. ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
  153. ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
  154. } else {
  155. ads->ds_ctl0 = 0;
  156. ads->ds_ctl1 = segLen | AR_TxMore;
  157. ads->ds_ctl2 = 0;
  158. ads->ds_ctl3 = 0;
  159. }
  160. ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
  161. ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
  162. ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
  163. ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
  164. ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
  165. return true;
  166. }
  167. void ath9k_hw_cleartxdesc(struct ath_hw *ah, struct ath_desc *ds)
  168. {
  169. struct ar5416_desc *ads = AR5416DESC(ds);
  170. ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
  171. ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
  172. ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
  173. ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
  174. ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
  175. }
  176. int ath9k_hw_txprocdesc(struct ath_hw *ah, struct ath_desc *ds)
  177. {
  178. struct ar5416_desc *ads = AR5416DESC(ds);
  179. if ((ads->ds_txstatus9 & AR_TxDone) == 0)
  180. return -EINPROGRESS;
  181. ds->ds_txstat.ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
  182. ds->ds_txstat.ts_tstamp = ads->AR_SendTimestamp;
  183. ds->ds_txstat.ts_status = 0;
  184. ds->ds_txstat.ts_flags = 0;
  185. if (ads->ds_txstatus1 & AR_ExcessiveRetries)
  186. ds->ds_txstat.ts_status |= ATH9K_TXERR_XRETRY;
  187. if (ads->ds_txstatus1 & AR_Filtered)
  188. ds->ds_txstat.ts_status |= ATH9K_TXERR_FILT;
  189. if (ads->ds_txstatus1 & AR_FIFOUnderrun) {
  190. ds->ds_txstat.ts_status |= ATH9K_TXERR_FIFO;
  191. ath9k_hw_updatetxtriglevel(ah, true);
  192. }
  193. if (ads->ds_txstatus9 & AR_TxOpExceeded)
  194. ds->ds_txstat.ts_status |= ATH9K_TXERR_XTXOP;
  195. if (ads->ds_txstatus1 & AR_TxTimerExpired)
  196. ds->ds_txstat.ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
  197. if (ads->ds_txstatus1 & AR_DescCfgErr)
  198. ds->ds_txstat.ts_flags |= ATH9K_TX_DESC_CFG_ERR;
  199. if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
  200. ds->ds_txstat.ts_flags |= ATH9K_TX_DATA_UNDERRUN;
  201. ath9k_hw_updatetxtriglevel(ah, true);
  202. }
  203. if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
  204. ds->ds_txstat.ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
  205. ath9k_hw_updatetxtriglevel(ah, true);
  206. }
  207. if (ads->ds_txstatus0 & AR_TxBaStatus) {
  208. ds->ds_txstat.ts_flags |= ATH9K_TX_BA;
  209. ds->ds_txstat.ba_low = ads->AR_BaBitmapLow;
  210. ds->ds_txstat.ba_high = ads->AR_BaBitmapHigh;
  211. }
  212. ds->ds_txstat.ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
  213. switch (ds->ds_txstat.ts_rateindex) {
  214. case 0:
  215. ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
  216. break;
  217. case 1:
  218. ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
  219. break;
  220. case 2:
  221. ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
  222. break;
  223. case 3:
  224. ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
  225. break;
  226. }
  227. ds->ds_txstat.ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
  228. ds->ds_txstat.ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
  229. ds->ds_txstat.ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
  230. ds->ds_txstat.ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
  231. ds->ds_txstat.ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
  232. ds->ds_txstat.ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
  233. ds->ds_txstat.ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
  234. ds->ds_txstat.evm0 = ads->AR_TxEVM0;
  235. ds->ds_txstat.evm1 = ads->AR_TxEVM1;
  236. ds->ds_txstat.evm2 = ads->AR_TxEVM2;
  237. ds->ds_txstat.ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
  238. ds->ds_txstat.ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
  239. ds->ds_txstat.ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
  240. ds->ds_txstat.ts_antenna = 0;
  241. return 0;
  242. }
  243. void ath9k_hw_set11n_txdesc(struct ath_hw *ah, struct ath_desc *ds,
  244. u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
  245. u32 keyIx, enum ath9k_key_type keyType, u32 flags)
  246. {
  247. struct ar5416_desc *ads = AR5416DESC(ds);
  248. txPower += ah->txpower_indexoffset;
  249. if (txPower > 63)
  250. txPower = 63;
  251. ads->ds_ctl0 = (pktLen & AR_FrameLen)
  252. | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  253. | SM(txPower, AR_XmitPower)
  254. | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  255. | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
  256. | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
  257. | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
  258. ads->ds_ctl1 =
  259. (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
  260. | SM(type, AR_FrameType)
  261. | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
  262. | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
  263. | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
  264. ads->ds_ctl6 = SM(keyType, AR_EncrType);
  265. if (AR_SREV_9285(ah)) {
  266. ads->ds_ctl8 = 0;
  267. ads->ds_ctl9 = 0;
  268. ads->ds_ctl10 = 0;
  269. ads->ds_ctl11 = 0;
  270. }
  271. }
  272. void ath9k_hw_set11n_ratescenario(struct ath_hw *ah, struct ath_desc *ds,
  273. struct ath_desc *lastds,
  274. u32 durUpdateEn, u32 rtsctsRate,
  275. u32 rtsctsDuration,
  276. struct ath9k_11n_rate_series series[],
  277. u32 nseries, u32 flags)
  278. {
  279. struct ar5416_desc *ads = AR5416DESC(ds);
  280. struct ar5416_desc *last_ads = AR5416DESC(lastds);
  281. u32 ds_ctl0;
  282. if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
  283. ds_ctl0 = ads->ds_ctl0;
  284. if (flags & ATH9K_TXDESC_RTSENA) {
  285. ds_ctl0 &= ~AR_CTSEnable;
  286. ds_ctl0 |= AR_RTSEnable;
  287. } else {
  288. ds_ctl0 &= ~AR_RTSEnable;
  289. ds_ctl0 |= AR_CTSEnable;
  290. }
  291. ads->ds_ctl0 = ds_ctl0;
  292. } else {
  293. ads->ds_ctl0 =
  294. (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
  295. }
  296. ads->ds_ctl2 = set11nTries(series, 0)
  297. | set11nTries(series, 1)
  298. | set11nTries(series, 2)
  299. | set11nTries(series, 3)
  300. | (durUpdateEn ? AR_DurUpdateEna : 0)
  301. | SM(0, AR_BurstDur);
  302. ads->ds_ctl3 = set11nRate(series, 0)
  303. | set11nRate(series, 1)
  304. | set11nRate(series, 2)
  305. | set11nRate(series, 3);
  306. ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
  307. | set11nPktDurRTSCTS(series, 1);
  308. ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
  309. | set11nPktDurRTSCTS(series, 3);
  310. ads->ds_ctl7 = set11nRateFlags(series, 0)
  311. | set11nRateFlags(series, 1)
  312. | set11nRateFlags(series, 2)
  313. | set11nRateFlags(series, 3)
  314. | SM(rtsctsRate, AR_RTSCTSRate);
  315. last_ads->ds_ctl2 = ads->ds_ctl2;
  316. last_ads->ds_ctl3 = ads->ds_ctl3;
  317. }
  318. void ath9k_hw_set11n_aggr_first(struct ath_hw *ah, struct ath_desc *ds,
  319. u32 aggrLen)
  320. {
  321. struct ar5416_desc *ads = AR5416DESC(ds);
  322. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  323. ads->ds_ctl6 &= ~AR_AggrLen;
  324. ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
  325. }
  326. void ath9k_hw_set11n_aggr_middle(struct ath_hw *ah, struct ath_desc *ds,
  327. u32 numDelims)
  328. {
  329. struct ar5416_desc *ads = AR5416DESC(ds);
  330. unsigned int ctl6;
  331. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  332. ctl6 = ads->ds_ctl6;
  333. ctl6 &= ~AR_PadDelim;
  334. ctl6 |= SM(numDelims, AR_PadDelim);
  335. ads->ds_ctl6 = ctl6;
  336. }
  337. void ath9k_hw_set11n_aggr_last(struct ath_hw *ah, struct ath_desc *ds)
  338. {
  339. struct ar5416_desc *ads = AR5416DESC(ds);
  340. ads->ds_ctl1 |= AR_IsAggr;
  341. ads->ds_ctl1 &= ~AR_MoreAggr;
  342. ads->ds_ctl6 &= ~AR_PadDelim;
  343. }
  344. void ath9k_hw_clr11n_aggr(struct ath_hw *ah, struct ath_desc *ds)
  345. {
  346. struct ar5416_desc *ads = AR5416DESC(ds);
  347. ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
  348. }
  349. void ath9k_hw_set11n_burstduration(struct ath_hw *ah, struct ath_desc *ds,
  350. u32 burstDuration)
  351. {
  352. struct ar5416_desc *ads = AR5416DESC(ds);
  353. ads->ds_ctl2 &= ~AR_BurstDur;
  354. ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
  355. }
  356. void ath9k_hw_set11n_virtualmorefrag(struct ath_hw *ah, struct ath_desc *ds,
  357. u32 vmf)
  358. {
  359. struct ar5416_desc *ads = AR5416DESC(ds);
  360. if (vmf)
  361. ads->ds_ctl0 |= AR_VirtMoreFrag;
  362. else
  363. ads->ds_ctl0 &= ~AR_VirtMoreFrag;
  364. }
  365. void ath9k_hw_gettxintrtxqs(struct ath_hw *ah, u32 *txqs)
  366. {
  367. *txqs &= ah->intr_txqs;
  368. ah->intr_txqs &= ~(*txqs);
  369. }
  370. bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
  371. const struct ath9k_tx_queue_info *qinfo)
  372. {
  373. u32 cw;
  374. struct ath9k_hw_capabilities *pCap = &ah->caps;
  375. struct ath9k_tx_queue_info *qi;
  376. if (q >= pCap->total_queues) {
  377. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
  378. return false;
  379. }
  380. qi = &ah->txq[q];
  381. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  382. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
  383. return false;
  384. }
  385. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %p\n", qi);
  386. qi->tqi_ver = qinfo->tqi_ver;
  387. qi->tqi_subtype = qinfo->tqi_subtype;
  388. qi->tqi_qflags = qinfo->tqi_qflags;
  389. qi->tqi_priority = qinfo->tqi_priority;
  390. if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
  391. qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
  392. else
  393. qi->tqi_aifs = INIT_AIFS;
  394. if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
  395. cw = min(qinfo->tqi_cwmin, 1024U);
  396. qi->tqi_cwmin = 1;
  397. while (qi->tqi_cwmin < cw)
  398. qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
  399. } else
  400. qi->tqi_cwmin = qinfo->tqi_cwmin;
  401. if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
  402. cw = min(qinfo->tqi_cwmax, 1024U);
  403. qi->tqi_cwmax = 1;
  404. while (qi->tqi_cwmax < cw)
  405. qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
  406. } else
  407. qi->tqi_cwmax = INIT_CWMAX;
  408. if (qinfo->tqi_shretry != 0)
  409. qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
  410. else
  411. qi->tqi_shretry = INIT_SH_RETRY;
  412. if (qinfo->tqi_lgretry != 0)
  413. qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
  414. else
  415. qi->tqi_lgretry = INIT_LG_RETRY;
  416. qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
  417. qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
  418. qi->tqi_burstTime = qinfo->tqi_burstTime;
  419. qi->tqi_readyTime = qinfo->tqi_readyTime;
  420. switch (qinfo->tqi_subtype) {
  421. case ATH9K_WME_UPSD:
  422. if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
  423. qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
  424. break;
  425. default:
  426. break;
  427. }
  428. return true;
  429. }
  430. bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
  431. struct ath9k_tx_queue_info *qinfo)
  432. {
  433. struct ath9k_hw_capabilities *pCap = &ah->caps;
  434. struct ath9k_tx_queue_info *qi;
  435. if (q >= pCap->total_queues) {
  436. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
  437. return false;
  438. }
  439. qi = &ah->txq[q];
  440. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  441. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
  442. return false;
  443. }
  444. qinfo->tqi_qflags = qi->tqi_qflags;
  445. qinfo->tqi_ver = qi->tqi_ver;
  446. qinfo->tqi_subtype = qi->tqi_subtype;
  447. qinfo->tqi_qflags = qi->tqi_qflags;
  448. qinfo->tqi_priority = qi->tqi_priority;
  449. qinfo->tqi_aifs = qi->tqi_aifs;
  450. qinfo->tqi_cwmin = qi->tqi_cwmin;
  451. qinfo->tqi_cwmax = qi->tqi_cwmax;
  452. qinfo->tqi_shretry = qi->tqi_shretry;
  453. qinfo->tqi_lgretry = qi->tqi_lgretry;
  454. qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
  455. qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
  456. qinfo->tqi_burstTime = qi->tqi_burstTime;
  457. qinfo->tqi_readyTime = qi->tqi_readyTime;
  458. return true;
  459. }
  460. int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
  461. const struct ath9k_tx_queue_info *qinfo)
  462. {
  463. struct ath9k_tx_queue_info *qi;
  464. struct ath9k_hw_capabilities *pCap = &ah->caps;
  465. int q;
  466. switch (type) {
  467. case ATH9K_TX_QUEUE_BEACON:
  468. q = pCap->total_queues - 1;
  469. break;
  470. case ATH9K_TX_QUEUE_CAB:
  471. q = pCap->total_queues - 2;
  472. break;
  473. case ATH9K_TX_QUEUE_PSPOLL:
  474. q = 1;
  475. break;
  476. case ATH9K_TX_QUEUE_UAPSD:
  477. q = pCap->total_queues - 3;
  478. break;
  479. case ATH9K_TX_QUEUE_DATA:
  480. for (q = 0; q < pCap->total_queues; q++)
  481. if (ah->txq[q].tqi_type ==
  482. ATH9K_TX_QUEUE_INACTIVE)
  483. break;
  484. if (q == pCap->total_queues) {
  485. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
  486. "no available tx queue\n");
  487. return -1;
  488. }
  489. break;
  490. default:
  491. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "bad tx queue type %u\n", type);
  492. return -1;
  493. }
  494. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q);
  495. qi = &ah->txq[q];
  496. if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
  497. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
  498. "tx queue %u already active\n", q);
  499. return -1;
  500. }
  501. memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
  502. qi->tqi_type = type;
  503. if (qinfo == NULL) {
  504. qi->tqi_qflags =
  505. TXQ_FLAG_TXOKINT_ENABLE
  506. | TXQ_FLAG_TXERRINT_ENABLE
  507. | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
  508. qi->tqi_aifs = INIT_AIFS;
  509. qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
  510. qi->tqi_cwmax = INIT_CWMAX;
  511. qi->tqi_shretry = INIT_SH_RETRY;
  512. qi->tqi_lgretry = INIT_LG_RETRY;
  513. qi->tqi_physCompBuf = 0;
  514. } else {
  515. qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
  516. (void) ath9k_hw_set_txq_props(ah, q, qinfo);
  517. }
  518. return q;
  519. }
  520. bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
  521. {
  522. struct ath9k_hw_capabilities *pCap = &ah->caps;
  523. struct ath9k_tx_queue_info *qi;
  524. if (q >= pCap->total_queues) {
  525. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
  526. return false;
  527. }
  528. qi = &ah->txq[q];
  529. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  530. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q);
  531. return false;
  532. }
  533. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "release queue %u\n", q);
  534. qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
  535. ah->txok_interrupt_mask &= ~(1 << q);
  536. ah->txerr_interrupt_mask &= ~(1 << q);
  537. ah->txdesc_interrupt_mask &= ~(1 << q);
  538. ah->txeol_interrupt_mask &= ~(1 << q);
  539. ah->txurn_interrupt_mask &= ~(1 << q);
  540. ath9k_hw_set_txq_interrupts(ah, qi);
  541. return true;
  542. }
  543. bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
  544. {
  545. struct ath9k_hw_capabilities *pCap = &ah->caps;
  546. struct ath9k_channel *chan = ah->curchan;
  547. struct ath9k_tx_queue_info *qi;
  548. u32 cwMin, chanCwMin, value;
  549. if (q >= pCap->total_queues) {
  550. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
  551. return false;
  552. }
  553. qi = &ah->txq[q];
  554. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  555. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q);
  556. return true;
  557. }
  558. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "reset queue %u\n", q);
  559. if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
  560. if (chan && IS_CHAN_B(chan))
  561. chanCwMin = INIT_CWMIN_11B;
  562. else
  563. chanCwMin = INIT_CWMIN;
  564. for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
  565. } else
  566. cwMin = qi->tqi_cwmin;
  567. REG_WRITE(ah, AR_DLCL_IFS(q),
  568. SM(cwMin, AR_D_LCL_IFS_CWMIN) |
  569. SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
  570. SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
  571. REG_WRITE(ah, AR_DRETRY_LIMIT(q),
  572. SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
  573. SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
  574. SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
  575. REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
  576. REG_WRITE(ah, AR_DMISC(q),
  577. AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
  578. if (qi->tqi_cbrPeriod) {
  579. REG_WRITE(ah, AR_QCBRCFG(q),
  580. SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
  581. SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
  582. REG_WRITE(ah, AR_QMISC(q),
  583. REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
  584. (qi->tqi_cbrOverflowLimit ?
  585. AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
  586. }
  587. if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
  588. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  589. SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
  590. AR_Q_RDYTIMECFG_EN);
  591. }
  592. REG_WRITE(ah, AR_DCHNTIME(q),
  593. SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
  594. (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
  595. if (qi->tqi_burstTime
  596. && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
  597. REG_WRITE(ah, AR_QMISC(q),
  598. REG_READ(ah, AR_QMISC(q)) |
  599. AR_Q_MISC_RDYTIME_EXP_POLICY);
  600. }
  601. if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
  602. REG_WRITE(ah, AR_DMISC(q),
  603. REG_READ(ah, AR_DMISC(q)) |
  604. AR_D_MISC_POST_FR_BKOFF_DIS);
  605. }
  606. if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
  607. REG_WRITE(ah, AR_DMISC(q),
  608. REG_READ(ah, AR_DMISC(q)) |
  609. AR_D_MISC_FRAG_BKOFF_EN);
  610. }
  611. switch (qi->tqi_type) {
  612. case ATH9K_TX_QUEUE_BEACON:
  613. REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
  614. | AR_Q_MISC_FSP_DBA_GATED
  615. | AR_Q_MISC_BEACON_USE
  616. | AR_Q_MISC_CBR_INCR_DIS1);
  617. REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
  618. | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  619. AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
  620. | AR_D_MISC_BEACON_USE
  621. | AR_D_MISC_POST_FR_BKOFF_DIS);
  622. break;
  623. case ATH9K_TX_QUEUE_CAB:
  624. REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
  625. | AR_Q_MISC_FSP_DBA_GATED
  626. | AR_Q_MISC_CBR_INCR_DIS1
  627. | AR_Q_MISC_CBR_INCR_DIS0);
  628. value = (qi->tqi_readyTime -
  629. (ah->config.sw_beacon_response_time -
  630. ah->config.dma_beacon_response_time) -
  631. ah->config.additional_swba_backoff) * 1024;
  632. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  633. value | AR_Q_RDYTIMECFG_EN);
  634. REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
  635. | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  636. AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
  637. break;
  638. case ATH9K_TX_QUEUE_PSPOLL:
  639. REG_WRITE(ah, AR_QMISC(q),
  640. REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
  641. break;
  642. case ATH9K_TX_QUEUE_UAPSD:
  643. REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
  644. AR_D_MISC_POST_FR_BKOFF_DIS);
  645. break;
  646. default:
  647. break;
  648. }
  649. if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
  650. REG_WRITE(ah, AR_DMISC(q),
  651. REG_READ(ah, AR_DMISC(q)) |
  652. SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
  653. AR_D_MISC_ARB_LOCKOUT_CNTRL) |
  654. AR_D_MISC_POST_FR_BKOFF_DIS);
  655. }
  656. if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
  657. ah->txok_interrupt_mask |= 1 << q;
  658. else
  659. ah->txok_interrupt_mask &= ~(1 << q);
  660. if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
  661. ah->txerr_interrupt_mask |= 1 << q;
  662. else
  663. ah->txerr_interrupt_mask &= ~(1 << q);
  664. if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
  665. ah->txdesc_interrupt_mask |= 1 << q;
  666. else
  667. ah->txdesc_interrupt_mask &= ~(1 << q);
  668. if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
  669. ah->txeol_interrupt_mask |= 1 << q;
  670. else
  671. ah->txeol_interrupt_mask &= ~(1 << q);
  672. if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
  673. ah->txurn_interrupt_mask |= 1 << q;
  674. else
  675. ah->txurn_interrupt_mask &= ~(1 << q);
  676. ath9k_hw_set_txq_interrupts(ah, qi);
  677. return true;
  678. }
  679. int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
  680. u32 pa, struct ath_desc *nds, u64 tsf)
  681. {
  682. struct ar5416_desc ads;
  683. struct ar5416_desc *adsp = AR5416DESC(ds);
  684. u32 phyerr;
  685. if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
  686. return -EINPROGRESS;
  687. ads.u.rx = adsp->u.rx;
  688. ds->ds_rxstat.rs_status = 0;
  689. ds->ds_rxstat.rs_flags = 0;
  690. ds->ds_rxstat.rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
  691. ds->ds_rxstat.rs_tstamp = ads.AR_RcvTimestamp;
  692. ds->ds_rxstat.rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
  693. ds->ds_rxstat.rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00);
  694. ds->ds_rxstat.rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01);
  695. ds->ds_rxstat.rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02);
  696. ds->ds_rxstat.rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10);
  697. ds->ds_rxstat.rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11);
  698. ds->ds_rxstat.rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12);
  699. if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
  700. ds->ds_rxstat.rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
  701. else
  702. ds->ds_rxstat.rs_keyix = ATH9K_RXKEYIX_INVALID;
  703. ds->ds_rxstat.rs_rate = RXSTATUS_RATE(ah, (&ads));
  704. ds->ds_rxstat.rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
  705. ds->ds_rxstat.rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
  706. ds->ds_rxstat.rs_moreaggr =
  707. (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
  708. ds->ds_rxstat.rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
  709. ds->ds_rxstat.rs_flags =
  710. (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
  711. ds->ds_rxstat.rs_flags |=
  712. (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
  713. if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
  714. ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
  715. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
  716. ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_POST;
  717. if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
  718. ds->ds_rxstat.rs_flags |= ATH9K_RX_DECRYPT_BUSY;
  719. if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
  720. if (ads.ds_rxstatus8 & AR_CRCErr)
  721. ds->ds_rxstat.rs_status |= ATH9K_RXERR_CRC;
  722. else if (ads.ds_rxstatus8 & AR_PHYErr) {
  723. ds->ds_rxstat.rs_status |= ATH9K_RXERR_PHY;
  724. phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
  725. ds->ds_rxstat.rs_phyerr = phyerr;
  726. } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
  727. ds->ds_rxstat.rs_status |= ATH9K_RXERR_DECRYPT;
  728. else if (ads.ds_rxstatus8 & AR_MichaelErr)
  729. ds->ds_rxstat.rs_status |= ATH9K_RXERR_MIC;
  730. }
  731. return 0;
  732. }
  733. bool ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
  734. u32 size, u32 flags)
  735. {
  736. struct ar5416_desc *ads = AR5416DESC(ds);
  737. struct ath9k_hw_capabilities *pCap = &ah->caps;
  738. ads->ds_ctl1 = size & AR_BufLen;
  739. if (flags & ATH9K_RXDESC_INTREQ)
  740. ads->ds_ctl1 |= AR_RxIntrReq;
  741. ads->ds_rxstatus8 &= ~AR_RxDone;
  742. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  743. memset(&(ads->u), 0, sizeof(ads->u));
  744. return true;
  745. }
  746. bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
  747. {
  748. u32 reg;
  749. if (set) {
  750. REG_SET_BIT(ah, AR_DIAG_SW,
  751. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  752. if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
  753. 0, AH_WAIT_TIMEOUT)) {
  754. REG_CLR_BIT(ah, AR_DIAG_SW,
  755. (AR_DIAG_RX_DIS |
  756. AR_DIAG_RX_ABORT));
  757. reg = REG_READ(ah, AR_OBS_BUS_1);
  758. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  759. "rx failed to go idle in 10 ms RXSM=0x%x\n", reg);
  760. return false;
  761. }
  762. } else {
  763. REG_CLR_BIT(ah, AR_DIAG_SW,
  764. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  765. }
  766. return true;
  767. }
  768. void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
  769. {
  770. REG_WRITE(ah, AR_RXDP, rxdp);
  771. }
  772. void ath9k_hw_rxena(struct ath_hw *ah)
  773. {
  774. REG_WRITE(ah, AR_CR, AR_CR_RXE);
  775. }
  776. void ath9k_hw_startpcureceive(struct ath_hw *ah)
  777. {
  778. ath9k_enable_mib_counters(ah);
  779. ath9k_ani_reset(ah);
  780. REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  781. }
  782. void ath9k_hw_stoppcurecv(struct ath_hw *ah)
  783. {
  784. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
  785. ath9k_hw_disable_mib_counters(ah);
  786. }
  787. bool ath9k_hw_stopdmarecv(struct ath_hw *ah)
  788. {
  789. #define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
  790. #define AH_RX_TIME_QUANTUM 100 /* usec */
  791. int i;
  792. REG_WRITE(ah, AR_CR, AR_CR_RXD);
  793. /* Wait for rx enable bit to go low */
  794. for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
  795. if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
  796. break;
  797. udelay(AH_TIME_QUANTUM);
  798. }
  799. if (i == 0) {
  800. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
  801. "dma failed to stop in %d ms "
  802. "AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
  803. AH_RX_STOP_DMA_TIMEOUT / 1000,
  804. REG_READ(ah, AR_CR),
  805. REG_READ(ah, AR_DIAG_SW));
  806. return false;
  807. } else {
  808. return true;
  809. }
  810. #undef AH_RX_TIME_QUANTUM
  811. #undef AH_RX_STOP_DMA_TIMEOUT
  812. }