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_setRxDP = ar5416SetRxDP,
73 .ah_stopDmaReceive = ar5416StopDmaReceive,
74 .ah_enableReceive = ar5416EnableReceive,
75 .ah_startPcuReceive = ar5416StartPcuReceive,
76 .ah_stopPcuReceive = ar5416StopPcuReceive,
78 /* Interrupt Functions */
79 .ah_isInterruptPending = ar5416IsInterruptPending,
80 .ah_getPendingInterrupts = ar5416GetPendingInterrupts,
81 .ah_getInterrupts = ar5416GetInterrupts,
82 .ah_setInterrupts = ar5416SetInterrupts,
86 void ar5416Detach(struct ath_hal *ah)
88 HALASSERT(ah != AH_NULL);
93 ar5416Attach(a_uint32_t devid,HAL_SOFTC sc, adf_os_device_t dev,
94 a_uint32_t flags, HAL_STATUS *status)
96 struct ath_hal_5416 *ahp;
99 ahp = ath_hal_malloc(sizeof (struct ath_hal_5416));
100 if (ahp == AH_NULL) {
101 *status = HAL_ENOMEM;
104 ah = &ahp->ah_priv.h;
106 OS_MEMCPY(&ahp->ah_priv, &ar5416hal_10, sizeof(struct ath_hal_private));
111 /* If its a Owl 2.0 chip then change the hal structure to
112 point to the Owl 2.0 ar5416_hal_20 structure */
114 ah->ah_set11nTxDesc = ar5416Set11nTxDesc_20;
115 ah->ah_set11nRateScenario = ar5416Set11nRateScenario_20;
116 ah->ah_set11nAggrFirst = ar5416Set11nAggrFirst_20;
117 ah->ah_set11nAggrMiddle = ar5416Set11nAggrMiddle_20;
118 ah->ah_set11nAggrLast = ar5416Set11nAggrLast_20;
119 ah->ah_clr11nAggr = ar5416Clr11nAggr_20;
120 ah->ah_set11nBurstDuration = ar5416Set11nBurstDuration_20;
121 ah->ah_setupRxDesc = ar5416SetupRxDesc_20;
122 ah->ah_procRxDescFast = ar5416ProcRxDescFast_20;
123 ah->ah_updateCTSForBursting = NULL;
124 ah->ah_setupTxDesc = ar5416SetupTxDesc_20;
125 ah->ah_reqTxIntrDesc = ar5416IntrReqTxDesc_20;
126 ah->ah_fillTxDesc = ar5416FillTxDesc_20;
127 ah->ah_fillKeyTxDesc = ar5416FillKeyTxDesc_20;
128 ah->ah_procTxDesc = ar5416ProcTxDesc_20;
129 ah->ah_set11nVirtualMoreFrag = ar5416Set11nVirtualMoreFrag_20;
135 /**********************/
136 /* Interrupt Handling */
137 /**********************/
139 HAL_BOOL ar5416IsInterruptPending(struct ath_hal *ah)
141 a_uint32_t host_isr = OS_REG_READ(ah, AR_INTR_ASYNC_CAUSE);
143 * Some platforms trigger our ISR before applying power to
144 * the card, so make sure.
146 return ((host_isr != AR_INTR_SPURIOUS) && (host_isr & AR_INTR_MAC_IRQ));
149 HAL_BOOL ar5416GetPendingInterrupts(struct ath_hal *ah, HAL_INT *masked)
153 HAL_BOOL fatal_int = AH_FALSE;
154 a_uint32_t sync_cause;
156 if (OS_REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
157 if ((OS_REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M) != AR_RTC_STATUS_ON) {
166 isr = OS_REG_READ(ah, AR_ISR_RAC);
167 if (isr == 0xffffffff) {
172 *masked = isr & HAL_INT_COMMON;
174 #ifdef AR5416_INT_MITIGATION
175 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM)) {
176 *masked |= HAL_INT_RX;
178 if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM)) {
179 *masked |= HAL_INT_TX;
183 if (isr & AR_ISR_BCNMISC) {
186 s2_s = OS_REG_READ(ah, AR_ISR_S2_S);
188 if (s2_s & AR_ISR_S2_GTT) {
189 *masked |= HAL_INT_GTT;
192 if (s2_s & AR_ISR_S2_CST) {
193 *masked |= HAL_INT_CST;
197 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
198 *masked |= HAL_INT_RX;
199 if (isr & (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR | AR_ISR_TXEOL)) {
200 struct ath_hal_5416 *ahp = AH5416(ah);
201 a_uint32_t s0_s, s1_s;
203 *masked |= HAL_INT_TX;
204 s0_s = OS_REG_READ(ah, AR_ISR_S0_S);
205 s1_s = OS_REG_READ(ah, AR_ISR_S1_S);
206 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
207 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
208 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
209 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
213 sync_cause = OS_REG_READ(ah, AR_INTR_SYNC_CAUSE);
214 fatal_int = ((sync_cause != AR_INTR_SPURIOUS) &&
215 (sync_cause & (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))) ?
218 if (AH_TRUE == fatal_int) {
219 OS_REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
220 (void) OS_REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
226 HAL_INT ar5416GetInterrupts(struct ath_hal *ah)
228 return AH5416(ah)->ah_maskReg;
232 ar5416SetInterrupts(struct ath_hal *ah, HAL_INT ints)
234 struct ath_hal_5416 *ahp = AH5416(ah);
235 a_uint32_t omask = ahp->ah_maskReg;
238 if (omask & HAL_INT_GLOBAL) {
239 OS_REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
240 (void) OS_REG_READ(ah, AR_IER);
243 mask = ints & HAL_INT_COMMON;
244 if (ints & HAL_INT_TX) {
245 #ifdef AR5416_INT_MITIGATION
246 mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM;
249 mask |= AR_IMR_TXDESC;
251 mask |= AR_IMR_TXERR;
252 mask |= AR_IMR_TXEOL;
254 if (ints & HAL_INT_RX) {
255 mask |= AR_IMR_RXERR;
256 #ifdef AR5416_INT_MITIGATION
257 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
259 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
263 if (ints & (HAL_INT_GTT | HAL_INT_CST)) {
264 mask |= AR_IMR_BCNMISC;
267 OS_REG_WRITE(ah, AR_IMR, mask);
268 (void) OS_REG_READ(ah, AR_IMR);
269 ahp->ah_maskReg = ints;
271 /* Re-enable interrupts if they were enabled before. */
272 if (ints & HAL_INT_GLOBAL) {
273 OS_REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
274 /* See explanation above... */
275 (void) OS_REG_READ(ah, AR_IER);
278 OS_REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, AR_INTR_MAC_IRQ);
279 OS_REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
280 OS_REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_ALL);
289 u_int64_t ar5416GetTsf64(struct ath_hal *ah)
293 tsf = OS_REG_READ(ah, AR_TSF_U32);
294 tsf = (tsf << 32) | OS_REG_READ(ah, AR_TSF_L32);
302 void ar5416SetRxDP(struct ath_hal *ah, a_uint32_t rxdp)
304 OS_REG_WRITE(ah, AR_RXDP, rxdp);
305 HALASSERT(OS_REG_READ(ah, AR_RXDP) == rxdp);
308 void ar5416SetMulticastFilter(struct ath_hal *ah, a_uint32_t filter0, a_uint32_t filter1)
310 OS_REG_WRITE(ah, AR_MCAST_FIL0, filter0);
311 OS_REG_WRITE(ah, AR_MCAST_FIL1, filter1);
314 HAL_BOOL ar5416ClrMulticastFilterIndex(struct ath_hal *ah, a_uint32_t ix)
321 val = OS_REG_READ(ah, AR_MCAST_FIL1);
322 OS_REG_WRITE(ah, AR_MCAST_FIL1, (val &~ (1<<(ix-32))));
324 val = OS_REG_READ(ah, AR_MCAST_FIL0);
325 OS_REG_WRITE(ah, AR_MCAST_FIL0, (val &~ (1<<ix)));
330 HAL_BOOL ar5416StopDmaReceive(struct ath_hal *ah)
332 OS_REG_WRITE(ah, AR_CR, AR_CR_RXD); /* Set receive disable bit */
333 if (!ath_hal_wait(ah, AR_CR, AR_CR_RXE, 0)) {
340 HAL_BOOL ar5416SetMulticastFilterIndex(struct ath_hal *ah, a_uint32_t ix)
347 val = OS_REG_READ(ah, AR_MCAST_FIL1);
348 OS_REG_WRITE(ah, AR_MCAST_FIL1, (val | (1<<(ix-32))));
350 val = OS_REG_READ(ah, AR_MCAST_FIL0);
351 OS_REG_WRITE(ah, AR_MCAST_FIL0, (val | (1<<ix)));
356 void ar5416StartPcuReceive(struct ath_hal *ah)
358 OS_REG_CLR_BIT(ah, AR_DIAG_SW,
359 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
362 void ar5416SetRxFilter(struct ath_hal *ah, a_uint32_t bits)
366 OS_REG_WRITE(ah, AR_RX_FILTER, (bits & 0xff) | AR_RX_COMPR_BAR);
368 if (bits & HAL_RX_FILTER_PHYRADAR)
369 phybits |= AR_PHY_ERR_RADAR;
370 if (bits & HAL_RX_FILTER_PHYERR)
371 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
372 OS_REG_WRITE(ah, AR_PHY_ERR, phybits);
374 OS_REG_WRITE(ah, AR_RXCFG,OS_REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
376 OS_REG_WRITE(ah, AR_RXCFG,OS_REG_READ(ah, AR_RXCFG) &~ AR_RXCFG_ZLFDMA);
380 void ar5416EnableReceive(struct ath_hal *ah)
382 OS_REG_WRITE(ah, AR_CR, AR_CR_RXE);
385 void ar5416StopPcuReceive(struct ath_hal *ah)
387 OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
390 HAL_BOOL ar5416SetupRxDesc_20(struct ath_hal *ah, struct ath_rx_desc *ds,
391 a_uint32_t size, a_uint32_t flags)
393 struct ar5416_desc *ads = AR5416DESC(ds);
395 HALASSERT((size &~ AR_BufLen) == 0);
397 ads->ds_ctl1 = size & AR_BufLen;
398 if (flags & HAL_RXDESC_INTREQ)
399 ads->ds_ctl1 |= AR_RxIntrReq;
401 /* this should be enough */
402 ads->ds_rxstatus8 &= ~AR_RxDone;
407 HAL_STATUS ar5416ProcRxDescFast_20(struct ath_hal *ah, struct ath_rx_desc *ds,
408 a_uint32_t pa, struct ath_desc *nds,
409 struct ath_rx_status *rx_stats)
411 struct ar5416_desc ads;
412 struct ar5416_desc *adsp = AR5416DESC(ds);
413 struct ar5416_desc *ands = AR5416DESC(nds);
415 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
416 return HAL_EINPROGRESS;
418 * Given the use of a self-linked tail be very sure that the hw is
419 * done with this descriptor; the hw may have done this descriptor
420 * once and picked it up again...make sure the hw has moved on.
422 if ((ands->ds_rxstatus8 & AR_RxDone) == 0
423 && OS_REG_READ(ah, AR_RXDP) == pa)
424 return HAL_EINPROGRESS;
427 * Now we need to get the stats from the descriptor. Since desc are
428 * uncached, lets make a copy of the stats first. Note that, since we
429 * touch most of the rx stats, a memcpy would always be more efficient
431 * Next we fill in all values in a caller passed stack variable.
432 * This reduces the number of uncached accesses.
433 * Do this copy here, after the check so that when the checks fail, we
434 * dont end up copying the entire stats uselessly.
436 ads.u.rx = adsp->u.rx;
438 rx_stats->rs_status = 0;
439 rx_stats->rs_flags = 0;
441 rx_stats->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
442 rx_stats->rs_tstamp = ads.AR_RcvTimestamp;
444 /* XXX what about KeyCacheMiss? */
445 rx_stats->rs_rssi_combined =
446 MS(ads.ds_rxstatus4, AR_RxRSSICombined);
447 rx_stats->rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00);
448 rx_stats->rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01);
449 rx_stats->rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02);
450 rx_stats->rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10);
451 rx_stats->rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11);
452 rx_stats->rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12);
453 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
454 rx_stats->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
456 rx_stats->rs_keyix = HAL_RXKEYIX_INVALID;
457 /* NB: caller expected to do rate table mapping */
458 rx_stats->rs_rate = RXSTATUS_RATE(ah, (&ads));
459 rx_stats->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
461 rx_stats->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
462 rx_stats->rs_moreaggr = (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
463 rx_stats->rs_flags |= (ads.ds_rxstatus3 & AR_GI) ? HAL_RX_GI : 0;
464 rx_stats->rs_flags |= (ads.ds_rxstatus3 & AR_2040) ? HAL_RX_2040 : 0;
466 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
467 rx_stats->rs_flags |= HAL_RX_DELIM_CRC_PRE;
468 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
469 rx_stats->rs_flags |= HAL_RX_DELIM_CRC_POST;
470 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
471 rx_stats->rs_flags |= HAL_RX_DECRYPT_BUSY;
473 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
475 * These four bits should not be set together. The
476 * 5416 spec states a Michael error can only occur if
477 * DecryptCRCErr not set (and TKIP is used). Experience
478 * indicates however that you can also get Michael errors
479 * when a CRC error is detected, but these are specious.
480 * Consequently we filter them out here so we don't
481 * confuse and/or complicate drivers.
483 if (ads.ds_rxstatus8 & AR_CRCErr)
484 rx_stats->rs_status |= HAL_RXERR_CRC;
485 else if (ads.ds_rxstatus8 & AR_PHYErr) {
488 rx_stats->rs_status |= HAL_RXERR_PHY;
489 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
490 rx_stats->rs_phyerr = phyerr;
491 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
492 rx_stats->rs_status |= HAL_RXERR_DECRYPT;
493 else if (ads.ds_rxstatus8 & AR_MichaelErr)
494 rx_stats->rs_status |= HAL_RXERR_MIC;
496 rx_stats->evm0=ads.AR_RxEVM0;
497 rx_stats->evm1=ads.AR_RxEVM1;
498 rx_stats->evm2=ads.AR_RxEVM2;
507 HAL_BOOL ar5416UpdateTxTrigLevel(struct ath_hal *ah, HAL_BOOL bIncTrigLevel)
509 struct ath_hal_5416 *ahp = AH5416(ah);
510 a_uint32_t txcfg, curLevel, newLevel;
514 * Disable interrupts while futzing with the fifo level.
516 omask = ar5416SetInterrupts(ah, ahp->ah_maskReg &~ HAL_INT_GLOBAL);
518 txcfg = OS_REG_READ(ah, AR_TXCFG);
519 curLevel = MS(txcfg, AR_FTRIG);
523 if (curLevel < MAX_TX_FIFO_THRESHOLD)
525 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
527 if (newLevel != curLevel)
528 OS_REG_WRITE(ah, AR_TXCFG,
529 (txcfg &~ AR_FTRIG) | SM(newLevel, AR_FTRIG));
531 /* re-enable chip interrupts */
532 ar5416SetInterrupts(ah, omask);
534 return (newLevel != curLevel);
537 HAL_BOOL ar5416SetTxDP(struct ath_hal *ah, a_uint32_t q, a_uint32_t txdp)
539 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
540 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
543 * Make sure that TXE is deasserted before setting the TXDP. If TXE
544 * is still asserted, setting TXDP will have no effect.
546 HALASSERT((OS_REG_READ(ah, AR_Q_TXE) & (1 << q)) == 0);
548 OS_REG_WRITE(ah, AR_QTXDP(q), txdp);
553 HAL_BOOL ar5416StartTxDma(struct ath_hal *ah, a_uint32_t q)
555 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
556 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
558 /* Check to be sure we're not enabling a q that has its TXD bit set. */
559 HALASSERT((OS_REG_READ(ah, AR_Q_TXD) & (1 << q)) == 0);
561 OS_REG_WRITE(ah, AR_Q_TXE, 1 << q);
566 a_uint32_t ar5416NumTxPending(struct ath_hal *ah, a_uint32_t q)
570 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
571 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
573 npend = OS_REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
576 * Pending frame count (PFC) can momentarily go to zero
577 * while TXE remains asserted. In other words a PFC of
578 * zero is not sufficient to say that the queue has stopped.
580 if (OS_REG_READ(ah, AR_Q_TXE) & (1 << q))
584 if (npend && (AH5416(ah)->ah_txq[q].tqi_type == HAL_TX_QUEUE_CAB)) {
585 if (OS_REG_READ(ah, AR_Q_RDYTIMESHDN) & (1 << q)) {
586 isrPrintf("RTSD on CAB queue\n");
587 /* Clear the ReadyTime shutdown status bits */
588 OS_REG_WRITE(ah, AR_Q_RDYTIMESHDN, 1 << q);
595 HAL_BOOL ar5416AbortTxDma(struct ath_hal *ah)
600 * set txd on all queues
602 OS_REG_WRITE(ah, AR_Q_TXD, AR_Q_TXD_M);
607 OS_REG_SET_BIT(ah, AR_PCU_MISC, (AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF));
608 OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
609 OS_REG_SET_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
612 * wait on all tx queues
614 for (q = 0; q < AR_NUM_QCU; q++) {
615 for (i = 0; i < AR5416_ABORT_LOOPS; i++) {
616 if (!ar5416NumTxPending(ah, q))
619 OS_DELAY(AR5416_ABORT_WAIT);
621 if (i == AR5416_ABORT_LOOPS) {
627 * clear tx abort bits
629 OS_REG_CLR_BIT(ah, AR_PCU_MISC, (AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF));
630 OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
631 OS_REG_CLR_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
636 OS_REG_WRITE(ah, AR_Q_TXD, 0);
641 HAL_BOOL ar5416StopTxDma(struct ath_hal*ah, a_uint32_t q)
645 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
647 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
649 OS_REG_WRITE(ah, AR_Q_TXD, 1 << q);
650 for (i = 1000; i != 0; i--) {
651 if (ar5416NumTxPending(ah, q) == 0)
653 OS_DELAY(100); /* XXX get actual value */
656 OS_REG_WRITE(ah, AR_Q_TXD, 0);
660 void ar5416IntrReqTxDesc_20(struct ath_hal *ah, struct ath_desc *ds)
662 struct ar5416_desc *ads = AR5416DESC(ds);
663 ads->ds_ctl0 |= AR_TxIntrReq;
666 HAL_BOOL ar5416SetupTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
671 a_uint32_t txRate0, a_uint32_t txTries0,
675 a_uint32_t rtsctsRate,
676 a_uint32_t rtsctsDuration,
677 a_uint32_t compicvLen,
678 a_uint32_t compivLen,
681 #define RTSCTS (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)
683 struct ar5416_desc *ads = AR5416DESC(ds);
687 ads->ds_txstatus9 &= ~AR_TxDone;
689 HALASSERT(txTries0 != 0);
690 HALASSERT(isValidPktType(type));
691 HALASSERT(isValidTxRate(txRate0));
692 HALASSERT((flags & RTSCTS) != RTSCTS);
697 ads->ds_ctl0 = (pktLen & AR_FrameLen)
698 | (txPower << AR_XmitPower_S)
699 | (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)
700 | (flags & HAL_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
701 | (flags & HAL_TXDESC_INTREQ ? AR_TxIntrReq : 0);
703 ads->ds_ctl1 = (type << AR_FrameType_S)
704 | (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0);
705 ads->ds_ctl2 = SM(txTries0, AR_XmitDataTries0);
706 ads->ds_ctl3 = (txRate0 << AR_XmitRate0_S);
708 ads->ds_ctl7 = SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel0)
709 | SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel1)
710 | SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel2)
711 | SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel3);
713 if (keyIx != HAL_TXKEYIX_INVALID) {
714 /* XXX validate key index */
715 ads->ds_ctl1 |= SM(keyIx, AR_DestIdx);
716 ads->ds_ctl0 |= AR_DestIdxValid;
719 if (flags & RTSCTS) {
720 if (!isValidTxRate(rtsctsRate)) {
723 /* XXX validate rtsctsDuration */
724 ads->ds_ctl0 |= (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0)
725 | (flags & HAL_TXDESC_RTSENA ? AR_RTSEnable : 0);
726 ads->ds_ctl2 |= SM(rtsctsDuration, AR_BurstDur);
727 ads->ds_ctl3 |= (rtsctsRate << AR_RTSCTSRate_S);
734 HAL_BOOL ar5416FillTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
735 a_uint32_t segLen, HAL_BOOL firstSeg, HAL_BOOL lastSeg,
736 const struct ath_tx_desc *ds0)
738 struct ar5416_desc *ads = AR5416DESC(ds);
740 HALASSERT((segLen &~ AR_BufLen) == 0);
744 * First descriptor, don't clobber xmit control data
745 * setup by ar5416SetupTxDesc.
747 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
748 } else if (lastSeg) {
750 * Last descriptor in a multi-descriptor frame,
751 * copy the multi-rate transmit parameters from
752 * the first frame for processing on completion.
755 ads->ds_ctl1 = segLen;
756 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
757 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
760 * Intermediate descriptor in a multi-descriptor frame.
763 ads->ds_ctl1 = segLen | AR_TxMore;
767 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
772 HAL_BOOL ar5416FillKeyTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
773 HAL_KEY_TYPE keyType)
775 struct ar5416_desc *ads = AR5416DESC(ds);
777 ads->ds_ctl6 = SM(keyType, AR_EncrType);
781 HAL_STATUS ar5416ProcTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *gds)
783 struct ar5416_desc *ads = AR5416DESC(gds);
784 struct ath_tx_desc *ds = (struct ath_tx_desc *)gds;
786 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
787 return HAL_EINPROGRESS;
789 ads->ds_txstatus9 &= ~AR_TxDone;
791 /* Update software copies of the HW status */
792 ds->ds_txstat.ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
793 ds->ds_txstat.ts_tstamp = ads->AR_SendTimestamp;
794 ds->ds_txstat.ts_status = 0;
795 ds->ds_txstat.ts_flags = 0;
797 if (ads->ds_txstatus1 & AR_ExcessiveRetries)
798 ds->ds_txstat.ts_status |= HAL_TXERR_XRETRY;
799 if (ads->ds_txstatus1 & AR_Filtered)
800 ds->ds_txstat.ts_status |= HAL_TXERR_FILT;
801 if (ads->ds_txstatus1 & AR_FIFOUnderrun)
802 ds->ds_txstat.ts_status |= HAL_TXERR_FIFO;
803 if (ads->ds_txstatus9 & AR_TxOpExceeded)
804 ds->ds_txstat.ts_status |= HAL_TXERR_XTXOP;
805 if (ads->ds_txstatus1 & AR_TxTimerExpired)
806 ds->ds_txstat.ts_status |= HAL_TXERR_TIMER_EXPIRED;
808 if (ads->ds_txstatus1 & AR_DescCfgErr)
809 ds->ds_txstat.ts_flags |= HAL_TX_DESC_CFG_ERR;
810 if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
811 ds->ds_txstat.ts_flags |= HAL_TX_DATA_UNDERRUN;
812 ar5416UpdateTxTrigLevel(ah, AH_TRUE);
814 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
815 ds->ds_txstat.ts_flags |= HAL_TX_DELIM_UNDERRUN;
816 ar5416UpdateTxTrigLevel(ah, AH_TRUE);
818 if (ads->ds_txstatus0 & AR_TxBaStatus) {
819 ds->ds_txstat.ts_flags |= HAL_TX_BA;
820 ds->ds_txstat.ba_low = ads->AR_BaBitmapLow;
821 ds->ds_txstat.ba_high = ads->AR_BaBitmapHigh;
825 * Extract the transmit rate used and mark the rate as
826 * ``alternate'' if it wasn't the series 0 rate.
828 ds->ds_txstat.ts_rate = MS(ads->ds_txstatus9, AR_FinalTxIdx);
829 ds->ds_txstat.ts_rssi_combined =
830 MS(ads->ds_txstatus5, AR_TxRSSICombined);
831 ds->ds_txstat.ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
832 ds->ds_txstat.ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
833 ds->ds_txstat.ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
834 ds->ds_txstat.ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
835 ds->ds_txstat.ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
836 ds->ds_txstat.ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
837 ds->ds_txstat.evm0 = ads->AR_TxEVM0;
838 ds->ds_txstat.evm1 = ads->AR_TxEVM1;
839 ds->ds_txstat.evm2 = ads->AR_TxEVM2;
840 ds->ds_txstat.ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
841 ds->ds_txstat.ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
842 ds->ds_txstat.ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
843 ds->ds_txstat.ts_antenna = 0; /* ignored for owl */
848 void ar5416Set11nTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
849 a_uint32_t pktLen, HAL_PKT_TYPE type, a_uint32_t txPower,
850 a_uint32_t keyIx, HAL_KEY_TYPE keyType,
853 struct ar5416_desc *ads = AR5416DESC(ds);
855 HALASSERT(isValidPktType(type));
856 HALASSERT(isValidKeyType(keyType));
861 ads->ds_ctl0 = (pktLen & AR_FrameLen)
862 | (flags & HAL_TXDESC_VMF ? AR_VirtMoreFrag : 0)
863 | SM(txPower, AR_XmitPower)
864 | (flags & HAL_TXDESC_RTSENA ? AR_RTSEnable : 0)
865 | (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)
866 | (flags & HAL_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
867 | (flags & HAL_TXDESC_INTREQ ? AR_TxIntrReq : 0)
868 | (keyIx != HAL_TXKEYIX_INVALID ? AR_DestIdxValid : 0)
869 | (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0);
871 ads->ds_ctl1 = (keyIx != HAL_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
872 | SM(type, AR_FrameType)
873 | (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0)
874 | (flags & HAL_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
875 | (flags & HAL_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
877 ads->ds_ctl6 = SM(keyType, AR_EncrType);
882 void ar5416Set11nRateScenario_20(struct ath_hal *ah, struct ath_tx_desc *ds,
883 a_uint32_t durUpdateEn, a_uint32_t rtsctsRate,
884 a_uint32_t rtsctsDuration,
885 HAL_11N_RATE_SERIES series[], a_uint32_t nseries,
888 struct ar5416_desc *ads = AR5416DESC(ds);
891 HALASSERT(nseries == 4);
895 * Rate control settings override
897 ds_ctl0 = ads->ds_ctl0;
899 if (flags & (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) {
900 if (flags & HAL_TXDESC_RTSENA) {
901 ds_ctl0 &= ~AR_CTSEnable;
902 ds_ctl0 |= AR_RTSEnable;
904 ds_ctl0 &= ~AR_RTSEnable;
905 ds_ctl0 |= AR_CTSEnable;
908 ds_ctl0 = (ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
911 ads->ds_ctl0 = ds_ctl0;
913 ads->ds_ctl2 = set11nTries(series, 0)
914 | set11nTries(series, 1)
915 | set11nTries(series, 2)
916 | set11nTries(series, 3)
917 | (durUpdateEn ? AR_DurUpdateEn : 0);
919 ads->ds_ctl3 = set11nRate(series, 0)
920 | set11nRate(series, 1)
921 | set11nRate(series, 2)
922 | set11nRate(series, 3);
924 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
925 | set11nPktDurRTSCTS(series, 1);
927 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
928 | set11nPktDurRTSCTS(series, 3);
930 ads->ds_ctl7 = set11nRateFlags(series, 0)
931 | set11nRateFlags(series, 1)
932 | set11nRateFlags(series, 2)
933 | set11nRateFlags(series, 3)
934 | SM(rtsctsRate, AR_RTSCTSRate);
939 void ar5416Set11nRateScenario_20(struct ath_hal *ah, struct ath_tx_desc *ds,
940 a_uint32_t durUpdateEn, a_uint32_t rtsctsRate,
941 a_uint32_t rtsctsDuration,
942 HAL_11N_RATE_SERIES series[], a_uint32_t nseries,
945 struct ar5416_desc *ads = AR5416DESC(ds);
948 HALASSERT(nseries == 4);
952 * Rate control settings override
954 if (flags & (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) {
955 ds_ctl0 = ads->ds_ctl0;
957 if (flags & HAL_TXDESC_RTSENA) {
958 ds_ctl0 &= ~AR_CTSEnable;
959 ds_ctl0 |= AR_RTSEnable;
961 ds_ctl0 &= ~AR_RTSEnable;
962 ds_ctl0 |= AR_CTSEnable;
965 ads->ds_ctl0 = ds_ctl0;
968 ads->ds_ctl2 = set11nTries(series, 0)
969 | set11nTries(series, 1)
970 | set11nTries(series, 2)
971 | set11nTries(series, 3)
972 | (durUpdateEn ? AR_DurUpdateEn : 0);
974 ads->ds_ctl3 = set11nRate(series, 0)
975 | set11nRate(series, 1)
976 | set11nRate(series, 2)
977 | set11nRate(series, 3);
979 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
980 | set11nPktDurRTSCTS(series, 1);
982 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
983 | set11nPktDurRTSCTS(series, 3);
985 ads->ds_ctl7 = set11nRateFlags(series, 0)
986 | set11nRateFlags(series, 1)
987 | set11nRateFlags(series, 2)
988 | set11nRateFlags(series, 3)
989 | SM(rtsctsRate, AR_RTSCTSRate);
994 void ar5416Set11nAggrFirst_20(struct ath_hal *ah, struct ath_tx_desc *ds, a_uint32_t aggrLen,
995 a_uint32_t numDelims)
997 struct ar5416_desc *ads = AR5416DESC(ds);
999 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
1001 ads->ds_ctl6 &= ~(AR_AggrLen | AR_PadDelim);
1002 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen) |
1003 SM(numDelims, AR_PadDelim);
1006 void ar5416Set11nAggrMiddle_20(struct ath_hal *ah, struct ath_tx_desc *ds, a_uint32_t numDelims)
1008 struct ar5416_desc *ads = AR5416DESC(ds);
1011 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
1014 * We use a stack variable to manipulate ctl6 to reduce uncached
1015 * read modify, modfiy, write.
1017 ctl6 = ads->ds_ctl6;
1018 ctl6 &= ~AR_PadDelim;
1019 ctl6 |= SM(numDelims, AR_PadDelim);
1020 ads->ds_ctl6 = ctl6;
1023 void ar5416Set11nAggrLast_20(struct ath_hal *ah, struct ath_tx_desc *ds)
1025 struct ar5416_desc *ads = AR5416DESC(ds);
1027 ads->ds_ctl1 |= AR_IsAggr;
1028 ads->ds_ctl1 &= ~AR_MoreAggr;
1029 ads->ds_ctl6 &= ~AR_PadDelim;
1032 void ar5416Clr11nAggr_20(struct ath_hal *ah, struct ath_tx_desc *ds)
1034 struct ar5416_desc *ads = AR5416DESC(ds);
1036 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
1039 void ar5416Set11nBurstDuration_20(struct ath_hal *ah, struct ath_tx_desc *ds,
1040 a_uint32_t burstDuration)
1042 struct ar5416_desc *ads = AR5416DESC(ds);
1044 ads->ds_ctl2 &= ~AR_BurstDur;
1045 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
1048 void ar5416Set11nVirtualMoreFrag_20(struct ath_hal *ah, struct ath_tx_desc *ds,
1051 struct ar5416_desc *ads = AR5416DESC(ds);
1054 ads->ds_ctl0 |= AR_VirtMoreFrag;
1056 ads->ds_ctl0 &= ~AR_VirtMoreFrag;