mac.c 27 KB

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