blob: 4a2060e5a7774616e438bb5f9dd4567e36d6c677 [file] [log] [blame]
Sujithf1dc5602008-10-29 10:16:30 +05301/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Sujithf1dc5602008-10-29 10:16:30 +05303 *
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
Luis R. Rodriguez990b70a2009-09-13 23:55:05 -070017#include "hw.h"
Sujithf1dc5602008-10-29 10:16:30 +053018
Sujithcbe61d82009-02-09 13:27:12 +053019static void ath9k_hw_set_txq_interrupts(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +053020 struct ath9k_tx_queue_info *qi)
21{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070022 ath_print(ath9k_hw_common(ah), ATH_DBG_INTERRUPT,
23 "tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
24 ah->txok_interrupt_mask, ah->txerr_interrupt_mask,
25 ah->txdesc_interrupt_mask, ah->txeol_interrupt_mask,
26 ah->txurn_interrupt_mask);
Sujithf1dc5602008-10-29 10:16:30 +053027
28 REG_WRITE(ah, AR_IMR_S0,
Sujith2660b812009-02-09 13:27:26 +053029 SM(ah->txok_interrupt_mask, AR_IMR_S0_QCU_TXOK)
30 | SM(ah->txdesc_interrupt_mask, AR_IMR_S0_QCU_TXDESC));
Sujithf1dc5602008-10-29 10:16:30 +053031 REG_WRITE(ah, AR_IMR_S1,
Sujith2660b812009-02-09 13:27:26 +053032 SM(ah->txerr_interrupt_mask, AR_IMR_S1_QCU_TXERR)
33 | SM(ah->txeol_interrupt_mask, AR_IMR_S1_QCU_TXEOL));
Pavel Roskin74bad5c2010-02-23 18:15:27 -050034
35 ah->imrs2_reg &= ~AR_IMR_S2_QCU_TXURN;
36 ah->imrs2_reg |= (ah->txurn_interrupt_mask & AR_IMR_S2_QCU_TXURN);
37 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +053038}
39
Sujithcbe61d82009-02-09 13:27:12 +053040u32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053041{
42 return REG_READ(ah, AR_QTXDP(q));
43}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040044EXPORT_SYMBOL(ath9k_hw_gettxbuf);
Sujithf1dc5602008-10-29 10:16:30 +053045
Sujith54e4cec2009-08-07 09:45:09 +053046void ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp)
Sujithf1dc5602008-10-29 10:16:30 +053047{
48 REG_WRITE(ah, AR_QTXDP(q), txdp);
Sujithf1dc5602008-10-29 10:16:30 +053049}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040050EXPORT_SYMBOL(ath9k_hw_puttxbuf);
Sujithf1dc5602008-10-29 10:16:30 +053051
Sujith54e4cec2009-08-07 09:45:09 +053052void ath9k_hw_txstart(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053053{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070054 ath_print(ath9k_hw_common(ah), ATH_DBG_QUEUE,
55 "Enable TXE on queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +053056 REG_WRITE(ah, AR_Q_TXE, 1 << q);
Sujithf1dc5602008-10-29 10:16:30 +053057}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040058EXPORT_SYMBOL(ath9k_hw_txstart);
Sujithf1dc5602008-10-29 10:16:30 +053059
Sujithcbe61d82009-02-09 13:27:12 +053060u32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053061{
62 u32 npend;
63
64 npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
65 if (npend == 0) {
66
67 if (REG_READ(ah, AR_Q_TXE) & (1 << q))
68 npend = 1;
69 }
70
71 return npend;
72}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040073EXPORT_SYMBOL(ath9k_hw_numtxpending);
Sujithf1dc5602008-10-29 10:16:30 +053074
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -050075/**
76 * ath9k_hw_updatetxtriglevel - adjusts the frame trigger level
77 *
78 * @ah: atheros hardware struct
79 * @bIncTrigLevel: whether or not the frame trigger level should be updated
80 *
81 * The frame trigger level specifies the minimum number of bytes,
82 * in units of 64 bytes, that must be DMA'ed into the PCU TX FIFO
83 * before the PCU will initiate sending the frame on the air. This can
84 * mean we initiate transmit before a full frame is on the PCU TX FIFO.
85 * Resets to 0x1 (meaning 64 bytes or a full frame, whichever occurs
86 * first)
87 *
88 * Caution must be taken to ensure to set the frame trigger level based
89 * on the DMA request size. For example if the DMA request size is set to
90 * 128 bytes the trigger level cannot exceed 6 * 64 = 384. This is because
91 * there need to be enough space in the tx FIFO for the requested transfer
92 * size. Hence the tx FIFO will stop with 512 - 128 = 384 bytes. If we set
93 * the threshold to a value beyond 6, then the transmit will hang.
94 *
95 * Current dual stream devices have a PCU TX FIFO size of 8 KB.
96 * Current single stream devices have a PCU TX FIFO size of 4 KB, however,
97 * there is a hardware issue which forces us to use 2 KB instead so the
98 * frame trigger level must not exceed 2 KB for these chipsets.
99 */
Sujithcbe61d82009-02-09 13:27:12 +0530100bool ath9k_hw_updatetxtriglevel(struct ath_hw *ah, bool bIncTrigLevel)
Sujithf1dc5602008-10-29 10:16:30 +0530101{
Sujithf1dc5602008-10-29 10:16:30 +0530102 u32 txcfg, curLevel, newLevel;
103 enum ath9k_int omask;
104
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500105 if (ah->tx_trig_level >= ah->config.max_txtrig_level)
Sujithf1dc5602008-10-29 10:16:30 +0530106 return false;
107
Pavel Roskin152d5302010-03-31 18:05:37 -0400108 omask = ath9k_hw_set_interrupts(ah, ah->imask & ~ATH9K_INT_GLOBAL);
Sujithf1dc5602008-10-29 10:16:30 +0530109
110 txcfg = REG_READ(ah, AR_TXCFG);
111 curLevel = MS(txcfg, AR_FTRIG);
112 newLevel = curLevel;
113 if (bIncTrigLevel) {
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500114 if (curLevel < ah->config.max_txtrig_level)
Sujithf1dc5602008-10-29 10:16:30 +0530115 newLevel++;
116 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
117 newLevel--;
118 if (newLevel != curLevel)
119 REG_WRITE(ah, AR_TXCFG,
120 (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
121
122 ath9k_hw_set_interrupts(ah, omask);
123
Sujith2660b812009-02-09 13:27:26 +0530124 ah->tx_trig_level = newLevel;
Sujithf1dc5602008-10-29 10:16:30 +0530125
126 return newLevel != curLevel;
127}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400128EXPORT_SYMBOL(ath9k_hw_updatetxtriglevel);
Sujithf1dc5602008-10-29 10:16:30 +0530129
Sujithcbe61d82009-02-09 13:27:12 +0530130bool ath9k_hw_stoptxdma(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530131{
Sujith94ff91d2009-01-27 15:06:38 +0530132#define ATH9K_TX_STOP_DMA_TIMEOUT 4000 /* usec */
133#define ATH9K_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700134 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530135 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujith94ff91d2009-01-27 15:06:38 +0530136 struct ath9k_tx_queue_info *qi;
Sujithf1dc5602008-10-29 10:16:30 +0530137 u32 tsfLow, j, wait;
Sujith94ff91d2009-01-27 15:06:38 +0530138 u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
139
140 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700141 ath_print(common, ATH_DBG_QUEUE, "Stopping TX DMA, "
142 "invalid queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530143 return false;
144 }
145
Sujith2660b812009-02-09 13:27:26 +0530146 qi = &ah->txq[q];
Sujith94ff91d2009-01-27 15:06:38 +0530147 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700148 ath_print(common, ATH_DBG_QUEUE, "Stopping TX DMA, "
149 "inactive queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530150 return false;
151 }
Sujithf1dc5602008-10-29 10:16:30 +0530152
153 REG_WRITE(ah, AR_Q_TXD, 1 << q);
154
Sujith94ff91d2009-01-27 15:06:38 +0530155 for (wait = wait_time; wait != 0; wait--) {
Sujithf1dc5602008-10-29 10:16:30 +0530156 if (ath9k_hw_numtxpending(ah, q) == 0)
157 break;
Sujith94ff91d2009-01-27 15:06:38 +0530158 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530159 }
160
161 if (ath9k_hw_numtxpending(ah, q)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700162 ath_print(common, ATH_DBG_QUEUE,
163 "%s: Num of pending TX Frames %d on Q %d\n",
164 __func__, ath9k_hw_numtxpending(ah, q), q);
Sujithf1dc5602008-10-29 10:16:30 +0530165
166 for (j = 0; j < 2; j++) {
167 tsfLow = REG_READ(ah, AR_TSF_L32);
168 REG_WRITE(ah, AR_QUIET2,
169 SM(10, AR_QUIET2_QUIET_DUR));
170 REG_WRITE(ah, AR_QUIET_PERIOD, 100);
171 REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
172 REG_SET_BIT(ah, AR_TIMER_MODE,
173 AR_QUIET_TIMER_EN);
174
175 if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10))
176 break;
177
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700178 ath_print(common, ATH_DBG_QUEUE,
179 "TSF has moved while trying to set "
180 "quiet time TSF: 0x%08x\n", tsfLow);
Sujithf1dc5602008-10-29 10:16:30 +0530181 }
182
183 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
184
185 udelay(200);
186 REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);
187
Sujith94ff91d2009-01-27 15:06:38 +0530188 wait = wait_time;
Sujithf1dc5602008-10-29 10:16:30 +0530189 while (ath9k_hw_numtxpending(ah, q)) {
190 if ((--wait) == 0) {
Sujithe8009e92009-12-14 14:57:08 +0530191 ath_print(common, ATH_DBG_FATAL,
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700192 "Failed to stop TX DMA in 100 "
193 "msec after killing last frame\n");
Sujithf1dc5602008-10-29 10:16:30 +0530194 break;
195 }
Sujith94ff91d2009-01-27 15:06:38 +0530196 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530197 }
198
199 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
200 }
201
202 REG_WRITE(ah, AR_Q_TXD, 0);
Sujithf1dc5602008-10-29 10:16:30 +0530203 return wait != 0;
Sujith94ff91d2009-01-27 15:06:38 +0530204
205#undef ATH9K_TX_STOP_DMA_TIMEOUT
206#undef ATH9K_TIME_QUANTUM
Sujithf1dc5602008-10-29 10:16:30 +0530207}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400208EXPORT_SYMBOL(ath9k_hw_stoptxdma);
Sujithf1dc5602008-10-29 10:16:30 +0530209
Sujith54e4cec2009-08-07 09:45:09 +0530210void ath9k_hw_filltxdesc(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530211 u32 segLen, bool firstSeg,
212 bool lastSeg, const struct ath_desc *ds0)
213{
214 struct ar5416_desc *ads = AR5416DESC(ds);
215
216 if (firstSeg) {
217 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
218 } else if (lastSeg) {
219 ads->ds_ctl0 = 0;
220 ads->ds_ctl1 = segLen;
221 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
222 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
223 } else {
224 ads->ds_ctl0 = 0;
225 ads->ds_ctl1 = segLen | AR_TxMore;
226 ads->ds_ctl2 = 0;
227 ads->ds_ctl3 = 0;
228 }
229 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
230 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
231 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
232 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
233 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530234}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400235EXPORT_SYMBOL(ath9k_hw_filltxdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530236
Sujithcbe61d82009-02-09 13:27:12 +0530237void ath9k_hw_cleartxdesc(struct ath_hw *ah, struct ath_desc *ds)
Sujithf1dc5602008-10-29 10:16:30 +0530238{
239 struct ar5416_desc *ads = AR5416DESC(ds);
240
241 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
242 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
243 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
244 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
245 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
246}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400247EXPORT_SYMBOL(ath9k_hw_cleartxdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530248
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700249int ath9k_hw_txprocdesc(struct ath_hw *ah, struct ath_desc *ds,
250 struct ath_tx_status *ts)
Sujithf1dc5602008-10-29 10:16:30 +0530251{
252 struct ar5416_desc *ads = AR5416DESC(ds);
253
254 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
255 return -EINPROGRESS;
256
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700257 ts->ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
258 ts->ts_tstamp = ads->AR_SendTimestamp;
259 ts->ts_status = 0;
260 ts->ts_flags = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530261
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -0500262 if (ads->ds_txstatus1 & AR_FrmXmitOK)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700263 ts->ts_status |= ATH9K_TX_ACKED;
Sujithf1dc5602008-10-29 10:16:30 +0530264 if (ads->ds_txstatus1 & AR_ExcessiveRetries)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700265 ts->ts_status |= ATH9K_TXERR_XRETRY;
Sujithf1dc5602008-10-29 10:16:30 +0530266 if (ads->ds_txstatus1 & AR_Filtered)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700267 ts->ts_status |= ATH9K_TXERR_FILT;
Sujithdaa9deb2008-11-18 09:10:22 +0530268 if (ads->ds_txstatus1 & AR_FIFOUnderrun) {
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700269 ts->ts_status |= ATH9K_TXERR_FIFO;
Sujithdaa9deb2008-11-18 09:10:22 +0530270 ath9k_hw_updatetxtriglevel(ah, true);
271 }
Sujithf1dc5602008-10-29 10:16:30 +0530272 if (ads->ds_txstatus9 & AR_TxOpExceeded)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700273 ts->ts_status |= ATH9K_TXERR_XTXOP;
Sujithf1dc5602008-10-29 10:16:30 +0530274 if (ads->ds_txstatus1 & AR_TxTimerExpired)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700275 ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
Sujithf1dc5602008-10-29 10:16:30 +0530276
277 if (ads->ds_txstatus1 & AR_DescCfgErr)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700278 ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
Sujithf1dc5602008-10-29 10:16:30 +0530279 if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700280 ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
Sujithf1dc5602008-10-29 10:16:30 +0530281 ath9k_hw_updatetxtriglevel(ah, true);
282 }
283 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700284 ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
Sujithf1dc5602008-10-29 10:16:30 +0530285 ath9k_hw_updatetxtriglevel(ah, true);
286 }
287 if (ads->ds_txstatus0 & AR_TxBaStatus) {
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700288 ts->ts_flags |= ATH9K_TX_BA;
289 ts->ba_low = ads->AR_BaBitmapLow;
290 ts->ba_high = ads->AR_BaBitmapHigh;
Sujithf1dc5602008-10-29 10:16:30 +0530291 }
292
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700293 ts->ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
294 switch (ts->ts_rateindex) {
Sujithf1dc5602008-10-29 10:16:30 +0530295 case 0:
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700296 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
Sujithf1dc5602008-10-29 10:16:30 +0530297 break;
298 case 1:
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700299 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
Sujithf1dc5602008-10-29 10:16:30 +0530300 break;
301 case 2:
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700302 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
Sujithf1dc5602008-10-29 10:16:30 +0530303 break;
304 case 3:
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700305 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
Sujithf1dc5602008-10-29 10:16:30 +0530306 break;
307 }
308
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700309 ts->ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
310 ts->ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
311 ts->ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
312 ts->ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
313 ts->ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
314 ts->ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
315 ts->ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
316 ts->evm0 = ads->AR_TxEVM0;
317 ts->evm1 = ads->AR_TxEVM1;
318 ts->evm2 = ads->AR_TxEVM2;
319 ts->ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
320 ts->ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
321 ts->ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
322 ts->ts_antenna = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530323
324 return 0;
325}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400326EXPORT_SYMBOL(ath9k_hw_txprocdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530327
Sujithcbe61d82009-02-09 13:27:12 +0530328void ath9k_hw_set11n_txdesc(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530329 u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
330 u32 keyIx, enum ath9k_key_type keyType, u32 flags)
331{
332 struct ar5416_desc *ads = AR5416DESC(ds);
Sujithf1dc5602008-10-29 10:16:30 +0530333
Sujith2660b812009-02-09 13:27:26 +0530334 txPower += ah->txpower_indexoffset;
Sujithf1dc5602008-10-29 10:16:30 +0530335 if (txPower > 63)
336 txPower = 63;
337
338 ads->ds_ctl0 = (pktLen & AR_FrameLen)
339 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
340 | SM(txPower, AR_XmitPower)
341 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
342 | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
343 | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
344 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
345
346 ads->ds_ctl1 =
347 (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
348 | SM(type, AR_FrameType)
349 | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
350 | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
351 | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
352
353 ads->ds_ctl6 = SM(keyType, AR_EncrType);
354
Sujithe492d7c2010-03-17 14:25:17 +0530355 if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +0530356 ads->ds_ctl8 = 0;
357 ads->ds_ctl9 = 0;
358 ads->ds_ctl10 = 0;
359 ads->ds_ctl11 = 0;
360 }
361}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400362EXPORT_SYMBOL(ath9k_hw_set11n_txdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530363
Sujithcbe61d82009-02-09 13:27:12 +0530364void ath9k_hw_set11n_ratescenario(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530365 struct ath_desc *lastds,
366 u32 durUpdateEn, u32 rtsctsRate,
367 u32 rtsctsDuration,
368 struct ath9k_11n_rate_series series[],
369 u32 nseries, u32 flags)
370{
371 struct ar5416_desc *ads = AR5416DESC(ds);
372 struct ar5416_desc *last_ads = AR5416DESC(lastds);
373 u32 ds_ctl0;
374
Sujithf1dc5602008-10-29 10:16:30 +0530375 if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
376 ds_ctl0 = ads->ds_ctl0;
377
378 if (flags & ATH9K_TXDESC_RTSENA) {
379 ds_ctl0 &= ~AR_CTSEnable;
380 ds_ctl0 |= AR_RTSEnable;
381 } else {
382 ds_ctl0 &= ~AR_RTSEnable;
383 ds_ctl0 |= AR_CTSEnable;
384 }
385
386 ads->ds_ctl0 = ds_ctl0;
387 } else {
388 ads->ds_ctl0 =
389 (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
390 }
391
392 ads->ds_ctl2 = set11nTries(series, 0)
393 | set11nTries(series, 1)
394 | set11nTries(series, 2)
395 | set11nTries(series, 3)
396 | (durUpdateEn ? AR_DurUpdateEna : 0)
397 | SM(0, AR_BurstDur);
398
399 ads->ds_ctl3 = set11nRate(series, 0)
400 | set11nRate(series, 1)
401 | set11nRate(series, 2)
402 | set11nRate(series, 3);
403
404 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
405 | set11nPktDurRTSCTS(series, 1);
406
407 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
408 | set11nPktDurRTSCTS(series, 3);
409
410 ads->ds_ctl7 = set11nRateFlags(series, 0)
411 | set11nRateFlags(series, 1)
412 | set11nRateFlags(series, 2)
413 | set11nRateFlags(series, 3)
414 | SM(rtsctsRate, AR_RTSCTSRate);
415 last_ads->ds_ctl2 = ads->ds_ctl2;
416 last_ads->ds_ctl3 = ads->ds_ctl3;
417}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400418EXPORT_SYMBOL(ath9k_hw_set11n_ratescenario);
Sujithf1dc5602008-10-29 10:16:30 +0530419
Sujithcbe61d82009-02-09 13:27:12 +0530420void ath9k_hw_set11n_aggr_first(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530421 u32 aggrLen)
422{
423 struct ar5416_desc *ads = AR5416DESC(ds);
424
425 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
426 ads->ds_ctl6 &= ~AR_AggrLen;
427 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
428}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400429EXPORT_SYMBOL(ath9k_hw_set11n_aggr_first);
Sujithf1dc5602008-10-29 10:16:30 +0530430
Sujithcbe61d82009-02-09 13:27:12 +0530431void ath9k_hw_set11n_aggr_middle(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530432 u32 numDelims)
433{
434 struct ar5416_desc *ads = AR5416DESC(ds);
435 unsigned int ctl6;
436
437 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
438
439 ctl6 = ads->ds_ctl6;
440 ctl6 &= ~AR_PadDelim;
441 ctl6 |= SM(numDelims, AR_PadDelim);
442 ads->ds_ctl6 = ctl6;
443}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400444EXPORT_SYMBOL(ath9k_hw_set11n_aggr_middle);
Sujithf1dc5602008-10-29 10:16:30 +0530445
Sujithcbe61d82009-02-09 13:27:12 +0530446void ath9k_hw_set11n_aggr_last(struct ath_hw *ah, struct ath_desc *ds)
Sujithf1dc5602008-10-29 10:16:30 +0530447{
448 struct ar5416_desc *ads = AR5416DESC(ds);
449
450 ads->ds_ctl1 |= AR_IsAggr;
451 ads->ds_ctl1 &= ~AR_MoreAggr;
452 ads->ds_ctl6 &= ~AR_PadDelim;
453}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400454EXPORT_SYMBOL(ath9k_hw_set11n_aggr_last);
Sujithf1dc5602008-10-29 10:16:30 +0530455
Sujithcbe61d82009-02-09 13:27:12 +0530456void ath9k_hw_clr11n_aggr(struct ath_hw *ah, struct ath_desc *ds)
Sujithf1dc5602008-10-29 10:16:30 +0530457{
458 struct ar5416_desc *ads = AR5416DESC(ds);
459
460 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
461}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400462EXPORT_SYMBOL(ath9k_hw_clr11n_aggr);
Sujithf1dc5602008-10-29 10:16:30 +0530463
Sujithcbe61d82009-02-09 13:27:12 +0530464void ath9k_hw_set11n_burstduration(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530465 u32 burstDuration)
466{
467 struct ar5416_desc *ads = AR5416DESC(ds);
468
469 ads->ds_ctl2 &= ~AR_BurstDur;
470 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
471}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400472EXPORT_SYMBOL(ath9k_hw_set11n_burstduration);
Sujithf1dc5602008-10-29 10:16:30 +0530473
Sujithcbe61d82009-02-09 13:27:12 +0530474void ath9k_hw_set11n_virtualmorefrag(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530475 u32 vmf)
476{
477 struct ar5416_desc *ads = AR5416DESC(ds);
478
479 if (vmf)
480 ads->ds_ctl0 |= AR_VirtMoreFrag;
481 else
482 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
483}
484
Sujithcbe61d82009-02-09 13:27:12 +0530485void ath9k_hw_gettxintrtxqs(struct ath_hw *ah, u32 *txqs)
Sujithf1dc5602008-10-29 10:16:30 +0530486{
Sujith2660b812009-02-09 13:27:26 +0530487 *txqs &= ah->intr_txqs;
488 ah->intr_txqs &= ~(*txqs);
Sujithf1dc5602008-10-29 10:16:30 +0530489}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400490EXPORT_SYMBOL(ath9k_hw_gettxintrtxqs);
Sujithf1dc5602008-10-29 10:16:30 +0530491
Sujithcbe61d82009-02-09 13:27:12 +0530492bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530493 const struct ath9k_tx_queue_info *qinfo)
494{
495 u32 cw;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700496 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530497 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530498 struct ath9k_tx_queue_info *qi;
499
500 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700501 ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
502 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530503 return false;
504 }
505
Sujith2660b812009-02-09 13:27:26 +0530506 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530507 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700508 ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
509 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530510 return false;
511 }
512
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700513 ath_print(common, ATH_DBG_QUEUE, "Set queue properties for: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530514
515 qi->tqi_ver = qinfo->tqi_ver;
516 qi->tqi_subtype = qinfo->tqi_subtype;
517 qi->tqi_qflags = qinfo->tqi_qflags;
518 qi->tqi_priority = qinfo->tqi_priority;
519 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
520 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
521 else
522 qi->tqi_aifs = INIT_AIFS;
523 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
524 cw = min(qinfo->tqi_cwmin, 1024U);
525 qi->tqi_cwmin = 1;
526 while (qi->tqi_cwmin < cw)
527 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
528 } else
529 qi->tqi_cwmin = qinfo->tqi_cwmin;
530 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
531 cw = min(qinfo->tqi_cwmax, 1024U);
532 qi->tqi_cwmax = 1;
533 while (qi->tqi_cwmax < cw)
534 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
535 } else
536 qi->tqi_cwmax = INIT_CWMAX;
537
538 if (qinfo->tqi_shretry != 0)
539 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
540 else
541 qi->tqi_shretry = INIT_SH_RETRY;
542 if (qinfo->tqi_lgretry != 0)
543 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
544 else
545 qi->tqi_lgretry = INIT_LG_RETRY;
546 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
547 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
548 qi->tqi_burstTime = qinfo->tqi_burstTime;
549 qi->tqi_readyTime = qinfo->tqi_readyTime;
550
551 switch (qinfo->tqi_subtype) {
552 case ATH9K_WME_UPSD:
553 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
554 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
555 break;
556 default:
557 break;
558 }
559
560 return true;
561}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400562EXPORT_SYMBOL(ath9k_hw_set_txq_props);
Sujithf1dc5602008-10-29 10:16:30 +0530563
Sujithcbe61d82009-02-09 13:27:12 +0530564bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530565 struct ath9k_tx_queue_info *qinfo)
566{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700567 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530568 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530569 struct ath9k_tx_queue_info *qi;
570
571 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700572 ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
573 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530574 return false;
575 }
576
Sujith2660b812009-02-09 13:27:26 +0530577 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530578 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700579 ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
580 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530581 return false;
582 }
583
584 qinfo->tqi_qflags = qi->tqi_qflags;
585 qinfo->tqi_ver = qi->tqi_ver;
586 qinfo->tqi_subtype = qi->tqi_subtype;
587 qinfo->tqi_qflags = qi->tqi_qflags;
588 qinfo->tqi_priority = qi->tqi_priority;
589 qinfo->tqi_aifs = qi->tqi_aifs;
590 qinfo->tqi_cwmin = qi->tqi_cwmin;
591 qinfo->tqi_cwmax = qi->tqi_cwmax;
592 qinfo->tqi_shretry = qi->tqi_shretry;
593 qinfo->tqi_lgretry = qi->tqi_lgretry;
594 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
595 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
596 qinfo->tqi_burstTime = qi->tqi_burstTime;
597 qinfo->tqi_readyTime = qi->tqi_readyTime;
598
599 return true;
600}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400601EXPORT_SYMBOL(ath9k_hw_get_txq_props);
Sujithf1dc5602008-10-29 10:16:30 +0530602
Sujithcbe61d82009-02-09 13:27:12 +0530603int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
Sujithf1dc5602008-10-29 10:16:30 +0530604 const struct ath9k_tx_queue_info *qinfo)
605{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700606 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530607 struct ath9k_tx_queue_info *qi;
Sujith2660b812009-02-09 13:27:26 +0530608 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530609 int q;
610
611 switch (type) {
612 case ATH9K_TX_QUEUE_BEACON:
613 q = pCap->total_queues - 1;
614 break;
615 case ATH9K_TX_QUEUE_CAB:
616 q = pCap->total_queues - 2;
617 break;
618 case ATH9K_TX_QUEUE_PSPOLL:
619 q = 1;
620 break;
621 case ATH9K_TX_QUEUE_UAPSD:
622 q = pCap->total_queues - 3;
623 break;
624 case ATH9K_TX_QUEUE_DATA:
625 for (q = 0; q < pCap->total_queues; q++)
Sujith2660b812009-02-09 13:27:26 +0530626 if (ah->txq[q].tqi_type ==
Sujithf1dc5602008-10-29 10:16:30 +0530627 ATH9K_TX_QUEUE_INACTIVE)
628 break;
629 if (q == pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700630 ath_print(common, ATH_DBG_FATAL,
631 "No available TX queue\n");
Sujithf1dc5602008-10-29 10:16:30 +0530632 return -1;
633 }
634 break;
635 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700636 ath_print(common, ATH_DBG_FATAL,
637 "Invalid TX queue type: %u\n", type);
Sujithf1dc5602008-10-29 10:16:30 +0530638 return -1;
639 }
640
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700641 ath_print(common, ATH_DBG_QUEUE, "Setup TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530642
Sujith2660b812009-02-09 13:27:26 +0530643 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530644 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700645 ath_print(common, ATH_DBG_FATAL,
646 "TX queue: %u already active\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530647 return -1;
648 }
649 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
650 qi->tqi_type = type;
651 if (qinfo == NULL) {
652 qi->tqi_qflags =
653 TXQ_FLAG_TXOKINT_ENABLE
654 | TXQ_FLAG_TXERRINT_ENABLE
655 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
656 qi->tqi_aifs = INIT_AIFS;
657 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
658 qi->tqi_cwmax = INIT_CWMAX;
659 qi->tqi_shretry = INIT_SH_RETRY;
660 qi->tqi_lgretry = INIT_LG_RETRY;
661 qi->tqi_physCompBuf = 0;
662 } else {
663 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
664 (void) ath9k_hw_set_txq_props(ah, q, qinfo);
665 }
666
667 return q;
668}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400669EXPORT_SYMBOL(ath9k_hw_setuptxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530670
Sujithcbe61d82009-02-09 13:27:12 +0530671bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530672{
Sujith2660b812009-02-09 13:27:26 +0530673 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700674 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530675 struct ath9k_tx_queue_info *qi;
676
677 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700678 ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
679 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530680 return false;
681 }
Sujith2660b812009-02-09 13:27:26 +0530682 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530683 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700684 ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
685 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530686 return false;
687 }
688
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700689 ath_print(common, ATH_DBG_QUEUE, "Release TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530690
691 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
Sujith2660b812009-02-09 13:27:26 +0530692 ah->txok_interrupt_mask &= ~(1 << q);
693 ah->txerr_interrupt_mask &= ~(1 << q);
694 ah->txdesc_interrupt_mask &= ~(1 << q);
695 ah->txeol_interrupt_mask &= ~(1 << q);
696 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530697 ath9k_hw_set_txq_interrupts(ah, qi);
698
699 return true;
700}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400701EXPORT_SYMBOL(ath9k_hw_releasetxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530702
Sujithcbe61d82009-02-09 13:27:12 +0530703bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530704{
Sujith2660b812009-02-09 13:27:26 +0530705 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700706 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530707 struct ath9k_channel *chan = ah->curchan;
Sujithf1dc5602008-10-29 10:16:30 +0530708 struct ath9k_tx_queue_info *qi;
709 u32 cwMin, chanCwMin, value;
710
711 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700712 ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
713 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530714 return false;
715 }
716
Sujith2660b812009-02-09 13:27:26 +0530717 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530718 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700719 ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
720 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530721 return true;
722 }
723
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700724 ath_print(common, ATH_DBG_QUEUE, "Reset TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530725
726 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
727 if (chan && IS_CHAN_B(chan))
728 chanCwMin = INIT_CWMIN_11B;
729 else
730 chanCwMin = INIT_CWMIN;
731
732 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
733 } else
734 cwMin = qi->tqi_cwmin;
735
736 REG_WRITE(ah, AR_DLCL_IFS(q),
737 SM(cwMin, AR_D_LCL_IFS_CWMIN) |
738 SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
739 SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
740
741 REG_WRITE(ah, AR_DRETRY_LIMIT(q),
742 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
743 SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
744 SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
745
746 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
747 REG_WRITE(ah, AR_DMISC(q),
748 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
749
750 if (qi->tqi_cbrPeriod) {
751 REG_WRITE(ah, AR_QCBRCFG(q),
752 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
753 SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
754 REG_WRITE(ah, AR_QMISC(q),
755 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
756 (qi->tqi_cbrOverflowLimit ?
757 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
758 }
759 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
760 REG_WRITE(ah, AR_QRDYTIMECFG(q),
761 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
762 AR_Q_RDYTIMECFG_EN);
763 }
764
765 REG_WRITE(ah, AR_DCHNTIME(q),
766 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
767 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
768
769 if (qi->tqi_burstTime
770 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
771 REG_WRITE(ah, AR_QMISC(q),
772 REG_READ(ah, AR_QMISC(q)) |
773 AR_Q_MISC_RDYTIME_EXP_POLICY);
774
775 }
776
777 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
778 REG_WRITE(ah, AR_DMISC(q),
779 REG_READ(ah, AR_DMISC(q)) |
780 AR_D_MISC_POST_FR_BKOFF_DIS);
781 }
782 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
783 REG_WRITE(ah, AR_DMISC(q),
784 REG_READ(ah, AR_DMISC(q)) |
785 AR_D_MISC_FRAG_BKOFF_EN);
786 }
787 switch (qi->tqi_type) {
788 case ATH9K_TX_QUEUE_BEACON:
789 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
790 | AR_Q_MISC_FSP_DBA_GATED
791 | AR_Q_MISC_BEACON_USE
792 | AR_Q_MISC_CBR_INCR_DIS1);
793
794 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
795 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
796 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
797 | AR_D_MISC_BEACON_USE
798 | AR_D_MISC_POST_FR_BKOFF_DIS);
799 break;
800 case ATH9K_TX_QUEUE_CAB:
801 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
802 | AR_Q_MISC_FSP_DBA_GATED
803 | AR_Q_MISC_CBR_INCR_DIS1
804 | AR_Q_MISC_CBR_INCR_DIS0);
805 value = (qi->tqi_readyTime -
Sujith2660b812009-02-09 13:27:26 +0530806 (ah->config.sw_beacon_response_time -
807 ah->config.dma_beacon_response_time) -
808 ah->config.additional_swba_backoff) * 1024;
Sujithf1dc5602008-10-29 10:16:30 +0530809 REG_WRITE(ah, AR_QRDYTIMECFG(q),
810 value | AR_Q_RDYTIMECFG_EN);
811 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
812 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
813 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
814 break;
815 case ATH9K_TX_QUEUE_PSPOLL:
816 REG_WRITE(ah, AR_QMISC(q),
817 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
818 break;
819 case ATH9K_TX_QUEUE_UAPSD:
820 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
821 AR_D_MISC_POST_FR_BKOFF_DIS);
822 break;
823 default:
824 break;
825 }
826
827 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
828 REG_WRITE(ah, AR_DMISC(q),
829 REG_READ(ah, AR_DMISC(q)) |
830 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
831 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
832 AR_D_MISC_POST_FR_BKOFF_DIS);
833 }
834
835 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530836 ah->txok_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530837 else
Sujith2660b812009-02-09 13:27:26 +0530838 ah->txok_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530839 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530840 ah->txerr_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530841 else
Sujith2660b812009-02-09 13:27:26 +0530842 ah->txerr_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530843 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530844 ah->txdesc_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530845 else
Sujith2660b812009-02-09 13:27:26 +0530846 ah->txdesc_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530847 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530848 ah->txeol_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530849 else
Sujith2660b812009-02-09 13:27:26 +0530850 ah->txeol_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530851 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530852 ah->txurn_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530853 else
Sujith2660b812009-02-09 13:27:26 +0530854 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530855 ath9k_hw_set_txq_interrupts(ah, qi);
856
857 return true;
858}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400859EXPORT_SYMBOL(ath9k_hw_resettxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530860
Sujithcbe61d82009-02-09 13:27:12 +0530861int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700862 struct ath_rx_status *rs, u64 tsf)
Sujithf1dc5602008-10-29 10:16:30 +0530863{
864 struct ar5416_desc ads;
865 struct ar5416_desc *adsp = AR5416DESC(ds);
866 u32 phyerr;
867
868 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
869 return -EINPROGRESS;
870
871 ads.u.rx = adsp->u.rx;
872
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700873 rs->rs_status = 0;
874 rs->rs_flags = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530875
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700876 rs->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
877 rs->rs_tstamp = ads.AR_RcvTimestamp;
Sujithf1dc5602008-10-29 10:16:30 +0530878
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400879 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700880 rs->rs_rssi = ATH9K_RSSI_BAD;
881 rs->rs_rssi_ctl0 = ATH9K_RSSI_BAD;
882 rs->rs_rssi_ctl1 = ATH9K_RSSI_BAD;
883 rs->rs_rssi_ctl2 = ATH9K_RSSI_BAD;
884 rs->rs_rssi_ext0 = ATH9K_RSSI_BAD;
885 rs->rs_rssi_ext1 = ATH9K_RSSI_BAD;
886 rs->rs_rssi_ext2 = ATH9K_RSSI_BAD;
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400887 } else {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700888 rs->rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
889 rs->rs_rssi_ctl0 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400890 AR_RxRSSIAnt00);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700891 rs->rs_rssi_ctl1 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400892 AR_RxRSSIAnt01);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700893 rs->rs_rssi_ctl2 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400894 AR_RxRSSIAnt02);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700895 rs->rs_rssi_ext0 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400896 AR_RxRSSIAnt10);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700897 rs->rs_rssi_ext1 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400898 AR_RxRSSIAnt11);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700899 rs->rs_rssi_ext2 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400900 AR_RxRSSIAnt12);
901 }
Sujithf1dc5602008-10-29 10:16:30 +0530902 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700903 rs->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
Sujithf1dc5602008-10-29 10:16:30 +0530904 else
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700905 rs->rs_keyix = ATH9K_RXKEYIX_INVALID;
Sujithf1dc5602008-10-29 10:16:30 +0530906
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700907 rs->rs_rate = RXSTATUS_RATE(ah, (&ads));
908 rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
Sujithf1dc5602008-10-29 10:16:30 +0530909
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700910 rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
911 rs->rs_moreaggr =
Sujithf1dc5602008-10-29 10:16:30 +0530912 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700913 rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
914 rs->rs_flags =
Sujithf1dc5602008-10-29 10:16:30 +0530915 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700916 rs->rs_flags |=
Sujithf1dc5602008-10-29 10:16:30 +0530917 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
918
919 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700920 rs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
Sujithf1dc5602008-10-29 10:16:30 +0530921 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700922 rs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
Sujithf1dc5602008-10-29 10:16:30 +0530923 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700924 rs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
Sujithf1dc5602008-10-29 10:16:30 +0530925
926 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
927 if (ads.ds_rxstatus8 & AR_CRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700928 rs->rs_status |= ATH9K_RXERR_CRC;
Sujithf1dc5602008-10-29 10:16:30 +0530929 else if (ads.ds_rxstatus8 & AR_PHYErr) {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700930 rs->rs_status |= ATH9K_RXERR_PHY;
Sujithf1dc5602008-10-29 10:16:30 +0530931 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700932 rs->rs_phyerr = phyerr;
Sujithf1dc5602008-10-29 10:16:30 +0530933 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700934 rs->rs_status |= ATH9K_RXERR_DECRYPT;
Sujithf1dc5602008-10-29 10:16:30 +0530935 else if (ads.ds_rxstatus8 & AR_MichaelErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700936 rs->rs_status |= ATH9K_RXERR_MIC;
Sujithf1dc5602008-10-29 10:16:30 +0530937 }
938
939 return 0;
940}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400941EXPORT_SYMBOL(ath9k_hw_rxprocdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530942
Sujith54e4cec2009-08-07 09:45:09 +0530943void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530944 u32 size, u32 flags)
945{
946 struct ar5416_desc *ads = AR5416DESC(ds);
Sujith2660b812009-02-09 13:27:26 +0530947 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530948
949 ads->ds_ctl1 = size & AR_BufLen;
950 if (flags & ATH9K_RXDESC_INTREQ)
951 ads->ds_ctl1 |= AR_RxIntrReq;
952
953 ads->ds_rxstatus8 &= ~AR_RxDone;
954 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
955 memset(&(ads->u), 0, sizeof(ads->u));
Sujithf1dc5602008-10-29 10:16:30 +0530956}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400957EXPORT_SYMBOL(ath9k_hw_setuprxdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530958
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -0500959/*
960 * This can stop or re-enables RX.
961 *
962 * If bool is set this will kill any frame which is currently being
963 * transferred between the MAC and baseband and also prevent any new
964 * frames from getting started.
965 */
Sujithcbe61d82009-02-09 13:27:12 +0530966bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
Sujithf1dc5602008-10-29 10:16:30 +0530967{
968 u32 reg;
969
970 if (set) {
971 REG_SET_BIT(ah, AR_DIAG_SW,
972 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
973
Sujith0caa7b12009-02-16 13:23:20 +0530974 if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
975 0, AH_WAIT_TIMEOUT)) {
Sujithf1dc5602008-10-29 10:16:30 +0530976 REG_CLR_BIT(ah, AR_DIAG_SW,
977 (AR_DIAG_RX_DIS |
978 AR_DIAG_RX_ABORT));
979
980 reg = REG_READ(ah, AR_OBS_BUS_1);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700981 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
982 "RX failed to go idle in 10 ms RXSM=0x%x\n",
983 reg);
Sujithf1dc5602008-10-29 10:16:30 +0530984
985 return false;
986 }
987 } else {
988 REG_CLR_BIT(ah, AR_DIAG_SW,
989 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
990 }
991
992 return true;
993}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400994EXPORT_SYMBOL(ath9k_hw_setrxabort);
Sujithf1dc5602008-10-29 10:16:30 +0530995
Sujithcbe61d82009-02-09 13:27:12 +0530996void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
Sujithf1dc5602008-10-29 10:16:30 +0530997{
998 REG_WRITE(ah, AR_RXDP, rxdp);
999}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001000EXPORT_SYMBOL(ath9k_hw_putrxbuf);
Sujithf1dc5602008-10-29 10:16:30 +05301001
Sujithcbe61d82009-02-09 13:27:12 +05301002void ath9k_hw_rxena(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301003{
1004 REG_WRITE(ah, AR_CR, AR_CR_RXE);
1005}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001006EXPORT_SYMBOL(ath9k_hw_rxena);
Sujithf1dc5602008-10-29 10:16:30 +05301007
Sujithcbe61d82009-02-09 13:27:12 +05301008void ath9k_hw_startpcureceive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301009{
Sujithf1dc5602008-10-29 10:16:30 +05301010 ath9k_enable_mib_counters(ah);
1011
1012 ath9k_ani_reset(ah);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301013
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301014 REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
Sujithf1dc5602008-10-29 10:16:30 +05301015}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001016EXPORT_SYMBOL(ath9k_hw_startpcureceive);
Sujithf1dc5602008-10-29 10:16:30 +05301017
Sujithcbe61d82009-02-09 13:27:12 +05301018void ath9k_hw_stoppcurecv(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301019{
1020 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
1021
1022 ath9k_hw_disable_mib_counters(ah);
1023}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001024EXPORT_SYMBOL(ath9k_hw_stoppcurecv);
Sujithf1dc5602008-10-29 10:16:30 +05301025
Sujithcbe61d82009-02-09 13:27:12 +05301026bool ath9k_hw_stopdmarecv(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301027{
Sujith0caa7b12009-02-16 13:23:20 +05301028#define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
1029#define AH_RX_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001030 struct ath_common *common = ath9k_hw_common(ah);
Sujith0caa7b12009-02-16 13:23:20 +05301031 int i;
1032
Sujithf1dc5602008-10-29 10:16:30 +05301033 REG_WRITE(ah, AR_CR, AR_CR_RXD);
1034
Sujith0caa7b12009-02-16 13:23:20 +05301035 /* Wait for rx enable bit to go low */
1036 for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
1037 if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
1038 break;
1039 udelay(AH_TIME_QUANTUM);
1040 }
1041
1042 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001043 ath_print(common, ATH_DBG_FATAL,
1044 "DMA failed to stop in %d ms "
1045 "AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
1046 AH_RX_STOP_DMA_TIMEOUT / 1000,
1047 REG_READ(ah, AR_CR),
1048 REG_READ(ah, AR_DIAG_SW));
Sujithf1dc5602008-10-29 10:16:30 +05301049 return false;
1050 } else {
1051 return true;
1052 }
Sujith0caa7b12009-02-16 13:23:20 +05301053
1054#undef AH_RX_TIME_QUANTUM
1055#undef AH_RX_STOP_DMA_TIMEOUT
Sujithf1dc5602008-10-29 10:16:30 +05301056}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001057EXPORT_SYMBOL(ath9k_hw_stopdmarecv);
Luis R. Rodriguez536b3a72009-10-06 21:19:11 -04001058
1059int ath9k_hw_beaconq_setup(struct ath_hw *ah)
1060{
1061 struct ath9k_tx_queue_info qi;
1062
1063 memset(&qi, 0, sizeof(qi));
1064 qi.tqi_aifs = 1;
1065 qi.tqi_cwmin = 0;
1066 qi.tqi_cwmax = 0;
1067 /* NB: don't enable any interrupts */
1068 return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
1069}
1070EXPORT_SYMBOL(ath9k_hw_beaconq_setup);