2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2008 Atheros Communications, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "ah_internal.h"
25 #include "ar5212/ar5212.h"
26 #include "ar5212/ar5212reg.h"
27 #include "ar5212/ar5212desc.h"
28 #include "ar5212/ar5212phy.h"
29 #ifdef AH_SUPPORT_5311
30 #include "ar5212/ar5311reg.h"
33 #ifdef AH_NEED_DESC_SWAP
34 static void ar5212SwapTxDesc(struct ath_desc *ds);
38 * Update Tx FIFO trigger level.
40 * Set bIncTrigLevel to TRUE to increase the trigger level.
41 * Set bIncTrigLevel to FALSE to decrease the trigger level.
43 * Returns TRUE if the trigger level was updated
46 ar5212UpdateTxTrigLevel(struct ath_hal *ah, HAL_BOOL bIncTrigLevel)
48 struct ath_hal_5212 *ahp = AH5212(ah);
49 uint32_t txcfg, curLevel, newLevel;
52 if (ahp->ah_txTrigLev >= ahp->ah_maxTxTrigLev)
56 * Disable interrupts while futzing with the fifo level.
58 omask = ath_hal_setInterrupts(ah, ahp->ah_maskReg &~ HAL_INT_GLOBAL);
60 txcfg = OS_REG_READ(ah, AR_TXCFG);
61 curLevel = MS(txcfg, AR_FTRIG);
63 if (bIncTrigLevel) { /* increase the trigger level */
64 if (curLevel < ahp->ah_maxTxTrigLev)
66 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
68 if (newLevel != curLevel)
69 /* Update the trigger level */
70 OS_REG_WRITE(ah, AR_TXCFG,
71 (txcfg &~ AR_FTRIG) | SM(newLevel, AR_FTRIG));
73 ahp->ah_txTrigLev = newLevel;
75 /* re-enable chip interrupts */
76 ath_hal_setInterrupts(ah, omask);
78 return (newLevel != curLevel);
82 * Set the properties of the tx queue with the parameters
86 ar5212SetTxQueueProps(struct ath_hal *ah, int q, const HAL_TXQ_INFO *qInfo)
88 struct ath_hal_5212 *ahp = AH5212(ah);
89 HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
91 if (q >= pCap->halTotalQueues) {
92 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
96 return ath_hal_setTxQProps(ah, &ahp->ah_txq[q], qInfo);
100 * Return the properties for the specified tx queue.
103 ar5212GetTxQueueProps(struct ath_hal *ah, int q, HAL_TXQ_INFO *qInfo)
105 struct ath_hal_5212 *ahp = AH5212(ah);
106 HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
109 if (q >= pCap->halTotalQueues) {
110 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
114 return ath_hal_getTxQProps(ah, qInfo, &ahp->ah_txq[q]);
118 * Allocate and initialize a tx DCU/QCU combination.
121 ar5212SetupTxQueue(struct ath_hal *ah, HAL_TX_QUEUE type,
122 const HAL_TXQ_INFO *qInfo)
124 struct ath_hal_5212 *ahp = AH5212(ah);
125 HAL_TX_QUEUE_INFO *qi;
126 HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
129 /* by default enable OK+ERR+DESC+URN interrupts */
130 defqflags = HAL_TXQ_TXOKINT_ENABLE
131 | HAL_TXQ_TXERRINT_ENABLE
132 | HAL_TXQ_TXDESCINT_ENABLE
133 | HAL_TXQ_TXURNINT_ENABLE;
134 /* XXX move queue assignment to driver */
136 case HAL_TX_QUEUE_BEACON:
137 q = pCap->halTotalQueues-1; /* highest priority */
138 defqflags |= HAL_TXQ_DBA_GATED
139 | HAL_TXQ_CBR_DIS_QEMPTY
140 | HAL_TXQ_ARB_LOCKOUT_GLOBAL
141 | HAL_TXQ_BACKOFF_DISABLE;
143 case HAL_TX_QUEUE_CAB:
144 q = pCap->halTotalQueues-2; /* next highest priority */
145 defqflags |= HAL_TXQ_DBA_GATED
146 | HAL_TXQ_CBR_DIS_QEMPTY
147 | HAL_TXQ_CBR_DIS_BEMPTY
148 | HAL_TXQ_ARB_LOCKOUT_GLOBAL
149 | HAL_TXQ_BACKOFF_DISABLE;
151 case HAL_TX_QUEUE_UAPSD:
152 q = pCap->halTotalQueues-3; /* nextest highest priority */
153 if (ahp->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE) {
154 HALDEBUG(ah, HAL_DEBUG_ANY,
155 "%s: no available UAPSD tx queue\n", __func__);
159 case HAL_TX_QUEUE_DATA:
160 for (q = 0; q < pCap->halTotalQueues; q++)
161 if (ahp->ah_txq[q].tqi_type == HAL_TX_QUEUE_INACTIVE)
163 if (q == pCap->halTotalQueues) {
164 HALDEBUG(ah, HAL_DEBUG_ANY,
165 "%s: no available tx queue\n", __func__);
170 HALDEBUG(ah, HAL_DEBUG_ANY,
171 "%s: bad tx queue type %u\n", __func__, type);
175 HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);
177 qi = &ahp->ah_txq[q];
178 if (qi->tqi_type != HAL_TX_QUEUE_INACTIVE) {
179 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: tx queue %u already active\n",
183 OS_MEMZERO(qi, sizeof(HAL_TX_QUEUE_INFO));
185 if (qInfo == AH_NULL) {
186 qi->tqi_qflags = defqflags;
187 qi->tqi_aifs = INIT_AIFS;
188 qi->tqi_cwmin = HAL_TXQ_USEDEFAULT; /* NB: do at reset */
189 qi->tqi_cwmax = INIT_CWMAX;
190 qi->tqi_shretry = INIT_SH_RETRY;
191 qi->tqi_lgretry = INIT_LG_RETRY;
192 qi->tqi_physCompBuf = 0;
194 qi->tqi_physCompBuf = qInfo->tqi_compBuf;
195 (void) ar5212SetTxQueueProps(ah, q, qInfo);
197 /* NB: must be followed by ar5212ResetTxQueue */
202 * Update the h/w interrupt registers to reflect a tx q's configuration.
205 setTxQInterrupts(struct ath_hal *ah, HAL_TX_QUEUE_INFO *qi)
207 struct ath_hal_5212 *ahp = AH5212(ah);
209 HALDEBUG(ah, HAL_DEBUG_TXQUEUE,
210 "%s: tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n", __func__,
211 ahp->ah_txOkInterruptMask, ahp->ah_txErrInterruptMask,
212 ahp->ah_txDescInterruptMask, ahp->ah_txEolInterruptMask,
213 ahp->ah_txUrnInterruptMask);
215 OS_REG_WRITE(ah, AR_IMR_S0,
216 SM(ahp->ah_txOkInterruptMask, AR_IMR_S0_QCU_TXOK)
217 | SM(ahp->ah_txDescInterruptMask, AR_IMR_S0_QCU_TXDESC)
219 OS_REG_WRITE(ah, AR_IMR_S1,
220 SM(ahp->ah_txErrInterruptMask, AR_IMR_S1_QCU_TXERR)
221 | SM(ahp->ah_txEolInterruptMask, AR_IMR_S1_QCU_TXEOL)
223 OS_REG_RMW_FIELD(ah, AR_IMR_S2,
224 AR_IMR_S2_QCU_TXURN, ahp->ah_txUrnInterruptMask);
228 * Free a tx DCU/QCU combination.
231 ar5212ReleaseTxQueue(struct ath_hal *ah, u_int q)
233 struct ath_hal_5212 *ahp = AH5212(ah);
234 HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
235 HAL_TX_QUEUE_INFO *qi;
237 if (q >= pCap->halTotalQueues) {
238 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
242 qi = &ahp->ah_txq[q];
243 if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {
244 HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: inactive queue %u\n",
249 HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: release queue %u\n", __func__, q);
251 qi->tqi_type = HAL_TX_QUEUE_INACTIVE;
252 ahp->ah_txOkInterruptMask &= ~(1 << q);
253 ahp->ah_txErrInterruptMask &= ~(1 << q);
254 ahp->ah_txDescInterruptMask &= ~(1 << q);
255 ahp->ah_txEolInterruptMask &= ~(1 << q);
256 ahp->ah_txUrnInterruptMask &= ~(1 << q);
257 setTxQInterrupts(ah, qi);
263 * Set the retry, aifs, cwmin/max, readyTime regs for specified queue
265 * phwChannel has been set to point to the current channel
267 #define TU_TO_USEC(_tu) ((_tu) << 10)
269 ar5212ResetTxQueue(struct ath_hal *ah, u_int q)
271 struct ath_hal_5212 *ahp = AH5212(ah);
272 HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
273 const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan;
274 HAL_TX_QUEUE_INFO *qi;
275 uint32_t cwMin, chanCwMin, qmisc, dmisc;
277 if (q >= pCap->halTotalQueues) {
278 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
282 qi = &ahp->ah_txq[q];
283 if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {
284 HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: inactive queue %u\n",
286 return AH_TRUE; /* XXX??? */
289 HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: reset queue %u\n", __func__, q);
291 if (qi->tqi_cwmin == HAL_TXQ_USEDEFAULT) {
293 * Select cwmin according to channel type.
294 * NB: chan can be NULL during attach
296 if (chan && IEEE80211_IS_CHAN_B(chan))
297 chanCwMin = INIT_CWMIN_11B;
299 chanCwMin = INIT_CWMIN;
300 /* make sure that the CWmin is of the form (2^n - 1) */
301 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1)
304 cwMin = qi->tqi_cwmin;
306 /* set cwMin/Max and AIFS values */
307 OS_REG_WRITE(ah, AR_DLCL_IFS(q),
308 SM(cwMin, AR_D_LCL_IFS_CWMIN)
309 | SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX)
310 | SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
312 /* Set retry limit values */
313 OS_REG_WRITE(ah, AR_DRETRY_LIMIT(q),
314 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH)
315 | SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG)
316 | SM(qi->tqi_lgretry, AR_D_RETRY_LIMIT_FR_LG)
317 | SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH)
320 /* NB: always enable early termination on the QCU */
321 qmisc = AR_Q_MISC_DCU_EARLY_TERM_REQ
322 | SM(AR_Q_MISC_FSP_ASAP, AR_Q_MISC_FSP);
324 /* NB: always enable DCU to wait for next fragment from QCU */
325 dmisc = AR_D_MISC_FRAG_WAIT_EN;
327 #ifdef AH_SUPPORT_5311
328 if (AH_PRIVATE(ah)->ah_macVersion < AR_SREV_VERSION_OAHU) {
329 /* Configure DCU to use the global sequence count */
330 dmisc |= AR5311_D_MISC_SEQ_NUM_CONTROL;
333 /* multiqueue support */
334 if (qi->tqi_cbrPeriod) {
335 OS_REG_WRITE(ah, AR_QCBRCFG(q),
336 SM(qi->tqi_cbrPeriod,AR_Q_CBRCFG_CBR_INTERVAL)
337 | SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_CBR_OVF_THRESH));
338 qmisc = (qmisc &~ AR_Q_MISC_FSP) | AR_Q_MISC_FSP_CBR;
339 if (qi->tqi_cbrOverflowLimit)
340 qmisc |= AR_Q_MISC_CBR_EXP_CNTR_LIMIT;
342 if (qi->tqi_readyTime) {
343 OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),
344 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_INT)
345 | AR_Q_RDYTIMECFG_ENA);
348 OS_REG_WRITE(ah, AR_DCHNTIME(q),
349 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR)
350 | (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
352 if (qi->tqi_readyTime &&
353 (qi->tqi_qflags & HAL_TXQ_RDYTIME_EXP_POLICY_ENABLE))
354 qmisc |= AR_Q_MISC_RDYTIME_EXP_POLICY;
355 if (qi->tqi_qflags & HAL_TXQ_DBA_GATED)
356 qmisc = (qmisc &~ AR_Q_MISC_FSP) | AR_Q_MISC_FSP_DBA_GATED;
357 if (MS(qmisc, AR_Q_MISC_FSP) != AR_Q_MISC_FSP_ASAP) {
359 * These are meangingful only when not scheduled asap.
361 if (qi->tqi_qflags & HAL_TXQ_CBR_DIS_BEMPTY)
362 qmisc |= AR_Q_MISC_CBR_INCR_DIS0;
364 qmisc &= ~AR_Q_MISC_CBR_INCR_DIS0;
365 if (qi->tqi_qflags & HAL_TXQ_CBR_DIS_QEMPTY)
366 qmisc |= AR_Q_MISC_CBR_INCR_DIS1;
368 qmisc &= ~AR_Q_MISC_CBR_INCR_DIS1;
371 if (qi->tqi_qflags & HAL_TXQ_BACKOFF_DISABLE)
372 dmisc |= AR_D_MISC_POST_FR_BKOFF_DIS;
373 if (qi->tqi_qflags & HAL_TXQ_FRAG_BURST_BACKOFF_ENABLE)
374 dmisc |= AR_D_MISC_FRAG_BKOFF_EN;
375 if (qi->tqi_qflags & HAL_TXQ_ARB_LOCKOUT_GLOBAL)
376 dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
377 AR_D_MISC_ARB_LOCKOUT_CNTRL);
378 else if (qi->tqi_qflags & HAL_TXQ_ARB_LOCKOUT_INTRA)
379 dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_INTRA_FR,
380 AR_D_MISC_ARB_LOCKOUT_CNTRL);
381 if (qi->tqi_qflags & HAL_TXQ_IGNORE_VIRTCOL)
382 dmisc |= SM(AR_D_MISC_VIR_COL_HANDLING_IGNORE,
383 AR_D_MISC_VIR_COL_HANDLING);
384 if (qi->tqi_qflags & HAL_TXQ_SEQNUM_INC_DIS)
385 dmisc |= AR_D_MISC_SEQ_NUM_INCR_DIS;
388 * Fillin type-dependent bits. Most of this can be
389 * removed by specifying the queue parameters in the
390 * driver; it's here for backwards compatibility.
392 switch (qi->tqi_type) {
393 case HAL_TX_QUEUE_BEACON: /* beacon frames */
394 qmisc |= AR_Q_MISC_FSP_DBA_GATED
395 | AR_Q_MISC_BEACON_USE
396 | AR_Q_MISC_CBR_INCR_DIS1;
398 dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
399 AR_D_MISC_ARB_LOCKOUT_CNTRL)
400 | AR_D_MISC_BEACON_USE
401 | AR_D_MISC_POST_FR_BKOFF_DIS;
403 case HAL_TX_QUEUE_CAB: /* CAB frames */
405 * No longer Enable AR_Q_MISC_RDYTIME_EXP_POLICY,
406 * There is an issue with the CAB Queue
407 * not properly refreshing the Tx descriptor if
408 * the TXE clear setting is used.
410 qmisc |= AR_Q_MISC_FSP_DBA_GATED
411 | AR_Q_MISC_CBR_INCR_DIS1
412 | AR_Q_MISC_CBR_INCR_DIS0;
414 if (qi->tqi_readyTime) {
415 HALDEBUG(ah, HAL_DEBUG_TXQUEUE,
416 "%s: using tqi_readyTime\n", __func__);
417 OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),
418 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_INT) |
419 AR_Q_RDYTIMECFG_ENA);
423 * NB: don't set default ready time if driver
424 * has explicitly specified something. This is
425 * here solely for backwards compatibility.
428 * XXX for now, hard-code a CAB interval of 70%
429 * XXX of the total beacon interval.
432 value = (ahp->ah_beaconInterval * 70 / 100)
433 - (ah->ah_config.ah_sw_beacon_response_time -
434 + ah->ah_config.ah_dma_beacon_response_time)
435 - ah->ah_config.ah_additional_swba_backoff;
437 * XXX Ensure it isn't too low - nothing lower
442 HALDEBUG(ah, HAL_DEBUG_TXQUEUE,
443 "%s: defaulting to rdytime = %d uS\n",
445 OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),
446 SM(TU_TO_USEC(value), AR_Q_RDYTIMECFG_INT) |
447 AR_Q_RDYTIMECFG_ENA);
449 dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
450 AR_D_MISC_ARB_LOCKOUT_CNTRL);
452 default: /* NB: silence compiler */
456 OS_REG_WRITE(ah, AR_QMISC(q), qmisc);
457 OS_REG_WRITE(ah, AR_DMISC(q), dmisc);
459 /* Setup compression scratchpad buffer */
461 * XXX: calling this asynchronously to queue operation can
462 * cause unexpected behavior!!!
464 if (qi->tqi_physCompBuf) {
465 HALASSERT(qi->tqi_type == HAL_TX_QUEUE_DATA ||
466 qi->tqi_type == HAL_TX_QUEUE_UAPSD);
467 OS_REG_WRITE(ah, AR_Q_CBBS, (80 + 2*q));
468 OS_REG_WRITE(ah, AR_Q_CBBA, qi->tqi_physCompBuf);
469 OS_REG_WRITE(ah, AR_Q_CBC, HAL_COMP_BUF_MAX_SIZE/1024);
470 OS_REG_WRITE(ah, AR_Q0_MISC + 4*q,
471 OS_REG_READ(ah, AR_Q0_MISC + 4*q)
472 | AR_Q_MISC_QCU_COMP_EN);
476 * Always update the secondary interrupt mask registers - this
477 * could be a new queue getting enabled in a running system or
478 * hw getting re-initialized during a reset!
480 * Since we don't differentiate between tx interrupts corresponding
481 * to individual queues - secondary tx mask regs are always unmasked;
482 * tx interrupts are enabled/disabled for all queues collectively
483 * using the primary mask reg
485 if (qi->tqi_qflags & HAL_TXQ_TXOKINT_ENABLE)
486 ahp->ah_txOkInterruptMask |= 1 << q;
488 ahp->ah_txOkInterruptMask &= ~(1 << q);
489 if (qi->tqi_qflags & HAL_TXQ_TXERRINT_ENABLE)
490 ahp->ah_txErrInterruptMask |= 1 << q;
492 ahp->ah_txErrInterruptMask &= ~(1 << q);
493 if (qi->tqi_qflags & HAL_TXQ_TXDESCINT_ENABLE)
494 ahp->ah_txDescInterruptMask |= 1 << q;
496 ahp->ah_txDescInterruptMask &= ~(1 << q);
497 if (qi->tqi_qflags & HAL_TXQ_TXEOLINT_ENABLE)
498 ahp->ah_txEolInterruptMask |= 1 << q;
500 ahp->ah_txEolInterruptMask &= ~(1 << q);
501 if (qi->tqi_qflags & HAL_TXQ_TXURNINT_ENABLE)
502 ahp->ah_txUrnInterruptMask |= 1 << q;
504 ahp->ah_txUrnInterruptMask &= ~(1 << q);
505 setTxQInterrupts(ah, qi);
512 * Get the TXDP for the specified queue
515 ar5212GetTxDP(struct ath_hal *ah, u_int q)
517 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
518 return OS_REG_READ(ah, AR_QTXDP(q));
522 * Set the TxDP for the specified queue
525 ar5212SetTxDP(struct ath_hal *ah, u_int q, uint32_t txdp)
527 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
528 HALASSERT(AH5212(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
531 * Make sure that TXE is deasserted before setting the TXDP. If TXE
532 * is still asserted, setting TXDP will have no effect.
534 HALASSERT((OS_REG_READ(ah, AR_Q_TXE) & (1 << q)) == 0);
536 OS_REG_WRITE(ah, AR_QTXDP(q), txdp);
542 * Set Transmit Enable bits for the specified queue
545 ar5212StartTxDma(struct ath_hal *ah, u_int q)
547 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
549 HALASSERT(AH5212(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
551 HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);
553 /* Check to be sure we're not enabling a q that has its TXD bit set. */
554 HALASSERT((OS_REG_READ(ah, AR_Q_TXD) & (1 << q)) == 0);
556 OS_REG_WRITE(ah, AR_Q_TXE, 1 << q);
561 * Return the number of pending frames or 0 if the specified
565 ar5212NumTxPending(struct ath_hal *ah, u_int q)
569 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
570 HALASSERT(AH5212(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
572 npend = OS_REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
575 * Pending frame count (PFC) can momentarily go to zero
576 * while TXE remains asserted. In other words a PFC of
577 * zero is not sufficient to say that the queue has stopped.
579 if (OS_REG_READ(ah, AR_Q_TXE) & (1 << q))
580 npend = 1; /* arbitrarily return 1 */
586 * Stop transmit on the specified queue
589 ar5212StopTxDma(struct ath_hal *ah, u_int q)
594 HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);
596 HALASSERT(AH5212(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
598 OS_REG_WRITE(ah, AR_Q_TXD, 1 << q);
599 for (i = 1000; i != 0; i--) {
600 if (ar5212NumTxPending(ah, q) == 0)
602 OS_DELAY(100); /* XXX get actual value */
606 HALDEBUG(ah, HAL_DEBUG_ANY,
607 "%s: queue %u DMA did not stop in 100 msec\n", __func__, q);
608 HALDEBUG(ah, HAL_DEBUG_ANY,
609 "%s: QSTS 0x%x Q_TXE 0x%x Q_TXD 0x%x Q_CBR 0x%x\n", __func__,
610 OS_REG_READ(ah, AR_QSTS(q)), OS_REG_READ(ah, AR_Q_TXE),
611 OS_REG_READ(ah, AR_Q_TXD), OS_REG_READ(ah, AR_QCBRCFG(q)));
612 HALDEBUG(ah, HAL_DEBUG_ANY,
613 "%s: Q_MISC 0x%x Q_RDYTIMECFG 0x%x Q_RDYTIMESHDN 0x%x\n",
614 __func__, OS_REG_READ(ah, AR_QMISC(q)),
615 OS_REG_READ(ah, AR_QRDYTIMECFG(q)),
616 OS_REG_READ(ah, AR_Q_RDYTIMESHDN));
618 #endif /* AH_DEBUG */
620 /* 2413+ and up can kill packets at the PCU level */
621 if (ar5212NumTxPending(ah, q) &&
622 (IS_2413(ah) || IS_5413(ah) || IS_2425(ah) || IS_2417(ah))) {
625 HALDEBUG(ah, HAL_DEBUG_TXQUEUE,
626 "%s: Num of pending TX Frames %d on Q %d\n",
627 __func__, ar5212NumTxPending(ah, q), q);
629 /* Kill last PCU Tx Frame */
630 /* TODO - save off and restore current values of Q1/Q2? */
631 for (j = 0; j < 2; j++) {
632 tsfLow = OS_REG_READ(ah, AR_TSF_L32);
633 OS_REG_WRITE(ah, AR_QUIET2, SM(100, AR_QUIET2_QUIET_PER) |
634 SM(10, AR_QUIET2_QUIET_DUR));
635 OS_REG_WRITE(ah, AR_QUIET1, AR_QUIET1_QUIET_ENABLE |
636 SM(tsfLow >> 10, AR_QUIET1_NEXT_QUIET));
637 if ((OS_REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10)) {
640 HALDEBUG(ah, HAL_DEBUG_ANY,
641 "%s: TSF moved while trying to set quiet time "
642 "TSF: 0x%08x\n", __func__, tsfLow);
643 HALASSERT(j < 1); /* TSF shouldn't count twice or reg access is taking forever */
646 OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_CHAN_IDLE);
648 /* Allow the quiet mechanism to do its work */
650 OS_REG_CLR_BIT(ah, AR_QUIET1, AR_QUIET1_QUIET_ENABLE);
652 /* Give at least 1 millisec more to wait */
655 /* Verify all transmit is dead */
656 while (ar5212NumTxPending(ah, q)) {
658 HALDEBUG(ah, HAL_DEBUG_ANY,
659 "%s: Failed to stop Tx DMA in %d msec after killing last frame\n",
666 OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_CHAN_IDLE);
669 OS_REG_WRITE(ah, AR_Q_TXD, 0);
674 * Descriptor Access Functions
677 #define VALID_PKT_TYPES \
678 ((1<<HAL_PKT_TYPE_NORMAL)|(1<<HAL_PKT_TYPE_ATIM)|\
679 (1<<HAL_PKT_TYPE_PSPOLL)|(1<<HAL_PKT_TYPE_PROBE_RESP)|\
680 (1<<HAL_PKT_TYPE_BEACON))
681 #define isValidPktType(_t) ((1<<(_t)) & VALID_PKT_TYPES)
682 #define VALID_TX_RATES \
683 ((1<<0x0b)|(1<<0x0f)|(1<<0x0a)|(1<<0x0e)|(1<<0x09)|(1<<0x0d)|\
684 (1<<0x08)|(1<<0x0c)|(1<<0x1b)|(1<<0x1a)|(1<<0x1e)|(1<<0x19)|\
685 (1<<0x1d)|(1<<0x18)|(1<<0x1c))
686 #define isValidTxRate(_r) ((1<<(_r)) & VALID_TX_RATES)
689 ar5212SetupTxDesc(struct ath_hal *ah, struct ath_desc *ds,
694 u_int txRate0, u_int txTries0,
699 u_int rtsctsDuration,
704 #define RTSCTS (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)
705 struct ar5212_desc *ads = AR5212DESC(ds);
706 struct ath_hal_5212 *ahp = AH5212(ah);
710 HALASSERT(txTries0 != 0);
711 HALASSERT(isValidPktType(type));
712 HALASSERT(isValidTxRate(txRate0));
713 HALASSERT((flags & RTSCTS) != RTSCTS);
714 /* XXX validate antMode */
716 txPower = (txPower + ahp->ah_txPowerIndexOffset );
717 if(txPower > 63) txPower=63;
719 ads->ds_ctl0 = (pktLen & AR_FrameLen)
720 | (txPower << AR_XmitPower_S)
721 | (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)
722 | (flags & HAL_TXDESC_CLRDMASK ? AR_ClearDestMask : 0)
723 | SM(antMode, AR_AntModeXmit)
724 | (flags & HAL_TXDESC_INTREQ ? AR_TxInterReq : 0)
726 ads->ds_ctl1 = (type << AR_FrmType_S)
727 | (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0)
728 | (comp << AR_CompProc_S)
729 | (compicvLen << AR_CompICVLen_S)
730 | (compivLen << AR_CompIVLen_S)
732 ads->ds_ctl2 = SM(txTries0, AR_XmitDataTries0)
733 | (flags & HAL_TXDESC_DURENA ? AR_DurUpdateEna : 0)
735 ads->ds_ctl3 = (txRate0 << AR_XmitRate0_S)
737 if (keyIx != HAL_TXKEYIX_INVALID) {
738 /* XXX validate key index */
739 ads->ds_ctl1 |= SM(keyIx, AR_DestIdx);
740 ads->ds_ctl0 |= AR_DestIdxValid;
742 if (flags & RTSCTS) {
743 if (!isValidTxRate(rtsctsRate)) {
744 HALDEBUG(ah, HAL_DEBUG_ANY,
745 "%s: invalid rts/cts rate 0x%x\n",
746 __func__, rtsctsRate);
749 /* XXX validate rtsctsDuration */
750 ads->ds_ctl0 |= (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0)
751 | (flags & HAL_TXDESC_RTSENA ? AR_RTSCTSEnable : 0)
753 ads->ds_ctl2 |= SM(rtsctsDuration, AR_RTSCTSDuration);
754 ads->ds_ctl3 |= (rtsctsRate << AR_RTSCTSRate_S);
761 ar5212SetupXTxDesc(struct ath_hal *ah, struct ath_desc *ds,
762 u_int txRate1, u_int txTries1,
763 u_int txRate2, u_int txTries2,
764 u_int txRate3, u_int txTries3)
766 struct ar5212_desc *ads = AR5212DESC(ds);
769 HALASSERT(isValidTxRate(txRate1));
770 ads->ds_ctl2 |= SM(txTries1, AR_XmitDataTries1)
773 ads->ds_ctl3 |= (txRate1 << AR_XmitRate1_S);
776 HALASSERT(isValidTxRate(txRate2));
777 ads->ds_ctl2 |= SM(txTries2, AR_XmitDataTries2)
780 ads->ds_ctl3 |= (txRate2 << AR_XmitRate2_S);
783 HALASSERT(isValidTxRate(txRate3));
784 ads->ds_ctl2 |= SM(txTries3, AR_XmitDataTries3)
787 ads->ds_ctl3 |= (txRate3 << AR_XmitRate3_S);
793 ar5212IntrReqTxDesc(struct ath_hal *ah, struct ath_desc *ds)
795 struct ar5212_desc *ads = AR5212DESC(ds);
797 #ifdef AH_NEED_DESC_SWAP
798 ads->ds_ctl0 |= __bswap32(AR_TxInterReq);
800 ads->ds_ctl0 |= AR_TxInterReq;
805 ar5212FillTxDesc(struct ath_hal *ah, struct ath_desc *ds,
806 HAL_DMA_ADDR *bufAddrList, uint32_t *segLenList, u_int qcuId,
807 u_int descId, HAL_BOOL firstSeg, HAL_BOOL lastSeg,
808 const struct ath_desc *ds0)
810 struct ar5212_desc *ads = AR5212DESC(ds);
811 uint32_t segLen = segLenList[0];
813 HALASSERT((segLen &~ AR_BufLen) == 0);
815 ds->ds_data = bufAddrList[0];
819 * First descriptor, don't clobber xmit control data
820 * setup by ar5212SetupTxDesc.
822 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_More);
823 } else if (lastSeg) { /* !firstSeg && lastSeg */
825 * Last descriptor in a multi-descriptor frame,
826 * copy the multi-rate transmit parameters from
827 * the first frame for processing on completion.
829 ads->ds_ctl1 = segLen;
830 #ifdef AH_NEED_DESC_SWAP
831 ads->ds_ctl0 = __bswap32(AR5212DESC_CONST(ds0)->ds_ctl0)
833 ads->ds_ctl2 = __bswap32(AR5212DESC_CONST(ds0)->ds_ctl2);
834 ads->ds_ctl3 = __bswap32(AR5212DESC_CONST(ds0)->ds_ctl3);
836 ads->ds_ctl0 = AR5212DESC_CONST(ds0)->ds_ctl0 & AR_TxInterReq;
837 ads->ds_ctl2 = AR5212DESC_CONST(ds0)->ds_ctl2;
838 ads->ds_ctl3 = AR5212DESC_CONST(ds0)->ds_ctl3;
840 } else { /* !firstSeg && !lastSeg */
842 * Intermediate descriptor in a multi-descriptor frame.
844 #ifdef AH_NEED_DESC_SWAP
845 ads->ds_ctl0 = __bswap32(AR5212DESC_CONST(ds0)->ds_ctl0)
848 ads->ds_ctl0 = AR5212DESC_CONST(ds0)->ds_ctl0 & AR_TxInterReq;
850 ads->ds_ctl1 = segLen | AR_More;
854 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
858 #ifdef AH_NEED_DESC_SWAP
859 /* Swap transmit descriptor */
861 ar5212SwapTxDesc(struct ath_desc *ds)
863 ds->ds_data = __bswap32(ds->ds_data);
864 ds->ds_ctl0 = __bswap32(ds->ds_ctl0);
865 ds->ds_ctl1 = __bswap32(ds->ds_ctl1);
866 ds->ds_hw[0] = __bswap32(ds->ds_hw[0]);
867 ds->ds_hw[1] = __bswap32(ds->ds_hw[1]);
868 ds->ds_hw[2] = __bswap32(ds->ds_hw[2]);
869 ds->ds_hw[3] = __bswap32(ds->ds_hw[3]);
874 * Processing of HW TX descriptor.
877 ar5212ProcTxDesc(struct ath_hal *ah,
878 struct ath_desc *ds, struct ath_tx_status *ts)
880 struct ar5212_desc *ads = AR5212DESC(ds);
882 #ifdef AH_NEED_DESC_SWAP
883 if ((ads->ds_txstatus1 & __bswap32(AR_Done)) == 0)
884 return HAL_EINPROGRESS;
886 ar5212SwapTxDesc(ds);
888 if ((ads->ds_txstatus1 & AR_Done) == 0)
889 return HAL_EINPROGRESS;
892 /* Update software copies of the HW status */
893 ts->ts_seqnum = MS(ads->ds_txstatus1, AR_SeqNum);
894 ts->ts_tstamp = MS(ads->ds_txstatus0, AR_SendTimestamp);
896 if ((ads->ds_txstatus0 & AR_FrmXmitOK) == 0) {
897 if (ads->ds_txstatus0 & AR_ExcessiveRetries)
898 ts->ts_status |= HAL_TXERR_XRETRY;
899 if (ads->ds_txstatus0 & AR_Filtered)
900 ts->ts_status |= HAL_TXERR_FILT;
901 if (ads->ds_txstatus0 & AR_FIFOUnderrun)
902 ts->ts_status |= HAL_TXERR_FIFO;
905 * Extract the transmit rate used and mark the rate as
906 * ``alternate'' if it wasn't the series 0 rate.
908 ts->ts_finaltsi = MS(ads->ds_txstatus1, AR_FinalTSIndex);
909 switch (ts->ts_finaltsi) {
911 ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate0);
914 ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate1);
917 ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate2);
920 ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate3);
923 ts->ts_rssi = MS(ads->ds_txstatus1, AR_AckSigStrength);
924 ts->ts_shortretry = MS(ads->ds_txstatus0, AR_RTSFailCnt);
925 ts->ts_longretry = MS(ads->ds_txstatus0, AR_DataFailCnt);
927 * The retry count has the number of un-acked tries for the
928 * final series used. When doing multi-rate retry we must
929 * fixup the retry count by adding in the try counts for
930 * each series that was fully-processed. Beware that this
931 * takes values from the try counts in the final descriptor.
932 * These are not required by the hardware. We assume they
933 * are placed there by the driver as otherwise we have no
934 * access and the driver can't do the calculation because it
935 * doesn't know the descriptor format.
937 switch (ts->ts_finaltsi) {
938 case 3: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries2);
939 case 2: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries1);
940 case 1: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries0);
942 ts->ts_virtcol = MS(ads->ds_txstatus0, AR_VirtCollCnt);
943 ts->ts_antenna = (ads->ds_txstatus1 & AR_XmitAtenna ? 2 : 1);
949 * Determine which tx queues need interrupt servicing.
952 ar5212GetTxIntrQueue(struct ath_hal *ah, uint32_t *txqs)
954 struct ath_hal_5212 *ahp = AH5212(ah);
955 *txqs &= ahp->ah_intrTxqs;
956 ahp->ah_intrTxqs &= ~(*txqs);
960 * Retrieve the rate table from the given TX completion descriptor
963 ar5212GetTxCompletionRates(struct ath_hal *ah, const struct ath_desc *ds0, int *rates, int *tries)
965 const struct ar5212_desc *ads = AR5212DESC_CONST(ds0);
967 rates[0] = MS(ads->ds_ctl3, AR_XmitRate0);
968 rates[1] = MS(ads->ds_ctl3, AR_XmitRate1);
969 rates[2] = MS(ads->ds_ctl3, AR_XmitRate2);
970 rates[3] = MS(ads->ds_ctl3, AR_XmitRate3);
972 tries[0] = MS(ads->ds_ctl2, AR_XmitDataTries0);
973 tries[1] = MS(ads->ds_ctl2, AR_XmitDataTries1);
974 tries[2] = MS(ads->ds_ctl2, AR_XmitDataTries2);
975 tries[3] = MS(ads->ds_ctl2, AR_XmitDataTries3);
981 ar5212SetTxDescLink(struct ath_hal *ah, void *ds, uint32_t link)
983 struct ar5212_desc *ads = AR5212DESC(ds);
989 ar5212GetTxDescLink(struct ath_hal *ah, void *ds, uint32_t *link)
991 struct ar5212_desc *ads = AR5212DESC(ds);
993 *link = ads->ds_link;
997 ar5212GetTxDescLinkPtr(struct ath_hal *ah, void *ds, uint32_t **linkptr)
999 struct ar5212_desc *ads = AR5212DESC(ds);
1001 *linkptr = &ads->ds_link;