mac.c 30 KB

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