Merge branch 'for_2.6.40/gpio-move' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / drivers / net / wireless / ath / ath9k / ar9003_mac.c
1 /*
2  * Copyright (c) 2010-2011 Atheros Communications Inc.
3  *
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 #include "hw.h"
17 #include "ar9003_mac.h"
18
19 static void ar9003_hw_rx_enable(struct ath_hw *hw)
20 {
21         REG_WRITE(hw, AR_CR, 0);
22 }
23
24 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
25 {
26         int checksum;
27
28         checksum = ads->info + ads->link
29                 + ads->data0 + ads->ctl3
30                 + ads->data1 + ads->ctl5
31                 + ads->data2 + ads->ctl7
32                 + ads->data3 + ads->ctl9;
33
34         return ((checksum & 0xffff) + (checksum >> 16)) & AR_TxPtrChkSum;
35 }
36
37 static void ar9003_hw_set_desc_link(void *ds, u32 ds_link)
38 {
39         struct ar9003_txc *ads = ds;
40
41         ads->link = ds_link;
42         ads->ctl10 &= ~AR_TxPtrChkSum;
43         ads->ctl10 |= ar9003_calc_ptr_chksum(ads);
44 }
45
46 static void ar9003_hw_get_desc_link(void *ds, u32 **ds_link)
47 {
48         struct ar9003_txc *ads = ds;
49
50         *ds_link = &ads->link;
51 }
52
53 static bool ar9003_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
54 {
55         u32 isr = 0;
56         u32 mask2 = 0;
57         struct ath9k_hw_capabilities *pCap = &ah->caps;
58         u32 sync_cause = 0;
59         struct ath_common *common = ath9k_hw_common(ah);
60
61         if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
62                 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
63                                 == AR_RTC_STATUS_ON)
64                         isr = REG_READ(ah, AR_ISR);
65         }
66
67         sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) & AR_INTR_SYNC_DEFAULT;
68
69         *masked = 0;
70
71         if (!isr && !sync_cause)
72                 return false;
73
74         if (isr) {
75                 if (isr & AR_ISR_BCNMISC) {
76                         u32 isr2;
77                         isr2 = REG_READ(ah, AR_ISR_S2);
78
79                         mask2 |= ((isr2 & AR_ISR_S2_TIM) >>
80                                   MAP_ISR_S2_TIM);
81                         mask2 |= ((isr2 & AR_ISR_S2_DTIM) >>
82                                   MAP_ISR_S2_DTIM);
83                         mask2 |= ((isr2 & AR_ISR_S2_DTIMSYNC) >>
84                                   MAP_ISR_S2_DTIMSYNC);
85                         mask2 |= ((isr2 & AR_ISR_S2_CABEND) >>
86                                   MAP_ISR_S2_CABEND);
87                         mask2 |= ((isr2 & AR_ISR_S2_GTT) <<
88                                   MAP_ISR_S2_GTT);
89                         mask2 |= ((isr2 & AR_ISR_S2_CST) <<
90                                   MAP_ISR_S2_CST);
91                         mask2 |= ((isr2 & AR_ISR_S2_TSFOOR) >>
92                                   MAP_ISR_S2_TSFOOR);
93                         mask2 |= ((isr2 & AR_ISR_S2_BB_WATCHDOG) >>
94                                   MAP_ISR_S2_BB_WATCHDOG);
95
96                         if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
97                                 REG_WRITE(ah, AR_ISR_S2, isr2);
98                                 isr &= ~AR_ISR_BCNMISC;
99                         }
100                 }
101
102                 if ((pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED))
103                         isr = REG_READ(ah, AR_ISR_RAC);
104
105                 if (isr == 0xffffffff) {
106                         *masked = 0;
107                         return false;
108                 }
109
110                 *masked = isr & ATH9K_INT_COMMON;
111
112                 if (ah->config.rx_intr_mitigation)
113                         if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
114                                 *masked |= ATH9K_INT_RXLP;
115
116                 if (ah->config.tx_intr_mitigation)
117                         if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM))
118                                 *masked |= ATH9K_INT_TX;
119
120                 if (isr & (AR_ISR_LP_RXOK | AR_ISR_RXERR))
121                         *masked |= ATH9K_INT_RXLP;
122
123                 if (isr & AR_ISR_HP_RXOK)
124                         *masked |= ATH9K_INT_RXHP;
125
126                 if (isr & (AR_ISR_TXOK | AR_ISR_TXERR | AR_ISR_TXEOL)) {
127                         *masked |= ATH9K_INT_TX;
128
129                         if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
130                                 u32 s0, s1;
131                                 s0 = REG_READ(ah, AR_ISR_S0);
132                                 REG_WRITE(ah, AR_ISR_S0, s0);
133                                 s1 = REG_READ(ah, AR_ISR_S1);
134                                 REG_WRITE(ah, AR_ISR_S1, s1);
135
136                                 isr &= ~(AR_ISR_TXOK | AR_ISR_TXERR |
137                                          AR_ISR_TXEOL);
138                         }
139                 }
140
141                 if (isr & AR_ISR_GENTMR) {
142                         u32 s5;
143
144                         if (pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)
145                                 s5 = REG_READ(ah, AR_ISR_S5_S);
146                         else
147                                 s5 = REG_READ(ah, AR_ISR_S5);
148
149                         ah->intr_gen_timer_trigger =
150                                 MS(s5, AR_ISR_S5_GENTIMER_TRIG);
151
152                         ah->intr_gen_timer_thresh =
153                                 MS(s5, AR_ISR_S5_GENTIMER_THRESH);
154
155                         if (ah->intr_gen_timer_trigger)
156                                 *masked |= ATH9K_INT_GENTIMER;
157
158                         if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
159                                 REG_WRITE(ah, AR_ISR_S5, s5);
160                                 isr &= ~AR_ISR_GENTMR;
161                         }
162
163                 }
164
165                 *masked |= mask2;
166
167                 if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
168                         REG_WRITE(ah, AR_ISR, isr);
169
170                         (void) REG_READ(ah, AR_ISR);
171                 }
172
173                 if (*masked & ATH9K_INT_BB_WATCHDOG)
174                         ar9003_hw_bb_watchdog_read(ah);
175         }
176
177         if (sync_cause) {
178                 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
179                         REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
180                         REG_WRITE(ah, AR_RC, 0);
181                         *masked |= ATH9K_INT_FATAL;
182                 }
183
184                 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
185                         ath_dbg(common, ATH_DBG_INTERRUPT,
186                                 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
187
188                 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
189                 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
190
191         }
192         return true;
193 }
194
195 static void ar9003_hw_fill_txdesc(struct ath_hw *ah, void *ds, u32 seglen,
196                                   bool is_firstseg, bool is_lastseg,
197                                   const void *ds0, dma_addr_t buf_addr,
198                                   unsigned int qcu)
199 {
200         struct ar9003_txc *ads = (struct ar9003_txc *) ds;
201         unsigned int descid = 0;
202
203         ads->info = (ATHEROS_VENDOR_ID << AR_DescId_S) |
204                                      (1 << AR_TxRxDesc_S) |
205                                      (1 << AR_CtrlStat_S) |
206                                      (qcu << AR_TxQcuNum_S) | 0x17;
207
208         ads->data0 = buf_addr;
209         ads->data1 = 0;
210         ads->data2 = 0;
211         ads->data3 = 0;
212
213         ads->ctl3 = (seglen << AR_BufLen_S);
214         ads->ctl3 &= AR_BufLen;
215
216         /* Fill in pointer checksum and descriptor id */
217         ads->ctl10 = ar9003_calc_ptr_chksum(ads);
218         ads->ctl10 |= (descid << AR_TxDescId_S);
219
220         if (is_firstseg) {
221                 ads->ctl12 |= (is_lastseg ? 0 : AR_TxMore);
222         } else if (is_lastseg) {
223                 ads->ctl11 = 0;
224                 ads->ctl12 = 0;
225                 ads->ctl13 = AR9003TXC_CONST(ds0)->ctl13;
226                 ads->ctl14 = AR9003TXC_CONST(ds0)->ctl14;
227         } else {
228                 /* XXX Intermediate descriptor in a multi-descriptor frame.*/
229                 ads->ctl11 = 0;
230                 ads->ctl12 = AR_TxMore;
231                 ads->ctl13 = 0;
232                 ads->ctl14 = 0;
233         }
234 }
235
236 static int ar9003_hw_proc_txdesc(struct ath_hw *ah, void *ds,
237                                  struct ath_tx_status *ts)
238 {
239         struct ar9003_txs *ads;
240         u32 status;
241
242         ads = &ah->ts_ring[ah->ts_tail];
243
244         status = ACCESS_ONCE(ads->status8);
245         if ((status & AR_TxDone) == 0)
246                 return -EINPROGRESS;
247
248         ah->ts_tail = (ah->ts_tail + 1) % ah->ts_size;
249
250         if ((MS(ads->ds_info, AR_DescId) != ATHEROS_VENDOR_ID) ||
251             (MS(ads->ds_info, AR_TxRxDesc) != 1)) {
252                 ath_dbg(ath9k_hw_common(ah), ATH_DBG_XMIT,
253                         "Tx Descriptor error %x\n", ads->ds_info);
254                 memset(ads, 0, sizeof(*ads));
255                 return -EIO;
256         }
257
258         if (status & AR_TxOpExceeded)
259                 ts->ts_status |= ATH9K_TXERR_XTXOP;
260         ts->ts_rateindex = MS(status, AR_FinalTxIdx);
261         ts->ts_seqnum = MS(status, AR_SeqNum);
262         ts->tid = MS(status, AR_TxTid);
263
264         ts->qid = MS(ads->ds_info, AR_TxQcuNum);
265         ts->desc_id = MS(ads->status1, AR_TxDescId);
266         ts->ts_tstamp = ads->status4;
267         ts->ts_status = 0;
268         ts->ts_flags  = 0;
269
270         status = ACCESS_ONCE(ads->status2);
271         ts->ts_rssi_ctl0 = MS(status, AR_TxRSSIAnt00);
272         ts->ts_rssi_ctl1 = MS(status, AR_TxRSSIAnt01);
273         ts->ts_rssi_ctl2 = MS(status, AR_TxRSSIAnt02);
274         if (status & AR_TxBaStatus) {
275                 ts->ts_flags |= ATH9K_TX_BA;
276                 ts->ba_low = ads->status5;
277                 ts->ba_high = ads->status6;
278         }
279
280         status = ACCESS_ONCE(ads->status3);
281         if (status & AR_ExcessiveRetries)
282                 ts->ts_status |= ATH9K_TXERR_XRETRY;
283         if (status & AR_Filtered)
284                 ts->ts_status |= ATH9K_TXERR_FILT;
285         if (status & AR_FIFOUnderrun) {
286                 ts->ts_status |= ATH9K_TXERR_FIFO;
287                 ath9k_hw_updatetxtriglevel(ah, true);
288         }
289         if (status & AR_TxTimerExpired)
290                 ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
291         if (status & AR_DescCfgErr)
292                 ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
293         if (status & AR_TxDataUnderrun) {
294                 ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
295                 ath9k_hw_updatetxtriglevel(ah, true);
296         }
297         if (status & AR_TxDelimUnderrun) {
298                 ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
299                 ath9k_hw_updatetxtriglevel(ah, true);
300         }
301         ts->ts_shortretry = MS(status, AR_RTSFailCnt);
302         ts->ts_longretry = MS(status, AR_DataFailCnt);
303         ts->ts_virtcol = MS(status, AR_VirtRetryCnt);
304
305         status = ACCESS_ONCE(ads->status7);
306         ts->ts_rssi = MS(status, AR_TxRSSICombined);
307         ts->ts_rssi_ext0 = MS(status, AR_TxRSSIAnt10);
308         ts->ts_rssi_ext1 = MS(status, AR_TxRSSIAnt11);
309         ts->ts_rssi_ext2 = MS(status, AR_TxRSSIAnt12);
310
311         memset(ads, 0, sizeof(*ads));
312
313         return 0;
314 }
315
316 static void ar9003_hw_set11n_txdesc(struct ath_hw *ah, void *ds,
317                 u32 pktlen, enum ath9k_pkt_type type, u32 txpower,
318                 u32 keyIx, enum ath9k_key_type keyType, u32 flags)
319 {
320         struct ar9003_txc *ads = (struct ar9003_txc *) ds;
321
322         if (txpower > ah->txpower_limit)
323                 txpower = ah->txpower_limit;
324
325         if (txpower > 63)
326                 txpower = 63;
327
328         ads->ctl11 = (pktlen & AR_FrameLen)
329                 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
330                 | SM(txpower, AR_XmitPower)
331                 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
332                 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0)
333                 | (flags & ATH9K_TXDESC_LOWRXCHAIN ? AR_LowRxChain : 0);
334
335         ads->ctl12 =
336                 (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
337                 | SM(type, AR_FrameType)
338                 | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
339                 | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
340                 | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
341
342         ads->ctl17 = SM(keyType, AR_EncrType) |
343                      (flags & ATH9K_TXDESC_LDPC ? AR_LDPC : 0);
344         ads->ctl18 = 0;
345         ads->ctl19 = AR_Not_Sounding;
346
347         ads->ctl20 = 0;
348         ads->ctl21 = 0;
349         ads->ctl22 = 0;
350 }
351
352 static void ar9003_hw_set_clrdmask(struct ath_hw *ah, void *ds, bool val)
353 {
354         struct ar9003_txc *ads = (struct ar9003_txc *) ds;
355
356         if (val)
357                 ads->ctl11 |= AR_ClrDestMask;
358         else
359                 ads->ctl11 &= ~AR_ClrDestMask;
360 }
361
362 static void ar9003_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
363                                           void *lastds,
364                                           u32 durUpdateEn, u32 rtsctsRate,
365                                           u32 rtsctsDuration,
366                                           struct ath9k_11n_rate_series series[],
367                                           u32 nseries, u32 flags)
368 {
369         struct ar9003_txc *ads = (struct ar9003_txc *) ds;
370         struct ar9003_txc *last_ads = (struct ar9003_txc *) lastds;
371         u_int32_t ctl11;
372
373         if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
374                 ctl11 = ads->ctl11;
375
376                 if (flags & ATH9K_TXDESC_RTSENA) {
377                         ctl11 &= ~AR_CTSEnable;
378                         ctl11 |= AR_RTSEnable;
379                 } else {
380                         ctl11 &= ~AR_RTSEnable;
381                         ctl11 |= AR_CTSEnable;
382                 }
383
384                 ads->ctl11 = ctl11;
385         } else {
386                 ads->ctl11 = (ads->ctl11 & ~(AR_RTSEnable | AR_CTSEnable));
387         }
388
389         ads->ctl13 = set11nTries(series, 0)
390                 |  set11nTries(series, 1)
391                 |  set11nTries(series, 2)
392                 |  set11nTries(series, 3)
393                 |  (durUpdateEn ? AR_DurUpdateEna : 0)
394                 |  SM(0, AR_BurstDur);
395
396         ads->ctl14 = set11nRate(series, 0)
397                 |  set11nRate(series, 1)
398                 |  set11nRate(series, 2)
399                 |  set11nRate(series, 3);
400
401         ads->ctl15 = set11nPktDurRTSCTS(series, 0)
402                 |  set11nPktDurRTSCTS(series, 1);
403
404         ads->ctl16 = set11nPktDurRTSCTS(series, 2)
405                 |  set11nPktDurRTSCTS(series, 3);
406
407         ads->ctl18 = set11nRateFlags(series, 0)
408                 |  set11nRateFlags(series, 1)
409                 |  set11nRateFlags(series, 2)
410                 |  set11nRateFlags(series, 3)
411                 | SM(rtsctsRate, AR_RTSCTSRate);
412         ads->ctl19 = AR_Not_Sounding;
413
414         last_ads->ctl13 = ads->ctl13;
415         last_ads->ctl14 = ads->ctl14;
416 }
417
418 static void ar9003_hw_set11n_aggr_first(struct ath_hw *ah, void *ds,
419                                         u32 aggrLen)
420 {
421 #define FIRST_DESC_NDELIMS 60
422         struct ar9003_txc *ads = (struct ar9003_txc *) ds;
423
424         ads->ctl12 |= (AR_IsAggr | AR_MoreAggr);
425
426         if (ah->ent_mode & AR_ENT_OTP_MPSD) {
427                 u32 ctl17, ndelim;
428                 /*
429                  * Add delimiter when using RTS/CTS with aggregation
430                  * and non enterprise AR9003 card
431                  */
432                 ctl17 = ads->ctl17;
433                 ndelim = MS(ctl17, AR_PadDelim);
434
435                 if (ndelim < FIRST_DESC_NDELIMS) {
436                         aggrLen += (FIRST_DESC_NDELIMS - ndelim) * 4;
437                         ndelim = FIRST_DESC_NDELIMS;
438                 }
439
440                 ctl17 &= ~AR_AggrLen;
441                 ctl17 |= SM(aggrLen, AR_AggrLen);
442
443                 ctl17 &= ~AR_PadDelim;
444                 ctl17 |= SM(ndelim, AR_PadDelim);
445
446                 ads->ctl17 = ctl17;
447         } else {
448                 ads->ctl17 &= ~AR_AggrLen;
449                 ads->ctl17 |= SM(aggrLen, AR_AggrLen);
450         }
451 }
452
453 static void ar9003_hw_set11n_aggr_middle(struct ath_hw *ah, void *ds,
454                                          u32 numDelims)
455 {
456         struct ar9003_txc *ads = (struct ar9003_txc *) ds;
457         unsigned int ctl17;
458
459         ads->ctl12 |= (AR_IsAggr | AR_MoreAggr);
460
461         /*
462          * We use a stack variable to manipulate ctl6 to reduce uncached
463          * read modify, modfiy, write.
464          */
465         ctl17 = ads->ctl17;
466         ctl17 &= ~AR_PadDelim;
467         ctl17 |= SM(numDelims, AR_PadDelim);
468         ads->ctl17 = ctl17;
469 }
470
471 static void ar9003_hw_set11n_aggr_last(struct ath_hw *ah, void *ds)
472 {
473         struct ar9003_txc *ads = (struct ar9003_txc *) ds;
474
475         ads->ctl12 |= AR_IsAggr;
476         ads->ctl12 &= ~AR_MoreAggr;
477         ads->ctl17 &= ~AR_PadDelim;
478 }
479
480 static void ar9003_hw_clr11n_aggr(struct ath_hw *ah, void *ds)
481 {
482         struct ar9003_txc *ads = (struct ar9003_txc *) ds;
483
484         ads->ctl12 &= (~AR_IsAggr & ~AR_MoreAggr);
485 }
486
487 void ar9003_hw_set_paprd_txdesc(struct ath_hw *ah, void *ds, u8 chains)
488 {
489         struct ar9003_txc *ads = ds;
490
491         ads->ctl12 |= SM(chains, AR_PAPRDChainMask);
492 }
493 EXPORT_SYMBOL(ar9003_hw_set_paprd_txdesc);
494
495 void ar9003_hw_attach_mac_ops(struct ath_hw *hw)
496 {
497         struct ath_hw_ops *ops = ath9k_hw_ops(hw);
498
499         ops->rx_enable = ar9003_hw_rx_enable;
500         ops->set_desc_link = ar9003_hw_set_desc_link;
501         ops->get_desc_link = ar9003_hw_get_desc_link;
502         ops->get_isr = ar9003_hw_get_isr;
503         ops->fill_txdesc = ar9003_hw_fill_txdesc;
504         ops->proc_txdesc = ar9003_hw_proc_txdesc;
505         ops->set11n_txdesc = ar9003_hw_set11n_txdesc;
506         ops->set11n_ratescenario = ar9003_hw_set11n_ratescenario;
507         ops->set11n_aggr_first = ar9003_hw_set11n_aggr_first;
508         ops->set11n_aggr_middle = ar9003_hw_set11n_aggr_middle;
509         ops->set11n_aggr_last = ar9003_hw_set11n_aggr_last;
510         ops->clr11n_aggr = ar9003_hw_clr11n_aggr;
511         ops->set_clrdmask = ar9003_hw_set_clrdmask;
512 }
513
514 void ath9k_hw_set_rx_bufsize(struct ath_hw *ah, u16 buf_size)
515 {
516         REG_WRITE(ah, AR_DATABUF_SIZE, buf_size & AR_DATABUF_SIZE_MASK);
517 }
518 EXPORT_SYMBOL(ath9k_hw_set_rx_bufsize);
519
520 void ath9k_hw_addrxbuf_edma(struct ath_hw *ah, u32 rxdp,
521                             enum ath9k_rx_qtype qtype)
522 {
523         if (qtype == ATH9K_RX_QUEUE_HP)
524                 REG_WRITE(ah, AR_HP_RXDP, rxdp);
525         else
526                 REG_WRITE(ah, AR_LP_RXDP, rxdp);
527 }
528 EXPORT_SYMBOL(ath9k_hw_addrxbuf_edma);
529
530 int ath9k_hw_process_rxdesc_edma(struct ath_hw *ah, struct ath_rx_status *rxs,
531                                  void *buf_addr)
532 {
533         struct ar9003_rxs *rxsp = (struct ar9003_rxs *) buf_addr;
534         unsigned int phyerr;
535
536         /* TODO: byte swap on big endian for ar9300_10 */
537
538         if ((rxsp->status11 & AR_RxDone) == 0)
539                 return -EINPROGRESS;
540
541         if (MS(rxsp->ds_info, AR_DescId) != 0x168c)
542                 return -EINVAL;
543
544         if ((rxsp->ds_info & (AR_TxRxDesc | AR_CtrlStat)) != 0)
545                 return -EINPROGRESS;
546
547         if (!rxs)
548                 return 0;
549
550         rxs->rs_status = 0;
551         rxs->rs_flags =  0;
552
553         rxs->rs_datalen = rxsp->status2 & AR_DataLen;
554         rxs->rs_tstamp =  rxsp->status3;
555
556         /* XXX: Keycache */
557         rxs->rs_rssi = MS(rxsp->status5, AR_RxRSSICombined);
558         rxs->rs_rssi_ctl0 = MS(rxsp->status1, AR_RxRSSIAnt00);
559         rxs->rs_rssi_ctl1 = MS(rxsp->status1, AR_RxRSSIAnt01);
560         rxs->rs_rssi_ctl2 = MS(rxsp->status1, AR_RxRSSIAnt02);
561         rxs->rs_rssi_ext0 = MS(rxsp->status5, AR_RxRSSIAnt10);
562         rxs->rs_rssi_ext1 = MS(rxsp->status5, AR_RxRSSIAnt11);
563         rxs->rs_rssi_ext2 = MS(rxsp->status5, AR_RxRSSIAnt12);
564
565         if (rxsp->status11 & AR_RxKeyIdxValid)
566                 rxs->rs_keyix = MS(rxsp->status11, AR_KeyIdx);
567         else
568                 rxs->rs_keyix = ATH9K_RXKEYIX_INVALID;
569
570         rxs->rs_rate = MS(rxsp->status1, AR_RxRate);
571         rxs->rs_more = (rxsp->status2 & AR_RxMore) ? 1 : 0;
572
573         rxs->rs_isaggr = (rxsp->status11 & AR_RxAggr) ? 1 : 0;
574         rxs->rs_moreaggr = (rxsp->status11 & AR_RxMoreAggr) ? 1 : 0;
575         rxs->rs_antenna = (MS(rxsp->status4, AR_RxAntenna) & 0x7);
576         rxs->rs_flags  = (rxsp->status4 & AR_GI) ? ATH9K_RX_GI : 0;
577         rxs->rs_flags  |= (rxsp->status4 & AR_2040) ? ATH9K_RX_2040 : 0;
578
579         rxs->evm0 = rxsp->status6;
580         rxs->evm1 = rxsp->status7;
581         rxs->evm2 = rxsp->status8;
582         rxs->evm3 = rxsp->status9;
583         rxs->evm4 = (rxsp->status10 & 0xffff);
584
585         if (rxsp->status11 & AR_PreDelimCRCErr)
586                 rxs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
587
588         if (rxsp->status11 & AR_PostDelimCRCErr)
589                 rxs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
590
591         if (rxsp->status11 & AR_DecryptBusyErr)
592                 rxs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
593
594         if ((rxsp->status11 & AR_RxFrameOK) == 0) {
595                 /*
596                  * AR_CRCErr will bet set to true if we're on the last
597                  * subframe and the AR_PostDelimCRCErr is caught.
598                  * In a way this also gives us a guarantee that when
599                  * (!(AR_CRCErr) && (AR_PostDelimCRCErr)) we cannot
600                  * possibly be reviewing the last subframe. AR_CRCErr
601                  * is the CRC of the actual data.
602                  */
603                 if (rxsp->status11 & AR_CRCErr)
604                         rxs->rs_status |= ATH9K_RXERR_CRC;
605                 else if (rxsp->status11 & AR_PHYErr) {
606                         phyerr = MS(rxsp->status11, AR_PHYErrCode);
607                         /*
608                          * If we reach a point here where AR_PostDelimCRCErr is
609                          * true it implies we're *not* on the last subframe. In
610                          * in that case that we know already that the CRC of
611                          * the frame was OK, and MAC would send an ACK for that
612                          * subframe, even if we did get a phy error of type
613                          * ATH9K_PHYERR_OFDM_RESTART. This is only applicable
614                          * to frame that are prior to the last subframe.
615                          * The AR_PostDelimCRCErr is the CRC for the MPDU
616                          * delimiter, which contains the 4 reserved bits,
617                          * the MPDU length (12 bits), and follows the MPDU
618                          * delimiter for an A-MPDU subframe (0x4E = 'N' ASCII).
619                          */
620                         if ((phyerr == ATH9K_PHYERR_OFDM_RESTART) &&
621                             (rxsp->status11 & AR_PostDelimCRCErr)) {
622                                 rxs->rs_phyerr = 0;
623                         } else {
624                                 rxs->rs_status |= ATH9K_RXERR_PHY;
625                                 rxs->rs_phyerr = phyerr;
626                         }
627
628                 } else if (rxsp->status11 & AR_DecryptCRCErr)
629                         rxs->rs_status |= ATH9K_RXERR_DECRYPT;
630                 else if (rxsp->status11 & AR_MichaelErr)
631                         rxs->rs_status |= ATH9K_RXERR_MIC;
632
633                 if (rxsp->status11 & AR_KeyMiss)
634                         rxs->rs_status |= ATH9K_RXERR_DECRYPT;
635         }
636
637         return 0;
638 }
639 EXPORT_SYMBOL(ath9k_hw_process_rxdesc_edma);
640
641 void ath9k_hw_reset_txstatus_ring(struct ath_hw *ah)
642 {
643         ah->ts_tail = 0;
644
645         memset((void *) ah->ts_ring, 0,
646                 ah->ts_size * sizeof(struct ar9003_txs));
647
648         ath_dbg(ath9k_hw_common(ah), ATH_DBG_XMIT,
649                 "TS Start 0x%x End 0x%x Virt %p, Size %d\n",
650                 ah->ts_paddr_start, ah->ts_paddr_end,
651                 ah->ts_ring, ah->ts_size);
652
653         REG_WRITE(ah, AR_Q_STATUS_RING_START, ah->ts_paddr_start);
654         REG_WRITE(ah, AR_Q_STATUS_RING_END, ah->ts_paddr_end);
655 }
656
657 void ath9k_hw_setup_statusring(struct ath_hw *ah, void *ts_start,
658                                u32 ts_paddr_start,
659                                u8 size)
660 {
661
662         ah->ts_paddr_start = ts_paddr_start;
663         ah->ts_paddr_end = ts_paddr_start + (size * sizeof(struct ar9003_txs));
664         ah->ts_size = size;
665         ah->ts_ring = (struct ar9003_txs *) ts_start;
666
667         ath9k_hw_reset_txstatus_ring(ah);
668 }
669 EXPORT_SYMBOL(ath9k_hw_setup_statusring);