nuke ath_hal_*xstbcsupport
[open-ath9k-htc-firmware.git] / target_firmware / wlan / ar5416_hw.c
1 /*
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted (subject to the limitations in the
7  * disclaimer below) provided that the following conditions are met:
8  *
9  *  * Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *  * Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the
15  *    distribution.
16  *
17  *  * Neither the name of Qualcomm Atheros nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22  * GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 #include "opt_ah.h"
37 #include "ah.h"
38 #include "ah_internal.h"
39 #include "ar5416.h"
40 #include "ar5416reg.h"
41 #include "ar5416phy.h"
42 #include "ar5416desc.h"
43
44 #define N(a) (sizeof(a)/sizeof(a[0]))
45 #define AR_INTR_SPURIOUS 0xffffffff
46 #define ar5416_desc ar5416_desc_20
47 #define AR5416_ABORT_LOOPS 1000
48 #define AR5416_ABORT_WAIT  5
49 #define AR5416DESC         AR5416DESC_20
50 #define AR5416DESC_CONST   AR5416DESC_CONST_20
51
52 /*****************/
53 /* Attach/Detach */
54 /*****************/
55
56 static const struct ath_hal_private ar5416hal_10 = {{
57                 .ah_getRateTable        = ar5416GetRateTable,
58                 .ah_detach              = ar5416Detach,
59
60                 /* Transmit functions */
61                 .ah_updateTxTrigLevel   = ar5416UpdateTxTrigLevel,
62                 .ah_getTxDP             = ar5416GetTxDP,
63                 .ah_setTxDP             = ar5416SetTxDP,
64                 .ah_numTxPending        = ar5416NumTxPending,    
65                 .ah_startTxDma          = ar5416StartTxDma,
66                 .ah_stopTxDma           = ar5416StopTxDma,
67         
68                 .ah_getTxIntrQueue      = ar5416GetTxIntrQueue,
69                 .ah_abortTxDma          = ar5416AbortTxDma,
70
71                 /* Misc Functions */
72                 .ah_getCapability       = ar5416GetCapability,
73                 .ah_getTsf32            = ar5416GetTsf32,
74                 .ah_getTsf64            = ar5416GetTsf64,
75                 .ah_resetTsf            = ar5416ResetTsf,
76                 .ah_setRxFilter         = ar5416SetRxFilter,
77
78                 /* RX Functions */
79                 .ah_getRxDP             = ar5416GetRxDP,
80                 .ah_setRxDP             = ar5416SetRxDP,
81                 .ah_stopDmaReceive      = ar5416StopDmaReceive,
82                 .ah_enableReceive       = ar5416EnableReceive,
83                 .ah_startPcuReceive     = ar5416StartPcuReceive,
84                 .ah_stopPcuReceive      = ar5416StopPcuReceive,
85
86                 /* Interrupt Functions */
87                 .ah_isInterruptPending   = ar5416IsInterruptPending,
88                 .ah_getPendingInterrupts = ar5416GetPendingInterrupts,
89                 .ah_getInterrupts        = ar5416GetInterrupts,
90                 .ah_setInterrupts        = ar5416SetInterrupts,
91         },
92 };
93
94 void ar5416Detach(struct ath_hal *ah)
95 {
96         HALASSERT(ah != AH_NULL);
97         ath_hal_free(ah);
98 }
99
100 struct ath_hal *
101 ar5416Attach(a_uint32_t devid,HAL_SOFTC sc, adf_os_device_t dev,
102              a_uint32_t flags, HAL_STATUS *status)
103 {
104         struct ath_hal_5416 *ahp;
105         struct ath_hal *ah;
106
107         ahp = ath_hal_malloc(sizeof (struct ath_hal_5416));
108         if (ahp == AH_NULL) {
109                 *status = HAL_ENOMEM;
110                 return AH_NULL;
111         }
112         ah = &ahp->ah_priv.h;
113
114         OS_MEMCPY(&ahp->ah_priv, &ar5416hal_10, sizeof(struct ath_hal_private));
115
116         ah->ah_dev = dev;
117         ah->ah_sc = sc;
118         
119         /* If its a Owl 2.0 chip then change the hal structure to
120            point to the Owl 2.0 ar5416_hal_20 structure */
121         if(1) {
122                 ah->ah_set11nTxDesc        = ar5416Set11nTxDesc_20;
123                 ah->ah_set11nRateScenario  = ar5416Set11nRateScenario_20;
124                 ah->ah_set11nAggrFirst     = ar5416Set11nAggrFirst_20;
125                 ah->ah_set11nAggrMiddle    = ar5416Set11nAggrMiddle_20;
126                 ah->ah_set11nAggrLast      = ar5416Set11nAggrLast_20;
127                 ah->ah_clr11nAggr          = ar5416Clr11nAggr_20;
128                 ah->ah_set11nBurstDuration = ar5416Set11nBurstDuration_20;
129                 ah->ah_setupRxDesc         = ar5416SetupRxDesc_20;
130                 ah->ah_procRxDescFast      = ar5416ProcRxDescFast_20;
131                 ah->ah_updateCTSForBursting = NULL;
132                 ah->ah_setupTxDesc         = ar5416SetupTxDesc_20;
133                 ah->ah_reqTxIntrDesc       = ar5416IntrReqTxDesc_20;
134                 ah->ah_fillTxDesc          = ar5416FillTxDesc_20;
135                 ah->ah_fillKeyTxDesc       = ar5416FillKeyTxDesc_20;
136                 ah->ah_procTxDesc          = ar5416ProcTxDesc_20;
137                 ah->ah_set11nVirtualMoreFrag = ar5416Set11nVirtualMoreFrag_20;
138         }
139
140         return ah;
141 }
142
143 /**********************/
144 /* Interrupt Handling */
145 /**********************/
146
147 HAL_BOOL ar5416IsInterruptPending(struct ath_hal *ah)
148 {
149         a_uint32_t host_isr = OS_REG_READ(ah, AR_INTR_ASYNC_CAUSE);
150         /*
151          * Some platforms trigger our ISR before applying power to
152          * the card, so make sure.
153          */
154         return ((host_isr != AR_INTR_SPURIOUS) && (host_isr & AR_INTR_MAC_IRQ));
155 }
156
157 HAL_BOOL ar5416GetPendingInterrupts(struct ath_hal *ah, HAL_INT *masked)
158 {
159         a_uint32_t isr;
160 #ifndef AR9100
161         HAL_BOOL fatal_int = AH_FALSE;
162         a_uint32_t sync_cause;
163
164         if (OS_REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
165                 if ((OS_REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M) != AR_RTC_STATUS_ON) {
166                         *masked = 0;
167                         return AH_FALSE;
168                 }
169         } else {
170                 *masked = 0;
171                 return AH_FALSE;
172         }
173 #endif
174         isr = OS_REG_READ(ah, AR_ISR_RAC);
175         if (isr == 0xffffffff) {
176                 *masked = 0;
177                 return AH_FALSE;
178         }
179
180         *masked = isr & HAL_INT_COMMON;
181
182 #ifdef AR5416_INT_MITIGATION
183         if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM)) {
184                 *masked |= HAL_INT_RX;
185         }
186         if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM)) {
187                 *masked |= HAL_INT_TX;
188         }
189 #endif
190
191         if (isr & AR_ISR_BCNMISC) {
192                 a_uint32_t s2_s;
193
194                 s2_s = OS_REG_READ(ah, AR_ISR_S2_S);
195
196                 if (s2_s & AR_ISR_S2_GTT) {
197                         *masked |= HAL_INT_GTT;
198                 }
199
200                 if (s2_s & AR_ISR_S2_CST) {
201                         *masked |= HAL_INT_CST;
202                 }
203         }
204
205         if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
206                 *masked |= HAL_INT_RX;
207         if (isr & (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR | AR_ISR_TXEOL)) {
208                 struct ath_hal_5416 *ahp = AH5416(ah);
209                 a_uint32_t           s0_s, s1_s;
210
211                 *masked |= HAL_INT_TX;
212                 s0_s = OS_REG_READ(ah, AR_ISR_S0_S);
213                 s1_s = OS_REG_READ(ah, AR_ISR_S1_S);
214                 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
215                 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
216                 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
217                 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
218         }
219
220 #ifndef AR9100
221         sync_cause = OS_REG_READ(ah, AR_INTR_SYNC_CAUSE);
222         fatal_int = ((sync_cause != AR_INTR_SPURIOUS) &&
223                      (sync_cause & (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))) ?
224                 AH_TRUE : AH_FALSE;
225
226         if (AH_TRUE == fatal_int) {
227                 OS_REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
228                 (void) OS_REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
229         }
230 #endif
231         return AH_TRUE;
232 }
233
234 HAL_INT ar5416GetInterrupts(struct ath_hal *ah)
235 {
236         return AH5416(ah)->ah_maskReg;
237 }
238
239 HAL_INT
240 ar5416SetInterrupts(struct ath_hal *ah, HAL_INT ints)
241 {
242         struct ath_hal_5416 *ahp = AH5416(ah);
243         a_uint32_t omask = ahp->ah_maskReg;
244         a_uint32_t mask;
245
246         if (omask & HAL_INT_GLOBAL) {
247                 OS_REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
248                 (void) OS_REG_READ(ah, AR_IER);
249         }
250
251         mask = ints & HAL_INT_COMMON;
252         if (ints & HAL_INT_TX) {
253 #ifdef AR5416_INT_MITIGATION
254                 mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM;
255 #else
256                 mask |= AR_IMR_TXOK;
257                 mask |= AR_IMR_TXDESC;
258 #endif
259                 mask |= AR_IMR_TXERR;
260                 mask |= AR_IMR_TXEOL;
261         }
262         if (ints & HAL_INT_RX) {
263                 mask |= AR_IMR_RXERR;
264 #ifdef AR5416_INT_MITIGATION
265                 mask |=  AR_IMR_RXMINTR | AR_IMR_RXINTM;
266 #else
267                 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
268 #endif
269         }
270
271         if (ints & (HAL_INT_GTT | HAL_INT_CST)) {
272                 mask |= AR_IMR_BCNMISC;
273         }
274
275         OS_REG_WRITE(ah, AR_IMR, mask);
276         (void) OS_REG_READ(ah, AR_IMR);
277         ahp->ah_maskReg = ints;
278
279         /* Re-enable interrupts if they were enabled before. */
280         if (ints & HAL_INT_GLOBAL) {
281                 OS_REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
282                 /* See explanation above... */
283                 (void) OS_REG_READ(ah, AR_IER);
284         }
285
286         OS_REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, AR_INTR_MAC_IRQ);
287         OS_REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
288         OS_REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_ALL);
289
290         return omask;
291 }
292
293 /****************/
294 /* Capabilities */
295 /****************/
296
297 HAL_STATUS ar5416GetCapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
298                                a_uint32_t capability, a_uint32_t *result)
299
300 {
301         return ath_hal_getcapability(ah, type, capability, result);
302 }
303
304 /****************/
305 /* TSF Handling */
306 /****************/
307
308 u_int64_t ar5416GetTsf64(struct ath_hal *ah)
309 {
310         u_int64_t tsf;
311
312         tsf = OS_REG_READ(ah, AR_TSF_U32);
313         tsf = (tsf << 32) | OS_REG_READ(ah, AR_TSF_L32);
314
315         return tsf;
316 }
317
318 a_uint32_t ar5416GetTsf32(struct ath_hal *ah)
319 {
320         return OS_REG_READ(ah, AR_TSF_L32);
321 }
322
323 void ar5416ResetTsf(struct ath_hal *ah)
324 {
325         a_int32_t count;
326
327         count = 0;
328
329         while (OS_REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) {
330                 count++;
331                 if (count > 10) {
332                         break;
333                 }
334                 OS_DELAY(10);
335         }
336         OS_REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
337 }
338
339 /******/
340 /* RX */
341 /******/
342
343 a_uint32_t ar5416GetRxDP(struct ath_hal *ath)
344 {
345         return OS_REG_READ(ath, AR_RXDP);
346 }
347
348
349 void ar5416SetRxDP(struct ath_hal *ah, a_uint32_t rxdp)
350 {
351         OS_REG_WRITE(ah, AR_RXDP, rxdp);
352         HALASSERT(OS_REG_READ(ah, AR_RXDP) == rxdp);
353 }
354
355 void ar5416SetMulticastFilter(struct ath_hal *ah, a_uint32_t filter0, a_uint32_t filter1)
356 {
357         OS_REG_WRITE(ah, AR_MCAST_FIL0, filter0);
358         OS_REG_WRITE(ah, AR_MCAST_FIL1, filter1);
359 }
360
361 HAL_BOOL ar5416ClrMulticastFilterIndex(struct ath_hal *ah, a_uint32_t ix)
362 {
363         a_uint32_t val;
364
365         if (ix >= 64)
366                 return AH_FALSE;
367         if (ix >= 32) {
368                 val = OS_REG_READ(ah, AR_MCAST_FIL1);
369                 OS_REG_WRITE(ah, AR_MCAST_FIL1, (val &~ (1<<(ix-32))));
370         } else {
371                 val = OS_REG_READ(ah, AR_MCAST_FIL0);
372                 OS_REG_WRITE(ah, AR_MCAST_FIL0, (val &~ (1<<ix)));
373         }
374         return AH_TRUE;
375 }
376
377 HAL_BOOL ar5416StopDmaReceive(struct ath_hal *ah)
378 {
379         OS_REG_WRITE(ah, AR_CR, AR_CR_RXD); /* Set receive disable bit */
380         if (!ath_hal_wait(ah, AR_CR, AR_CR_RXE, 0)) {
381                 return AH_FALSE;
382         } else {
383                 return AH_TRUE;
384         }
385 }
386
387 HAL_BOOL ar5416SetMulticastFilterIndex(struct ath_hal *ah, a_uint32_t ix)
388 {
389         a_uint32_t val;
390
391         if (ix >= 64)
392                 return AH_FALSE;
393         if (ix >= 32) {
394                 val = OS_REG_READ(ah, AR_MCAST_FIL1);
395                 OS_REG_WRITE(ah, AR_MCAST_FIL1, (val | (1<<(ix-32))));
396         } else {
397                 val = OS_REG_READ(ah, AR_MCAST_FIL0);
398                 OS_REG_WRITE(ah, AR_MCAST_FIL0, (val | (1<<ix)));
399         }
400         return AH_TRUE;
401 }
402
403 void ar5416StartPcuReceive(struct ath_hal *ah)
404 {
405         OS_REG_CLR_BIT(ah, AR_DIAG_SW,
406                        (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
407 }
408
409 void ar5416SetRxFilter(struct ath_hal *ah, a_uint32_t bits)
410 {
411         a_uint32_t phybits;
412     
413         OS_REG_WRITE(ah, AR_RX_FILTER, (bits & 0xff) | AR_RX_COMPR_BAR);
414         phybits = 0;
415         if (bits & HAL_RX_FILTER_PHYRADAR)
416                 phybits |= AR_PHY_ERR_RADAR;
417         if (bits & HAL_RX_FILTER_PHYERR)
418                 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
419         OS_REG_WRITE(ah, AR_PHY_ERR, phybits);
420         if (phybits) {
421                 OS_REG_WRITE(ah, AR_RXCFG,OS_REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
422         } else {
423                 OS_REG_WRITE(ah, AR_RXCFG,OS_REG_READ(ah, AR_RXCFG) &~ AR_RXCFG_ZLFDMA);
424         }
425 }
426
427 void ar5416EnableReceive(struct ath_hal *ah)
428 {
429         OS_REG_WRITE(ah, AR_CR, AR_CR_RXE);
430 }
431
432 void ar5416StopPcuReceive(struct ath_hal *ah)
433 {
434         OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
435 }
436
437 HAL_BOOL ar5416SetupRxDesc_20(struct ath_hal *ah, struct ath_rx_desc *ds,
438                               a_uint32_t size, a_uint32_t flags)
439 {
440         struct ar5416_desc *ads = AR5416DESC(ds);
441
442         HALASSERT((size &~ AR_BufLen) == 0);
443
444         ads->ds_ctl1 = size & AR_BufLen;
445         if (flags & HAL_RXDESC_INTREQ)
446                 ads->ds_ctl1 |= AR_RxIntrReq;
447
448         /* this should be enough */
449         ads->ds_rxstatus8 &= ~AR_RxDone;
450
451         return AH_TRUE;
452 }
453
454 HAL_STATUS ar5416ProcRxDescFast_20(struct ath_hal *ah, struct ath_rx_desc *ds,
455                                    a_uint32_t pa, struct ath_desc *nds,
456                                    struct ath_rx_status *rx_stats)
457 {
458         struct ar5416_desc ads;
459         struct ar5416_desc *adsp = AR5416DESC(ds);
460         struct ar5416_desc *ands = AR5416DESC(nds);
461
462         if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
463                 return HAL_EINPROGRESS;
464         /*
465          * Given the use of a self-linked tail be very sure that the hw is
466          * done with this descriptor; the hw may have done this descriptor
467          * once and picked it up again...make sure the hw has moved on.
468          */
469         if ((ands->ds_rxstatus8 & AR_RxDone) == 0
470             && OS_REG_READ(ah, AR_RXDP) == pa)
471                 return HAL_EINPROGRESS;
472
473         /*
474          * Now we need to get the stats from the descriptor. Since desc are 
475          * uncached, lets make a copy of the stats first. Note that, since we
476          * touch most of the rx stats, a memcpy would always be more efficient
477          *
478          * Next we fill in all values in a caller passed stack variable.
479          * This reduces the number of uncached accesses.
480          * Do this copy here, after the check so that when the checks fail, we
481          * dont end up copying the entire stats uselessly.
482          */
483         ads.u.rx = adsp->u.rx;
484
485         rx_stats->rs_status = 0;
486         rx_stats->rs_flags = 0;
487
488         rx_stats->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
489         rx_stats->rs_tstamp =  ads.AR_RcvTimestamp;
490
491         /* XXX what about KeyCacheMiss? */
492         rx_stats->rs_rssi_combined = 
493                 MS(ads.ds_rxstatus4, AR_RxRSSICombined);
494         rx_stats->rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00);
495         rx_stats->rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01);
496         rx_stats->rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02);
497         rx_stats->rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10);
498         rx_stats->rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11);
499         rx_stats->rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12);
500         if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
501                 rx_stats->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
502         else
503                 rx_stats->rs_keyix = HAL_RXKEYIX_INVALID;
504         /* NB: caller expected to do rate table mapping */
505         rx_stats->rs_rate = RXSTATUS_RATE(ah, (&ads));
506         rx_stats->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
507
508         rx_stats->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
509         rx_stats->rs_moreaggr = (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
510         rx_stats->rs_flags  |= (ads.ds_rxstatus3 & AR_GI) ? HAL_RX_GI : 0;
511         rx_stats->rs_flags  |= (ads.ds_rxstatus3 & AR_2040) ? HAL_RX_2040 : 0;
512
513         if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
514                 rx_stats->rs_flags |= HAL_RX_DELIM_CRC_PRE;
515         if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
516                 rx_stats->rs_flags |= HAL_RX_DELIM_CRC_POST;
517         if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
518                 rx_stats->rs_flags |= HAL_RX_DECRYPT_BUSY;
519
520         if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
521                 /*
522                  * These four bits should not be set together.  The
523                  * 5416 spec states a Michael error can only occur if
524                  * DecryptCRCErr not set (and TKIP is used).  Experience
525                  * indicates however that you can also get Michael errors
526                  * when a CRC error is detected, but these are specious.
527                  * Consequently we filter them out here so we don't
528                  * confuse and/or complicate drivers.
529                  */
530                 if (ads.ds_rxstatus8 & AR_CRCErr)
531                         rx_stats->rs_status |= HAL_RXERR_CRC;
532                 else if (ads.ds_rxstatus8 & AR_PHYErr) {
533                         a_uint32_t phyerr;
534
535                         rx_stats->rs_status |= HAL_RXERR_PHY;
536                         phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
537                         rx_stats->rs_phyerr = phyerr;
538                 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
539                         rx_stats->rs_status |= HAL_RXERR_DECRYPT;
540                 else if (ads.ds_rxstatus8 & AR_MichaelErr)
541                         rx_stats->rs_status |= HAL_RXERR_MIC;
542         }
543         rx_stats->evm0=ads.AR_RxEVM0;
544         rx_stats->evm1=ads.AR_RxEVM1;
545         rx_stats->evm2=ads.AR_RxEVM2;
546
547         return HAL_OK;
548 }
549
550 /******/
551 /* TX */
552 /******/
553
554 HAL_BOOL ar5416UpdateTxTrigLevel(struct ath_hal *ah, HAL_BOOL bIncTrigLevel)
555 {
556         struct ath_hal_5416 *ahp = AH5416(ah);
557         a_uint32_t txcfg, curLevel, newLevel;
558         HAL_INT omask;
559
560         /*
561          * Disable interrupts while futzing with the fifo level.
562          */
563         omask = ar5416SetInterrupts(ah, ahp->ah_maskReg &~ HAL_INT_GLOBAL);
564
565         txcfg = OS_REG_READ(ah, AR_TXCFG);
566         curLevel = MS(txcfg, AR_FTRIG);
567         newLevel = curLevel;
568
569         if (bIncTrigLevel)  {
570                 if (curLevel < MAX_TX_FIFO_THRESHOLD)
571                         newLevel ++;
572         } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
573                 newLevel--;
574         if (newLevel != curLevel)
575                 OS_REG_WRITE(ah, AR_TXCFG,
576                              (txcfg &~ AR_FTRIG) | SM(newLevel, AR_FTRIG));
577
578         /* re-enable chip interrupts */
579         ar5416SetInterrupts(ah, omask);
580
581         return (newLevel != curLevel);
582 }
583
584 a_uint32_t ar5416GetTxDP(struct ath_hal *ah, a_uint32_t q)
585 {
586         HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
587         return OS_REG_READ(ah, AR_QTXDP(q));
588 }
589
590 HAL_BOOL ar5416SetTxDP(struct ath_hal *ah, a_uint32_t q, a_uint32_t txdp)
591 {
592         HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
593         HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
594
595         /*
596          * Make sure that TXE is deasserted before setting the TXDP.  If TXE
597          * is still asserted, setting TXDP will have no effect.
598          */
599         HALASSERT((OS_REG_READ(ah, AR_Q_TXE) & (1 << q)) == 0);
600
601         OS_REG_WRITE(ah, AR_QTXDP(q), txdp);
602
603         return AH_TRUE;
604 }
605
606 HAL_BOOL ar5416StartTxDma(struct ath_hal *ah, a_uint32_t q)
607 {
608         HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
609         HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
610
611         /* Check to be sure we're not enabling a q that has its TXD bit set. */
612         HALASSERT((OS_REG_READ(ah, AR_Q_TXD) & (1 << q)) == 0);
613
614         OS_REG_WRITE(ah, AR_Q_TXE, 1 << q);
615
616         return AH_TRUE;
617 }
618
619 a_uint32_t ar5416NumTxPending(struct ath_hal *ah, a_uint32_t q)
620 {
621         a_uint32_t npend;
622
623         HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
624         HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
625
626         npend = OS_REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
627         if (npend == 0) {
628                 /*
629                  * Pending frame count (PFC) can momentarily go to zero
630                  * while TXE remains asserted.  In other words a PFC of
631                  * zero is not sufficient to say that the queue has stopped.
632                  */
633                 if (OS_REG_READ(ah, AR_Q_TXE) & (1 << q))
634                         npend = 1;
635         }
636 #ifdef DEBUG
637         if (npend && (AH5416(ah)->ah_txq[q].tqi_type == HAL_TX_QUEUE_CAB)) {
638                 if (OS_REG_READ(ah, AR_Q_RDYTIMESHDN) & (1 << q)) {
639                         isrPrintf("RTSD on CAB queue\n");
640                         /* Clear the ReadyTime shutdown status bits */
641                         OS_REG_WRITE(ah, AR_Q_RDYTIMESHDN, 1 << q);
642                 }
643         }
644 #endif
645         return npend;
646 }
647
648 HAL_BOOL ar5416AbortTxDma(struct ath_hal *ah)
649 {
650         a_int32_t i, q;
651
652         /*
653          * set txd on all queues
654          */
655         OS_REG_WRITE(ah, AR_Q_TXD, AR_Q_TXD_M);
656
657         /*
658          * set tx abort bits
659          */
660         OS_REG_SET_BIT(ah, AR_PCU_MISC, (AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF));
661         OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
662         OS_REG_SET_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
663
664         /*
665          * wait on all tx queues
666          */
667         for (q = 0; q < AR_NUM_QCU; q++) {
668                 for (i = 0; i < AR5416_ABORT_LOOPS; i++) {
669                         if (!ar5416NumTxPending(ah, q))
670                                 break;
671
672                         OS_DELAY(AR5416_ABORT_WAIT);
673                 }
674                 if (i == AR5416_ABORT_LOOPS) {
675                         return AH_FALSE;
676                 }
677         }
678
679         /*
680          * clear tx abort bits
681          */
682         OS_REG_CLR_BIT(ah, AR_PCU_MISC, (AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF));
683         OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
684         OS_REG_CLR_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
685
686         /*
687          * clear txd
688          */
689         OS_REG_WRITE(ah, AR_Q_TXD, 0);
690
691         return AH_TRUE;
692 }
693
694 HAL_BOOL ar5416StopTxDma(struct ath_hal*ah, a_uint32_t q)
695 {
696         a_uint32_t i;
697         
698         HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
699
700         HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
701
702         OS_REG_WRITE(ah, AR_Q_TXD, 1 << q);
703         for (i = 1000; i != 0; i--) {
704                 if (ar5416NumTxPending(ah, q) == 0)
705                         break;
706                 OS_DELAY(100);        /* XXX get actual value */
707         }
708
709         OS_REG_WRITE(ah, AR_Q_TXD, 0);
710         return (i != 0);
711 }
712
713 void ar5416GetTxIntrQueue(struct ath_hal *ah, a_uint32_t *txqs)
714 {
715         struct ath_hal_5416 *ahp = AH5416(ah);
716         *txqs &= ahp->ah_intrTxqs;
717         ahp->ah_intrTxqs &= ~(*txqs);
718 }
719
720 void ar5416IntrReqTxDesc_20(struct ath_hal *ah, struct ath_desc *ds)
721 {
722         struct ar5416_desc *ads = AR5416DESC(ds);
723         ads->ds_ctl0 |= AR_TxIntrReq;
724 }
725
726 HAL_BOOL ar5416SetupTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
727                               a_uint32_t pktLen,
728                               a_uint32_t hdrLen,
729                               HAL_PKT_TYPE type,
730                               a_uint32_t txPower,
731                               a_uint32_t txRate0, a_uint32_t txTries0,
732                               a_uint32_t keyIx,
733                               a_uint32_t antMode,
734                               a_uint32_t flags,
735                               a_uint32_t rtsctsRate,
736                               a_uint32_t rtsctsDuration,
737                               a_uint32_t compicvLen,
738                               a_uint32_t compivLen,
739                               a_uint32_t comp)
740 {
741 #define RTSCTS  (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)
742
743         struct ar5416_desc *ads = AR5416DESC(ds);
744
745         (void) hdrLen;
746
747         ads->ds_txstatus9 &= ~AR_TxDone;
748
749         HALASSERT(txTries0 != 0);
750         HALASSERT(isValidPktType(type));
751         HALASSERT(isValidTxRate(txRate0));
752         HALASSERT((flags & RTSCTS) != RTSCTS);
753
754         if (txPower > 63)
755                 txPower=63;
756
757         ads->ds_ctl0 = (pktLen & AR_FrameLen)
758                 | (txPower << AR_XmitPower_S)
759                 | (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)
760                 | (flags & HAL_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
761                 | (flags & HAL_TXDESC_INTREQ ? AR_TxIntrReq : 0);
762
763         ads->ds_ctl1 = (type << AR_FrameType_S)
764                 | (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0);
765         ads->ds_ctl2 = SM(txTries0, AR_XmitDataTries0);
766         ads->ds_ctl3 = (txRate0 << AR_XmitRate0_S);
767
768         ads->ds_ctl7 = SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel0) 
769                 | SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel1)
770                 | SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel2) 
771                 | SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel3);
772
773         if (keyIx != HAL_TXKEYIX_INVALID) {
774                 /* XXX validate key index */
775                 ads->ds_ctl1 |= SM(keyIx, AR_DestIdx);
776                 ads->ds_ctl0 |= AR_DestIdxValid;
777         }
778
779         if (flags & RTSCTS) {
780                 if (!isValidTxRate(rtsctsRate)) {
781                         return AH_FALSE;
782                 }
783                 /* XXX validate rtsctsDuration */
784                 ads->ds_ctl0 |= (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0)
785                         | (flags & HAL_TXDESC_RTSENA ? AR_RTSEnable : 0);
786                 ads->ds_ctl2 |= SM(rtsctsDuration, AR_BurstDur);
787                 ads->ds_ctl3 |= (rtsctsRate << AR_RTSCTSRate_S);
788         }
789         return AH_TRUE;
790
791 #undef RTSCTS
792 }
793
794 HAL_BOOL ar5416FillTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
795                              a_uint32_t segLen, HAL_BOOL firstSeg, HAL_BOOL lastSeg,
796                              const struct ath_tx_desc *ds0)
797 {
798         struct ar5416_desc *ads = AR5416DESC(ds);
799
800         HALASSERT((segLen &~ AR_BufLen) == 0);
801
802         if (firstSeg) {
803                 /*
804                  * First descriptor, don't clobber xmit control data
805                  * setup by ar5416SetupTxDesc.
806                  */
807                 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
808         } else if (lastSeg) {
809                 /*
810                  * Last descriptor in a multi-descriptor frame,
811                  * copy the multi-rate transmit parameters from
812                  * the first frame for processing on completion.
813                  */
814                 ads->ds_ctl0 = 0;
815                 ads->ds_ctl1 = segLen;
816                 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
817                 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
818         } else {
819                 /*
820                  * Intermediate descriptor in a multi-descriptor frame.
821                  */
822                 ads->ds_ctl0 = 0;
823                 ads->ds_ctl1 = segLen | AR_TxMore;
824                 ads->ds_ctl2 = 0;
825                 ads->ds_ctl3 = 0;
826         }
827         ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
828
829         return AH_TRUE;
830 }
831
832 HAL_BOOL ar5416FillKeyTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
833                                 HAL_KEY_TYPE keyType)
834 {
835         struct ar5416_desc *ads = AR5416DESC(ds);
836
837         ads->ds_ctl6 = SM(keyType, AR_EncrType);
838         return AH_TRUE;
839 }
840
841 HAL_STATUS ar5416ProcTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *gds)
842 {
843         struct ar5416_desc *ads = AR5416DESC(gds);
844         struct ath_tx_desc *ds = (struct ath_tx_desc *)gds;
845         
846         if ((ads->ds_txstatus9 & AR_TxDone) == 0)
847                 return HAL_EINPROGRESS;
848
849         ads->ds_txstatus9 &= ~AR_TxDone;
850
851         /* Update software copies of the HW status */
852         ds->ds_txstat.ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
853         ds->ds_txstat.ts_tstamp = ads->AR_SendTimestamp;
854         ds->ds_txstat.ts_status = 0;
855         ds->ds_txstat.ts_flags  = 0;
856
857         if (ads->ds_txstatus1 & AR_ExcessiveRetries)
858                 ds->ds_txstat.ts_status |= HAL_TXERR_XRETRY;
859         if (ads->ds_txstatus1 & AR_Filtered)
860                 ds->ds_txstat.ts_status |= HAL_TXERR_FILT;
861         if (ads->ds_txstatus1 & AR_FIFOUnderrun)
862                 ds->ds_txstat.ts_status |= HAL_TXERR_FIFO;
863         if (ads->ds_txstatus9 & AR_TxOpExceeded)
864                 ds->ds_txstat.ts_status |= HAL_TXERR_XTXOP;
865         if (ads->ds_txstatus1 & AR_TxTimerExpired)
866                 ds->ds_txstat.ts_status |= HAL_TXERR_TIMER_EXPIRED;
867
868         if (ads->ds_txstatus1 & AR_DescCfgErr)
869                 ds->ds_txstat.ts_flags |= HAL_TX_DESC_CFG_ERR;
870         if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
871                 ds->ds_txstat.ts_flags |= HAL_TX_DATA_UNDERRUN;
872                 ar5416UpdateTxTrigLevel(ah, AH_TRUE);
873         }
874         if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
875                 ds->ds_txstat.ts_flags |= HAL_TX_DELIM_UNDERRUN;
876                 ar5416UpdateTxTrigLevel(ah, AH_TRUE);
877         }
878         if (ads->ds_txstatus0 & AR_TxBaStatus) {
879                 ds->ds_txstat.ts_flags |= HAL_TX_BA;
880                 ds->ds_txstat.ba_low = ads->AR_BaBitmapLow;
881                 ds->ds_txstat.ba_high = ads->AR_BaBitmapHigh;
882         }
883
884         /*
885          * Extract the transmit rate used and mark the rate as
886          * ``alternate'' if it wasn't the series 0 rate.
887          */
888         ds->ds_txstat.ts_rate = MS(ads->ds_txstatus9, AR_FinalTxIdx);
889         ds->ds_txstat.ts_rssi_combined = 
890                 MS(ads->ds_txstatus5, AR_TxRSSICombined);
891         ds->ds_txstat.ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
892         ds->ds_txstat.ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
893         ds->ds_txstat.ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
894         ds->ds_txstat.ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
895         ds->ds_txstat.ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
896         ds->ds_txstat.ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
897         ds->ds_txstat.evm0 = ads->AR_TxEVM0;
898         ds->ds_txstat.evm1 = ads->AR_TxEVM1;
899         ds->ds_txstat.evm2 = ads->AR_TxEVM2;
900         ds->ds_txstat.ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
901         ds->ds_txstat.ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
902         ds->ds_txstat.ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
903         ds->ds_txstat.ts_antenna = 0;           /* ignored for owl */
904
905         return HAL_OK;
906 }
907
908 void ar5416Set11nTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
909                            a_uint32_t pktLen, HAL_PKT_TYPE type, a_uint32_t txPower,
910                            a_uint32_t keyIx, HAL_KEY_TYPE keyType,
911                            a_uint32_t flags)
912 {
913         struct ar5416_desc *ads = AR5416DESC(ds);
914
915         HALASSERT(isValidPktType(type));
916         HALASSERT(isValidKeyType(keyType));
917
918         if (txPower > 63)
919                 txPower = 63;
920
921         ads->ds_ctl0 = (pktLen & AR_FrameLen)
922                 | (flags & HAL_TXDESC_VMF ? AR_VirtMoreFrag : 0)
923                 | SM(txPower, AR_XmitPower)
924                 | (flags & HAL_TXDESC_RTSENA ? AR_RTSEnable : 0)
925                 | (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)
926                 | (flags & HAL_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
927                 | (flags & HAL_TXDESC_INTREQ ? AR_TxIntrReq : 0)
928                 | (keyIx != HAL_TXKEYIX_INVALID ? AR_DestIdxValid : 0)
929                 | (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0);
930
931         ads->ds_ctl1 = (keyIx != HAL_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
932                 | SM(type, AR_FrameType)
933                 | (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0)
934                 | (flags & HAL_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
935                 | (flags & HAL_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
936
937         ads->ds_ctl6 = SM(keyType, AR_EncrType);
938 }
939
940 #ifdef MAGPIE_MERLIN
941
942 void ar5416Set11nRateScenario_20(struct ath_hal *ah, struct ath_tx_desc *ds,
943                                  a_uint32_t durUpdateEn, a_uint32_t rtsctsRate,
944                                  a_uint32_t rtsctsDuration,
945                                  HAL_11N_RATE_SERIES series[], a_uint32_t nseries,
946                                  a_uint32_t flags)
947 {
948         struct ar5416_desc *ads = AR5416DESC(ds);
949         a_uint32_t ds_ctl0;
950
951         HALASSERT(nseries == 4);
952         (void)nseries;
953
954         /*
955          * Rate control settings override
956          */
957         ds_ctl0 = ads->ds_ctl0;
958
959         if (flags & (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) {
960                 if (flags & HAL_TXDESC_RTSENA) {
961                         ds_ctl0 &= ~AR_CTSEnable;
962                         ds_ctl0 |= AR_RTSEnable;
963                 } else {
964                         ds_ctl0 &= ~AR_RTSEnable;
965                         ds_ctl0 |= AR_CTSEnable;
966                 }
967         } else {
968                 ds_ctl0 = (ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
969         }
970
971         ads->ds_ctl0 = ds_ctl0;
972
973         ads->ds_ctl2 = set11nTries(series, 0)
974                 |  set11nTries(series, 1)
975                 |  set11nTries(series, 2)
976                 |  set11nTries(series, 3)
977                 |  (durUpdateEn ? AR_DurUpdateEn : 0);
978
979         ads->ds_ctl3 = set11nRate(series, 0)
980                 |  set11nRate(series, 1)
981                 |  set11nRate(series, 2)
982                 |  set11nRate(series, 3);
983
984         ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
985                 |  set11nPktDurRTSCTS(series, 1);
986
987         ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
988                 |  set11nPktDurRTSCTS(series, 3);
989
990         ads->ds_ctl7 = set11nRateFlags(series, 0)
991                 |  set11nRateFlags(series, 1)
992                 |  set11nRateFlags(series, 2)
993                 |  set11nRateFlags(series, 3)
994                 | SM(rtsctsRate, AR_RTSCTSRate);
995 }
996
997 #else
998
999 void ar5416Set11nRateScenario_20(struct ath_hal *ah, struct ath_tx_desc *ds,
1000                                  a_uint32_t durUpdateEn, a_uint32_t rtsctsRate,
1001                                  a_uint32_t rtsctsDuration,
1002                                  HAL_11N_RATE_SERIES series[], a_uint32_t nseries,
1003                                  a_uint32_t flags)
1004 {
1005         struct ar5416_desc *ads = AR5416DESC(ds);
1006         a_uint32_t ds_ctl0;
1007
1008         HALASSERT(nseries == 4);
1009         (void)nseries;
1010
1011         /*
1012          * Rate control settings override
1013          */
1014         if (flags & (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) {
1015                 ds_ctl0 = ads->ds_ctl0;
1016
1017                 if (flags & HAL_TXDESC_RTSENA) {
1018                         ds_ctl0 &= ~AR_CTSEnable;
1019                         ds_ctl0 |= AR_RTSEnable;
1020                 } else {
1021                         ds_ctl0 &= ~AR_RTSEnable;
1022                         ds_ctl0 |= AR_CTSEnable;
1023                 }
1024
1025                 ads->ds_ctl0 = ds_ctl0;
1026         }
1027
1028         ads->ds_ctl2 = set11nTries(series, 0)
1029                 |  set11nTries(series, 1)
1030                 |  set11nTries(series, 2)
1031                 |  set11nTries(series, 3)
1032                 |  (durUpdateEn ? AR_DurUpdateEn : 0);
1033
1034         ads->ds_ctl3 = set11nRate(series, 0)
1035                 |  set11nRate(series, 1)
1036                 |  set11nRate(series, 2)
1037                 |  set11nRate(series, 3);
1038
1039         ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
1040                 |  set11nPktDurRTSCTS(series, 1);
1041
1042         ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
1043                 |  set11nPktDurRTSCTS(series, 3);
1044
1045         ads->ds_ctl7 = set11nRateFlags(series, 0)
1046                 |  set11nRateFlags(series, 1)
1047                 |  set11nRateFlags(series, 2)
1048                 |  set11nRateFlags(series, 3)
1049                 | SM(rtsctsRate, AR_RTSCTSRate);
1050 }
1051
1052 #endif
1053
1054 void ar5416Set11nAggrFirst_20(struct ath_hal *ah, struct ath_tx_desc *ds, a_uint32_t aggrLen,
1055                               a_uint32_t numDelims)
1056 {
1057         struct ar5416_desc *ads = AR5416DESC(ds);
1058
1059         ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
1060
1061         ads->ds_ctl6 &= ~(AR_AggrLen | AR_PadDelim);
1062         ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen) |
1063                 SM(numDelims, AR_PadDelim);
1064 }
1065
1066 void ar5416Set11nAggrMiddle_20(struct ath_hal *ah, struct ath_tx_desc *ds, a_uint32_t numDelims)
1067 {
1068         struct ar5416_desc *ads = AR5416DESC(ds);
1069         a_uint32_t ctl6;
1070
1071         ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
1072
1073         /*
1074          * We use a stack variable to manipulate ctl6 to reduce uncached 
1075          * read modify, modfiy, write.
1076          */
1077         ctl6 = ads->ds_ctl6;
1078         ctl6 &= ~AR_PadDelim;
1079         ctl6 |= SM(numDelims, AR_PadDelim);
1080         ads->ds_ctl6 = ctl6;
1081 }
1082
1083 void ar5416Set11nAggrLast_20(struct ath_hal *ah, struct ath_tx_desc *ds)
1084 {
1085         struct ar5416_desc *ads = AR5416DESC(ds);
1086
1087         ads->ds_ctl1 |= AR_IsAggr;
1088         ads->ds_ctl1 &= ~AR_MoreAggr;
1089         ads->ds_ctl6 &= ~AR_PadDelim;
1090 }
1091
1092 void ar5416Clr11nAggr_20(struct ath_hal *ah, struct ath_tx_desc *ds)
1093 {
1094         struct ar5416_desc *ads = AR5416DESC(ds);
1095
1096         ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
1097 }
1098
1099 void ar5416Set11nBurstDuration_20(struct ath_hal *ah, struct ath_tx_desc *ds,
1100                                   a_uint32_t burstDuration)
1101 {
1102         struct ar5416_desc *ads = AR5416DESC(ds);
1103
1104         ads->ds_ctl2 &= ~AR_BurstDur;
1105         ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
1106 }
1107
1108 void ar5416Set11nVirtualMoreFrag_20(struct ath_hal *ah, struct ath_tx_desc *ds,
1109                                     a_uint32_t vmf)
1110 {
1111         struct ar5416_desc *ads = AR5416DESC(ds);
1112
1113         if (vmf) {
1114                 ads->ds_ctl0 |= AR_VirtMoreFrag;
1115         } else {
1116                 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
1117         }
1118 }