mac.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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. (void) nseries;
  290. (void) rtsctsDuration;
  291. if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
  292. ds_ctl0 = ads->ds_ctl0;
  293. if (flags & ATH9K_TXDESC_RTSENA) {
  294. ds_ctl0 &= ~AR_CTSEnable;
  295. ds_ctl0 |= AR_RTSEnable;
  296. } else {
  297. ds_ctl0 &= ~AR_RTSEnable;
  298. ds_ctl0 |= AR_CTSEnable;
  299. }
  300. ads->ds_ctl0 = ds_ctl0;
  301. } else {
  302. ads->ds_ctl0 =
  303. (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
  304. }
  305. ads->ds_ctl2 = set11nTries(series, 0)
  306. | set11nTries(series, 1)
  307. | set11nTries(series, 2)
  308. | set11nTries(series, 3)
  309. | (durUpdateEn ? AR_DurUpdateEna : 0)
  310. | SM(0, AR_BurstDur);
  311. ads->ds_ctl3 = set11nRate(series, 0)
  312. | set11nRate(series, 1)
  313. | set11nRate(series, 2)
  314. | set11nRate(series, 3);
  315. ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
  316. | set11nPktDurRTSCTS(series, 1);
  317. ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
  318. | set11nPktDurRTSCTS(series, 3);
  319. ads->ds_ctl7 = set11nRateFlags(series, 0)
  320. | set11nRateFlags(series, 1)
  321. | set11nRateFlags(series, 2)
  322. | set11nRateFlags(series, 3)
  323. | SM(rtsctsRate, AR_RTSCTSRate);
  324. last_ads->ds_ctl2 = ads->ds_ctl2;
  325. last_ads->ds_ctl3 = ads->ds_ctl3;
  326. }
  327. void ath9k_hw_set11n_aggr_first(struct ath_hal *ah, struct ath_desc *ds,
  328. u32 aggrLen)
  329. {
  330. struct ar5416_desc *ads = AR5416DESC(ds);
  331. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  332. ads->ds_ctl6 &= ~AR_AggrLen;
  333. ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
  334. }
  335. void ath9k_hw_set11n_aggr_middle(struct ath_hal *ah, struct ath_desc *ds,
  336. u32 numDelims)
  337. {
  338. struct ar5416_desc *ads = AR5416DESC(ds);
  339. unsigned int ctl6;
  340. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  341. ctl6 = ads->ds_ctl6;
  342. ctl6 &= ~AR_PadDelim;
  343. ctl6 |= SM(numDelims, AR_PadDelim);
  344. ads->ds_ctl6 = ctl6;
  345. }
  346. void ath9k_hw_set11n_aggr_last(struct ath_hal *ah, struct ath_desc *ds)
  347. {
  348. struct ar5416_desc *ads = AR5416DESC(ds);
  349. ads->ds_ctl1 |= AR_IsAggr;
  350. ads->ds_ctl1 &= ~AR_MoreAggr;
  351. ads->ds_ctl6 &= ~AR_PadDelim;
  352. }
  353. void ath9k_hw_clr11n_aggr(struct ath_hal *ah, struct ath_desc *ds)
  354. {
  355. struct ar5416_desc *ads = AR5416DESC(ds);
  356. ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
  357. }
  358. void ath9k_hw_set11n_burstduration(struct ath_hal *ah, struct ath_desc *ds,
  359. u32 burstDuration)
  360. {
  361. struct ar5416_desc *ads = AR5416DESC(ds);
  362. ads->ds_ctl2 &= ~AR_BurstDur;
  363. ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
  364. }
  365. void ath9k_hw_set11n_virtualmorefrag(struct ath_hal *ah, struct ath_desc *ds,
  366. u32 vmf)
  367. {
  368. struct ar5416_desc *ads = AR5416DESC(ds);
  369. if (vmf)
  370. ads->ds_ctl0 |= AR_VirtMoreFrag;
  371. else
  372. ads->ds_ctl0 &= ~AR_VirtMoreFrag;
  373. }
  374. void ath9k_hw_gettxintrtxqs(struct ath_hal *ah, u32 *txqs)
  375. {
  376. struct ath_hal_5416 *ahp = AH5416(ah);
  377. *txqs &= ahp->ah_intrTxqs;
  378. ahp->ah_intrTxqs &= ~(*txqs);
  379. }
  380. bool ath9k_hw_set_txq_props(struct ath_hal *ah, int q,
  381. const struct ath9k_tx_queue_info *qinfo)
  382. {
  383. u32 cw;
  384. struct ath_hal_5416 *ahp = AH5416(ah);
  385. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  386. struct ath9k_tx_queue_info *qi;
  387. if (q >= pCap->total_queues) {
  388. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
  389. return false;
  390. }
  391. qi = &ahp->ah_txq[q];
  392. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  393. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
  394. return false;
  395. }
  396. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %p\n", qi);
  397. qi->tqi_ver = qinfo->tqi_ver;
  398. qi->tqi_subtype = qinfo->tqi_subtype;
  399. qi->tqi_qflags = qinfo->tqi_qflags;
  400. qi->tqi_priority = qinfo->tqi_priority;
  401. if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
  402. qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
  403. else
  404. qi->tqi_aifs = INIT_AIFS;
  405. if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
  406. cw = min(qinfo->tqi_cwmin, 1024U);
  407. qi->tqi_cwmin = 1;
  408. while (qi->tqi_cwmin < cw)
  409. qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
  410. } else
  411. qi->tqi_cwmin = qinfo->tqi_cwmin;
  412. if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
  413. cw = min(qinfo->tqi_cwmax, 1024U);
  414. qi->tqi_cwmax = 1;
  415. while (qi->tqi_cwmax < cw)
  416. qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
  417. } else
  418. qi->tqi_cwmax = INIT_CWMAX;
  419. if (qinfo->tqi_shretry != 0)
  420. qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
  421. else
  422. qi->tqi_shretry = INIT_SH_RETRY;
  423. if (qinfo->tqi_lgretry != 0)
  424. qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
  425. else
  426. qi->tqi_lgretry = INIT_LG_RETRY;
  427. qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
  428. qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
  429. qi->tqi_burstTime = qinfo->tqi_burstTime;
  430. qi->tqi_readyTime = qinfo->tqi_readyTime;
  431. switch (qinfo->tqi_subtype) {
  432. case ATH9K_WME_UPSD:
  433. if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
  434. qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
  435. break;
  436. default:
  437. break;
  438. }
  439. return true;
  440. }
  441. bool ath9k_hw_get_txq_props(struct ath_hal *ah, int q,
  442. struct ath9k_tx_queue_info *qinfo)
  443. {
  444. struct ath_hal_5416 *ahp = AH5416(ah);
  445. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  446. struct ath9k_tx_queue_info *qi;
  447. if (q >= pCap->total_queues) {
  448. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
  449. return false;
  450. }
  451. qi = &ahp->ah_txq[q];
  452. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  453. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
  454. return false;
  455. }
  456. qinfo->tqi_qflags = qi->tqi_qflags;
  457. qinfo->tqi_ver = qi->tqi_ver;
  458. qinfo->tqi_subtype = qi->tqi_subtype;
  459. qinfo->tqi_qflags = qi->tqi_qflags;
  460. qinfo->tqi_priority = qi->tqi_priority;
  461. qinfo->tqi_aifs = qi->tqi_aifs;
  462. qinfo->tqi_cwmin = qi->tqi_cwmin;
  463. qinfo->tqi_cwmax = qi->tqi_cwmax;
  464. qinfo->tqi_shretry = qi->tqi_shretry;
  465. qinfo->tqi_lgretry = qi->tqi_lgretry;
  466. qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
  467. qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
  468. qinfo->tqi_burstTime = qi->tqi_burstTime;
  469. qinfo->tqi_readyTime = qi->tqi_readyTime;
  470. return true;
  471. }
  472. int ath9k_hw_setuptxqueue(struct ath_hal *ah, enum ath9k_tx_queue type,
  473. const struct ath9k_tx_queue_info *qinfo)
  474. {
  475. struct ath_hal_5416 *ahp = AH5416(ah);
  476. struct ath9k_tx_queue_info *qi;
  477. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  478. int q;
  479. switch (type) {
  480. case ATH9K_TX_QUEUE_BEACON:
  481. q = pCap->total_queues - 1;
  482. break;
  483. case ATH9K_TX_QUEUE_CAB:
  484. q = pCap->total_queues - 2;
  485. break;
  486. case ATH9K_TX_QUEUE_PSPOLL:
  487. q = 1;
  488. break;
  489. case ATH9K_TX_QUEUE_UAPSD:
  490. q = pCap->total_queues - 3;
  491. break;
  492. case ATH9K_TX_QUEUE_DATA:
  493. for (q = 0; q < pCap->total_queues; q++)
  494. if (ahp->ah_txq[q].tqi_type ==
  495. ATH9K_TX_QUEUE_INACTIVE)
  496. break;
  497. if (q == pCap->total_queues) {
  498. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
  499. "no available tx queue\n");
  500. return -1;
  501. }
  502. break;
  503. default:
  504. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "bad tx queue type %u\n", type);
  505. return -1;
  506. }
  507. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q);
  508. qi = &ahp->ah_txq[q];
  509. if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
  510. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
  511. "tx queue %u already active\n", q);
  512. return -1;
  513. }
  514. memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
  515. qi->tqi_type = type;
  516. if (qinfo == NULL) {
  517. qi->tqi_qflags =
  518. TXQ_FLAG_TXOKINT_ENABLE
  519. | TXQ_FLAG_TXERRINT_ENABLE
  520. | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
  521. qi->tqi_aifs = INIT_AIFS;
  522. qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
  523. qi->tqi_cwmax = INIT_CWMAX;
  524. qi->tqi_shretry = INIT_SH_RETRY;
  525. qi->tqi_lgretry = INIT_LG_RETRY;
  526. qi->tqi_physCompBuf = 0;
  527. } else {
  528. qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
  529. (void) ath9k_hw_set_txq_props(ah, q, qinfo);
  530. }
  531. return q;
  532. }
  533. bool ath9k_hw_releasetxqueue(struct ath_hal *ah, u32 q)
  534. {
  535. struct ath_hal_5416 *ahp = AH5416(ah);
  536. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  537. struct ath9k_tx_queue_info *qi;
  538. if (q >= pCap->total_queues) {
  539. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
  540. return false;
  541. }
  542. qi = &ahp->ah_txq[q];
  543. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  544. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q);
  545. return false;
  546. }
  547. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "release queue %u\n", q);
  548. qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
  549. ahp->ah_txOkInterruptMask &= ~(1 << q);
  550. ahp->ah_txErrInterruptMask &= ~(1 << q);
  551. ahp->ah_txDescInterruptMask &= ~(1 << q);
  552. ahp->ah_txEolInterruptMask &= ~(1 << q);
  553. ahp->ah_txUrnInterruptMask &= ~(1 << q);
  554. ath9k_hw_set_txq_interrupts(ah, qi);
  555. return true;
  556. }
  557. bool ath9k_hw_resettxqueue(struct ath_hal *ah, u32 q)
  558. {
  559. struct ath_hal_5416 *ahp = AH5416(ah);
  560. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  561. struct ath9k_channel *chan = ah->ah_curchan;
  562. struct ath9k_tx_queue_info *qi;
  563. u32 cwMin, chanCwMin, value;
  564. if (q >= pCap->total_queues) {
  565. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
  566. return false;
  567. }
  568. qi = &ahp->ah_txq[q];
  569. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  570. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q);
  571. return true;
  572. }
  573. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "reset queue %u\n", q);
  574. if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
  575. if (chan && IS_CHAN_B(chan))
  576. chanCwMin = INIT_CWMIN_11B;
  577. else
  578. chanCwMin = INIT_CWMIN;
  579. for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
  580. } else
  581. cwMin = qi->tqi_cwmin;
  582. REG_WRITE(ah, AR_DLCL_IFS(q),
  583. SM(cwMin, AR_D_LCL_IFS_CWMIN) |
  584. SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
  585. SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
  586. REG_WRITE(ah, AR_DRETRY_LIMIT(q),
  587. SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
  588. SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
  589. SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
  590. REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
  591. REG_WRITE(ah, AR_DMISC(q),
  592. AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
  593. if (qi->tqi_cbrPeriod) {
  594. REG_WRITE(ah, AR_QCBRCFG(q),
  595. SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
  596. SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
  597. REG_WRITE(ah, AR_QMISC(q),
  598. REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
  599. (qi->tqi_cbrOverflowLimit ?
  600. AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
  601. }
  602. if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
  603. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  604. SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
  605. AR_Q_RDYTIMECFG_EN);
  606. }
  607. REG_WRITE(ah, AR_DCHNTIME(q),
  608. SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
  609. (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
  610. if (qi->tqi_burstTime
  611. && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
  612. REG_WRITE(ah, AR_QMISC(q),
  613. REG_READ(ah, AR_QMISC(q)) |
  614. AR_Q_MISC_RDYTIME_EXP_POLICY);
  615. }
  616. if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
  617. REG_WRITE(ah, AR_DMISC(q),
  618. REG_READ(ah, AR_DMISC(q)) |
  619. AR_D_MISC_POST_FR_BKOFF_DIS);
  620. }
  621. if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
  622. REG_WRITE(ah, AR_DMISC(q),
  623. REG_READ(ah, AR_DMISC(q)) |
  624. AR_D_MISC_FRAG_BKOFF_EN);
  625. }
  626. switch (qi->tqi_type) {
  627. case ATH9K_TX_QUEUE_BEACON:
  628. REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
  629. | AR_Q_MISC_FSP_DBA_GATED
  630. | AR_Q_MISC_BEACON_USE
  631. | AR_Q_MISC_CBR_INCR_DIS1);
  632. REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
  633. | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  634. AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
  635. | AR_D_MISC_BEACON_USE
  636. | AR_D_MISC_POST_FR_BKOFF_DIS);
  637. break;
  638. case ATH9K_TX_QUEUE_CAB:
  639. REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
  640. | AR_Q_MISC_FSP_DBA_GATED
  641. | AR_Q_MISC_CBR_INCR_DIS1
  642. | AR_Q_MISC_CBR_INCR_DIS0);
  643. value = (qi->tqi_readyTime -
  644. (ah->ah_config.sw_beacon_response_time -
  645. ah->ah_config.dma_beacon_response_time) -
  646. ah->ah_config.additional_swba_backoff) * 1024;
  647. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  648. value | AR_Q_RDYTIMECFG_EN);
  649. REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
  650. | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  651. AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
  652. break;
  653. case ATH9K_TX_QUEUE_PSPOLL:
  654. REG_WRITE(ah, AR_QMISC(q),
  655. REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
  656. break;
  657. case ATH9K_TX_QUEUE_UAPSD:
  658. REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
  659. AR_D_MISC_POST_FR_BKOFF_DIS);
  660. break;
  661. default:
  662. break;
  663. }
  664. if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
  665. REG_WRITE(ah, AR_DMISC(q),
  666. REG_READ(ah, AR_DMISC(q)) |
  667. SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
  668. AR_D_MISC_ARB_LOCKOUT_CNTRL) |
  669. AR_D_MISC_POST_FR_BKOFF_DIS);
  670. }
  671. if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
  672. ahp->ah_txOkInterruptMask |= 1 << q;
  673. else
  674. ahp->ah_txOkInterruptMask &= ~(1 << q);
  675. if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
  676. ahp->ah_txErrInterruptMask |= 1 << q;
  677. else
  678. ahp->ah_txErrInterruptMask &= ~(1 << q);
  679. if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
  680. ahp->ah_txDescInterruptMask |= 1 << q;
  681. else
  682. ahp->ah_txDescInterruptMask &= ~(1 << q);
  683. if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
  684. ahp->ah_txEolInterruptMask |= 1 << q;
  685. else
  686. ahp->ah_txEolInterruptMask &= ~(1 << q);
  687. if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
  688. ahp->ah_txUrnInterruptMask |= 1 << q;
  689. else
  690. ahp->ah_txUrnInterruptMask &= ~(1 << q);
  691. ath9k_hw_set_txq_interrupts(ah, qi);
  692. return true;
  693. }
  694. int ath9k_hw_rxprocdesc(struct ath_hal *ah, struct ath_desc *ds,
  695. u32 pa, struct ath_desc *nds, u64 tsf)
  696. {
  697. struct ar5416_desc ads;
  698. struct ar5416_desc *adsp = AR5416DESC(ds);
  699. u32 phyerr;
  700. if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
  701. return -EINPROGRESS;
  702. ads.u.rx = adsp->u.rx;
  703. ds->ds_rxstat.rs_status = 0;
  704. ds->ds_rxstat.rs_flags = 0;
  705. ds->ds_rxstat.rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
  706. ds->ds_rxstat.rs_tstamp = ads.AR_RcvTimestamp;
  707. ds->ds_rxstat.rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
  708. ds->ds_rxstat.rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00);
  709. ds->ds_rxstat.rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01);
  710. ds->ds_rxstat.rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02);
  711. ds->ds_rxstat.rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10);
  712. ds->ds_rxstat.rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11);
  713. ds->ds_rxstat.rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12);
  714. if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
  715. ds->ds_rxstat.rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
  716. else
  717. ds->ds_rxstat.rs_keyix = ATH9K_RXKEYIX_INVALID;
  718. ds->ds_rxstat.rs_rate = RXSTATUS_RATE(ah, (&ads));
  719. ds->ds_rxstat.rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
  720. ds->ds_rxstat.rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
  721. ds->ds_rxstat.rs_moreaggr =
  722. (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
  723. ds->ds_rxstat.rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
  724. ds->ds_rxstat.rs_flags =
  725. (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
  726. ds->ds_rxstat.rs_flags |=
  727. (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
  728. if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
  729. ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
  730. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
  731. ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_POST;
  732. if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
  733. ds->ds_rxstat.rs_flags |= ATH9K_RX_DECRYPT_BUSY;
  734. if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
  735. if (ads.ds_rxstatus8 & AR_CRCErr)
  736. ds->ds_rxstat.rs_status |= ATH9K_RXERR_CRC;
  737. else if (ads.ds_rxstatus8 & AR_PHYErr) {
  738. ds->ds_rxstat.rs_status |= ATH9K_RXERR_PHY;
  739. phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
  740. ds->ds_rxstat.rs_phyerr = phyerr;
  741. } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
  742. ds->ds_rxstat.rs_status |= ATH9K_RXERR_DECRYPT;
  743. else if (ads.ds_rxstatus8 & AR_MichaelErr)
  744. ds->ds_rxstat.rs_status |= ATH9K_RXERR_MIC;
  745. }
  746. return 0;
  747. }
  748. bool ath9k_hw_setuprxdesc(struct ath_hal *ah, struct ath_desc *ds,
  749. u32 size, u32 flags)
  750. {
  751. struct ar5416_desc *ads = AR5416DESC(ds);
  752. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  753. ads->ds_ctl1 = size & AR_BufLen;
  754. if (flags & ATH9K_RXDESC_INTREQ)
  755. ads->ds_ctl1 |= AR_RxIntrReq;
  756. ads->ds_rxstatus8 &= ~AR_RxDone;
  757. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  758. memset(&(ads->u), 0, sizeof(ads->u));
  759. return true;
  760. }
  761. bool ath9k_hw_setrxabort(struct ath_hal *ah, bool set)
  762. {
  763. u32 reg;
  764. if (set) {
  765. REG_SET_BIT(ah, AR_DIAG_SW,
  766. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  767. if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE, 0)) {
  768. REG_CLR_BIT(ah, AR_DIAG_SW,
  769. (AR_DIAG_RX_DIS |
  770. AR_DIAG_RX_ABORT));
  771. reg = REG_READ(ah, AR_OBS_BUS_1);
  772. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  773. "rx failed to go idle in 10 ms RXSM=0x%x\n", reg);
  774. return false;
  775. }
  776. } else {
  777. REG_CLR_BIT(ah, AR_DIAG_SW,
  778. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  779. }
  780. return true;
  781. }
  782. void ath9k_hw_putrxbuf(struct ath_hal *ah, u32 rxdp)
  783. {
  784. REG_WRITE(ah, AR_RXDP, rxdp);
  785. }
  786. void ath9k_hw_rxena(struct ath_hal *ah)
  787. {
  788. REG_WRITE(ah, AR_CR, AR_CR_RXE);
  789. }
  790. void ath9k_hw_startpcureceive(struct ath_hal *ah)
  791. {
  792. ath9k_enable_mib_counters(ah);
  793. ath9k_ani_reset(ah);
  794. REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  795. }
  796. void ath9k_hw_stoppcurecv(struct ath_hal *ah)
  797. {
  798. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
  799. ath9k_hw_disable_mib_counters(ah);
  800. }
  801. bool ath9k_hw_stopdmarecv(struct ath_hal *ah)
  802. {
  803. REG_WRITE(ah, AR_CR, AR_CR_RXD);
  804. if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0)) {
  805. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
  806. "dma failed to stop in 10ms\n"
  807. "AR_CR=0x%08x\nAR_DIAG_SW=0x%08x\n",
  808. REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW));
  809. return false;
  810. } else {
  811. return true;
  812. }
  813. }