mac.c 27 KB

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