mac.c 27 KB

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