mac.c 27 KB

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