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_stopPcuReceive = ar5416StopPcuReceive,
77 /* Interrupt Functions */
78 .ah_isInterruptPending = ar5416IsInterruptPending,
79 .ah_getPendingInterrupts = ar5416GetPendingInterrupts,
80 .ah_setInterrupts = ar5416SetInterrupts,
84 void ar5416Detach(struct ath_hal *ah)
86 HALASSERT(ah != AH_NULL);
91 ar5416Attach(a_uint32_t devid,HAL_SOFTC sc, adf_os_device_t dev,
92 a_uint32_t flags, HAL_STATUS *status)
94 struct ath_hal_5416 *ahp;
97 ahp = ath_hal_malloc(sizeof (struct ath_hal_5416));
102 ah = &ahp->ah_priv.h;
104 OS_MEMCPY(&ahp->ah_priv, &ar5416hal_10, sizeof(struct ath_hal_private));
109 ah->ah_set11nTxDesc = ar5416Set11nTxDesc_20;
110 ah->ah_set11nRateScenario = ar5416Set11nRateScenario_20;
111 ah->ah_set11nAggrFirst = ar5416Set11nAggrFirst_20;
112 ah->ah_set11nAggrMiddle = ar5416Set11nAggrMiddle_20;
113 ah->ah_set11nAggrLast = ar5416Set11nAggrLast_20;
114 ah->ah_clr11nAggr = ar5416Clr11nAggr_20;
115 ah->ah_set11nBurstDuration = ar5416Set11nBurstDuration_20;
116 ah->ah_setupRxDesc = ar5416SetupRxDesc_20;
117 ah->ah_procRxDescFast = ar5416ProcRxDescFast_20;
118 ah->ah_setupTxDesc = ar5416SetupTxDesc_20;
119 ah->ah_fillTxDesc = ar5416FillTxDesc_20;
120 ah->ah_fillKeyTxDesc = ar5416FillKeyTxDesc_20;
121 ah->ah_procTxDesc = ar5416ProcTxDesc_20;
122 ah->ah_set11nVirtualMoreFrag = ar5416Set11nVirtualMoreFrag_20;
127 /**********************/
128 /* Interrupt Handling */
129 /**********************/
131 HAL_BOOL ar5416IsInterruptPending(struct ath_hal *ah)
133 a_uint32_t host_isr = OS_REG_READ(ah, AR_INTR_ASYNC_CAUSE);
135 * Some platforms trigger our ISR before applying power to
136 * the card, so make sure.
138 return ((host_isr != AR_INTR_SPURIOUS) && (host_isr & AR_INTR_MAC_IRQ));
141 HAL_BOOL ar5416GetPendingInterrupts(struct ath_hal *ah, HAL_INT *masked)
145 HAL_BOOL fatal_int = AH_FALSE;
146 a_uint32_t sync_cause;
148 if (OS_REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
149 if ((OS_REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M) != AR_RTC_STATUS_ON) {
158 isr = OS_REG_READ(ah, AR_ISR_RAC);
159 if (isr == 0xffffffff) {
164 *masked = isr & HAL_INT_COMMON;
166 #ifdef AR5416_INT_MITIGATION
167 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM)) {
168 *masked |= HAL_INT_RX;
170 if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM)) {
171 *masked |= HAL_INT_TX;
175 if (isr & AR_ISR_BCNMISC) {
178 s2_s = OS_REG_READ(ah, AR_ISR_S2_S);
180 if (s2_s & AR_ISR_S2_GTT) {
181 *masked |= HAL_INT_GTT;
184 if (s2_s & AR_ISR_S2_CST) {
185 *masked |= HAL_INT_CST;
189 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
190 *masked |= HAL_INT_RX;
191 if (isr & (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR | AR_ISR_TXEOL)) {
192 struct ath_hal_5416 *ahp = AH5416(ah);
193 a_uint32_t s0_s, s1_s;
195 *masked |= HAL_INT_TX;
196 s0_s = OS_REG_READ(ah, AR_ISR_S0_S);
197 s1_s = OS_REG_READ(ah, AR_ISR_S1_S);
198 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
199 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
200 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
201 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
205 sync_cause = OS_REG_READ(ah, AR_INTR_SYNC_CAUSE);
206 fatal_int = ((sync_cause != AR_INTR_SPURIOUS) &&
207 (sync_cause & (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))) ?
210 if (AH_TRUE == fatal_int) {
211 OS_REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
212 (void) OS_REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
219 ar5416SetInterrupts(struct ath_hal *ah, HAL_INT ints)
221 struct ath_hal_5416 *ahp = AH5416(ah);
222 a_uint32_t omask = ahp->ah_maskReg;
225 if (omask & HAL_INT_GLOBAL) {
226 OS_REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
227 (void) OS_REG_READ(ah, AR_IER);
230 mask = ints & HAL_INT_COMMON;
231 if (ints & HAL_INT_TX) {
232 #ifdef AR5416_INT_MITIGATION
233 mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM;
236 mask |= AR_IMR_TXDESC;
238 mask |= AR_IMR_TXERR;
239 mask |= AR_IMR_TXEOL;
241 if (ints & HAL_INT_RX) {
242 mask |= AR_IMR_RXERR;
243 #ifdef AR5416_INT_MITIGATION
244 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
246 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
250 if (ints & (HAL_INT_GTT | HAL_INT_CST)) {
251 mask |= AR_IMR_BCNMISC;
254 OS_REG_WRITE(ah, AR_IMR, mask);
255 (void) OS_REG_READ(ah, AR_IMR);
256 ahp->ah_maskReg = ints;
258 /* Re-enable interrupts if they were enabled before. */
259 if (ints & HAL_INT_GLOBAL) {
260 OS_REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
261 /* See explanation above... */
262 (void) OS_REG_READ(ah, AR_IER);
265 OS_REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, AR_INTR_MAC_IRQ);
266 OS_REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
267 OS_REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_ALL);
276 u_int64_t ar5416GetTsf64(struct ath_hal *ah)
280 tsf = OS_REG_READ(ah, AR_TSF_U32);
281 tsf = (tsf << 32) | OS_REG_READ(ah, AR_TSF_L32);
289 void ar5416SetRxDP(struct ath_hal *ah, a_uint32_t rxdp)
291 OS_REG_WRITE(ah, AR_RXDP, rxdp);
292 HALASSERT(OS_REG_READ(ah, AR_RXDP) == rxdp);
295 HAL_BOOL ar5416StopDmaReceive(struct ath_hal *ah)
297 OS_REG_WRITE(ah, AR_CR, AR_CR_RXD); /* Set receive disable bit */
298 if (!ath_hal_wait(ah, AR_CR, AR_CR_RXE, 0)) {
305 HAL_BOOL ar5416SetMulticastFilterIndex(struct ath_hal *ah, a_uint32_t ix)
312 val = OS_REG_READ(ah, AR_MCAST_FIL1);
313 OS_REG_WRITE(ah, AR_MCAST_FIL1, (val | (1<<(ix-32))));
315 val = OS_REG_READ(ah, AR_MCAST_FIL0);
316 OS_REG_WRITE(ah, AR_MCAST_FIL0, (val | (1<<ix)));
321 void ar5416SetRxFilter(struct ath_hal *ah, a_uint32_t bits)
325 OS_REG_WRITE(ah, AR_RX_FILTER, (bits & 0xff) | AR_RX_COMPR_BAR);
327 if (bits & HAL_RX_FILTER_PHYRADAR)
328 phybits |= AR_PHY_ERR_RADAR;
329 if (bits & HAL_RX_FILTER_PHYERR)
330 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
331 OS_REG_WRITE(ah, AR_PHY_ERR, phybits);
333 OS_REG_WRITE(ah, AR_RXCFG,OS_REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
335 OS_REG_WRITE(ah, AR_RXCFG,OS_REG_READ(ah, AR_RXCFG) &~ AR_RXCFG_ZLFDMA);
339 void ar5416EnableReceive(struct ath_hal *ah)
341 OS_REG_WRITE(ah, AR_CR, AR_CR_RXE);
344 void ar5416StopPcuReceive(struct ath_hal *ah)
346 OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
349 HAL_BOOL ar5416SetupRxDesc_20(struct ath_hal *ah, struct ath_rx_desc *ds,
350 a_uint32_t size, a_uint32_t flags)
352 struct ar5416_desc *ads = AR5416DESC(ds);
354 HALASSERT((size &~ AR_BufLen) == 0);
356 ads->ds_ctl1 = size & AR_BufLen;
357 if (flags & HAL_RXDESC_INTREQ)
358 ads->ds_ctl1 |= AR_RxIntrReq;
360 /* this should be enough */
361 ads->ds_rxstatus8 &= ~AR_RxDone;
366 HAL_STATUS ar5416ProcRxDescFast_20(struct ath_hal *ah, struct ath_rx_desc *ds,
367 a_uint32_t pa, struct ath_desc *nds,
368 struct ath_rx_status *rx_stats)
370 struct ar5416_desc ads;
371 struct ar5416_desc *adsp = AR5416DESC(ds);
372 struct ar5416_desc *ands = AR5416DESC(nds);
374 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
375 return HAL_EINPROGRESS;
377 * Given the use of a self-linked tail be very sure that the hw is
378 * done with this descriptor; the hw may have done this descriptor
379 * once and picked it up again...make sure the hw has moved on.
381 if ((ands->ds_rxstatus8 & AR_RxDone) == 0
382 && OS_REG_READ(ah, AR_RXDP) == pa)
383 return HAL_EINPROGRESS;
386 * Now we need to get the stats from the descriptor. Since desc are
387 * uncached, lets make a copy of the stats first. Note that, since we
388 * touch most of the rx stats, a memcpy would always be more efficient
390 * Next we fill in all values in a caller passed stack variable.
391 * This reduces the number of uncached accesses.
392 * Do this copy here, after the check so that when the checks fail, we
393 * dont end up copying the entire stats uselessly.
395 ads.u.rx = adsp->u.rx;
397 rx_stats->rs_status = 0;
398 rx_stats->rs_flags = 0;
400 rx_stats->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
401 rx_stats->rs_tstamp = ads.AR_RcvTimestamp;
403 /* XXX what about KeyCacheMiss? */
404 rx_stats->rs_rssi_combined =
405 MS(ads.ds_rxstatus4, AR_RxRSSICombined);
406 rx_stats->rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00);
407 rx_stats->rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01);
408 rx_stats->rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02);
409 rx_stats->rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10);
410 rx_stats->rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11);
411 rx_stats->rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12);
412 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
413 rx_stats->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
415 rx_stats->rs_keyix = HAL_RXKEYIX_INVALID;
416 /* NB: caller expected to do rate table mapping */
417 rx_stats->rs_rate = RXSTATUS_RATE(ah, (&ads));
418 rx_stats->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
420 rx_stats->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
421 rx_stats->rs_moreaggr = (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
422 rx_stats->rs_flags |= (ads.ds_rxstatus3 & AR_GI) ? HAL_RX_GI : 0;
423 rx_stats->rs_flags |= (ads.ds_rxstatus3 & AR_2040) ? HAL_RX_2040 : 0;
425 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
426 rx_stats->rs_flags |= HAL_RX_DELIM_CRC_PRE;
427 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
428 rx_stats->rs_flags |= HAL_RX_DELIM_CRC_POST;
429 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
430 rx_stats->rs_flags |= HAL_RX_DECRYPT_BUSY;
432 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
434 * These four bits should not be set together. The
435 * 5416 spec states a Michael error can only occur if
436 * DecryptCRCErr not set (and TKIP is used). Experience
437 * indicates however that you can also get Michael errors
438 * when a CRC error is detected, but these are specious.
439 * Consequently we filter them out here so we don't
440 * confuse and/or complicate drivers.
442 if (ads.ds_rxstatus8 & AR_CRCErr)
443 rx_stats->rs_status |= HAL_RXERR_CRC;
444 else if (ads.ds_rxstatus8 & AR_PHYErr) {
447 rx_stats->rs_status |= HAL_RXERR_PHY;
448 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
449 rx_stats->rs_phyerr = phyerr;
450 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
451 rx_stats->rs_status |= HAL_RXERR_DECRYPT;
452 else if (ads.ds_rxstatus8 & AR_MichaelErr)
453 rx_stats->rs_status |= HAL_RXERR_MIC;
455 rx_stats->evm0=ads.AR_RxEVM0;
456 rx_stats->evm1=ads.AR_RxEVM1;
457 rx_stats->evm2=ads.AR_RxEVM2;
466 HAL_BOOL ar5416UpdateTxTrigLevel(struct ath_hal *ah, HAL_BOOL bIncTrigLevel)
468 struct ath_hal_5416 *ahp = AH5416(ah);
469 a_uint32_t txcfg, curLevel, newLevel;
473 * Disable interrupts while futzing with the fifo level.
475 omask = ar5416SetInterrupts(ah, ahp->ah_maskReg &~ HAL_INT_GLOBAL);
477 txcfg = OS_REG_READ(ah, AR_TXCFG);
478 curLevel = MS(txcfg, AR_FTRIG);
482 if (curLevel < MAX_TX_FIFO_THRESHOLD)
484 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
486 if (newLevel != curLevel)
487 OS_REG_WRITE(ah, AR_TXCFG,
488 (txcfg &~ AR_FTRIG) | SM(newLevel, AR_FTRIG));
490 /* re-enable chip interrupts */
491 ar5416SetInterrupts(ah, omask);
493 return (newLevel != curLevel);
496 HAL_BOOL ar5416SetTxDP(struct ath_hal *ah, a_uint32_t q, a_uint32_t txdp)
498 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
499 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
502 * Make sure that TXE is deasserted before setting the TXDP. If TXE
503 * is still asserted, setting TXDP will have no effect.
505 HALASSERT((OS_REG_READ(ah, AR_Q_TXE) & (1 << q)) == 0);
507 OS_REG_WRITE(ah, AR_QTXDP(q), txdp);
512 HAL_BOOL ar5416StartTxDma(struct ath_hal *ah, a_uint32_t q)
514 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
515 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
517 /* Check to be sure we're not enabling a q that has its TXD bit set. */
518 HALASSERT((OS_REG_READ(ah, AR_Q_TXD) & (1 << q)) == 0);
520 OS_REG_WRITE(ah, AR_Q_TXE, 1 << q);
525 a_uint32_t ar5416NumTxPending(struct ath_hal *ah, a_uint32_t q)
529 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
530 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
532 npend = OS_REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
535 * Pending frame count (PFC) can momentarily go to zero
536 * while TXE remains asserted. In other words a PFC of
537 * zero is not sufficient to say that the queue has stopped.
539 if (OS_REG_READ(ah, AR_Q_TXE) & (1 << q))
543 if (npend && (AH5416(ah)->ah_txq[q].tqi_type == HAL_TX_QUEUE_CAB)) {
544 if (OS_REG_READ(ah, AR_Q_RDYTIMESHDN) & (1 << q)) {
545 isrPrintf("RTSD on CAB queue\n");
546 /* Clear the ReadyTime shutdown status bits */
547 OS_REG_WRITE(ah, AR_Q_RDYTIMESHDN, 1 << q);
554 HAL_BOOL ar5416AbortTxDma(struct ath_hal *ah)
559 * set txd on all queues
561 OS_REG_WRITE(ah, AR_Q_TXD, AR_Q_TXD_M);
566 OS_REG_SET_BIT(ah, AR_PCU_MISC, (AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF));
567 OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
568 OS_REG_SET_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
571 * wait on all tx queues
573 for (q = 0; q < AR_NUM_QCU; q++) {
574 for (i = 0; i < AR5416_ABORT_LOOPS; i++) {
575 if (!ar5416NumTxPending(ah, q))
578 OS_DELAY(AR5416_ABORT_WAIT);
580 if (i == AR5416_ABORT_LOOPS) {
586 * clear tx abort bits
588 OS_REG_CLR_BIT(ah, AR_PCU_MISC, (AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF));
589 OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
590 OS_REG_CLR_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
595 OS_REG_WRITE(ah, AR_Q_TXD, 0);
600 HAL_BOOL ar5416StopTxDma(struct ath_hal*ah, a_uint32_t q)
604 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
606 HALASSERT(AH5416(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
608 OS_REG_WRITE(ah, AR_Q_TXD, 1 << q);
609 for (i = 1000; i != 0; i--) {
610 if (ar5416NumTxPending(ah, q) == 0)
612 OS_DELAY(100); /* XXX get actual value */
615 OS_REG_WRITE(ah, AR_Q_TXD, 0);
619 HAL_BOOL ar5416SetupTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
624 a_uint32_t txRate0, a_uint32_t txTries0,
628 a_uint32_t rtsctsRate,
629 a_uint32_t rtsctsDuration,
630 a_uint32_t compicvLen,
631 a_uint32_t compivLen,
634 #define RTSCTS (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)
636 struct ar5416_desc *ads = AR5416DESC(ds);
640 ads->ds_txstatus9 &= ~AR_TxDone;
642 HALASSERT(txTries0 != 0);
643 HALASSERT(isValidPktType(type));
644 HALASSERT(isValidTxRate(txRate0));
645 HALASSERT((flags & RTSCTS) != RTSCTS);
650 ads->ds_ctl0 = (pktLen & AR_FrameLen)
651 | (txPower << AR_XmitPower_S)
652 | (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)
653 | (flags & HAL_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
654 | (flags & HAL_TXDESC_INTREQ ? AR_TxIntrReq : 0);
656 ads->ds_ctl1 = (type << AR_FrameType_S)
657 | (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0);
658 ads->ds_ctl2 = SM(txTries0, AR_XmitDataTries0);
659 ads->ds_ctl3 = (txRate0 << AR_XmitRate0_S);
661 ads->ds_ctl7 = SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel0)
662 | SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel1)
663 | SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel2)
664 | SM(AR5416_LEGACY_CHAINMASK, AR_ChainSel3);
666 if (keyIx != HAL_TXKEYIX_INVALID) {
667 /* XXX validate key index */
668 ads->ds_ctl1 |= SM(keyIx, AR_DestIdx);
669 ads->ds_ctl0 |= AR_DestIdxValid;
672 if (flags & RTSCTS) {
673 if (!isValidTxRate(rtsctsRate)) {
676 /* XXX validate rtsctsDuration */
677 ads->ds_ctl0 |= (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0)
678 | (flags & HAL_TXDESC_RTSENA ? AR_RTSEnable : 0);
679 ads->ds_ctl2 |= SM(rtsctsDuration, AR_BurstDur);
680 ads->ds_ctl3 |= (rtsctsRate << AR_RTSCTSRate_S);
687 HAL_BOOL ar5416FillTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
688 a_uint32_t segLen, HAL_BOOL firstSeg, HAL_BOOL lastSeg,
689 const struct ath_tx_desc *ds0)
691 struct ar5416_desc *ads = AR5416DESC(ds);
693 HALASSERT((segLen &~ AR_BufLen) == 0);
697 * First descriptor, don't clobber xmit control data
698 * setup by ar5416SetupTxDesc.
700 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
701 } else if (lastSeg) {
703 * Last descriptor in a multi-descriptor frame,
704 * copy the multi-rate transmit parameters from
705 * the first frame for processing on completion.
708 ads->ds_ctl1 = segLen;
709 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
710 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
713 * Intermediate descriptor in a multi-descriptor frame.
716 ads->ds_ctl1 = segLen | AR_TxMore;
720 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
725 HAL_BOOL ar5416FillKeyTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
726 HAL_KEY_TYPE keyType)
728 struct ar5416_desc *ads = AR5416DESC(ds);
730 ads->ds_ctl6 = SM(keyType, AR_EncrType);
734 HAL_STATUS ar5416ProcTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *gds)
736 struct ar5416_desc *ads = AR5416DESC(gds);
737 struct ath_tx_desc *ds = (struct ath_tx_desc *)gds;
739 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
740 return HAL_EINPROGRESS;
742 ads->ds_txstatus9 &= ~AR_TxDone;
744 /* Update software copies of the HW status */
745 ds->ds_txstat.ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
746 ds->ds_txstat.ts_tstamp = ads->AR_SendTimestamp;
747 ds->ds_txstat.ts_status = 0;
748 ds->ds_txstat.ts_flags = 0;
750 if (ads->ds_txstatus1 & AR_ExcessiveRetries)
751 ds->ds_txstat.ts_status |= HAL_TXERR_XRETRY;
752 if (ads->ds_txstatus1 & AR_Filtered)
753 ds->ds_txstat.ts_status |= HAL_TXERR_FILT;
754 if (ads->ds_txstatus1 & AR_FIFOUnderrun)
755 ds->ds_txstat.ts_status |= HAL_TXERR_FIFO;
756 if (ads->ds_txstatus9 & AR_TxOpExceeded)
757 ds->ds_txstat.ts_status |= HAL_TXERR_XTXOP;
758 if (ads->ds_txstatus1 & AR_TxTimerExpired)
759 ds->ds_txstat.ts_status |= HAL_TXERR_TIMER_EXPIRED;
761 if (ads->ds_txstatus1 & AR_DescCfgErr)
762 ds->ds_txstat.ts_flags |= HAL_TX_DESC_CFG_ERR;
763 if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
764 ds->ds_txstat.ts_flags |= HAL_TX_DATA_UNDERRUN;
765 ar5416UpdateTxTrigLevel(ah, AH_TRUE);
767 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
768 ds->ds_txstat.ts_flags |= HAL_TX_DELIM_UNDERRUN;
769 ar5416UpdateTxTrigLevel(ah, AH_TRUE);
771 if (ads->ds_txstatus0 & AR_TxBaStatus) {
772 ds->ds_txstat.ts_flags |= HAL_TX_BA;
773 ds->ds_txstat.ba_low = ads->AR_BaBitmapLow;
774 ds->ds_txstat.ba_high = ads->AR_BaBitmapHigh;
778 * Extract the transmit rate used and mark the rate as
779 * ``alternate'' if it wasn't the series 0 rate.
781 ds->ds_txstat.ts_rate = MS(ads->ds_txstatus9, AR_FinalTxIdx);
782 ds->ds_txstat.ts_rssi_combined =
783 MS(ads->ds_txstatus5, AR_TxRSSICombined);
784 ds->ds_txstat.ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
785 ds->ds_txstat.ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
786 ds->ds_txstat.ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
787 ds->ds_txstat.ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
788 ds->ds_txstat.ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
789 ds->ds_txstat.ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
790 ds->ds_txstat.evm0 = ads->AR_TxEVM0;
791 ds->ds_txstat.evm1 = ads->AR_TxEVM1;
792 ds->ds_txstat.evm2 = ads->AR_TxEVM2;
793 ds->ds_txstat.ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
794 ds->ds_txstat.ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
795 ds->ds_txstat.ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
796 ds->ds_txstat.ts_antenna = 0; /* ignored for owl */
801 void ar5416Set11nTxDesc_20(struct ath_hal *ah, struct ath_tx_desc *ds,
802 a_uint32_t pktLen, HAL_PKT_TYPE type, a_uint32_t txPower,
803 a_uint32_t keyIx, HAL_KEY_TYPE keyType,
806 struct ar5416_desc *ads = AR5416DESC(ds);
808 HALASSERT(isValidPktType(type));
809 HALASSERT(isValidKeyType(keyType));
814 ads->ds_ctl0 = (pktLen & AR_FrameLen)
815 | (flags & HAL_TXDESC_VMF ? AR_VirtMoreFrag : 0)
816 | SM(txPower, AR_XmitPower)
817 | (flags & HAL_TXDESC_RTSENA ? AR_RTSEnable : 0)
818 | (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)
819 | (flags & HAL_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
820 | (flags & HAL_TXDESC_INTREQ ? AR_TxIntrReq : 0)
821 | (keyIx != HAL_TXKEYIX_INVALID ? AR_DestIdxValid : 0)
822 | (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0);
824 ads->ds_ctl1 = (keyIx != HAL_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
825 | SM(type, AR_FrameType)
826 | (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0)
827 | (flags & HAL_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
828 | (flags & HAL_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
830 ads->ds_ctl6 = SM(keyType, AR_EncrType);
835 void ar5416Set11nRateScenario_20(struct ath_hal *ah, struct ath_tx_desc *ds,
836 a_uint32_t durUpdateEn, a_uint32_t rtsctsRate,
837 a_uint32_t rtsctsDuration,
838 HAL_11N_RATE_SERIES series[], a_uint32_t nseries,
841 struct ar5416_desc *ads = AR5416DESC(ds);
844 HALASSERT(nseries == 4);
848 * Rate control settings override
850 ds_ctl0 = ads->ds_ctl0;
852 if (flags & (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) {
853 if (flags & HAL_TXDESC_RTSENA) {
854 ds_ctl0 &= ~AR_CTSEnable;
855 ds_ctl0 |= AR_RTSEnable;
857 ds_ctl0 &= ~AR_RTSEnable;
858 ds_ctl0 |= AR_CTSEnable;
861 ds_ctl0 = (ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
864 ads->ds_ctl0 = ds_ctl0;
866 ads->ds_ctl2 = set11nTries(series, 0)
867 | set11nTries(series, 1)
868 | set11nTries(series, 2)
869 | set11nTries(series, 3)
870 | (durUpdateEn ? AR_DurUpdateEn : 0);
872 ads->ds_ctl3 = set11nRate(series, 0)
873 | set11nRate(series, 1)
874 | set11nRate(series, 2)
875 | set11nRate(series, 3);
877 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
878 | set11nPktDurRTSCTS(series, 1);
880 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
881 | set11nPktDurRTSCTS(series, 3);
883 ads->ds_ctl7 = set11nRateFlags(series, 0)
884 | set11nRateFlags(series, 1)
885 | set11nRateFlags(series, 2)
886 | set11nRateFlags(series, 3)
887 | SM(rtsctsRate, AR_RTSCTSRate);
892 void ar5416Set11nRateScenario_20(struct ath_hal *ah, struct ath_tx_desc *ds,
893 a_uint32_t durUpdateEn, a_uint32_t rtsctsRate,
894 a_uint32_t rtsctsDuration,
895 HAL_11N_RATE_SERIES series[], a_uint32_t nseries,
898 struct ar5416_desc *ads = AR5416DESC(ds);
901 HALASSERT(nseries == 4);
905 * Rate control settings override
907 if (flags & (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) {
908 ds_ctl0 = ads->ds_ctl0;
910 if (flags & HAL_TXDESC_RTSENA) {
911 ds_ctl0 &= ~AR_CTSEnable;
912 ds_ctl0 |= AR_RTSEnable;
914 ds_ctl0 &= ~AR_RTSEnable;
915 ds_ctl0 |= AR_CTSEnable;
918 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 ar5416Set11nAggrFirst_20(struct ath_hal *ah, struct ath_tx_desc *ds, a_uint32_t aggrLen,
948 a_uint32_t numDelims)
950 struct ar5416_desc *ads = AR5416DESC(ds);
952 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
954 ads->ds_ctl6 &= ~(AR_AggrLen | AR_PadDelim);
955 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen) |
956 SM(numDelims, AR_PadDelim);
959 void ar5416Set11nAggrMiddle_20(struct ath_hal *ah, struct ath_tx_desc *ds, a_uint32_t numDelims)
961 struct ar5416_desc *ads = AR5416DESC(ds);
964 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
967 * We use a stack variable to manipulate ctl6 to reduce uncached
968 * read modify, modfiy, write.
971 ctl6 &= ~AR_PadDelim;
972 ctl6 |= SM(numDelims, AR_PadDelim);
976 void ar5416Set11nAggrLast_20(struct ath_hal *ah, struct ath_tx_desc *ds)
978 struct ar5416_desc *ads = AR5416DESC(ds);
980 ads->ds_ctl1 |= AR_IsAggr;
981 ads->ds_ctl1 &= ~AR_MoreAggr;
982 ads->ds_ctl6 &= ~AR_PadDelim;
985 void ar5416Clr11nAggr_20(struct ath_hal *ah, struct ath_tx_desc *ds)
987 struct ar5416_desc *ads = AR5416DESC(ds);
989 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
992 void ar5416Set11nBurstDuration_20(struct ath_hal *ah, struct ath_tx_desc *ds,
993 a_uint32_t burstDuration)
995 struct ar5416_desc *ads = AR5416DESC(ds);
997 ads->ds_ctl2 &= ~AR_BurstDur;
998 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
1001 void ar5416Set11nVirtualMoreFrag_20(struct ath_hal *ah, struct ath_tx_desc *ds,
1004 struct ar5416_desc *ads = AR5416DESC(ds);
1007 ads->ds_ctl0 |= AR_VirtMoreFrag;
1009 ads->ds_ctl0 &= ~AR_VirtMoreFrag;