Path: blob/main/sys/dev/ath/ath_hal/ar5212/ar5212_xmit.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2009 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2008 Atheros Communications, Inc.5*6* Permission to use, copy, modify, and/or distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*/18#include "opt_ah.h"1920#include "ah.h"21#include "ah_internal.h"22#include "ah_desc.h"2324#include "ar5212/ar5212.h"25#include "ar5212/ar5212reg.h"26#include "ar5212/ar5212desc.h"27#include "ar5212/ar5212phy.h"28#ifdef AH_SUPPORT_531129#include "ar5212/ar5311reg.h"30#endif3132#ifdef AH_NEED_DESC_SWAP33static void ar5212SwapTxDesc(struct ath_desc *ds);34#endif3536/*37* Update Tx FIFO trigger level.38*39* Set bIncTrigLevel to TRUE to increase the trigger level.40* Set bIncTrigLevel to FALSE to decrease the trigger level.41*42* Returns TRUE if the trigger level was updated43*/44HAL_BOOL45ar5212UpdateTxTrigLevel(struct ath_hal *ah, HAL_BOOL bIncTrigLevel)46{47struct ath_hal_5212 *ahp = AH5212(ah);48uint32_t txcfg, curLevel, newLevel;49HAL_INT omask;5051if (ahp->ah_txTrigLev >= ahp->ah_maxTxTrigLev)52return AH_FALSE;5354/*55* Disable interrupts while futzing with the fifo level.56*/57omask = ath_hal_setInterrupts(ah, ahp->ah_maskReg &~ HAL_INT_GLOBAL);5859txcfg = OS_REG_READ(ah, AR_TXCFG);60curLevel = MS(txcfg, AR_FTRIG);61newLevel = curLevel;62if (bIncTrigLevel) { /* increase the trigger level */63if (curLevel < ahp->ah_maxTxTrigLev)64newLevel++;65} else if (curLevel > MIN_TX_FIFO_THRESHOLD)66newLevel--;67if (newLevel != curLevel)68/* Update the trigger level */69OS_REG_WRITE(ah, AR_TXCFG,70(txcfg &~ AR_FTRIG) | SM(newLevel, AR_FTRIG));7172ahp->ah_txTrigLev = newLevel;7374/* re-enable chip interrupts */75ath_hal_setInterrupts(ah, omask);7677return (newLevel != curLevel);78}7980/*81* Set the properties of the tx queue with the parameters82* from qInfo.83*/84HAL_BOOL85ar5212SetTxQueueProps(struct ath_hal *ah, int q, const HAL_TXQ_INFO *qInfo)86{87struct ath_hal_5212 *ahp = AH5212(ah);88HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;8990if (q >= pCap->halTotalQueues) {91HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",92__func__, q);93return AH_FALSE;94}95return ath_hal_setTxQProps(ah, &ahp->ah_txq[q], qInfo);96}9798/*99* Return the properties for the specified tx queue.100*/101HAL_BOOL102ar5212GetTxQueueProps(struct ath_hal *ah, int q, HAL_TXQ_INFO *qInfo)103{104struct ath_hal_5212 *ahp = AH5212(ah);105HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;106107if (q >= pCap->halTotalQueues) {108HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",109__func__, q);110return AH_FALSE;111}112return ath_hal_getTxQProps(ah, qInfo, &ahp->ah_txq[q]);113}114115/*116* Allocate and initialize a tx DCU/QCU combination.117*/118int119ar5212SetupTxQueue(struct ath_hal *ah, HAL_TX_QUEUE type,120const HAL_TXQ_INFO *qInfo)121{122struct ath_hal_5212 *ahp = AH5212(ah);123HAL_TX_QUEUE_INFO *qi;124HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;125int q, defqflags;126127/* by default enable OK+ERR+DESC+URN interrupts */128defqflags = HAL_TXQ_TXOKINT_ENABLE129| HAL_TXQ_TXERRINT_ENABLE130| HAL_TXQ_TXDESCINT_ENABLE131| HAL_TXQ_TXURNINT_ENABLE;132/* XXX move queue assignment to driver */133switch (type) {134case HAL_TX_QUEUE_BEACON:135q = pCap->halTotalQueues-1; /* highest priority */136defqflags |= HAL_TXQ_DBA_GATED137| HAL_TXQ_CBR_DIS_QEMPTY138| HAL_TXQ_ARB_LOCKOUT_GLOBAL139| HAL_TXQ_BACKOFF_DISABLE;140break;141case HAL_TX_QUEUE_CAB:142q = pCap->halTotalQueues-2; /* next highest priority */143defqflags |= HAL_TXQ_DBA_GATED144| HAL_TXQ_CBR_DIS_QEMPTY145| HAL_TXQ_CBR_DIS_BEMPTY146| HAL_TXQ_ARB_LOCKOUT_GLOBAL147| HAL_TXQ_BACKOFF_DISABLE;148break;149case HAL_TX_QUEUE_UAPSD:150q = pCap->halTotalQueues-3; /* nextest highest priority */151if (ahp->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE) {152HALDEBUG(ah, HAL_DEBUG_ANY,153"%s: no available UAPSD tx queue\n", __func__);154return -1;155}156break;157case HAL_TX_QUEUE_DATA:158for (q = 0; q < pCap->halTotalQueues; q++)159if (ahp->ah_txq[q].tqi_type == HAL_TX_QUEUE_INACTIVE)160break;161if (q == pCap->halTotalQueues) {162HALDEBUG(ah, HAL_DEBUG_ANY,163"%s: no available tx queue\n", __func__);164return -1;165}166break;167default:168HALDEBUG(ah, HAL_DEBUG_ANY,169"%s: bad tx queue type %u\n", __func__, type);170return -1;171}172173HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);174175qi = &ahp->ah_txq[q];176if (qi->tqi_type != HAL_TX_QUEUE_INACTIVE) {177HALDEBUG(ah, HAL_DEBUG_ANY, "%s: tx queue %u already active\n",178__func__, q);179return -1;180}181OS_MEMZERO(qi, sizeof(HAL_TX_QUEUE_INFO));182qi->tqi_type = type;183if (qInfo == AH_NULL) {184qi->tqi_qflags = defqflags;185qi->tqi_aifs = INIT_AIFS;186qi->tqi_cwmin = HAL_TXQ_USEDEFAULT; /* NB: do at reset */187qi->tqi_cwmax = INIT_CWMAX;188qi->tqi_shretry = INIT_SH_RETRY;189qi->tqi_lgretry = INIT_LG_RETRY;190qi->tqi_physCompBuf = 0;191} else {192qi->tqi_physCompBuf = qInfo->tqi_compBuf;193(void) ar5212SetTxQueueProps(ah, q, qInfo);194}195/* NB: must be followed by ar5212ResetTxQueue */196return q;197}198199/*200* Update the h/w interrupt registers to reflect a tx q's configuration.201*/202static void203setTxQInterrupts(struct ath_hal *ah, HAL_TX_QUEUE_INFO *qi)204{205struct ath_hal_5212 *ahp = AH5212(ah);206207HALDEBUG(ah, HAL_DEBUG_TXQUEUE,208"%s: tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n", __func__,209ahp->ah_txOkInterruptMask, ahp->ah_txErrInterruptMask,210ahp->ah_txDescInterruptMask, ahp->ah_txEolInterruptMask,211ahp->ah_txUrnInterruptMask);212213OS_REG_WRITE(ah, AR_IMR_S0,214SM(ahp->ah_txOkInterruptMask, AR_IMR_S0_QCU_TXOK)215| SM(ahp->ah_txDescInterruptMask, AR_IMR_S0_QCU_TXDESC)216);217OS_REG_WRITE(ah, AR_IMR_S1,218SM(ahp->ah_txErrInterruptMask, AR_IMR_S1_QCU_TXERR)219| SM(ahp->ah_txEolInterruptMask, AR_IMR_S1_QCU_TXEOL)220);221OS_REG_RMW_FIELD(ah, AR_IMR_S2,222AR_IMR_S2_QCU_TXURN, ahp->ah_txUrnInterruptMask);223}224225/*226* Free a tx DCU/QCU combination.227*/228HAL_BOOL229ar5212ReleaseTxQueue(struct ath_hal *ah, u_int q)230{231struct ath_hal_5212 *ahp = AH5212(ah);232HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;233HAL_TX_QUEUE_INFO *qi;234235if (q >= pCap->halTotalQueues) {236HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",237__func__, q);238return AH_FALSE;239}240qi = &ahp->ah_txq[q];241if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {242HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: inactive queue %u\n",243__func__, q);244return AH_FALSE;245}246247HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: release queue %u\n", __func__, q);248249qi->tqi_type = HAL_TX_QUEUE_INACTIVE;250ahp->ah_txOkInterruptMask &= ~(1 << q);251ahp->ah_txErrInterruptMask &= ~(1 << q);252ahp->ah_txDescInterruptMask &= ~(1 << q);253ahp->ah_txEolInterruptMask &= ~(1 << q);254ahp->ah_txUrnInterruptMask &= ~(1 << q);255setTxQInterrupts(ah, qi);256257return AH_TRUE;258}259260/*261* Set the retry, aifs, cwmin/max, readyTime regs for specified queue262* Assumes:263* phwChannel has been set to point to the current channel264*/265#define TU_TO_USEC(_tu) ((_tu) << 10)266HAL_BOOL267ar5212ResetTxQueue(struct ath_hal *ah, u_int q)268{269struct ath_hal_5212 *ahp = AH5212(ah);270HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;271const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan;272HAL_TX_QUEUE_INFO *qi;273uint32_t cwMin, chanCwMin, qmisc, dmisc;274275if (q >= pCap->halTotalQueues) {276HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",277__func__, q);278return AH_FALSE;279}280qi = &ahp->ah_txq[q];281if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {282HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: inactive queue %u\n",283__func__, q);284return AH_TRUE; /* XXX??? */285}286287HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: reset queue %u\n", __func__, q);288289if (qi->tqi_cwmin == HAL_TXQ_USEDEFAULT) {290/*291* Select cwmin according to channel type.292* NB: chan can be NULL during attach293*/294if (chan && IEEE80211_IS_CHAN_B(chan))295chanCwMin = INIT_CWMIN_11B;296else297chanCwMin = INIT_CWMIN;298/* make sure that the CWmin is of the form (2^n - 1) */299for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1)300;301} else302cwMin = qi->tqi_cwmin;303304/* set cwMin/Max and AIFS values */305OS_REG_WRITE(ah, AR_DLCL_IFS(q),306SM(cwMin, AR_D_LCL_IFS_CWMIN)307| SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX)308| SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));309310/* Set retry limit values */311OS_REG_WRITE(ah, AR_DRETRY_LIMIT(q),312SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH)313| SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG)314| SM(qi->tqi_lgretry, AR_D_RETRY_LIMIT_FR_LG)315| SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH)316);317318/* NB: always enable early termination on the QCU */319qmisc = AR_Q_MISC_DCU_EARLY_TERM_REQ320| SM(AR_Q_MISC_FSP_ASAP, AR_Q_MISC_FSP);321322/* NB: always enable DCU to wait for next fragment from QCU */323dmisc = AR_D_MISC_FRAG_WAIT_EN;324325#ifdef AH_SUPPORT_5311326if (AH_PRIVATE(ah)->ah_macVersion < AR_SREV_VERSION_OAHU) {327/* Configure DCU to use the global sequence count */328dmisc |= AR5311_D_MISC_SEQ_NUM_CONTROL;329}330#endif331/* multiqueue support */332if (qi->tqi_cbrPeriod) {333OS_REG_WRITE(ah, AR_QCBRCFG(q),334SM(qi->tqi_cbrPeriod,AR_Q_CBRCFG_CBR_INTERVAL)335| SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_CBR_OVF_THRESH));336qmisc = (qmisc &~ AR_Q_MISC_FSP) | AR_Q_MISC_FSP_CBR;337if (qi->tqi_cbrOverflowLimit)338qmisc |= AR_Q_MISC_CBR_EXP_CNTR_LIMIT;339}340if (qi->tqi_readyTime) {341OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),342SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_INT)343| AR_Q_RDYTIMECFG_ENA);344}345346OS_REG_WRITE(ah, AR_DCHNTIME(q),347SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR)348| (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));349350if (qi->tqi_readyTime &&351(qi->tqi_qflags & HAL_TXQ_RDYTIME_EXP_POLICY_ENABLE))352qmisc |= AR_Q_MISC_RDYTIME_EXP_POLICY;353if (qi->tqi_qflags & HAL_TXQ_DBA_GATED)354qmisc = (qmisc &~ AR_Q_MISC_FSP) | AR_Q_MISC_FSP_DBA_GATED;355if (MS(qmisc, AR_Q_MISC_FSP) != AR_Q_MISC_FSP_ASAP) {356/*357* These are meangingful only when not scheduled asap.358*/359if (qi->tqi_qflags & HAL_TXQ_CBR_DIS_BEMPTY)360qmisc |= AR_Q_MISC_CBR_INCR_DIS0;361else362qmisc &= ~AR_Q_MISC_CBR_INCR_DIS0;363if (qi->tqi_qflags & HAL_TXQ_CBR_DIS_QEMPTY)364qmisc |= AR_Q_MISC_CBR_INCR_DIS1;365else366qmisc &= ~AR_Q_MISC_CBR_INCR_DIS1;367}368369if (qi->tqi_qflags & HAL_TXQ_BACKOFF_DISABLE)370dmisc |= AR_D_MISC_POST_FR_BKOFF_DIS;371if (qi->tqi_qflags & HAL_TXQ_FRAG_BURST_BACKOFF_ENABLE)372dmisc |= AR_D_MISC_FRAG_BKOFF_EN;373if (qi->tqi_qflags & HAL_TXQ_ARB_LOCKOUT_GLOBAL)374dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,375AR_D_MISC_ARB_LOCKOUT_CNTRL);376else if (qi->tqi_qflags & HAL_TXQ_ARB_LOCKOUT_INTRA)377dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_INTRA_FR,378AR_D_MISC_ARB_LOCKOUT_CNTRL);379if (qi->tqi_qflags & HAL_TXQ_IGNORE_VIRTCOL)380dmisc |= SM(AR_D_MISC_VIR_COL_HANDLING_IGNORE,381AR_D_MISC_VIR_COL_HANDLING);382if (qi->tqi_qflags & HAL_TXQ_SEQNUM_INC_DIS)383dmisc |= AR_D_MISC_SEQ_NUM_INCR_DIS;384385/*386* Fillin type-dependent bits. Most of this can be387* removed by specifying the queue parameters in the388* driver; it's here for backwards compatibility.389*/390switch (qi->tqi_type) {391case HAL_TX_QUEUE_BEACON: /* beacon frames */392qmisc |= AR_Q_MISC_FSP_DBA_GATED393| AR_Q_MISC_BEACON_USE394| AR_Q_MISC_CBR_INCR_DIS1;395396dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,397AR_D_MISC_ARB_LOCKOUT_CNTRL)398| AR_D_MISC_BEACON_USE399| AR_D_MISC_POST_FR_BKOFF_DIS;400break;401case HAL_TX_QUEUE_CAB: /* CAB frames */402/*403* No longer Enable AR_Q_MISC_RDYTIME_EXP_POLICY,404* There is an issue with the CAB Queue405* not properly refreshing the Tx descriptor if406* the TXE clear setting is used.407*/408qmisc |= AR_Q_MISC_FSP_DBA_GATED409| AR_Q_MISC_CBR_INCR_DIS1410| AR_Q_MISC_CBR_INCR_DIS0;411412if (qi->tqi_readyTime) {413HALDEBUG(ah, HAL_DEBUG_TXQUEUE,414"%s: using tqi_readyTime\n", __func__);415OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),416SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_INT) |417AR_Q_RDYTIMECFG_ENA);418} else {419int value;420/*421* NB: don't set default ready time if driver422* has explicitly specified something. This is423* here solely for backwards compatibility.424*/425/*426* XXX for now, hard-code a CAB interval of 70%427* XXX of the total beacon interval.428*/429430value = (ahp->ah_beaconInterval * 70 / 100)431- (ah->ah_config.ah_sw_beacon_response_time -432+ ah->ah_config.ah_dma_beacon_response_time)433- ah->ah_config.ah_additional_swba_backoff;434/*435* XXX Ensure it isn't too low - nothing lower436* XXX than 10 TU437*/438if (value < 10)439value = 10;440HALDEBUG(ah, HAL_DEBUG_TXQUEUE,441"%s: defaulting to rdytime = %d uS\n",442__func__, value);443OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),444SM(TU_TO_USEC(value), AR_Q_RDYTIMECFG_INT) |445AR_Q_RDYTIMECFG_ENA);446}447dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,448AR_D_MISC_ARB_LOCKOUT_CNTRL);449break;450default: /* NB: silence compiler */451break;452}453454OS_REG_WRITE(ah, AR_QMISC(q), qmisc);455OS_REG_WRITE(ah, AR_DMISC(q), dmisc);456457/* Setup compression scratchpad buffer */458/*459* XXX: calling this asynchronously to queue operation can460* cause unexpected behavior!!!461*/462if (qi->tqi_physCompBuf) {463HALASSERT(qi->tqi_type == HAL_TX_QUEUE_DATA ||464qi->tqi_type == HAL_TX_QUEUE_UAPSD);465OS_REG_WRITE(ah, AR_Q_CBBS, (80 + 2*q));466OS_REG_WRITE(ah, AR_Q_CBBA, qi->tqi_physCompBuf);467OS_REG_WRITE(ah, AR_Q_CBC, HAL_COMP_BUF_MAX_SIZE/1024);468OS_REG_WRITE(ah, AR_Q0_MISC + 4*q,469OS_REG_READ(ah, AR_Q0_MISC + 4*q)470| AR_Q_MISC_QCU_COMP_EN);471}472473/*474* Always update the secondary interrupt mask registers - this475* could be a new queue getting enabled in a running system or476* hw getting re-initialized during a reset!477*478* Since we don't differentiate between tx interrupts corresponding479* to individual queues - secondary tx mask regs are always unmasked;480* tx interrupts are enabled/disabled for all queues collectively481* using the primary mask reg482*/483if (qi->tqi_qflags & HAL_TXQ_TXOKINT_ENABLE)484ahp->ah_txOkInterruptMask |= 1 << q;485else486ahp->ah_txOkInterruptMask &= ~(1 << q);487if (qi->tqi_qflags & HAL_TXQ_TXERRINT_ENABLE)488ahp->ah_txErrInterruptMask |= 1 << q;489else490ahp->ah_txErrInterruptMask &= ~(1 << q);491if (qi->tqi_qflags & HAL_TXQ_TXDESCINT_ENABLE)492ahp->ah_txDescInterruptMask |= 1 << q;493else494ahp->ah_txDescInterruptMask &= ~(1 << q);495if (qi->tqi_qflags & HAL_TXQ_TXEOLINT_ENABLE)496ahp->ah_txEolInterruptMask |= 1 << q;497else498ahp->ah_txEolInterruptMask &= ~(1 << q);499if (qi->tqi_qflags & HAL_TXQ_TXURNINT_ENABLE)500ahp->ah_txUrnInterruptMask |= 1 << q;501else502ahp->ah_txUrnInterruptMask &= ~(1 << q);503setTxQInterrupts(ah, qi);504505return AH_TRUE;506}507#undef TU_TO_USEC508509/*510* Get the TXDP for the specified queue511*/512uint32_t513ar5212GetTxDP(struct ath_hal *ah, u_int q)514{515HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);516return OS_REG_READ(ah, AR_QTXDP(q));517}518519/*520* Set the TxDP for the specified queue521*/522HAL_BOOL523ar5212SetTxDP(struct ath_hal *ah, u_int q, uint32_t txdp)524{525HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);526HALASSERT(AH5212(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);527528/*529* Make sure that TXE is deasserted before setting the TXDP. If TXE530* is still asserted, setting TXDP will have no effect.531*/532HALASSERT((OS_REG_READ(ah, AR_Q_TXE) & (1 << q)) == 0);533534OS_REG_WRITE(ah, AR_QTXDP(q), txdp);535536return AH_TRUE;537}538539/*540* Set Transmit Enable bits for the specified queue541*/542HAL_BOOL543ar5212StartTxDma(struct ath_hal *ah, u_int q)544{545HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);546547HALASSERT(AH5212(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);548549HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);550551/* Check to be sure we're not enabling a q that has its TXD bit set. */552HALASSERT((OS_REG_READ(ah, AR_Q_TXD) & (1 << q)) == 0);553554OS_REG_WRITE(ah, AR_Q_TXE, 1 << q);555return AH_TRUE;556}557558/*559* Return the number of pending frames or 0 if the specified560* queue is stopped.561*/562uint32_t563ar5212NumTxPending(struct ath_hal *ah, u_int q)564{565uint32_t npend;566567HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);568HALASSERT(AH5212(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);569570npend = OS_REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;571if (npend == 0) {572/*573* Pending frame count (PFC) can momentarily go to zero574* while TXE remains asserted. In other words a PFC of575* zero is not sufficient to say that the queue has stopped.576*/577if (OS_REG_READ(ah, AR_Q_TXE) & (1 << q))578npend = 1; /* arbitrarily return 1 */579}580return npend;581}582583/*584* Stop transmit on the specified queue585*/586HAL_BOOL587ar5212StopTxDma(struct ath_hal *ah, u_int q)588{589u_int i;590u_int wait;591592HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);593594HALASSERT(AH5212(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);595596OS_REG_WRITE(ah, AR_Q_TXD, 1 << q);597for (i = 1000; i != 0; i--) {598if (ar5212NumTxPending(ah, q) == 0)599break;600OS_DELAY(100); /* XXX get actual value */601}602#ifdef AH_DEBUG603if (i == 0) {604HALDEBUG(ah, HAL_DEBUG_ANY,605"%s: queue %u DMA did not stop in 100 msec\n", __func__, q);606HALDEBUG(ah, HAL_DEBUG_ANY,607"%s: QSTS 0x%x Q_TXE 0x%x Q_TXD 0x%x Q_CBR 0x%x\n", __func__,608OS_REG_READ(ah, AR_QSTS(q)), OS_REG_READ(ah, AR_Q_TXE),609OS_REG_READ(ah, AR_Q_TXD), OS_REG_READ(ah, AR_QCBRCFG(q)));610HALDEBUG(ah, HAL_DEBUG_ANY,611"%s: Q_MISC 0x%x Q_RDYTIMECFG 0x%x Q_RDYTIMESHDN 0x%x\n",612__func__, OS_REG_READ(ah, AR_QMISC(q)),613OS_REG_READ(ah, AR_QRDYTIMECFG(q)),614OS_REG_READ(ah, AR_Q_RDYTIMESHDN));615}616#endif /* AH_DEBUG */617618/* 2413+ and up can kill packets at the PCU level */619if (ar5212NumTxPending(ah, q) &&620(IS_2413(ah) || IS_5413(ah) || IS_2425(ah) || IS_2417(ah))) {621uint32_t tsfLow, j;622623HALDEBUG(ah, HAL_DEBUG_TXQUEUE,624"%s: Num of pending TX Frames %d on Q %d\n",625__func__, ar5212NumTxPending(ah, q), q);626627/* Kill last PCU Tx Frame */628/* TODO - save off and restore current values of Q1/Q2? */629for (j = 0; j < 2; j++) {630tsfLow = OS_REG_READ(ah, AR_TSF_L32);631OS_REG_WRITE(ah, AR_QUIET2, SM(100, AR_QUIET2_QUIET_PER) |632SM(10, AR_QUIET2_QUIET_DUR));633OS_REG_WRITE(ah, AR_QUIET1, AR_QUIET1_QUIET_ENABLE |634SM(tsfLow >> 10, AR_QUIET1_NEXT_QUIET));635if ((OS_REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10)) {636break;637}638HALDEBUG(ah, HAL_DEBUG_ANY,639"%s: TSF moved while trying to set quiet time "640"TSF: 0x%08x\n", __func__, tsfLow);641HALASSERT(j < 1); /* TSF shouldn't count twice or reg access is taking forever */642}643644OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_CHAN_IDLE);645646/* Allow the quiet mechanism to do its work */647OS_DELAY(200);648OS_REG_CLR_BIT(ah, AR_QUIET1, AR_QUIET1_QUIET_ENABLE);649650/* Give at least 1 millisec more to wait */651wait = 100;652653/* Verify all transmit is dead */654while (ar5212NumTxPending(ah, q)) {655if ((--wait) == 0) {656HALDEBUG(ah, HAL_DEBUG_ANY,657"%s: Failed to stop Tx DMA in %d msec after killing last frame\n",658__func__, wait);659break;660}661OS_DELAY(10);662}663664OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_CHAN_IDLE);665}666667OS_REG_WRITE(ah, AR_Q_TXD, 0);668return (i != 0);669}670671/*672* Descriptor Access Functions673*/674675#define VALID_PKT_TYPES \676((1<<HAL_PKT_TYPE_NORMAL)|(1<<HAL_PKT_TYPE_ATIM)|\677(1<<HAL_PKT_TYPE_PSPOLL)|(1<<HAL_PKT_TYPE_PROBE_RESP)|\678(1<<HAL_PKT_TYPE_BEACON))679#define isValidPktType(_t) ((1<<(_t)) & VALID_PKT_TYPES)680#define VALID_TX_RATES \681((1<<0x0b)|(1<<0x0f)|(1<<0x0a)|(1<<0x0e)|(1<<0x09)|(1<<0x0d)|\682(1<<0x08)|(1<<0x0c)|(1<<0x1b)|(1<<0x1a)|(1<<0x1e)|(1<<0x19)|\683(1<<0x1d)|(1<<0x18)|(1<<0x1c))684#define isValidTxRate(_r) ((1<<(_r)) & VALID_TX_RATES)685686HAL_BOOL687ar5212SetupTxDesc(struct ath_hal *ah, struct ath_desc *ds,688u_int pktLen,689u_int hdrLen,690HAL_PKT_TYPE type,691u_int txPower,692u_int txRate0, u_int txTries0,693u_int keyIx,694u_int antMode,695u_int flags,696u_int rtsctsRate,697u_int rtsctsDuration,698u_int compicvLen,699u_int compivLen,700u_int comp)701{702#define RTSCTS (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)703struct ar5212_desc *ads = AR5212DESC(ds);704struct ath_hal_5212 *ahp = AH5212(ah);705706(void) hdrLen;707708HALASSERT(txTries0 != 0);709HALASSERT(isValidPktType(type));710HALASSERT(isValidTxRate(txRate0));711HALASSERT((flags & RTSCTS) != RTSCTS);712/* XXX validate antMode */713714txPower = (txPower + ahp->ah_txPowerIndexOffset );715if(txPower > 63) txPower=63;716717ads->ds_ctl0 = (pktLen & AR_FrameLen)718| (txPower << AR_XmitPower_S)719| (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)720| (flags & HAL_TXDESC_CLRDMASK ? AR_ClearDestMask : 0)721| SM(antMode, AR_AntModeXmit)722| (flags & HAL_TXDESC_INTREQ ? AR_TxInterReq : 0)723;724ads->ds_ctl1 = (type << AR_FrmType_S)725| (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0)726| (comp << AR_CompProc_S)727| (compicvLen << AR_CompICVLen_S)728| (compivLen << AR_CompIVLen_S)729;730ads->ds_ctl2 = SM(txTries0, AR_XmitDataTries0)731| (flags & HAL_TXDESC_DURENA ? AR_DurUpdateEna : 0)732;733ads->ds_ctl3 = (txRate0 << AR_XmitRate0_S)734;735if (keyIx != HAL_TXKEYIX_INVALID) {736/* XXX validate key index */737ads->ds_ctl1 |= SM(keyIx, AR_DestIdx);738ads->ds_ctl0 |= AR_DestIdxValid;739}740if (flags & RTSCTS) {741if (!isValidTxRate(rtsctsRate)) {742HALDEBUG(ah, HAL_DEBUG_ANY,743"%s: invalid rts/cts rate 0x%x\n",744__func__, rtsctsRate);745return AH_FALSE;746}747/* XXX validate rtsctsDuration */748ads->ds_ctl0 |= (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0)749| (flags & HAL_TXDESC_RTSENA ? AR_RTSCTSEnable : 0)750;751ads->ds_ctl2 |= SM(rtsctsDuration, AR_RTSCTSDuration);752ads->ds_ctl3 |= (rtsctsRate << AR_RTSCTSRate_S);753}754return AH_TRUE;755#undef RTSCTS756}757758HAL_BOOL759ar5212SetupXTxDesc(struct ath_hal *ah, struct ath_desc *ds,760u_int txRate1, u_int txTries1,761u_int txRate2, u_int txTries2,762u_int txRate3, u_int txTries3)763{764struct ar5212_desc *ads = AR5212DESC(ds);765766if (txTries1) {767HALASSERT(isValidTxRate(txRate1));768ads->ds_ctl2 |= SM(txTries1, AR_XmitDataTries1)769| AR_DurUpdateEna770;771ads->ds_ctl3 |= (txRate1 << AR_XmitRate1_S);772}773if (txTries2) {774HALASSERT(isValidTxRate(txRate2));775ads->ds_ctl2 |= SM(txTries2, AR_XmitDataTries2)776| AR_DurUpdateEna777;778ads->ds_ctl3 |= (txRate2 << AR_XmitRate2_S);779}780if (txTries3) {781HALASSERT(isValidTxRate(txRate3));782ads->ds_ctl2 |= SM(txTries3, AR_XmitDataTries3)783| AR_DurUpdateEna784;785ads->ds_ctl3 |= (txRate3 << AR_XmitRate3_S);786}787return AH_TRUE;788}789790void791ar5212IntrReqTxDesc(struct ath_hal *ah, struct ath_desc *ds)792{793struct ar5212_desc *ads = AR5212DESC(ds);794795#ifdef AH_NEED_DESC_SWAP796ads->ds_ctl0 |= __bswap32(AR_TxInterReq);797#else798ads->ds_ctl0 |= AR_TxInterReq;799#endif800}801802HAL_BOOL803ar5212FillTxDesc(struct ath_hal *ah, struct ath_desc *ds,804HAL_DMA_ADDR *bufAddrList, uint32_t *segLenList, u_int qcuId,805u_int descId, HAL_BOOL firstSeg, HAL_BOOL lastSeg,806const struct ath_desc *ds0)807{808struct ar5212_desc *ads = AR5212DESC(ds);809uint32_t segLen = segLenList[0];810811HALASSERT((segLen &~ AR_BufLen) == 0);812813ds->ds_data = bufAddrList[0];814815if (firstSeg) {816/*817* First descriptor, don't clobber xmit control data818* setup by ar5212SetupTxDesc.819*/820ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_More);821} else if (lastSeg) { /* !firstSeg && lastSeg */822/*823* Last descriptor in a multi-descriptor frame,824* copy the multi-rate transmit parameters from825* the first frame for processing on completion.826*/827ads->ds_ctl1 = segLen;828#ifdef AH_NEED_DESC_SWAP829ads->ds_ctl0 = __bswap32(AR5212DESC_CONST(ds0)->ds_ctl0)830& AR_TxInterReq;831ads->ds_ctl2 = __bswap32(AR5212DESC_CONST(ds0)->ds_ctl2);832ads->ds_ctl3 = __bswap32(AR5212DESC_CONST(ds0)->ds_ctl3);833#else834ads->ds_ctl0 = AR5212DESC_CONST(ds0)->ds_ctl0 & AR_TxInterReq;835ads->ds_ctl2 = AR5212DESC_CONST(ds0)->ds_ctl2;836ads->ds_ctl3 = AR5212DESC_CONST(ds0)->ds_ctl3;837#endif838} else { /* !firstSeg && !lastSeg */839/*840* Intermediate descriptor in a multi-descriptor frame.841*/842#ifdef AH_NEED_DESC_SWAP843ads->ds_ctl0 = __bswap32(AR5212DESC_CONST(ds0)->ds_ctl0)844& AR_TxInterReq;845#else846ads->ds_ctl0 = AR5212DESC_CONST(ds0)->ds_ctl0 & AR_TxInterReq;847#endif848ads->ds_ctl1 = segLen | AR_More;849ads->ds_ctl2 = 0;850ads->ds_ctl3 = 0;851}852ads->ds_txstatus0 = ads->ds_txstatus1 = 0;853return AH_TRUE;854}855856#ifdef AH_NEED_DESC_SWAP857/* Swap transmit descriptor */858static __inline void859ar5212SwapTxDesc(struct ath_desc *ds)860{861ds->ds_data = __bswap32(ds->ds_data);862ds->ds_ctl0 = __bswap32(ds->ds_ctl0);863ds->ds_ctl1 = __bswap32(ds->ds_ctl1);864ds->ds_hw[0] = __bswap32(ds->ds_hw[0]);865ds->ds_hw[1] = __bswap32(ds->ds_hw[1]);866ds->ds_hw[2] = __bswap32(ds->ds_hw[2]);867ds->ds_hw[3] = __bswap32(ds->ds_hw[3]);868}869#endif870871/*872* Processing of HW TX descriptor.873*/874HAL_STATUS875ar5212ProcTxDesc(struct ath_hal *ah,876struct ath_desc *ds, struct ath_tx_status *ts)877{878struct ar5212_desc *ads = AR5212DESC(ds);879880#ifdef AH_NEED_DESC_SWAP881if ((ads->ds_txstatus1 & __bswap32(AR_Done)) == 0)882return HAL_EINPROGRESS;883884ar5212SwapTxDesc(ds);885#else886if ((ads->ds_txstatus1 & AR_Done) == 0)887return HAL_EINPROGRESS;888#endif889890/* Update software copies of the HW status */891ts->ts_seqnum = MS(ads->ds_txstatus1, AR_SeqNum);892ts->ts_tstamp = MS(ads->ds_txstatus0, AR_SendTimestamp);893ts->ts_status = 0;894if ((ads->ds_txstatus0 & AR_FrmXmitOK) == 0) {895if (ads->ds_txstatus0 & AR_ExcessiveRetries)896ts->ts_status |= HAL_TXERR_XRETRY;897if (ads->ds_txstatus0 & AR_Filtered)898ts->ts_status |= HAL_TXERR_FILT;899if (ads->ds_txstatus0 & AR_FIFOUnderrun)900ts->ts_status |= HAL_TXERR_FIFO;901}902/*903* Extract the transmit rate used and mark the rate as904* ``alternate'' if it wasn't the series 0 rate.905*/906ts->ts_finaltsi = MS(ads->ds_txstatus1, AR_FinalTSIndex);907switch (ts->ts_finaltsi) {908case 0:909ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate0);910break;911case 1:912ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate1);913break;914case 2:915ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate2);916break;917case 3:918ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate3);919break;920}921ts->ts_rssi = MS(ads->ds_txstatus1, AR_AckSigStrength);922ts->ts_shortretry = MS(ads->ds_txstatus0, AR_RTSFailCnt);923ts->ts_longretry = MS(ads->ds_txstatus0, AR_DataFailCnt);924/*925* The retry count has the number of un-acked tries for the926* final series used. When doing multi-rate retry we must927* fixup the retry count by adding in the try counts for928* each series that was fully-processed. Beware that this929* takes values from the try counts in the final descriptor.930* These are not required by the hardware. We assume they931* are placed there by the driver as otherwise we have no932* access and the driver can't do the calculation because it933* doesn't know the descriptor format.934*/935switch (ts->ts_finaltsi) {936case 3: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries2);937case 2: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries1);938case 1: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries0);939}940ts->ts_virtcol = MS(ads->ds_txstatus0, AR_VirtCollCnt);941ts->ts_antenna = (ads->ds_txstatus1 & AR_XmitAtenna ? 2 : 1);942943return HAL_OK;944}945946/*947* Determine which tx queues need interrupt servicing.948*/949void950ar5212GetTxIntrQueue(struct ath_hal *ah, uint32_t *txqs)951{952struct ath_hal_5212 *ahp = AH5212(ah);953*txqs &= ahp->ah_intrTxqs;954ahp->ah_intrTxqs &= ~(*txqs);955}956957/*958* Retrieve the rate table from the given TX completion descriptor959*/960HAL_BOOL961ar5212GetTxCompletionRates(struct ath_hal *ah, const struct ath_desc *ds0, int *rates, int *tries)962{963const struct ar5212_desc *ads = AR5212DESC_CONST(ds0);964965rates[0] = MS(ads->ds_ctl3, AR_XmitRate0);966rates[1] = MS(ads->ds_ctl3, AR_XmitRate1);967rates[2] = MS(ads->ds_ctl3, AR_XmitRate2);968rates[3] = MS(ads->ds_ctl3, AR_XmitRate3);969970tries[0] = MS(ads->ds_ctl2, AR_XmitDataTries0);971tries[1] = MS(ads->ds_ctl2, AR_XmitDataTries1);972tries[2] = MS(ads->ds_ctl2, AR_XmitDataTries2);973tries[3] = MS(ads->ds_ctl2, AR_XmitDataTries3);974975return AH_TRUE;976}977978void979ar5212SetTxDescLink(struct ath_hal *ah, void *ds, uint32_t link)980{981struct ar5212_desc *ads = AR5212DESC(ds);982983ads->ds_link = link;984}985986void987ar5212GetTxDescLink(struct ath_hal *ah, void *ds, uint32_t *link)988{989struct ar5212_desc *ads = AR5212DESC(ds);990991*link = ads->ds_link;992}993994void995ar5212GetTxDescLinkPtr(struct ath_hal *ah, void *ds, uint32_t **linkptr)996{997struct ar5212_desc *ads = AR5212DESC(ds);998999*linkptr = &ads->ds_link;1000}100110021003