blob: 4a36ec53f7320ccde9df38d698a499ca85e3ca09 [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 Thiagarajancee1f622010-04-15 17:38:26 -0400186void ar9002_hw_attach_mac_ops(struct ath_hw *ah)
187{
188 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
189
190 ops->rx_enable = ar9002_hw_rx_enable;
Vasanthakumar Thiagarajan87d5efb2010-04-15 17:38:43 -0400191 ops->set_desc_link = ar9002_hw_set_desc_link;
192 ops->get_desc_link = ar9002_hw_get_desc_link;
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400193 ops->get_isr = ar9002_hw_get_isr;
Vasanthakumar Thiagarajancee1f622010-04-15 17:38:26 -0400194}
Vasanthakumar Thiagarajan87d5efb2010-04-15 17:38:43 -0400195
Sujithcbe61d82009-02-09 13:27:12 +0530196static void ath9k_hw_set_txq_interrupts(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530197 struct ath9k_tx_queue_info *qi)
198{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700199 ath_print(ath9k_hw_common(ah), ATH_DBG_INTERRUPT,
200 "tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
201 ah->txok_interrupt_mask, ah->txerr_interrupt_mask,
202 ah->txdesc_interrupt_mask, ah->txeol_interrupt_mask,
203 ah->txurn_interrupt_mask);
Sujithf1dc5602008-10-29 10:16:30 +0530204
205 REG_WRITE(ah, AR_IMR_S0,
Sujith2660b812009-02-09 13:27:26 +0530206 SM(ah->txok_interrupt_mask, AR_IMR_S0_QCU_TXOK)
207 | SM(ah->txdesc_interrupt_mask, AR_IMR_S0_QCU_TXDESC));
Sujithf1dc5602008-10-29 10:16:30 +0530208 REG_WRITE(ah, AR_IMR_S1,
Sujith2660b812009-02-09 13:27:26 +0530209 SM(ah->txerr_interrupt_mask, AR_IMR_S1_QCU_TXERR)
210 | SM(ah->txeol_interrupt_mask, AR_IMR_S1_QCU_TXEOL));
Pavel Roskin74bad5c2010-02-23 18:15:27 -0500211
212 ah->imrs2_reg &= ~AR_IMR_S2_QCU_TXURN;
213 ah->imrs2_reg |= (ah->txurn_interrupt_mask & AR_IMR_S2_QCU_TXURN);
214 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +0530215}
216
Sujithcbe61d82009-02-09 13:27:12 +0530217u32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530218{
219 return REG_READ(ah, AR_QTXDP(q));
220}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400221EXPORT_SYMBOL(ath9k_hw_gettxbuf);
Sujithf1dc5602008-10-29 10:16:30 +0530222
Sujith54e4cec2009-08-07 09:45:09 +0530223void ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp)
Sujithf1dc5602008-10-29 10:16:30 +0530224{
225 REG_WRITE(ah, AR_QTXDP(q), txdp);
Sujithf1dc5602008-10-29 10:16:30 +0530226}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400227EXPORT_SYMBOL(ath9k_hw_puttxbuf);
Sujithf1dc5602008-10-29 10:16:30 +0530228
Sujith54e4cec2009-08-07 09:45:09 +0530229void ath9k_hw_txstart(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530230{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700231 ath_print(ath9k_hw_common(ah), ATH_DBG_QUEUE,
232 "Enable TXE on queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530233 REG_WRITE(ah, AR_Q_TXE, 1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530234}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400235EXPORT_SYMBOL(ath9k_hw_txstart);
Sujithf1dc5602008-10-29 10:16:30 +0530236
Sujithcbe61d82009-02-09 13:27:12 +0530237u32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530238{
239 u32 npend;
240
241 npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
242 if (npend == 0) {
243
244 if (REG_READ(ah, AR_Q_TXE) & (1 << q))
245 npend = 1;
246 }
247
248 return npend;
249}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400250EXPORT_SYMBOL(ath9k_hw_numtxpending);
Sujithf1dc5602008-10-29 10:16:30 +0530251
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500252/**
253 * ath9k_hw_updatetxtriglevel - adjusts the frame trigger level
254 *
255 * @ah: atheros hardware struct
256 * @bIncTrigLevel: whether or not the frame trigger level should be updated
257 *
258 * The frame trigger level specifies the minimum number of bytes,
259 * in units of 64 bytes, that must be DMA'ed into the PCU TX FIFO
260 * before the PCU will initiate sending the frame on the air. This can
261 * mean we initiate transmit before a full frame is on the PCU TX FIFO.
262 * Resets to 0x1 (meaning 64 bytes or a full frame, whichever occurs
263 * first)
264 *
265 * Caution must be taken to ensure to set the frame trigger level based
266 * on the DMA request size. For example if the DMA request size is set to
267 * 128 bytes the trigger level cannot exceed 6 * 64 = 384. This is because
268 * there need to be enough space in the tx FIFO for the requested transfer
269 * size. Hence the tx FIFO will stop with 512 - 128 = 384 bytes. If we set
270 * the threshold to a value beyond 6, then the transmit will hang.
271 *
272 * Current dual stream devices have a PCU TX FIFO size of 8 KB.
273 * Current single stream devices have a PCU TX FIFO size of 4 KB, however,
274 * there is a hardware issue which forces us to use 2 KB instead so the
275 * frame trigger level must not exceed 2 KB for these chipsets.
276 */
Sujithcbe61d82009-02-09 13:27:12 +0530277bool ath9k_hw_updatetxtriglevel(struct ath_hw *ah, bool bIncTrigLevel)
Sujithf1dc5602008-10-29 10:16:30 +0530278{
Sujithf1dc5602008-10-29 10:16:30 +0530279 u32 txcfg, curLevel, newLevel;
280 enum ath9k_int omask;
281
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500282 if (ah->tx_trig_level >= ah->config.max_txtrig_level)
Sujithf1dc5602008-10-29 10:16:30 +0530283 return false;
284
Pavel Roskin152d5302010-03-31 18:05:37 -0400285 omask = ath9k_hw_set_interrupts(ah, ah->imask & ~ATH9K_INT_GLOBAL);
Sujithf1dc5602008-10-29 10:16:30 +0530286
287 txcfg = REG_READ(ah, AR_TXCFG);
288 curLevel = MS(txcfg, AR_FTRIG);
289 newLevel = curLevel;
290 if (bIncTrigLevel) {
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500291 if (curLevel < ah->config.max_txtrig_level)
Sujithf1dc5602008-10-29 10:16:30 +0530292 newLevel++;
293 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
294 newLevel--;
295 if (newLevel != curLevel)
296 REG_WRITE(ah, AR_TXCFG,
297 (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
298
299 ath9k_hw_set_interrupts(ah, omask);
300
Sujith2660b812009-02-09 13:27:26 +0530301 ah->tx_trig_level = newLevel;
Sujithf1dc5602008-10-29 10:16:30 +0530302
303 return newLevel != curLevel;
304}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400305EXPORT_SYMBOL(ath9k_hw_updatetxtriglevel);
Sujithf1dc5602008-10-29 10:16:30 +0530306
Sujithcbe61d82009-02-09 13:27:12 +0530307bool ath9k_hw_stoptxdma(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530308{
Sujith94ff91d2009-01-27 15:06:38 +0530309#define ATH9K_TX_STOP_DMA_TIMEOUT 4000 /* usec */
310#define ATH9K_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700311 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530312 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujith94ff91d2009-01-27 15:06:38 +0530313 struct ath9k_tx_queue_info *qi;
Sujithf1dc5602008-10-29 10:16:30 +0530314 u32 tsfLow, j, wait;
Sujith94ff91d2009-01-27 15:06:38 +0530315 u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
316
317 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700318 ath_print(common, ATH_DBG_QUEUE, "Stopping TX DMA, "
319 "invalid queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530320 return false;
321 }
322
Sujith2660b812009-02-09 13:27:26 +0530323 qi = &ah->txq[q];
Sujith94ff91d2009-01-27 15:06:38 +0530324 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700325 ath_print(common, ATH_DBG_QUEUE, "Stopping TX DMA, "
326 "inactive queue: %u\n", q);
Sujith94ff91d2009-01-27 15:06:38 +0530327 return false;
328 }
Sujithf1dc5602008-10-29 10:16:30 +0530329
330 REG_WRITE(ah, AR_Q_TXD, 1 << q);
331
Sujith94ff91d2009-01-27 15:06:38 +0530332 for (wait = wait_time; wait != 0; wait--) {
Sujithf1dc5602008-10-29 10:16:30 +0530333 if (ath9k_hw_numtxpending(ah, q) == 0)
334 break;
Sujith94ff91d2009-01-27 15:06:38 +0530335 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530336 }
337
338 if (ath9k_hw_numtxpending(ah, q)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700339 ath_print(common, ATH_DBG_QUEUE,
340 "%s: Num of pending TX Frames %d on Q %d\n",
341 __func__, ath9k_hw_numtxpending(ah, q), q);
Sujithf1dc5602008-10-29 10:16:30 +0530342
343 for (j = 0; j < 2; j++) {
344 tsfLow = REG_READ(ah, AR_TSF_L32);
345 REG_WRITE(ah, AR_QUIET2,
346 SM(10, AR_QUIET2_QUIET_DUR));
347 REG_WRITE(ah, AR_QUIET_PERIOD, 100);
348 REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
349 REG_SET_BIT(ah, AR_TIMER_MODE,
350 AR_QUIET_TIMER_EN);
351
352 if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10))
353 break;
354
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700355 ath_print(common, ATH_DBG_QUEUE,
356 "TSF has moved while trying to set "
357 "quiet time TSF: 0x%08x\n", tsfLow);
Sujithf1dc5602008-10-29 10:16:30 +0530358 }
359
360 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
361
362 udelay(200);
363 REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);
364
Sujith94ff91d2009-01-27 15:06:38 +0530365 wait = wait_time;
Sujithf1dc5602008-10-29 10:16:30 +0530366 while (ath9k_hw_numtxpending(ah, q)) {
367 if ((--wait) == 0) {
Sujithe8009e92009-12-14 14:57:08 +0530368 ath_print(common, ATH_DBG_FATAL,
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700369 "Failed to stop TX DMA in 100 "
370 "msec after killing last frame\n");
Sujithf1dc5602008-10-29 10:16:30 +0530371 break;
372 }
Sujith94ff91d2009-01-27 15:06:38 +0530373 udelay(ATH9K_TIME_QUANTUM);
Sujithf1dc5602008-10-29 10:16:30 +0530374 }
375
376 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
377 }
378
379 REG_WRITE(ah, AR_Q_TXD, 0);
Sujithf1dc5602008-10-29 10:16:30 +0530380 return wait != 0;
Sujith94ff91d2009-01-27 15:06:38 +0530381
382#undef ATH9K_TX_STOP_DMA_TIMEOUT
383#undef ATH9K_TIME_QUANTUM
Sujithf1dc5602008-10-29 10:16:30 +0530384}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400385EXPORT_SYMBOL(ath9k_hw_stoptxdma);
Sujithf1dc5602008-10-29 10:16:30 +0530386
Sujith54e4cec2009-08-07 09:45:09 +0530387void ath9k_hw_filltxdesc(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530388 u32 segLen, bool firstSeg,
Vasanthakumar Thiagarajan3f3a1c82010-04-15 17:38:42 -0400389 bool lastSeg, const struct ath_desc *ds0,
390 dma_addr_t buf_addr)
Sujithf1dc5602008-10-29 10:16:30 +0530391{
392 struct ar5416_desc *ads = AR5416DESC(ds);
393
Vasanthakumar Thiagarajan3f3a1c82010-04-15 17:38:42 -0400394 ads->ds_data = buf_addr;
395
Sujithf1dc5602008-10-29 10:16:30 +0530396 if (firstSeg) {
397 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
398 } else if (lastSeg) {
399 ads->ds_ctl0 = 0;
400 ads->ds_ctl1 = segLen;
401 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
402 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
403 } else {
404 ads->ds_ctl0 = 0;
405 ads->ds_ctl1 = segLen | AR_TxMore;
406 ads->ds_ctl2 = 0;
407 ads->ds_ctl3 = 0;
408 }
409 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
410 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
411 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
412 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
413 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530414}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400415EXPORT_SYMBOL(ath9k_hw_filltxdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530416
Sujithcbe61d82009-02-09 13:27:12 +0530417void ath9k_hw_cleartxdesc(struct ath_hw *ah, struct ath_desc *ds)
Sujithf1dc5602008-10-29 10:16:30 +0530418{
419 struct ar5416_desc *ads = AR5416DESC(ds);
420
421 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
422 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
423 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
424 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
425 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
426}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400427EXPORT_SYMBOL(ath9k_hw_cleartxdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530428
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700429int ath9k_hw_txprocdesc(struct ath_hw *ah, struct ath_desc *ds,
430 struct ath_tx_status *ts)
Sujithf1dc5602008-10-29 10:16:30 +0530431{
432 struct ar5416_desc *ads = AR5416DESC(ds);
433
434 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
435 return -EINPROGRESS;
436
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700437 ts->ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
438 ts->ts_tstamp = ads->AR_SendTimestamp;
439 ts->ts_status = 0;
440 ts->ts_flags = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530441
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -0500442 if (ads->ds_txstatus1 & AR_FrmXmitOK)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700443 ts->ts_status |= ATH9K_TX_ACKED;
Sujithf1dc5602008-10-29 10:16:30 +0530444 if (ads->ds_txstatus1 & AR_ExcessiveRetries)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700445 ts->ts_status |= ATH9K_TXERR_XRETRY;
Sujithf1dc5602008-10-29 10:16:30 +0530446 if (ads->ds_txstatus1 & AR_Filtered)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700447 ts->ts_status |= ATH9K_TXERR_FILT;
Sujithdaa9deb2008-11-18 09:10:22 +0530448 if (ads->ds_txstatus1 & AR_FIFOUnderrun) {
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700449 ts->ts_status |= ATH9K_TXERR_FIFO;
Sujithdaa9deb2008-11-18 09:10:22 +0530450 ath9k_hw_updatetxtriglevel(ah, true);
451 }
Sujithf1dc5602008-10-29 10:16:30 +0530452 if (ads->ds_txstatus9 & AR_TxOpExceeded)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700453 ts->ts_status |= ATH9K_TXERR_XTXOP;
Sujithf1dc5602008-10-29 10:16:30 +0530454 if (ads->ds_txstatus1 & AR_TxTimerExpired)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700455 ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
Sujithf1dc5602008-10-29 10:16:30 +0530456
457 if (ads->ds_txstatus1 & AR_DescCfgErr)
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700458 ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
Sujithf1dc5602008-10-29 10:16:30 +0530459 if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700460 ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
Sujithf1dc5602008-10-29 10:16:30 +0530461 ath9k_hw_updatetxtriglevel(ah, true);
462 }
463 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700464 ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
Sujithf1dc5602008-10-29 10:16:30 +0530465 ath9k_hw_updatetxtriglevel(ah, true);
466 }
467 if (ads->ds_txstatus0 & AR_TxBaStatus) {
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700468 ts->ts_flags |= ATH9K_TX_BA;
469 ts->ba_low = ads->AR_BaBitmapLow;
470 ts->ba_high = ads->AR_BaBitmapHigh;
Sujithf1dc5602008-10-29 10:16:30 +0530471 }
472
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700473 ts->ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
474 switch (ts->ts_rateindex) {
Sujithf1dc5602008-10-29 10:16:30 +0530475 case 0:
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700476 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
Sujithf1dc5602008-10-29 10:16:30 +0530477 break;
478 case 1:
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700479 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
Sujithf1dc5602008-10-29 10:16:30 +0530480 break;
481 case 2:
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700482 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
Sujithf1dc5602008-10-29 10:16:30 +0530483 break;
484 case 3:
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700485 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
Sujithf1dc5602008-10-29 10:16:30 +0530486 break;
487 }
488
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700489 ts->ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
490 ts->ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
491 ts->ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
492 ts->ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
493 ts->ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
494 ts->ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
495 ts->ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
496 ts->evm0 = ads->AR_TxEVM0;
497 ts->evm1 = ads->AR_TxEVM1;
498 ts->evm2 = ads->AR_TxEVM2;
499 ts->ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
500 ts->ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
501 ts->ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
502 ts->ts_antenna = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530503
504 return 0;
505}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400506EXPORT_SYMBOL(ath9k_hw_txprocdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530507
Sujithcbe61d82009-02-09 13:27:12 +0530508void ath9k_hw_set11n_txdesc(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530509 u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
510 u32 keyIx, enum ath9k_key_type keyType, u32 flags)
511{
512 struct ar5416_desc *ads = AR5416DESC(ds);
Sujithf1dc5602008-10-29 10:16:30 +0530513
Sujith2660b812009-02-09 13:27:26 +0530514 txPower += ah->txpower_indexoffset;
Sujithf1dc5602008-10-29 10:16:30 +0530515 if (txPower > 63)
516 txPower = 63;
517
518 ads->ds_ctl0 = (pktLen & AR_FrameLen)
519 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
520 | SM(txPower, AR_XmitPower)
521 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
522 | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
523 | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
524 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
525
526 ads->ds_ctl1 =
527 (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
528 | SM(type, AR_FrameType)
529 | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
530 | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
531 | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
532
533 ads->ds_ctl6 = SM(keyType, AR_EncrType);
534
Sujithe492d7c2010-03-17 14:25:17 +0530535 if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +0530536 ads->ds_ctl8 = 0;
537 ads->ds_ctl9 = 0;
538 ads->ds_ctl10 = 0;
539 ads->ds_ctl11 = 0;
540 }
541}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400542EXPORT_SYMBOL(ath9k_hw_set11n_txdesc);
Sujithf1dc5602008-10-29 10:16:30 +0530543
Sujithcbe61d82009-02-09 13:27:12 +0530544void ath9k_hw_set11n_ratescenario(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530545 struct ath_desc *lastds,
546 u32 durUpdateEn, u32 rtsctsRate,
547 u32 rtsctsDuration,
548 struct ath9k_11n_rate_series series[],
549 u32 nseries, u32 flags)
550{
551 struct ar5416_desc *ads = AR5416DESC(ds);
552 struct ar5416_desc *last_ads = AR5416DESC(lastds);
553 u32 ds_ctl0;
554
Sujithf1dc5602008-10-29 10:16:30 +0530555 if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
556 ds_ctl0 = ads->ds_ctl0;
557
558 if (flags & ATH9K_TXDESC_RTSENA) {
559 ds_ctl0 &= ~AR_CTSEnable;
560 ds_ctl0 |= AR_RTSEnable;
561 } else {
562 ds_ctl0 &= ~AR_RTSEnable;
563 ds_ctl0 |= AR_CTSEnable;
564 }
565
566 ads->ds_ctl0 = ds_ctl0;
567 } else {
568 ads->ds_ctl0 =
569 (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
570 }
571
572 ads->ds_ctl2 = set11nTries(series, 0)
573 | set11nTries(series, 1)
574 | set11nTries(series, 2)
575 | set11nTries(series, 3)
576 | (durUpdateEn ? AR_DurUpdateEna : 0)
577 | SM(0, AR_BurstDur);
578
579 ads->ds_ctl3 = set11nRate(series, 0)
580 | set11nRate(series, 1)
581 | set11nRate(series, 2)
582 | set11nRate(series, 3);
583
584 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
585 | set11nPktDurRTSCTS(series, 1);
586
587 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
588 | set11nPktDurRTSCTS(series, 3);
589
590 ads->ds_ctl7 = set11nRateFlags(series, 0)
591 | set11nRateFlags(series, 1)
592 | set11nRateFlags(series, 2)
593 | set11nRateFlags(series, 3)
594 | SM(rtsctsRate, AR_RTSCTSRate);
595 last_ads->ds_ctl2 = ads->ds_ctl2;
596 last_ads->ds_ctl3 = ads->ds_ctl3;
597}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400598EXPORT_SYMBOL(ath9k_hw_set11n_ratescenario);
Sujithf1dc5602008-10-29 10:16:30 +0530599
Sujithcbe61d82009-02-09 13:27:12 +0530600void ath9k_hw_set11n_aggr_first(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530601 u32 aggrLen)
602{
603 struct ar5416_desc *ads = AR5416DESC(ds);
604
605 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
606 ads->ds_ctl6 &= ~AR_AggrLen;
607 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
608}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400609EXPORT_SYMBOL(ath9k_hw_set11n_aggr_first);
Sujithf1dc5602008-10-29 10:16:30 +0530610
Sujithcbe61d82009-02-09 13:27:12 +0530611void ath9k_hw_set11n_aggr_middle(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530612 u32 numDelims)
613{
614 struct ar5416_desc *ads = AR5416DESC(ds);
615 unsigned int ctl6;
616
617 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
618
619 ctl6 = ads->ds_ctl6;
620 ctl6 &= ~AR_PadDelim;
621 ctl6 |= SM(numDelims, AR_PadDelim);
622 ads->ds_ctl6 = ctl6;
623}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400624EXPORT_SYMBOL(ath9k_hw_set11n_aggr_middle);
Sujithf1dc5602008-10-29 10:16:30 +0530625
Sujithcbe61d82009-02-09 13:27:12 +0530626void ath9k_hw_set11n_aggr_last(struct ath_hw *ah, struct ath_desc *ds)
Sujithf1dc5602008-10-29 10:16:30 +0530627{
628 struct ar5416_desc *ads = AR5416DESC(ds);
629
630 ads->ds_ctl1 |= AR_IsAggr;
631 ads->ds_ctl1 &= ~AR_MoreAggr;
632 ads->ds_ctl6 &= ~AR_PadDelim;
633}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400634EXPORT_SYMBOL(ath9k_hw_set11n_aggr_last);
Sujithf1dc5602008-10-29 10:16:30 +0530635
Sujithcbe61d82009-02-09 13:27:12 +0530636void ath9k_hw_clr11n_aggr(struct ath_hw *ah, struct ath_desc *ds)
Sujithf1dc5602008-10-29 10:16:30 +0530637{
638 struct ar5416_desc *ads = AR5416DESC(ds);
639
640 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
641}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400642EXPORT_SYMBOL(ath9k_hw_clr11n_aggr);
Sujithf1dc5602008-10-29 10:16:30 +0530643
Sujithcbe61d82009-02-09 13:27:12 +0530644void ath9k_hw_set11n_burstduration(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530645 u32 burstDuration)
646{
647 struct ar5416_desc *ads = AR5416DESC(ds);
648
649 ads->ds_ctl2 &= ~AR_BurstDur;
650 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
651}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400652EXPORT_SYMBOL(ath9k_hw_set11n_burstduration);
Sujithf1dc5602008-10-29 10:16:30 +0530653
Sujithcbe61d82009-02-09 13:27:12 +0530654void ath9k_hw_set11n_virtualmorefrag(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +0530655 u32 vmf)
656{
657 struct ar5416_desc *ads = AR5416DESC(ds);
658
659 if (vmf)
660 ads->ds_ctl0 |= AR_VirtMoreFrag;
661 else
662 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
663}
664
Sujithcbe61d82009-02-09 13:27:12 +0530665void ath9k_hw_gettxintrtxqs(struct ath_hw *ah, u32 *txqs)
Sujithf1dc5602008-10-29 10:16:30 +0530666{
Sujith2660b812009-02-09 13:27:26 +0530667 *txqs &= ah->intr_txqs;
668 ah->intr_txqs &= ~(*txqs);
Sujithf1dc5602008-10-29 10:16:30 +0530669}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400670EXPORT_SYMBOL(ath9k_hw_gettxintrtxqs);
Sujithf1dc5602008-10-29 10:16:30 +0530671
Sujithcbe61d82009-02-09 13:27:12 +0530672bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530673 const struct ath9k_tx_queue_info *qinfo)
674{
675 u32 cw;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700676 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530677 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530678 struct ath9k_tx_queue_info *qi;
679
680 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700681 ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
682 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530683 return false;
684 }
685
Sujith2660b812009-02-09 13:27:26 +0530686 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530687 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700688 ath_print(common, ATH_DBG_QUEUE, "Set TXQ properties, "
689 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530690 return false;
691 }
692
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700693 ath_print(common, ATH_DBG_QUEUE, "Set queue properties for: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530694
695 qi->tqi_ver = qinfo->tqi_ver;
696 qi->tqi_subtype = qinfo->tqi_subtype;
697 qi->tqi_qflags = qinfo->tqi_qflags;
698 qi->tqi_priority = qinfo->tqi_priority;
699 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
700 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
701 else
702 qi->tqi_aifs = INIT_AIFS;
703 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
704 cw = min(qinfo->tqi_cwmin, 1024U);
705 qi->tqi_cwmin = 1;
706 while (qi->tqi_cwmin < cw)
707 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
708 } else
709 qi->tqi_cwmin = qinfo->tqi_cwmin;
710 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
711 cw = min(qinfo->tqi_cwmax, 1024U);
712 qi->tqi_cwmax = 1;
713 while (qi->tqi_cwmax < cw)
714 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
715 } else
716 qi->tqi_cwmax = INIT_CWMAX;
717
718 if (qinfo->tqi_shretry != 0)
719 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
720 else
721 qi->tqi_shretry = INIT_SH_RETRY;
722 if (qinfo->tqi_lgretry != 0)
723 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
724 else
725 qi->tqi_lgretry = INIT_LG_RETRY;
726 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
727 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
728 qi->tqi_burstTime = qinfo->tqi_burstTime;
729 qi->tqi_readyTime = qinfo->tqi_readyTime;
730
731 switch (qinfo->tqi_subtype) {
732 case ATH9K_WME_UPSD:
733 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
734 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
735 break;
736 default:
737 break;
738 }
739
740 return true;
741}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400742EXPORT_SYMBOL(ath9k_hw_set_txq_props);
Sujithf1dc5602008-10-29 10:16:30 +0530743
Sujithcbe61d82009-02-09 13:27:12 +0530744bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
Sujithf1dc5602008-10-29 10:16:30 +0530745 struct ath9k_tx_queue_info *qinfo)
746{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700747 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530748 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530749 struct ath9k_tx_queue_info *qi;
750
751 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700752 ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
753 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530754 return false;
755 }
756
Sujith2660b812009-02-09 13:27:26 +0530757 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530758 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700759 ath_print(common, ATH_DBG_QUEUE, "Get TXQ properties, "
760 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530761 return false;
762 }
763
764 qinfo->tqi_qflags = qi->tqi_qflags;
765 qinfo->tqi_ver = qi->tqi_ver;
766 qinfo->tqi_subtype = qi->tqi_subtype;
767 qinfo->tqi_qflags = qi->tqi_qflags;
768 qinfo->tqi_priority = qi->tqi_priority;
769 qinfo->tqi_aifs = qi->tqi_aifs;
770 qinfo->tqi_cwmin = qi->tqi_cwmin;
771 qinfo->tqi_cwmax = qi->tqi_cwmax;
772 qinfo->tqi_shretry = qi->tqi_shretry;
773 qinfo->tqi_lgretry = qi->tqi_lgretry;
774 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
775 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
776 qinfo->tqi_burstTime = qi->tqi_burstTime;
777 qinfo->tqi_readyTime = qi->tqi_readyTime;
778
779 return true;
780}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400781EXPORT_SYMBOL(ath9k_hw_get_txq_props);
Sujithf1dc5602008-10-29 10:16:30 +0530782
Sujithcbe61d82009-02-09 13:27:12 +0530783int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
Sujithf1dc5602008-10-29 10:16:30 +0530784 const struct ath9k_tx_queue_info *qinfo)
785{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700786 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530787 struct ath9k_tx_queue_info *qi;
Sujith2660b812009-02-09 13:27:26 +0530788 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530789 int q;
790
791 switch (type) {
792 case ATH9K_TX_QUEUE_BEACON:
793 q = pCap->total_queues - 1;
794 break;
795 case ATH9K_TX_QUEUE_CAB:
796 q = pCap->total_queues - 2;
797 break;
798 case ATH9K_TX_QUEUE_PSPOLL:
799 q = 1;
800 break;
801 case ATH9K_TX_QUEUE_UAPSD:
802 q = pCap->total_queues - 3;
803 break;
804 case ATH9K_TX_QUEUE_DATA:
805 for (q = 0; q < pCap->total_queues; q++)
Sujith2660b812009-02-09 13:27:26 +0530806 if (ah->txq[q].tqi_type ==
Sujithf1dc5602008-10-29 10:16:30 +0530807 ATH9K_TX_QUEUE_INACTIVE)
808 break;
809 if (q == pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700810 ath_print(common, ATH_DBG_FATAL,
811 "No available TX queue\n");
Sujithf1dc5602008-10-29 10:16:30 +0530812 return -1;
813 }
814 break;
815 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700816 ath_print(common, ATH_DBG_FATAL,
817 "Invalid TX queue type: %u\n", type);
Sujithf1dc5602008-10-29 10:16:30 +0530818 return -1;
819 }
820
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700821 ath_print(common, ATH_DBG_QUEUE, "Setup TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530822
Sujith2660b812009-02-09 13:27:26 +0530823 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530824 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700825 ath_print(common, ATH_DBG_FATAL,
826 "TX queue: %u already active\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530827 return -1;
828 }
829 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
830 qi->tqi_type = type;
831 if (qinfo == NULL) {
832 qi->tqi_qflags =
833 TXQ_FLAG_TXOKINT_ENABLE
834 | TXQ_FLAG_TXERRINT_ENABLE
835 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
836 qi->tqi_aifs = INIT_AIFS;
837 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
838 qi->tqi_cwmax = INIT_CWMAX;
839 qi->tqi_shretry = INIT_SH_RETRY;
840 qi->tqi_lgretry = INIT_LG_RETRY;
841 qi->tqi_physCompBuf = 0;
842 } else {
843 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
844 (void) ath9k_hw_set_txq_props(ah, q, qinfo);
845 }
846
847 return q;
848}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400849EXPORT_SYMBOL(ath9k_hw_setuptxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530850
Sujithcbe61d82009-02-09 13:27:12 +0530851bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530852{
Sujith2660b812009-02-09 13:27:26 +0530853 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700854 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530855 struct ath9k_tx_queue_info *qi;
856
857 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700858 ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
859 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530860 return false;
861 }
Sujith2660b812009-02-09 13:27:26 +0530862 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530863 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700864 ath_print(common, ATH_DBG_QUEUE, "Release TXQ, "
865 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530866 return false;
867 }
868
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700869 ath_print(common, ATH_DBG_QUEUE, "Release TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530870
871 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
Sujith2660b812009-02-09 13:27:26 +0530872 ah->txok_interrupt_mask &= ~(1 << q);
873 ah->txerr_interrupt_mask &= ~(1 << q);
874 ah->txdesc_interrupt_mask &= ~(1 << q);
875 ah->txeol_interrupt_mask &= ~(1 << q);
876 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +0530877 ath9k_hw_set_txq_interrupts(ah, qi);
878
879 return true;
880}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400881EXPORT_SYMBOL(ath9k_hw_releasetxqueue);
Sujithf1dc5602008-10-29 10:16:30 +0530882
Sujithcbe61d82009-02-09 13:27:12 +0530883bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
Sujithf1dc5602008-10-29 10:16:30 +0530884{
Sujith2660b812009-02-09 13:27:26 +0530885 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700886 struct ath_common *common = ath9k_hw_common(ah);
Sujith2660b812009-02-09 13:27:26 +0530887 struct ath9k_channel *chan = ah->curchan;
Sujithf1dc5602008-10-29 10:16:30 +0530888 struct ath9k_tx_queue_info *qi;
889 u32 cwMin, chanCwMin, value;
890
891 if (q >= pCap->total_queues) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700892 ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
893 "invalid queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530894 return false;
895 }
896
Sujith2660b812009-02-09 13:27:26 +0530897 qi = &ah->txq[q];
Sujithf1dc5602008-10-29 10:16:30 +0530898 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700899 ath_print(common, ATH_DBG_QUEUE, "Reset TXQ, "
900 "inactive queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530901 return true;
902 }
903
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700904 ath_print(common, ATH_DBG_QUEUE, "Reset TX queue: %u\n", q);
Sujithf1dc5602008-10-29 10:16:30 +0530905
906 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
907 if (chan && IS_CHAN_B(chan))
908 chanCwMin = INIT_CWMIN_11B;
909 else
910 chanCwMin = INIT_CWMIN;
911
912 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
913 } else
914 cwMin = qi->tqi_cwmin;
915
916 REG_WRITE(ah, AR_DLCL_IFS(q),
917 SM(cwMin, AR_D_LCL_IFS_CWMIN) |
918 SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
919 SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
920
921 REG_WRITE(ah, AR_DRETRY_LIMIT(q),
922 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
923 SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
924 SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
925
926 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
927 REG_WRITE(ah, AR_DMISC(q),
928 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
929
930 if (qi->tqi_cbrPeriod) {
931 REG_WRITE(ah, AR_QCBRCFG(q),
932 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
933 SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
934 REG_WRITE(ah, AR_QMISC(q),
935 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
936 (qi->tqi_cbrOverflowLimit ?
937 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
938 }
939 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
940 REG_WRITE(ah, AR_QRDYTIMECFG(q),
941 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
942 AR_Q_RDYTIMECFG_EN);
943 }
944
945 REG_WRITE(ah, AR_DCHNTIME(q),
946 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
947 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
948
949 if (qi->tqi_burstTime
950 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
951 REG_WRITE(ah, AR_QMISC(q),
952 REG_READ(ah, AR_QMISC(q)) |
953 AR_Q_MISC_RDYTIME_EXP_POLICY);
954
955 }
956
957 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
958 REG_WRITE(ah, AR_DMISC(q),
959 REG_READ(ah, AR_DMISC(q)) |
960 AR_D_MISC_POST_FR_BKOFF_DIS);
961 }
962 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
963 REG_WRITE(ah, AR_DMISC(q),
964 REG_READ(ah, AR_DMISC(q)) |
965 AR_D_MISC_FRAG_BKOFF_EN);
966 }
967 switch (qi->tqi_type) {
968 case ATH9K_TX_QUEUE_BEACON:
969 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
970 | AR_Q_MISC_FSP_DBA_GATED
971 | AR_Q_MISC_BEACON_USE
972 | AR_Q_MISC_CBR_INCR_DIS1);
973
974 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
975 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
976 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
977 | AR_D_MISC_BEACON_USE
978 | AR_D_MISC_POST_FR_BKOFF_DIS);
979 break;
980 case ATH9K_TX_QUEUE_CAB:
981 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
982 | AR_Q_MISC_FSP_DBA_GATED
983 | AR_Q_MISC_CBR_INCR_DIS1
984 | AR_Q_MISC_CBR_INCR_DIS0);
985 value = (qi->tqi_readyTime -
Sujith2660b812009-02-09 13:27:26 +0530986 (ah->config.sw_beacon_response_time -
987 ah->config.dma_beacon_response_time) -
988 ah->config.additional_swba_backoff) * 1024;
Sujithf1dc5602008-10-29 10:16:30 +0530989 REG_WRITE(ah, AR_QRDYTIMECFG(q),
990 value | AR_Q_RDYTIMECFG_EN);
991 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
992 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
993 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
994 break;
995 case ATH9K_TX_QUEUE_PSPOLL:
996 REG_WRITE(ah, AR_QMISC(q),
997 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
998 break;
999 case ATH9K_TX_QUEUE_UAPSD:
1000 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
1001 AR_D_MISC_POST_FR_BKOFF_DIS);
1002 break;
1003 default:
1004 break;
1005 }
1006
1007 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
1008 REG_WRITE(ah, AR_DMISC(q),
1009 REG_READ(ah, AR_DMISC(q)) |
1010 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
1011 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
1012 AR_D_MISC_POST_FR_BKOFF_DIS);
1013 }
1014
1015 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +05301016 ah->txok_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +05301017 else
Sujith2660b812009-02-09 13:27:26 +05301018 ah->txok_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +05301019 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +05301020 ah->txerr_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +05301021 else
Sujith2660b812009-02-09 13:27:26 +05301022 ah->txerr_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +05301023 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +05301024 ah->txdesc_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +05301025 else
Sujith2660b812009-02-09 13:27:26 +05301026 ah->txdesc_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +05301027 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +05301028 ah->txeol_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +05301029 else
Sujith2660b812009-02-09 13:27:26 +05301030 ah->txeol_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +05301031 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
Sujith2660b812009-02-09 13:27:26 +05301032 ah->txurn_interrupt_mask |= 1 << q;
Sujithf1dc5602008-10-29 10:16:30 +05301033 else
Sujith2660b812009-02-09 13:27:26 +05301034 ah->txurn_interrupt_mask &= ~(1 << q);
Sujithf1dc5602008-10-29 10:16:30 +05301035 ath9k_hw_set_txq_interrupts(ah, qi);
1036
1037 return true;
1038}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001039EXPORT_SYMBOL(ath9k_hw_resettxqueue);
Sujithf1dc5602008-10-29 10:16:30 +05301040
Sujithcbe61d82009-02-09 13:27:12 +05301041int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001042 struct ath_rx_status *rs, u64 tsf)
Sujithf1dc5602008-10-29 10:16:30 +05301043{
1044 struct ar5416_desc ads;
1045 struct ar5416_desc *adsp = AR5416DESC(ds);
1046 u32 phyerr;
1047
1048 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
1049 return -EINPROGRESS;
1050
1051 ads.u.rx = adsp->u.rx;
1052
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001053 rs->rs_status = 0;
1054 rs->rs_flags = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301055
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001056 rs->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
1057 rs->rs_tstamp = ads.AR_RcvTimestamp;
Sujithf1dc5602008-10-29 10:16:30 +05301058
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001059 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001060 rs->rs_rssi = ATH9K_RSSI_BAD;
1061 rs->rs_rssi_ctl0 = ATH9K_RSSI_BAD;
1062 rs->rs_rssi_ctl1 = ATH9K_RSSI_BAD;
1063 rs->rs_rssi_ctl2 = ATH9K_RSSI_BAD;
1064 rs->rs_rssi_ext0 = ATH9K_RSSI_BAD;
1065 rs->rs_rssi_ext1 = ATH9K_RSSI_BAD;
1066 rs->rs_rssi_ext2 = ATH9K_RSSI_BAD;
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001067 } else {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001068 rs->rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
1069 rs->rs_rssi_ctl0 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001070 AR_RxRSSIAnt00);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001071 rs->rs_rssi_ctl1 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001072 AR_RxRSSIAnt01);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001073 rs->rs_rssi_ctl2 = MS(ads.ds_rxstatus0,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001074 AR_RxRSSIAnt02);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001075 rs->rs_rssi_ext0 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001076 AR_RxRSSIAnt10);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001077 rs->rs_rssi_ext1 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001078 AR_RxRSSIAnt11);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001079 rs->rs_rssi_ext2 = MS(ads.ds_rxstatus4,
Senthil Balasubramaniandd8b15b2009-07-14 20:17:08 -04001080 AR_RxRSSIAnt12);
1081 }
Sujithf1dc5602008-10-29 10:16:30 +05301082 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001083 rs->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
Sujithf1dc5602008-10-29 10:16:30 +05301084 else
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001085 rs->rs_keyix = ATH9K_RXKEYIX_INVALID;
Sujithf1dc5602008-10-29 10:16:30 +05301086
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001087 rs->rs_rate = RXSTATUS_RATE(ah, (&ads));
1088 rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
Sujithf1dc5602008-10-29 10:16:30 +05301089
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001090 rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
1091 rs->rs_moreaggr =
Sujithf1dc5602008-10-29 10:16:30 +05301092 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001093 rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
1094 rs->rs_flags =
Sujithf1dc5602008-10-29 10:16:30 +05301095 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001096 rs->rs_flags |=
Sujithf1dc5602008-10-29 10:16:30 +05301097 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
1098
1099 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001100 rs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
Sujithf1dc5602008-10-29 10:16:30 +05301101 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001102 rs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
Sujithf1dc5602008-10-29 10:16:30 +05301103 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001104 rs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
Sujithf1dc5602008-10-29 10:16:30 +05301105
1106 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
1107 if (ads.ds_rxstatus8 & AR_CRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001108 rs->rs_status |= ATH9K_RXERR_CRC;
Sujithf1dc5602008-10-29 10:16:30 +05301109 else if (ads.ds_rxstatus8 & AR_PHYErr) {
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001110 rs->rs_status |= ATH9K_RXERR_PHY;
Sujithf1dc5602008-10-29 10:16:30 +05301111 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001112 rs->rs_phyerr = phyerr;
Sujithf1dc5602008-10-29 10:16:30 +05301113 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001114 rs->rs_status |= ATH9K_RXERR_DECRYPT;
Sujithf1dc5602008-10-29 10:16:30 +05301115 else if (ads.ds_rxstatus8 & AR_MichaelErr)
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001116 rs->rs_status |= ATH9K_RXERR_MIC;
Sujithf1dc5602008-10-29 10:16:30 +05301117 }
1118
1119 return 0;
1120}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001121EXPORT_SYMBOL(ath9k_hw_rxprocdesc);
Sujithf1dc5602008-10-29 10:16:30 +05301122
Sujith54e4cec2009-08-07 09:45:09 +05301123void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
Sujithf1dc5602008-10-29 10:16:30 +05301124 u32 size, u32 flags)
1125{
1126 struct ar5416_desc *ads = AR5416DESC(ds);
Sujith2660b812009-02-09 13:27:26 +05301127 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +05301128
1129 ads->ds_ctl1 = size & AR_BufLen;
1130 if (flags & ATH9K_RXDESC_INTREQ)
1131 ads->ds_ctl1 |= AR_RxIntrReq;
1132
1133 ads->ds_rxstatus8 &= ~AR_RxDone;
1134 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
1135 memset(&(ads->u), 0, sizeof(ads->u));
Sujithf1dc5602008-10-29 10:16:30 +05301136}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001137EXPORT_SYMBOL(ath9k_hw_setuprxdesc);
Sujithf1dc5602008-10-29 10:16:30 +05301138
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001139/*
1140 * This can stop or re-enables RX.
1141 *
1142 * If bool is set this will kill any frame which is currently being
1143 * transferred between the MAC and baseband and also prevent any new
1144 * frames from getting started.
1145 */
Sujithcbe61d82009-02-09 13:27:12 +05301146bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
Sujithf1dc5602008-10-29 10:16:30 +05301147{
1148 u32 reg;
1149
1150 if (set) {
1151 REG_SET_BIT(ah, AR_DIAG_SW,
1152 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1153
Sujith0caa7b12009-02-16 13:23:20 +05301154 if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
1155 0, AH_WAIT_TIMEOUT)) {
Sujithf1dc5602008-10-29 10:16:30 +05301156 REG_CLR_BIT(ah, AR_DIAG_SW,
1157 (AR_DIAG_RX_DIS |
1158 AR_DIAG_RX_ABORT));
1159
1160 reg = REG_READ(ah, AR_OBS_BUS_1);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001161 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1162 "RX failed to go idle in 10 ms RXSM=0x%x\n",
1163 reg);
Sujithf1dc5602008-10-29 10:16:30 +05301164
1165 return false;
1166 }
1167 } else {
1168 REG_CLR_BIT(ah, AR_DIAG_SW,
1169 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1170 }
1171
1172 return true;
1173}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001174EXPORT_SYMBOL(ath9k_hw_setrxabort);
Sujithf1dc5602008-10-29 10:16:30 +05301175
Sujithcbe61d82009-02-09 13:27:12 +05301176void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
Sujithf1dc5602008-10-29 10:16:30 +05301177{
1178 REG_WRITE(ah, AR_RXDP, rxdp);
1179}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001180EXPORT_SYMBOL(ath9k_hw_putrxbuf);
Sujithf1dc5602008-10-29 10:16:30 +05301181
Sujithcbe61d82009-02-09 13:27:12 +05301182void ath9k_hw_startpcureceive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301183{
Sujithf1dc5602008-10-29 10:16:30 +05301184 ath9k_enable_mib_counters(ah);
1185
1186 ath9k_ani_reset(ah);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301187
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301188 REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
Sujithf1dc5602008-10-29 10:16:30 +05301189}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001190EXPORT_SYMBOL(ath9k_hw_startpcureceive);
Sujithf1dc5602008-10-29 10:16:30 +05301191
Sujithcbe61d82009-02-09 13:27:12 +05301192void ath9k_hw_stoppcurecv(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301193{
1194 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
1195
1196 ath9k_hw_disable_mib_counters(ah);
1197}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001198EXPORT_SYMBOL(ath9k_hw_stoppcurecv);
Sujithf1dc5602008-10-29 10:16:30 +05301199
Sujithcbe61d82009-02-09 13:27:12 +05301200bool ath9k_hw_stopdmarecv(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301201{
Sujith0caa7b12009-02-16 13:23:20 +05301202#define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
1203#define AH_RX_TIME_QUANTUM 100 /* usec */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001204 struct ath_common *common = ath9k_hw_common(ah);
Sujith0caa7b12009-02-16 13:23:20 +05301205 int i;
1206
Sujithf1dc5602008-10-29 10:16:30 +05301207 REG_WRITE(ah, AR_CR, AR_CR_RXD);
1208
Sujith0caa7b12009-02-16 13:23:20 +05301209 /* Wait for rx enable bit to go low */
1210 for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
1211 if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
1212 break;
1213 udelay(AH_TIME_QUANTUM);
1214 }
1215
1216 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001217 ath_print(common, ATH_DBG_FATAL,
1218 "DMA failed to stop in %d ms "
1219 "AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
1220 AH_RX_STOP_DMA_TIMEOUT / 1000,
1221 REG_READ(ah, AR_CR),
1222 REG_READ(ah, AR_DIAG_SW));
Sujithf1dc5602008-10-29 10:16:30 +05301223 return false;
1224 } else {
1225 return true;
1226 }
Sujith0caa7b12009-02-16 13:23:20 +05301227
1228#undef AH_RX_TIME_QUANTUM
1229#undef AH_RX_STOP_DMA_TIMEOUT
Sujithf1dc5602008-10-29 10:16:30 +05301230}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001231EXPORT_SYMBOL(ath9k_hw_stopdmarecv);
Luis R. Rodriguez536b3a72009-10-06 21:19:11 -04001232
1233int ath9k_hw_beaconq_setup(struct ath_hw *ah)
1234{
1235 struct ath9k_tx_queue_info qi;
1236
1237 memset(&qi, 0, sizeof(qi));
1238 qi.tqi_aifs = 1;
1239 qi.tqi_cwmin = 0;
1240 qi.tqi_cwmax = 0;
1241 /* NB: don't enable any interrupts */
1242 return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
1243}
1244EXPORT_SYMBOL(ath9k_hw_beaconq_setup);
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -04001245
1246bool ath9k_hw_intrpend(struct ath_hw *ah)
1247{
1248 u32 host_isr;
1249
1250 if (AR_SREV_9100(ah))
1251 return true;
1252
1253 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
1254 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
1255 return true;
1256
1257 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1258 if ((host_isr & AR_INTR_SYNC_DEFAULT)
1259 && (host_isr != AR_INTR_SPURIOUS))
1260 return true;
1261
1262 return false;
1263}
1264EXPORT_SYMBOL(ath9k_hw_intrpend);
1265
1266enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah,
1267 enum ath9k_int ints)
1268{
1269 enum ath9k_int omask = ah->imask;
1270 u32 mask, mask2;
1271 struct ath9k_hw_capabilities *pCap = &ah->caps;
1272 struct ath_common *common = ath9k_hw_common(ah);
1273
1274 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
1275
1276 if (omask & ATH9K_INT_GLOBAL) {
1277 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
1278 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
1279 (void) REG_READ(ah, AR_IER);
1280 if (!AR_SREV_9100(ah)) {
1281 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
1282 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
1283
1284 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1285 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
1286 }
1287 }
1288
1289 /* TODO: global int Ref count */
1290 mask = ints & ATH9K_INT_COMMON;
1291 mask2 = 0;
1292
1293 if (ints & ATH9K_INT_TX) {
1294 if (ah->config.tx_intr_mitigation)
1295 mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM;
1296 if (ah->txok_interrupt_mask)
1297 mask |= AR_IMR_TXOK;
1298 if (ah->txdesc_interrupt_mask)
1299 mask |= AR_IMR_TXDESC;
1300 if (ah->txerr_interrupt_mask)
1301 mask |= AR_IMR_TXERR;
1302 if (ah->txeol_interrupt_mask)
1303 mask |= AR_IMR_TXEOL;
1304 }
1305 if (ints & ATH9K_INT_RX) {
1306 if (AR_SREV_9300_20_OR_LATER(ah)) {
1307 mask |= AR_IMR_RXERR | AR_IMR_RXOK_HP;
1308 if (ah->config.rx_intr_mitigation) {
1309 mask &= ~AR_IMR_RXOK_LP;
1310 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
1311 } else {
1312 mask |= AR_IMR_RXOK_LP;
1313 }
1314 } else {
1315 if (ah->config.rx_intr_mitigation)
1316 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
1317 else
1318 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
1319 }
1320 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
1321 mask |= AR_IMR_GENTMR;
1322 }
1323
1324 if (ints & (ATH9K_INT_BMISC)) {
1325 mask |= AR_IMR_BCNMISC;
1326 if (ints & ATH9K_INT_TIM)
1327 mask2 |= AR_IMR_S2_TIM;
1328 if (ints & ATH9K_INT_DTIM)
1329 mask2 |= AR_IMR_S2_DTIM;
1330 if (ints & ATH9K_INT_DTIMSYNC)
1331 mask2 |= AR_IMR_S2_DTIMSYNC;
1332 if (ints & ATH9K_INT_CABEND)
1333 mask2 |= AR_IMR_S2_CABEND;
1334 if (ints & ATH9K_INT_TSFOOR)
1335 mask2 |= AR_IMR_S2_TSFOOR;
1336 }
1337
1338 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
1339 mask |= AR_IMR_BCNMISC;
1340 if (ints & ATH9K_INT_GTT)
1341 mask2 |= AR_IMR_S2_GTT;
1342 if (ints & ATH9K_INT_CST)
1343 mask2 |= AR_IMR_S2_CST;
1344 }
1345
1346 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
1347 REG_WRITE(ah, AR_IMR, mask);
1348 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
1349 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
1350 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
1351 ah->imrs2_reg |= mask2;
1352 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
1353
1354 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1355 if (ints & ATH9K_INT_TIM_TIMER)
1356 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
1357 else
1358 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
1359 }
1360
1361 if (ints & ATH9K_INT_GLOBAL) {
1362 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
1363 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
1364 if (!AR_SREV_9100(ah)) {
1365 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
1366 AR_INTR_MAC_IRQ);
1367 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
1368
1369
1370 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
1371 AR_INTR_SYNC_DEFAULT);
1372 REG_WRITE(ah, AR_INTR_SYNC_MASK,
1373 AR_INTR_SYNC_DEFAULT);
1374 }
1375 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
1376 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
1377 }
1378
1379 return omask;
1380}
1381EXPORT_SYMBOL(ath9k_hw_set_interrupts);