blob: e955bb9d98cbe0380ef5d070005b373c1a132b8d [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{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070023 ath_print(ath9k_hw_common(ah), ATH_DBG_INTERRUPT,
24 "tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
25 ah->txok_interrupt_mask, ah->txerr_interrupt_mask,
26 ah->txdesc_interrupt_mask, ah->txeol_interrupt_mask,
27 ah->txurn_interrupt_mask);
Sujithf1dc5602008-10-29 10:16:30 +053028
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);
43 DISABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +053044}
45
Sujithcbe61d82009-02-09 13:27:12 +053046u32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053047{
48 return REG_READ(ah, AR_QTXDP(q));
49}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040050EXPORT_SYMBOL(ath9k_hw_gettxbuf);
Sujithf1dc5602008-10-29 10:16:30 +053051
Sujith54e4cec2009-08-07 09:45:09 +053052void ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp)
Sujithf1dc5602008-10-29 10:16:30 +053053{
54 REG_WRITE(ah, AR_QTXDP(q), txdp);
Sujithf1dc5602008-10-29 10:16:30 +053055}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040056EXPORT_SYMBOL(ath9k_hw_puttxbuf);
Sujithf1dc5602008-10-29 10:16:30 +053057
Sujith54e4cec2009-08-07 09:45:09 +053058void ath9k_hw_txstart(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053059{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070060 ath_print(ath9k_hw_common(ah), ATH_DBG_QUEUE,
61 "Enable TXE on queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +053062 REG_WRITE(ah, AR_Q_TXE, 1 << q);
Sujithf1dc5602008-10-29 10:16:30 +053063}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040064EXPORT_SYMBOL(ath9k_hw_txstart);
Sujithf1dc5602008-10-29 10:16:30 +053065
Vasanthakumar Thiagarajancc610ac02010-04-15 17:39:26 -040066void ath9k_hw_cleartxdesc(struct ath_hw *ah, void *ds)
67{
68 struct ar5416_desc *ads = AR5416DESC(ds);
69
70 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
71 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
72 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
73 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
74 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
75}
76EXPORT_SYMBOL(ath9k_hw_cleartxdesc);
77
Sujithcbe61d82009-02-09 13:27:12 +053078u32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +053079{
80 u32 npend;
81
82 npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
83 if (npend == 0) {
84
85 if (REG_READ(ah, AR_Q_TXE) & (1 << q))
86 npend = 1;
87 }
88
89 return npend;
90}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040091EXPORT_SYMBOL(ath9k_hw_numtxpending);
Sujithf1dc5602008-10-29 10:16:30 +053092
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -050093/**
94 * ath9k_hw_updatetxtriglevel - adjusts the frame trigger level
95 *
96 * @ah: atheros hardware struct
97 * @bIncTrigLevel: whether or not the frame trigger level should be updated
98 *
99 * The frame trigger level specifies the minimum number of bytes,
100 * in units of 64 bytes, that must be DMA'ed into the PCU TX FIFO
101 * before the PCU will initiate sending the frame on the air. This can
102 * mean we initiate transmit before a full frame is on the PCU TX FIFO.
103 * Resets to 0x1 (meaning 64 bytes or a full frame, whichever occurs
104 * first)
105 *
106 * Caution must be taken to ensure to set the frame trigger level based
107 * on the DMA request size. For example if the DMA request size is set to
108 * 128 bytes the trigger level cannot exceed 6 * 64 = 384. This is because
109 * there need to be enough space in the tx FIFO for the requested transfer
110 * size. Hence the tx FIFO will stop with 512 - 128 = 384 bytes. If we set
111 * the threshold to a value beyond 6, then the transmit will hang.
112 *
113 * Current dual stream devices have a PCU TX FIFO size of 8 KB.
114 * Current single stream devices have a PCU TX FIFO size of 4 KB, however,
115 * there is a hardware issue which forces us to use 2 KB instead so the
116 * frame trigger level must not exceed 2 KB for these chipsets.
117 */
Sujithcbe61d82009-02-09 13:27:12 +0530118bool ath9k_hw_updatetxtriglevel(struct ath_hw *ah, bool bIncTrigLevel)
Sujithf1dc5602008-10-29 10:16:30 +0530119{
Sujithf1dc5602008-10-29 10:16:30 +0530120 u32 txcfg, curLevel, newLevel;
121 enum ath9k_int omask;
122
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500123 if (ah->tx_trig_level >= ah->config.max_txtrig_level)
Sujithf1dc5602008-10-29 10:16:30 +0530124 return false;
125
Pavel Roskin152d5302010-03-31 18:05:37 -0400126 omask = ath9k_hw_set_interrupts(ah, ah->imask & ~ATH9K_INT_GLOBAL);
Sujithf1dc5602008-10-29 10:16:30 +0530127
128 txcfg = REG_READ(ah, AR_TXCFG);
129 curLevel = MS(txcfg, AR_FTRIG);
130 newLevel = curLevel;
131 if (bIncTrigLevel) {
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500132 if (curLevel < ah->config.max_txtrig_level)
Sujithf1dc5602008-10-29 10:16:30 +0530133 newLevel++;
134 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
135 newLevel--;
136 if (newLevel != curLevel)
137 REG_WRITE(ah, AR_TXCFG,
138 (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
139
140 ath9k_hw_set_interrupts(ah, omask);
141
Sujith2660b812009-02-09 13:27:26 +0530142 ah->tx_trig_level = newLevel;
Sujithf1dc5602008-10-29 10:16:30 +0530143
144 return newLevel != curLevel;
145}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400146EXPORT_SYMBOL(ath9k_hw_updatetxtriglevel);
Sujithf1dc5602008-10-29 10:16:30 +0530147
Sujithcbe61d82009-02-09 13:27:12 +0530148bool ath9k_hw_stoptxdma(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530149{
Sujith94ff91d2009-01-27 15:06:38 +0530150#define ATH9K_TX_STOP_DMA_TIMEOUT 4000 /* usec */
151#define ATH9K_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700152 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530153 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujith94ff91d2009-01-27 15:06:38 +0530154 struct ath9k_tx_queue_info *qi;
Sujithf1dc5602008-10-29 10:16:30 +0530155 u32 tsfLow, j, wait;
Sujith94ff91d2009-01-27 15:06:38 +0530156 u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
157
158 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700159 ath_print(common, ATH_DBG_QUEUE, "Stopping TX DMA, "
160 "invalid queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530161 return false;
162 }
163
Sujith2660b812009-02-09 13:27:26 +0530164 qi = &ah->txq[q];
Sujith94ff91d2009-01-27 15:06:38 +0530165 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700166 ath_print(common, ATH_DBG_QUEUE, "Stopping TX DMA, "
167 "inactive queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530168 return false;
169 }
Sujithf1dc5602008-10-29 10:16:30 +0530170
171 REG_WRITE(ah, AR_Q_TXD, 1 << q);
172
Sujith94ff91d2009-01-27 15:06:38 +0530173 for (wait = wait_time; wait != 0; wait--) {
Sujithf1dc5602008-10-29 10:16:30 +0530174 if (ath9k_hw_numtxpending(ah, q) == 0)
175 break;
Sujith94ff91d2009-01-27 15:06:38 +0530176 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530177 }
178
179 if (ath9k_hw_numtxpending(ah, q)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700180 ath_print(common, ATH_DBG_QUEUE,
181 "%s: Num of pending TX Frames %d on Q %d\n",
182 __func__, ath9k_hw_numtxpending(ah, q), q);
Sujithf1dc5602008-10-29 10:16:30 +0530183
184 for (j = 0; j < 2; j++) {
185 tsfLow = REG_READ(ah, AR_TSF_L32);
186 REG_WRITE(ah, AR_QUIET2,
187 SM(10, AR_QUIET2_QUIET_DUR));
188 REG_WRITE(ah, AR_QUIET_PERIOD, 100);
189 REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
190 REG_SET_BIT(ah, AR_TIMER_MODE,
191 AR_QUIET_TIMER_EN);
192
193 if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10))
194 break;
195
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700196 ath_print(common, ATH_DBG_QUEUE,
197 "TSF has moved while trying to set "
198 "quiet time TSF: 0x%08x\n", tsfLow);
Sujithf1dc5602008-10-29 10:16:30 +0530199 }
200
201 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
202
203 udelay(200);
204 REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);
205
Sujith94ff91d2009-01-27 15:06:38 +0530206 wait = wait_time;
Sujithf1dc5602008-10-29 10:16:30 +0530207 while (ath9k_hw_numtxpending(ah, q)) {
208 if ((--wait) == 0) {
Sujithe8009e92009-12-14 14:57:08 +0530209 ath_print(common, ATH_DBG_FATAL,
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700210 "Failed to stop TX DMA in 100 "
211 "msec after killing last frame\n");
Sujithf1dc5602008-10-29 10:16:30 +0530212 break;
213 }
Sujith94ff91d2009-01-27 15:06:38 +0530214 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530215 }
216
217 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
218 }
219
220 REG_WRITE(ah, AR_Q_TXD, 0);
Sujithf1dc5602008-10-29 10:16:30 +0530221 return wait != 0;
Sujith94ff91d2009-01-27 15:06:38 +0530222
223#undef ATH9K_TX_STOP_DMA_TIMEOUT
224#undef ATH9K_TIME_QUANTUM
Sujithf1dc5602008-10-29 10:16:30 +0530225}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400226EXPORT_SYMBOL(ath9k_hw_stoptxdma);
Sujithf1dc5602008-10-29 10:16:30 +0530227
Sujithcbe61d82009-02-09 13:27:12 +0530228void ath9k_hw_gettxintrtxqs(struct ath_hw *ah, u32 *txqs)
Sujithf1dc5602008-10-29 10:16:30 +0530229{
Sujith2660b812009-02-09 13:27:26 +0530230 *txqs &= ah->intr_txqs;
231 ah->intr_txqs &= ~(*txqs);
Sujithf1dc5602008-10-29 10:16:30 +0530232}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400233EXPORT_SYMBOL(ath9k_hw_gettxintrtxqs);
Sujithf1dc5602008-10-29 10:16:30 +0530234
Sujithcbe61d82009-02-09 13:27:12 +0530235bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530236 const struct ath9k_tx_queue_info *qinfo)
237{
238 u32 cw;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700239 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530240 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530241 struct ath9k_tx_queue_info *qi;
242
243 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700244 ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
245 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530246 return false;
247 }
248
Sujith2660b812009-02-09 13:27:26 +0530249 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530250 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700251 ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
252 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530253 return false;
254 }
255
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700256 ath_print(common, ATH_DBG_QUEUE, "Set queue properties for: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530257
258 qi->tqi_ver = qinfo->tqi_ver;
259 qi->tqi_subtype = qinfo->tqi_subtype;
260 qi->tqi_qflags = qinfo->tqi_qflags;
261 qi->tqi_priority = qinfo->tqi_priority;
262 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
263 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
264 else
265 qi->tqi_aifs = INIT_AIFS;
266 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
267 cw = min(qinfo->tqi_cwmin, 1024U);
268 qi->tqi_cwmin = 1;
269 while (qi->tqi_cwmin < cw)
270 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
271 } else
272 qi->tqi_cwmin = qinfo->tqi_cwmin;
273 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
274 cw = min(qinfo->tqi_cwmax, 1024U);
275 qi->tqi_cwmax = 1;
276 while (qi->tqi_cwmax < cw)
277 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
278 } else
279 qi->tqi_cwmax = INIT_CWMAX;
280
281 if (qinfo->tqi_shretry != 0)
282 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
283 else
284 qi->tqi_shretry = INIT_SH_RETRY;
285 if (qinfo->tqi_lgretry != 0)
286 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
287 else
288 qi->tqi_lgretry = INIT_LG_RETRY;
289 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
290 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
291 qi->tqi_burstTime = qinfo->tqi_burstTime;
292 qi->tqi_readyTime = qinfo->tqi_readyTime;
293
294 switch (qinfo->tqi_subtype) {
295 case ATH9K_WME_UPSD:
296 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
297 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
298 break;
299 default:
300 break;
301 }
302
303 return true;
304}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400305EXPORT_SYMBOL(ath9k_hw_set_txq_props);
Sujithf1dc5602008-10-29 10:16:30 +0530306
Sujithcbe61d82009-02-09 13:27:12 +0530307bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530308 struct ath9k_tx_queue_info *qinfo)
309{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700310 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530311 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530312 struct ath9k_tx_queue_info *qi;
313
314 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700315 ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
316 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530317 return false;
318 }
319
Sujith2660b812009-02-09 13:27:26 +0530320 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530321 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700322 ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
323 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530324 return false;
325 }
326
327 qinfo->tqi_qflags = qi->tqi_qflags;
328 qinfo->tqi_ver = qi->tqi_ver;
329 qinfo->tqi_subtype = qi->tqi_subtype;
330 qinfo->tqi_qflags = qi->tqi_qflags;
331 qinfo->tqi_priority = qi->tqi_priority;
332 qinfo->tqi_aifs = qi->tqi_aifs;
333 qinfo->tqi_cwmin = qi->tqi_cwmin;
334 qinfo->tqi_cwmax = qi->tqi_cwmax;
335 qinfo->tqi_shretry = qi->tqi_shretry;
336 qinfo->tqi_lgretry = qi->tqi_lgretry;
337 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
338 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
339 qinfo->tqi_burstTime = qi->tqi_burstTime;
340 qinfo->tqi_readyTime = qi->tqi_readyTime;
341
342 return true;
343}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400344EXPORT_SYMBOL(ath9k_hw_get_txq_props);
Sujithf1dc5602008-10-29 10:16:30 +0530345
Sujithcbe61d82009-02-09 13:27:12 +0530346int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
Sujithf1dc5602008-10-29 10:16:30 +0530347 const struct ath9k_tx_queue_info *qinfo)
348{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700349 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530350 struct ath9k_tx_queue_info *qi;
Sujith2660b812009-02-09 13:27:26 +0530351 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530352 int q;
353
354 switch (type) {
355 case ATH9K_TX_QUEUE_BEACON:
356 q = pCap->total_queues - 1;
357 break;
358 case ATH9K_TX_QUEUE_CAB:
359 q = pCap->total_queues - 2;
360 break;
361 case ATH9K_TX_QUEUE_PSPOLL:
362 q = 1;
363 break;
364 case ATH9K_TX_QUEUE_UAPSD:
365 q = pCap->total_queues - 3;
366 break;
367 case ATH9K_TX_QUEUE_DATA:
368 for (q = 0; q < pCap->total_queues; q++)
Sujith2660b812009-02-09 13:27:26 +0530369 if (ah->txq[q].tqi_type ==
Sujithf1dc5602008-10-29 10:16:30 +0530370 ATH9K_TX_QUEUE_INACTIVE)
371 break;
372 if (q == pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700373 ath_print(common, ATH_DBG_FATAL,
374 "No available TX queue\n");
Sujithf1dc5602008-10-29 10:16:30 +0530375 return -1;
376 }
377 break;
378 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700379 ath_print(common, ATH_DBG_FATAL,
380 "Invalid TX queue type: %u\n", type);
Sujithf1dc5602008-10-29 10:16:30 +0530381 return -1;
382 }
383
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700384 ath_print(common, ATH_DBG_QUEUE, "Setup TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530385
Sujith2660b812009-02-09 13:27:26 +0530386 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530387 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700388 ath_print(common, ATH_DBG_FATAL,
389 "TX queue: %u already active\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530390 return -1;
391 }
392 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
393 qi->tqi_type = type;
394 if (qinfo == NULL) {
395 qi->tqi_qflags =
396 TXQ_FLAG_TXOKINT_ENABLE
397 | TXQ_FLAG_TXERRINT_ENABLE
398 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
399 qi->tqi_aifs = INIT_AIFS;
400 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
401 qi->tqi_cwmax = INIT_CWMAX;
402 qi->tqi_shretry = INIT_SH_RETRY;
403 qi->tqi_lgretry = INIT_LG_RETRY;
404 qi->tqi_physCompBuf = 0;
405 } else {
406 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
407 (void) ath9k_hw_set_txq_props(ah, q, qinfo);
408 }
409
410 return q;
411}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400412EXPORT_SYMBOL(ath9k_hw_setuptxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530413
Sujithcbe61d82009-02-09 13:27:12 +0530414bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530415{
Sujith2660b812009-02-09 13:27:26 +0530416 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700417 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530418 struct ath9k_tx_queue_info *qi;
419
420 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700421 ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
422 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530423 return false;
424 }
Sujith2660b812009-02-09 13:27:26 +0530425 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530426 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700427 ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
428 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530429 return false;
430 }
431
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700432 ath_print(common, ATH_DBG_QUEUE, "Release TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530433
434 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
Sujith2660b812009-02-09 13:27:26 +0530435 ah->txok_interrupt_mask &= ~(1 << q);
436 ah->txerr_interrupt_mask &= ~(1 << q);
437 ah->txdesc_interrupt_mask &= ~(1 << q);
438 ah->txeol_interrupt_mask &= ~(1 << q);
439 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530440 ath9k_hw_set_txq_interrupts(ah, qi);
441
442 return true;
443}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400444EXPORT_SYMBOL(ath9k_hw_releasetxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530445
Sujithcbe61d82009-02-09 13:27:12 +0530446bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530447{
Sujith2660b812009-02-09 13:27:26 +0530448 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700449 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530450 struct ath9k_channel *chan = ah->curchan;
Sujithf1dc5602008-10-29 10:16:30 +0530451 struct ath9k_tx_queue_info *qi;
452 u32 cwMin, chanCwMin, value;
453
454 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700455 ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
456 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530457 return false;
458 }
459
Sujith2660b812009-02-09 13:27:26 +0530460 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530461 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700462 ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
463 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530464 return true;
465 }
466
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700467 ath_print(common, ATH_DBG_QUEUE, "Reset TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530468
469 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
470 if (chan && IS_CHAN_B(chan))
471 chanCwMin = INIT_CWMIN_11B;
472 else
473 chanCwMin = INIT_CWMIN;
474
475 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
476 } else
477 cwMin = qi->tqi_cwmin;
478
Sujith7d0d0df2010-04-16 11:53:57 +0530479 ENABLE_REGWRITE_BUFFER(ah);
480
Sujithf1dc5602008-10-29 10:16:30 +0530481 REG_WRITE(ah, AR_DLCL_IFS(q),
482 SM(cwMin, AR_D_LCL_IFS_CWMIN) |
483 SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
484 SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
485
486 REG_WRITE(ah, AR_DRETRY_LIMIT(q),
487 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
488 SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
489 SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
490
491 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
492 REG_WRITE(ah, AR_DMISC(q),
493 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
494
Sujith7d0d0df2010-04-16 11:53:57 +0530495 REGWRITE_BUFFER_FLUSH(ah);
496
Sujithf1dc5602008-10-29 10:16:30 +0530497 if (qi->tqi_cbrPeriod) {
498 REG_WRITE(ah, AR_QCBRCFG(q),
499 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
500 SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
501 REG_WRITE(ah, AR_QMISC(q),
502 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
503 (qi->tqi_cbrOverflowLimit ?
504 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
505 }
506 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
507 REG_WRITE(ah, AR_QRDYTIMECFG(q),
508 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
509 AR_Q_RDYTIMECFG_EN);
510 }
511
Sujith7d0d0df2010-04-16 11:53:57 +0530512 REGWRITE_BUFFER_FLUSH(ah);
513
Sujithf1dc5602008-10-29 10:16:30 +0530514 REG_WRITE(ah, AR_DCHNTIME(q),
515 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
516 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
517
518 if (qi->tqi_burstTime
519 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
520 REG_WRITE(ah, AR_QMISC(q),
521 REG_READ(ah, AR_QMISC(q)) |
522 AR_Q_MISC_RDYTIME_EXP_POLICY);
523
524 }
525
526 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
527 REG_WRITE(ah, AR_DMISC(q),
528 REG_READ(ah, AR_DMISC(q)) |
529 AR_D_MISC_POST_FR_BKOFF_DIS);
530 }
Sujith7d0d0df2010-04-16 11:53:57 +0530531
532 REGWRITE_BUFFER_FLUSH(ah);
533 DISABLE_REGWRITE_BUFFER(ah);
534
Sujithf1dc5602008-10-29 10:16:30 +0530535 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
536 REG_WRITE(ah, AR_DMISC(q),
537 REG_READ(ah, AR_DMISC(q)) |
538 AR_D_MISC_FRAG_BKOFF_EN);
539 }
540 switch (qi->tqi_type) {
541 case ATH9K_TX_QUEUE_BEACON:
Sujith7d0d0df2010-04-16 11:53:57 +0530542 ENABLE_REGWRITE_BUFFER(ah);
543
Sujithf1dc5602008-10-29 10:16:30 +0530544 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
545 | AR_Q_MISC_FSP_DBA_GATED
546 | AR_Q_MISC_BEACON_USE
547 | AR_Q_MISC_CBR_INCR_DIS1);
548
549 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
550 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
551 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
552 | AR_D_MISC_BEACON_USE
553 | AR_D_MISC_POST_FR_BKOFF_DIS);
Sujith7d0d0df2010-04-16 11:53:57 +0530554
555 REGWRITE_BUFFER_FLUSH(ah);
556 DISABLE_REGWRITE_BUFFER(ah);
557
Luis R. Rodriguez9a2af882010-06-14 20:17:36 -0400558 /*
559 * cwmin and cwmax should be 0 for beacon queue
560 * but not for IBSS as we would create an imbalance
561 * on beaconing fairness for participating nodes.
562 */
563 if (AR_SREV_9300_20_OR_LATER(ah) &&
564 ah->opmode != NL80211_IFTYPE_ADHOC) {
Luis R. Rodriguez3deb4da2010-04-15 17:39:32 -0400565 REG_WRITE(ah, AR_DLCL_IFS(q), SM(0, AR_D_LCL_IFS_CWMIN)
566 | SM(0, AR_D_LCL_IFS_CWMAX)
567 | SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
568 }
Sujithf1dc5602008-10-29 10:16:30 +0530569 break;
570 case ATH9K_TX_QUEUE_CAB:
Sujith7d0d0df2010-04-16 11:53:57 +0530571 ENABLE_REGWRITE_BUFFER(ah);
572
Sujithf1dc5602008-10-29 10:16:30 +0530573 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
574 | AR_Q_MISC_FSP_DBA_GATED
575 | AR_Q_MISC_CBR_INCR_DIS1
576 | AR_Q_MISC_CBR_INCR_DIS0);
577 value = (qi->tqi_readyTime -
Sujith2660b812009-02-09 13:27:26 +0530578 (ah->config.sw_beacon_response_time -
579 ah->config.dma_beacon_response_time) -
580 ah->config.additional_swba_backoff) * 1024;
Sujithf1dc5602008-10-29 10:16:30 +0530581 REG_WRITE(ah, AR_QRDYTIMECFG(q),
582 value | AR_Q_RDYTIMECFG_EN);
583 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
584 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
585 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
Sujith7d0d0df2010-04-16 11:53:57 +0530586
587 REGWRITE_BUFFER_FLUSH(ah);
588 DISABLE_REGWRITE_BUFFER(ah);
589
Sujithf1dc5602008-10-29 10:16:30 +0530590 break;
591 case ATH9K_TX_QUEUE_PSPOLL:
592 REG_WRITE(ah, AR_QMISC(q),
593 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
594 break;
595 case ATH9K_TX_QUEUE_UAPSD:
596 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
597 AR_D_MISC_POST_FR_BKOFF_DIS);
598 break;
599 default:
600 break;
601 }
602
603 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
604 REG_WRITE(ah, AR_DMISC(q),
605 REG_READ(ah, AR_DMISC(q)) |
606 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
607 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
608 AR_D_MISC_POST_FR_BKOFF_DIS);
609 }
610
Luis R. Rodriguez79de2372010-04-15 17:39:31 -0400611 if (AR_SREV_9300_20_OR_LATER(ah))
612 REG_WRITE(ah, AR_Q_DESC_CRCCHK, AR_Q_DESC_CRCCHK_EN);
613
Sujithf1dc5602008-10-29 10:16:30 +0530614 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530615 ah->txok_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530616 else
Sujith2660b812009-02-09 13:27:26 +0530617 ah->txok_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530618 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530619 ah->txerr_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530620 else
Sujith2660b812009-02-09 13:27:26 +0530621 ah->txerr_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530622 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530623 ah->txdesc_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530624 else
Sujith2660b812009-02-09 13:27:26 +0530625 ah->txdesc_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530626 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530627 ah->txeol_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530628 else
Sujith2660b812009-02-09 13:27:26 +0530629 ah->txeol_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530630 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +0530631 ah->txurn_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +0530632 else
Sujith2660b812009-02-09 13:27:26 +0530633 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530634 ath9k_hw_set_txq_interrupts(ah, qi);
635
636 return true;
637}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400638EXPORT_SYMBOL(ath9k_hw_resettxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530639
Sujithcbe61d82009-02-09 13:27:12 +0530640int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700641 struct ath_rx_status *rs, u64 tsf)
Sujithf1dc5602008-10-29 10:16:30 +0530642{
643 struct ar5416_desc ads;
644 struct ar5416_desc *adsp = AR5416DESC(ds);
645 u32 phyerr;
646
647 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
648 return -EINPROGRESS;
649
650 ads.u.rx = adsp->u.rx;
651
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700652 rs->rs_status = 0;
653 rs->rs_flags = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530654
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700655 rs->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
656 rs->rs_tstamp = ads.AR_RcvTimestamp;
Sujithf1dc5602008-10-29 10:16:30 +0530657
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400658 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700659 rs->rs_rssi = ATH9K_RSSI_BAD;
660 rs->rs_rssi_ctl0 = ATH9K_RSSI_BAD;
661 rs->rs_rssi_ctl1 = ATH9K_RSSI_BAD;
662 rs->rs_rssi_ctl2 = ATH9K_RSSI_BAD;
663 rs->rs_rssi_ext0 = ATH9K_RSSI_BAD;
664 rs->rs_rssi_ext1 = ATH9K_RSSI_BAD;
665 rs->rs_rssi_ext2 = ATH9K_RSSI_BAD;
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400666 } else {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700667 rs->rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
668 rs->rs_rssi_ctl0 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400669 AR_RxRSSIAnt00);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700670 rs->rs_rssi_ctl1 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400671 AR_RxRSSIAnt01);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700672 rs->rs_rssi_ctl2 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400673 AR_RxRSSIAnt02);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700674 rs->rs_rssi_ext0 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400675 AR_RxRSSIAnt10);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700676 rs->rs_rssi_ext1 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400677 AR_RxRSSIAnt11);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700678 rs->rs_rssi_ext2 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -0400679 AR_RxRSSIAnt12);
680 }
Sujithf1dc5602008-10-29 10:16:30 +0530681 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700682 rs->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
Sujithf1dc5602008-10-29 10:16:30 +0530683 else
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700684 rs->rs_keyix = ATH9K_RXKEYIX_INVALID;
Sujithf1dc5602008-10-29 10:16:30 +0530685
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700686 rs->rs_rate = RXSTATUS_RATE(ah, (&ads));
687 rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
Sujithf1dc5602008-10-29 10:16:30 +0530688
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700689 rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
690 rs->rs_moreaggr =
Sujithf1dc5602008-10-29 10:16:30 +0530691 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700692 rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
693 rs->rs_flags =
Sujithf1dc5602008-10-29 10:16:30 +0530694 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700695 rs->rs_flags |=
Sujithf1dc5602008-10-29 10:16:30 +0530696 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
697
698 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700699 rs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
Sujithf1dc5602008-10-29 10:16:30 +0530700 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700701 rs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
Sujithf1dc5602008-10-29 10:16:30 +0530702 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700703 rs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
Sujithf1dc5602008-10-29 10:16:30 +0530704
705 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
706 if (ads.ds_rxstatus8 & AR_CRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700707 rs->rs_status |= ATH9K_RXERR_CRC;
Sujithf1dc5602008-10-29 10:16:30 +0530708 else if (ads.ds_rxstatus8 & AR_PHYErr) {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700709 rs->rs_status |= ATH9K_RXERR_PHY;
Sujithf1dc5602008-10-29 10:16:30 +0530710 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700711 rs->rs_phyerr = phyerr;
Sujithf1dc5602008-10-29 10:16:30 +0530712 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700713 rs->rs_status |= ATH9K_RXERR_DECRYPT;
Sujithf1dc5602008-10-29 10:16:30 +0530714 else if (ads.ds_rxstatus8 & AR_MichaelErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700715 rs->rs_status |= ATH9K_RXERR_MIC;
Sujithf1dc5602008-10-29 10:16:30 +0530716 }
717
718 return 0;
719}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400720EXPORT_SYMBOL(ath9k_hw_rxprocdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530721
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -0500722/*
723 * This can stop or re-enables RX.
724 *
725 * If bool is set this will kill any frame which is currently being
726 * transferred between the MAC and baseband and also prevent any new
727 * frames from getting started.
728 */
Sujithcbe61d82009-02-09 13:27:12 +0530729bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
Sujithf1dc5602008-10-29 10:16:30 +0530730{
731 u32 reg;
732
733 if (set) {
734 REG_SET_BIT(ah, AR_DIAG_SW,
735 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
736
Sujith0caa7b12009-02-16 13:23:20 +0530737 if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
738 0, AH_WAIT_TIMEOUT)) {
Sujithf1dc5602008-10-29 10:16:30 +0530739 REG_CLR_BIT(ah, AR_DIAG_SW,
740 (AR_DIAG_RX_DIS |
741 AR_DIAG_RX_ABORT));
742
743 reg = REG_READ(ah, AR_OBS_BUS_1);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700744 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
745 "RX failed to go idle in 10 ms RXSM=0x%x\n",
746 reg);
Sujithf1dc5602008-10-29 10:16:30 +0530747
748 return false;
749 }
750 } else {
751 REG_CLR_BIT(ah, AR_DIAG_SW,
752 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
753 }
754
755 return true;
756}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400757EXPORT_SYMBOL(ath9k_hw_setrxabort);
Sujithf1dc5602008-10-29 10:16:30 +0530758
Sujithcbe61d82009-02-09 13:27:12 +0530759void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
Sujithf1dc5602008-10-29 10:16:30 +0530760{
761 REG_WRITE(ah, AR_RXDP, rxdp);
762}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400763EXPORT_SYMBOL(ath9k_hw_putrxbuf);
Sujithf1dc5602008-10-29 10:16:30 +0530764
Luis R. Rodriguez40346b62010-06-12 00:33:44 -0400765void ath9k_hw_startpcureceive(struct ath_hw *ah, bool is_scanning)
Sujithf1dc5602008-10-29 10:16:30 +0530766{
Sujithf1dc5602008-10-29 10:16:30 +0530767 ath9k_enable_mib_counters(ah);
768
Luis R. Rodriguez40346b62010-06-12 00:33:44 -0400769 ath9k_ani_reset(ah, is_scanning);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530770
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +0530771 REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
Sujithf1dc5602008-10-29 10:16:30 +0530772}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400773EXPORT_SYMBOL(ath9k_hw_startpcureceive);
Sujithf1dc5602008-10-29 10:16:30 +0530774
Sujithcbe61d82009-02-09 13:27:12 +0530775void ath9k_hw_stoppcurecv(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530776{
777 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
778
779 ath9k_hw_disable_mib_counters(ah);
780}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400781EXPORT_SYMBOL(ath9k_hw_stoppcurecv);
Sujithf1dc5602008-10-29 10:16:30 +0530782
Vasanthakumar Thiagarajan9b9cc612010-04-15 17:39:41 -0400783void ath9k_hw_abortpcurecv(struct ath_hw *ah)
784{
785 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_ABORT | AR_DIAG_RX_DIS);
786
787 ath9k_hw_disable_mib_counters(ah);
788}
789EXPORT_SYMBOL(ath9k_hw_abortpcurecv);
790
Sujithcbe61d82009-02-09 13:27:12 +0530791bool ath9k_hw_stopdmarecv(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530792{
Sujith0caa7b12009-02-16 13:23:20 +0530793#define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
794#define AH_RX_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700795 struct ath_common *common = ath9k_hw_common(ah);
Sujith0caa7b12009-02-16 13:23:20 +0530796 int i;
797
Sujithf1dc5602008-10-29 10:16:30 +0530798 REG_WRITE(ah, AR_CR, AR_CR_RXD);
799
Sujith0caa7b12009-02-16 13:23:20 +0530800 /* Wait for rx enable bit to go low */
801 for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
802 if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
803 break;
804 udelay(AH_TIME_QUANTUM);
805 }
806
807 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700808 ath_print(common, ATH_DBG_FATAL,
809 "DMA failed to stop in %d ms "
810 "AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
811 AH_RX_STOP_DMA_TIMEOUT / 1000,
812 REG_READ(ah, AR_CR),
813 REG_READ(ah, AR_DIAG_SW));
Sujithf1dc5602008-10-29 10:16:30 +0530814 return false;
815 } else {
816 return true;
817 }
Sujith0caa7b12009-02-16 13:23:20 +0530818
819#undef AH_RX_TIME_QUANTUM
820#undef AH_RX_STOP_DMA_TIMEOUT
Sujithf1dc5602008-10-29 10:16:30 +0530821}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400822EXPORT_SYMBOL(ath9k_hw_stopdmarecv);
Luis R. Rodriguez536b3a72009-10-06 21:19:11 -0400823
824int ath9k_hw_beaconq_setup(struct ath_hw *ah)
825{
826 struct ath9k_tx_queue_info qi;
827
828 memset(&qi, 0, sizeof(qi));
829 qi.tqi_aifs = 1;
830 qi.tqi_cwmin = 0;
831 qi.tqi_cwmax = 0;
832 /* NB: don't enable any interrupts */
833 return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
834}
835EXPORT_SYMBOL(ath9k_hw_beaconq_setup);
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400836
837bool ath9k_hw_intrpend(struct ath_hw *ah)
838{
839 u32 host_isr;
840
841 if (AR_SREV_9100(ah))
842 return true;
843
844 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
845 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
846 return true;
847
848 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
849 if ((host_isr & AR_INTR_SYNC_DEFAULT)
850 && (host_isr != AR_INTR_SPURIOUS))
851 return true;
852
853 return false;
854}
855EXPORT_SYMBOL(ath9k_hw_intrpend);
856
857enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah,
858 enum ath9k_int ints)
859{
860 enum ath9k_int omask = ah->imask;
861 u32 mask, mask2;
862 struct ath9k_hw_capabilities *pCap = &ah->caps;
863 struct ath_common *common = ath9k_hw_common(ah);
864
865 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
866
867 if (omask & ATH9K_INT_GLOBAL) {
868 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
869 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
870 (void) REG_READ(ah, AR_IER);
871 if (!AR_SREV_9100(ah)) {
872 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
873 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
874
875 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
876 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
877 }
878 }
879
880 /* TODO: global int Ref count */
881 mask = ints & ATH9K_INT_COMMON;
882 mask2 = 0;
883
884 if (ints & ATH9K_INT_TX) {
885 if (ah->config.tx_intr_mitigation)
886 mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM;
Luis R. Rodriguez5bea4002010-04-26 15:04:41 -0400887 else {
888 if (ah->txok_interrupt_mask)
889 mask |= AR_IMR_TXOK;
890 if (ah->txdesc_interrupt_mask)
891 mask |= AR_IMR_TXDESC;
892 }
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400893 if (ah->txerr_interrupt_mask)
894 mask |= AR_IMR_TXERR;
895 if (ah->txeol_interrupt_mask)
896 mask |= AR_IMR_TXEOL;
897 }
898 if (ints & ATH9K_INT_RX) {
899 if (AR_SREV_9300_20_OR_LATER(ah)) {
900 mask |= AR_IMR_RXERR | AR_IMR_RXOK_HP;
901 if (ah->config.rx_intr_mitigation) {
902 mask &= ~AR_IMR_RXOK_LP;
903 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
904 } else {
905 mask |= AR_IMR_RXOK_LP;
906 }
907 } else {
908 if (ah->config.rx_intr_mitigation)
909 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
910 else
911 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
912 }
913 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
914 mask |= AR_IMR_GENTMR;
915 }
916
917 if (ints & (ATH9K_INT_BMISC)) {
918 mask |= AR_IMR_BCNMISC;
919 if (ints & ATH9K_INT_TIM)
920 mask2 |= AR_IMR_S2_TIM;
921 if (ints & ATH9K_INT_DTIM)
922 mask2 |= AR_IMR_S2_DTIM;
923 if (ints & ATH9K_INT_DTIMSYNC)
924 mask2 |= AR_IMR_S2_DTIMSYNC;
925 if (ints & ATH9K_INT_CABEND)
926 mask2 |= AR_IMR_S2_CABEND;
927 if (ints & ATH9K_INT_TSFOOR)
928 mask2 |= AR_IMR_S2_TSFOOR;
929 }
930
931 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
932 mask |= AR_IMR_BCNMISC;
933 if (ints & ATH9K_INT_GTT)
934 mask2 |= AR_IMR_S2_GTT;
935 if (ints & ATH9K_INT_CST)
936 mask2 |= AR_IMR_S2_CST;
937 }
938
939 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
940 REG_WRITE(ah, AR_IMR, mask);
941 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
942 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
943 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
944 ah->imrs2_reg |= mask2;
945 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
946
947 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
948 if (ints & ATH9K_INT_TIM_TIMER)
949 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
950 else
951 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
952 }
953
954 if (ints & ATH9K_INT_GLOBAL) {
955 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
956 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
957 if (!AR_SREV_9100(ah)) {
958 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
959 AR_INTR_MAC_IRQ);
960 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
961
962
963 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
964 AR_INTR_SYNC_DEFAULT);
965 REG_WRITE(ah, AR_INTR_SYNC_MASK,
966 AR_INTR_SYNC_DEFAULT);
967 }
968 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
969 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
970 }
971
972 return omask;
973}
974EXPORT_SYMBOL(ath9k_hw_set_interrupts);