blob: 22fa5125abff0682a1a65e44a3ec747c47e9f4ae [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
Vasanthakumar Thiagarajancee1f622010-04-15 17:38:26 -040019static void ar9002_hw_rx_enable(struct ath_hw *ah)
20{
21 REG_WRITE(ah, AR_CR, AR_CR_RXE);
22}
23
Vasanthakumar Thiagarajan87d5efb2010-04-15 17:38:43 -040024static void ar9002_hw_set_desc_link(void *ds, u32 ds_link)
25{
26 ((struct ath_desc *) ds)->ds_link = ds_link;
27}
28
29static void ar9002_hw_get_desc_link(void *ds, u32 **ds_link)
30{
31 *ds_link = &((struct ath_desc *)ds)->ds_link;
32}
33
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -040034static bool ar9002_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
35{
36 u32 isr = 0;
37 u32 mask2 = 0;
38 struct ath9k_hw_capabilities *pCap = &ah->caps;
39 u32 sync_cause = 0;
40 bool fatal_int = false;
41 struct ath_common *common = ath9k_hw_common(ah);
42
43 if (!AR_SREV_9100(ah)) {
44 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
45 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
46 == AR_RTC_STATUS_ON) {
47 isr = REG_READ(ah, AR_ISR);
48 }
49 }
50
51 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
52 AR_INTR_SYNC_DEFAULT;
53
54 *masked = 0;
55
56 if (!isr && !sync_cause)
57 return false;
58 } else {
59 *masked = 0;
60 isr = REG_READ(ah, AR_ISR);
61 }
62
63 if (isr) {
64 if (isr & AR_ISR_BCNMISC) {
65 u32 isr2;
66 isr2 = REG_READ(ah, AR_ISR_S2);
67 if (isr2 & AR_ISR_S2_TIM)
68 mask2 |= ATH9K_INT_TIM;
69 if (isr2 & AR_ISR_S2_DTIM)
70 mask2 |= ATH9K_INT_DTIM;
71 if (isr2 & AR_ISR_S2_DTIMSYNC)
72 mask2 |= ATH9K_INT_DTIMSYNC;
73 if (isr2 & (AR_ISR_S2_CABEND))
74 mask2 |= ATH9K_INT_CABEND;
75 if (isr2 & AR_ISR_S2_GTT)
76 mask2 |= ATH9K_INT_GTT;
77 if (isr2 & AR_ISR_S2_CST)
78 mask2 |= ATH9K_INT_CST;
79 if (isr2 & AR_ISR_S2_TSFOOR)
80 mask2 |= ATH9K_INT_TSFOOR;
81 }
82
83 isr = REG_READ(ah, AR_ISR_RAC);
84 if (isr == 0xffffffff) {
85 *masked = 0;
86 return false;
87 }
88
89 *masked = isr & ATH9K_INT_COMMON;
90
91 if (ah->config.rx_intr_mitigation) {
92 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
93 *masked |= ATH9K_INT_RX;
94 }
95
96 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
97 *masked |= ATH9K_INT_RX;
98 if (isr &
99 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
100 AR_ISR_TXEOL)) {
101 u32 s0_s, s1_s;
102
103 *masked |= ATH9K_INT_TX;
104
105 s0_s = REG_READ(ah, AR_ISR_S0_S);
106 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
107 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
108
109 s1_s = REG_READ(ah, AR_ISR_S1_S);
110 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
111 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
112 }
113
114 if (isr & AR_ISR_RXORN) {
115 ath_print(common, ATH_DBG_INTERRUPT,
116 "receive FIFO overrun interrupt\n");
117 }
118
119 if (!AR_SREV_9100(ah)) {
120 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
121 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
122 if (isr5 & AR_ISR_S5_TIM_TIMER)
123 *masked |= ATH9K_INT_TIM_TIMER;
124 }
125 }
126
127 *masked |= mask2;
128 }
129
130 if (AR_SREV_9100(ah))
131 return true;
132
133 if (isr & AR_ISR_GENTMR) {
134 u32 s5_s;
135
136 s5_s = REG_READ(ah, AR_ISR_S5_S);
137 if (isr & AR_ISR_GENTMR) {
138 ah->intr_gen_timer_trigger =
139 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
140
141 ah->intr_gen_timer_thresh =
142 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
143
144 if (ah->intr_gen_timer_trigger)
145 *masked |= ATH9K_INT_GENTIMER;
146
147 }
148 }
149
150 if (sync_cause) {
151 fatal_int =
152 (sync_cause &
153 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
154 ? true : false;
155
156 if (fatal_int) {
157 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
158 ath_print(common, ATH_DBG_ANY,
159 "received PCI FATAL interrupt\n");
160 }
161 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
162 ath_print(common, ATH_DBG_ANY,
163 "received PCI PERR interrupt\n");
164 }
165 *masked |= ATH9K_INT_FATAL;
166 }
167 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
168 ath_print(common, ATH_DBG_INTERRUPT,
169 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
170 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
171 REG_WRITE(ah, AR_RC, 0);
172 *masked |= ATH9K_INT_FATAL;
173 }
174 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
175 ath_print(common, ATH_DBG_INTERRUPT,
176 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
177 }
178
179 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
180 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
181 }
182
183 return true;
184}
185
Vasanthakumar Thiagarajancc610ac02010-04-15 17:39:26 -0400186static void ar9002_hw_fill_txdesc(struct ath_hw *ah, void *ds, u32 seglen,
187 bool is_firstseg, bool is_lastseg,
188 const void *ds0, dma_addr_t buf_addr,
189 unsigned int qcu)
190{
191 struct ar5416_desc *ads = AR5416DESC(ds);
192
193 ads->ds_data = buf_addr;
194
195 if (is_firstseg) {
196 ads->ds_ctl1 |= seglen | (is_lastseg ? 0 : AR_TxMore);
197 } else if (is_lastseg) {
198 ads->ds_ctl0 = 0;
199 ads->ds_ctl1 = seglen;
200 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
201 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
202 } else {
203 ads->ds_ctl0 = 0;
204 ads->ds_ctl1 = seglen | AR_TxMore;
205 ads->ds_ctl2 = 0;
206 ads->ds_ctl3 = 0;
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
215static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
216 struct ath_tx_status *ts)
217{
218 struct ar5416_desc *ads = AR5416DESC(ds);
219
220 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
221 return -EINPROGRESS;
222
223 ts->ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
224 ts->ts_tstamp = ads->AR_SendTimestamp;
225 ts->ts_status = 0;
226 ts->ts_flags = 0;
227
228 if (ads->ds_txstatus1 & AR_FrmXmitOK)
229 ts->ts_status |= ATH9K_TX_ACKED;
230 if (ads->ds_txstatus1 & AR_ExcessiveRetries)
231 ts->ts_status |= ATH9K_TXERR_XRETRY;
232 if (ads->ds_txstatus1 & AR_Filtered)
233 ts->ts_status |= ATH9K_TXERR_FILT;
234 if (ads->ds_txstatus1 & AR_FIFOUnderrun) {
235 ts->ts_status |= ATH9K_TXERR_FIFO;
236 ath9k_hw_updatetxtriglevel(ah, true);
237 }
238 if (ads->ds_txstatus9 & AR_TxOpExceeded)
239 ts->ts_status |= ATH9K_TXERR_XTXOP;
240 if (ads->ds_txstatus1 & AR_TxTimerExpired)
241 ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
242
243 if (ads->ds_txstatus1 & AR_DescCfgErr)
244 ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
245 if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
246 ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
247 ath9k_hw_updatetxtriglevel(ah, true);
248 }
249 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
250 ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
251 ath9k_hw_updatetxtriglevel(ah, true);
252 }
253 if (ads->ds_txstatus0 & AR_TxBaStatus) {
254 ts->ts_flags |= ATH9K_TX_BA;
255 ts->ba_low = ads->AR_BaBitmapLow;
256 ts->ba_high = ads->AR_BaBitmapHigh;
257 }
258
259 ts->ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
260 switch (ts->ts_rateindex) {
261 case 0:
262 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
263 break;
264 case 1:
265 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
266 break;
267 case 2:
268 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
269 break;
270 case 3:
271 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
272 break;
273 }
274
275 ts->ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
276 ts->ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
277 ts->ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
278 ts->ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
279 ts->ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
280 ts->ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
281 ts->ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
282 ts->evm0 = ads->AR_TxEVM0;
283 ts->evm1 = ads->AR_TxEVM1;
284 ts->evm2 = ads->AR_TxEVM2;
285 ts->ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
286 ts->ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
287 ts->ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
288 ts->ts_antenna = 0;
289
290 return 0;
291}
292
293static void ar9002_hw_set11n_txdesc(struct ath_hw *ah, void *ds,
294 u32 pktLen, enum ath9k_pkt_type type,
295 u32 txPower, u32 keyIx,
296 enum ath9k_key_type keyType, u32 flags)
297{
298 struct ar5416_desc *ads = AR5416DESC(ds);
299
300 txPower += ah->txpower_indexoffset;
301 if (txPower > 63)
302 txPower = 63;
303
304 ads->ds_ctl0 = (pktLen & AR_FrameLen)
305 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
306 | SM(txPower, AR_XmitPower)
307 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
308 | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
309 | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
310 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
311
312 ads->ds_ctl1 =
313 (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
314 | SM(type, AR_FrameType)
315 | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
316 | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
317 | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
318
319 ads->ds_ctl6 = SM(keyType, AR_EncrType);
320
321 if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
322 ads->ds_ctl8 = 0;
323 ads->ds_ctl9 = 0;
324 ads->ds_ctl10 = 0;
325 ads->ds_ctl11 = 0;
326 }
327}
328
329static void ar9002_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
330 void *lastds,
331 u32 durUpdateEn, u32 rtsctsRate,
332 u32 rtsctsDuration,
333 struct ath9k_11n_rate_series series[],
334 u32 nseries, u32 flags)
335{
336 struct ar5416_desc *ads = AR5416DESC(ds);
337 struct ar5416_desc *last_ads = AR5416DESC(lastds);
338 u32 ds_ctl0;
339
340 if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
341 ds_ctl0 = ads->ds_ctl0;
342
343 if (flags & ATH9K_TXDESC_RTSENA) {
344 ds_ctl0 &= ~AR_CTSEnable;
345 ds_ctl0 |= AR_RTSEnable;
346 } else {
347 ds_ctl0 &= ~AR_RTSEnable;
348 ds_ctl0 |= AR_CTSEnable;
349 }
350
351 ads->ds_ctl0 = ds_ctl0;
352 } else {
353 ads->ds_ctl0 =
354 (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
355 }
356
357 ads->ds_ctl2 = set11nTries(series, 0)
358 | set11nTries(series, 1)
359 | set11nTries(series, 2)
360 | set11nTries(series, 3)
361 | (durUpdateEn ? AR_DurUpdateEna : 0)
362 | SM(0, AR_BurstDur);
363
364 ads->ds_ctl3 = set11nRate(series, 0)
365 | set11nRate(series, 1)
366 | set11nRate(series, 2)
367 | set11nRate(series, 3);
368
369 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
370 | set11nPktDurRTSCTS(series, 1);
371
372 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
373 | set11nPktDurRTSCTS(series, 3);
374
375 ads->ds_ctl7 = set11nRateFlags(series, 0)
376 | set11nRateFlags(series, 1)
377 | set11nRateFlags(series, 2)
378 | set11nRateFlags(series, 3)
379 | SM(rtsctsRate, AR_RTSCTSRate);
380 last_ads->ds_ctl2 = ads->ds_ctl2;
381 last_ads->ds_ctl3 = ads->ds_ctl3;
382}
383
384static void ar9002_hw_set11n_aggr_first(struct ath_hw *ah, void *ds,
385 u32 aggrLen)
386{
387 struct ar5416_desc *ads = AR5416DESC(ds);
388
389 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
390 ads->ds_ctl6 &= ~AR_AggrLen;
391 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
392}
393
394static void ar9002_hw_set11n_aggr_middle(struct ath_hw *ah, void *ds,
395 u32 numDelims)
396{
397 struct ar5416_desc *ads = AR5416DESC(ds);
398 unsigned int ctl6;
399
400 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
401
402 ctl6 = ads->ds_ctl6;
403 ctl6 &= ~AR_PadDelim;
404 ctl6 |= SM(numDelims, AR_PadDelim);
405 ads->ds_ctl6 = ctl6;
406}
407
408static void ar9002_hw_set11n_aggr_last(struct ath_hw *ah, void *ds)
409{
410 struct ar5416_desc *ads = AR5416DESC(ds);
411
412 ads->ds_ctl1 |= AR_IsAggr;
413 ads->ds_ctl1 &= ~AR_MoreAggr;
414 ads->ds_ctl6 &= ~AR_PadDelim;
415}
416
417static void ar9002_hw_clr11n_aggr(struct ath_hw *ah, void *ds)
418{
419 struct ar5416_desc *ads = AR5416DESC(ds);
420
421 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
422}
423
424static void ar9002_hw_set11n_burstduration(struct ath_hw *ah, void *ds,
425 u32 burstDuration)
426{
427 struct ar5416_desc *ads = AR5416DESC(ds);
428
429 ads->ds_ctl2 &= ~AR_BurstDur;
430 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
431}
432
433static void ar9002_hw_set11n_virtualmorefrag(struct ath_hw *ah, void *ds,
434 u32 vmf)
435{
436 struct ar5416_desc *ads = AR5416DESC(ds);
437
438 if (vmf)
439 ads->ds_ctl0 |= AR_VirtMoreFrag;
440 else
441 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
442}
443
Vasanthakumar Thiagarajancee1f622010-04-15 17:38:26 -0400444void ar9002_hw_attach_mac_ops(struct ath_hw *ah)
445{
446 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
447
448 ops->rx_enable = ar9002_hw_rx_enable;
Vasanthakumar Thiagarajan87d5efb2010-04-15 17:38:43 -0400449 ops->set_desc_link = ar9002_hw_set_desc_link;
450 ops->get_desc_link = ar9002_hw_get_desc_link;
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400451 ops->get_isr = ar9002_hw_get_isr;
Vasanthakumar Thiagarajancc610ac02010-04-15 17:39:26 -0400452 ops->fill_txdesc = ar9002_hw_fill_txdesc;
453 ops->proc_txdesc = ar9002_hw_proc_txdesc;
454 ops->set11n_txdesc = ar9002_hw_set11n_txdesc;
455 ops->set11n_ratescenario = ar9002_hw_set11n_ratescenario;
456 ops->set11n_aggr_first = ar9002_hw_set11n_aggr_first;
457 ops->set11n_aggr_middle = ar9002_hw_set11n_aggr_middle;
458 ops->set11n_aggr_last = ar9002_hw_set11n_aggr_last;
459 ops->clr11n_aggr = ar9002_hw_clr11n_aggr;
460 ops->set11n_burstduration = ar9002_hw_set11n_burstduration;
461 ops->set11n_virtualmorefrag = ar9002_hw_set11n_virtualmorefrag;
Vasanthakumar Thiagarajancee1f622010-04-15 17:38:26 -0400462}
Vasanthakumar Thiagarajan87d5efb2010-04-15 17:38:43 -0400463
Sujithcbe61d82009-02-09 13:27:12 +0530464static void ath9k_hw_set_txq_interrupts(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530465 struct ath9k_tx_queue_info *qi)
466{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700467 ath_print(ath9k_hw_common(ah), ATH_DBG_INTERRUPT,
468 "tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
469 ah->txok_interrupt_mask, ah->txerr_interrupt_mask,
470 ah->txdesc_interrupt_mask, ah->txeol_interrupt_mask,
471 ah->txurn_interrupt_mask);
Sujithf1dc5602008-10-29 10:16:30 +0530472
473 REG_WRITE(ah, AR_IMR_S0,
Sujith2660b812009-02-09 13:27:26 +0530474 SM(ah->txok_interrupt_mask, AR_IMR_S0_QCU_TXOK)
475 | SM(ah->txdesc_interrupt_mask, AR_IMR_S0_QCU_TXDESC));
Sujithf1dc5602008-10-29 10:16:30 +0530476 REG_WRITE(ah, AR_IMR_S1,
Sujith2660b812009-02-09 13:27:26 +0530477 SM(ah->txerr_interrupt_mask, AR_IMR_S1_QCU_TXERR)
478 | SM(ah->txeol_interrupt_mask, AR_IMR_S1_QCU_TXEOL));
Pavel Roskin74bad5c2010-02-23 18:15:27 -0500479
480 ah->imrs2_reg &= ~AR_IMR_S2_QCU_TXURN;
481 ah->imrs2_reg |= (ah->txurn_interrupt_mask & AR_IMR_S2_QCU_TXURN);
482 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +0530483}
484
Sujithcbe61d82009-02-09 13:27:12 +0530485u32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530486{
487 return REG_READ(ah, AR_QTXDP(q));
488}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400489EXPORT_SYMBOL(ath9k_hw_gettxbuf);
Sujithf1dc5602008-10-29 10:16:30 +0530490
Sujith54e4cec2009-08-07 09:45:09 +0530491void ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp)
Sujithf1dc5602008-10-29 10:16:30 +0530492{
493 REG_WRITE(ah, AR_QTXDP(q), txdp);
Sujithf1dc5602008-10-29 10:16:30 +0530494}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400495EXPORT_SYMBOL(ath9k_hw_puttxbuf);
Sujithf1dc5602008-10-29 10:16:30 +0530496
Sujith54e4cec2009-08-07 09:45:09 +0530497void ath9k_hw_txstart(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530498{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700499 ath_print(ath9k_hw_common(ah), ATH_DBG_QUEUE,
500 "Enable TXE on queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530501 REG_WRITE(ah, AR_Q_TXE, 1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530502}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400503EXPORT_SYMBOL(ath9k_hw_txstart);
Sujithf1dc5602008-10-29 10:16:30 +0530504
Vasanthakumar Thiagarajancc610ac02010-04-15 17:39:26 -0400505void ath9k_hw_cleartxdesc(struct ath_hw *ah, void *ds)
506{
507 struct ar5416_desc *ads = AR5416DESC(ds);
508
509 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
510 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
511 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
512 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
513 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
514}
515EXPORT_SYMBOL(ath9k_hw_cleartxdesc);
516
Sujithcbe61d82009-02-09 13:27:12 +0530517u32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530518{
519 u32 npend;
520
521 npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
522 if (npend == 0) {
523
524 if (REG_READ(ah, AR_Q_TXE) & (1 << q))
525 npend = 1;
526 }
527
528 return npend;
529}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400530EXPORT_SYMBOL(ath9k_hw_numtxpending);
Sujithf1dc5602008-10-29 10:16:30 +0530531
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500532/**
533 * ath9k_hw_updatetxtriglevel - adjusts the frame trigger level
534 *
535 * @ah: atheros hardware struct
536 * @bIncTrigLevel: whether or not the frame trigger level should be updated
537 *
538 * The frame trigger level specifies the minimum number of bytes,
539 * in units of 64 bytes, that must be DMA'ed into the PCU TX FIFO
540 * before the PCU will initiate sending the frame on the air. This can
541 * mean we initiate transmit before a full frame is on the PCU TX FIFO.
542 * Resets to 0x1 (meaning 64 bytes or a full frame, whichever occurs
543 * first)
544 *
545 * Caution must be taken to ensure to set the frame trigger level based
546 * on the DMA request size. For example if the DMA request size is set to
547 * 128 bytes the trigger level cannot exceed 6 * 64 = 384. This is because
548 * there need to be enough space in the tx FIFO for the requested transfer
549 * size. Hence the tx FIFO will stop with 512 - 128 = 384 bytes. If we set
550 * the threshold to a value beyond 6, then the transmit will hang.
551 *
552 * Current dual stream devices have a PCU TX FIFO size of 8 KB.
553 * Current single stream devices have a PCU TX FIFO size of 4 KB, however,
554 * there is a hardware issue which forces us to use 2 KB instead so the
555 * frame trigger level must not exceed 2 KB for these chipsets.
556 */
Sujithcbe61d82009-02-09 13:27:12 +0530557bool ath9k_hw_updatetxtriglevel(struct ath_hw *ah, bool bIncTrigLevel)
Sujithf1dc5602008-10-29 10:16:30 +0530558{
Sujithf1dc5602008-10-29 10:16:30 +0530559 u32 txcfg, curLevel, newLevel;
560 enum ath9k_int omask;
561
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500562 if (ah->tx_trig_level >= ah->config.max_txtrig_level)
Sujithf1dc5602008-10-29 10:16:30 +0530563 return false;
564
Pavel Roskin152d5302010-03-31 18:05:37 -0400565 omask = ath9k_hw_set_interrupts(ah, ah->imask & ~ATH9K_INT_GLOBAL);
Sujithf1dc5602008-10-29 10:16:30 +0530566
567 txcfg = REG_READ(ah, AR_TXCFG);
568 curLevel = MS(txcfg, AR_FTRIG);
569 newLevel = curLevel;
570 if (bIncTrigLevel) {
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500571 if (curLevel < ah->config.max_txtrig_level)
Sujithf1dc5602008-10-29 10:16:30 +0530572 newLevel++;
573 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
574 newLevel--;
575 if (newLevel != curLevel)
576 REG_WRITE(ah, AR_TXCFG,
577 (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
578
579 ath9k_hw_set_interrupts(ah, omask);
580
Sujith2660b812009-02-09 13:27:26 +0530581 ah->tx_trig_level = newLevel;
Sujithf1dc5602008-10-29 10:16:30 +0530582
583 return newLevel != curLevel;
584}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400585EXPORT_SYMBOL(ath9k_hw_updatetxtriglevel);
Sujithf1dc5602008-10-29 10:16:30 +0530586
Sujithcbe61d82009-02-09 13:27:12 +0530587bool ath9k_hw_stoptxdma(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530588{
Sujith94ff91d2009-01-27 15:06:38 +0530589#define ATH9K_TX_STOP_DMA_TIMEOUT 4000 /* usec */
590#define ATH9K_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700591 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530592 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujith94ff91d2009-01-27 15:06:38 +0530593 struct ath9k_tx_queue_info *qi;
Sujithf1dc5602008-10-29 10:16:30 +0530594 u32 tsfLow, j, wait;
Sujith94ff91d2009-01-27 15:06:38 +0530595 u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
596
597 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700598 ath_print(common, ATH_DBG_QUEUE, "Stopping TX DMA, "
599 "invalid queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530600 return false;
601 }
602
Sujith2660b812009-02-09 13:27:26 +0530603 qi = &ah->txq[q];
Sujith94ff91d2009-01-27 15:06:38 +0530604 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700605 ath_print(common, ATH_DBG_QUEUE, "Stopping TX DMA, "
606 "inactive queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530607 return false;
608 }
Sujithf1dc5602008-10-29 10:16:30 +0530609
610 REG_WRITE(ah, AR_Q_TXD, 1 << q);
611
Sujith94ff91d2009-01-27 15:06:38 +0530612 for (wait = wait_time; wait != 0; wait--) {
Sujithf1dc5602008-10-29 10:16:30 +0530613 if (ath9k_hw_numtxpending(ah, q) == 0)
614 break;
Sujith94ff91d2009-01-27 15:06:38 +0530615 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530616 }
617
618 if (ath9k_hw_numtxpending(ah, q)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700619 ath_print(common, ATH_DBG_QUEUE,
620 "%s: Num of pending TX Frames %d on Q %d\n",
621 __func__, ath9k_hw_numtxpending(ah, q), q);
Sujithf1dc5602008-10-29 10:16:30 +0530622
623 for (j = 0; j < 2; j++) {
624 tsfLow = REG_READ(ah, AR_TSF_L32);
625 REG_WRITE(ah, AR_QUIET2,
626 SM(10, AR_QUIET2_QUIET_DUR));
627 REG_WRITE(ah, AR_QUIET_PERIOD, 100);
628 REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
629 REG_SET_BIT(ah, AR_TIMER_MODE,
630 AR_QUIET_TIMER_EN);
631
632 if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10))
633 break;
634
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700635 ath_print(common, ATH_DBG_QUEUE,
636 "TSF has moved while trying to set "
637 "quiet time TSF: 0x%08x\n", tsfLow);
Sujithf1dc5602008-10-29 10:16:30 +0530638 }
639
640 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
641
642 udelay(200);
643 REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);
644
Sujith94ff91d2009-01-27 15:06:38 +0530645 wait = wait_time;
Sujithf1dc5602008-10-29 10:16:30 +0530646 while (ath9k_hw_numtxpending(ah, q)) {
647 if ((--wait) == 0) {
Sujithe8009e92009-12-14 14:57:08 +0530648 ath_print(common, ATH_DBG_FATAL,
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700649 "Failed to stop TX DMA in 100 "
650 "msec after killing last frame\n");
Sujithf1dc5602008-10-29 10:16:30 +0530651 break;
652 }
Sujith94ff91d2009-01-27 15:06:38 +0530653 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530654 }
655
656 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
657 }
658
659 REG_WRITE(ah, AR_Q_TXD, 0);
Sujithf1dc5602008-10-29 10:16:30 +0530660 return wait != 0;
Sujith94ff91d2009-01-27 15:06:38 +0530661
662#undef ATH9K_TX_STOP_DMA_TIMEOUT
663#undef ATH9K_TIME_QUANTUM
Sujithf1dc5602008-10-29 10:16:30 +0530664}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400665EXPORT_SYMBOL(ath9k_hw_stoptxdma);
Sujithf1dc5602008-10-29 10:16:30 +0530666
Sujithcbe61d82009-02-09 13:27:12 +0530667void ath9k_hw_gettxintrtxqs(struct ath_hw *ah, u32 *txqs)
Sujithf1dc5602008-10-29 10:16:30 +0530668{
Sujith2660b812009-02-09 13:27:26 +0530669 *txqs &= ah->intr_txqs;
670 ah->intr_txqs &= ~(*txqs);
Sujithf1dc5602008-10-29 10:16:30 +0530671}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400672EXPORT_SYMBOL(ath9k_hw_gettxintrtxqs);
Sujithf1dc5602008-10-29 10:16:30 +0530673
Sujithcbe61d82009-02-09 13:27:12 +0530674bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530675 const struct ath9k_tx_queue_info *qinfo)
676{
677 u32 cw;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700678 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530679 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530680 struct ath9k_tx_queue_info *qi;
681
682 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700683 ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
684 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530685 return false;
686 }
687
Sujith2660b812009-02-09 13:27:26 +0530688 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530689 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700690 ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
691 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530692 return false;
693 }
694
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700695 ath_print(common, ATH_DBG_QUEUE, "Set queue properties for: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530696
697 qi->tqi_ver = qinfo->tqi_ver;
698 qi->tqi_subtype = qinfo->tqi_subtype;
699 qi->tqi_qflags = qinfo->tqi_qflags;
700 qi->tqi_priority = qinfo->tqi_priority;
701 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
702 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
703 else
704 qi->tqi_aifs = INIT_AIFS;
705 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
706 cw = min(qinfo->tqi_cwmin, 1024U);
707 qi->tqi_cwmin = 1;
708 while (qi->tqi_cwmin < cw)
709 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
710 } else
711 qi->tqi_cwmin = qinfo->tqi_cwmin;
712 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
713 cw = min(qinfo->tqi_cwmax, 1024U);
714 qi->tqi_cwmax = 1;
715 while (qi->tqi_cwmax < cw)
716 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
717 } else
718 qi->tqi_cwmax = INIT_CWMAX;
719
720 if (qinfo->tqi_shretry != 0)
721 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
722 else
723 qi->tqi_shretry = INIT_SH_RETRY;
724 if (qinfo->tqi_lgretry != 0)
725 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
726 else
727 qi->tqi_lgretry = INIT_LG_RETRY;
728 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
729 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
730 qi->tqi_burstTime = qinfo->tqi_burstTime;
731 qi->tqi_readyTime = qinfo->tqi_readyTime;
732
733 switch (qinfo->tqi_subtype) {
734 case ATH9K_WME_UPSD:
735 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
736 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
737 break;
738 default:
739 break;
740 }
741
742 return true;
743}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400744EXPORT_SYMBOL(ath9k_hw_set_txq_props);
Sujithf1dc5602008-10-29 10:16:30 +0530745
Sujithcbe61d82009-02-09 13:27:12 +0530746bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530747 struct ath9k_tx_queue_info *qinfo)
748{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700749 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530750 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530751 struct ath9k_tx_queue_info *qi;
752
753 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700754 ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
755 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530756 return false;
757 }
758
Sujith2660b812009-02-09 13:27:26 +0530759 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530760 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700761 ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
762 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530763 return false;
764 }
765
766 qinfo->tqi_qflags = qi->tqi_qflags;
767 qinfo->tqi_ver = qi->tqi_ver;
768 qinfo->tqi_subtype = qi->tqi_subtype;
769 qinfo->tqi_qflags = qi->tqi_qflags;
770 qinfo->tqi_priority = qi->tqi_priority;
771 qinfo->tqi_aifs = qi->tqi_aifs;
772 qinfo->tqi_cwmin = qi->tqi_cwmin;
773 qinfo->tqi_cwmax = qi->tqi_cwmax;
774 qinfo->tqi_shretry = qi->tqi_shretry;
775 qinfo->tqi_lgretry = qi->tqi_lgretry;
776 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
777 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
778 qinfo->tqi_burstTime = qi->tqi_burstTime;
779 qinfo->tqi_readyTime = qi->tqi_readyTime;
780
781 return true;
782}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400783EXPORT_SYMBOL(ath9k_hw_get_txq_props);
Sujithf1dc5602008-10-29 10:16:30 +0530784
Sujithcbe61d82009-02-09 13:27:12 +0530785int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
Sujithf1dc5602008-10-29 10:16:30 +0530786 const struct ath9k_tx_queue_info *qinfo)
787{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700788 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530789 struct ath9k_tx_queue_info *qi;
Sujith2660b812009-02-09 13:27:26 +0530790 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530791 int q;
792
793 switch (type) {
794 case ATH9K_TX_QUEUE_BEACON:
795 q = pCap->total_queues - 1;
796 break;
797 case ATH9K_TX_QUEUE_CAB:
798 q = pCap->total_queues - 2;
799 break;
800 case ATH9K_TX_QUEUE_PSPOLL:
801 q = 1;
802 break;
803 case ATH9K_TX_QUEUE_UAPSD:
804 q = pCap->total_queues - 3;
805 break;
806 case ATH9K_TX_QUEUE_DATA:
807 for (q = 0; q < pCap->total_queues; q++)
Sujith2660b812009-02-09 13:27:26 +0530808 if (ah->txq[q].tqi_type ==
Sujithf1dc5602008-10-29 10:16:30 +0530809 ATH9K_TX_QUEUE_INACTIVE)
810 break;
811 if (q == pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700812 ath_print(common, ATH_DBG_FATAL,
813 "No available TX queue\n");
Sujithf1dc5602008-10-29 10:16:30 +0530814 return -1;
815 }
816 break;
817 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700818 ath_print(common, ATH_DBG_FATAL,
819 "Invalid TX queue type: %u\n", type);
Sujithf1dc5602008-10-29 10:16:30 +0530820 return -1;
821 }
822
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700823 ath_print(common, ATH_DBG_QUEUE, "Setup TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530824
Sujith2660b812009-02-09 13:27:26 +0530825 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530826 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700827 ath_print(common, ATH_DBG_FATAL,
828 "TX queue: %u already active\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530829 return -1;
830 }
831 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
832 qi->tqi_type = type;
833 if (qinfo == NULL) {
834 qi->tqi_qflags =
835 TXQ_FLAG_TXOKINT_ENABLE
836 | TXQ_FLAG_TXERRINT_ENABLE
837 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
838 qi->tqi_aifs = INIT_AIFS;
839 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
840 qi->tqi_cwmax = INIT_CWMAX;
841 qi->tqi_shretry = INIT_SH_RETRY;
842 qi->tqi_lgretry = INIT_LG_RETRY;
843 qi->tqi_physCompBuf = 0;
844 } else {
845 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
846 (void) ath9k_hw_set_txq_props(ah, q, qinfo);
847 }
848
849 return q;
850}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400851EXPORT_SYMBOL(ath9k_hw_setuptxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530852
Sujithcbe61d82009-02-09 13:27:12 +0530853bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530854{
Sujith2660b812009-02-09 13:27:26 +0530855 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700856 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530857 struct ath9k_tx_queue_info *qi;
858
859 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700860 ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
861 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530862 return false;
863 }
Sujith2660b812009-02-09 13:27:26 +0530864 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530865 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700866 ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
867 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530868 return false;
869 }
870
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700871 ath_print(common, ATH_DBG_QUEUE, "Release TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530872
873 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
Sujith2660b812009-02-09 13:27:26 +0530874 ah->txok_interrupt_mask &= ~(1 << q);
875 ah->txerr_interrupt_mask &= ~(1 << q);
876 ah->txdesc_interrupt_mask &= ~(1 << q);
877 ah->txeol_interrupt_mask &= ~(1 << q);
878 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530879 ath9k_hw_set_txq_interrupts(ah, qi);
880
881 return true;
882}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400883EXPORT_SYMBOL(ath9k_hw_releasetxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530884
Sujithcbe61d82009-02-09 13:27:12 +0530885bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530886{
Sujith2660b812009-02-09 13:27:26 +0530887 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700888 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530889 struct ath9k_channel *chan = ah->curchan;
Sujithf1dc5602008-10-29 10:16:30 +0530890 struct ath9k_tx_queue_info *qi;
891 u32 cwMin, chanCwMin, value;
892
893 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700894 ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
895 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530896 return false;
897 }
898
Sujith2660b812009-02-09 13:27:26 +0530899 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530900 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700901 ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
902 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530903 return true;
904 }
905
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700906 ath_print(common, ATH_DBG_QUEUE, "Reset TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530907
908 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
909 if (chan && IS_CHAN_B(chan))
910 chanCwMin = INIT_CWMIN_11B;
911 else
912 chanCwMin = INIT_CWMIN;
913
914 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
915 } else
916 cwMin = qi->tqi_cwmin;
917
918 REG_WRITE(ah, AR_DLCL_IFS(q),
919 SM(cwMin, AR_D_LCL_IFS_CWMIN) |
920 SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
921 SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
922
923 REG_WRITE(ah, AR_DRETRY_LIMIT(q),
924 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
925 SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
926 SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
927
928 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
929 REG_WRITE(ah, AR_DMISC(q),
930 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
931
932 if (qi->tqi_cbrPeriod) {
933 REG_WRITE(ah, AR_QCBRCFG(q),
934 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
935 SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
936 REG_WRITE(ah, AR_QMISC(q),
937 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
938 (qi->tqi_cbrOverflowLimit ?
939 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
940 }
941 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
942 REG_WRITE(ah, AR_QRDYTIMECFG(q),
943 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
944 AR_Q_RDYTIMECFG_EN);
945 }
946
947 REG_WRITE(ah, AR_DCHNTIME(q),
948 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
949 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
950
951 if (qi->tqi_burstTime
952 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
953 REG_WRITE(ah, AR_QMISC(q),
954 REG_READ(ah, AR_QMISC(q)) |
955 AR_Q_MISC_RDYTIME_EXP_POLICY);
956
957 }
958
959 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
960 REG_WRITE(ah, AR_DMISC(q),
961 REG_READ(ah, AR_DMISC(q)) |
962 AR_D_MISC_POST_FR_BKOFF_DIS);
963 }
964 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
965 REG_WRITE(ah, AR_DMISC(q),
966 REG_READ(ah, AR_DMISC(q)) |
967 AR_D_MISC_FRAG_BKOFF_EN);
968 }
969 switch (qi->tqi_type) {
970 case ATH9K_TX_QUEUE_BEACON:
971 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
972 | AR_Q_MISC_FSP_DBA_GATED
973 | AR_Q_MISC_BEACON_USE
974 | AR_Q_MISC_CBR_INCR_DIS1);
975
976 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
977 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
978 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
979 | AR_D_MISC_BEACON_USE
980 | AR_D_MISC_POST_FR_BKOFF_DIS);
981 break;
982 case ATH9K_TX_QUEUE_CAB:
983 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
984 | AR_Q_MISC_FSP_DBA_GATED
985 | AR_Q_MISC_CBR_INCR_DIS1
986 | AR_Q_MISC_CBR_INCR_DIS0);
987 value = (qi->tqi_readyTime -
Sujith2660b812009-02-09 13:27:26 +0530988 (ah->config.sw_beacon_response_time -
989 ah->config.dma_beacon_response_time) -
990 ah->config.additional_swba_backoff) * 1024;
Sujithf1dc5602008-10-29 10:16:30 +0530991 REG_WRITE(ah, AR_QRDYTIMECFG(q),
992 value | AR_Q_RDYTIMECFG_EN);
993 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
994 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
995 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
996 break;
997 case ATH9K_TX_QUEUE_PSPOLL:
998 REG_WRITE(ah, AR_QMISC(q),
999 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
1000 break;
1001 case ATH9K_TX_QUEUE_UAPSD:
1002 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
1003 AR_D_MISC_POST_FR_BKOFF_DIS);
1004 break;
1005 default:
1006 break;
1007 }
1008
1009 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
1010 REG_WRITE(ah, AR_DMISC(q),
1011 REG_READ(ah, AR_DMISC(q)) |
1012 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
1013 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
1014 AR_D_MISC_POST_FR_BKOFF_DIS);
1015 }
1016
1017 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +05301018 ah->txok_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +05301019 else
Sujith2660b812009-02-09 13:27:26 +05301020 ah->txok_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +05301021 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +05301022 ah->txerr_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +05301023 else
Sujith2660b812009-02-09 13:27:26 +05301024 ah->txerr_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +05301025 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +05301026 ah->txdesc_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +05301027 else
Sujith2660b812009-02-09 13:27:26 +05301028 ah->txdesc_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +05301029 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +05301030 ah->txeol_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +05301031 else
Sujith2660b812009-02-09 13:27:26 +05301032 ah->txeol_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +05301033 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +05301034 ah->txurn_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +05301035 else
Sujith2660b812009-02-09 13:27:26 +05301036 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +05301037 ath9k_hw_set_txq_interrupts(ah, qi);
1038
1039 return true;
1040}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001041EXPORT_SYMBOL(ath9k_hw_resettxqueue);
Sujithf1dc5602008-10-29 10:16:30 +05301042
Sujithcbe61d82009-02-09 13:27:12 +05301043int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001044 struct ath_rx_status *rs, u64 tsf)
Sujithf1dc5602008-10-29 10:16:30 +05301045{
1046 struct ar5416_desc ads;
1047 struct ar5416_desc *adsp = AR5416DESC(ds);
1048 u32 phyerr;
1049
1050 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
1051 return -EINPROGRESS;
1052
1053 ads.u.rx = adsp->u.rx;
1054
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001055 rs->rs_status = 0;
1056 rs->rs_flags = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301057
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001058 rs->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
1059 rs->rs_tstamp = ads.AR_RcvTimestamp;
Sujithf1dc5602008-10-29 10:16:30 +05301060
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001061 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001062 rs->rs_rssi = ATH9K_RSSI_BAD;
1063 rs->rs_rssi_ctl0 = ATH9K_RSSI_BAD;
1064 rs->rs_rssi_ctl1 = ATH9K_RSSI_BAD;
1065 rs->rs_rssi_ctl2 = ATH9K_RSSI_BAD;
1066 rs->rs_rssi_ext0 = ATH9K_RSSI_BAD;
1067 rs->rs_rssi_ext1 = ATH9K_RSSI_BAD;
1068 rs->rs_rssi_ext2 = ATH9K_RSSI_BAD;
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001069 } else {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001070 rs->rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
1071 rs->rs_rssi_ctl0 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001072 AR_RxRSSIAnt00);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001073 rs->rs_rssi_ctl1 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001074 AR_RxRSSIAnt01);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001075 rs->rs_rssi_ctl2 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001076 AR_RxRSSIAnt02);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001077 rs->rs_rssi_ext0 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001078 AR_RxRSSIAnt10);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001079 rs->rs_rssi_ext1 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001080 AR_RxRSSIAnt11);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001081 rs->rs_rssi_ext2 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001082 AR_RxRSSIAnt12);
1083 }
Sujithf1dc5602008-10-29 10:16:30 +05301084 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001085 rs->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
Sujithf1dc5602008-10-29 10:16:30 +05301086 else
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001087 rs->rs_keyix = ATH9K_RXKEYIX_INVALID;
Sujithf1dc5602008-10-29 10:16:30 +05301088
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001089 rs->rs_rate = RXSTATUS_RATE(ah, (&ads));
1090 rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
Sujithf1dc5602008-10-29 10:16:30 +05301091
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001092 rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
1093 rs->rs_moreaggr =
Sujithf1dc5602008-10-29 10:16:30 +05301094 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001095 rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
1096 rs->rs_flags =
Sujithf1dc5602008-10-29 10:16:30 +05301097 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001098 rs->rs_flags |=
Sujithf1dc5602008-10-29 10:16:30 +05301099 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
1100
1101 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001102 rs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
Sujithf1dc5602008-10-29 10:16:30 +05301103 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001104 rs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
Sujithf1dc5602008-10-29 10:16:30 +05301105 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001106 rs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
Sujithf1dc5602008-10-29 10:16:30 +05301107
1108 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
1109 if (ads.ds_rxstatus8 & AR_CRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001110 rs->rs_status |= ATH9K_RXERR_CRC;
Sujithf1dc5602008-10-29 10:16:30 +05301111 else if (ads.ds_rxstatus8 & AR_PHYErr) {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001112 rs->rs_status |= ATH9K_RXERR_PHY;
Sujithf1dc5602008-10-29 10:16:30 +05301113 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001114 rs->rs_phyerr = phyerr;
Sujithf1dc5602008-10-29 10:16:30 +05301115 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001116 rs->rs_status |= ATH9K_RXERR_DECRYPT;
Sujithf1dc5602008-10-29 10:16:30 +05301117 else if (ads.ds_rxstatus8 & AR_MichaelErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001118 rs->rs_status |= ATH9K_RXERR_MIC;
Sujithf1dc5602008-10-29 10:16:30 +05301119 }
1120
1121 return 0;
1122}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001123EXPORT_SYMBOL(ath9k_hw_rxprocdesc);
Sujithf1dc5602008-10-29 10:16:30 +05301124
Sujith54e4cec2009-08-07 09:45:09 +05301125void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +05301126 u32 size, u32 flags)
1127{
1128 struct ar5416_desc *ads = AR5416DESC(ds);
Sujith2660b812009-02-09 13:27:26 +05301129 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +05301130
1131 ads->ds_ctl1 = size & AR_BufLen;
1132 if (flags & ATH9K_RXDESC_INTREQ)
1133 ads->ds_ctl1 |= AR_RxIntrReq;
1134
1135 ads->ds_rxstatus8 &= ~AR_RxDone;
1136 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
1137 memset(&(ads->u), 0, sizeof(ads->u));
Sujithf1dc5602008-10-29 10:16:30 +05301138}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001139EXPORT_SYMBOL(ath9k_hw_setuprxdesc);
Sujithf1dc5602008-10-29 10:16:30 +05301140
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001141/*
1142 * This can stop or re-enables RX.
1143 *
1144 * If bool is set this will kill any frame which is currently being
1145 * transferred between the MAC and baseband and also prevent any new
1146 * frames from getting started.
1147 */
Sujithcbe61d82009-02-09 13:27:12 +05301148bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
Sujithf1dc5602008-10-29 10:16:30 +05301149{
1150 u32 reg;
1151
1152 if (set) {
1153 REG_SET_BIT(ah, AR_DIAG_SW,
1154 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1155
Sujith0caa7b12009-02-16 13:23:20 +05301156 if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
1157 0, AH_WAIT_TIMEOUT)) {
Sujithf1dc5602008-10-29 10:16:30 +05301158 REG_CLR_BIT(ah, AR_DIAG_SW,
1159 (AR_DIAG_RX_DIS |
1160 AR_DIAG_RX_ABORT));
1161
1162 reg = REG_READ(ah, AR_OBS_BUS_1);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001163 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1164 "RX failed to go idle in 10 ms RXSM=0x%x\n",
1165 reg);
Sujithf1dc5602008-10-29 10:16:30 +05301166
1167 return false;
1168 }
1169 } else {
1170 REG_CLR_BIT(ah, AR_DIAG_SW,
1171 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1172 }
1173
1174 return true;
1175}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001176EXPORT_SYMBOL(ath9k_hw_setrxabort);
Sujithf1dc5602008-10-29 10:16:30 +05301177
Sujithcbe61d82009-02-09 13:27:12 +05301178void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
Sujithf1dc5602008-10-29 10:16:30 +05301179{
1180 REG_WRITE(ah, AR_RXDP, rxdp);
1181}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001182EXPORT_SYMBOL(ath9k_hw_putrxbuf);
Sujithf1dc5602008-10-29 10:16:30 +05301183
Sujithcbe61d82009-02-09 13:27:12 +05301184void ath9k_hw_startpcureceive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301185{
Sujithf1dc5602008-10-29 10:16:30 +05301186 ath9k_enable_mib_counters(ah);
1187
1188 ath9k_ani_reset(ah);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301189
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301190 REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
Sujithf1dc5602008-10-29 10:16:30 +05301191}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001192EXPORT_SYMBOL(ath9k_hw_startpcureceive);
Sujithf1dc5602008-10-29 10:16:30 +05301193
Sujithcbe61d82009-02-09 13:27:12 +05301194void ath9k_hw_stoppcurecv(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301195{
1196 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
1197
1198 ath9k_hw_disable_mib_counters(ah);
1199}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001200EXPORT_SYMBOL(ath9k_hw_stoppcurecv);
Sujithf1dc5602008-10-29 10:16:30 +05301201
Sujithcbe61d82009-02-09 13:27:12 +05301202bool ath9k_hw_stopdmarecv(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301203{
Sujith0caa7b12009-02-16 13:23:20 +05301204#define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
1205#define AH_RX_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001206 struct ath_common *common = ath9k_hw_common(ah);
Sujith0caa7b12009-02-16 13:23:20 +05301207 int i;
1208
Sujithf1dc5602008-10-29 10:16:30 +05301209 REG_WRITE(ah, AR_CR, AR_CR_RXD);
1210
Sujith0caa7b12009-02-16 13:23:20 +05301211 /* Wait for rx enable bit to go low */
1212 for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
1213 if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
1214 break;
1215 udelay(AH_TIME_QUANTUM);
1216 }
1217
1218 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001219 ath_print(common, ATH_DBG_FATAL,
1220 "DMA failed to stop in %d ms "
1221 "AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
1222 AH_RX_STOP_DMA_TIMEOUT / 1000,
1223 REG_READ(ah, AR_CR),
1224 REG_READ(ah, AR_DIAG_SW));
Sujithf1dc5602008-10-29 10:16:30 +05301225 return false;
1226 } else {
1227 return true;
1228 }
Sujith0caa7b12009-02-16 13:23:20 +05301229
1230#undef AH_RX_TIME_QUANTUM
1231#undef AH_RX_STOP_DMA_TIMEOUT
Sujithf1dc5602008-10-29 10:16:30 +05301232}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001233EXPORT_SYMBOL(ath9k_hw_stopdmarecv);
Luis R. Rodriguez536b3a72009-10-06 21:19:11 -04001234
1235int ath9k_hw_beaconq_setup(struct ath_hw *ah)
1236{
1237 struct ath9k_tx_queue_info qi;
1238
1239 memset(&qi, 0, sizeof(qi));
1240 qi.tqi_aifs = 1;
1241 qi.tqi_cwmin = 0;
1242 qi.tqi_cwmax = 0;
1243 /* NB: don't enable any interrupts */
1244 return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
1245}
1246EXPORT_SYMBOL(ath9k_hw_beaconq_setup);
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -04001247
1248bool ath9k_hw_intrpend(struct ath_hw *ah)
1249{
1250 u32 host_isr;
1251
1252 if (AR_SREV_9100(ah))
1253 return true;
1254
1255 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
1256 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
1257 return true;
1258
1259 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1260 if ((host_isr & AR_INTR_SYNC_DEFAULT)
1261 && (host_isr != AR_INTR_SPURIOUS))
1262 return true;
1263
1264 return false;
1265}
1266EXPORT_SYMBOL(ath9k_hw_intrpend);
1267
1268enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah,
1269 enum ath9k_int ints)
1270{
1271 enum ath9k_int omask = ah->imask;
1272 u32 mask, mask2;
1273 struct ath9k_hw_capabilities *pCap = &ah->caps;
1274 struct ath_common *common = ath9k_hw_common(ah);
1275
1276 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
1277
1278 if (omask & ATH9K_INT_GLOBAL) {
1279 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
1280 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
1281 (void) REG_READ(ah, AR_IER);
1282 if (!AR_SREV_9100(ah)) {
1283 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
1284 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
1285
1286 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1287 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
1288 }
1289 }
1290
1291 /* TODO: global int Ref count */
1292 mask = ints & ATH9K_INT_COMMON;
1293 mask2 = 0;
1294
1295 if (ints & ATH9K_INT_TX) {
1296 if (ah->config.tx_intr_mitigation)
1297 mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM;
1298 if (ah->txok_interrupt_mask)
1299 mask |= AR_IMR_TXOK;
1300 if (ah->txdesc_interrupt_mask)
1301 mask |= AR_IMR_TXDESC;
1302 if (ah->txerr_interrupt_mask)
1303 mask |= AR_IMR_TXERR;
1304 if (ah->txeol_interrupt_mask)
1305 mask |= AR_IMR_TXEOL;
1306 }
1307 if (ints & ATH9K_INT_RX) {
1308 if (AR_SREV_9300_20_OR_LATER(ah)) {
1309 mask |= AR_IMR_RXERR | AR_IMR_RXOK_HP;
1310 if (ah->config.rx_intr_mitigation) {
1311 mask &= ~AR_IMR_RXOK_LP;
1312 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
1313 } else {
1314 mask |= AR_IMR_RXOK_LP;
1315 }
1316 } else {
1317 if (ah->config.rx_intr_mitigation)
1318 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
1319 else
1320 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
1321 }
1322 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
1323 mask |= AR_IMR_GENTMR;
1324 }
1325
1326 if (ints & (ATH9K_INT_BMISC)) {
1327 mask |= AR_IMR_BCNMISC;
1328 if (ints & ATH9K_INT_TIM)
1329 mask2 |= AR_IMR_S2_TIM;
1330 if (ints & ATH9K_INT_DTIM)
1331 mask2 |= AR_IMR_S2_DTIM;
1332 if (ints & ATH9K_INT_DTIMSYNC)
1333 mask2 |= AR_IMR_S2_DTIMSYNC;
1334 if (ints & ATH9K_INT_CABEND)
1335 mask2 |= AR_IMR_S2_CABEND;
1336 if (ints & ATH9K_INT_TSFOOR)
1337 mask2 |= AR_IMR_S2_TSFOOR;
1338 }
1339
1340 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
1341 mask |= AR_IMR_BCNMISC;
1342 if (ints & ATH9K_INT_GTT)
1343 mask2 |= AR_IMR_S2_GTT;
1344 if (ints & ATH9K_INT_CST)
1345 mask2 |= AR_IMR_S2_CST;
1346 }
1347
1348 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
1349 REG_WRITE(ah, AR_IMR, mask);
1350 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
1351 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
1352 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
1353 ah->imrs2_reg |= mask2;
1354 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
1355
1356 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1357 if (ints & ATH9K_INT_TIM_TIMER)
1358 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
1359 else
1360 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
1361 }
1362
1363 if (ints & ATH9K_INT_GLOBAL) {
1364 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
1365 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
1366 if (!AR_SREV_9100(ah)) {
1367 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
1368 AR_INTR_MAC_IRQ);
1369 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
1370
1371
1372 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
1373 AR_INTR_SYNC_DEFAULT);
1374 REG_WRITE(ah, AR_INTR_SYNC_MASK,
1375 AR_INTR_SYNC_DEFAULT);
1376 }
1377 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
1378 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
1379 }
1380
1381 return omask;
1382}
1383EXPORT_SYMBOL(ath9k_hw_set_interrupts);