]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/net/wireless/ath/ath9k/ar9002_mac.c
ath9k_hw: small optimization in ar9002_hw_get_isr
[net-next-2.6.git] / drivers / net / wireless / ath / ath9k / ar9002_mac.c
1 /*
2  * Copyright (c) 2008-2009 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
17 #include "hw.h"
18
19 #define AR_BufLen           0x00000fff
20
21 static void ar9002_hw_rx_enable(struct ath_hw *ah)
22 {
23         REG_WRITE(ah, AR_CR, AR_CR_RXE);
24 }
25
26 static void ar9002_hw_set_desc_link(void *ds, u32 ds_link)
27 {
28         ((struct ath_desc*) ds)->ds_link = ds_link;
29 }
30
31 static void ar9002_hw_get_desc_link(void *ds, u32 **ds_link)
32 {
33         *ds_link = &((struct ath_desc *)ds)->ds_link;
34 }
35
36 static bool ar9002_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
37 {
38         u32 isr = 0;
39         u32 mask2 = 0;
40         struct ath9k_hw_capabilities *pCap = &ah->caps;
41         u32 sync_cause = 0;
42         bool fatal_int = false;
43         struct ath_common *common = ath9k_hw_common(ah);
44
45         if (!AR_SREV_9100(ah)) {
46                 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
47                         if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
48                             == AR_RTC_STATUS_ON) {
49                                 isr = REG_READ(ah, AR_ISR);
50                         }
51                 }
52
53                 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
54                         AR_INTR_SYNC_DEFAULT;
55
56                 *masked = 0;
57
58                 if (!isr && !sync_cause)
59                         return false;
60         } else {
61                 *masked = 0;
62                 isr = REG_READ(ah, AR_ISR);
63         }
64
65         if (isr) {
66                 if (isr & AR_ISR_BCNMISC) {
67                         u32 isr2;
68                         isr2 = REG_READ(ah, AR_ISR_S2);
69                         if (isr2 & AR_ISR_S2_TIM)
70                                 mask2 |= ATH9K_INT_TIM;
71                         if (isr2 & AR_ISR_S2_DTIM)
72                                 mask2 |= ATH9K_INT_DTIM;
73                         if (isr2 & AR_ISR_S2_DTIMSYNC)
74                                 mask2 |= ATH9K_INT_DTIMSYNC;
75                         if (isr2 & (AR_ISR_S2_CABEND))
76                                 mask2 |= ATH9K_INT_CABEND;
77                         if (isr2 & AR_ISR_S2_GTT)
78                                 mask2 |= ATH9K_INT_GTT;
79                         if (isr2 & AR_ISR_S2_CST)
80                                 mask2 |= ATH9K_INT_CST;
81                         if (isr2 & AR_ISR_S2_TSFOOR)
82                                 mask2 |= ATH9K_INT_TSFOOR;
83                 }
84
85                 isr = REG_READ(ah, AR_ISR_RAC);
86                 if (isr == 0xffffffff) {
87                         *masked = 0;
88                         return false;
89                 }
90
91                 *masked = isr & ATH9K_INT_COMMON;
92
93                 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM |
94                            AR_ISR_RXOK | AR_ISR_RXERR))
95                         *masked |= ATH9K_INT_RX;
96
97                 if (isr &
98                     (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
99                      AR_ISR_TXEOL)) {
100                         u32 s0_s, s1_s;
101
102                         *masked |= ATH9K_INT_TX;
103
104                         s0_s = REG_READ(ah, AR_ISR_S0_S);
105                         ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
106                         ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
107
108                         s1_s = REG_READ(ah, AR_ISR_S1_S);
109                         ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
110                         ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
111                 }
112
113                 if (isr & AR_ISR_RXORN) {
114                         ath_print(common, ATH_DBG_INTERRUPT,
115                                   "receive FIFO overrun interrupt\n");
116                 }
117
118                 *masked |= mask2;
119         }
120
121         if (AR_SREV_9100(ah))
122                 return true;
123
124         if (isr & AR_ISR_GENTMR) {
125                 u32 s5_s;
126
127                 s5_s = REG_READ(ah, AR_ISR_S5_S);
128                 ah->intr_gen_timer_trigger =
129                                 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
130
131                 ah->intr_gen_timer_thresh =
132                         MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
133
134                 if (ah->intr_gen_timer_trigger)
135                         *masked |= ATH9K_INT_GENTIMER;
136
137                 if ((s5_s & AR_ISR_S5_TIM_TIMER) &&
138                     !(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
139                         *masked |= ATH9K_INT_TIM_TIMER;
140         }
141
142         if (sync_cause) {
143                 fatal_int =
144                         (sync_cause &
145                          (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
146                         ? true : false;
147
148                 if (fatal_int) {
149                         if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
150                                 ath_print(common, ATH_DBG_ANY,
151                                           "received PCI FATAL interrupt\n");
152                         }
153                         if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
154                                 ath_print(common, ATH_DBG_ANY,
155                                           "received PCI PERR interrupt\n");
156                         }
157                         *masked |= ATH9K_INT_FATAL;
158                 }
159                 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
160                         ath_print(common, ATH_DBG_INTERRUPT,
161                                   "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
162                         REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
163                         REG_WRITE(ah, AR_RC, 0);
164                         *masked |= ATH9K_INT_FATAL;
165                 }
166                 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
167                         ath_print(common, ATH_DBG_INTERRUPT,
168                                   "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
169                 }
170
171                 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
172                 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
173         }
174
175         return true;
176 }
177
178 static void ar9002_hw_fill_txdesc(struct ath_hw *ah, void *ds, u32 seglen,
179                                   bool is_firstseg, bool is_lastseg,
180                                   const void *ds0, dma_addr_t buf_addr,
181                                   unsigned int qcu)
182 {
183         struct ar5416_desc *ads = AR5416DESC(ds);
184
185         ads->ds_data = buf_addr;
186
187         if (is_firstseg) {
188                 ads->ds_ctl1 |= seglen | (is_lastseg ? 0 : AR_TxMore);
189         } else if (is_lastseg) {
190                 ads->ds_ctl0 = 0;
191                 ads->ds_ctl1 = seglen;
192                 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
193                 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
194         } else {
195                 ads->ds_ctl0 = 0;
196                 ads->ds_ctl1 = seglen | AR_TxMore;
197                 ads->ds_ctl2 = 0;
198                 ads->ds_ctl3 = 0;
199         }
200         ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
201         ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
202         ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
203         ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
204         ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
205 }
206
207 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
208                                  struct ath_tx_status *ts)
209 {
210         struct ar5416_desc *ads = AR5416DESC(ds);
211
212         if ((ads->ds_txstatus9 & AR_TxDone) == 0)
213                 return -EINPROGRESS;
214
215         ts->ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
216         ts->ts_tstamp = ads->AR_SendTimestamp;
217         ts->ts_status = 0;
218         ts->ts_flags = 0;
219
220         if (ads->ds_txstatus1 & AR_FrmXmitOK)
221                 ts->ts_status |= ATH9K_TX_ACKED;
222         if (ads->ds_txstatus1 & AR_ExcessiveRetries)
223                 ts->ts_status |= ATH9K_TXERR_XRETRY;
224         if (ads->ds_txstatus1 & AR_Filtered)
225                 ts->ts_status |= ATH9K_TXERR_FILT;
226         if (ads->ds_txstatus1 & AR_FIFOUnderrun) {
227                 ts->ts_status |= ATH9K_TXERR_FIFO;
228                 ath9k_hw_updatetxtriglevel(ah, true);
229         }
230         if (ads->ds_txstatus9 & AR_TxOpExceeded)
231                 ts->ts_status |= ATH9K_TXERR_XTXOP;
232         if (ads->ds_txstatus1 & AR_TxTimerExpired)
233                 ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
234
235         if (ads->ds_txstatus1 & AR_DescCfgErr)
236                 ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
237         if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
238                 ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
239                 ath9k_hw_updatetxtriglevel(ah, true);
240         }
241         if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
242                 ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
243                 ath9k_hw_updatetxtriglevel(ah, true);
244         }
245         if (ads->ds_txstatus0 & AR_TxBaStatus) {
246                 ts->ts_flags |= ATH9K_TX_BA;
247                 ts->ba_low = ads->AR_BaBitmapLow;
248                 ts->ba_high = ads->AR_BaBitmapHigh;
249         }
250
251         ts->ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
252         switch (ts->ts_rateindex) {
253         case 0:
254                 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
255                 break;
256         case 1:
257                 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
258                 break;
259         case 2:
260                 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
261                 break;
262         case 3:
263                 ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
264                 break;
265         }
266
267         ts->ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
268         ts->ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
269         ts->ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
270         ts->ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
271         ts->ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
272         ts->ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
273         ts->ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
274         ts->evm0 = ads->AR_TxEVM0;
275         ts->evm1 = ads->AR_TxEVM1;
276         ts->evm2 = ads->AR_TxEVM2;
277         ts->ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
278         ts->ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
279         ts->ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
280         ts->tid = MS(ads->ds_txstatus9, AR_TxTid);
281         ts->ts_antenna = 0;
282
283         return 0;
284 }
285
286 static void ar9002_hw_set11n_txdesc(struct ath_hw *ah, void *ds,
287                                     u32 pktLen, enum ath9k_pkt_type type,
288                                     u32 txPower, u32 keyIx,
289                                     enum ath9k_key_type keyType, u32 flags)
290 {
291         struct ar5416_desc *ads = AR5416DESC(ds);
292
293         txPower += ah->txpower_indexoffset;
294         if (txPower > 63)
295                 txPower = 63;
296
297         ads->ds_ctl0 = (pktLen & AR_FrameLen)
298                 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
299                 | SM(txPower, AR_XmitPower)
300                 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
301                 | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
302                 | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
303                 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
304
305         ads->ds_ctl1 =
306                 (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
307                 | SM(type, AR_FrameType)
308                 | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
309                 | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
310                 | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
311
312         ads->ds_ctl6 = SM(keyType, AR_EncrType);
313
314         if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
315                 ads->ds_ctl8 = 0;
316                 ads->ds_ctl9 = 0;
317                 ads->ds_ctl10 = 0;
318                 ads->ds_ctl11 = 0;
319         }
320 }
321
322 static void ar9002_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
323                                           void *lastds,
324                                           u32 durUpdateEn, u32 rtsctsRate,
325                                           u32 rtsctsDuration,
326                                           struct ath9k_11n_rate_series series[],
327                                           u32 nseries, u32 flags)
328 {
329         struct ar5416_desc *ads = AR5416DESC(ds);
330         struct ar5416_desc *last_ads = AR5416DESC(lastds);
331         u32 ds_ctl0;
332
333         if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
334                 ds_ctl0 = ads->ds_ctl0;
335
336                 if (flags & ATH9K_TXDESC_RTSENA) {
337                         ds_ctl0 &= ~AR_CTSEnable;
338                         ds_ctl0 |= AR_RTSEnable;
339                 } else {
340                         ds_ctl0 &= ~AR_RTSEnable;
341                         ds_ctl0 |= AR_CTSEnable;
342                 }
343
344                 ads->ds_ctl0 = ds_ctl0;
345         } else {
346                 ads->ds_ctl0 =
347                         (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
348         }
349
350         ads->ds_ctl2 = set11nTries(series, 0)
351                 | set11nTries(series, 1)
352                 | set11nTries(series, 2)
353                 | set11nTries(series, 3)
354                 | (durUpdateEn ? AR_DurUpdateEna : 0)
355                 | SM(0, AR_BurstDur);
356
357         ads->ds_ctl3 = set11nRate(series, 0)
358                 | set11nRate(series, 1)
359                 | set11nRate(series, 2)
360                 | set11nRate(series, 3);
361
362         ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
363                 | set11nPktDurRTSCTS(series, 1);
364
365         ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
366                 | set11nPktDurRTSCTS(series, 3);
367
368         ads->ds_ctl7 = set11nRateFlags(series, 0)
369                 | set11nRateFlags(series, 1)
370                 | set11nRateFlags(series, 2)
371                 | set11nRateFlags(series, 3)
372                 | SM(rtsctsRate, AR_RTSCTSRate);
373         last_ads->ds_ctl2 = ads->ds_ctl2;
374         last_ads->ds_ctl3 = ads->ds_ctl3;
375 }
376
377 static void ar9002_hw_set11n_aggr_first(struct ath_hw *ah, void *ds,
378                                         u32 aggrLen)
379 {
380         struct ar5416_desc *ads = AR5416DESC(ds);
381
382         ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
383         ads->ds_ctl6 &= ~AR_AggrLen;
384         ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
385 }
386
387 static void ar9002_hw_set11n_aggr_middle(struct ath_hw *ah, void *ds,
388                                          u32 numDelims)
389 {
390         struct ar5416_desc *ads = AR5416DESC(ds);
391         unsigned int ctl6;
392
393         ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
394
395         ctl6 = ads->ds_ctl6;
396         ctl6 &= ~AR_PadDelim;
397         ctl6 |= SM(numDelims, AR_PadDelim);
398         ads->ds_ctl6 = ctl6;
399 }
400
401 static void ar9002_hw_set11n_aggr_last(struct ath_hw *ah, void *ds)
402 {
403         struct ar5416_desc *ads = AR5416DESC(ds);
404
405         ads->ds_ctl1 |= AR_IsAggr;
406         ads->ds_ctl1 &= ~AR_MoreAggr;
407         ads->ds_ctl6 &= ~AR_PadDelim;
408 }
409
410 static void ar9002_hw_clr11n_aggr(struct ath_hw *ah, void *ds)
411 {
412         struct ar5416_desc *ads = AR5416DESC(ds);
413
414         ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
415 }
416
417 static void ar9002_hw_set11n_burstduration(struct ath_hw *ah, void *ds,
418                                            u32 burstDuration)
419 {
420         struct ar5416_desc *ads = AR5416DESC(ds);
421
422         ads->ds_ctl2 &= ~AR_BurstDur;
423         ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
424 }
425
426 static void ar9002_hw_set11n_virtualmorefrag(struct ath_hw *ah, void *ds,
427                                             u32 vmf)
428 {
429         struct ar5416_desc *ads = AR5416DESC(ds);
430
431         if (vmf)
432                 ads->ds_ctl0 |= AR_VirtMoreFrag;
433         else
434                 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
435 }
436
437 void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
438                           u32 size, u32 flags)
439 {
440         struct ar5416_desc *ads = AR5416DESC(ds);
441         struct ath9k_hw_capabilities *pCap = &ah->caps;
442
443         ads->ds_ctl1 = size & AR_BufLen;
444         if (flags & ATH9K_RXDESC_INTREQ)
445                 ads->ds_ctl1 |= AR_RxIntrReq;
446
447         ads->ds_rxstatus8 &= ~AR_RxDone;
448         if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
449                 memset(&(ads->u), 0, sizeof(ads->u));
450 }
451 EXPORT_SYMBOL(ath9k_hw_setuprxdesc);
452
453 void ar9002_hw_attach_mac_ops(struct ath_hw *ah)
454 {
455         struct ath_hw_ops *ops = ath9k_hw_ops(ah);
456
457         ops->rx_enable = ar9002_hw_rx_enable;
458         ops->set_desc_link = ar9002_hw_set_desc_link;
459         ops->get_desc_link = ar9002_hw_get_desc_link;
460         ops->get_isr = ar9002_hw_get_isr;
461         ops->fill_txdesc = ar9002_hw_fill_txdesc;
462         ops->proc_txdesc = ar9002_hw_proc_txdesc;
463         ops->set11n_txdesc = ar9002_hw_set11n_txdesc;
464         ops->set11n_ratescenario = ar9002_hw_set11n_ratescenario;
465         ops->set11n_aggr_first = ar9002_hw_set11n_aggr_first;
466         ops->set11n_aggr_middle = ar9002_hw_set11n_aggr_middle;
467         ops->set11n_aggr_last = ar9002_hw_set11n_aggr_last;
468         ops->clr11n_aggr = ar9002_hw_clr11n_aggr;
469         ops->set11n_burstduration = ar9002_hw_set11n_burstduration;
470         ops->set11n_virtualmorefrag = ar9002_hw_set11n_virtualmorefrag;
471 }