mac.c 30 KB

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