blob: 926f201ce4fa688ac3a6c4fd8fbaf833d23edbb8 [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
Sujith394cf0a2009-02-09 13:26:54 +053017#include "ath9k.h"
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070018#include "hw.h"
Sujithf1dc5602008-10-29 10:16:30 +053019
Sujithcbe61d82009-02-09 13:27:12 +053020static void ath9k_hw_set_txq_interrupts(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +053021 struct ath9k_tx_queue_info *qi)
22{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070023 ath_print(ath9k_hw_common(ah), ATH_DBG_INTERRUPT,
24 "tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
25 ah->txok_interrupt_mask, ah->txerr_interrupt_mask,
26 ah->txdesc_interrupt_mask, ah->txeol_interrupt_mask,
27 ah->txurn_interrupt_mask);
Sujithf1dc5602008-10-29 10:16:30 +053028
29 REG_WRITE(ah, AR_IMR_S0,
Sujith2660b812009-02-09 13:27:26 +053030 SM(ah->txok_interrupt_mask, AR_IMR_S0_QCU_TXOK)
31 | SM(ah->txdesc_interrupt_mask, AR_IMR_S0_QCU_TXDESC));
Sujithf1dc5602008-10-29 10:16:30 +053032 REG_WRITE(ah, AR_IMR_S1,
Sujith2660b812009-02-09 13:27:26 +053033 SM(ah->txerr_interrupt_mask, AR_IMR_S1_QCU_TXERR)
34 | SM(ah->txeol_interrupt_mask, AR_IMR_S1_QCU_TXEOL));
Sujithf1dc5602008-10-29 10:16:30 +053035 REG_RMW_FIELD(ah, AR_IMR_S2,
Sujith2660b812009-02-09 13:27:26 +053036 AR_IMR_S2_QCU_TXURN, ah->txurn_interrupt_mask);
Sujithf1dc5602008-10-29 10:16:30 +053037}
38
Sujithcbe61d82009-02-09 13:27:12 +053039u32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053040{
41 return REG_READ(ah, AR_QTXDP(q));
42}
43
Sujith54e4cec2009-08-07 09:45:09 +053044void ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp)
Sujithf1dc5602008-10-29 10:16:30 +053045{
46 REG_WRITE(ah, AR_QTXDP(q), txdp);
Sujithf1dc5602008-10-29 10:16:30 +053047}
48
Sujith54e4cec2009-08-07 09:45:09 +053049void ath9k_hw_txstart(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053050{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070051 ath_print(ath9k_hw_common(ah), ATH_DBG_QUEUE,
52 "Enable TXE on queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +053053 REG_WRITE(ah, AR_Q_TXE, 1 << q);
Sujithf1dc5602008-10-29 10:16:30 +053054}
55
Sujithcbe61d82009-02-09 13:27:12 +053056u32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053057{
58 u32 npend;
59
60 npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
61 if (npend == 0) {
62
63 if (REG_READ(ah, AR_Q_TXE) & (1 << q))
64 npend = 1;
65 }
66
67 return npend;
68}
69
Sujithcbe61d82009-02-09 13:27:12 +053070bool ath9k_hw_updatetxtriglevel(struct ath_hw *ah, bool bIncTrigLevel)
Sujithf1dc5602008-10-29 10:16:30 +053071{
Sujithf1dc5602008-10-29 10:16:30 +053072 u32 txcfg, curLevel, newLevel;
73 enum ath9k_int omask;
74
Sujith2660b812009-02-09 13:27:26 +053075 if (ah->tx_trig_level >= MAX_TX_FIFO_THRESHOLD)
Sujithf1dc5602008-10-29 10:16:30 +053076 return false;
77
Sujith2660b812009-02-09 13:27:26 +053078 omask = ath9k_hw_set_interrupts(ah, ah->mask_reg & ~ATH9K_INT_GLOBAL);
Sujithf1dc5602008-10-29 10:16:30 +053079
80 txcfg = REG_READ(ah, AR_TXCFG);
81 curLevel = MS(txcfg, AR_FTRIG);
82 newLevel = curLevel;
83 if (bIncTrigLevel) {
84 if (curLevel < MAX_TX_FIFO_THRESHOLD)
85 newLevel++;
86 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
87 newLevel--;
88 if (newLevel != curLevel)
89 REG_WRITE(ah, AR_TXCFG,
90 (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
91
92 ath9k_hw_set_interrupts(ah, omask);
93
Sujith2660b812009-02-09 13:27:26 +053094 ah->tx_trig_level = newLevel;
Sujithf1dc5602008-10-29 10:16:30 +053095
96 return newLevel != curLevel;
97}
98
Sujithcbe61d82009-02-09 13:27:12 +053099bool ath9k_hw_stoptxdma(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530100{
Sujith94ff91d2009-01-27 15:06:38 +0530101#define ATH9K_TX_STOP_DMA_TIMEOUT 4000 /* usec */
102#define ATH9K_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700103 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530104 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujith94ff91d2009-01-27 15:06:38 +0530105 struct ath9k_tx_queue_info *qi;
Sujithf1dc5602008-10-29 10:16:30 +0530106 u32 tsfLow, j, wait;
Sujith94ff91d2009-01-27 15:06:38 +0530107 u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
108
109 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700110 ath_print(common, ATH_DBG_QUEUE, "Stopping TX DMA, "
111 "invalid queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530112 return false;
113 }
114
Sujith2660b812009-02-09 13:27:26 +0530115 qi = &ah->txq[q];
Sujith94ff91d2009-01-27 15:06:38 +0530116 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700117 ath_print(common, ATH_DBG_QUEUE, "Stopping TX DMA, "
118 "inactive queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530119 return false;
120 }
Sujithf1dc5602008-10-29 10:16:30 +0530121
122 REG_WRITE(ah, AR_Q_TXD, 1 << q);
123
Sujith94ff91d2009-01-27 15:06:38 +0530124 for (wait = wait_time; wait != 0; wait--) {
Sujithf1dc5602008-10-29 10:16:30 +0530125 if (ath9k_hw_numtxpending(ah, q) == 0)
126 break;
Sujith94ff91d2009-01-27 15:06:38 +0530127 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530128 }
129
130 if (ath9k_hw_numtxpending(ah, q)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700131 ath_print(common, ATH_DBG_QUEUE,
132 "%s: Num of pending TX Frames %d on Q %d\n",
133 __func__, ath9k_hw_numtxpending(ah, q), q);
Sujithf1dc5602008-10-29 10:16:30 +0530134
135 for (j = 0; j < 2; j++) {
136 tsfLow = REG_READ(ah, AR_TSF_L32);
137 REG_WRITE(ah, AR_QUIET2,
138 SM(10, AR_QUIET2_QUIET_DUR));
139 REG_WRITE(ah, AR_QUIET_PERIOD, 100);
140 REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
141 REG_SET_BIT(ah, AR_TIMER_MODE,
142 AR_QUIET_TIMER_EN);
143
144 if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10))
145 break;
146
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700147 ath_print(common, ATH_DBG_QUEUE,
148 "TSF has moved while trying to set "
149 "quiet time TSF: 0x%08x\n", tsfLow);
Sujithf1dc5602008-10-29 10:16:30 +0530150 }
151
152 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
153
154 udelay(200);
155 REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);
156
Sujith94ff91d2009-01-27 15:06:38 +0530157 wait = wait_time;
Sujithf1dc5602008-10-29 10:16:30 +0530158 while (ath9k_hw_numtxpending(ah, q)) {
159 if ((--wait) == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700160 ath_print(common, ATH_DBG_QUEUE,
161 "Failed to stop TX DMA in 100 "
162 "msec after killing last frame\n");
Sujithf1dc5602008-10-29 10:16:30 +0530163 break;
164 }
Sujith94ff91d2009-01-27 15:06:38 +0530165 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530166 }
167
168 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
169 }
170
171 REG_WRITE(ah, AR_Q_TXD, 0);
Sujithf1dc5602008-10-29 10:16:30 +0530172 return wait != 0;
Sujith94ff91d2009-01-27 15:06:38 +0530173
174#undef ATH9K_TX_STOP_DMA_TIMEOUT
175#undef ATH9K_TIME_QUANTUM
Sujithf1dc5602008-10-29 10:16:30 +0530176}
177
Sujith54e4cec2009-08-07 09:45:09 +0530178void ath9k_hw_filltxdesc(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530179 u32 segLen, bool firstSeg,
180 bool lastSeg, const struct ath_desc *ds0)
181{
182 struct ar5416_desc *ads = AR5416DESC(ds);
183
184 if (firstSeg) {
185 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
186 } else if (lastSeg) {
187 ads->ds_ctl0 = 0;
188 ads->ds_ctl1 = segLen;
189 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
190 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
191 } else {
192 ads->ds_ctl0 = 0;
193 ads->ds_ctl1 = segLen | AR_TxMore;
194 ads->ds_ctl2 = 0;
195 ads->ds_ctl3 = 0;
196 }
197 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
198 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
199 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
200 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
201 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530202}
203
Sujithcbe61d82009-02-09 13:27:12 +0530204void ath9k_hw_cleartxdesc(struct ath_hw *ah, struct ath_desc *ds)
Sujithf1dc5602008-10-29 10:16:30 +0530205{
206 struct ar5416_desc *ads = AR5416DESC(ds);
207
208 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
209 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
210 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
211 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
212 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
213}
214
Sujithcbe61d82009-02-09 13:27:12 +0530215int ath9k_hw_txprocdesc(struct ath_hw *ah, struct ath_desc *ds)
Sujithf1dc5602008-10-29 10:16:30 +0530216{
217 struct ar5416_desc *ads = AR5416DESC(ds);
218
219 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
220 return -EINPROGRESS;
221
222 ds->ds_txstat.ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
223 ds->ds_txstat.ts_tstamp = ads->AR_SendTimestamp;
224 ds->ds_txstat.ts_status = 0;
225 ds->ds_txstat.ts_flags = 0;
226
227 if (ads->ds_txstatus1 & AR_ExcessiveRetries)
228 ds->ds_txstat.ts_status |= ATH9K_TXERR_XRETRY;
229 if (ads->ds_txstatus1 & AR_Filtered)
230 ds->ds_txstat.ts_status |= ATH9K_TXERR_FILT;
Sujithdaa9deb2008-11-18 09:10:22 +0530231 if (ads->ds_txstatus1 & AR_FIFOUnderrun) {
Sujithf1dc5602008-10-29 10:16:30 +0530232 ds->ds_txstat.ts_status |= ATH9K_TXERR_FIFO;
Sujithdaa9deb2008-11-18 09:10:22 +0530233 ath9k_hw_updatetxtriglevel(ah, true);
234 }
Sujithf1dc5602008-10-29 10:16:30 +0530235 if (ads->ds_txstatus9 & AR_TxOpExceeded)
236 ds->ds_txstat.ts_status |= ATH9K_TXERR_XTXOP;
237 if (ads->ds_txstatus1 & AR_TxTimerExpired)
238 ds->ds_txstat.ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
239
240 if (ads->ds_txstatus1 & AR_DescCfgErr)
241 ds->ds_txstat.ts_flags |= ATH9K_TX_DESC_CFG_ERR;
242 if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
243 ds->ds_txstat.ts_flags |= ATH9K_TX_DATA_UNDERRUN;
244 ath9k_hw_updatetxtriglevel(ah, true);
245 }
246 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
247 ds->ds_txstat.ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
248 ath9k_hw_updatetxtriglevel(ah, true);
249 }
250 if (ads->ds_txstatus0 & AR_TxBaStatus) {
251 ds->ds_txstat.ts_flags |= ATH9K_TX_BA;
252 ds->ds_txstat.ba_low = ads->AR_BaBitmapLow;
253 ds->ds_txstat.ba_high = ads->AR_BaBitmapHigh;
254 }
255
256 ds->ds_txstat.ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
257 switch (ds->ds_txstat.ts_rateindex) {
258 case 0:
259 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
260 break;
261 case 1:
262 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
263 break;
264 case 2:
265 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
266 break;
267 case 3:
268 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
269 break;
270 }
271
272 ds->ds_txstat.ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
273 ds->ds_txstat.ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
274 ds->ds_txstat.ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
275 ds->ds_txstat.ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
276 ds->ds_txstat.ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
277 ds->ds_txstat.ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
278 ds->ds_txstat.ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
279 ds->ds_txstat.evm0 = ads->AR_TxEVM0;
280 ds->ds_txstat.evm1 = ads->AR_TxEVM1;
281 ds->ds_txstat.evm2 = ads->AR_TxEVM2;
282 ds->ds_txstat.ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
283 ds->ds_txstat.ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
284 ds->ds_txstat.ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
Sujith83befbd2009-02-16 13:23:21 +0530285 ds->ds_txstat.ts_antenna = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530286
287 return 0;
288}
289
Sujithcbe61d82009-02-09 13:27:12 +0530290void ath9k_hw_set11n_txdesc(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530291 u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
292 u32 keyIx, enum ath9k_key_type keyType, u32 flags)
293{
294 struct ar5416_desc *ads = AR5416DESC(ds);
Sujithf1dc5602008-10-29 10:16:30 +0530295
Sujith2660b812009-02-09 13:27:26 +0530296 txPower += ah->txpower_indexoffset;
Sujithf1dc5602008-10-29 10:16:30 +0530297 if (txPower > 63)
298 txPower = 63;
299
300 ads->ds_ctl0 = (pktLen & AR_FrameLen)
301 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
302 | SM(txPower, AR_XmitPower)
303 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
304 | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
305 | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
306 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
307
308 ads->ds_ctl1 =
309 (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
310 | SM(type, AR_FrameType)
311 | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
312 | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
313 | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
314
315 ads->ds_ctl6 = SM(keyType, AR_EncrType);
316
317 if (AR_SREV_9285(ah)) {
318 ads->ds_ctl8 = 0;
319 ads->ds_ctl9 = 0;
320 ads->ds_ctl10 = 0;
321 ads->ds_ctl11 = 0;
322 }
323}
324
Sujithcbe61d82009-02-09 13:27:12 +0530325void ath9k_hw_set11n_ratescenario(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530326 struct ath_desc *lastds,
327 u32 durUpdateEn, u32 rtsctsRate,
328 u32 rtsctsDuration,
329 struct ath9k_11n_rate_series series[],
330 u32 nseries, u32 flags)
331{
332 struct ar5416_desc *ads = AR5416DESC(ds);
333 struct ar5416_desc *last_ads = AR5416DESC(lastds);
334 u32 ds_ctl0;
335
Sujithf1dc5602008-10-29 10:16:30 +0530336 if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
337 ds_ctl0 = ads->ds_ctl0;
338
339 if (flags & ATH9K_TXDESC_RTSENA) {
340 ds_ctl0 &= ~AR_CTSEnable;
341 ds_ctl0 |= AR_RTSEnable;
342 } else {
343 ds_ctl0 &= ~AR_RTSEnable;
344 ds_ctl0 |= AR_CTSEnable;
345 }
346
347 ads->ds_ctl0 = ds_ctl0;
348 } else {
349 ads->ds_ctl0 =
350 (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
351 }
352
353 ads->ds_ctl2 = set11nTries(series, 0)
354 | set11nTries(series, 1)
355 | set11nTries(series, 2)
356 | set11nTries(series, 3)
357 | (durUpdateEn ? AR_DurUpdateEna : 0)
358 | SM(0, AR_BurstDur);
359
360 ads->ds_ctl3 = set11nRate(series, 0)
361 | set11nRate(series, 1)
362 | set11nRate(series, 2)
363 | set11nRate(series, 3);
364
365 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
366 | set11nPktDurRTSCTS(series, 1);
367
368 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
369 | set11nPktDurRTSCTS(series, 3);
370
371 ads->ds_ctl7 = set11nRateFlags(series, 0)
372 | set11nRateFlags(series, 1)
373 | set11nRateFlags(series, 2)
374 | set11nRateFlags(series, 3)
375 | SM(rtsctsRate, AR_RTSCTSRate);
376 last_ads->ds_ctl2 = ads->ds_ctl2;
377 last_ads->ds_ctl3 = ads->ds_ctl3;
378}
379
Sujithcbe61d82009-02-09 13:27:12 +0530380void ath9k_hw_set11n_aggr_first(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530381 u32 aggrLen)
382{
383 struct ar5416_desc *ads = AR5416DESC(ds);
384
385 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
386 ads->ds_ctl6 &= ~AR_AggrLen;
387 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
388}
389
Sujithcbe61d82009-02-09 13:27:12 +0530390void ath9k_hw_set11n_aggr_middle(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530391 u32 numDelims)
392{
393 struct ar5416_desc *ads = AR5416DESC(ds);
394 unsigned int ctl6;
395
396 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
397
398 ctl6 = ads->ds_ctl6;
399 ctl6 &= ~AR_PadDelim;
400 ctl6 |= SM(numDelims, AR_PadDelim);
401 ads->ds_ctl6 = ctl6;
402}
403
Sujithcbe61d82009-02-09 13:27:12 +0530404void ath9k_hw_set11n_aggr_last(struct ath_hw *ah, struct ath_desc *ds)
Sujithf1dc5602008-10-29 10:16:30 +0530405{
406 struct ar5416_desc *ads = AR5416DESC(ds);
407
408 ads->ds_ctl1 |= AR_IsAggr;
409 ads->ds_ctl1 &= ~AR_MoreAggr;
410 ads->ds_ctl6 &= ~AR_PadDelim;
411}
412
Sujithcbe61d82009-02-09 13:27:12 +0530413void ath9k_hw_clr11n_aggr(struct ath_hw *ah, struct ath_desc *ds)
Sujithf1dc5602008-10-29 10:16:30 +0530414{
415 struct ar5416_desc *ads = AR5416DESC(ds);
416
417 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
418}
419
Sujithcbe61d82009-02-09 13:27:12 +0530420void ath9k_hw_set11n_burstduration(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530421 u32 burstDuration)
422{
423 struct ar5416_desc *ads = AR5416DESC(ds);
424
425 ads->ds_ctl2 &= ~AR_BurstDur;
426 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
427}
428
Sujithcbe61d82009-02-09 13:27:12 +0530429void ath9k_hw_set11n_virtualmorefrag(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530430 u32 vmf)
431{
432 struct ar5416_desc *ads = AR5416DESC(ds);
433
434 if (vmf)
435 ads->ds_ctl0 |= AR_VirtMoreFrag;
436 else
437 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
438}
439
Sujithcbe61d82009-02-09 13:27:12 +0530440void ath9k_hw_gettxintrtxqs(struct ath_hw *ah, u32 *txqs)
Sujithf1dc5602008-10-29 10:16:30 +0530441{
Sujith2660b812009-02-09 13:27:26 +0530442 *txqs &= ah->intr_txqs;
443 ah->intr_txqs &= ~(*txqs);
Sujithf1dc5602008-10-29 10:16:30 +0530444}
445
Sujithcbe61d82009-02-09 13:27:12 +0530446bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530447 const struct ath9k_tx_queue_info *qinfo)
448{
449 u32 cw;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700450 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530451 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530452 struct ath9k_tx_queue_info *qi;
453
454 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700455 ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
456 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530457 return false;
458 }
459
Sujith2660b812009-02-09 13:27:26 +0530460 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530461 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700462 ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
463 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530464 return false;
465 }
466
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700467 ath_print(common, ATH_DBG_QUEUE, "Set queue properties for: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530468
469 qi->tqi_ver = qinfo->tqi_ver;
470 qi->tqi_subtype = qinfo->tqi_subtype;
471 qi->tqi_qflags = qinfo->tqi_qflags;
472 qi->tqi_priority = qinfo->tqi_priority;
473 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
474 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
475 else
476 qi->tqi_aifs = INIT_AIFS;
477 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
478 cw = min(qinfo->tqi_cwmin, 1024U);
479 qi->tqi_cwmin = 1;
480 while (qi->tqi_cwmin < cw)
481 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
482 } else
483 qi->tqi_cwmin = qinfo->tqi_cwmin;
484 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
485 cw = min(qinfo->tqi_cwmax, 1024U);
486 qi->tqi_cwmax = 1;
487 while (qi->tqi_cwmax < cw)
488 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
489 } else
490 qi->tqi_cwmax = INIT_CWMAX;
491
492 if (qinfo->tqi_shretry != 0)
493 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
494 else
495 qi->tqi_shretry = INIT_SH_RETRY;
496 if (qinfo->tqi_lgretry != 0)
497 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
498 else
499 qi->tqi_lgretry = INIT_LG_RETRY;
500 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
501 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
502 qi->tqi_burstTime = qinfo->tqi_burstTime;
503 qi->tqi_readyTime = qinfo->tqi_readyTime;
504
505 switch (qinfo->tqi_subtype) {
506 case ATH9K_WME_UPSD:
507 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
508 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
509 break;
510 default:
511 break;
512 }
513
514 return true;
515}
516
Sujithcbe61d82009-02-09 13:27:12 +0530517bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530518 struct ath9k_tx_queue_info *qinfo)
519{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700520 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530521 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530522 struct ath9k_tx_queue_info *qi;
523
524 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700525 ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
526 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530527 return false;
528 }
529
Sujith2660b812009-02-09 13:27:26 +0530530 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530531 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700532 ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
533 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530534 return false;
535 }
536
537 qinfo->tqi_qflags = qi->tqi_qflags;
538 qinfo->tqi_ver = qi->tqi_ver;
539 qinfo->tqi_subtype = qi->tqi_subtype;
540 qinfo->tqi_qflags = qi->tqi_qflags;
541 qinfo->tqi_priority = qi->tqi_priority;
542 qinfo->tqi_aifs = qi->tqi_aifs;
543 qinfo->tqi_cwmin = qi->tqi_cwmin;
544 qinfo->tqi_cwmax = qi->tqi_cwmax;
545 qinfo->tqi_shretry = qi->tqi_shretry;
546 qinfo->tqi_lgretry = qi->tqi_lgretry;
547 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
548 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
549 qinfo->tqi_burstTime = qi->tqi_burstTime;
550 qinfo->tqi_readyTime = qi->tqi_readyTime;
551
552 return true;
553}
554
Sujithcbe61d82009-02-09 13:27:12 +0530555int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
Sujithf1dc5602008-10-29 10:16:30 +0530556 const struct ath9k_tx_queue_info *qinfo)
557{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700558 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530559 struct ath9k_tx_queue_info *qi;
Sujith2660b812009-02-09 13:27:26 +0530560 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530561 int q;
562
563 switch (type) {
564 case ATH9K_TX_QUEUE_BEACON:
565 q = pCap->total_queues - 1;
566 break;
567 case ATH9K_TX_QUEUE_CAB:
568 q = pCap->total_queues - 2;
569 break;
570 case ATH9K_TX_QUEUE_PSPOLL:
571 q = 1;
572 break;
573 case ATH9K_TX_QUEUE_UAPSD:
574 q = pCap->total_queues - 3;
575 break;
576 case ATH9K_TX_QUEUE_DATA:
577 for (q = 0; q < pCap->total_queues; q++)
Sujith2660b812009-02-09 13:27:26 +0530578 if (ah->txq[q].tqi_type ==
Sujithf1dc5602008-10-29 10:16:30 +0530579 ATH9K_TX_QUEUE_INACTIVE)
580 break;
581 if (q == pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700582 ath_print(common, ATH_DBG_FATAL,
583 "No available TX queue\n");
Sujithf1dc5602008-10-29 10:16:30 +0530584 return -1;
585 }
586 break;
587 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700588 ath_print(common, ATH_DBG_FATAL,
589 "Invalid TX queue type: %u\n", type);
Sujithf1dc5602008-10-29 10:16:30 +0530590 return -1;
591 }
592
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700593 ath_print(common, ATH_DBG_QUEUE, "Setup TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530594
Sujith2660b812009-02-09 13:27:26 +0530595 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530596 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700597 ath_print(common, ATH_DBG_FATAL,
598 "TX queue: %u already active\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530599 return -1;
600 }
601 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
602 qi->tqi_type = type;
603 if (qinfo == NULL) {
604 qi->tqi_qflags =
605 TXQ_FLAG_TXOKINT_ENABLE
606 | TXQ_FLAG_TXERRINT_ENABLE
607 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
608 qi->tqi_aifs = INIT_AIFS;
609 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
610 qi->tqi_cwmax = INIT_CWMAX;
611 qi->tqi_shretry = INIT_SH_RETRY;
612 qi->tqi_lgretry = INIT_LG_RETRY;
613 qi->tqi_physCompBuf = 0;
614 } else {
615 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
616 (void) ath9k_hw_set_txq_props(ah, q, qinfo);
617 }
618
619 return q;
620}
621
Sujithcbe61d82009-02-09 13:27:12 +0530622bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530623{
Sujith2660b812009-02-09 13:27:26 +0530624 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700625 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530626 struct ath9k_tx_queue_info *qi;
627
628 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700629 ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
630 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530631 return false;
632 }
Sujith2660b812009-02-09 13:27:26 +0530633 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530634 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700635 ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
636 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530637 return false;
638 }
639
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700640 ath_print(common, ATH_DBG_QUEUE, "Release TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530641
642 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
Sujith2660b812009-02-09 13:27:26 +0530643 ah->txok_interrupt_mask &= ~(1 << q);
644 ah->txerr_interrupt_mask &= ~(1 << q);
645 ah->txdesc_interrupt_mask &= ~(1 << q);
646 ah->txeol_interrupt_mask &= ~(1 << q);
647 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530648 ath9k_hw_set_txq_interrupts(ah, qi);
649
650 return true;
651}
652
Sujithcbe61d82009-02-09 13:27:12 +0530653bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530654{
Sujith2660b812009-02-09 13:27:26 +0530655 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700656 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530657 struct ath9k_channel *chan = ah->curchan;
Sujithf1dc5602008-10-29 10:16:30 +0530658 struct ath9k_tx_queue_info *qi;
659 u32 cwMin, chanCwMin, value;
660
661 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700662 ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
663 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530664 return false;
665 }
666
Sujith2660b812009-02-09 13:27:26 +0530667 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530668 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700669 ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
670 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530671 return true;
672 }
673
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700674 ath_print(common, ATH_DBG_QUEUE, "Reset TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530675
676 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
677 if (chan && IS_CHAN_B(chan))
678 chanCwMin = INIT_CWMIN_11B;
679 else
680 chanCwMin = INIT_CWMIN;
681
682 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
683 } else
684 cwMin = qi->tqi_cwmin;
685
686 REG_WRITE(ah, AR_DLCL_IFS(q),
687 SM(cwMin, AR_D_LCL_IFS_CWMIN) |
688 SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
689 SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
690
691 REG_WRITE(ah, AR_DRETRY_LIMIT(q),
692 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
693 SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
694 SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
695
696 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
697 REG_WRITE(ah, AR_DMISC(q),
698 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
699
700 if (qi->tqi_cbrPeriod) {
701 REG_WRITE(ah, AR_QCBRCFG(q),
702 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
703 SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
704 REG_WRITE(ah, AR_QMISC(q),
705 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
706 (qi->tqi_cbrOverflowLimit ?
707 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
708 }
709 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
710 REG_WRITE(ah, AR_QRDYTIMECFG(q),
711 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
712 AR_Q_RDYTIMECFG_EN);
713 }
714
715 REG_WRITE(ah, AR_DCHNTIME(q),
716 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
717 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
718
719 if (qi->tqi_burstTime
720 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
721 REG_WRITE(ah, AR_QMISC(q),
722 REG_READ(ah, AR_QMISC(q)) |
723 AR_Q_MISC_RDYTIME_EXP_POLICY);
724
725 }
726
727 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
728 REG_WRITE(ah, AR_DMISC(q),
729 REG_READ(ah, AR_DMISC(q)) |
730 AR_D_MISC_POST_FR_BKOFF_DIS);
731 }
732 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
733 REG_WRITE(ah, AR_DMISC(q),
734 REG_READ(ah, AR_DMISC(q)) |
735 AR_D_MISC_FRAG_BKOFF_EN);
736 }
737 switch (qi->tqi_type) {
738 case ATH9K_TX_QUEUE_BEACON:
739 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
740 | AR_Q_MISC_FSP_DBA_GATED
741 | AR_Q_MISC_BEACON_USE
742 | AR_Q_MISC_CBR_INCR_DIS1);
743
744 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
745 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
746 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
747 | AR_D_MISC_BEACON_USE
748 | AR_D_MISC_POST_FR_BKOFF_DIS);
749 break;
750 case ATH9K_TX_QUEUE_CAB:
751 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
752 | AR_Q_MISC_FSP_DBA_GATED
753 | AR_Q_MISC_CBR_INCR_DIS1
754 | AR_Q_MISC_CBR_INCR_DIS0);
755 value = (qi->tqi_readyTime -
Sujith2660b812009-02-09 13:27:26 +0530756 (ah->config.sw_beacon_response_time -
757 ah->config.dma_beacon_response_time) -
758 ah->config.additional_swba_backoff) * 1024;
Sujithf1dc5602008-10-29 10:16:30 +0530759 REG_WRITE(ah, AR_QRDYTIMECFG(q),
760 value | AR_Q_RDYTIMECFG_EN);
761 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
762 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
763 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
764 break;
765 case ATH9K_TX_QUEUE_PSPOLL:
766 REG_WRITE(ah, AR_QMISC(q),
767 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
768 break;
769 case ATH9K_TX_QUEUE_UAPSD:
770 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
771 AR_D_MISC_POST_FR_BKOFF_DIS);
772 break;
773 default:
774 break;
775 }
776
777 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
778 REG_WRITE(ah, AR_DMISC(q),
779 REG_READ(ah, AR_DMISC(q)) |
780 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
781 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
782 AR_D_MISC_POST_FR_BKOFF_DIS);
783 }
784
785 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530786 ah->txok_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530787 else
Sujith2660b812009-02-09 13:27:26 +0530788 ah->txok_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530789 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530790 ah->txerr_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530791 else
Sujith2660b812009-02-09 13:27:26 +0530792 ah->txerr_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530793 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530794 ah->txdesc_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530795 else
Sujith2660b812009-02-09 13:27:26 +0530796 ah->txdesc_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530797 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530798 ah->txeol_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530799 else
Sujith2660b812009-02-09 13:27:26 +0530800 ah->txeol_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530801 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530802 ah->txurn_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530803 else
Sujith2660b812009-02-09 13:27:26 +0530804 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530805 ath9k_hw_set_txq_interrupts(ah, qi);
806
807 return true;
808}
809
Sujithcbe61d82009-02-09 13:27:12 +0530810int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530811 u32 pa, struct ath_desc *nds, u64 tsf)
812{
813 struct ar5416_desc ads;
814 struct ar5416_desc *adsp = AR5416DESC(ds);
815 u32 phyerr;
816
817 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
818 return -EINPROGRESS;
819
820 ads.u.rx = adsp->u.rx;
821
822 ds->ds_rxstat.rs_status = 0;
823 ds->ds_rxstat.rs_flags = 0;
824
825 ds->ds_rxstat.rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
826 ds->ds_rxstat.rs_tstamp = ads.AR_RcvTimestamp;
827
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400828 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) {
829 ds->ds_rxstat.rs_rssi = ATH9K_RSSI_BAD;
830 ds->ds_rxstat.rs_rssi_ctl0 = ATH9K_RSSI_BAD;
831 ds->ds_rxstat.rs_rssi_ctl1 = ATH9K_RSSI_BAD;
832 ds->ds_rxstat.rs_rssi_ctl2 = ATH9K_RSSI_BAD;
833 ds->ds_rxstat.rs_rssi_ext0 = ATH9K_RSSI_BAD;
834 ds->ds_rxstat.rs_rssi_ext1 = ATH9K_RSSI_BAD;
835 ds->ds_rxstat.rs_rssi_ext2 = ATH9K_RSSI_BAD;
836 } else {
837 ds->ds_rxstat.rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
838 ds->ds_rxstat.rs_rssi_ctl0 = MS(ads.ds_rxstatus0,
839 AR_RxRSSIAnt00);
840 ds->ds_rxstat.rs_rssi_ctl1 = MS(ads.ds_rxstatus0,
841 AR_RxRSSIAnt01);
842 ds->ds_rxstat.rs_rssi_ctl2 = MS(ads.ds_rxstatus0,
843 AR_RxRSSIAnt02);
844 ds->ds_rxstat.rs_rssi_ext0 = MS(ads.ds_rxstatus4,
845 AR_RxRSSIAnt10);
846 ds->ds_rxstat.rs_rssi_ext1 = MS(ads.ds_rxstatus4,
847 AR_RxRSSIAnt11);
848 ds->ds_rxstat.rs_rssi_ext2 = MS(ads.ds_rxstatus4,
849 AR_RxRSSIAnt12);
850 }
Sujithf1dc5602008-10-29 10:16:30 +0530851 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
852 ds->ds_rxstat.rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
853 else
854 ds->ds_rxstat.rs_keyix = ATH9K_RXKEYIX_INVALID;
855
856 ds->ds_rxstat.rs_rate = RXSTATUS_RATE(ah, (&ads));
857 ds->ds_rxstat.rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
858
859 ds->ds_rxstat.rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
860 ds->ds_rxstat.rs_moreaggr =
861 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
862 ds->ds_rxstat.rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
863 ds->ds_rxstat.rs_flags =
864 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
865 ds->ds_rxstat.rs_flags |=
866 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
867
868 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
869 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
870 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
871 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_POST;
872 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
873 ds->ds_rxstat.rs_flags |= ATH9K_RX_DECRYPT_BUSY;
874
875 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
876 if (ads.ds_rxstatus8 & AR_CRCErr)
877 ds->ds_rxstat.rs_status |= ATH9K_RXERR_CRC;
878 else if (ads.ds_rxstatus8 & AR_PHYErr) {
879 ds->ds_rxstat.rs_status |= ATH9K_RXERR_PHY;
880 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
881 ds->ds_rxstat.rs_phyerr = phyerr;
882 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
883 ds->ds_rxstat.rs_status |= ATH9K_RXERR_DECRYPT;
884 else if (ads.ds_rxstatus8 & AR_MichaelErr)
885 ds->ds_rxstat.rs_status |= ATH9K_RXERR_MIC;
886 }
887
888 return 0;
889}
890
Sujith54e4cec2009-08-07 09:45:09 +0530891void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530892 u32 size, u32 flags)
893{
894 struct ar5416_desc *ads = AR5416DESC(ds);
Sujith2660b812009-02-09 13:27:26 +0530895 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530896
897 ads->ds_ctl1 = size & AR_BufLen;
898 if (flags & ATH9K_RXDESC_INTREQ)
899 ads->ds_ctl1 |= AR_RxIntrReq;
900
901 ads->ds_rxstatus8 &= ~AR_RxDone;
902 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
903 memset(&(ads->u), 0, sizeof(ads->u));
Sujithf1dc5602008-10-29 10:16:30 +0530904}
905
Sujithcbe61d82009-02-09 13:27:12 +0530906bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
Sujithf1dc5602008-10-29 10:16:30 +0530907{
908 u32 reg;
909
910 if (set) {
911 REG_SET_BIT(ah, AR_DIAG_SW,
912 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
913
Sujith0caa7b12009-02-16 13:23:20 +0530914 if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
915 0, AH_WAIT_TIMEOUT)) {
Sujithf1dc5602008-10-29 10:16:30 +0530916 REG_CLR_BIT(ah, AR_DIAG_SW,
917 (AR_DIAG_RX_DIS |
918 AR_DIAG_RX_ABORT));
919
920 reg = REG_READ(ah, AR_OBS_BUS_1);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700921 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
922 "RX failed to go idle in 10 ms RXSM=0x%x\n",
923 reg);
Sujithf1dc5602008-10-29 10:16:30 +0530924
925 return false;
926 }
927 } else {
928 REG_CLR_BIT(ah, AR_DIAG_SW,
929 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
930 }
931
932 return true;
933}
934
Sujithcbe61d82009-02-09 13:27:12 +0530935void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
Sujithf1dc5602008-10-29 10:16:30 +0530936{
937 REG_WRITE(ah, AR_RXDP, rxdp);
938}
939
Sujithcbe61d82009-02-09 13:27:12 +0530940void ath9k_hw_rxena(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530941{
942 REG_WRITE(ah, AR_CR, AR_CR_RXE);
943}
944
Sujithcbe61d82009-02-09 13:27:12 +0530945void ath9k_hw_startpcureceive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530946{
Sujithf1dc5602008-10-29 10:16:30 +0530947 ath9k_enable_mib_counters(ah);
948
949 ath9k_ani_reset(ah);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530950
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +0530951 REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
Sujithf1dc5602008-10-29 10:16:30 +0530952}
953
Sujithcbe61d82009-02-09 13:27:12 +0530954void ath9k_hw_stoppcurecv(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530955{
956 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
957
958 ath9k_hw_disable_mib_counters(ah);
959}
960
Sujithcbe61d82009-02-09 13:27:12 +0530961bool ath9k_hw_stopdmarecv(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530962{
Sujith0caa7b12009-02-16 13:23:20 +0530963#define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
964#define AH_RX_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700965 struct ath_common *common = ath9k_hw_common(ah);
Sujith0caa7b12009-02-16 13:23:20 +0530966 int i;
967
Sujithf1dc5602008-10-29 10:16:30 +0530968 REG_WRITE(ah, AR_CR, AR_CR_RXD);
969
Sujith0caa7b12009-02-16 13:23:20 +0530970 /* Wait for rx enable bit to go low */
971 for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
972 if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
973 break;
974 udelay(AH_TIME_QUANTUM);
975 }
976
977 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700978 ath_print(common, ATH_DBG_FATAL,
979 "DMA failed to stop in %d ms "
980 "AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
981 AH_RX_STOP_DMA_TIMEOUT / 1000,
982 REG_READ(ah, AR_CR),
983 REG_READ(ah, AR_DIAG_SW));
Sujithf1dc5602008-10-29 10:16:30 +0530984 return false;
985 } else {
986 return true;
987 }
Sujith0caa7b12009-02-16 13:23:20 +0530988
989#undef AH_RX_TIME_QUANTUM
990#undef AH_RX_STOP_DMA_TIMEOUT
Sujithf1dc5602008-10-29 10:16:30 +0530991}