mac.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  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. dma_addr_t buf_addr)
  189. {
  190. struct ar5416_desc *ads = AR5416DESC(ds);
  191. ads->ds_data = buf_addr;
  192. if (firstSeg) {
  193. ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
  194. } else if (lastSeg) {
  195. ads->ds_ctl0 = 0;
  196. ads->ds_ctl1 = segLen;
  197. ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
  198. ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
  199. } else {
  200. ads->ds_ctl0 = 0;
  201. ads->ds_ctl1 = segLen | AR_TxMore;
  202. ads->ds_ctl2 = 0;
  203. ads->ds_ctl3 = 0;
  204. }
  205. ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
  206. ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
  207. ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
  208. ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
  209. ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
  210. }
  211. EXPORT_SYMBOL(ath9k_hw_filltxdesc);
  212. void ath9k_hw_cleartxdesc(struct ath_hw *ah, struct ath_desc *ds)
  213. {
  214. struct ar5416_desc *ads = AR5416DESC(ds);
  215. ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
  216. ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
  217. ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
  218. ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
  219. ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
  220. }
  221. EXPORT_SYMBOL(ath9k_hw_cleartxdesc);
  222. int ath9k_hw_txprocdesc(struct ath_hw *ah, struct ath_desc *ds,
  223. struct ath_tx_status *ts)
  224. {
  225. struct ar5416_desc *ads = AR5416DESC(ds);
  226. if ((ads->ds_txstatus9 & AR_TxDone) == 0)
  227. return -EINPROGRESS;
  228. ts->ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
  229. ts->ts_tstamp = ads->AR_SendTimestamp;
  230. ts->ts_status = 0;
  231. ts->ts_flags = 0;
  232. if (ads->ds_txstatus1 & AR_FrmXmitOK)
  233. ts->ts_status |= ATH9K_TX_ACKED;
  234. if (ads->ds_txstatus1 & AR_ExcessiveRetries)
  235. ts->ts_status |= ATH9K_TXERR_XRETRY;
  236. if (ads->ds_txstatus1 & AR_Filtered)
  237. ts->ts_status |= ATH9K_TXERR_FILT;
  238. if (ads->ds_txstatus1 & AR_FIFOUnderrun) {
  239. ts->ts_status |= ATH9K_TXERR_FIFO;
  240. ath9k_hw_updatetxtriglevel(ah, true);
  241. }
  242. if (ads->ds_txstatus9 & AR_TxOpExceeded)
  243. ts->ts_status |= ATH9K_TXERR_XTXOP;
  244. if (ads->ds_txstatus1 & AR_TxTimerExpired)
  245. ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
  246. if (ads->ds_txstatus1 & AR_DescCfgErr)
  247. ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
  248. if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
  249. ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
  250. ath9k_hw_updatetxtriglevel(ah, true);
  251. }
  252. if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
  253. ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
  254. ath9k_hw_updatetxtriglevel(ah, true);
  255. }
  256. if (ads->ds_txstatus0 & AR_TxBaStatus) {
  257. ts->ts_flags |= ATH9K_TX_BA;
  258. ts->ba_low = ads->AR_BaBitmapLow;
  259. ts->ba_high = ads->AR_BaBitmapHigh;
  260. }
  261. ts->ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
  262. switch (ts->ts_rateindex) {
  263. case 0:
  264. ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
  265. break;
  266. case 1:
  267. ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
  268. break;
  269. case 2:
  270. ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
  271. break;
  272. case 3:
  273. ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
  274. break;
  275. }
  276. ts->ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
  277. ts->ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
  278. ts->ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
  279. ts->ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
  280. ts->ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
  281. ts->ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
  282. ts->ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
  283. ts->evm0 = ads->AR_TxEVM0;
  284. ts->evm1 = ads->AR_TxEVM1;
  285. ts->evm2 = ads->AR_TxEVM2;
  286. ts->ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
  287. ts->ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
  288. ts->ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
  289. ts->ts_antenna = 0;
  290. return 0;
  291. }
  292. EXPORT_SYMBOL(ath9k_hw_txprocdesc);
  293. void ath9k_hw_set11n_txdesc(struct ath_hw *ah, struct ath_desc *ds,
  294. u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
  295. u32 keyIx, enum ath9k_key_type keyType, u32 flags)
  296. {
  297. struct ar5416_desc *ads = AR5416DESC(ds);
  298. txPower += ah->txpower_indexoffset;
  299. if (txPower > 63)
  300. txPower = 63;
  301. ads->ds_ctl0 = (pktLen & AR_FrameLen)
  302. | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  303. | SM(txPower, AR_XmitPower)
  304. | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  305. | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
  306. | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
  307. | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
  308. ads->ds_ctl1 =
  309. (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
  310. | SM(type, AR_FrameType)
  311. | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
  312. | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
  313. | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
  314. ads->ds_ctl6 = SM(keyType, AR_EncrType);
  315. if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
  316. ads->ds_ctl8 = 0;
  317. ads->ds_ctl9 = 0;
  318. ads->ds_ctl10 = 0;
  319. ads->ds_ctl11 = 0;
  320. }
  321. }
  322. EXPORT_SYMBOL(ath9k_hw_set11n_txdesc);
  323. void ath9k_hw_set11n_ratescenario(struct ath_hw *ah, struct ath_desc *ds,
  324. struct ath_desc *lastds,
  325. u32 durUpdateEn, u32 rtsctsRate,
  326. u32 rtsctsDuration,
  327. struct ath9k_11n_rate_series series[],
  328. u32 nseries, u32 flags)
  329. {
  330. struct ar5416_desc *ads = AR5416DESC(ds);
  331. struct ar5416_desc *last_ads = AR5416DESC(lastds);
  332. u32 ds_ctl0;
  333. if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
  334. ds_ctl0 = ads->ds_ctl0;
  335. if (flags & ATH9K_TXDESC_RTSENA) {
  336. ds_ctl0 &= ~AR_CTSEnable;
  337. ds_ctl0 |= AR_RTSEnable;
  338. } else {
  339. ds_ctl0 &= ~AR_RTSEnable;
  340. ds_ctl0 |= AR_CTSEnable;
  341. }
  342. ads->ds_ctl0 = ds_ctl0;
  343. } else {
  344. ads->ds_ctl0 =
  345. (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
  346. }
  347. ads->ds_ctl2 = set11nTries(series, 0)
  348. | set11nTries(series, 1)
  349. | set11nTries(series, 2)
  350. | set11nTries(series, 3)
  351. | (durUpdateEn ? AR_DurUpdateEna : 0)
  352. | SM(0, AR_BurstDur);
  353. ads->ds_ctl3 = set11nRate(series, 0)
  354. | set11nRate(series, 1)
  355. | set11nRate(series, 2)
  356. | set11nRate(series, 3);
  357. ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
  358. | set11nPktDurRTSCTS(series, 1);
  359. ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
  360. | set11nPktDurRTSCTS(series, 3);
  361. ads->ds_ctl7 = set11nRateFlags(series, 0)
  362. | set11nRateFlags(series, 1)
  363. | set11nRateFlags(series, 2)
  364. | set11nRateFlags(series, 3)
  365. | SM(rtsctsRate, AR_RTSCTSRate);
  366. last_ads->ds_ctl2 = ads->ds_ctl2;
  367. last_ads->ds_ctl3 = ads->ds_ctl3;
  368. }
  369. EXPORT_SYMBOL(ath9k_hw_set11n_ratescenario);
  370. void ath9k_hw_set11n_aggr_first(struct ath_hw *ah, struct ath_desc *ds,
  371. u32 aggrLen)
  372. {
  373. struct ar5416_desc *ads = AR5416DESC(ds);
  374. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  375. ads->ds_ctl6 &= ~AR_AggrLen;
  376. ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
  377. }
  378. EXPORT_SYMBOL(ath9k_hw_set11n_aggr_first);
  379. void ath9k_hw_set11n_aggr_middle(struct ath_hw *ah, struct ath_desc *ds,
  380. u32 numDelims)
  381. {
  382. struct ar5416_desc *ads = AR5416DESC(ds);
  383. unsigned int ctl6;
  384. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  385. ctl6 = ads->ds_ctl6;
  386. ctl6 &= ~AR_PadDelim;
  387. ctl6 |= SM(numDelims, AR_PadDelim);
  388. ads->ds_ctl6 = ctl6;
  389. }
  390. EXPORT_SYMBOL(ath9k_hw_set11n_aggr_middle);
  391. void ath9k_hw_set11n_aggr_last(struct ath_hw *ah, struct ath_desc *ds)
  392. {
  393. struct ar5416_desc *ads = AR5416DESC(ds);
  394. ads->ds_ctl1 |= AR_IsAggr;
  395. ads->ds_ctl1 &= ~AR_MoreAggr;
  396. ads->ds_ctl6 &= ~AR_PadDelim;
  397. }
  398. EXPORT_SYMBOL(ath9k_hw_set11n_aggr_last);
  399. void ath9k_hw_clr11n_aggr(struct ath_hw *ah, struct ath_desc *ds)
  400. {
  401. struct ar5416_desc *ads = AR5416DESC(ds);
  402. ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
  403. }
  404. EXPORT_SYMBOL(ath9k_hw_clr11n_aggr);
  405. void ath9k_hw_set11n_burstduration(struct ath_hw *ah, struct ath_desc *ds,
  406. u32 burstDuration)
  407. {
  408. struct ar5416_desc *ads = AR5416DESC(ds);
  409. ads->ds_ctl2 &= ~AR_BurstDur;
  410. ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
  411. }
  412. EXPORT_SYMBOL(ath9k_hw_set11n_burstduration);
  413. void ath9k_hw_set11n_virtualmorefrag(struct ath_hw *ah, struct ath_desc *ds,
  414. u32 vmf)
  415. {
  416. struct ar5416_desc *ads = AR5416DESC(ds);
  417. if (vmf)
  418. ads->ds_ctl0 |= AR_VirtMoreFrag;
  419. else
  420. ads->ds_ctl0 &= ~AR_VirtMoreFrag;
  421. }
  422. void ath9k_hw_gettxintrtxqs(struct ath_hw *ah, u32 *txqs)
  423. {
  424. *txqs &= ah->intr_txqs;
  425. ah->intr_txqs &= ~(*txqs);
  426. }
  427. EXPORT_SYMBOL(ath9k_hw_gettxintrtxqs);
  428. bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
  429. const struct ath9k_tx_queue_info *qinfo)
  430. {
  431. u32 cw;
  432. struct ath_common *common = ath9k_hw_common(ah);
  433. struct ath9k_hw_capabilities *pCap = &ah->caps;
  434. struct ath9k_tx_queue_info *qi;
  435. if (q >= pCap->total_queues) {
  436. ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
  437. "invalid queue: %u\n", q);
  438. return false;
  439. }
  440. qi = &ah->txq[q];
  441. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  442. ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
  443. "inactive queue: %u\n", q);
  444. return false;
  445. }
  446. ath_print(common, ATH_DBG_QUEUE, "Set queue properties for: %u\n", q);
  447. qi->tqi_ver = qinfo->tqi_ver;
  448. qi->tqi_subtype = qinfo->tqi_subtype;
  449. qi->tqi_qflags = qinfo->tqi_qflags;
  450. qi->tqi_priority = qinfo->tqi_priority;
  451. if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
  452. qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
  453. else
  454. qi->tqi_aifs = INIT_AIFS;
  455. if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
  456. cw = min(qinfo->tqi_cwmin, 1024U);
  457. qi->tqi_cwmin = 1;
  458. while (qi->tqi_cwmin < cw)
  459. qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
  460. } else
  461. qi->tqi_cwmin = qinfo->tqi_cwmin;
  462. if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
  463. cw = min(qinfo->tqi_cwmax, 1024U);
  464. qi->tqi_cwmax = 1;
  465. while (qi->tqi_cwmax < cw)
  466. qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
  467. } else
  468. qi->tqi_cwmax = INIT_CWMAX;
  469. if (qinfo->tqi_shretry != 0)
  470. qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
  471. else
  472. qi->tqi_shretry = INIT_SH_RETRY;
  473. if (qinfo->tqi_lgretry != 0)
  474. qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
  475. else
  476. qi->tqi_lgretry = INIT_LG_RETRY;
  477. qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
  478. qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
  479. qi->tqi_burstTime = qinfo->tqi_burstTime;
  480. qi->tqi_readyTime = qinfo->tqi_readyTime;
  481. switch (qinfo->tqi_subtype) {
  482. case ATH9K_WME_UPSD:
  483. if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
  484. qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
  485. break;
  486. default:
  487. break;
  488. }
  489. return true;
  490. }
  491. EXPORT_SYMBOL(ath9k_hw_set_txq_props);
  492. bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
  493. struct ath9k_tx_queue_info *qinfo)
  494. {
  495. struct ath_common *common = ath9k_hw_common(ah);
  496. struct ath9k_hw_capabilities *pCap = &ah->caps;
  497. struct ath9k_tx_queue_info *qi;
  498. if (q >= pCap->total_queues) {
  499. ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
  500. "invalid queue: %u\n", q);
  501. return false;
  502. }
  503. qi = &ah->txq[q];
  504. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  505. ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
  506. "inactive queue: %u\n", q);
  507. return false;
  508. }
  509. qinfo->tqi_qflags = qi->tqi_qflags;
  510. qinfo->tqi_ver = qi->tqi_ver;
  511. qinfo->tqi_subtype = qi->tqi_subtype;
  512. qinfo->tqi_qflags = qi->tqi_qflags;
  513. qinfo->tqi_priority = qi->tqi_priority;
  514. qinfo->tqi_aifs = qi->tqi_aifs;
  515. qinfo->tqi_cwmin = qi->tqi_cwmin;
  516. qinfo->tqi_cwmax = qi->tqi_cwmax;
  517. qinfo->tqi_shretry = qi->tqi_shretry;
  518. qinfo->tqi_lgretry = qi->tqi_lgretry;
  519. qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
  520. qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
  521. qinfo->tqi_burstTime = qi->tqi_burstTime;
  522. qinfo->tqi_readyTime = qi->tqi_readyTime;
  523. return true;
  524. }
  525. EXPORT_SYMBOL(ath9k_hw_get_txq_props);
  526. int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
  527. const struct ath9k_tx_queue_info *qinfo)
  528. {
  529. struct ath_common *common = ath9k_hw_common(ah);
  530. struct ath9k_tx_queue_info *qi;
  531. struct ath9k_hw_capabilities *pCap = &ah->caps;
  532. int q;
  533. switch (type) {
  534. case ATH9K_TX_QUEUE_BEACON:
  535. q = pCap->total_queues - 1;
  536. break;
  537. case ATH9K_TX_QUEUE_CAB:
  538. q = pCap->total_queues - 2;
  539. break;
  540. case ATH9K_TX_QUEUE_PSPOLL:
  541. q = 1;
  542. break;
  543. case ATH9K_TX_QUEUE_UAPSD:
  544. q = pCap->total_queues - 3;
  545. break;
  546. case ATH9K_TX_QUEUE_DATA:
  547. for (q = 0; q < pCap->total_queues; q++)
  548. if (ah->txq[q].tqi_type ==
  549. ATH9K_TX_QUEUE_INACTIVE)
  550. break;
  551. if (q == pCap->total_queues) {
  552. ath_print(common, ATH_DBG_FATAL,
  553. "No available TX queue\n");
  554. return -1;
  555. }
  556. break;
  557. default:
  558. ath_print(common, ATH_DBG_FATAL,
  559. "Invalid TX queue type: %u\n", type);
  560. return -1;
  561. }
  562. ath_print(common, ATH_DBG_QUEUE, "Setup TX queue: %u\n", q);
  563. qi = &ah->txq[q];
  564. if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
  565. ath_print(common, ATH_DBG_FATAL,
  566. "TX queue: %u already active\n", q);
  567. return -1;
  568. }
  569. memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
  570. qi->tqi_type = type;
  571. if (qinfo == NULL) {
  572. qi->tqi_qflags =
  573. TXQ_FLAG_TXOKINT_ENABLE
  574. | TXQ_FLAG_TXERRINT_ENABLE
  575. | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
  576. qi->tqi_aifs = INIT_AIFS;
  577. qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
  578. qi->tqi_cwmax = INIT_CWMAX;
  579. qi->tqi_shretry = INIT_SH_RETRY;
  580. qi->tqi_lgretry = INIT_LG_RETRY;
  581. qi->tqi_physCompBuf = 0;
  582. } else {
  583. qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
  584. (void) ath9k_hw_set_txq_props(ah, q, qinfo);
  585. }
  586. return q;
  587. }
  588. EXPORT_SYMBOL(ath9k_hw_setuptxqueue);
  589. bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
  590. {
  591. struct ath9k_hw_capabilities *pCap = &ah->caps;
  592. struct ath_common *common = ath9k_hw_common(ah);
  593. struct ath9k_tx_queue_info *qi;
  594. if (q >= pCap->total_queues) {
  595. ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
  596. "invalid queue: %u\n", q);
  597. return false;
  598. }
  599. qi = &ah->txq[q];
  600. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  601. ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
  602. "inactive queue: %u\n", q);
  603. return false;
  604. }
  605. ath_print(common, ATH_DBG_QUEUE, "Release TX queue: %u\n", q);
  606. qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
  607. ah->txok_interrupt_mask &= ~(1 << q);
  608. ah->txerr_interrupt_mask &= ~(1 << q);
  609. ah->txdesc_interrupt_mask &= ~(1 << q);
  610. ah->txeol_interrupt_mask &= ~(1 << q);
  611. ah->txurn_interrupt_mask &= ~(1 << q);
  612. ath9k_hw_set_txq_interrupts(ah, qi);
  613. return true;
  614. }
  615. EXPORT_SYMBOL(ath9k_hw_releasetxqueue);
  616. bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
  617. {
  618. struct ath9k_hw_capabilities *pCap = &ah->caps;
  619. struct ath_common *common = ath9k_hw_common(ah);
  620. struct ath9k_channel *chan = ah->curchan;
  621. struct ath9k_tx_queue_info *qi;
  622. u32 cwMin, chanCwMin, value;
  623. if (q >= pCap->total_queues) {
  624. ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
  625. "invalid queue: %u\n", q);
  626. return false;
  627. }
  628. qi = &ah->txq[q];
  629. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  630. ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
  631. "inactive queue: %u\n", q);
  632. return true;
  633. }
  634. ath_print(common, ATH_DBG_QUEUE, "Reset TX queue: %u\n", q);
  635. if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
  636. if (chan && IS_CHAN_B(chan))
  637. chanCwMin = INIT_CWMIN_11B;
  638. else
  639. chanCwMin = INIT_CWMIN;
  640. for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
  641. } else
  642. cwMin = qi->tqi_cwmin;
  643. REG_WRITE(ah, AR_DLCL_IFS(q),
  644. SM(cwMin, AR_D_LCL_IFS_CWMIN) |
  645. SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
  646. SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
  647. REG_WRITE(ah, AR_DRETRY_LIMIT(q),
  648. SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
  649. SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
  650. SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
  651. REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
  652. REG_WRITE(ah, AR_DMISC(q),
  653. AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
  654. if (qi->tqi_cbrPeriod) {
  655. REG_WRITE(ah, AR_QCBRCFG(q),
  656. SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
  657. SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
  658. REG_WRITE(ah, AR_QMISC(q),
  659. REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
  660. (qi->tqi_cbrOverflowLimit ?
  661. AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
  662. }
  663. if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
  664. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  665. SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
  666. AR_Q_RDYTIMECFG_EN);
  667. }
  668. REG_WRITE(ah, AR_DCHNTIME(q),
  669. SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
  670. (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
  671. if (qi->tqi_burstTime
  672. && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
  673. REG_WRITE(ah, AR_QMISC(q),
  674. REG_READ(ah, AR_QMISC(q)) |
  675. AR_Q_MISC_RDYTIME_EXP_POLICY);
  676. }
  677. if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
  678. REG_WRITE(ah, AR_DMISC(q),
  679. REG_READ(ah, AR_DMISC(q)) |
  680. AR_D_MISC_POST_FR_BKOFF_DIS);
  681. }
  682. if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
  683. REG_WRITE(ah, AR_DMISC(q),
  684. REG_READ(ah, AR_DMISC(q)) |
  685. AR_D_MISC_FRAG_BKOFF_EN);
  686. }
  687. switch (qi->tqi_type) {
  688. case ATH9K_TX_QUEUE_BEACON:
  689. REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
  690. | AR_Q_MISC_FSP_DBA_GATED
  691. | AR_Q_MISC_BEACON_USE
  692. | AR_Q_MISC_CBR_INCR_DIS1);
  693. REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
  694. | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  695. AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
  696. | AR_D_MISC_BEACON_USE
  697. | AR_D_MISC_POST_FR_BKOFF_DIS);
  698. break;
  699. case ATH9K_TX_QUEUE_CAB:
  700. REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
  701. | AR_Q_MISC_FSP_DBA_GATED
  702. | AR_Q_MISC_CBR_INCR_DIS1
  703. | AR_Q_MISC_CBR_INCR_DIS0);
  704. value = (qi->tqi_readyTime -
  705. (ah->config.sw_beacon_response_time -
  706. ah->config.dma_beacon_response_time) -
  707. ah->config.additional_swba_backoff) * 1024;
  708. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  709. value | AR_Q_RDYTIMECFG_EN);
  710. REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
  711. | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
  712. AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
  713. break;
  714. case ATH9K_TX_QUEUE_PSPOLL:
  715. REG_WRITE(ah, AR_QMISC(q),
  716. REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
  717. break;
  718. case ATH9K_TX_QUEUE_UAPSD:
  719. REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
  720. AR_D_MISC_POST_FR_BKOFF_DIS);
  721. break;
  722. default:
  723. break;
  724. }
  725. if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
  726. REG_WRITE(ah, AR_DMISC(q),
  727. REG_READ(ah, AR_DMISC(q)) |
  728. SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
  729. AR_D_MISC_ARB_LOCKOUT_CNTRL) |
  730. AR_D_MISC_POST_FR_BKOFF_DIS);
  731. }
  732. if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
  733. ah->txok_interrupt_mask |= 1 << q;
  734. else
  735. ah->txok_interrupt_mask &= ~(1 << q);
  736. if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
  737. ah->txerr_interrupt_mask |= 1 << q;
  738. else
  739. ah->txerr_interrupt_mask &= ~(1 << q);
  740. if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
  741. ah->txdesc_interrupt_mask |= 1 << q;
  742. else
  743. ah->txdesc_interrupt_mask &= ~(1 << q);
  744. if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
  745. ah->txeol_interrupt_mask |= 1 << q;
  746. else
  747. ah->txeol_interrupt_mask &= ~(1 << q);
  748. if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
  749. ah->txurn_interrupt_mask |= 1 << q;
  750. else
  751. ah->txurn_interrupt_mask &= ~(1 << q);
  752. ath9k_hw_set_txq_interrupts(ah, qi);
  753. return true;
  754. }
  755. EXPORT_SYMBOL(ath9k_hw_resettxqueue);
  756. int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
  757. struct ath_rx_status *rs, u64 tsf)
  758. {
  759. struct ar5416_desc ads;
  760. struct ar5416_desc *adsp = AR5416DESC(ds);
  761. u32 phyerr;
  762. if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
  763. return -EINPROGRESS;
  764. ads.u.rx = adsp->u.rx;
  765. rs->rs_status = 0;
  766. rs->rs_flags = 0;
  767. rs->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
  768. rs->rs_tstamp = ads.AR_RcvTimestamp;
  769. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) {
  770. rs->rs_rssi = ATH9K_RSSI_BAD;
  771. rs->rs_rssi_ctl0 = ATH9K_RSSI_BAD;
  772. rs->rs_rssi_ctl1 = ATH9K_RSSI_BAD;
  773. rs->rs_rssi_ctl2 = ATH9K_RSSI_BAD;
  774. rs->rs_rssi_ext0 = ATH9K_RSSI_BAD;
  775. rs->rs_rssi_ext1 = ATH9K_RSSI_BAD;
  776. rs->rs_rssi_ext2 = ATH9K_RSSI_BAD;
  777. } else {
  778. rs->rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
  779. rs->rs_rssi_ctl0 = MS(ads.ds_rxstatus0,
  780. AR_RxRSSIAnt00);
  781. rs->rs_rssi_ctl1 = MS(ads.ds_rxstatus0,
  782. AR_RxRSSIAnt01);
  783. rs->rs_rssi_ctl2 = MS(ads.ds_rxstatus0,
  784. AR_RxRSSIAnt02);
  785. rs->rs_rssi_ext0 = MS(ads.ds_rxstatus4,
  786. AR_RxRSSIAnt10);
  787. rs->rs_rssi_ext1 = MS(ads.ds_rxstatus4,
  788. AR_RxRSSIAnt11);
  789. rs->rs_rssi_ext2 = MS(ads.ds_rxstatus4,
  790. AR_RxRSSIAnt12);
  791. }
  792. if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
  793. rs->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
  794. else
  795. rs->rs_keyix = ATH9K_RXKEYIX_INVALID;
  796. rs->rs_rate = RXSTATUS_RATE(ah, (&ads));
  797. rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
  798. rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
  799. rs->rs_moreaggr =
  800. (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
  801. rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
  802. rs->rs_flags =
  803. (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
  804. rs->rs_flags |=
  805. (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
  806. if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
  807. rs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
  808. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
  809. rs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
  810. if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
  811. rs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
  812. if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
  813. if (ads.ds_rxstatus8 & AR_CRCErr)
  814. rs->rs_status |= ATH9K_RXERR_CRC;
  815. else if (ads.ds_rxstatus8 & AR_PHYErr) {
  816. rs->rs_status |= ATH9K_RXERR_PHY;
  817. phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
  818. rs->rs_phyerr = phyerr;
  819. } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
  820. rs->rs_status |= ATH9K_RXERR_DECRYPT;
  821. else if (ads.ds_rxstatus8 & AR_MichaelErr)
  822. rs->rs_status |= ATH9K_RXERR_MIC;
  823. }
  824. return 0;
  825. }
  826. EXPORT_SYMBOL(ath9k_hw_rxprocdesc);
  827. void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
  828. u32 size, u32 flags)
  829. {
  830. struct ar5416_desc *ads = AR5416DESC(ds);
  831. struct ath9k_hw_capabilities *pCap = &ah->caps;
  832. ads->ds_ctl1 = size & AR_BufLen;
  833. if (flags & ATH9K_RXDESC_INTREQ)
  834. ads->ds_ctl1 |= AR_RxIntrReq;
  835. ads->ds_rxstatus8 &= ~AR_RxDone;
  836. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  837. memset(&(ads->u), 0, sizeof(ads->u));
  838. }
  839. EXPORT_SYMBOL(ath9k_hw_setuprxdesc);
  840. /*
  841. * This can stop or re-enables RX.
  842. *
  843. * If bool is set this will kill any frame which is currently being
  844. * transferred between the MAC and baseband and also prevent any new
  845. * frames from getting started.
  846. */
  847. bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
  848. {
  849. u32 reg;
  850. if (set) {
  851. REG_SET_BIT(ah, AR_DIAG_SW,
  852. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  853. if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
  854. 0, AH_WAIT_TIMEOUT)) {
  855. REG_CLR_BIT(ah, AR_DIAG_SW,
  856. (AR_DIAG_RX_DIS |
  857. AR_DIAG_RX_ABORT));
  858. reg = REG_READ(ah, AR_OBS_BUS_1);
  859. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  860. "RX failed to go idle in 10 ms RXSM=0x%x\n",
  861. reg);
  862. return false;
  863. }
  864. } else {
  865. REG_CLR_BIT(ah, AR_DIAG_SW,
  866. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  867. }
  868. return true;
  869. }
  870. EXPORT_SYMBOL(ath9k_hw_setrxabort);
  871. void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
  872. {
  873. REG_WRITE(ah, AR_RXDP, rxdp);
  874. }
  875. EXPORT_SYMBOL(ath9k_hw_putrxbuf);
  876. void ath9k_hw_startpcureceive(struct ath_hw *ah)
  877. {
  878. ath9k_enable_mib_counters(ah);
  879. ath9k_ani_reset(ah);
  880. REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  881. }
  882. EXPORT_SYMBOL(ath9k_hw_startpcureceive);
  883. void ath9k_hw_stoppcurecv(struct ath_hw *ah)
  884. {
  885. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
  886. ath9k_hw_disable_mib_counters(ah);
  887. }
  888. EXPORT_SYMBOL(ath9k_hw_stoppcurecv);
  889. bool ath9k_hw_stopdmarecv(struct ath_hw *ah)
  890. {
  891. #define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
  892. #define AH_RX_TIME_QUANTUM 100 /* usec */
  893. struct ath_common *common = ath9k_hw_common(ah);
  894. int i;
  895. REG_WRITE(ah, AR_CR, AR_CR_RXD);
  896. /* Wait for rx enable bit to go low */
  897. for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
  898. if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
  899. break;
  900. udelay(AH_TIME_QUANTUM);
  901. }
  902. if (i == 0) {
  903. ath_print(common, ATH_DBG_FATAL,
  904. "DMA failed to stop in %d ms "
  905. "AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
  906. AH_RX_STOP_DMA_TIMEOUT / 1000,
  907. REG_READ(ah, AR_CR),
  908. REG_READ(ah, AR_DIAG_SW));
  909. return false;
  910. } else {
  911. return true;
  912. }
  913. #undef AH_RX_TIME_QUANTUM
  914. #undef AH_RX_STOP_DMA_TIMEOUT
  915. }
  916. EXPORT_SYMBOL(ath9k_hw_stopdmarecv);
  917. int ath9k_hw_beaconq_setup(struct ath_hw *ah)
  918. {
  919. struct ath9k_tx_queue_info qi;
  920. memset(&qi, 0, sizeof(qi));
  921. qi.tqi_aifs = 1;
  922. qi.tqi_cwmin = 0;
  923. qi.tqi_cwmax = 0;
  924. /* NB: don't enable any interrupts */
  925. return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
  926. }
  927. EXPORT_SYMBOL(ath9k_hw_beaconq_setup);