blob: 58aaf9ab0920f230064f22be2e85df8df10e07b0 [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"
Luis R. Rodriguezac0bb762010-06-12 00:33:42 -040018#include "hw-ops.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{
Joe Perches226afe62010-12-02 19:12:37 -080023 ath_dbg(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
Sujith7d0d0df2010-04-16 11:53:57 +053029 ENABLE_REGWRITE_BUFFER(ah);
30
Sujithf1dc5602008-10-29 10:16:30 +053031 REG_WRITE(ah, AR_IMR_S0,
Sujith2660b812009-02-09 13:27:26 +053032 SM(ah->txok_interrupt_mask, AR_IMR_S0_QCU_TXOK)
33 | SM(ah->txdesc_interrupt_mask, AR_IMR_S0_QCU_TXDESC));
Sujithf1dc5602008-10-29 10:16:30 +053034 REG_WRITE(ah, AR_IMR_S1,
Sujith2660b812009-02-09 13:27:26 +053035 SM(ah->txerr_interrupt_mask, AR_IMR_S1_QCU_TXERR)
36 | SM(ah->txeol_interrupt_mask, AR_IMR_S1_QCU_TXEOL));
Pavel Roskin74bad5c2010-02-23 18:15:27 -050037
38 ah->imrs2_reg &= ~AR_IMR_S2_QCU_TXURN;
39 ah->imrs2_reg |= (ah->txurn_interrupt_mask & AR_IMR_S2_QCU_TXURN);
40 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujith7d0d0df2010-04-16 11:53:57 +053041
42 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +053043}
44
Sujithcbe61d82009-02-09 13:27:12 +053045u32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053046{
47 return REG_READ(ah, AR_QTXDP(q));
48}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040049EXPORT_SYMBOL(ath9k_hw_gettxbuf);
Sujithf1dc5602008-10-29 10:16:30 +053050
Sujith54e4cec2009-08-07 09:45:09 +053051void ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp)
Sujithf1dc5602008-10-29 10:16:30 +053052{
53 REG_WRITE(ah, AR_QTXDP(q), txdp);
Sujithf1dc5602008-10-29 10:16:30 +053054}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040055EXPORT_SYMBOL(ath9k_hw_puttxbuf);
Sujithf1dc5602008-10-29 10:16:30 +053056
Sujith54e4cec2009-08-07 09:45:09 +053057void ath9k_hw_txstart(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053058{
Joe Perches226afe62010-12-02 19:12:37 -080059 ath_dbg(ath9k_hw_common(ah), ATH_DBG_QUEUE,
60 "Enable TXE on queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +053061 REG_WRITE(ah, AR_Q_TXE, 1 << q);
Sujithf1dc5602008-10-29 10:16:30 +053062}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040063EXPORT_SYMBOL(ath9k_hw_txstart);
Sujithf1dc5602008-10-29 10:16:30 +053064
Vasanthakumar Thiagarajancc610ac02010-04-15 17:39:26 -040065void ath9k_hw_cleartxdesc(struct ath_hw *ah, void *ds)
66{
67 struct ar5416_desc *ads = AR5416DESC(ds);
68
69 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
70 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
71 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
72 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
73 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
74}
75EXPORT_SYMBOL(ath9k_hw_cleartxdesc);
76
Sujithcbe61d82009-02-09 13:27:12 +053077u32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053078{
79 u32 npend;
80
81 npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
82 if (npend == 0) {
83
84 if (REG_READ(ah, AR_Q_TXE) & (1 << q))
85 npend = 1;
86 }
87
88 return npend;
89}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040090EXPORT_SYMBOL(ath9k_hw_numtxpending);
Sujithf1dc5602008-10-29 10:16:30 +053091
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -050092/**
93 * ath9k_hw_updatetxtriglevel - adjusts the frame trigger level
94 *
95 * @ah: atheros hardware struct
96 * @bIncTrigLevel: whether or not the frame trigger level should be updated
97 *
98 * The frame trigger level specifies the minimum number of bytes,
99 * in units of 64 bytes, that must be DMA'ed into the PCU TX FIFO
100 * before the PCU will initiate sending the frame on the air. This can
101 * mean we initiate transmit before a full frame is on the PCU TX FIFO.
102 * Resets to 0x1 (meaning 64 bytes or a full frame, whichever occurs
103 * first)
104 *
105 * Caution must be taken to ensure to set the frame trigger level based
106 * on the DMA request size. For example if the DMA request size is set to
107 * 128 bytes the trigger level cannot exceed 6 * 64 = 384. This is because
108 * there need to be enough space in the tx FIFO for the requested transfer
109 * size. Hence the tx FIFO will stop with 512 - 128 = 384 bytes. If we set
110 * the threshold to a value beyond 6, then the transmit will hang.
111 *
112 * Current dual stream devices have a PCU TX FIFO size of 8 KB.
113 * Current single stream devices have a PCU TX FIFO size of 4 KB, however,
114 * there is a hardware issue which forces us to use 2 KB instead so the
115 * frame trigger level must not exceed 2 KB for these chipsets.
116 */
Sujithcbe61d82009-02-09 13:27:12 +0530117bool ath9k_hw_updatetxtriglevel(struct ath_hw *ah, bool bIncTrigLevel)
Sujithf1dc5602008-10-29 10:16:30 +0530118{
Sujithf1dc5602008-10-29 10:16:30 +0530119 u32 txcfg, curLevel, newLevel;
Sujithf1dc5602008-10-29 10:16:30 +0530120
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500121 if (ah->tx_trig_level >= ah->config.max_txtrig_level)
Sujithf1dc5602008-10-29 10:16:30 +0530122 return false;
123
Felix Fietkau4df30712010-11-08 20:54:47 +0100124 ath9k_hw_disable_interrupts(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530125
126 txcfg = REG_READ(ah, AR_TXCFG);
127 curLevel = MS(txcfg, AR_FTRIG);
128 newLevel = curLevel;
129 if (bIncTrigLevel) {
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500130 if (curLevel < ah->config.max_txtrig_level)
Sujithf1dc5602008-10-29 10:16:30 +0530131 newLevel++;
132 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
133 newLevel--;
134 if (newLevel != curLevel)
135 REG_WRITE(ah, AR_TXCFG,
136 (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
137
Felix Fietkau4df30712010-11-08 20:54:47 +0100138 ath9k_hw_enable_interrupts(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530139
Sujith2660b812009-02-09 13:27:26 +0530140 ah->tx_trig_level = newLevel;
Sujithf1dc5602008-10-29 10:16:30 +0530141
142 return newLevel != curLevel;
143}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400144EXPORT_SYMBOL(ath9k_hw_updatetxtriglevel);
Sujithf1dc5602008-10-29 10:16:30 +0530145
Felix Fietkau0d51ccc2011-03-11 21:38:18 +0100146void ath9k_hw_abort_tx_dma(struct ath_hw *ah)
147{
148 int i, q;
149
150 REG_WRITE(ah, AR_Q_TXD, AR_Q_TXD_M);
151
152 REG_SET_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF);
153 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
154 REG_SET_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
155
156 for (q = 0; q < AR_NUM_QCU; q++) {
157 for (i = 0; i < 1000; i++) {
158 if (i)
159 udelay(5);
160
161 if (!ath9k_hw_numtxpending(ah, q))
162 break;
163 }
164 }
165
166 REG_CLR_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF);
167 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
168 REG_CLR_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
169
170 REG_WRITE(ah, AR_Q_TXD, 0);
171}
172EXPORT_SYMBOL(ath9k_hw_abort_tx_dma);
173
Sujithcbe61d82009-02-09 13:27:12 +0530174bool ath9k_hw_stoptxdma(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530175{
Sujith94ff91d2009-01-27 15:06:38 +0530176#define ATH9K_TX_STOP_DMA_TIMEOUT 4000 /* usec */
177#define ATH9K_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700178 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530179 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujith94ff91d2009-01-27 15:06:38 +0530180 struct ath9k_tx_queue_info *qi;
Sujithf1dc5602008-10-29 10:16:30 +0530181 u32 tsfLow, j, wait;
Sujith94ff91d2009-01-27 15:06:38 +0530182 u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
183
184 if (q >= pCap->total_queues) {
Joe Perches226afe62010-12-02 19:12:37 -0800185 ath_dbg(common, ATH_DBG_QUEUE,
186 "Stopping TX DMA, invalid queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530187 return false;
188 }
189
Sujith2660b812009-02-09 13:27:26 +0530190 qi = &ah->txq[q];
Sujith94ff91d2009-01-27 15:06:38 +0530191 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Joe Perches226afe62010-12-02 19:12:37 -0800192 ath_dbg(common, ATH_DBG_QUEUE,
193 "Stopping TX DMA, inactive queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530194 return false;
195 }
Sujithf1dc5602008-10-29 10:16:30 +0530196
197 REG_WRITE(ah, AR_Q_TXD, 1 << q);
198
Sujith94ff91d2009-01-27 15:06:38 +0530199 for (wait = wait_time; wait != 0; wait--) {
Sujithf1dc5602008-10-29 10:16:30 +0530200 if (ath9k_hw_numtxpending(ah, q) == 0)
201 break;
Sujith94ff91d2009-01-27 15:06:38 +0530202 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530203 }
204
205 if (ath9k_hw_numtxpending(ah, q)) {
Joe Perches226afe62010-12-02 19:12:37 -0800206 ath_dbg(common, ATH_DBG_QUEUE,
207 "%s: Num of pending TX Frames %d on Q %d\n",
208 __func__, ath9k_hw_numtxpending(ah, q), q);
Sujithf1dc5602008-10-29 10:16:30 +0530209
210 for (j = 0; j < 2; j++) {
211 tsfLow = REG_READ(ah, AR_TSF_L32);
212 REG_WRITE(ah, AR_QUIET2,
213 SM(10, AR_QUIET2_QUIET_DUR));
214 REG_WRITE(ah, AR_QUIET_PERIOD, 100);
215 REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
216 REG_SET_BIT(ah, AR_TIMER_MODE,
217 AR_QUIET_TIMER_EN);
218
219 if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10))
220 break;
221
Joe Perches226afe62010-12-02 19:12:37 -0800222 ath_dbg(common, ATH_DBG_QUEUE,
223 "TSF has moved while trying to set quiet time TSF: 0x%08x\n",
224 tsfLow);
Sujithf1dc5602008-10-29 10:16:30 +0530225 }
226
227 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
228
229 udelay(200);
230 REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);
231
Sujith94ff91d2009-01-27 15:06:38 +0530232 wait = wait_time;
Sujithf1dc5602008-10-29 10:16:30 +0530233 while (ath9k_hw_numtxpending(ah, q)) {
234 if ((--wait) == 0) {
Joe Perches38002762010-12-02 19:12:36 -0800235 ath_err(common,
236 "Failed to stop TX DMA in 100 msec after killing last frame\n");
Sujithf1dc5602008-10-29 10:16:30 +0530237 break;
238 }
Sujith94ff91d2009-01-27 15:06:38 +0530239 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530240 }
241
242 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
243 }
244
245 REG_WRITE(ah, AR_Q_TXD, 0);
Sujithf1dc5602008-10-29 10:16:30 +0530246 return wait != 0;
Sujith94ff91d2009-01-27 15:06:38 +0530247
248#undef ATH9K_TX_STOP_DMA_TIMEOUT
249#undef ATH9K_TIME_QUANTUM
Sujithf1dc5602008-10-29 10:16:30 +0530250}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400251EXPORT_SYMBOL(ath9k_hw_stoptxdma);
Sujithf1dc5602008-10-29 10:16:30 +0530252
Sujithcbe61d82009-02-09 13:27:12 +0530253void ath9k_hw_gettxintrtxqs(struct ath_hw *ah, u32 *txqs)
Sujithf1dc5602008-10-29 10:16:30 +0530254{
Sujith2660b812009-02-09 13:27:26 +0530255 *txqs &= ah->intr_txqs;
256 ah->intr_txqs &= ~(*txqs);
Sujithf1dc5602008-10-29 10:16:30 +0530257}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400258EXPORT_SYMBOL(ath9k_hw_gettxintrtxqs);
Sujithf1dc5602008-10-29 10:16:30 +0530259
Sujithcbe61d82009-02-09 13:27:12 +0530260bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530261 const struct ath9k_tx_queue_info *qinfo)
262{
263 u32 cw;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700264 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530265 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530266 struct ath9k_tx_queue_info *qi;
267
268 if (q >= pCap->total_queues) {
Joe Perches226afe62010-12-02 19:12:37 -0800269 ath_dbg(common, ATH_DBG_QUEUE,
270 "Set TXQ properties, invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530271 return false;
272 }
273
Sujith2660b812009-02-09 13:27:26 +0530274 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530275 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Joe Perches226afe62010-12-02 19:12:37 -0800276 ath_dbg(common, ATH_DBG_QUEUE,
277 "Set TXQ properties, inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530278 return false;
279 }
280
Joe Perches226afe62010-12-02 19:12:37 -0800281 ath_dbg(common, ATH_DBG_QUEUE, "Set queue properties for: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530282
283 qi->tqi_ver = qinfo->tqi_ver;
284 qi->tqi_subtype = qinfo->tqi_subtype;
285 qi->tqi_qflags = qinfo->tqi_qflags;
286 qi->tqi_priority = qinfo->tqi_priority;
287 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
288 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
289 else
290 qi->tqi_aifs = INIT_AIFS;
291 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
292 cw = min(qinfo->tqi_cwmin, 1024U);
293 qi->tqi_cwmin = 1;
294 while (qi->tqi_cwmin < cw)
295 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
296 } else
297 qi->tqi_cwmin = qinfo->tqi_cwmin;
298 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
299 cw = min(qinfo->tqi_cwmax, 1024U);
300 qi->tqi_cwmax = 1;
301 while (qi->tqi_cwmax < cw)
302 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
303 } else
304 qi->tqi_cwmax = INIT_CWMAX;
305
306 if (qinfo->tqi_shretry != 0)
307 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
308 else
309 qi->tqi_shretry = INIT_SH_RETRY;
310 if (qinfo->tqi_lgretry != 0)
311 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
312 else
313 qi->tqi_lgretry = INIT_LG_RETRY;
314 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
315 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
316 qi->tqi_burstTime = qinfo->tqi_burstTime;
317 qi->tqi_readyTime = qinfo->tqi_readyTime;
318
319 switch (qinfo->tqi_subtype) {
320 case ATH9K_WME_UPSD:
321 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
322 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
323 break;
324 default:
325 break;
326 }
327
328 return true;
329}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400330EXPORT_SYMBOL(ath9k_hw_set_txq_props);
Sujithf1dc5602008-10-29 10:16:30 +0530331
Sujithcbe61d82009-02-09 13:27:12 +0530332bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530333 struct ath9k_tx_queue_info *qinfo)
334{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700335 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530336 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530337 struct ath9k_tx_queue_info *qi;
338
339 if (q >= pCap->total_queues) {
Joe Perches226afe62010-12-02 19:12:37 -0800340 ath_dbg(common, ATH_DBG_QUEUE,
341 "Get TXQ properties, invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530342 return false;
343 }
344
Sujith2660b812009-02-09 13:27:26 +0530345 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530346 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Joe Perches226afe62010-12-02 19:12:37 -0800347 ath_dbg(common, ATH_DBG_QUEUE,
348 "Get TXQ properties, inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530349 return false;
350 }
351
352 qinfo->tqi_qflags = qi->tqi_qflags;
353 qinfo->tqi_ver = qi->tqi_ver;
354 qinfo->tqi_subtype = qi->tqi_subtype;
355 qinfo->tqi_qflags = qi->tqi_qflags;
356 qinfo->tqi_priority = qi->tqi_priority;
357 qinfo->tqi_aifs = qi->tqi_aifs;
358 qinfo->tqi_cwmin = qi->tqi_cwmin;
359 qinfo->tqi_cwmax = qi->tqi_cwmax;
360 qinfo->tqi_shretry = qi->tqi_shretry;
361 qinfo->tqi_lgretry = qi->tqi_lgretry;
362 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
363 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
364 qinfo->tqi_burstTime = qi->tqi_burstTime;
365 qinfo->tqi_readyTime = qi->tqi_readyTime;
366
367 return true;
368}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400369EXPORT_SYMBOL(ath9k_hw_get_txq_props);
Sujithf1dc5602008-10-29 10:16:30 +0530370
Sujithcbe61d82009-02-09 13:27:12 +0530371int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
Sujithf1dc5602008-10-29 10:16:30 +0530372 const struct ath9k_tx_queue_info *qinfo)
373{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700374 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530375 struct ath9k_tx_queue_info *qi;
Sujith2660b812009-02-09 13:27:26 +0530376 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530377 int q;
378
379 switch (type) {
380 case ATH9K_TX_QUEUE_BEACON:
381 q = pCap->total_queues - 1;
382 break;
383 case ATH9K_TX_QUEUE_CAB:
384 q = pCap->total_queues - 2;
385 break;
386 case ATH9K_TX_QUEUE_PSPOLL:
387 q = 1;
388 break;
389 case ATH9K_TX_QUEUE_UAPSD:
390 q = pCap->total_queues - 3;
391 break;
392 case ATH9K_TX_QUEUE_DATA:
393 for (q = 0; q < pCap->total_queues; q++)
Sujith2660b812009-02-09 13:27:26 +0530394 if (ah->txq[q].tqi_type ==
Sujithf1dc5602008-10-29 10:16:30 +0530395 ATH9K_TX_QUEUE_INACTIVE)
396 break;
397 if (q == pCap->total_queues) {
Joe Perches38002762010-12-02 19:12:36 -0800398 ath_err(common, "No available TX queue\n");
Sujithf1dc5602008-10-29 10:16:30 +0530399 return -1;
400 }
401 break;
402 default:
Joe Perches38002762010-12-02 19:12:36 -0800403 ath_err(common, "Invalid TX queue type: %u\n", type);
Sujithf1dc5602008-10-29 10:16:30 +0530404 return -1;
405 }
406
Joe Perches226afe62010-12-02 19:12:37 -0800407 ath_dbg(common, ATH_DBG_QUEUE, "Setup TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530408
Sujith2660b812009-02-09 13:27:26 +0530409 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530410 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
Joe Perches38002762010-12-02 19:12:36 -0800411 ath_err(common, "TX queue: %u already active\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530412 return -1;
413 }
414 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
415 qi->tqi_type = type;
416 if (qinfo == NULL) {
417 qi->tqi_qflags =
418 TXQ_FLAG_TXOKINT_ENABLE
419 | TXQ_FLAG_TXERRINT_ENABLE
420 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
421 qi->tqi_aifs = INIT_AIFS;
422 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
423 qi->tqi_cwmax = INIT_CWMAX;
424 qi->tqi_shretry = INIT_SH_RETRY;
425 qi->tqi_lgretry = INIT_LG_RETRY;
426 qi->tqi_physCompBuf = 0;
427 } else {
428 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
429 (void) ath9k_hw_set_txq_props(ah, q, qinfo);
430 }
431
432 return q;
433}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400434EXPORT_SYMBOL(ath9k_hw_setuptxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530435
Sujithcbe61d82009-02-09 13:27:12 +0530436bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530437{
Sujith2660b812009-02-09 13:27:26 +0530438 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700439 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530440 struct ath9k_tx_queue_info *qi;
441
442 if (q >= pCap->total_queues) {
Joe Perches226afe62010-12-02 19:12:37 -0800443 ath_dbg(common, ATH_DBG_QUEUE,
444 "Release TXQ, invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530445 return false;
446 }
Sujith2660b812009-02-09 13:27:26 +0530447 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530448 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Joe Perches226afe62010-12-02 19:12:37 -0800449 ath_dbg(common, ATH_DBG_QUEUE,
450 "Release TXQ, inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530451 return false;
452 }
453
Joe Perches226afe62010-12-02 19:12:37 -0800454 ath_dbg(common, ATH_DBG_QUEUE, "Release TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530455
456 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
Sujith2660b812009-02-09 13:27:26 +0530457 ah->txok_interrupt_mask &= ~(1 << q);
458 ah->txerr_interrupt_mask &= ~(1 << q);
459 ah->txdesc_interrupt_mask &= ~(1 << q);
460 ah->txeol_interrupt_mask &= ~(1 << q);
461 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530462 ath9k_hw_set_txq_interrupts(ah, qi);
463
464 return true;
465}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400466EXPORT_SYMBOL(ath9k_hw_releasetxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530467
Sujithcbe61d82009-02-09 13:27:12 +0530468bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530469{
Sujith2660b812009-02-09 13:27:26 +0530470 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700471 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530472 struct ath9k_channel *chan = ah->curchan;
Sujithf1dc5602008-10-29 10:16:30 +0530473 struct ath9k_tx_queue_info *qi;
474 u32 cwMin, chanCwMin, value;
475
476 if (q >= pCap->total_queues) {
Joe Perches226afe62010-12-02 19:12:37 -0800477 ath_dbg(common, ATH_DBG_QUEUE,
478 "Reset TXQ, invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530479 return false;
480 }
481
Sujith2660b812009-02-09 13:27:26 +0530482 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530483 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Joe Perches226afe62010-12-02 19:12:37 -0800484 ath_dbg(common, ATH_DBG_QUEUE,
485 "Reset TXQ, inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530486 return true;
487 }
488
Joe Perches226afe62010-12-02 19:12:37 -0800489 ath_dbg(common, ATH_DBG_QUEUE, "Reset TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530490
491 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
492 if (chan && IS_CHAN_B(chan))
493 chanCwMin = INIT_CWMIN_11B;
494 else
495 chanCwMin = INIT_CWMIN;
496
497 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
498 } else
499 cwMin = qi->tqi_cwmin;
500
Sujith7d0d0df2010-04-16 11:53:57 +0530501 ENABLE_REGWRITE_BUFFER(ah);
502
Sujithf1dc5602008-10-29 10:16:30 +0530503 REG_WRITE(ah, AR_DLCL_IFS(q),
504 SM(cwMin, AR_D_LCL_IFS_CWMIN) |
505 SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
506 SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
507
508 REG_WRITE(ah, AR_DRETRY_LIMIT(q),
509 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
510 SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
511 SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
512
513 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
514 REG_WRITE(ah, AR_DMISC(q),
515 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
516
517 if (qi->tqi_cbrPeriod) {
518 REG_WRITE(ah, AR_QCBRCFG(q),
519 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
520 SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
521 REG_WRITE(ah, AR_QMISC(q),
522 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
523 (qi->tqi_cbrOverflowLimit ?
524 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
525 }
526 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
527 REG_WRITE(ah, AR_QRDYTIMECFG(q),
528 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
529 AR_Q_RDYTIMECFG_EN);
530 }
531
532 REG_WRITE(ah, AR_DCHNTIME(q),
533 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
534 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
535
536 if (qi->tqi_burstTime
537 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
538 REG_WRITE(ah, AR_QMISC(q),
539 REG_READ(ah, AR_QMISC(q)) |
540 AR_Q_MISC_RDYTIME_EXP_POLICY);
541
542 }
543
544 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
545 REG_WRITE(ah, AR_DMISC(q),
546 REG_READ(ah, AR_DMISC(q)) |
547 AR_D_MISC_POST_FR_BKOFF_DIS);
548 }
Sujith7d0d0df2010-04-16 11:53:57 +0530549
550 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530551
Sujithf1dc5602008-10-29 10:16:30 +0530552 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
553 REG_WRITE(ah, AR_DMISC(q),
554 REG_READ(ah, AR_DMISC(q)) |
555 AR_D_MISC_FRAG_BKOFF_EN);
556 }
557 switch (qi->tqi_type) {
558 case ATH9K_TX_QUEUE_BEACON:
Sujith7d0d0df2010-04-16 11:53:57 +0530559 ENABLE_REGWRITE_BUFFER(ah);
560
Sujithf1dc5602008-10-29 10:16:30 +0530561 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
562 | AR_Q_MISC_FSP_DBA_GATED
563 | AR_Q_MISC_BEACON_USE
564 | AR_Q_MISC_CBR_INCR_DIS1);
565
566 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
567 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
568 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
569 | AR_D_MISC_BEACON_USE
570 | AR_D_MISC_POST_FR_BKOFF_DIS);
Sujith7d0d0df2010-04-16 11:53:57 +0530571
572 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530573
Luis R. Rodriguez9a2af882010-06-14 20:17:36 -0400574 /*
575 * cwmin and cwmax should be 0 for beacon queue
576 * but not for IBSS as we would create an imbalance
577 * on beaconing fairness for participating nodes.
578 */
579 if (AR_SREV_9300_20_OR_LATER(ah) &&
580 ah->opmode != NL80211_IFTYPE_ADHOC) {
Luis R. Rodriguez3deb4da2010-04-15 17:39:32 -0400581 REG_WRITE(ah, AR_DLCL_IFS(q), SM(0, AR_D_LCL_IFS_CWMIN)
582 | SM(0, AR_D_LCL_IFS_CWMAX)
583 | SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
584 }
Sujithf1dc5602008-10-29 10:16:30 +0530585 break;
586 case ATH9K_TX_QUEUE_CAB:
Sujith7d0d0df2010-04-16 11:53:57 +0530587 ENABLE_REGWRITE_BUFFER(ah);
588
Sujithf1dc5602008-10-29 10:16:30 +0530589 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
590 | AR_Q_MISC_FSP_DBA_GATED
591 | AR_Q_MISC_CBR_INCR_DIS1
592 | AR_Q_MISC_CBR_INCR_DIS0);
593 value = (qi->tqi_readyTime -
Sujith2660b812009-02-09 13:27:26 +0530594 (ah->config.sw_beacon_response_time -
595 ah->config.dma_beacon_response_time) -
596 ah->config.additional_swba_backoff) * 1024;
Sujithf1dc5602008-10-29 10:16:30 +0530597 REG_WRITE(ah, AR_QRDYTIMECFG(q),
598 value | AR_Q_RDYTIMECFG_EN);
599 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
600 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
601 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
Sujith7d0d0df2010-04-16 11:53:57 +0530602
603 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530604
Sujithf1dc5602008-10-29 10:16:30 +0530605 break;
606 case ATH9K_TX_QUEUE_PSPOLL:
607 REG_WRITE(ah, AR_QMISC(q),
608 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
609 break;
610 case ATH9K_TX_QUEUE_UAPSD:
611 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
612 AR_D_MISC_POST_FR_BKOFF_DIS);
613 break;
614 default:
615 break;
616 }
617
618 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
619 REG_WRITE(ah, AR_DMISC(q),
620 REG_READ(ah, AR_DMISC(q)) |
621 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
622 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
623 AR_D_MISC_POST_FR_BKOFF_DIS);
624 }
625
Luis R. Rodriguez79de2372010-04-15 17:39:31 -0400626 if (AR_SREV_9300_20_OR_LATER(ah))
627 REG_WRITE(ah, AR_Q_DESC_CRCCHK, AR_Q_DESC_CRCCHK_EN);
628
Sujithf1dc5602008-10-29 10:16:30 +0530629 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530630 ah->txok_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530631 else
Sujith2660b812009-02-09 13:27:26 +0530632 ah->txok_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530633 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530634 ah->txerr_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530635 else
Sujith2660b812009-02-09 13:27:26 +0530636 ah->txerr_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530637 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530638 ah->txdesc_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530639 else
Sujith2660b812009-02-09 13:27:26 +0530640 ah->txdesc_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530641 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530642 ah->txeol_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530643 else
Sujith2660b812009-02-09 13:27:26 +0530644 ah->txeol_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530645 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530646 ah->txurn_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530647 else
Sujith2660b812009-02-09 13:27:26 +0530648 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530649 ath9k_hw_set_txq_interrupts(ah, qi);
650
651 return true;
652}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400653EXPORT_SYMBOL(ath9k_hw_resettxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530654
Sujithcbe61d82009-02-09 13:27:12 +0530655int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700656 struct ath_rx_status *rs, u64 tsf)
Sujithf1dc5602008-10-29 10:16:30 +0530657{
658 struct ar5416_desc ads;
659 struct ar5416_desc *adsp = AR5416DESC(ds);
660 u32 phyerr;
661
662 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
663 return -EINPROGRESS;
664
665 ads.u.rx = adsp->u.rx;
666
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700667 rs->rs_status = 0;
668 rs->rs_flags = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530669
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700670 rs->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
671 rs->rs_tstamp = ads.AR_RcvTimestamp;
Sujithf1dc5602008-10-29 10:16:30 +0530672
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400673 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700674 rs->rs_rssi = ATH9K_RSSI_BAD;
675 rs->rs_rssi_ctl0 = ATH9K_RSSI_BAD;
676 rs->rs_rssi_ctl1 = ATH9K_RSSI_BAD;
677 rs->rs_rssi_ctl2 = ATH9K_RSSI_BAD;
678 rs->rs_rssi_ext0 = ATH9K_RSSI_BAD;
679 rs->rs_rssi_ext1 = ATH9K_RSSI_BAD;
680 rs->rs_rssi_ext2 = ATH9K_RSSI_BAD;
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400681 } else {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700682 rs->rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
683 rs->rs_rssi_ctl0 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400684 AR_RxRSSIAnt00);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700685 rs->rs_rssi_ctl1 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400686 AR_RxRSSIAnt01);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700687 rs->rs_rssi_ctl2 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400688 AR_RxRSSIAnt02);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700689 rs->rs_rssi_ext0 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400690 AR_RxRSSIAnt10);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700691 rs->rs_rssi_ext1 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400692 AR_RxRSSIAnt11);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700693 rs->rs_rssi_ext2 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400694 AR_RxRSSIAnt12);
695 }
Sujithf1dc5602008-10-29 10:16:30 +0530696 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700697 rs->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
Sujithf1dc5602008-10-29 10:16:30 +0530698 else
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700699 rs->rs_keyix = ATH9K_RXKEYIX_INVALID;
Sujithf1dc5602008-10-29 10:16:30 +0530700
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700701 rs->rs_rate = RXSTATUS_RATE(ah, (&ads));
702 rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
Sujithf1dc5602008-10-29 10:16:30 +0530703
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700704 rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
705 rs->rs_moreaggr =
Sujithf1dc5602008-10-29 10:16:30 +0530706 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700707 rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
708 rs->rs_flags =
Sujithf1dc5602008-10-29 10:16:30 +0530709 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700710 rs->rs_flags |=
Sujithf1dc5602008-10-29 10:16:30 +0530711 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
712
713 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700714 rs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
Sujithf1dc5602008-10-29 10:16:30 +0530715 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700716 rs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
Sujithf1dc5602008-10-29 10:16:30 +0530717 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700718 rs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
Sujithf1dc5602008-10-29 10:16:30 +0530719
720 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
Felix Fietkau115dad72011-01-14 00:06:27 +0100721 /*
722 * Treat these errors as mutually exclusive to avoid spurious
723 * extra error reports from the hardware. If a CRC error is
724 * reported, then decryption and MIC errors are irrelevant,
725 * the frame is going to be dropped either way
726 */
Sujithf1dc5602008-10-29 10:16:30 +0530727 if (ads.ds_rxstatus8 & AR_CRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700728 rs->rs_status |= ATH9K_RXERR_CRC;
Felix Fietkau115dad72011-01-14 00:06:27 +0100729 else if (ads.ds_rxstatus8 & AR_PHYErr) {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700730 rs->rs_status |= ATH9K_RXERR_PHY;
Sujithf1dc5602008-10-29 10:16:30 +0530731 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700732 rs->rs_phyerr = phyerr;
Felix Fietkau115dad72011-01-14 00:06:27 +0100733 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700734 rs->rs_status |= ATH9K_RXERR_DECRYPT;
Felix Fietkau115dad72011-01-14 00:06:27 +0100735 else if (ads.ds_rxstatus8 & AR_MichaelErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700736 rs->rs_status |= ATH9K_RXERR_MIC;
Felix Fietkau115dad72011-01-14 00:06:27 +0100737
Felix Fietkau1c30cc12010-12-28 15:46:16 +0100738 if (ads.ds_rxstatus8 & AR_KeyMiss)
Felix Fietkau3ae74c32010-09-14 18:38:26 +0200739 rs->rs_status |= ATH9K_RXERR_DECRYPT;
Sujithf1dc5602008-10-29 10:16:30 +0530740 }
741
742 return 0;
743}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400744EXPORT_SYMBOL(ath9k_hw_rxprocdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530745
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -0500746/*
747 * This can stop or re-enables RX.
748 *
749 * If bool is set this will kill any frame which is currently being
750 * transferred between the MAC and baseband and also prevent any new
751 * frames from getting started.
752 */
Sujithcbe61d82009-02-09 13:27:12 +0530753bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
Sujithf1dc5602008-10-29 10:16:30 +0530754{
755 u32 reg;
756
757 if (set) {
758 REG_SET_BIT(ah, AR_DIAG_SW,
759 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
760
Sujith0caa7b12009-02-16 13:23:20 +0530761 if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
762 0, AH_WAIT_TIMEOUT)) {
Sujithf1dc5602008-10-29 10:16:30 +0530763 REG_CLR_BIT(ah, AR_DIAG_SW,
764 (AR_DIAG_RX_DIS |
765 AR_DIAG_RX_ABORT));
766
767 reg = REG_READ(ah, AR_OBS_BUS_1);
Joe Perches38002762010-12-02 19:12:36 -0800768 ath_err(ath9k_hw_common(ah),
769 "RX failed to go idle in 10 ms RXSM=0x%x\n",
770 reg);
Sujithf1dc5602008-10-29 10:16:30 +0530771
772 return false;
773 }
774 } else {
775 REG_CLR_BIT(ah, AR_DIAG_SW,
776 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
777 }
778
779 return true;
780}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400781EXPORT_SYMBOL(ath9k_hw_setrxabort);
Sujithf1dc5602008-10-29 10:16:30 +0530782
Sujithcbe61d82009-02-09 13:27:12 +0530783void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
Sujithf1dc5602008-10-29 10:16:30 +0530784{
785 REG_WRITE(ah, AR_RXDP, rxdp);
786}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400787EXPORT_SYMBOL(ath9k_hw_putrxbuf);
Sujithf1dc5602008-10-29 10:16:30 +0530788
Luis R. Rodriguez40346b62010-06-12 00:33:44 -0400789void ath9k_hw_startpcureceive(struct ath_hw *ah, bool is_scanning)
Sujithf1dc5602008-10-29 10:16:30 +0530790{
Sujithf1dc5602008-10-29 10:16:30 +0530791 ath9k_enable_mib_counters(ah);
792
Luis R. Rodriguez40346b62010-06-12 00:33:44 -0400793 ath9k_ani_reset(ah, is_scanning);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530794
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +0530795 REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
Sujithf1dc5602008-10-29 10:16:30 +0530796}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400797EXPORT_SYMBOL(ath9k_hw_startpcureceive);
Sujithf1dc5602008-10-29 10:16:30 +0530798
Vasanthakumar Thiagarajan9b9cc612010-04-15 17:39:41 -0400799void ath9k_hw_abortpcurecv(struct ath_hw *ah)
800{
801 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_ABORT | AR_DIAG_RX_DIS);
802
803 ath9k_hw_disable_mib_counters(ah);
804}
805EXPORT_SYMBOL(ath9k_hw_abortpcurecv);
806
Sujithcbe61d82009-02-09 13:27:12 +0530807bool ath9k_hw_stopdmarecv(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530808{
Sujith0caa7b12009-02-16 13:23:20 +0530809#define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
810#define AH_RX_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700811 struct ath_common *common = ath9k_hw_common(ah);
Sujith0caa7b12009-02-16 13:23:20 +0530812 int i;
813
Sujithf1dc5602008-10-29 10:16:30 +0530814 REG_WRITE(ah, AR_CR, AR_CR_RXD);
815
Sujith0caa7b12009-02-16 13:23:20 +0530816 /* Wait for rx enable bit to go low */
817 for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
818 if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
819 break;
820 udelay(AH_TIME_QUANTUM);
821 }
822
823 if (i == 0) {
Joe Perches38002762010-12-02 19:12:36 -0800824 ath_err(common,
825 "DMA failed to stop in %d ms AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
826 AH_RX_STOP_DMA_TIMEOUT / 1000,
827 REG_READ(ah, AR_CR),
828 REG_READ(ah, AR_DIAG_SW));
Sujithf1dc5602008-10-29 10:16:30 +0530829 return false;
830 } else {
831 return true;
832 }
Sujith0caa7b12009-02-16 13:23:20 +0530833
834#undef AH_RX_TIME_QUANTUM
835#undef AH_RX_STOP_DMA_TIMEOUT
Sujithf1dc5602008-10-29 10:16:30 +0530836}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400837EXPORT_SYMBOL(ath9k_hw_stopdmarecv);
Luis R. Rodriguez536b3a72009-10-06 21:19:11 -0400838
839int ath9k_hw_beaconq_setup(struct ath_hw *ah)
840{
841 struct ath9k_tx_queue_info qi;
842
843 memset(&qi, 0, sizeof(qi));
844 qi.tqi_aifs = 1;
845 qi.tqi_cwmin = 0;
846 qi.tqi_cwmax = 0;
847 /* NB: don't enable any interrupts */
848 return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
849}
850EXPORT_SYMBOL(ath9k_hw_beaconq_setup);
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400851
852bool ath9k_hw_intrpend(struct ath_hw *ah)
853{
854 u32 host_isr;
855
856 if (AR_SREV_9100(ah))
857 return true;
858
859 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
860 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
861 return true;
862
863 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
864 if ((host_isr & AR_INTR_SYNC_DEFAULT)
865 && (host_isr != AR_INTR_SPURIOUS))
866 return true;
867
868 return false;
869}
870EXPORT_SYMBOL(ath9k_hw_intrpend);
871
Felix Fietkau4df30712010-11-08 20:54:47 +0100872void ath9k_hw_disable_interrupts(struct ath_hw *ah)
873{
874 struct ath_common *common = ath9k_hw_common(ah);
875
Joe Perches226afe62010-12-02 19:12:37 -0800876 ath_dbg(common, ATH_DBG_INTERRUPT, "disable IER\n");
Felix Fietkau4df30712010-11-08 20:54:47 +0100877 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
878 (void) REG_READ(ah, AR_IER);
879 if (!AR_SREV_9100(ah)) {
880 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
881 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
882
883 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
884 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
885 }
886}
887EXPORT_SYMBOL(ath9k_hw_disable_interrupts);
888
889void ath9k_hw_enable_interrupts(struct ath_hw *ah)
890{
891 struct ath_common *common = ath9k_hw_common(ah);
892
893 if (!(ah->imask & ATH9K_INT_GLOBAL))
894 return;
895
Joe Perches226afe62010-12-02 19:12:37 -0800896 ath_dbg(common, ATH_DBG_INTERRUPT, "enable IER\n");
Felix Fietkau4df30712010-11-08 20:54:47 +0100897 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
898 if (!AR_SREV_9100(ah)) {
899 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
900 AR_INTR_MAC_IRQ);
901 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
902
903
904 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
905 AR_INTR_SYNC_DEFAULT);
906 REG_WRITE(ah, AR_INTR_SYNC_MASK,
907 AR_INTR_SYNC_DEFAULT);
908 }
Joe Perches226afe62010-12-02 19:12:37 -0800909 ath_dbg(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
910 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Felix Fietkau4df30712010-11-08 20:54:47 +0100911}
912EXPORT_SYMBOL(ath9k_hw_enable_interrupts);
913
914void ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400915{
916 enum ath9k_int omask = ah->imask;
917 u32 mask, mask2;
918 struct ath9k_hw_capabilities *pCap = &ah->caps;
919 struct ath_common *common = ath9k_hw_common(ah);
920
Felix Fietkau4df30712010-11-08 20:54:47 +0100921 if (!(ints & ATH9K_INT_GLOBAL))
922 ath9k_hw_enable_interrupts(ah);
923
Joe Perches226afe62010-12-02 19:12:37 -0800924 ath_dbg(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400925
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400926 /* TODO: global int Ref count */
927 mask = ints & ATH9K_INT_COMMON;
928 mask2 = 0;
929
930 if (ints & ATH9K_INT_TX) {
931 if (ah->config.tx_intr_mitigation)
932 mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM;
Luis R. Rodriguez5bea4002010-04-26 15:04:41 -0400933 else {
934 if (ah->txok_interrupt_mask)
935 mask |= AR_IMR_TXOK;
936 if (ah->txdesc_interrupt_mask)
937 mask |= AR_IMR_TXDESC;
938 }
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400939 if (ah->txerr_interrupt_mask)
940 mask |= AR_IMR_TXERR;
941 if (ah->txeol_interrupt_mask)
942 mask |= AR_IMR_TXEOL;
943 }
944 if (ints & ATH9K_INT_RX) {
945 if (AR_SREV_9300_20_OR_LATER(ah)) {
946 mask |= AR_IMR_RXERR | AR_IMR_RXOK_HP;
947 if (ah->config.rx_intr_mitigation) {
948 mask &= ~AR_IMR_RXOK_LP;
949 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
950 } else {
951 mask |= AR_IMR_RXOK_LP;
952 }
953 } else {
954 if (ah->config.rx_intr_mitigation)
955 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
956 else
957 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
958 }
959 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
960 mask |= AR_IMR_GENTMR;
961 }
962
963 if (ints & (ATH9K_INT_BMISC)) {
964 mask |= AR_IMR_BCNMISC;
965 if (ints & ATH9K_INT_TIM)
966 mask2 |= AR_IMR_S2_TIM;
967 if (ints & ATH9K_INT_DTIM)
968 mask2 |= AR_IMR_S2_DTIM;
969 if (ints & ATH9K_INT_DTIMSYNC)
970 mask2 |= AR_IMR_S2_DTIMSYNC;
971 if (ints & ATH9K_INT_CABEND)
972 mask2 |= AR_IMR_S2_CABEND;
973 if (ints & ATH9K_INT_TSFOOR)
974 mask2 |= AR_IMR_S2_TSFOOR;
975 }
976
977 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
978 mask |= AR_IMR_BCNMISC;
979 if (ints & ATH9K_INT_GTT)
980 mask2 |= AR_IMR_S2_GTT;
981 if (ints & ATH9K_INT_CST)
982 mask2 |= AR_IMR_S2_CST;
983 }
984
Joe Perches226afe62010-12-02 19:12:37 -0800985 ath_dbg(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400986 REG_WRITE(ah, AR_IMR, mask);
987 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
988 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
989 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
990 ah->imrs2_reg |= mask2;
991 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
992
993 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
994 if (ints & ATH9K_INT_TIM_TIMER)
995 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
996 else
997 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
998 }
999
Felix Fietkau4df30712010-11-08 20:54:47 +01001000 ath9k_hw_enable_interrupts(ah);
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -04001001
Felix Fietkau4df30712010-11-08 20:54:47 +01001002 return;
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -04001003}
1004EXPORT_SYMBOL(ath9k_hw_set_interrupts);