2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
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:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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
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.
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.
37 #include "ah_internal.h"
39 #include "ar5416reg.h"
40 #include "ar5416desc.h"
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
54 static const struct ath_hal_private ar5416hal_10 = {{
55 .ah_getRateTable = ar5416GetRateTable,
56 .ah_detach = ar5416Detach,
58 /* Transmit functions */
59 .ah_updateTxTrigLevel = ar5416UpdateTxTrigLevel,
60 .ah_setTxDP = ar5416SetTxDP,
61 .ah_numTxPending = ar5416NumTxPending,
62 .ah_startTxDma = ar5416StartTxDma,
63 .ah_stopTxDma = ar5416StopTxDma,
65 .ah_abortTxDma = ar5416AbortTxDma,
68 .ah_getTsf64 = ar5416GetTsf64,
69 .ah_setRxFilter = ar5416SetRxFilter,
72 .ah_getRxDP = ar5416GetRxDP,
73 .ah_setRxDP = ar5416SetRxDP,
74 .ah_stopDmaReceive = ar5416StopDmaReceive,
75 .ah_enableReceive = ar5416EnableReceive,
76 .ah_startPcuReceive = ar5416StartPcuReceive,
77 .ah_stopPcuReceive = ar5416StopPcuReceive,
79 /* Interrupt Functions */
80 .ah_isInterruptPending = ar5416IsInterruptPending,
81 .ah_getPendingInterrupts = ar5416GetPendingInterrupts,
82 .ah_getInterrupts = ar5416GetInterrupts,
83 .ah_setInterrupts = ar5416SetInterrupts,
87 void ar5416Detach(struct ath_hal *ah)
89 HALASSERT(ah != AH_NULL);
94 ar5416Attach(a_uint32_t devid,HAL_SOFTC sc, adf_os_device_t dev,
95 a_uint32_t flags, HAL_STATUS *status)
97 struct ath_hal_5416 *ahp;
100 ahp = ath_hal_malloc(sizeof (struct ath_hal_5416));
101 if (ahp == AH_NULL) {
102 *status = HAL_ENOMEM;
105 ah = &ahp->ah_priv.h;
107 OS_MEMCPY(&ahp->ah_priv, &ar5416hal_10, sizeof(struct ath_hal_private));
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 */
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;
136 /**********************/
137 /* Interrupt Handling */
138 /**********************/
140 HAL_BOOL ar5416IsInterruptPending(struct ath_hal *ah)
142 a_uint32_t host_isr = OS_REG_READ(ah, AR_INTR_ASYNC_CAUSE);
144 * Some platforms trigger our ISR before applying power to
145 * the card, so make sure.
147 return ((host_isr != AR_INTR_SPURIOUS) && (host_isr & AR_INTR_MAC_IRQ));
150 HAL_BOOL ar5416GetPendingInterrupts(struct ath_hal *ah, HAL_INT *masked)
154 HAL_BOOL fatal_int = AH_FALSE;
155 a_uint32_t sync_cause;
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) {
167 isr = OS_REG_READ(ah, AR_ISR_RAC);
168 if (isr == 0xffffffff) {
173 *masked = isr & HAL_INT_COMMON;
175 #ifdef AR5416_INT_MITIGATION
176 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM)) {
177 *masked |= HAL_INT_RX;
179 if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM)) {
180 *masked |= HAL_INT_TX;
184 if (isr & AR_ISR_BCNMISC) {
187 s2_s = OS_REG_READ(ah, AR_ISR_S2_S);
189 if (s2_s & AR_ISR_S2_GTT) {
190 *masked |= HAL_INT_GTT;
193 if (s2_s & AR_ISR_S2_CST) {
194 *masked |= HAL_INT_CST;
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;
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);
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))) ?
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);
227 HAL_INT ar5416GetInterrupts(struct ath_hal *ah)
229 return AH5416(ah)->ah_maskReg;
233 ar5416SetInterrupts(struct ath_hal *ah, HAL_INT ints)
235 struct ath_hal_5416 *ahp = AH5416(ah);
236 a_uint32_t omask = ahp->ah_maskReg;
239 if (omask & HAL_INT_GLOBAL) {
240 OS_REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
241 (void) OS_REG_READ(ah, AR_IER);
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;
250 mask |= AR_IMR_TXDESC;
252 mask |= AR_IMR_TXERR;
253 mask |= AR_IMR_TXEOL;
255 if (ints & HAL_INT_RX) {
256 mask |= AR_IMR_RXERR;
257 #ifdef AR5416_INT_MITIGATION
258 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
260 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
264 if (ints & (HAL_INT_GTT | HAL_INT_CST)) {
265 mask |= AR_IMR_BCNMISC;
268 OS_REG_WRITE(ah, AR_IMR, mask);
269 (void) OS_REG_READ(ah, AR_IMR);
270 ahp->ah_maskReg = ints;
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);
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);
290 u_int64_t ar5416GetTsf64(struct ath_hal *ah)
294 tsf = OS_REG_READ(ah, AR_TSF_U32);
295 tsf = (tsf << 32) | OS_REG_READ(ah, AR_TSF_L32);
304 a_uint32_t ar5416GetRxDP(struct ath_hal *ath)
306 return OS_REG_READ(ath, AR_RXDP);
310 void ar5416SetRxDP(struct ath_hal *ah, a_uint32_t rxdp)
312 OS_REG_WRITE(ah, AR_RXDP, rxdp);
313 HALASSERT(OS_REG_READ(ah, AR_RXDP) == rxdp);
316 void ar5416SetMulticastFilter(struct ath_hal *ah, a_uint32_t filter0, a_uint32_t filter1)
318 OS_REG_WRITE(ah, AR_MCAST_FIL0, filter0);
319 OS_REG_WRITE(ah, AR_MCAST_FIL1, filter1);
322 HAL_BOOL ar5416ClrMulticastFilterIndex(struct ath_hal *ah, a_uint32_t ix)
329 val = OS_REG_READ(ah, AR_MCAST_FIL1);
330 OS_REG_WRITE(ah, AR_MCAST_FIL1, (val &~ (1<<(ix-32))));
332 val = OS_REG_READ(ah, AR_MCAST_FIL0);
333 OS_REG_WRITE(ah, AR_MCAST_FIL0, (val &~ (1<<ix)));
338 HAL_BOOL ar5416StopDmaReceive(struct ath_hal *ah)
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)) {
348 HAL_BOOL ar5416SetMulticastFilterIndex(struct ath_hal *ah, a_uint32_t ix)
355 val = OS_REG_READ(ah, AR_MCAST_FIL1);
356 OS_REG_WRITE(ah, AR_MCAST_FIL1, (val | (1<<(ix-32))));
358 val = OS_REG_READ(ah, AR_MCAST_FIL0);
359 OS_REG_WRITE(ah, AR_MCAST_FIL0, (val | (1<<ix)));
364 void ar5416StartPcuReceive(struct ath_hal *ah)
366 OS_REG_CLR_BIT(ah, AR_DIAG_SW,
367 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
370 void ar5416SetRxFilter(struct ath_hal *ah, a_uint32_t bits)
374 OS_REG_WRITE(ah, AR_RX_FILTER, (bits & 0xff) | AR_RX_COMPR_BAR);
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);
382 OS_REG_WRITE(ah, AR_RXCFG,OS_REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
384 OS_REG_WRITE(ah, AR_RXCFG,OS_REG_READ(ah, AR_RXCFG) &~ AR_RXCFG_ZLFDMA);
388 void ar5416EnableReceive(struct ath_hal *ah)
390 OS_REG_WRITE(ah, AR_CR, AR_CR_RXE);
393 void ar5416StopPcuReceive(struct ath_hal *ah)
395 OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
398 HAL_BOOL ar5416SetupRxDesc_20(struct ath_hal *ah, struct ath_rx_desc *ds,
399 a_uint32_t size, a_uint32_t flags)
401 struct ar5416_desc *ads = AR5416DESC(ds);
403 HALASSERT((size &~ AR_BufLen) == 0);
405 ads->ds_ctl1 = size & AR_BufLen;
406 if (flags & HAL_RXDESC_INTREQ)
407 ads->ds_ctl1 |= AR_RxIntrReq;
409 /* this should be enough */
410 ads->ds_rxstatus8 &= ~AR_RxDone;
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)
419 struct ar5416_desc ads;
420 struct ar5416_desc *adsp = AR5416DESC(ds);
421 struct ar5416_desc *ands = AR5416DESC(nds);
423 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
424 return HAL_EINPROGRESS;
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.
430 if ((ands->ds_rxstatus8 & AR_RxDone) == 0
431 && OS_REG_READ(ah, AR_RXDP) == pa)
432 return HAL_EINPROGRESS;
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
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.
444 ads.u.rx = adsp->u.rx;
446 rx_stats->rs_status = 0;
447 rx_stats->rs_flags = 0;
449 rx_stats->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
450 rx_stats->rs_tstamp = ads.AR_RcvTimestamp;
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);
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;
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;
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;
481 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
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.
491 if (ads.ds_rxstatus8 & AR_CRCErr)
492 rx_stats->rs_status |= HAL_RXERR_CRC;
493 else if (ads.ds_rxstatus8 & AR_PHYErr) {
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;
504 rx_stats->evm0=ads.AR_RxEVM0;
505 rx_stats->evm1=ads.AR_RxEVM1;
506 rx_stats->evm2=ads.AR_RxEVM2;
515 HAL_BOOL ar5416UpdateTxTrigLevel(struct ath_hal *ah, HAL_BOOL bIncTrigLevel)
517 struct ath_hal_5416 *ahp = AH5416(ah);
518 a_uint32_t txcfg, curLevel, newLevel;
522 * Disable interrupts while futzing with the fifo level.
524 omask = ar5416SetInterrupts(ah, ahp->ah_maskReg &~ HAL_INT_GLOBAL);
526 txcfg = OS_REG_READ(ah, AR_TXCFG);
527 curLevel = MS(txcfg, AR_FTRIG);
531 if (curLevel < MAX_TX_FIFO_THRESHOLD)
533 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
535 if (newLevel != curLevel)
536 OS_REG_WRITE(ah, AR_TXCFG,
537 (txcfg &~ AR_FTRIG) | SM(newLevel, AR_FTRIG));
539 /* re-enable chip interrupts */
540 ar5416SetInterrupts(ah, omask);
542 return (newLevel != curLevel);
545 HAL_BOOL ar5416SetTxDP(struct ath_hal *ah, a_uint32_t q, a_uint32_t txdp)
547 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
548 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
551 * Make sure that TXE is deasserted before setting the TXDP. If TXE
552 * is still asserted, setting TXDP will have no effect.
554 HALASSERT((OS_REG_READ(ah, AR_Q_TXE) & (1 << q)) == 0);
556 OS_REG_WRITE(ah, AR_QTXDP(q), txdp);
561 HAL_BOOL ar5416StartTxDma(struct ath_hal *ah, a_uint32_t q)
563 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
564 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
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);
569 OS_REG_WRITE(ah, AR_Q_TXE, 1 << q);
574 a_uint32_t ar5416NumTxPending(struct ath_hal *ah, a_uint32_t q)
578 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
579 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
581 npend = OS_REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
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.
588 if (OS_REG_READ(ah, AR_Q_TXE) & (1 << q))
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);
603 HAL_BOOL ar5416AbortTxDma(struct ath_hal *ah)
608 * set txd on all queues
610 OS_REG_WRITE(ah, AR_Q_TXD, AR_Q_TXD_M);
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);
620 * wait on all tx queues
622 for (q = 0; q < AR_NUM_QCU; q++) {
623 for (i = 0; i < AR5416_ABORT_LOOPS; i++) {
624 if (!ar5416NumTxPending(ah, q))
627 OS_DELAY(AR5416_ABORT_WAIT);
629 if (i == AR5416_ABORT_LOOPS) {
635 * clear tx abort bits
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);
644 OS_REG_WRITE(ah, AR_Q_TXD, 0);
649 HAL_BOOL ar5416StopTxDma(struct ath_hal*ah, a_uint32_t q)
653 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
655 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
657 OS_REG_WRITE(ah, AR_Q_TXD, 1 << q);
658 for (i = 1000; i != 0; i--) {
659 if (ar5416NumTxPending(ah, q) == 0)
661 OS_DELAY(100); /* XXX get actual value */
664 OS_REG_WRITE(ah, AR_Q_TXD, 0);
668 void ar5416IntrReqTxDesc_20(struct ath_hal *ah, struct ath_desc *ds)
670 struct ar5416_desc *ads = AR5416DESC(ds);
671 ads->ds_ctl0 |= AR_TxIntrReq;
674 HAL_BOOL ar5416SetupTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
679 a_uint32_t txRate0, a_uint32_t txTries0,
683 a_uint32_t rtsctsRate,
684 a_uint32_t rtsctsDuration,
685 a_uint32_t compicvLen,
686 a_uint32_t compivLen,
689 #define RTSCTS (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)
691 struct ar5416_desc *ads = AR5416DESC(ds);
695 ads->ds_txstatus9 &= ~AR_TxDone;
697 HALASSERT(txTries0 != 0);
698 HALASSERT(isValidPktType(type));
699 HALASSERT(isValidTxRate(txRate0));
700 HALASSERT((flags & RTSCTS) != RTSCTS);
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);
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);
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);
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;
727 if (flags & RTSCTS) {
728 if (!isValidTxRate(rtsctsRate)) {
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);
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)
746 struct ar5416_desc *ads = AR5416DESC(ds);
748 HALASSERT((segLen &~ AR_BufLen) == 0);
752 * First descriptor, don't clobber xmit control data
753 * setup by ar5416SetupTxDesc.
755 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
756 } else if (lastSeg) {
758 * Last descriptor in a multi-descriptor frame,
759 * copy the multi-rate transmit parameters from
760 * the first frame for processing on completion.
763 ads->ds_ctl1 = segLen;
764 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
765 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
768 * Intermediate descriptor in a multi-descriptor frame.
771 ads->ds_ctl1 = segLen | AR_TxMore;
775 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
780 HAL_BOOL ar5416FillKeyTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
781 HAL_KEY_TYPE keyType)
783 struct ar5416_desc *ads = AR5416DESC(ds);
785 ads->ds_ctl6 = SM(keyType, AR_EncrType);
789 HAL_STATUS ar5416ProcTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *gds)
791 struct ar5416_desc *ads = AR5416DESC(gds);
792 struct ath_tx_desc *ds = (struct ath_tx_desc *)gds;
794 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
795 return HAL_EINPROGRESS;
797 ads->ds_txstatus9 &= ~AR_TxDone;
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;
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;
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);
822 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
823 ds->ds_txstat.ts_flags |= HAL_TX_DELIM_UNDERRUN;
824 ar5416UpdateTxTrigLevel(ah, AH_TRUE);
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;
833 * Extract the transmit rate used and mark the rate as
834 * ``alternate'' if it wasn't the series 0 rate.
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 */
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,
861 struct ar5416_desc *ads = AR5416DESC(ds);
863 HALASSERT(isValidPktType(type));
864 HALASSERT(isValidKeyType(keyType));
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);
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);
885 ads->ds_ctl6 = SM(keyType, AR_EncrType);
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,
896 struct ar5416_desc *ads = AR5416DESC(ds);
899 HALASSERT(nseries == 4);
903 * Rate control settings override
905 ds_ctl0 = ads->ds_ctl0;
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;
912 ds_ctl0 &= ~AR_RTSEnable;
913 ds_ctl0 |= AR_CTSEnable;
916 ds_ctl0 = (ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
919 ads->ds_ctl0 = ds_ctl0;
921 ads->ds_ctl2 = set11nTries(series, 0)
922 | set11nTries(series, 1)
923 | set11nTries(series, 2)
924 | set11nTries(series, 3)
925 | (durUpdateEn ? AR_DurUpdateEn : 0);
927 ads->ds_ctl3 = set11nRate(series, 0)
928 | set11nRate(series, 1)
929 | set11nRate(series, 2)
930 | set11nRate(series, 3);
932 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
933 | set11nPktDurRTSCTS(series, 1);
935 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
936 | set11nPktDurRTSCTS(series, 3);
938 ads->ds_ctl7 = set11nRateFlags(series, 0)
939 | set11nRateFlags(series, 1)
940 | set11nRateFlags(series, 2)
941 | set11nRateFlags(series, 3)
942 | SM(rtsctsRate, AR_RTSCTSRate);
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,
953 struct ar5416_desc *ads = AR5416DESC(ds);
956 HALASSERT(nseries == 4);
960 * Rate control settings override
962 if (flags & (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) {
963 ds_ctl0 = ads->ds_ctl0;
965 if (flags & HAL_TXDESC_RTSENA) {
966 ds_ctl0 &= ~AR_CTSEnable;
967 ds_ctl0 |= AR_RTSEnable;
969 ds_ctl0 &= ~AR_RTSEnable;
970 ds_ctl0 |= AR_CTSEnable;
973 ads->ds_ctl0 = ds_ctl0;
976 ads->ds_ctl2 = set11nTries(series, 0)
977 | set11nTries(series, 1)
978 | set11nTries(series, 2)
979 | set11nTries(series, 3)
980 | (durUpdateEn ? AR_DurUpdateEn : 0);
982 ads->ds_ctl3 = set11nRate(series, 0)
983 | set11nRate(series, 1)
984 | set11nRate(series, 2)
985 | set11nRate(series, 3);
987 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
988 | set11nPktDurRTSCTS(series, 1);
990 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
991 | set11nPktDurRTSCTS(series, 3);
993 ads->ds_ctl7 = set11nRateFlags(series, 0)
994 | set11nRateFlags(series, 1)
995 | set11nRateFlags(series, 2)
996 | set11nRateFlags(series, 3)
997 | SM(rtsctsRate, AR_RTSCTSRate);
1002 void ar5416Set11nAggrFirst_20(struct ath_hal *ah, struct ath_tx_desc *ds, a_uint32_t aggrLen,
1003 a_uint32_t numDelims)
1005 struct ar5416_desc *ads = AR5416DESC(ds);
1007 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
1009 ads->ds_ctl6 &= ~(AR_AggrLen | AR_PadDelim);
1010 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen) |
1011 SM(numDelims, AR_PadDelim);
1014 void ar5416Set11nAggrMiddle_20(struct ath_hal *ah, struct ath_tx_desc *ds, a_uint32_t numDelims)
1016 struct ar5416_desc *ads = AR5416DESC(ds);
1019 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
1022 * We use a stack variable to manipulate ctl6 to reduce uncached
1023 * read modify, modfiy, write.
1025 ctl6 = ads->ds_ctl6;
1026 ctl6 &= ~AR_PadDelim;
1027 ctl6 |= SM(numDelims, AR_PadDelim);
1028 ads->ds_ctl6 = ctl6;
1031 void ar5416Set11nAggrLast_20(struct ath_hal *ah, struct ath_tx_desc *ds)
1033 struct ar5416_desc *ads = AR5416DESC(ds);
1035 ads->ds_ctl1 |= AR_IsAggr;
1036 ads->ds_ctl1 &= ~AR_MoreAggr;
1037 ads->ds_ctl6 &= ~AR_PadDelim;
1040 void ar5416Clr11nAggr_20(struct ath_hal *ah, struct ath_tx_desc *ds)
1042 struct ar5416_desc *ads = AR5416DESC(ds);
1044 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
1047 void ar5416Set11nBurstDuration_20(struct ath_hal *ah, struct ath_tx_desc *ds,
1048 a_uint32_t burstDuration)
1050 struct ar5416_desc *ads = AR5416DESC(ds);
1052 ads->ds_ctl2 &= ~AR_BurstDur;
1053 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
1056 void ar5416Set11nVirtualMoreFrag_20(struct ath_hal *ah, struct ath_tx_desc *ds,
1059 struct ar5416_desc *ads = AR5416DESC(ds);
1062 ads->ds_ctl0 |= AR_VirtMoreFrag;
1064 ads->ds_ctl0 &= ~AR_VirtMoreFrag;