mac.c 29 KB

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