mac.c 30 KB

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