blob: 8d1bca03bc0e862bb3c9359b59a6efcf3da2398e [file] [log] [blame]
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04001/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2010-2011 Atheros Communications Inc.
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04003 *
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 */
Paul Gortmakeree40fa02011-05-27 16:14:23 -040016#include <linux/export.h>
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -040017#include "hw.h"
Luis R. Rodriguezb622a722010-04-15 17:39:28 -040018#include "ar9003_mac.h"
Sujith Manoharanf4701b52012-02-22 12:41:18 +053019#include "ar9003_mci.h"
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -040020
21static void ar9003_hw_rx_enable(struct ath_hw *hw)
22{
23 REG_WRITE(hw, AR_CR, 0);
24}
25
Felix Fietkau2b63a412011-09-14 21:24:21 +020026static void
27ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
28{
29 struct ar9003_txc *ads = ds;
30 int checksum = 0;
31 u32 val, ctl12, ctl17;
Sujith Manoharan9da27232012-02-16 11:53:00 +053032 u8 desc_len;
33
34 desc_len = (AR_SREV_9462(ah) ? 0x18 : 0x17);
Felix Fietkau2b63a412011-09-14 21:24:21 +020035
36 val = (ATHEROS_VENDOR_ID << AR_DescId_S) |
37 (1 << AR_TxRxDesc_S) |
38 (1 << AR_CtrlStat_S) |
Sujith Manoharan9da27232012-02-16 11:53:00 +053039 (i->qcu << AR_TxQcuNum_S) | desc_len;
Felix Fietkau2b63a412011-09-14 21:24:21 +020040
41 checksum += val;
42 ACCESS_ONCE(ads->info) = val;
43
44 checksum += i->link;
45 ACCESS_ONCE(ads->link) = i->link;
46
47 checksum += i->buf_addr[0];
48 ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49 checksum += i->buf_addr[1];
50 ACCESS_ONCE(ads->data1) = i->buf_addr[1];
51 checksum += i->buf_addr[2];
52 ACCESS_ONCE(ads->data2) = i->buf_addr[2];
53 checksum += i->buf_addr[3];
54 ACCESS_ONCE(ads->data3) = i->buf_addr[3];
55
56 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
57 ACCESS_ONCE(ads->ctl3) = val;
58 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
59 ACCESS_ONCE(ads->ctl5) = val;
60 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
61 ACCESS_ONCE(ads->ctl7) = val;
62 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
63 ACCESS_ONCE(ads->ctl9) = val;
64
65 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
66 ACCESS_ONCE(ads->ctl10) = checksum;
67
68 if (i->is_first || i->is_last) {
69 ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
70 | set11nTries(i->rates, 1)
71 | set11nTries(i->rates, 2)
72 | set11nTries(i->rates, 3)
73 | (i->dur_update ? AR_DurUpdateEna : 0)
74 | SM(0, AR_BurstDur);
75
76 ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
77 | set11nRate(i->rates, 1)
78 | set11nRate(i->rates, 2)
79 | set11nRate(i->rates, 3);
80 } else {
81 ACCESS_ONCE(ads->ctl13) = 0;
82 ACCESS_ONCE(ads->ctl14) = 0;
83 }
84
85 ads->ctl20 = 0;
86 ads->ctl21 = 0;
87 ads->ctl22 = 0;
Sujith Manoharan9da27232012-02-16 11:53:00 +053088 ads->ctl23 = 0;
Felix Fietkau2b63a412011-09-14 21:24:21 +020089
90 ctl17 = SM(i->keytype, AR_EncrType);
91 if (!i->is_first) {
92 ACCESS_ONCE(ads->ctl11) = 0;
93 ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
94 ACCESS_ONCE(ads->ctl15) = 0;
95 ACCESS_ONCE(ads->ctl16) = 0;
96 ACCESS_ONCE(ads->ctl17) = ctl17;
97 ACCESS_ONCE(ads->ctl18) = 0;
98 ACCESS_ONCE(ads->ctl19) = 0;
99 return;
100 }
101
102 ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
103 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
104 | SM(i->txpower, AR_XmitPower)
105 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
106 | (i->keyix != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0)
107 | (i->flags & ATH9K_TXDESC_LOWRXCHAIN ? AR_LowRxChain : 0)
108 | (i->flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
109 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
110 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
111
112 ctl12 = (i->keyix != ATH9K_TXKEYIX_INVALID ?
113 SM(i->keyix, AR_DestIdx) : 0)
114 | SM(i->type, AR_FrameType)
115 | (i->flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
116 | (i->flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
117 | (i->flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
118
119 ctl17 |= (i->flags & ATH9K_TXDESC_LDPC ? AR_LDPC : 0);
120 switch (i->aggr) {
121 case AGGR_BUF_FIRST:
122 ctl17 |= SM(i->aggr_len, AR_AggrLen);
123 /* fall through */
124 case AGGR_BUF_MIDDLE:
125 ctl12 |= AR_IsAggr | AR_MoreAggr;
126 ctl17 |= SM(i->ndelim, AR_PadDelim);
127 break;
128 case AGGR_BUF_LAST:
129 ctl12 |= AR_IsAggr;
130 break;
131 case AGGR_BUF_NONE:
132 break;
133 }
134
135 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
136 ctl12 |= SM(val, AR_PAPRDChainMask);
137
138 ACCESS_ONCE(ads->ctl12) = ctl12;
139 ACCESS_ONCE(ads->ctl17) = ctl17;
140
141 ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
142 | set11nPktDurRTSCTS(i->rates, 1);
143
144 ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
145 | set11nPktDurRTSCTS(i->rates, 3);
146
147 ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
148 | set11nRateFlags(i->rates, 1)
149 | set11nRateFlags(i->rates, 2)
150 | set11nRateFlags(i->rates, 3)
151 | SM(i->rtscts_rate, AR_RTSCTSRate);
152
153 ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
154}
155
Vasanthakumar Thiagarajaneb823252010-04-15 17:39:35 -0400156static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
157{
158 int checksum;
159
160 checksum = ads->info + ads->link
161 + ads->data0 + ads->ctl3
162 + ads->data1 + ads->ctl5
163 + ads->data2 + ads->ctl7
164 + ads->data3 + ads->ctl9;
165
166 return ((checksum & 0xffff) + (checksum >> 16)) & AR_TxPtrChkSum;
167}
168
Vasanthakumar Thiagarajan87d5efb2010-04-15 17:38:43 -0400169static void ar9003_hw_set_desc_link(void *ds, u32 ds_link)
170{
Vasanthakumar Thiagarajaneb823252010-04-15 17:39:35 -0400171 struct ar9003_txc *ads = ds;
172
173 ads->link = ds_link;
174 ads->ctl10 &= ~AR_TxPtrChkSum;
175 ads->ctl10 |= ar9003_calc_ptr_chksum(ads);
Vasanthakumar Thiagarajan87d5efb2010-04-15 17:38:43 -0400176}
177
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400178static bool ar9003_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
179{
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -0400180 u32 isr = 0;
181 u32 mask2 = 0;
182 struct ath9k_hw_capabilities *pCap = &ah->caps;
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -0400183 struct ath_common *common = ath9k_hw_common(ah);
Mohammed Shafi Shajakhan4421d302011-11-30 10:41:21 +0530184 u32 sync_cause = 0, async_cause;
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -0400185
Mohammed Shafi Shajakhan4421d302011-11-30 10:41:21 +0530186 async_cause = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
187
188 if (async_cause & (AR_INTR_MAC_IRQ | AR_INTR_ASYNC_MASK_MCI)) {
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -0400189 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
190 == AR_RTC_STATUS_ON)
191 isr = REG_READ(ah, AR_ISR);
192 }
193
Mohammed Shafi Shajakhan4421d302011-11-30 10:41:21 +0530194
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -0400195 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) & AR_INTR_SYNC_DEFAULT;
196
197 *masked = 0;
198
Mohammed Shafi Shajakhan93fdd592011-12-08 11:59:02 +0530199 if (!isr && !sync_cause && !async_cause)
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -0400200 return false;
201
202 if (isr) {
203 if (isr & AR_ISR_BCNMISC) {
204 u32 isr2;
205 isr2 = REG_READ(ah, AR_ISR_S2);
206
207 mask2 |= ((isr2 & AR_ISR_S2_TIM) >>
208 MAP_ISR_S2_TIM);
209 mask2 |= ((isr2 & AR_ISR_S2_DTIM) >>
210 MAP_ISR_S2_DTIM);
211 mask2 |= ((isr2 & AR_ISR_S2_DTIMSYNC) >>
212 MAP_ISR_S2_DTIMSYNC);
213 mask2 |= ((isr2 & AR_ISR_S2_CABEND) >>
214 MAP_ISR_S2_CABEND);
215 mask2 |= ((isr2 & AR_ISR_S2_GTT) <<
216 MAP_ISR_S2_GTT);
217 mask2 |= ((isr2 & AR_ISR_S2_CST) <<
218 MAP_ISR_S2_CST);
219 mask2 |= ((isr2 & AR_ISR_S2_TSFOOR) >>
220 MAP_ISR_S2_TSFOOR);
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -0400221 mask2 |= ((isr2 & AR_ISR_S2_BB_WATCHDOG) >>
222 MAP_ISR_S2_BB_WATCHDOG);
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -0400223
224 if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
225 REG_WRITE(ah, AR_ISR_S2, isr2);
226 isr &= ~AR_ISR_BCNMISC;
227 }
228 }
229
230 if ((pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED))
231 isr = REG_READ(ah, AR_ISR_RAC);
232
233 if (isr == 0xffffffff) {
234 *masked = 0;
235 return false;
236 }
237
238 *masked = isr & ATH9K_INT_COMMON;
239
240 if (ah->config.rx_intr_mitigation)
241 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
242 *masked |= ATH9K_INT_RXLP;
243
244 if (ah->config.tx_intr_mitigation)
245 if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM))
246 *masked |= ATH9K_INT_TX;
247
248 if (isr & (AR_ISR_LP_RXOK | AR_ISR_RXERR))
249 *masked |= ATH9K_INT_RXLP;
250
251 if (isr & AR_ISR_HP_RXOK)
252 *masked |= ATH9K_INT_RXHP;
253
254 if (isr & (AR_ISR_TXOK | AR_ISR_TXERR | AR_ISR_TXEOL)) {
255 *masked |= ATH9K_INT_TX;
256
257 if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
258 u32 s0, s1;
259 s0 = REG_READ(ah, AR_ISR_S0);
260 REG_WRITE(ah, AR_ISR_S0, s0);
261 s1 = REG_READ(ah, AR_ISR_S1);
262 REG_WRITE(ah, AR_ISR_S1, s1);
263
264 isr &= ~(AR_ISR_TXOK | AR_ISR_TXERR |
265 AR_ISR_TXEOL);
266 }
267 }
268
269 if (isr & AR_ISR_GENTMR) {
270 u32 s5;
271
272 if (pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)
273 s5 = REG_READ(ah, AR_ISR_S5_S);
274 else
275 s5 = REG_READ(ah, AR_ISR_S5);
276
277 ah->intr_gen_timer_trigger =
278 MS(s5, AR_ISR_S5_GENTIMER_TRIG);
279
280 ah->intr_gen_timer_thresh =
281 MS(s5, AR_ISR_S5_GENTIMER_THRESH);
282
283 if (ah->intr_gen_timer_trigger)
284 *masked |= ATH9K_INT_GENTIMER;
285
286 if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
287 REG_WRITE(ah, AR_ISR_S5, s5);
288 isr &= ~AR_ISR_GENTMR;
289 }
290
291 }
292
293 *masked |= mask2;
294
295 if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
296 REG_WRITE(ah, AR_ISR, isr);
297
298 (void) REG_READ(ah, AR_ISR);
299 }
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -0400300
301 if (*masked & ATH9K_INT_BB_WATCHDOG)
302 ar9003_hw_bb_watchdog_read(ah);
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -0400303 }
304
Sujith Manoharan5a1e2732012-02-22 12:40:55 +0530305 if (async_cause & AR_INTR_ASYNC_MASK_MCI)
306 ar9003_mci_get_isr(ah, masked);
Mohammed Shafi Shajakhancc78d6b2011-12-08 11:59:03 +0530307
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -0400308 if (sync_cause) {
309 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
310 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
311 REG_WRITE(ah, AR_RC, 0);
312 *masked |= ATH9K_INT_FATAL;
313 }
314
315 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
Joe Perchesd2182b62011-12-15 14:55:53 -0800316 ath_dbg(common, INTERRUPT,
Joe Perches226afe62010-12-02 19:12:37 -0800317 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -0400318
Julia Lawall6fe14002010-08-05 22:26:56 +0200319 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -0400320 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
321
322 }
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400323 return true;
324}
325
Vasanthakumar Thiagarajancc610ac02010-04-15 17:39:26 -0400326static int ar9003_hw_proc_txdesc(struct ath_hw *ah, void *ds,
327 struct ath_tx_status *ts)
328{
Rajkumar Manoharandcfcbd52011-06-23 13:39:13 +0530329 struct ar9003_txc *txc = (struct ar9003_txc *) ds;
Vasanthakumar Thiagarajan994089d2010-04-15 17:39:29 -0400330 struct ar9003_txs *ads;
Felix Fietkaue0e9bc82010-10-15 20:03:30 +0200331 u32 status;
Vasanthakumar Thiagarajan994089d2010-04-15 17:39:29 -0400332
333 ads = &ah->ts_ring[ah->ts_tail];
334
Felix Fietkaue0e9bc82010-10-15 20:03:30 +0200335 status = ACCESS_ONCE(ads->status8);
336 if ((status & AR_TxDone) == 0)
Vasanthakumar Thiagarajan994089d2010-04-15 17:39:29 -0400337 return -EINPROGRESS;
338
Rajkumar Manoharandcfcbd52011-06-23 13:39:13 +0530339 ts->qid = MS(ads->ds_info, AR_TxQcuNum);
340 if (!txc || (MS(txc->info, AR_TxQcuNum) == ts->qid))
341 ah->ts_tail = (ah->ts_tail + 1) % ah->ts_size;
342 else
343 return -ENOENT;
Vasanthakumar Thiagarajan994089d2010-04-15 17:39:29 -0400344
345 if ((MS(ads->ds_info, AR_DescId) != ATHEROS_VENDOR_ID) ||
346 (MS(ads->ds_info, AR_TxRxDesc) != 1)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800347 ath_dbg(ath9k_hw_common(ah), XMIT,
Joe Perches226afe62010-12-02 19:12:37 -0800348 "Tx Descriptor error %x\n", ads->ds_info);
Vasanthakumar Thiagarajan994089d2010-04-15 17:39:29 -0400349 memset(ads, 0, sizeof(*ads));
350 return -EIO;
351 }
352
Felix Fietkaue0e9bc82010-10-15 20:03:30 +0200353 ts->ts_rateindex = MS(status, AR_FinalTxIdx);
354 ts->ts_seqnum = MS(status, AR_SeqNum);
355 ts->tid = MS(status, AR_TxTid);
356
Vasanthakumar Thiagarajan994089d2010-04-15 17:39:29 -0400357 ts->desc_id = MS(ads->status1, AR_TxDescId);
Vasanthakumar Thiagarajan994089d2010-04-15 17:39:29 -0400358 ts->ts_tstamp = ads->status4;
359 ts->ts_status = 0;
360 ts->ts_flags = 0;
361
Rajkumar Manoharan2a15b392011-08-20 17:22:09 +0530362 if (status & AR_TxOpExceeded)
363 ts->ts_status |= ATH9K_TXERR_XTXOP;
Felix Fietkaue0e9bc82010-10-15 20:03:30 +0200364 status = ACCESS_ONCE(ads->status2);
365 ts->ts_rssi_ctl0 = MS(status, AR_TxRSSIAnt00);
366 ts->ts_rssi_ctl1 = MS(status, AR_TxRSSIAnt01);
367 ts->ts_rssi_ctl2 = MS(status, AR_TxRSSIAnt02);
368 if (status & AR_TxBaStatus) {
Vasanthakumar Thiagarajan994089d2010-04-15 17:39:29 -0400369 ts->ts_flags |= ATH9K_TX_BA;
370 ts->ba_low = ads->status5;
371 ts->ba_high = ads->status6;
372 }
373
Felix Fietkaue0e9bc82010-10-15 20:03:30 +0200374 status = ACCESS_ONCE(ads->status3);
375 if (status & AR_ExcessiveRetries)
376 ts->ts_status |= ATH9K_TXERR_XRETRY;
377 if (status & AR_Filtered)
378 ts->ts_status |= ATH9K_TXERR_FILT;
379 if (status & AR_FIFOUnderrun) {
380 ts->ts_status |= ATH9K_TXERR_FIFO;
381 ath9k_hw_updatetxtriglevel(ah, true);
382 }
383 if (status & AR_TxTimerExpired)
384 ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
385 if (status & AR_DescCfgErr)
386 ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
387 if (status & AR_TxDataUnderrun) {
388 ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
389 ath9k_hw_updatetxtriglevel(ah, true);
390 }
391 if (status & AR_TxDelimUnderrun) {
392 ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
393 ath9k_hw_updatetxtriglevel(ah, true);
394 }
395 ts->ts_shortretry = MS(status, AR_RTSFailCnt);
396 ts->ts_longretry = MS(status, AR_DataFailCnt);
397 ts->ts_virtcol = MS(status, AR_VirtRetryCnt);
Vasanthakumar Thiagarajan994089d2010-04-15 17:39:29 -0400398
Felix Fietkaue0e9bc82010-10-15 20:03:30 +0200399 status = ACCESS_ONCE(ads->status7);
400 ts->ts_rssi = MS(status, AR_TxRSSICombined);
401 ts->ts_rssi_ext0 = MS(status, AR_TxRSSIAnt10);
402 ts->ts_rssi_ext1 = MS(status, AR_TxRSSIAnt11);
403 ts->ts_rssi_ext2 = MS(status, AR_TxRSSIAnt12);
Vasanthakumar Thiagarajan994089d2010-04-15 17:39:29 -0400404
405 memset(ads, 0, sizeof(*ads));
406
Vasanthakumar Thiagarajancc610ac02010-04-15 17:39:26 -0400407 return 0;
408}
Vasanthakumar Thiagarajancc610ac02010-04-15 17:39:26 -0400409
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -0400410void ar9003_hw_attach_mac_ops(struct ath_hw *hw)
411{
412 struct ath_hw_ops *ops = ath9k_hw_ops(hw);
413
414 ops->rx_enable = ar9003_hw_rx_enable;
Vasanthakumar Thiagarajan87d5efb2010-04-15 17:38:43 -0400415 ops->set_desc_link = ar9003_hw_set_desc_link;
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400416 ops->get_isr = ar9003_hw_get_isr;
Felix Fietkau2b63a412011-09-14 21:24:21 +0200417 ops->set_txdesc = ar9003_set_txdesc;
Vasanthakumar Thiagarajancc610ac02010-04-15 17:39:26 -0400418 ops->proc_txdesc = ar9003_hw_proc_txdesc;
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -0400419}
Vasanthakumar Thiagarajanad7b8062010-04-15 17:38:28 -0400420
421void ath9k_hw_set_rx_bufsize(struct ath_hw *ah, u16 buf_size)
422{
423 REG_WRITE(ah, AR_DATABUF_SIZE, buf_size & AR_DATABUF_SIZE_MASK);
424}
425EXPORT_SYMBOL(ath9k_hw_set_rx_bufsize);
426
427void ath9k_hw_addrxbuf_edma(struct ath_hw *ah, u32 rxdp,
428 enum ath9k_rx_qtype qtype)
429{
430 if (qtype == ATH9K_RX_QUEUE_HP)
431 REG_WRITE(ah, AR_HP_RXDP, rxdp);
432 else
433 REG_WRITE(ah, AR_LP_RXDP, rxdp);
434}
435EXPORT_SYMBOL(ath9k_hw_addrxbuf_edma);
436
437int ath9k_hw_process_rxdesc_edma(struct ath_hw *ah, struct ath_rx_status *rxs,
438 void *buf_addr)
439{
440 struct ar9003_rxs *rxsp = (struct ar9003_rxs *) buf_addr;
441 unsigned int phyerr;
442
443 /* TODO: byte swap on big endian for ar9300_10 */
444
Rajkumar Manoharancca1fe12011-07-29 17:38:16 +0530445 if (!rxs) {
446 if ((rxsp->status11 & AR_RxDone) == 0)
447 return -EINPROGRESS;
Vasanthakumar Thiagarajanad7b8062010-04-15 17:38:28 -0400448
Rajkumar Manoharancca1fe12011-07-29 17:38:16 +0530449 if (MS(rxsp->ds_info, AR_DescId) != 0x168c)
450 return -EINVAL;
Vasanthakumar Thiagarajanad7b8062010-04-15 17:38:28 -0400451
Rajkumar Manoharancca1fe12011-07-29 17:38:16 +0530452 if ((rxsp->ds_info & (AR_TxRxDesc | AR_CtrlStat)) != 0)
453 return -EINPROGRESS;
Vasanthakumar Thiagarajanad7b8062010-04-15 17:38:28 -0400454
Felix Fietkaub5c804752010-04-15 17:38:48 -0400455 return 0;
Rajkumar Manoharancca1fe12011-07-29 17:38:16 +0530456 }
Felix Fietkaub5c804752010-04-15 17:38:48 -0400457
Vasanthakumar Thiagarajanad7b8062010-04-15 17:38:28 -0400458 rxs->rs_status = 0;
459 rxs->rs_flags = 0;
460
461 rxs->rs_datalen = rxsp->status2 & AR_DataLen;
462 rxs->rs_tstamp = rxsp->status3;
463
464 /* XXX: Keycache */
465 rxs->rs_rssi = MS(rxsp->status5, AR_RxRSSICombined);
466 rxs->rs_rssi_ctl0 = MS(rxsp->status1, AR_RxRSSIAnt00);
467 rxs->rs_rssi_ctl1 = MS(rxsp->status1, AR_RxRSSIAnt01);
468 rxs->rs_rssi_ctl2 = MS(rxsp->status1, AR_RxRSSIAnt02);
469 rxs->rs_rssi_ext0 = MS(rxsp->status5, AR_RxRSSIAnt10);
470 rxs->rs_rssi_ext1 = MS(rxsp->status5, AR_RxRSSIAnt11);
471 rxs->rs_rssi_ext2 = MS(rxsp->status5, AR_RxRSSIAnt12);
472
473 if (rxsp->status11 & AR_RxKeyIdxValid)
474 rxs->rs_keyix = MS(rxsp->status11, AR_KeyIdx);
475 else
476 rxs->rs_keyix = ATH9K_RXKEYIX_INVALID;
477
478 rxs->rs_rate = MS(rxsp->status1, AR_RxRate);
479 rxs->rs_more = (rxsp->status2 & AR_RxMore) ? 1 : 0;
480
481 rxs->rs_isaggr = (rxsp->status11 & AR_RxAggr) ? 1 : 0;
482 rxs->rs_moreaggr = (rxsp->status11 & AR_RxMoreAggr) ? 1 : 0;
483 rxs->rs_antenna = (MS(rxsp->status4, AR_RxAntenna) & 0x7);
484 rxs->rs_flags = (rxsp->status4 & AR_GI) ? ATH9K_RX_GI : 0;
485 rxs->rs_flags |= (rxsp->status4 & AR_2040) ? ATH9K_RX_2040 : 0;
486
487 rxs->evm0 = rxsp->status6;
488 rxs->evm1 = rxsp->status7;
489 rxs->evm2 = rxsp->status8;
490 rxs->evm3 = rxsp->status9;
491 rxs->evm4 = (rxsp->status10 & 0xffff);
492
493 if (rxsp->status11 & AR_PreDelimCRCErr)
494 rxs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
495
496 if (rxsp->status11 & AR_PostDelimCRCErr)
497 rxs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
498
499 if (rxsp->status11 & AR_DecryptBusyErr)
500 rxs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
501
502 if ((rxsp->status11 & AR_RxFrameOK) == 0) {
Luis R. Rodriguez9171acc2010-07-14 20:08:41 -0400503 /*
504 * AR_CRCErr will bet set to true if we're on the last
505 * subframe and the AR_PostDelimCRCErr is caught.
506 * In a way this also gives us a guarantee that when
507 * (!(AR_CRCErr) && (AR_PostDelimCRCErr)) we cannot
508 * possibly be reviewing the last subframe. AR_CRCErr
509 * is the CRC of the actual data.
510 */
Felix Fietkau1c30cc12010-12-28 15:46:16 +0100511 if (rxsp->status11 & AR_CRCErr)
Vasanthakumar Thiagarajanad7b8062010-04-15 17:38:28 -0400512 rxs->rs_status |= ATH9K_RXERR_CRC;
Zefir Kurtisif4fb4b22012-02-27 12:52:06 +0100513 else if (rxsp->status11 & AR_DecryptCRCErr)
514 rxs->rs_status |= ATH9K_RXERR_DECRYPT;
515 else if (rxsp->status11 & AR_MichaelErr)
516 rxs->rs_status |= ATH9K_RXERR_MIC;
517 if (rxsp->status11 & AR_PHYErr) {
Vasanthakumar Thiagarajanad7b8062010-04-15 17:38:28 -0400518 phyerr = MS(rxsp->status11, AR_PHYErrCode);
Luis R. Rodriguez9171acc2010-07-14 20:08:41 -0400519 /*
520 * If we reach a point here where AR_PostDelimCRCErr is
521 * true it implies we're *not* on the last subframe. In
522 * in that case that we know already that the CRC of
523 * the frame was OK, and MAC would send an ACK for that
524 * subframe, even if we did get a phy error of type
525 * ATH9K_PHYERR_OFDM_RESTART. This is only applicable
526 * to frame that are prior to the last subframe.
527 * The AR_PostDelimCRCErr is the CRC for the MPDU
528 * delimiter, which contains the 4 reserved bits,
529 * the MPDU length (12 bits), and follows the MPDU
530 * delimiter for an A-MPDU subframe (0x4E = 'N' ASCII).
531 */
532 if ((phyerr == ATH9K_PHYERR_OFDM_RESTART) &&
533 (rxsp->status11 & AR_PostDelimCRCErr)) {
534 rxs->rs_phyerr = 0;
535 } else {
536 rxs->rs_status |= ATH9K_RXERR_PHY;
537 rxs->rs_phyerr = phyerr;
538 }
Zefir Kurtisif4fb4b22012-02-27 12:52:06 +0100539 };
Vasanthakumar Thiagarajanad7b8062010-04-15 17:38:28 -0400540 }
541
Felix Fietkau7a532fe2012-01-14 15:08:34 +0100542 if (rxsp->status11 & AR_KeyMiss)
543 rxs->rs_status |= ATH9K_RXERR_KEYMISS;
544
Vasanthakumar Thiagarajanad7b8062010-04-15 17:38:28 -0400545 return 0;
546}
547EXPORT_SYMBOL(ath9k_hw_process_rxdesc_edma);
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -0400548
549void ath9k_hw_reset_txstatus_ring(struct ath_hw *ah)
550{
551 ah->ts_tail = 0;
552
553 memset((void *) ah->ts_ring, 0,
554 ah->ts_size * sizeof(struct ar9003_txs));
555
Joe Perchesd2182b62011-12-15 14:55:53 -0800556 ath_dbg(ath9k_hw_common(ah), XMIT,
Joe Perches226afe62010-12-02 19:12:37 -0800557 "TS Start 0x%x End 0x%x Virt %p, Size %d\n",
558 ah->ts_paddr_start, ah->ts_paddr_end,
559 ah->ts_ring, ah->ts_size);
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -0400560
561 REG_WRITE(ah, AR_Q_STATUS_RING_START, ah->ts_paddr_start);
562 REG_WRITE(ah, AR_Q_STATUS_RING_END, ah->ts_paddr_end);
563}
564
565void ath9k_hw_setup_statusring(struct ath_hw *ah, void *ts_start,
566 u32 ts_paddr_start,
Rajkumar Manoharan016c2172011-12-23 21:27:02 +0530567 u16 size)
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -0400568{
569
570 ah->ts_paddr_start = ts_paddr_start;
571 ah->ts_paddr_end = ts_paddr_start + (size * sizeof(struct ar9003_txs));
572 ah->ts_size = size;
573 ah->ts_ring = (struct ar9003_txs *) ts_start;
574
575 ath9k_hw_reset_txstatus_ring(ah);
576}
577EXPORT_SYMBOL(ath9k_hw_setup_statusring);