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