Path: blob/main/sys/dev/ath/ath_hal/ar5416/ar5416_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_desc.h"22#include "ah_internal.h"2324#include "ar5416/ar5416.h"25#include "ar5416/ar5416reg.h"26#include "ar5416/ar5416phy.h"27#include "ar5416/ar5416desc.h"2829/*30* Stop transmit on the specified queue31*/32HAL_BOOL33ar5416StopTxDma(struct ath_hal *ah, u_int q)34{35#define STOP_DMA_TIMEOUT 4000 /* us */36#define STOP_DMA_ITER 100 /* us */37u_int i;3839HALASSERT(q < AH_PRIVATE(ah)->ah_caps.halTotalQueues);4041HALASSERT(AH5212(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);4243OS_REG_WRITE(ah, AR_Q_TXD, 1 << q);44for (i = STOP_DMA_TIMEOUT/STOP_DMA_ITER; i != 0; i--) {45if (ar5212NumTxPending(ah, q) == 0)46break;47OS_DELAY(STOP_DMA_ITER);48}49#ifdef AH_DEBUG50if (i == 0) {51HALDEBUG(ah, HAL_DEBUG_ANY,52"%s: queue %u DMA did not stop in 400 msec\n", __func__, q);53HALDEBUG(ah, HAL_DEBUG_ANY,54"%s: QSTS 0x%x Q_TXE 0x%x Q_TXD 0x%x Q_CBR 0x%x\n", __func__,55OS_REG_READ(ah, AR_QSTS(q)), OS_REG_READ(ah, AR_Q_TXE),56OS_REG_READ(ah, AR_Q_TXD), OS_REG_READ(ah, AR_QCBRCFG(q)));57HALDEBUG(ah, HAL_DEBUG_ANY,58"%s: Q_MISC 0x%x Q_RDYTIMECFG 0x%x Q_RDYTIMESHDN 0x%x\n",59__func__, OS_REG_READ(ah, AR_QMISC(q)),60OS_REG_READ(ah, AR_QRDYTIMECFG(q)),61OS_REG_READ(ah, AR_Q_RDYTIMESHDN));62}63#endif /* AH_DEBUG */6465/* ar5416 and up can kill packets at the PCU level */66if (ar5212NumTxPending(ah, q)) {67uint32_t j;6869HALDEBUG(ah, HAL_DEBUG_TXQUEUE,70"%s: Num of pending TX Frames %d on Q %d\n",71__func__, ar5212NumTxPending(ah, q), q);7273/* Kill last PCU Tx Frame */74/* TODO - save off and restore current values of Q1/Q2? */75for (j = 0; j < 2; j++) {76uint32_t tsfLow = OS_REG_READ(ah, AR_TSF_L32);77OS_REG_WRITE(ah, AR_QUIET2,78SM(10, AR_QUIET2_QUIET_DUR));79OS_REG_WRITE(ah, AR_QUIET_PERIOD, 100);80OS_REG_WRITE(ah, AR_NEXT_QUIET, tsfLow >> 10);81OS_REG_SET_BIT(ah, AR_TIMER_MODE, AR_TIMER_MODE_QUIET);8283if ((OS_REG_READ(ah, AR_TSF_L32)>>10) == (tsfLow>>10))84break;8586HALDEBUG(ah, HAL_DEBUG_ANY,87"%s: TSF moved while trying to set quiet time "88"TSF: 0x%08x\n", __func__, tsfLow);89HALASSERT(j < 1); /* TSF shouldn't count twice or reg access is taking forever */90}9192OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_CHAN_IDLE);9394/* Allow the quiet mechanism to do its work */95OS_DELAY(200);96OS_REG_CLR_BIT(ah, AR_TIMER_MODE, AR_TIMER_MODE_QUIET);9798/* Verify the transmit q is empty */99for (i = STOP_DMA_TIMEOUT/STOP_DMA_ITER; i != 0; i--) {100if (ar5212NumTxPending(ah, q) == 0)101break;102OS_DELAY(STOP_DMA_ITER);103}104if (i == 0) {105HALDEBUG(ah, HAL_DEBUG_ANY,106"%s: Failed to stop Tx DMA in %d msec after killing"107" last frame\n", __func__, STOP_DMA_TIMEOUT / 1000);108}109OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_CHAN_IDLE);110}111112OS_REG_WRITE(ah, AR_Q_TXD, 0);113return (i != 0);114#undef STOP_DMA_ITER115#undef STOP_DMA_TIMEOUT116}117118#define VALID_KEY_TYPES \119((1 << HAL_KEY_TYPE_CLEAR) | (1 << HAL_KEY_TYPE_WEP)|\120(1 << HAL_KEY_TYPE_AES) | (1 << HAL_KEY_TYPE_TKIP))121#define isValidKeyType(_t) ((1 << (_t)) & VALID_KEY_TYPES)122123#define set11nTries(_series, _index) \124(SM((_series)[_index].Tries, AR_XmitDataTries##_index))125126#define set11nRate(_series, _index) \127(SM((_series)[_index].Rate, AR_XmitRate##_index))128129#define set11nPktDurRTSCTS(_series, _index) \130(SM((_series)[_index].PktDuration, AR_PacketDur##_index) |\131((_series)[_index].RateFlags & HAL_RATESERIES_RTS_CTS ?\132AR_RTSCTSQual##_index : 0))133134#define set11nRateFlags(_series, _index) \135((_series)[_index].RateFlags & HAL_RATESERIES_2040 ? AR_2040_##_index : 0) \136|((_series)[_index].RateFlags & HAL_RATESERIES_HALFGI ? AR_GI##_index : 0) \137|((_series)[_index].RateFlags & HAL_RATESERIES_STBC ? AR_STBC##_index : 0) \138|SM((_series)[_index].ChSel, AR_ChainSel##_index)139140/*141* Descriptor Access Functions142*/143144#define VALID_PKT_TYPES \145((1<<HAL_PKT_TYPE_NORMAL)|(1<<HAL_PKT_TYPE_ATIM)|\146(1<<HAL_PKT_TYPE_PSPOLL)|(1<<HAL_PKT_TYPE_PROBE_RESP)|\147(1<<HAL_PKT_TYPE_BEACON)|(1<<HAL_PKT_TYPE_AMPDU))148#define isValidPktType(_t) ((1<<(_t)) & VALID_PKT_TYPES)149#define VALID_TX_RATES \150((1<<0x0b)|(1<<0x0f)|(1<<0x0a)|(1<<0x0e)|(1<<0x09)|(1<<0x0d)|\151(1<<0x08)|(1<<0x0c)|(1<<0x1b)|(1<<0x1a)|(1<<0x1e)|(1<<0x19)|\152(1<<0x1d)|(1<<0x18)|(1<<0x1c)|(1<<0x01)|(1<<0x02)|(1<<0x03)|\153(1<<0x04)|(1<<0x05)|(1<<0x06)|(1<<0x07)|(1<<0x00))154/* NB: accept HT rates */155#define isValidTxRate(_r) ((1<<((_r) & 0x7f)) & VALID_TX_RATES)156157static inline int158ar5416RateToRateTable(struct ath_hal *ah, uint8_t rate, HAL_BOOL is_ht40)159{160161/*162* Handle the non-MCS rates163*/164switch (rate) {165case /* 1 Mb */ 0x1b:166case /* 1 MbS*/ 0x1b | 0x4:167return (AH5416(ah)->ah_ratesArray[rate1l]);168case /* 2 Mb */ 0x1a:169return (AH5416(ah)->ah_ratesArray[rate2l]);170case /* 2 MbS*/ 0x1a | 0x4:171return (AH5416(ah)->ah_ratesArray[rate2s]);172case /* 5.5 Mb */ 0x19:173return (AH5416(ah)->ah_ratesArray[rate5_5l]);174case /* 5.5 MbS*/ 0x19 | 0x4:175return (AH5416(ah)->ah_ratesArray[rate5_5s]);176case /* 11 Mb */ 0x18:177return (AH5416(ah)->ah_ratesArray[rate11l]);178case /* 11 MbS*/ 0x18 | 0x4:179return (AH5416(ah)->ah_ratesArray[rate11s]);180}181182/* OFDM rates */183switch (rate) {184case /* 6 Mb */ 0x0b:185return (AH5416(ah)->ah_ratesArray[rate6mb]);186case /* 9 Mb */ 0x0f:187return (AH5416(ah)->ah_ratesArray[rate9mb]);188case /* 12 Mb */ 0x0a:189return (AH5416(ah)->ah_ratesArray[rate12mb]);190case /* 18 Mb */ 0x0e:191return (AH5416(ah)->ah_ratesArray[rate18mb]);192case /* 24 Mb */ 0x09:193return (AH5416(ah)->ah_ratesArray[rate24mb]);194case /* 36 Mb */ 0x0d:195return (AH5416(ah)->ah_ratesArray[rate36mb]);196case /* 48 Mb */ 0x08:197return (AH5416(ah)->ah_ratesArray[rate48mb]);198case /* 54 Mb */ 0x0c:199return (AH5416(ah)->ah_ratesArray[rate54mb]);200}201202/*203* Handle HT20/HT40 - we only have to do MCS0-7;204* there's no stream differences.205*/206if ((rate & 0x80) && is_ht40) {207return (AH5416(ah)->ah_ratesArray[rateHt40_0 + (rate & 0x7)]);208} else if (rate & 0x80) {209return (AH5416(ah)->ah_ratesArray[rateHt20_0 + (rate & 0x7)]);210}211212/* XXX default (eg XR, bad bad person!) */213return (AH5416(ah)->ah_ratesArray[rate6mb]);214}215216/*217* Return the TX power to be used for the given rate/chains/TX power.218*219* There are a bunch of tweaks to make to a given TX power based on220* the current configuration, so...221*/222static uint16_t223ar5416GetTxRatePower(struct ath_hal *ah, uint8_t rate, uint8_t tx_chainmask,224uint16_t txPower, HAL_BOOL is_ht40)225{226int n_txpower, max_txpower;227const int cck_ofdm_delta = 2;228#define EEP_MINOR(_ah) \229(AH_PRIVATE(_ah)->ah_eeversion & AR5416_EEP_VER_MINOR_MASK)230#define IS_EEP_MINOR_V2(_ah) (EEP_MINOR(_ah) >= AR5416_EEP_MINOR_VER_2)231232/* Take a copy ; we may underflow and thus need to clamp things */233n_txpower = txPower;234235/* HT40? Need to adjust the TX power by this */236if (is_ht40)237n_txpower += AH5416(ah)->ah_ht40PowerIncForPdadc;238239/*240* Merlin? Offset the target TX power offset - it defaults to241* starting at -5.0dBm, but that can change!242*243* Kiwi/Kite? Always -5.0dBm offset.244*/245if (AR_SREV_KIWI_10_OR_LATER(ah)) {246n_txpower -= (AR5416_PWR_TABLE_OFFSET_DB * 2);247} else if (AR_SREV_MERLIN_20_OR_LATER(ah)) {248int8_t pwr_table_offset = 0;249/* This is in dBm, convert to 1/2 dBm */250(void) ath_hal_eepromGet(ah, AR_EEP_PWR_TABLE_OFFSET,251&pwr_table_offset);252n_txpower -= (pwr_table_offset * 2);253}254255/*256* If Open-loop TX power control is used, the CCK rates need257* to be offset by that.258*259* Rates: 2S, 2L, 1S, 1L, 5.5S, 5.5L260*261* XXX Odd, we don't have a PHY table entry for long preamble262* 1mbit CCK?263*/264if (AR_SREV_MERLIN_20_OR_LATER(ah) &&265ath_hal_eepromGetFlag(ah, AR_EEP_OL_PWRCTRL)) {266if (rate == 0x19 || rate == 0x1a || rate == 0x1b ||267rate == (0x19 | 0x04) || rate == (0x1a | 0x04) ||268rate == (0x1b | 0x04)) {269n_txpower -= cck_ofdm_delta;270}271}272273/*274* We're now offset by the same amount that the static maximum275* PHY power tables are. So, clamp the value based on that rate.276*/277max_txpower = ar5416RateToRateTable(ah, rate, is_ht40);278#if 0279ath_hal_printf(ah, "%s: n_txpower = %d, max_txpower = %d, "280"rate = 0x%x , is_ht40 = %d\n",281__func__,282n_txpower,283max_txpower,284rate,285is_ht40);286#endif287n_txpower = MIN(max_txpower, n_txpower);288289/*290* We don't have to offset the TX power for two or three291* chain operation here - it's done by the AR_PHY_POWER_TX_SUB292* register setting via the EEPROM.293*294* So for vendors that programmed the maximum target power assuming295* that 2/3 chains are always on, things will just plain work.296* (They won't reach that target power if only one chain is on, but297* that's a different problem.)298*/299300/* Over/underflow? Adjust */301if (n_txpower < 0)302n_txpower = 0;303else if (n_txpower > 63)304n_txpower = 63;305306/*307* For some odd reason the AR9160 with txpower=0 results in a308* much higher (max?) TX power. So, if it's a chipset before309* AR9220/AR9280, just clamp the minimum value at 1.310*/311if ((! AR_SREV_MERLIN_10_OR_LATER(ah)) && (n_txpower == 0))312n_txpower = 1;313314return (n_txpower);315#undef EEP_MINOR316#undef IS_EEP_MINOR_V2317}318319HAL_BOOL320ar5416SetupTxDesc(struct ath_hal *ah, struct ath_desc *ds,321u_int pktLen,322u_int hdrLen,323HAL_PKT_TYPE type,324u_int txPower,325u_int txRate0, u_int txTries0,326u_int keyIx,327u_int antMode,328u_int flags,329u_int rtsctsRate,330u_int rtsctsDuration,331u_int compicvLen,332u_int compivLen,333u_int comp)334{335#define RTSCTS (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)336struct ar5416_desc *ads = AR5416DESC(ds);337struct ath_hal_5416 *ahp = AH5416(ah);338339(void) hdrLen;340341HALASSERT(txTries0 != 0);342HALASSERT(isValidPktType(type));343HALASSERT(isValidTxRate(txRate0));344HALASSERT((flags & RTSCTS) != RTSCTS);345/* XXX validate antMode */346347txPower = (txPower + AH5212(ah)->ah_txPowerIndexOffset);348if (txPower > 63)349txPower = 63;350351/*352* XXX For now, just assume that this isn't a HT40 frame.353* It'll get over-ridden by the multi-rate TX power setup.354*/355if (AH5212(ah)->ah_tpcEnabled) {356txPower = ar5416GetTxRatePower(ah, txRate0,357ahp->ah_tx_chainmask,358txPower,359AH_FALSE);360}361362ads->ds_ctl0 = (pktLen & AR_FrameLen)363| (txPower << AR_XmitPower_S)364| (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)365| (flags & HAL_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)366| (flags & HAL_TXDESC_INTREQ ? AR_TxIntrReq : 0)367;368ads->ds_ctl1 = (type << AR_FrameType_S)369| (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0)370| (flags & HAL_TXDESC_HWTS ? AR_InsertTS : 0)371;372ads->ds_ctl2 = SM(txTries0, AR_XmitDataTries0)373| (flags & HAL_TXDESC_DURENA ? AR_DurUpdateEn : 0)374;375ads->ds_ctl3 = (txRate0 << AR_XmitRate0_S)376;377ads->ds_ctl4 = 0;378ads->ds_ctl5 = 0;379ads->ds_ctl6 = 0;380ads->ds_ctl7 = SM(ahp->ah_tx_chainmask, AR_ChainSel0)381| SM(ahp->ah_tx_chainmask, AR_ChainSel1)382| SM(ahp->ah_tx_chainmask, AR_ChainSel2)383| SM(ahp->ah_tx_chainmask, AR_ChainSel3)384;385ads->ds_ctl8 = SM(0, AR_AntCtl0);386ads->ds_ctl9 = SM(0, AR_AntCtl1) | SM(txPower, AR_XmitPower1);387ads->ds_ctl10 = SM(0, AR_AntCtl2) | SM(txPower, AR_XmitPower2);388ads->ds_ctl11 = SM(0, AR_AntCtl3) | SM(txPower, AR_XmitPower3);389390if (keyIx != HAL_TXKEYIX_INVALID) {391/* XXX validate key index */392ads->ds_ctl1 |= SM(keyIx, AR_DestIdx);393ads->ds_ctl0 |= AR_DestIdxValid;394ads->ds_ctl6 |= SM(ahp->ah_keytype[keyIx], AR_EncrType);395}396if (flags & RTSCTS) {397if (!isValidTxRate(rtsctsRate)) {398HALDEBUG(ah, HAL_DEBUG_ANY,399"%s: invalid rts/cts rate 0x%x\n",400__func__, rtsctsRate);401return AH_FALSE;402}403/* XXX validate rtsctsDuration */404ads->ds_ctl0 |= (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0)405| (flags & HAL_TXDESC_RTSENA ? AR_RTSEnable : 0)406;407ads->ds_ctl7 |= (rtsctsRate << AR_RTSCTSRate_S);408}409410/*411* Set the TX antenna to 0 for Kite412* To preserve existing behaviour, also set the TPC bits to 0;413* when TPC is enabled these should be filled in appropriately.414*415* XXX TODO: when doing TPC, set the TX power up appropriately?416*/417if (AR_SREV_KITE(ah)) {418ads->ds_ctl8 = SM(0, AR_AntCtl0);419ads->ds_ctl9 = SM(0, AR_AntCtl1) | SM(0, AR_XmitPower1);420ads->ds_ctl10 = SM(0, AR_AntCtl2) | SM(0, AR_XmitPower2);421ads->ds_ctl11 = SM(0, AR_AntCtl3) | SM(0, AR_XmitPower3);422}423return AH_TRUE;424#undef RTSCTS425}426427HAL_BOOL428ar5416SetupXTxDesc(struct ath_hal *ah, struct ath_desc *ds,429u_int txRate1, u_int txTries1,430u_int txRate2, u_int txTries2,431u_int txRate3, u_int txTries3)432{433struct ar5416_desc *ads = AR5416DESC(ds);434435if (txTries1) {436HALASSERT(isValidTxRate(txRate1));437ads->ds_ctl2 |= SM(txTries1, AR_XmitDataTries1);438ads->ds_ctl3 |= (txRate1 << AR_XmitRate1_S);439}440if (txTries2) {441HALASSERT(isValidTxRate(txRate2));442ads->ds_ctl2 |= SM(txTries2, AR_XmitDataTries2);443ads->ds_ctl3 |= (txRate2 << AR_XmitRate2_S);444}445if (txTries3) {446HALASSERT(isValidTxRate(txRate3));447ads->ds_ctl2 |= SM(txTries3, AR_XmitDataTries3);448ads->ds_ctl3 |= (txRate3 << AR_XmitRate3_S);449}450return AH_TRUE;451}452453/*454* XXX TODO: Figure out if AR_InsertTS is required on all sub-frames455* of a TX descriptor.456*/457HAL_BOOL458ar5416FillTxDesc(struct ath_hal *ah, struct ath_desc *ds,459HAL_DMA_ADDR *bufAddrList, uint32_t *segLenList, u_int descId,460u_int qcuId, HAL_BOOL firstSeg, HAL_BOOL lastSeg,461const struct ath_desc *ds0)462{463struct ar5416_desc *ads = AR5416DESC(ds);464uint32_t segLen = segLenList[0];465466HALASSERT((segLen &~ AR_BufLen) == 0);467468ds->ds_data = bufAddrList[0];469470if (firstSeg) {471/*472* First descriptor, don't clobber xmit control data473* setup by ar5212SetupTxDesc.474*/475ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);476} else if (lastSeg) { /* !firstSeg && lastSeg */477/*478* Last descriptor in a multi-descriptor frame,479* copy the multi-rate transmit parameters from480* the first frame for processing on completion.481*/482ads->ds_ctl1 = segLen;483#ifdef AH_NEED_DESC_SWAP484ads->ds_ctl0 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl0)485& AR_TxIntrReq;486ads->ds_ctl2 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl2);487ads->ds_ctl3 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl3);488/* ctl6 - we only need encrtype; the rest are blank */489ads->ds_ctl6 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl6 & AR_EncrType);490#else491ads->ds_ctl0 = AR5416DESC_CONST(ds0)->ds_ctl0 & AR_TxIntrReq;492ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;493ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;494/* ctl6 - we only need encrtype; the rest are blank */495ads->ds_ctl6 = AR5416DESC_CONST(ds0)->ds_ctl6 & AR_EncrType;496#endif497} else { /* !firstSeg && !lastSeg */498/*499* Intermediate descriptor in a multi-descriptor frame.500*/501#ifdef AH_NEED_DESC_SWAP502ads->ds_ctl0 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl0)503& AR_TxIntrReq;504ads->ds_ctl6 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl6 & AR_EncrType);505#else506ads->ds_ctl0 = AR5416DESC_CONST(ds0)->ds_ctl0 & AR_TxIntrReq;507ads->ds_ctl6 = AR5416DESC_CONST(ds0)->ds_ctl6 & AR_EncrType;508#endif509ads->ds_ctl1 = segLen | AR_TxMore;510ads->ds_ctl2 = 0;511ads->ds_ctl3 = 0;512}513/* XXX only on last descriptor? */514OS_MEMZERO(ads->u.tx.status, sizeof(ads->u.tx.status));515return AH_TRUE;516}517518/*519* NB: cipher is no longer used, it's calculated.520*/521HAL_BOOL522ar5416ChainTxDesc(struct ath_hal *ah, struct ath_desc *ds,523HAL_DMA_ADDR *bufAddrList,524uint32_t *segLenList,525u_int pktLen,526u_int hdrLen,527HAL_PKT_TYPE type,528u_int keyIx,529HAL_CIPHER cipher,530uint8_t delims,531HAL_BOOL firstSeg,532HAL_BOOL lastSeg,533HAL_BOOL lastAggr)534{535struct ar5416_desc *ads = AR5416DESC(ds);536uint32_t *ds_txstatus = AR5416_DS_TXSTATUS(ah,ads);537struct ath_hal_5416 *ahp = AH5416(ah);538u_int segLen = segLenList[0];539540int isaggr = 0;541uint32_t last_aggr = 0;542543(void) hdrLen;544(void) ah;545546HALASSERT((segLen &~ AR_BufLen) == 0);547ds->ds_data = bufAddrList[0];548549HALASSERT(isValidPktType(type));550if (type == HAL_PKT_TYPE_AMPDU) {551type = HAL_PKT_TYPE_NORMAL;552isaggr = 1;553if (lastAggr == AH_FALSE)554last_aggr = AR_MoreAggr;555}556557/*558* Since this function is called before any of the other559* descriptor setup functions (at least in this particular560* 802.11n aggregation implementation), always bzero() the561* descriptor. Previously this would be done for all but562* the first segment.563* XXX TODO: figure out why; perhaps I'm using this slightly564* XXX incorrectly.565*/566OS_MEMZERO(ds->ds_hw, AR5416_DESC_TX_CTL_SZ);567568/*569* Note: VEOL should only be for the last descriptor in the chain.570*/571ads->ds_ctl0 = (pktLen & AR_FrameLen);572573/*574* For aggregates:575* + IsAggr must be set for all descriptors of all subframes of576* the aggregate577* + MoreAggr must be set for all descriptors of all subframes578* of the aggregate EXCEPT the last subframe;579* + MoreAggr must be _CLEAR_ for all descrpitors of the last580* subframe of the aggregate.581*/582ads->ds_ctl1 = (type << AR_FrameType_S)583| (isaggr ? (AR_IsAggr | last_aggr) : 0);584585ads->ds_ctl2 = 0;586ads->ds_ctl3 = 0;587if (keyIx != HAL_TXKEYIX_INVALID) {588/* XXX validate key index */589ads->ds_ctl1 |= SM(keyIx, AR_DestIdx);590ads->ds_ctl0 |= AR_DestIdxValid;591}592593ads->ds_ctl6 |= SM(ahp->ah_keytype[keyIx], AR_EncrType);594if (isaggr) {595ads->ds_ctl6 |= SM(delims, AR_PadDelim);596}597598if (firstSeg) {599ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);600} else if (lastSeg) { /* !firstSeg && lastSeg */601ads->ds_ctl0 = 0;602ads->ds_ctl1 |= segLen;603} else { /* !firstSeg && !lastSeg */604/*605* Intermediate descriptor in a multi-descriptor frame.606*/607ads->ds_ctl0 = 0;608ads->ds_ctl1 |= segLen | AR_TxMore;609}610ds_txstatus[0] = ds_txstatus[1] = 0;611ds_txstatus[9] &= ~AR_TxDone;612613return AH_TRUE;614}615616HAL_BOOL617ar5416SetupFirstTxDesc(struct ath_hal *ah, struct ath_desc *ds,618u_int aggrLen, u_int flags, u_int txPower,619u_int txRate0, u_int txTries0, u_int antMode,620u_int rtsctsRate, u_int rtsctsDuration)621{622#define RTSCTS (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)623struct ar5416_desc *ads = AR5416DESC(ds);624struct ath_hal_5212 *ahp = AH5212(ah);625626HALASSERT(txTries0 != 0);627HALASSERT(isValidTxRate(txRate0));628HALASSERT((flags & RTSCTS) != RTSCTS);629/* XXX validate antMode */630631txPower = (txPower + ahp->ah_txPowerIndexOffset );632if(txPower > 63) txPower=63;633634ads->ds_ctl0 |= (txPower << AR_XmitPower_S)635| (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)636| (flags & HAL_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)637| (flags & HAL_TXDESC_INTREQ ? AR_TxIntrReq : 0);638ads->ds_ctl1 |= (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0);639ads->ds_ctl2 |= SM(txTries0, AR_XmitDataTries0);640ads->ds_ctl3 |= (txRate0 << AR_XmitRate0_S);641ads->ds_ctl7 = SM(AH5416(ah)->ah_tx_chainmask, AR_ChainSel0)642| SM(AH5416(ah)->ah_tx_chainmask, AR_ChainSel1)643| SM(AH5416(ah)->ah_tx_chainmask, AR_ChainSel2)644| SM(AH5416(ah)->ah_tx_chainmask, AR_ChainSel3);645646/* NB: no V1 WAR */647ads->ds_ctl8 = SM(0, AR_AntCtl0);648ads->ds_ctl9 = SM(0, AR_AntCtl1) | SM(txPower, AR_XmitPower1);649ads->ds_ctl10 = SM(0, AR_AntCtl2) | SM(txPower, AR_XmitPower2);650ads->ds_ctl11 = SM(0, AR_AntCtl3) | SM(txPower, AR_XmitPower3);651652ads->ds_ctl6 &= ~(0xffff);653ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);654655if (flags & RTSCTS) {656/* XXX validate rtsctsDuration */657ads->ds_ctl0 |= (flags & HAL_TXDESC_CTSENA ? AR_CTSEnable : 0)658| (flags & HAL_TXDESC_RTSENA ? AR_RTSEnable : 0);659}660661/*662* Set the TX antenna to 0 for Kite663* To preserve existing behaviour, also set the TPC bits to 0;664* when TPC is enabled these should be filled in appropriately.665*/666if (AR_SREV_KITE(ah)) {667ads->ds_ctl8 = SM(0, AR_AntCtl0);668ads->ds_ctl9 = SM(0, AR_AntCtl1) | SM(0, AR_XmitPower1);669ads->ds_ctl10 = SM(0, AR_AntCtl2) | SM(0, AR_XmitPower2);670ads->ds_ctl11 = SM(0, AR_AntCtl3) | SM(0, AR_XmitPower3);671}672673return AH_TRUE;674#undef RTSCTS675}676677HAL_BOOL678ar5416SetupLastTxDesc(struct ath_hal *ah, struct ath_desc *ds,679const struct ath_desc *ds0)680{681struct ar5416_desc *ads = AR5416DESC(ds);682683ads->ds_ctl1 &= ~AR_MoreAggr;684ads->ds_ctl6 &= ~AR_PadDelim;685686/* hack to copy rate info to last desc for later processing */687#ifdef AH_NEED_DESC_SWAP688ads->ds_ctl2 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl2);689ads->ds_ctl3 = __bswap32(AR5416DESC_CONST(ds0)->ds_ctl3);690#else691ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;692ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;693#endif694return AH_TRUE;695}696697#ifdef AH_NEED_DESC_SWAP698/* Swap transmit descriptor */699static __inline void700ar5416SwapTxDesc(struct ath_desc *ds)701{702ds->ds_data = __bswap32(ds->ds_data);703ds->ds_ctl0 = __bswap32(ds->ds_ctl0);704ds->ds_ctl1 = __bswap32(ds->ds_ctl1);705ds->ds_hw[0] = __bswap32(ds->ds_hw[0]);706ds->ds_hw[1] = __bswap32(ds->ds_hw[1]);707ds->ds_hw[2] = __bswap32(ds->ds_hw[2]);708ds->ds_hw[3] = __bswap32(ds->ds_hw[3]);709}710#endif711712/*713* Processing of HW TX descriptor.714*/715HAL_STATUS716ar5416ProcTxDesc(struct ath_hal *ah,717struct ath_desc *ds, struct ath_tx_status *ts)718{719struct ar5416_desc *ads = AR5416DESC(ds);720uint32_t *ds_txstatus = AR5416_DS_TXSTATUS(ah,ads);721722#ifdef AH_NEED_DESC_SWAP723if ((ds_txstatus[9] & __bswap32(AR_TxDone)) == 0)724return HAL_EINPROGRESS;725ar5416SwapTxDesc(ds);726#else727if ((ds_txstatus[9] & AR_TxDone) == 0)728return HAL_EINPROGRESS;729#endif730731/* Update software copies of the HW status */732ts->ts_seqnum = MS(ds_txstatus[9], AR_SeqNum);733ts->ts_tstamp = AR_SendTimestamp(ds_txstatus);734ts->ts_tid = MS(ds_txstatus[9], AR_TxTid);735736ts->ts_status = 0;737if (ds_txstatus[1] & AR_ExcessiveRetries)738ts->ts_status |= HAL_TXERR_XRETRY;739if (ds_txstatus[1] & AR_Filtered)740ts->ts_status |= HAL_TXERR_FILT;741if (ds_txstatus[1] & AR_FIFOUnderrun)742ts->ts_status |= HAL_TXERR_FIFO;743if (ds_txstatus[9] & AR_TxOpExceeded)744ts->ts_status |= HAL_TXERR_XTXOP;745if (ds_txstatus[1] & AR_TxTimerExpired)746ts->ts_status |= HAL_TXERR_TIMER_EXPIRED;747748ts->ts_flags = 0;749if (ds_txstatus[0] & AR_TxBaStatus) {750ts->ts_flags |= HAL_TX_BA;751ts->ts_ba_low = AR_BaBitmapLow(ds_txstatus);752ts->ts_ba_high = AR_BaBitmapHigh(ds_txstatus);753}754if (ds->ds_ctl1 & AR_IsAggr)755ts->ts_flags |= HAL_TX_AGGR;756if (ds_txstatus[1] & AR_DescCfgErr)757ts->ts_flags |= HAL_TX_DESC_CFG_ERR;758if (ds_txstatus[1] & AR_TxDataUnderrun)759ts->ts_flags |= HAL_TX_DATA_UNDERRUN;760if (ds_txstatus[1] & AR_TxDelimUnderrun)761ts->ts_flags |= HAL_TX_DELIM_UNDERRUN;762763/*764* Extract the transmit rate used and mark the rate as765* ``alternate'' if it wasn't the series 0 rate.766*/767ts->ts_finaltsi = MS(ds_txstatus[9], AR_FinalTxIdx);768switch (ts->ts_finaltsi) {769case 0:770ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate0);771break;772case 1:773ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate1);774break;775case 2:776ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate2);777break;778case 3:779ts->ts_rate = MS(ads->ds_ctl3, AR_XmitRate3);780break;781}782783ts->ts_rssi = MS(ds_txstatus[5], AR_TxRSSICombined);784ts->ts_rssi_ctl[0] = MS(ds_txstatus[0], AR_TxRSSIAnt00);785ts->ts_rssi_ctl[1] = MS(ds_txstatus[0], AR_TxRSSIAnt01);786ts->ts_rssi_ctl[2] = MS(ds_txstatus[0], AR_TxRSSIAnt02);787ts->ts_rssi_ext[0] = MS(ds_txstatus[5], AR_TxRSSIAnt10);788ts->ts_rssi_ext[1] = MS(ds_txstatus[5], AR_TxRSSIAnt11);789ts->ts_rssi_ext[2] = MS(ds_txstatus[5], AR_TxRSSIAnt12);790ts->ts_evm0 = AR_TxEVM0(ds_txstatus);791ts->ts_evm1 = AR_TxEVM1(ds_txstatus);792ts->ts_evm2 = AR_TxEVM2(ds_txstatus);793794ts->ts_shortretry = MS(ds_txstatus[1], AR_RTSFailCnt);795ts->ts_longretry = MS(ds_txstatus[1], AR_DataFailCnt);796/*797* The retry count has the number of un-acked tries for the798* final series used. When doing multi-rate retry we must799* fixup the retry count by adding in the try counts for800* each series that was fully-processed. Beware that this801* takes values from the try counts in the final descriptor.802* These are not required by the hardware. We assume they803* are placed there by the driver as otherwise we have no804* access and the driver can't do the calculation because it805* doesn't know the descriptor format.806*/807switch (ts->ts_finaltsi) {808case 3: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries2);809case 2: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries1);810case 1: ts->ts_longretry += MS(ads->ds_ctl2, AR_XmitDataTries0);811}812813/*814* These fields are not used. Zero these to preserve compatibility815* with existing drivers.816*/817ts->ts_virtcol = MS(ads->ds_ctl1, AR_VirtRetryCnt);818ts->ts_antenna = 0; /* We don't switch antennas on Owl*/819820/* handle tx trigger level changes internally */821if ((ts->ts_status & HAL_TXERR_FIFO) ||822(ts->ts_flags & (HAL_TX_DATA_UNDERRUN | HAL_TX_DELIM_UNDERRUN)))823ar5212UpdateTxTrigLevel(ah, AH_TRUE);824825return HAL_OK;826}827828HAL_BOOL829ar5416SetGlobalTxTimeout(struct ath_hal *ah, u_int tu)830{831struct ath_hal_5416 *ahp = AH5416(ah);832833if (tu > 0xFFFF) {834HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad global tx timeout %u\n",835__func__, tu);836/* restore default handling */837ahp->ah_globaltxtimeout = (u_int) -1;838return AH_FALSE;839}840OS_REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);841ahp->ah_globaltxtimeout = tu;842return AH_TRUE;843}844845u_int846ar5416GetGlobalTxTimeout(struct ath_hal *ah)847{848return MS(OS_REG_READ(ah, AR_GTXTO), AR_GTXTO_TIMEOUT_LIMIT);849}850851#define HT_RC_2_MCS(_rc) ((_rc) & 0x0f)852static const u_int8_t baDurationDelta[] = {85324, // 0: BPSK85412, // 1: QPSK 1/285512, // 2: QPSK 3/48564, // 3: 16-QAM 1/28574, // 4: 16-QAM 3/48584, // 5: 64-QAM 2/38594, // 6: 64-QAM 3/48604, // 7: 64-QAM 5/686124, // 8: BPSK86212, // 9: QPSK 1/286312, // 10: QPSK 3/48644, // 11: 16-QAM 1/28654, // 12: 16-QAM 3/48664, // 13: 64-QAM 2/38674, // 14: 64-QAM 3/48684, // 15: 64-QAM 5/6869};870871void872ar5416Set11nRateScenario(struct ath_hal *ah, struct ath_desc *ds,873u_int durUpdateEn, u_int rtsctsRate,874HAL_11N_RATE_SERIES series[], u_int nseries, u_int flags)875{876struct ar5416_desc *ads = AR5416DESC(ds);877uint32_t ds_ctl0;878879HALASSERT(nseries == 4);880(void)nseries;881882/*883* Only one of RTS and CTS enable must be set.884* If a frame has both set, just do RTS protection -885* that's enough to satisfy legacy protection.886*/887if (flags & (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA)) {888ds_ctl0 = ads->ds_ctl0;889890if (flags & HAL_TXDESC_RTSENA) {891ds_ctl0 &= ~AR_CTSEnable;892ds_ctl0 |= AR_RTSEnable;893} else {894ds_ctl0 &= ~AR_RTSEnable;895ds_ctl0 |= AR_CTSEnable;896}897898ads->ds_ctl0 = ds_ctl0;899} else {900ads->ds_ctl0 =901(ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));902}903904ads->ds_ctl2 = set11nTries(series, 0)905| set11nTries(series, 1)906| set11nTries(series, 2)907| set11nTries(series, 3)908| (durUpdateEn ? AR_DurUpdateEn : 0);909910ads->ds_ctl3 = set11nRate(series, 0)911| set11nRate(series, 1)912| set11nRate(series, 2)913| set11nRate(series, 3);914915ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)916| set11nPktDurRTSCTS(series, 1);917918ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)919| set11nPktDurRTSCTS(series, 3);920921ads->ds_ctl7 = set11nRateFlags(series, 0)922| set11nRateFlags(series, 1)923| set11nRateFlags(series, 2)924| set11nRateFlags(series, 3)925| SM(rtsctsRate, AR_RTSCTSRate);926927/*928* Doing per-packet TPC - update the TX power for the first929* field; program in the other series.930*/931if (AH5212(ah)->ah_tpcEnabled) {932uint32_t ds_ctl0;933uint16_t txPower;934935/* Modify the tx power field for rate 0 */936txPower = ar5416GetTxRatePower(ah, series[0].Rate,937series[0].ChSel,938series[0].tx_power_cap,939!! (series[0].RateFlags & HAL_RATESERIES_2040));940ds_ctl0 = ads->ds_ctl0 & ~AR_XmitPower;941ds_ctl0 |= (txPower << AR_XmitPower_S);942ads->ds_ctl0 = ds_ctl0;943944/*945* Override the whole descriptor field for each TX power.946*947* This will need changing if we ever support antenna control948* programming.949*/950txPower = ar5416GetTxRatePower(ah, series[1].Rate,951series[1].ChSel,952series[1].tx_power_cap,953!! (series[1].RateFlags & HAL_RATESERIES_2040));954ads->ds_ctl9 = SM(0, AR_AntCtl1) | SM(txPower, AR_XmitPower1);955956txPower = ar5416GetTxRatePower(ah, series[2].Rate,957series[2].ChSel,958series[2].tx_power_cap,959!! (series[2].RateFlags & HAL_RATESERIES_2040));960ads->ds_ctl10 = SM(0, AR_AntCtl2) | SM(txPower, AR_XmitPower2);961962txPower = ar5416GetTxRatePower(ah, series[3].Rate,963series[3].ChSel,964series[3].tx_power_cap,965!! (series[3].RateFlags & HAL_RATESERIES_2040));966ads->ds_ctl11 = SM(0, AR_AntCtl3) | SM(txPower, AR_XmitPower3);967}968}969970/*971* Note: this should be called before calling ar5416SetBurstDuration()972* (if it is indeed called) in order to ensure that the burst duration973* is correctly updated with the BA delta workaround.974*/975void976ar5416Set11nAggrFirst(struct ath_hal *ah, struct ath_desc *ds, u_int aggrLen,977u_int numDelims)978{979struct ar5416_desc *ads = AR5416DESC(ds);980uint32_t flags;981uint32_t burstDur;982uint8_t rate;983984ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);985986ads->ds_ctl6 &= ~(AR_AggrLen | AR_PadDelim);987ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);988ads->ds_ctl6 |= SM(numDelims, AR_PadDelim);989990if (! AR_SREV_MERLIN_10_OR_LATER(ah)) {991/*992* XXX It'd be nice if I were passed in the rate scenario993* at this point..994*/995rate = MS(ads->ds_ctl3, AR_XmitRate0);996flags = ads->ds_ctl0 & (AR_CTSEnable | AR_RTSEnable);997/*998* WAR - MAC assumes normal ACK time instead of999* block ACK while computing packet duration.1000* Add this delta to the burst duration in the descriptor.1001*/1002if (flags && (ads->ds_ctl1 & AR_IsAggr)) {1003burstDur = baDurationDelta[HT_RC_2_MCS(rate)];1004ads->ds_ctl2 &= ~(AR_BurstDur);1005ads->ds_ctl2 |= SM(burstDur, AR_BurstDur);1006}1007}1008}10091010void1011ar5416Set11nAggrMiddle(struct ath_hal *ah, struct ath_desc *ds, u_int numDelims)1012{1013struct ar5416_desc *ads = AR5416DESC(ds);1014uint32_t *ds_txstatus = AR5416_DS_TXSTATUS(ah,ads);10151016ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);10171018ads->ds_ctl6 &= ~AR_PadDelim;1019ads->ds_ctl6 |= SM(numDelims, AR_PadDelim);1020ads->ds_ctl6 &= ~AR_AggrLen;10211022/*1023* Clear the TxDone status here, may need to change1024* func name to reflect this1025*/1026ds_txstatus[9] &= ~AR_TxDone;1027}10281029void1030ar5416Set11nAggrLast(struct ath_hal *ah, struct ath_desc *ds)1031{1032struct ar5416_desc *ads = AR5416DESC(ds);10331034ads->ds_ctl1 |= AR_IsAggr;1035ads->ds_ctl1 &= ~AR_MoreAggr;1036ads->ds_ctl6 &= ~AR_PadDelim;1037}10381039void1040ar5416Clr11nAggr(struct ath_hal *ah, struct ath_desc *ds)1041{1042struct ar5416_desc *ads = AR5416DESC(ds);10431044ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);1045ads->ds_ctl6 &= ~AR_PadDelim;1046ads->ds_ctl6 &= ~AR_AggrLen;1047}10481049void1050ar5416Set11nVirtualMoreFrag(struct ath_hal *ah, struct ath_desc *ds,1051u_int vmf)1052{1053struct ar5416_desc *ads = AR5416DESC(ds);1054if (vmf)1055ads->ds_ctl0 |= AR_VirtMoreFrag;1056else1057ads->ds_ctl0 &= ~AR_VirtMoreFrag;1058}10591060/*1061* Program the burst duration, with the included BA delta if it's1062* applicable.1063*/1064void1065ar5416Set11nBurstDuration(struct ath_hal *ah, struct ath_desc *ds,1066u_int burstDuration)1067{1068struct ar5416_desc *ads = AR5416DESC(ds);1069uint32_t burstDur = 0;1070uint8_t rate;10711072if (! AR_SREV_MERLIN_10_OR_LATER(ah)) {1073/*1074* XXX It'd be nice if I were passed in the rate scenario1075* at this point..1076*/1077rate = MS(ads->ds_ctl3, AR_XmitDataTries0);1078/*1079* WAR - MAC assumes normal ACK time instead of1080* block ACK while computing packet duration.1081* Add this delta to the burst duration in the descriptor.1082*/1083if (ads->ds_ctl1 & AR_IsAggr) {1084burstDur = baDurationDelta[HT_RC_2_MCS(rate)];1085}1086}10871088ads->ds_ctl2 &= ~AR_BurstDur;1089ads->ds_ctl2 |= SM(burstDur + burstDuration, AR_BurstDur);1090}10911092/*1093* Retrieve the rate table from the given TX completion descriptor1094*/1095HAL_BOOL1096ar5416GetTxCompletionRates(struct ath_hal *ah, const struct ath_desc *ds0, int *rates, int *tries)1097{1098const struct ar5416_desc *ads = AR5416DESC_CONST(ds0);10991100rates[0] = MS(ads->ds_ctl3, AR_XmitRate0);1101rates[1] = MS(ads->ds_ctl3, AR_XmitRate1);1102rates[2] = MS(ads->ds_ctl3, AR_XmitRate2);1103rates[3] = MS(ads->ds_ctl3, AR_XmitRate3);11041105tries[0] = MS(ads->ds_ctl2, AR_XmitDataTries0);1106tries[1] = MS(ads->ds_ctl2, AR_XmitDataTries1);1107tries[2] = MS(ads->ds_ctl2, AR_XmitDataTries2);1108tries[3] = MS(ads->ds_ctl2, AR_XmitDataTries3);11091110return AH_TRUE;1111}11121113/*1114* TX queue management routines - AR5416 and later chipsets1115*/11161117/*1118* Allocate and initialize a tx DCU/QCU combination.1119*/1120int1121ar5416SetupTxQueue(struct ath_hal *ah, HAL_TX_QUEUE type,1122const HAL_TXQ_INFO *qInfo)1123{1124struct ath_hal_5212 *ahp = AH5212(ah);1125HAL_TX_QUEUE_INFO *qi;1126HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;1127int q, defqflags;11281129/* by default enable OK+ERR+DESC+URN interrupts */1130defqflags = HAL_TXQ_TXOKINT_ENABLE1131| HAL_TXQ_TXERRINT_ENABLE1132| HAL_TXQ_TXDESCINT_ENABLE1133| HAL_TXQ_TXURNINT_ENABLE;1134/* XXX move queue assignment to driver */1135switch (type) {1136case HAL_TX_QUEUE_BEACON:1137q = pCap->halTotalQueues-1; /* highest priority */1138defqflags |= HAL_TXQ_DBA_GATED1139| HAL_TXQ_CBR_DIS_QEMPTY1140| HAL_TXQ_ARB_LOCKOUT_GLOBAL1141| HAL_TXQ_BACKOFF_DISABLE;1142break;1143case HAL_TX_QUEUE_CAB:1144q = pCap->halTotalQueues-2; /* next highest priority */1145defqflags |= HAL_TXQ_DBA_GATED1146| HAL_TXQ_CBR_DIS_QEMPTY1147| HAL_TXQ_CBR_DIS_BEMPTY1148| HAL_TXQ_ARB_LOCKOUT_GLOBAL1149| HAL_TXQ_BACKOFF_DISABLE;1150break;1151case HAL_TX_QUEUE_PSPOLL:1152q = 1; /* lowest priority */1153defqflags |= HAL_TXQ_DBA_GATED1154| HAL_TXQ_CBR_DIS_QEMPTY1155| HAL_TXQ_CBR_DIS_BEMPTY1156| HAL_TXQ_ARB_LOCKOUT_GLOBAL1157| HAL_TXQ_BACKOFF_DISABLE;1158break;1159case HAL_TX_QUEUE_UAPSD:1160q = pCap->halTotalQueues-3; /* nextest highest priority */1161if (ahp->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE) {1162HALDEBUG(ah, HAL_DEBUG_ANY,1163"%s: no available UAPSD tx queue\n", __func__);1164return -1;1165}1166break;1167case HAL_TX_QUEUE_DATA:1168for (q = 0; q < pCap->halTotalQueues; q++)1169if (ahp->ah_txq[q].tqi_type == HAL_TX_QUEUE_INACTIVE)1170break;1171if (q == pCap->halTotalQueues) {1172HALDEBUG(ah, HAL_DEBUG_ANY,1173"%s: no available tx queue\n", __func__);1174return -1;1175}1176break;1177default:1178HALDEBUG(ah, HAL_DEBUG_ANY,1179"%s: bad tx queue type %u\n", __func__, type);1180return -1;1181}11821183HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);11841185qi = &ahp->ah_txq[q];1186if (qi->tqi_type != HAL_TX_QUEUE_INACTIVE) {1187HALDEBUG(ah, HAL_DEBUG_ANY, "%s: tx queue %u already active\n",1188__func__, q);1189return -1;1190}1191OS_MEMZERO(qi, sizeof(HAL_TX_QUEUE_INFO));1192qi->tqi_type = type;1193if (qInfo == AH_NULL) {1194qi->tqi_qflags = defqflags;1195qi->tqi_aifs = INIT_AIFS;1196qi->tqi_cwmin = HAL_TXQ_USEDEFAULT; /* NB: do at reset */1197qi->tqi_cwmax = INIT_CWMAX;1198qi->tqi_shretry = INIT_SH_RETRY;1199qi->tqi_lgretry = INIT_LG_RETRY;1200qi->tqi_physCompBuf = 0;1201} else {1202qi->tqi_physCompBuf = qInfo->tqi_compBuf;1203(void) ar5212SetTxQueueProps(ah, q, qInfo);1204}1205/* NB: must be followed by ar5212ResetTxQueue */1206return q;1207}12081209/*1210* Update the h/w interrupt registers to reflect a tx q's configuration.1211*/1212static void1213setTxQInterrupts(struct ath_hal *ah, HAL_TX_QUEUE_INFO *qi)1214{1215struct ath_hal_5212 *ahp = AH5212(ah);12161217HALDEBUG(ah, HAL_DEBUG_TXQUEUE,1218"%s: tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n", __func__,1219ahp->ah_txOkInterruptMask, ahp->ah_txErrInterruptMask,1220ahp->ah_txDescInterruptMask, ahp->ah_txEolInterruptMask,1221ahp->ah_txUrnInterruptMask);12221223OS_REG_WRITE(ah, AR_IMR_S0,1224SM(ahp->ah_txOkInterruptMask, AR_IMR_S0_QCU_TXOK)1225| SM(ahp->ah_txDescInterruptMask, AR_IMR_S0_QCU_TXDESC)1226);1227OS_REG_WRITE(ah, AR_IMR_S1,1228SM(ahp->ah_txErrInterruptMask, AR_IMR_S1_QCU_TXERR)1229| SM(ahp->ah_txEolInterruptMask, AR_IMR_S1_QCU_TXEOL)1230);1231OS_REG_RMW_FIELD(ah, AR_IMR_S2,1232AR_IMR_S2_QCU_TXURN, ahp->ah_txUrnInterruptMask);1233}12341235/*1236* Set the retry, aifs, cwmin/max, readyTime regs for specified queue1237* Assumes:1238* phwChannel has been set to point to the current channel1239*/1240#define TU_TO_USEC(_tu) ((_tu) << 10)1241HAL_BOOL1242ar5416ResetTxQueue(struct ath_hal *ah, u_int q)1243{1244struct ath_hal_5212 *ahp = AH5212(ah);1245HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;1246const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan;1247HAL_TX_QUEUE_INFO *qi;1248uint32_t cwMin, chanCwMin, qmisc, dmisc;12491250if (q >= pCap->halTotalQueues) {1251HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",1252__func__, q);1253return AH_FALSE;1254}1255qi = &ahp->ah_txq[q];1256if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {1257HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: inactive queue %u\n",1258__func__, q);1259return AH_TRUE; /* XXX??? */1260}12611262HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: reset queue %u\n", __func__, q);12631264if (qi->tqi_cwmin == HAL_TXQ_USEDEFAULT) {1265/*1266* Select cwmin according to channel type.1267* NB: chan can be NULL during attach1268*/1269if (chan && IEEE80211_IS_CHAN_B(chan))1270chanCwMin = INIT_CWMIN_11B;1271else1272chanCwMin = INIT_CWMIN;1273/* make sure that the CWmin is of the form (2^n - 1) */1274for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1)1275;1276} else1277cwMin = qi->tqi_cwmin;12781279/* set cwMin/Max and AIFS values */1280OS_REG_WRITE(ah, AR_DLCL_IFS(q),1281SM(cwMin, AR_D_LCL_IFS_CWMIN)1282| SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX)1283| SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));12841285/* Set retry limit values */1286OS_REG_WRITE(ah, AR_DRETRY_LIMIT(q),1287SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH)1288| SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG)1289| SM(qi->tqi_lgretry, AR_D_RETRY_LIMIT_FR_LG)1290| SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH)1291);12921293/* NB: always enable early termination on the QCU */1294qmisc = AR_Q_MISC_DCU_EARLY_TERM_REQ1295| SM(AR_Q_MISC_FSP_ASAP, AR_Q_MISC_FSP);12961297/* NB: always enable DCU to wait for next fragment from QCU */1298dmisc = AR_D_MISC_FRAG_WAIT_EN;12991300/* Enable exponential backoff window */1301dmisc |= AR_D_MISC_BKOFF_PERSISTENCE;13021303/*1304* The chip reset default is to use a DCU backoff threshold of 0x2.1305* Restore this when programming the DCU MISC register.1306*/1307dmisc |= 0x2;13081309/* multiqueue support */1310if (qi->tqi_cbrPeriod) {1311OS_REG_WRITE(ah, AR_QCBRCFG(q),1312SM(qi->tqi_cbrPeriod,AR_Q_CBRCFG_CBR_INTERVAL)1313| SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_CBR_OVF_THRESH));1314qmisc = (qmisc &~ AR_Q_MISC_FSP) | AR_Q_MISC_FSP_CBR;1315if (qi->tqi_cbrOverflowLimit)1316qmisc |= AR_Q_MISC_CBR_EXP_CNTR_LIMIT;1317}13181319if (qi->tqi_readyTime && (qi->tqi_type != HAL_TX_QUEUE_CAB)) {1320OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),1321SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_INT)1322| AR_Q_RDYTIMECFG_ENA);1323}13241325OS_REG_WRITE(ah, AR_DCHNTIME(q),1326SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR)1327| (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));13281329if (qi->tqi_readyTime &&1330(qi->tqi_qflags & HAL_TXQ_RDYTIME_EXP_POLICY_ENABLE))1331qmisc |= AR_Q_MISC_RDYTIME_EXP_POLICY;1332if (qi->tqi_qflags & HAL_TXQ_DBA_GATED)1333qmisc = (qmisc &~ AR_Q_MISC_FSP) | AR_Q_MISC_FSP_DBA_GATED;1334if (MS(qmisc, AR_Q_MISC_FSP) != AR_Q_MISC_FSP_ASAP) {1335/*1336* These are meangingful only when not scheduled asap.1337*/1338if (qi->tqi_qflags & HAL_TXQ_CBR_DIS_BEMPTY)1339qmisc |= AR_Q_MISC_CBR_INCR_DIS0;1340else1341qmisc &= ~AR_Q_MISC_CBR_INCR_DIS0;1342if (qi->tqi_qflags & HAL_TXQ_CBR_DIS_QEMPTY)1343qmisc |= AR_Q_MISC_CBR_INCR_DIS1;1344else1345qmisc &= ~AR_Q_MISC_CBR_INCR_DIS1;1346}13471348if (qi->tqi_qflags & HAL_TXQ_BACKOFF_DISABLE)1349dmisc |= AR_D_MISC_POST_FR_BKOFF_DIS;1350if (qi->tqi_qflags & HAL_TXQ_FRAG_BURST_BACKOFF_ENABLE)1351dmisc |= AR_D_MISC_FRAG_BKOFF_EN;1352if (qi->tqi_qflags & HAL_TXQ_ARB_LOCKOUT_GLOBAL)1353dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,1354AR_D_MISC_ARB_LOCKOUT_CNTRL);1355else if (qi->tqi_qflags & HAL_TXQ_ARB_LOCKOUT_INTRA)1356dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_INTRA_FR,1357AR_D_MISC_ARB_LOCKOUT_CNTRL);1358if (qi->tqi_qflags & HAL_TXQ_IGNORE_VIRTCOL)1359dmisc |= SM(AR_D_MISC_VIR_COL_HANDLING_IGNORE,1360AR_D_MISC_VIR_COL_HANDLING);1361if (qi->tqi_qflags & HAL_TXQ_SEQNUM_INC_DIS)1362dmisc |= AR_D_MISC_SEQ_NUM_INCR_DIS;13631364/*1365* Fillin type-dependent bits. Most of this can be1366* removed by specifying the queue parameters in the1367* driver; it's here for backwards compatibility.1368*/1369switch (qi->tqi_type) {1370case HAL_TX_QUEUE_BEACON: /* beacon frames */1371qmisc |= AR_Q_MISC_FSP_DBA_GATED1372| AR_Q_MISC_BEACON_USE1373| AR_Q_MISC_CBR_INCR_DIS1;13741375dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,1376AR_D_MISC_ARB_LOCKOUT_CNTRL)1377| AR_D_MISC_BEACON_USE1378| AR_D_MISC_POST_FR_BKOFF_DIS;1379break;1380case HAL_TX_QUEUE_CAB: /* CAB frames */1381/*1382* No longer Enable AR_Q_MISC_RDYTIME_EXP_POLICY,1383* There is an issue with the CAB Queue1384* not properly refreshing the Tx descriptor if1385* the TXE clear setting is used.1386*/1387qmisc |= AR_Q_MISC_FSP_DBA_GATED1388| AR_Q_MISC_CBR_INCR_DIS11389| AR_Q_MISC_CBR_INCR_DIS0;1390HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: CAB: tqi_readyTime = %d\n",1391__func__, qi->tqi_readyTime);1392if (qi->tqi_readyTime) {1393HALDEBUG(ah, HAL_DEBUG_TXQUEUE,1394"%s: using tqi_readyTime\n", __func__);1395OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),1396SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_INT) |1397AR_Q_RDYTIMECFG_ENA);1398} else {1399int value;1400/*1401* NB: don't set default ready time if driver1402* has explicitly specified something. This is1403* here solely for backwards compatibility.1404*/1405/*1406* XXX for now, hard-code a CAB interval of 70%1407* XXX of the total beacon interval.1408*1409* XXX This keeps Merlin and later based MACs1410* XXX quite a bit happier (stops stuck beacons,1411* XXX which I gather is because of such a long1412* XXX cabq time.)1413*/1414value = (ahp->ah_beaconInterval * 50 / 100)1415- ah->ah_config.ah_additional_swba_backoff1416- ah->ah_config.ah_sw_beacon_response_time1417+ ah->ah_config.ah_dma_beacon_response_time;1418/*1419* XXX Ensure it isn't too low - nothing lower1420* XXX than 10 TU1421*/1422if (value < 10)1423value = 10;1424HALDEBUG(ah, HAL_DEBUG_TXQUEUE,1425"%s: defaulting to rdytime = %d uS\n",1426__func__, value);1427OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),1428SM(TU_TO_USEC(value), AR_Q_RDYTIMECFG_INT) |1429AR_Q_RDYTIMECFG_ENA);1430}1431dmisc |= SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,1432AR_D_MISC_ARB_LOCKOUT_CNTRL);1433break;1434case HAL_TX_QUEUE_PSPOLL:1435qmisc |= AR_Q_MISC_CBR_INCR_DIS1;1436break;1437case HAL_TX_QUEUE_UAPSD:1438dmisc |= AR_D_MISC_POST_FR_BKOFF_DIS;1439break;1440default: /* NB: silence compiler */1441break;1442}14431444OS_REG_WRITE(ah, AR_QMISC(q), qmisc);1445OS_REG_WRITE(ah, AR_DMISC(q), dmisc);14461447/* Setup compression scratchpad buffer */1448/*1449* XXX: calling this asynchronously to queue operation can1450* cause unexpected behavior!!!1451*/1452if (qi->tqi_physCompBuf) {1453HALASSERT(qi->tqi_type == HAL_TX_QUEUE_DATA ||1454qi->tqi_type == HAL_TX_QUEUE_UAPSD);1455OS_REG_WRITE(ah, AR_Q_CBBS, (80 + 2*q));1456OS_REG_WRITE(ah, AR_Q_CBBA, qi->tqi_physCompBuf);1457OS_REG_WRITE(ah, AR_Q_CBC, HAL_COMP_BUF_MAX_SIZE/1024);1458OS_REG_WRITE(ah, AR_Q0_MISC + 4*q,1459OS_REG_READ(ah, AR_Q0_MISC + 4*q)1460| AR_Q_MISC_QCU_COMP_EN);1461}14621463/*1464* Always update the secondary interrupt mask registers - this1465* could be a new queue getting enabled in a running system or1466* hw getting re-initialized during a reset!1467*1468* Since we don't differentiate between tx interrupts corresponding1469* to individual queues - secondary tx mask regs are always unmasked;1470* tx interrupts are enabled/disabled for all queues collectively1471* using the primary mask reg1472*/1473if (qi->tqi_qflags & HAL_TXQ_TXOKINT_ENABLE)1474ahp->ah_txOkInterruptMask |= 1 << q;1475else1476ahp->ah_txOkInterruptMask &= ~(1 << q);1477if (qi->tqi_qflags & HAL_TXQ_TXERRINT_ENABLE)1478ahp->ah_txErrInterruptMask |= 1 << q;1479else1480ahp->ah_txErrInterruptMask &= ~(1 << q);1481if (qi->tqi_qflags & HAL_TXQ_TXDESCINT_ENABLE)1482ahp->ah_txDescInterruptMask |= 1 << q;1483else1484ahp->ah_txDescInterruptMask &= ~(1 << q);1485if (qi->tqi_qflags & HAL_TXQ_TXEOLINT_ENABLE)1486ahp->ah_txEolInterruptMask |= 1 << q;1487else1488ahp->ah_txEolInterruptMask &= ~(1 << q);1489if (qi->tqi_qflags & HAL_TXQ_TXURNINT_ENABLE)1490ahp->ah_txUrnInterruptMask |= 1 << q;1491else1492ahp->ah_txUrnInterruptMask &= ~(1 << q);1493setTxQInterrupts(ah, qi);14941495return AH_TRUE;1496}1497#undef TU_TO_USEC149814991500