Path: blob/main/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_misc.c
48525 views
/*1* Copyright (c) 2013 Qualcomm Atheros, Inc.2*3* Permission to use, copy, modify, and/or distribute this software for any4* purpose with or without fee is hereby granted, provided that the above5* copyright notice and this permission notice appear in all copies.6*7* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH8* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY9* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,10* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM11* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR12* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR13* PERFORMANCE OF THIS SOFTWARE.14*/1516#include "opt_ah.h"1718#include "ah.h"19#include "ah_internal.h"20#include "ah_devid.h"21#ifdef AH_DEBUG22#include "ah_desc.h" /* NB: for HAL_PHYERR* */23#endif2425#include "ar9300/ar9300.h"26#include "ar9300/ar9300reg.h"27#include "ar9300/ar9300phy.h"28#include "ar9300/ar9300desc.h"2930static u_int32_t ar9300_read_loc_timer(struct ath_hal *ah);3132void33ar9300_get_hw_hangs(struct ath_hal *ah, hal_hw_hangs_t *hangs)34{35struct ath_hal_9300 *ahp = AH9300(ah);36*hangs = 0;3738if (ar9300_get_capability(ah, HAL_CAP_BB_RIFS_HANG, 0, AH_NULL) == HAL_OK) {39*hangs |= HAL_RIFS_BB_HANG_WAR;40}41if (ar9300_get_capability(ah, HAL_CAP_BB_DFS_HANG, 0, AH_NULL) == HAL_OK) {42*hangs |= HAL_DFS_BB_HANG_WAR;43}44if (ar9300_get_capability(ah, HAL_CAP_BB_RX_CLEAR_STUCK_HANG, 0, AH_NULL)45== HAL_OK)46{47*hangs |= HAL_RX_STUCK_LOW_BB_HANG_WAR;48}49if (ar9300_get_capability(ah, HAL_CAP_MAC_HANG, 0, AH_NULL) == HAL_OK) {50*hangs |= HAL_MAC_HANG_WAR;51}52if (ar9300_get_capability(ah, HAL_CAP_PHYRESTART_CLR_WAR, 0, AH_NULL)53== HAL_OK)54{55*hangs |= HAL_PHYRESTART_CLR_WAR;56}5758ahp->ah_hang_wars = *hangs;59}6061/*62* XXX FreeBSD: the HAL version of ath_hal_mac_usec() knows about63* HT20, HT40, fast-clock, turbo mode, etc.64*/65static u_int66ar9300_mac_to_usec(struct ath_hal *ah, u_int clks)67{68#if 069const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan;7071if (chan && IEEE80211_IS_CHAN_HT40(chan)) {72return (ath_hal_mac_usec(ah, clks) / 2);73} else {74return (ath_hal_mac_usec(ah, clks));75}76#endif77return (ath_hal_mac_usec(ah, clks));78}7980u_int81ar9300_mac_to_clks(struct ath_hal *ah, u_int usecs)82{83#if 084const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan;8586if (chan && IEEE80211_IS_CHAN_HT40(chan)) {87return (ath_hal_mac_clks(ah, usecs) * 2);88} else {89return (ath_hal_mac_clks(ah, usecs));90}91#endif92return (ath_hal_mac_clks(ah, usecs));93}9495void96ar9300_get_mac_address(struct ath_hal *ah, u_int8_t *mac)97{98struct ath_hal_9300 *ahp = AH9300(ah);99100OS_MEMCPY(mac, ahp->ah_macaddr, IEEE80211_ADDR_LEN);101}102103HAL_BOOL104ar9300_set_mac_address(struct ath_hal *ah, const u_int8_t *mac)105{106struct ath_hal_9300 *ahp = AH9300(ah);107108OS_MEMCPY(ahp->ah_macaddr, mac, IEEE80211_ADDR_LEN);109return AH_TRUE;110}111112void113ar9300_get_bss_id_mask(struct ath_hal *ah, u_int8_t *mask)114{115struct ath_hal_9300 *ahp = AH9300(ah);116117OS_MEMCPY(mask, ahp->ah_bssid_mask, IEEE80211_ADDR_LEN);118}119120HAL_BOOL121ar9300_set_bss_id_mask(struct ath_hal *ah, const u_int8_t *mask)122{123struct ath_hal_9300 *ahp = AH9300(ah);124125/* save it since it must be rewritten on reset */126OS_MEMCPY(ahp->ah_bssid_mask, mask, IEEE80211_ADDR_LEN);127128OS_REG_WRITE(ah, AR_BSSMSKL, LE_READ_4(ahp->ah_bssid_mask));129OS_REG_WRITE(ah, AR_BSSMSKU, LE_READ_2(ahp->ah_bssid_mask + 4));130return AH_TRUE;131}132133/*134* Attempt to change the cards operating regulatory domain to the given value135* Returns: A_EINVAL for an unsupported regulatory domain.136* A_HARDWARE for an unwritable EEPROM or bad EEPROM version137*/138HAL_BOOL139ar9300_set_regulatory_domain(struct ath_hal *ah,140u_int16_t reg_domain, HAL_STATUS *status)141{142HAL_STATUS ecode;143144if (AH_PRIVATE(ah)->ah_currentRD == 0) {145AH_PRIVATE(ah)->ah_currentRD = reg_domain;146return AH_TRUE;147}148ecode = HAL_EIO;149150#if 0151bad:152#endif153if (status) {154*status = ecode;155}156return AH_FALSE;157}158159/*160* Return the wireless modes (a,b,g,t) supported by hardware.161*162* This value is what is actually supported by the hardware163* and is unaffected by regulatory/country code settings.164*165*/166u_int167ar9300_get_wireless_modes(struct ath_hal *ah)168{169return AH_PRIVATE(ah)->ah_caps.halWirelessModes;170}171172/*173* Set the interrupt and GPIO values so the ISR can disable RF174* on a switch signal. Assumes GPIO port and interrupt polarity175* are set prior to call.176*/177void178ar9300_enable_rf_kill(struct ath_hal *ah)179{180/* TODO - can this really be above the hal on the GPIO interface for181* TODO - the client only?182*/183struct ath_hal_9300 *ahp = AH9300(ah);184185if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {186/* Check RF kill GPIO before set/clear RFSILENT bits. */187if (ar9300_gpio_get(ah, ahp->ah_gpio_select) == ahp->ah_polarity) {188OS_REG_SET_BIT(ah, AR_HOSTIF_REG(ah, AR_RFSILENT),189AR_RFSILENT_FORCE);190OS_REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);191}192else {193OS_REG_CLR_BIT(ah, AR_HOSTIF_REG(ah, AR_RFSILENT),194AR_RFSILENT_FORCE);195OS_REG_CLR_BIT(ah, AR_PHY_TEST, RFSILENT_BB);196}197}198else {199/* Connect rfsilent_bb_l to baseband */200OS_REG_SET_BIT(ah, AR_HOSTIF_REG(ah, AR_GPIO_INPUT_EN_VAL),201AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);202203/* Set input mux for rfsilent_bb_l to GPIO #0 */204OS_REG_CLR_BIT(ah, AR_HOSTIF_REG(ah, AR_GPIO_INPUT_MUX2),205AR_GPIO_INPUT_MUX2_RFSILENT);206OS_REG_SET_BIT(ah, AR_HOSTIF_REG(ah, AR_GPIO_INPUT_MUX2),207(ahp->ah_gpio_select & 0x0f) << 4);208209/*210* Configure the desired GPIO port for input and211* enable baseband rf silence212*/213ath_hal_gpioCfgInput(ah, ahp->ah_gpio_select);214OS_REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);215}216217/*218* If radio disable switch connection to GPIO bit x is enabled219* program GPIO interrupt.220* If rfkill bit on eeprom is 1, setupeeprommap routine has already221* verified that it is a later version of eeprom, it has a place for222* rfkill bit and it is set to 1, indicating that GPIO bit x hardware223* connection is present.224*/225/*226* RFKill uses polling not interrupt,227* disable interrupt to avoid Eee PC 2.6.21.4 hang up issue228*/229if (ath_hal_hasrfkill_int(ah)) {230if (ahp->ah_gpio_bit == ar9300_gpio_get(ah, ahp->ah_gpio_select)) {231/* switch already closed, set to interrupt upon open */232ar9300_gpio_set_intr(ah, ahp->ah_gpio_select, !ahp->ah_gpio_bit);233} else {234ar9300_gpio_set_intr(ah, ahp->ah_gpio_select, ahp->ah_gpio_bit);235}236}237}238239/*240* Change the LED blinking pattern to correspond to the connectivity241*/242void243ar9300_set_led_state(struct ath_hal *ah, HAL_LED_STATE state)244{245static const u_int32_t ledbits[8] = {246AR_CFG_LED_ASSOC_NONE, /* HAL_LED_RESET */247AR_CFG_LED_ASSOC_PENDING, /* HAL_LED_INIT */248AR_CFG_LED_ASSOC_PENDING, /* HAL_LED_READY */249AR_CFG_LED_ASSOC_PENDING, /* HAL_LED_SCAN */250AR_CFG_LED_ASSOC_PENDING, /* HAL_LED_AUTH */251AR_CFG_LED_ASSOC_ACTIVE, /* HAL_LED_ASSOC */252AR_CFG_LED_ASSOC_ACTIVE, /* HAL_LED_RUN */253AR_CFG_LED_ASSOC_NONE,254};255256OS_REG_RMW_FIELD(ah, AR_CFG_LED, AR_CFG_LED_ASSOC_CTL, ledbits[state]);257}258259/*260* Sets the Power LED on the cardbus without affecting the Network LED.261*/262void263ar9300_set_power_led_state(struct ath_hal *ah, u_int8_t enabled)264{265u_int32_t val;266267val = enabled ? AR_CFG_LED_MODE_POWER_ON : AR_CFG_LED_MODE_POWER_OFF;268OS_REG_RMW_FIELD(ah, AR_CFG_LED, AR_CFG_LED_POWER, val);269}270271/*272* Sets the Network LED on the cardbus without affecting the Power LED.273*/274void275ar9300_set_network_led_state(struct ath_hal *ah, u_int8_t enabled)276{277u_int32_t val;278279val = enabled ? AR_CFG_LED_MODE_NETWORK_ON : AR_CFG_LED_MODE_NETWORK_OFF;280OS_REG_RMW_FIELD(ah, AR_CFG_LED, AR_CFG_LED_NETWORK, val);281}282283/*284* Change association related fields programmed into the hardware.285* Writing a valid BSSID to the hardware effectively enables the hardware286* to synchronize its TSF to the correct beacons and receive frames coming287* from that BSSID. It is called by the SME JOIN operation.288*/289void290ar9300_write_associd(struct ath_hal *ah, const u_int8_t *bssid,291u_int16_t assoc_id)292{293struct ath_hal_9300 *ahp = AH9300(ah);294295/* save bssid and assoc_id for restore on reset */296OS_MEMCPY(ahp->ah_bssid, bssid, IEEE80211_ADDR_LEN);297ahp->ah_assoc_id = assoc_id;298299OS_REG_WRITE(ah, AR_BSS_ID0, LE_READ_4(ahp->ah_bssid));300OS_REG_WRITE(ah, AR_BSS_ID1, LE_READ_2(ahp->ah_bssid + 4) |301((assoc_id & 0x3fff) << AR_BSS_ID1_AID_S));302}303304/*305* Get the current hardware tsf for stamlme306*/307u_int64_t308ar9300_get_tsf64(struct ath_hal *ah)309{310u_int64_t tsf;311312/* XXX sync multi-word read? */313tsf = OS_REG_READ(ah, AR_TSF_U32);314tsf = (tsf << 32) | OS_REG_READ(ah, AR_TSF_L32);315return tsf;316}317318void319ar9300_set_tsf64(struct ath_hal *ah, u_int64_t tsf)320{321OS_REG_WRITE(ah, AR_TSF_L32, (tsf & 0xffffffff));322OS_REG_WRITE(ah, AR_TSF_U32, ((tsf >> 32) & 0xffffffff));323}324325/*326* Get the current hardware tsf for stamlme327*/328u_int32_t329ar9300_get_tsf32(struct ath_hal *ah)330{331return OS_REG_READ(ah, AR_TSF_L32);332}333334u_int32_t335ar9300_get_tsf2_32(struct ath_hal *ah)336{337return OS_REG_READ(ah, AR_TSF2_L32);338}339340/*341* Reset the current hardware tsf for stamlme.342*/343void344ar9300_reset_tsf(struct ath_hal *ah)345{346int count;347348count = 0;349while (OS_REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) {350count++;351if (count > 10) {352HALDEBUG(ah, HAL_DEBUG_RESET,353"%s: AR_SLP32_TSF_WRITE_STATUS limit exceeded\n", __func__);354break;355}356OS_DELAY(10);357}358OS_REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);359}360361/*362* Set or clear hardware basic rate bit363* Set hardware basic rate set if basic rate is found364* and basic rate is equal or less than 2Mbps365*/366void367ar9300_set_basic_rate(struct ath_hal *ah, HAL_RATE_SET *rs)368{369const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan;370u_int32_t reg;371u_int8_t xset;372int i;373374if (chan == AH_NULL || !IEEE80211_IS_CHAN_CCK(chan)) {375return;376}377xset = 0;378for (i = 0; i < rs->rs_count; i++) {379u_int8_t rset = rs->rs_rates[i];380/* Basic rate defined? */381if ((rset & 0x80) && (rset &= 0x7f) >= xset) {382xset = rset;383}384}385/*386* Set the h/w bit to reflect whether or not the basic387* rate is found to be equal or less than 2Mbps.388*/389reg = OS_REG_READ(ah, AR_STA_ID1);390if (xset && xset / 2 <= 2) {391OS_REG_WRITE(ah, AR_STA_ID1, reg | AR_STA_ID1_BASE_RATE_11B);392} else {393OS_REG_WRITE(ah, AR_STA_ID1, reg &~ AR_STA_ID1_BASE_RATE_11B);394}395}396397/*398* Grab a semi-random value from hardware registers - may not399* change often400*/401u_int32_t402ar9300_get_random_seed(struct ath_hal *ah)403{404u_int32_t nf;405406nf = (OS_REG_READ(ah, AR_PHY(25)) >> 19) & 0x1ff;407if (nf & 0x100) {408nf = 0 - ((nf ^ 0x1ff) + 1);409}410return (OS_REG_READ(ah, AR_TSF_U32) ^411OS_REG_READ(ah, AR_TSF_L32) ^ nf);412}413414/*415* Detect if our card is present416*/417HAL_BOOL418ar9300_detect_card_present(struct ath_hal *ah)419{420u_int16_t mac_version, mac_rev;421u_int32_t v;422423/*424* Read the Silicon Revision register and compare that425* to what we read at attach time. If the same, we say426* a card/device is present.427*/428v = OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_SREV)) & AR_SREV_ID;429if (v == 0xFF) {430/* new SREV format */431v = OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_SREV));432/*433* Include 6-bit Chip Type (masked to 0) to differentiate434* from pre-Sowl versions435*/436mac_version = (v & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;437mac_rev = MS(v, AR_SREV_REVISION2);438} else {439mac_version = MS(v, AR_SREV_VERSION);440mac_rev = v & AR_SREV_REVISION;441}442return (AH_PRIVATE(ah)->ah_macVersion == mac_version &&443AH_PRIVATE(ah)->ah_macRev == mac_rev);444}445446/*447* Update MIB Counters448*/449void450ar9300_update_mib_mac_stats(struct ath_hal *ah)451{452struct ath_hal_9300 *ahp = AH9300(ah);453HAL_MIB_STATS* stats = &ahp->ah_stats.ast_mibstats;454455stats->ackrcv_bad += OS_REG_READ(ah, AR_ACK_FAIL);456stats->rts_bad += OS_REG_READ(ah, AR_RTS_FAIL);457stats->fcs_bad += OS_REG_READ(ah, AR_FCS_FAIL);458stats->rts_good += OS_REG_READ(ah, AR_RTS_OK);459stats->beacons += OS_REG_READ(ah, AR_BEACON_CNT);460}461462void463ar9300_get_mib_mac_stats(struct ath_hal *ah, HAL_MIB_STATS* stats)464{465struct ath_hal_9300 *ahp = AH9300(ah);466HAL_MIB_STATS* istats = &ahp->ah_stats.ast_mibstats;467468stats->ackrcv_bad = istats->ackrcv_bad;469stats->rts_bad = istats->rts_bad;470stats->fcs_bad = istats->fcs_bad;471stats->rts_good = istats->rts_good;472stats->beacons = istats->beacons;473}474475/*476* Detect if the HW supports spreading a CCK signal on channel 14477*/478HAL_BOOL479ar9300_is_japan_channel_spread_supported(struct ath_hal *ah)480{481return AH_TRUE;482}483484/*485* Get the rssi of frame curently being received.486*/487u_int32_t488ar9300_get_cur_rssi(struct ath_hal *ah)489{490/* XXX return (OS_REG_READ(ah, AR_PHY_CURRENT_RSSI) & 0xff); */491/* get combined RSSI */492return (OS_REG_READ(ah, AR_PHY_RSSI_3) & 0xff);493}494495#if ATH_GEN_RANDOMNESS496/*497* Get the rssi value from BB on ctl chain0.498*/499u_int32_t500ar9300_get_rssi_chain0(struct ath_hal *ah)501{502/* get ctl chain0 RSSI */503return OS_REG_READ(ah, AR_PHY_RSSI_0) & 0xff;504}505#endif506507u_int508ar9300_get_def_antenna(struct ath_hal *ah)509{510return (OS_REG_READ(ah, AR_DEF_ANTENNA) & 0x7);511}512513/* Setup coverage class */514void515ar9300_set_coverage_class(struct ath_hal *ah, u_int8_t coverageclass, int now)516{517}518519void520ar9300_set_def_antenna(struct ath_hal *ah, u_int antenna)521{522OS_REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));523}524525HAL_BOOL526ar9300_set_antenna_switch(struct ath_hal *ah,527HAL_ANT_SETTING settings, const struct ieee80211_channel *chan,528u_int8_t *tx_chainmask, u_int8_t *rx_chainmask, u_int8_t *antenna_cfgd)529{530struct ath_hal_9300 *ahp = AH9300(ah);531532/*533* Owl does not support diversity or changing antennas.534*535* Instead this API and function are defined differently for AR9300.536* To support Tablet PC's, this interface allows the system537* to dramatically reduce the TX power on a particular chain.538*539* Based on the value of (redefined) diversity_control, the540* reset code will decrease power on chain 0 or chain 1/2.541*542* Based on the value of bit 0 of antenna_switch_swap,543* the mapping between OID call and chain is defined as:544* 0: map A -> 0, B -> 1;545* 1: map A -> 1, B -> 0;546*547* NOTE:548* The devices that use this OID should use a tx_chain_mask and549* tx_chain_select_legacy setting of 5 or 3 if ANTENNA_FIXED_B is550* used in order to ensure an active transmit antenna. This551* API will allow the host to turn off the only transmitting552* antenna to ensure the antenna closest to the user's body is553* powered-down.554*/555/*556* Set antenna control for use during reset sequence by557* ar9300_decrease_chain_power()558*/559ahp->ah_diversity_control = settings;560561return AH_TRUE;562}563564HAL_BOOL565ar9300_is_sleep_after_beacon_broken(struct ath_hal *ah)566{567return AH_TRUE;568}569570HAL_BOOL571ar9300_set_slot_time(struct ath_hal *ah, u_int us)572{573struct ath_hal_9300 *ahp = AH9300(ah);574if (us < HAL_SLOT_TIME_9 || us > ar9300_mac_to_usec(ah, 0xffff)) {575HALDEBUG(ah, HAL_DEBUG_RESET, "%s: bad slot time %u\n", __func__, us);576ahp->ah_slot_time = (u_int) -1; /* restore default handling */577return AH_FALSE;578} else {579/* convert to system clocks */580OS_REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ar9300_mac_to_clks(ah, us));581ahp->ah_slot_time = us;582return AH_TRUE;583}584}585586HAL_BOOL587ar9300_set_ack_timeout(struct ath_hal *ah, u_int us)588{589struct ath_hal_9300 *ahp = AH9300(ah);590591if (us > ar9300_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {592HALDEBUG(ah, HAL_DEBUG_RESET, "%s: bad ack timeout %u\n", __func__, us);593ahp->ah_ack_timeout = (u_int) -1; /* restore default handling */594return AH_FALSE;595} else {596/* convert to system clocks */597OS_REG_RMW_FIELD(ah,598AR_TIME_OUT, AR_TIME_OUT_ACK, ar9300_mac_to_clks(ah, us));599ahp->ah_ack_timeout = us;600return AH_TRUE;601}602}603604u_int605ar9300_get_ack_timeout(struct ath_hal *ah)606{607u_int clks = MS(OS_REG_READ(ah, AR_TIME_OUT), AR_TIME_OUT_ACK);608return ar9300_mac_to_usec(ah, clks); /* convert from system clocks */609}610611HAL_STATUS612ar9300_set_quiet(struct ath_hal *ah, u_int32_t period, u_int32_t duration,613u_int32_t next_start, HAL_QUIET_FLAG flag)614{615#define TU_TO_USEC(_tu) ((_tu) << 10)616HAL_STATUS status = HAL_EIO;617u_int32_t tsf = 0, j, next_start_us = 0;618if (flag & HAL_QUIET_ENABLE) {619for (j = 0; j < 2; j++) {620next_start_us = TU_TO_USEC(next_start);621tsf = OS_REG_READ(ah, AR_TSF_L32);622if ((!next_start) || (flag & HAL_QUIET_ADD_CURRENT_TSF)) {623next_start_us += tsf;624}625if (flag & HAL_QUIET_ADD_SWBA_RESP_TIME) {626next_start_us +=627ah->ah_config.ah_sw_beacon_response_time;628}629OS_REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);630OS_REG_WRITE(ah, AR_QUIET2, SM(duration, AR_QUIET2_QUIET_DUR));631OS_REG_WRITE(ah, AR_QUIET_PERIOD, TU_TO_USEC(period));632OS_REG_WRITE(ah, AR_NEXT_QUIET_TIMER, next_start_us);633OS_REG_SET_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);634if ((OS_REG_READ(ah, AR_TSF_L32) >> 10) == tsf >> 10) {635status = HAL_OK;636break;637}638HALDEBUG(ah, HAL_DEBUG_QUEUE, "%s: TSF have moved "639"while trying to set quiet time TSF: 0x%08x\n", __func__, tsf);640/* TSF shouldn't count twice or reg access is taking forever */641HALASSERT(j < 1);642}643} else {644OS_REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);645status = HAL_OK;646}647648return status;649#undef TU_TO_USEC650}651652//#ifdef ATH_SUPPORT_DFS653void654ar9300_cac_tx_quiet(struct ath_hal *ah, HAL_BOOL enable)655{656uint32_t reg1, reg2;657658reg1 = OS_REG_READ(ah, AR_MAC_PCU_OFFSET(MAC_PCU_MISC_MODE));659reg2 = OS_REG_READ(ah, AR_MAC_PCU_OFFSET(MAC_PCU_QUIET_TIME_1));660AH9300(ah)->ah_cac_quiet_enabled = enable;661662if (enable) {663OS_REG_WRITE(ah, AR_MAC_PCU_OFFSET(MAC_PCU_MISC_MODE),664reg1 | AR_PCU_FORCE_QUIET_COLL);665OS_REG_WRITE(ah, AR_MAC_PCU_OFFSET(MAC_PCU_QUIET_TIME_1),666reg2 & ~AR_QUIET1_QUIET_ACK_CTS_ENABLE);667} else {668OS_REG_WRITE(ah, AR_MAC_PCU_OFFSET(MAC_PCU_MISC_MODE),669reg1 & ~AR_PCU_FORCE_QUIET_COLL);670OS_REG_WRITE(ah, AR_MAC_PCU_OFFSET(MAC_PCU_QUIET_TIME_1),671reg2 | AR_QUIET1_QUIET_ACK_CTS_ENABLE);672}673}674//#endif /* ATH_SUPPORT_DFS */675676void677ar9300_set_pcu_config(struct ath_hal *ah)678{679ar9300_set_operating_mode(ah, AH_PRIVATE(ah)->ah_opmode);680}681682HAL_STATUS683ar9300_get_capability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,684u_int32_t capability, u_int32_t *result)685{686struct ath_hal_9300 *ahp = AH9300(ah);687const HAL_CAPABILITIES *p_cap = &AH_PRIVATE(ah)->ah_caps;688struct ar9300_ani_state *ani;689690switch (type) {691case HAL_CAP_CIPHER: /* cipher handled in hardware */692switch (capability) {693case HAL_CIPHER_AES_CCM:694case HAL_CIPHER_AES_OCB:695case HAL_CIPHER_TKIP:696case HAL_CIPHER_WEP:697case HAL_CIPHER_MIC:698case HAL_CIPHER_CLR:699return HAL_OK;700default:701return HAL_ENOTSUPP;702}703case HAL_CAP_TKIP_MIC: /* handle TKIP MIC in hardware */704switch (capability) {705case 0: /* hardware capability */706return HAL_OK;707case 1:708return (ahp->ah_sta_id1_defaults &709AR_STA_ID1_CRPT_MIC_ENABLE) ? HAL_OK : HAL_ENXIO;710default:711return HAL_ENOTSUPP;712}713case HAL_CAP_TKIP_SPLIT: /* hardware TKIP uses split keys */714switch (capability) {715case 0: /* hardware capability */716return p_cap->halTkipMicTxRxKeySupport ? HAL_ENXIO : HAL_OK;717case 1: /* current setting */718return (ahp->ah_misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?719HAL_ENXIO : HAL_OK;720default:721return HAL_ENOTSUPP;722}723case HAL_CAP_WME_TKIPMIC:724/* hardware can do TKIP MIC when WMM is turned on */725return HAL_OK;726case HAL_CAP_PHYCOUNTERS: /* hardware PHY error counters */727return HAL_OK;728case HAL_CAP_DIVERSITY: /* hardware supports fast diversity */729switch (capability) {730case 0: /* hardware capability */731return HAL_OK;732case 1: /* current setting */733return (OS_REG_READ(ah, AR_PHY_CCK_DETECT) &734AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?735HAL_OK : HAL_ENXIO;736}737return HAL_EINVAL;738case HAL_CAP_TPC:739switch (capability) {740case 0: /* hardware capability */741return HAL_OK;742case 1:743return ah->ah_config.ath_hal_desc_tpc ?744HAL_OK : HAL_ENXIO;745}746return HAL_OK;747case HAL_CAP_PHYDIAG: /* radar pulse detection capability */748return HAL_OK;749case HAL_CAP_MCAST_KEYSRCH: /* multicast frame keycache search */750switch (capability) {751case 0: /* hardware capability */752return HAL_OK;753case 1:754if (OS_REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {755/*756* Owl and Merlin have problems in mcast key search.757* Disable this cap. in Ad-hoc mode. see Bug 25776 and758* 26802759*/760return HAL_ENXIO;761} else {762return (ahp->ah_sta_id1_defaults &763AR_STA_ID1_MCAST_KSRCH) ? HAL_OK : HAL_ENXIO;764}765}766return HAL_EINVAL;767case HAL_CAP_TSF_ADJUST: /* hardware has beacon tsf adjust */768switch (capability) {769case 0: /* hardware capability */770return p_cap->halTsfAddSupport ? HAL_OK : HAL_ENOTSUPP;771case 1:772return (ahp->ah_misc_mode & AR_PCU_TX_ADD_TSF) ?773HAL_OK : HAL_ENXIO;774}775return HAL_EINVAL;776case HAL_CAP_RFSILENT: /* rfsilent support */777if (capability == 3) { /* rfkill interrupt */778/*779* XXX: Interrupt-based notification of RF Kill state780* changes not working yet. Report that this feature781* is not supported so that polling is used instead.782*/783return (HAL_ENOTSUPP);784}785return ath_hal_getcapability(ah, type, capability, result);786case HAL_CAP_4ADDR_AGGR:787return HAL_OK;788case HAL_CAP_BB_RIFS_HANG:789return HAL_ENOTSUPP;790case HAL_CAP_BB_DFS_HANG:791return HAL_ENOTSUPP;792case HAL_CAP_BB_RX_CLEAR_STUCK_HANG:793/* Track chips that are known to have BB hangs related794* to rx_clear stuck low.795*/796return HAL_ENOTSUPP;797case HAL_CAP_MAC_HANG:798/* Track chips that are known to have MAC hangs.799*/800return HAL_OK;801case HAL_CAP_RIFS_RX_ENABLED:802/* Is RIFS RX currently enabled */803return (ahp->ah_rifs_enabled == AH_TRUE) ? HAL_OK : HAL_ENOTSUPP;804#if 0805case HAL_CAP_ANT_CFG_2GHZ:806*result = p_cap->halNumAntCfg2Ghz;807return HAL_OK;808case HAL_CAP_ANT_CFG_5GHZ:809*result = p_cap->halNumAntCfg5Ghz;810return HAL_OK;811case HAL_CAP_RX_STBC:812*result = p_cap->hal_rx_stbc_support;813return HAL_OK;814case HAL_CAP_TX_STBC:815*result = p_cap->hal_tx_stbc_support;816return HAL_OK;817#endif818case HAL_CAP_LDPC:819*result = p_cap->halLDPCSupport;820return HAL_OK;821case HAL_CAP_DYNAMIC_SMPS:822return HAL_OK;823case HAL_CAP_DS:824return (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah) || AR_SREV_APHRODITE(ah) ||825(p_cap->halTxChainMask & 0x3) != 0x3 ||826(p_cap->halRxChainMask & 0x3) != 0x3) ?827HAL_ENOTSUPP : HAL_OK;828case HAL_CAP_TS:829return (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah) || AR_SREV_APHRODITE(ah) ||830(p_cap->halTxChainMask & 0x7) != 0x7 ||831(p_cap->halRxChainMask & 0x7) != 0x7) ?832HAL_ENOTSUPP : HAL_OK;833case HAL_CAP_OL_PWRCTRL:834return (ar9300_eeprom_get(ahp, EEP_OL_PWRCTRL)) ?835HAL_OK : HAL_ENOTSUPP;836case HAL_CAP_CRDC:837#if ATH_SUPPORT_CRDC838return (AR_SREV_WASP(ah) &&839ah->ah_config.ath_hal_crdc_enable) ?840HAL_OK : HAL_ENOTSUPP;841#else842return HAL_ENOTSUPP;843#endif844#if 0845case HAL_CAP_MAX_WEP_TKIP_HT20_TX_RATEKBPS:846*result = (u_int32_t)(-1);847return HAL_OK;848case HAL_CAP_MAX_WEP_TKIP_HT40_TX_RATEKBPS:849*result = (u_int32_t)(-1);850return HAL_OK;851#endif852case HAL_CAP_BB_PANIC_WATCHDOG:853return HAL_OK;854case HAL_CAP_PHYRESTART_CLR_WAR:855if ((AH_PRIVATE((ah))->ah_macVersion == AR_SREV_VERSION_OSPREY) &&856(AH_PRIVATE((ah))->ah_macRev < AR_SREV_REVISION_AR9580_10))857{858return HAL_OK;859}860else861{862return HAL_ENOTSUPP;863}864case HAL_CAP_ENTERPRISE_MODE:865*result = ahp->ah_enterprise_mode >> 16;866/*867* WAR for EV 77658 - Add delimiters to first sub-frame when using868* RTS/CTS with aggregation and non-enterprise Osprey.869*870* Bug fixed in AR9580/Peacock, Wasp1.1 and later871*/872if ((ahp->ah_enterprise_mode & AR_ENT_OTP_MIN_PKT_SIZE_DISABLE) &&873!AR_SREV_AR9580_10_OR_LATER(ah) && (!AR_SREV_WASP(ah) ||874AR_SREV_WASP_10(ah))) {875*result |= AH_ENT_RTSCTS_DELIM_WAR;876}877return HAL_OK;878case HAL_CAP_LDPCWAR:879/* WAR for RIFS+LDPC issue is required for all chips currently880* supported by ar9300 HAL.881*/882return HAL_OK;883case HAL_CAP_ENABLE_APM:884*result = p_cap->halApmEnable;885return HAL_OK;886case HAL_CAP_PCIE_LCR_EXTSYNC_EN:887return (p_cap->hal_pcie_lcr_extsync_en == AH_TRUE) ? HAL_OK : HAL_ENOTSUPP;888case HAL_CAP_PCIE_LCR_OFFSET:889*result = p_cap->hal_pcie_lcr_offset;890return HAL_OK;891case HAL_CAP_SMARTANTENNA:892/* FIXME A request is pending with h/w team to add feature bit in893* caldata to detect if board has smart antenna or not, once added894* we need to fix his piece of code to read and return value without895* any compile flags896*/897#if UMAC_SUPPORT_SMARTANTENNA898/* enable smart antenna for Peacock, Wasp and scorpion899for future chips need to modify */900if (AR_SREV_AR9580_10(ah) || (AR_SREV_WASP(ah)) || AR_SREV_SCORPION(ah)) {901return HAL_OK;902} else {903return HAL_ENOTSUPP;904}905#else906return HAL_ENOTSUPP;907#endif908909#ifdef ATH_TRAFFIC_FAST_RECOVER910case HAL_CAP_TRAFFIC_FAST_RECOVER:911if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah) || AR_SREV_WASP_11(ah)) {912return HAL_OK;913} else {914return HAL_ENOTSUPP;915}916#endif917918/* FreeBSD ANI */919case HAL_CAP_INTMIT: /* interference mitigation */920switch (capability) {921case HAL_CAP_INTMIT_PRESENT: /* hardware capability */922return HAL_OK;923case HAL_CAP_INTMIT_ENABLE:924return (ahp->ah_proc_phy_err & HAL_PROCESS_ANI) ?925HAL_OK : HAL_ENXIO;926case HAL_CAP_INTMIT_NOISE_IMMUNITY_LEVEL:927case HAL_CAP_INTMIT_OFDM_WEAK_SIGNAL_LEVEL:928// case HAL_CAP_INTMIT_CCK_WEAK_SIGNAL_THR:929case HAL_CAP_INTMIT_FIRSTEP_LEVEL:930case HAL_CAP_INTMIT_SPUR_IMMUNITY_LEVEL:931ani = ar9300_ani_get_current_state(ah);932if (ani == AH_NULL)933return HAL_ENXIO;934switch (capability) {935/* XXX AR9300 HAL has OFDM/CCK noise immunity level params? */936case 2: *result = ani->ofdm_noise_immunity_level; break;937case 3: *result = !ani->ofdm_weak_sig_detect_off; break;938// case 4: *result = ani->cck_weak_sig_threshold; break;939case 5: *result = ani->firstep_level; break;940case 6: *result = ani->spur_immunity_level; break;941}942return HAL_OK;943}944return HAL_EINVAL;945case HAL_CAP_ENFORCE_TXOP:946if (capability == 0)947return (HAL_OK);948if (capability != 1)949return (HAL_ENOTSUPP);950(*result) = !! (ahp->ah_misc_mode & AR_PCU_TXOP_TBTT_LIMIT_ENA);951return (HAL_OK);952case HAL_CAP_TOA_LOCATIONING:953if (capability == 0)954return HAL_OK;955if (capability == 2) {956*result = ar9300_read_loc_timer(ah);957return (HAL_OK);958}959return HAL_ENOTSUPP;960default:961return ath_hal_getcapability(ah, type, capability, result);962}963}964965HAL_BOOL966ar9300_set_capability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,967u_int32_t capability, u_int32_t setting, HAL_STATUS *status)968{969struct ath_hal_9300 *ahp = AH9300(ah);970HAL_CAPABILITIES *p_cap = &AH_PRIVATE(ah)->ah_caps;971u_int32_t v;972973switch (type) {974case HAL_CAP_TKIP_SPLIT: /* hardware TKIP uses split keys */975if (! p_cap->halTkipMicTxRxKeySupport)976return AH_FALSE;977978if (setting)979ahp->ah_misc_mode &= ~AR_PCU_MIC_NEW_LOC_ENA;980else981ahp->ah_misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;982983OS_REG_WRITE(ah, AR_PCU_MISC, ahp->ah_misc_mode);984return AH_TRUE;985986case HAL_CAP_TKIP_MIC: /* handle TKIP MIC in hardware */987if (setting) {988ahp->ah_sta_id1_defaults |= AR_STA_ID1_CRPT_MIC_ENABLE;989} else {990ahp->ah_sta_id1_defaults &= ~AR_STA_ID1_CRPT_MIC_ENABLE;991}992return AH_TRUE;993case HAL_CAP_DIVERSITY:994v = OS_REG_READ(ah, AR_PHY_CCK_DETECT);995if (setting) {996v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;997} else {998v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;999}1000OS_REG_WRITE(ah, AR_PHY_CCK_DETECT, v);1001return AH_TRUE;1002case HAL_CAP_DIAG: /* hardware diagnostic support */1003/*1004* NB: could split this up into virtual capabilities,1005* (e.g. 1 => ACK, 2 => CTS, etc.) but it hardly1006* seems worth the additional complexity.1007*/1008#ifdef AH_DEBUG1009AH_PRIVATE(ah)->ah_diagreg = setting;1010#else1011AH_PRIVATE(ah)->ah_diagreg = setting & 0x6; /* ACK+CTS */1012#endif1013OS_REG_WRITE(ah, AR_DIAG_SW, AH_PRIVATE(ah)->ah_diagreg);1014return AH_TRUE;1015case HAL_CAP_TPC:1016ah->ah_config.ath_hal_desc_tpc = (setting != 0);1017return AH_TRUE;1018case HAL_CAP_MCAST_KEYSRCH: /* multicast frame keycache search */1019if (setting) {1020ahp->ah_sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;1021} else {1022ahp->ah_sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;1023}1024return AH_TRUE;1025case HAL_CAP_TSF_ADJUST: /* hardware has beacon tsf adjust */1026if (p_cap->halTsfAddSupport) {1027if (setting) {1028ahp->ah_misc_mode |= AR_PCU_TX_ADD_TSF;1029} else {1030ahp->ah_misc_mode &= ~AR_PCU_TX_ADD_TSF;1031}1032return AH_TRUE;1033}1034return AH_FALSE;10351036/* FreeBSD interrupt mitigation / ANI */1037case HAL_CAP_INTMIT: { /* interference mitigation */1038/* This maps the public ANI commands to the internal ANI commands */1039/* Private: HAL_ANI_CMD; Public: HAL_CAP_INTMIT_CMD */1040static const HAL_ANI_CMD cmds[] = {1041HAL_ANI_PRESENT,1042HAL_ANI_MODE,1043HAL_ANI_NOISE_IMMUNITY_LEVEL,1044HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION,1045HAL_ANI_CCK_WEAK_SIGNAL_THR,1046HAL_ANI_FIRSTEP_LEVEL,1047HAL_ANI_SPUR_IMMUNITY_LEVEL,1048};1049#define N(a) (sizeof(a) / sizeof(a[0]))1050return capability < N(cmds) ?1051ar9300_ani_control(ah, cmds[capability], setting) :1052AH_FALSE;1053#undef N1054}10551056case HAL_CAP_RXBUFSIZE: /* set MAC receive buffer size */1057ahp->rx_buf_size = setting & AR_DATABUF_MASK;1058OS_REG_WRITE(ah, AR_DATABUF, ahp->rx_buf_size);1059return AH_TRUE;10601061case HAL_CAP_ENFORCE_TXOP:1062if (capability != 1)1063return AH_FALSE;1064if (setting) {1065ahp->ah_misc_mode |= AR_PCU_TXOP_TBTT_LIMIT_ENA;1066OS_REG_SET_BIT(ah, AR_PCU_MISC, AR_PCU_TXOP_TBTT_LIMIT_ENA);1067} else {1068ahp->ah_misc_mode &= ~AR_PCU_TXOP_TBTT_LIMIT_ENA;1069OS_REG_CLR_BIT(ah, AR_PCU_MISC, AR_PCU_TXOP_TBTT_LIMIT_ENA);1070}1071return AH_TRUE;10721073case HAL_CAP_TOA_LOCATIONING:1074if (capability == 0)1075return AH_TRUE;1076if (capability == 1) {1077ar9300_update_loc_ctl_reg(ah, setting);1078return AH_TRUE;1079}1080return AH_FALSE;10811082#define owl_get_ntxchains(_txchainmask) \1083(((_txchainmask >> 2) & 1) + ((_txchainmask >> 1) & 1) + \1084(_txchainmask & 1))10851086case HAL_CAP_RX_CHAINMASK:1087setting &= ar9300_eeprom_get(ahp, EEP_RX_MASK);1088p_cap->halRxChainMask = setting;1089p_cap->halRxStreams = owl_get_ntxchains(setting);1090if (p_cap->halRxStreams > 3)1091p_cap->halRxStreams = 3;1092else if (p_cap->halRxStreams < 1)1093p_cap->halRxStreams = 1;1094return AH_TRUE;10951096case HAL_CAP_TX_CHAINMASK:1097setting &= ar9300_eeprom_get(ahp, EEP_TX_MASK);1098p_cap->halTxChainMask = setting;1099p_cap->halTxStreams = owl_get_ntxchains(setting);1100if (p_cap->halTxStreams > 3)1101p_cap->halTxStreams = 3;1102else if (p_cap->halTxStreams < 1)1103p_cap->halTxStreams = 1;1104return AH_TRUE;11051106#undef owl_get_ntxchains11071108/* fall thru... */1109default:1110return ath_hal_setcapability(ah, type, capability, setting, status);1111}1112}11131114#ifdef AH_DEBUG1115static void1116ar9300_print_reg(struct ath_hal *ah, u_int32_t args)1117{1118u_int32_t i = 0;11191120/* Read 0x80d0 to trigger pcie analyzer */1121HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1122"0x%04x 0x%08x\n", 0x80d0, OS_REG_READ(ah, 0x80d0));11231124if (args & HAL_DIAG_PRINT_REG_COUNTER) {1125struct ath_hal_9300 *ahp = AH9300(ah);1126u_int32_t tf, rf, rc, cc;11271128tf = OS_REG_READ(ah, AR_TFCNT);1129rf = OS_REG_READ(ah, AR_RFCNT);1130rc = OS_REG_READ(ah, AR_RCCNT);1131cc = OS_REG_READ(ah, AR_CCCNT);11321133HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1134"AR_TFCNT Diff= 0x%x\n", tf - ahp->last_tf);1135HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1136"AR_RFCNT Diff= 0x%x\n", rf - ahp->last_rf);1137HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1138"AR_RCCNT Diff= 0x%x\n", rc - ahp->last_rc);1139HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1140"AR_CCCNT Diff= 0x%x\n", cc - ahp->last_cc);11411142ahp->last_tf = tf;1143ahp->last_rf = rf;1144ahp->last_rc = rc;1145ahp->last_cc = cc;11461147HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1148"DMADBG0 = 0x%x\n", OS_REG_READ(ah, AR_DMADBG_0));1149HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1150"DMADBG1 = 0x%x\n", OS_REG_READ(ah, AR_DMADBG_1));1151HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1152"DMADBG2 = 0x%x\n", OS_REG_READ(ah, AR_DMADBG_2));1153HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1154"DMADBG3 = 0x%x\n", OS_REG_READ(ah, AR_DMADBG_3));1155HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1156"DMADBG4 = 0x%x\n", OS_REG_READ(ah, AR_DMADBG_4));1157HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1158"DMADBG5 = 0x%x\n", OS_REG_READ(ah, AR_DMADBG_5));1159HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1160"DMADBG6 = 0x%x\n", OS_REG_READ(ah, AR_DMADBG_6));1161HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1162"DMADBG7 = 0x%x\n", OS_REG_READ(ah, AR_DMADBG_7));1163}11641165if (args & HAL_DIAG_PRINT_REG_ALL) {1166for (i = 0x8; i <= 0xB8; i += sizeof(u_int32_t)) {1167HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1168i, OS_REG_READ(ah, i));1169}11701171for (i = 0x800; i <= (0x800 + (10 << 2)); i += sizeof(u_int32_t)) {1172HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1173i, OS_REG_READ(ah, i));1174}11751176HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1177"0x%04x 0x%08x\n", 0x840, OS_REG_READ(ah, i));11781179HALDEBUG(ah, HAL_DEBUG_PRINT_REG,1180"0x%04x 0x%08x\n", 0x880, OS_REG_READ(ah, i));11811182for (i = 0x8C0; i <= (0x8C0 + (10 << 2)); i += sizeof(u_int32_t)) {1183HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1184i, OS_REG_READ(ah, i));1185}11861187for (i = 0x1F00; i <= 0x1F04; i += sizeof(u_int32_t)) {1188HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1189i, OS_REG_READ(ah, i));1190}11911192for (i = 0x4000; i <= 0x408C; i += sizeof(u_int32_t)) {1193HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1194i, OS_REG_READ(ah, i));1195}11961197for (i = 0x5000; i <= 0x503C; i += sizeof(u_int32_t)) {1198HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1199i, OS_REG_READ(ah, i));1200}12011202for (i = 0x7040; i <= 0x7058; i += sizeof(u_int32_t)) {1203HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1204i, OS_REG_READ(ah, i));1205}12061207for (i = 0x8000; i <= 0x8098; i += sizeof(u_int32_t)) {1208HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1209i, OS_REG_READ(ah, i));1210}12111212for (i = 0x80D4; i <= 0x8200; i += sizeof(u_int32_t)) {1213HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1214i, OS_REG_READ(ah, i));1215}12161217for (i = 0x8240; i <= 0x97FC; i += sizeof(u_int32_t)) {1218HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1219i, OS_REG_READ(ah, i));1220}12211222for (i = 0x9800; i <= 0x99f0; i += sizeof(u_int32_t)) {1223HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1224i, OS_REG_READ(ah, i));1225}12261227for (i = 0x9c10; i <= 0x9CFC; i += sizeof(u_int32_t)) {1228HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1229i, OS_REG_READ(ah, i));1230}12311232for (i = 0xA200; i <= 0xA26C; i += sizeof(u_int32_t)) {1233HALDEBUG(ah, HAL_DEBUG_PRINT_REG, "0x%04x 0x%08x\n",1234i, OS_REG_READ(ah, i));1235}1236}1237}1238#endif12391240HAL_BOOL1241ar9300_get_diag_state(struct ath_hal *ah, int request,1242const void *args, u_int32_t argsize,1243void **result, u_int32_t *resultsize)1244{1245struct ath_hal_9300 *ahp = AH9300(ah);1246struct ar9300_ani_state *ani;12471248(void) ahp;1249if (ath_hal_getdiagstate(ah, request, args, argsize, result, resultsize)) {1250return AH_TRUE;1251}1252switch (request) {1253#ifdef AH_PRIVATE_DIAG1254case HAL_DIAG_EEPROM:1255*result = &ahp->ah_eeprom;1256*resultsize = sizeof(ar9300_eeprom_t);1257return AH_TRUE;12581259#if 0 /* XXX - TODO */1260case HAL_DIAG_EEPROM_EXP_11A:1261case HAL_DIAG_EEPROM_EXP_11B:1262case HAL_DIAG_EEPROM_EXP_11G:1263pe = &ahp->ah_mode_power_array2133[request - HAL_DIAG_EEPROM_EXP_11A];1264*result = pe->p_channels;1265*resultsize = (*result == AH_NULL) ? 0 :1266roundup(sizeof(u_int16_t) * pe->num_channels,1267sizeof(u_int32_t)) +1268sizeof(EXPN_DATA_PER_CHANNEL_2133) * pe->num_channels;1269return AH_TRUE;1270#endif1271case HAL_DIAG_RFGAIN:1272*result = &ahp->ah_gain_values;1273*resultsize = sizeof(GAIN_VALUES);1274return AH_TRUE;1275case HAL_DIAG_RFGAIN_CURSTEP:1276*result = (void *) ahp->ah_gain_values.curr_step;1277*resultsize = (*result == AH_NULL) ?12780 : sizeof(GAIN_OPTIMIZATION_STEP);1279return AH_TRUE;1280#if 0 /* XXX - TODO */1281case HAL_DIAG_PCDAC:1282*result = ahp->ah_pcdac_table;1283*resultsize = ahp->ah_pcdac_table_size;1284return AH_TRUE;1285#endif1286case HAL_DIAG_ANI_CURRENT:12871288ani = ar9300_ani_get_current_state(ah);1289if (ani == AH_NULL)1290return AH_FALSE;1291/* Convert ar9300 HAL to FreeBSD HAL ANI state */1292bzero(&ahp->ext_ani_state, sizeof(ahp->ext_ani_state));1293ahp->ext_ani_state.noiseImmunityLevel = ani->ofdm_noise_immunity_level;1294ahp->ext_ani_state.spurImmunityLevel = ani->spur_immunity_level;1295ahp->ext_ani_state.firstepLevel = ani->firstep_level;1296ahp->ext_ani_state.ofdmWeakSigDetectOff = ani->ofdm_weak_sig_detect_off;1297ahp->ext_ani_state.mrcCck = !! ani->mrc_cck_off;1298ahp->ext_ani_state.cckNoiseImmunityLevel = ani->cck_noise_immunity_level;12991300ahp->ext_ani_state.listenTime = ani->listen_time;13011302*result = &ahp->ext_ani_state;1303*resultsize = sizeof(ahp->ext_ani_state);1304#if 01305*result = ar9300_ani_get_current_state(ah);1306*resultsize = (*result == AH_NULL) ?13070 : sizeof(struct ar9300_ani_state);1308#endif1309return AH_TRUE;1310case HAL_DIAG_ANI_STATS:1311*result = ar9300_ani_get_current_stats(ah);1312*resultsize = (*result == AH_NULL) ?13130 : sizeof(HAL_ANI_STATS);1314return AH_TRUE;1315case HAL_DIAG_ANI_CMD:1316{1317HAL_ANI_CMD savefunc = ahp->ah_ani_function;1318if (argsize != 2*sizeof(u_int32_t)) {1319return AH_FALSE;1320}1321/* temporarly allow all functions so we can override */1322ahp->ah_ani_function = HAL_ANI_ALL;1323ar9300_ani_control(1324ah, ((const u_int32_t *)args)[0], ((const u_int32_t *)args)[1]);1325ahp->ah_ani_function = savefunc;1326return AH_TRUE;1327}1328#if 01329case HAL_DIAG_TXCONT:1330/*AR9300_CONTTXMODE(ah, (struct ath_desc *)args, argsize );*/1331return AH_TRUE;1332#endif /* 0 */1333#endif /* AH_PRIVATE_DIAG */1334case HAL_DIAG_CHANNELS:1335#if 01336*result = &(ahp->ah_priv.ah_channels[0]);1337*resultsize =1338sizeof(ahp->ah_priv.ah_channels[0]) * ahp->ah_priv.priv.ah_nchan;1339#endif1340return AH_TRUE;1341#ifdef AH_DEBUG1342case HAL_DIAG_PRINT_REG:1343ar9300_print_reg(ah, *((const u_int32_t *)args));1344return AH_TRUE;1345#endif1346default:1347break;1348}13491350return AH_FALSE;1351}13521353void1354ar9300_dma_reg_dump(struct ath_hal *ah)1355{1356#ifdef AH_DEBUG1357#define NUM_DMA_DEBUG_REGS 81358#define NUM_QUEUES 1013591360u_int32_t val[NUM_DMA_DEBUG_REGS];1361int qcu_offset = 0, dcu_offset = 0;1362u_int32_t *qcu_base = &val[0], *dcu_base = &val[4], reg;1363int i, j, k;1364int16_t nfarray[HAL_NUM_NF_READINGS];1365#ifdef ATH_NF_PER_CHAN1366HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, AH_PRIVATE(ah)->ah_curchan);1367#endif /* ATH_NF_PER_CHAN */1368HAL_NFCAL_HIST_FULL *h = AH_HOME_CHAN_NFCAL_HIST(ah, ichan);13691370/* selecting DMA OBS 8 */1371OS_REG_WRITE(ah, AR_MACMISC,1372((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |1373(AR_MACMISC_MISC_OBS_BUS_1 << AR_MACMISC_MISC_OBS_BUS_MSB_S)));13741375ath_hal_printf(ah, "Raw DMA Debug values:\n");1376for (i = 0; i < NUM_DMA_DEBUG_REGS; i++) {1377if (i % 4 == 0) {1378ath_hal_printf(ah, "\n");1379}13801381val[i] = OS_REG_READ(ah, AR_DMADBG_0 + (i * sizeof(u_int32_t)));1382ath_hal_printf(ah, "%d: %08x ", i, val[i]);1383}13841385ath_hal_printf(ah, "\n\n");1386ath_hal_printf(ah, "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");13871388for (i = 0; i < NUM_QUEUES; i++, qcu_offset += 4, dcu_offset += 5) {1389if (i == 8) {1390/* only 8 QCU entries in val[0] */1391qcu_offset = 0;1392qcu_base++;1393}13941395if (i == 6) {1396/* only 6 DCU entries in val[4] */1397dcu_offset = 0;1398dcu_base++;1399}14001401ath_hal_printf(ah,1402"%2d %2x %1x %2x %2x\n",1403i,1404(*qcu_base & (0x7 << qcu_offset)) >> qcu_offset,1405(*qcu_base & (0x8 << qcu_offset)) >> (qcu_offset + 3),1406val[2] & (0x7 << (i * 3)) >> (i * 3),1407(*dcu_base & (0x1f << dcu_offset)) >> dcu_offset);1408}14091410ath_hal_printf(ah, "\n");1411ath_hal_printf(ah,1412"qcu_stitch state: %2x qcu_fetch state: %2x\n",1413(val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);1414ath_hal_printf(ah,1415"qcu_complete state: %2x dcu_complete state: %2x\n",1416(val[3] & 0x1c000000) >> 26, (val[6] & 0x3));1417ath_hal_printf(ah,1418"dcu_arb state: %2x dcu_fp state: %2x\n",1419(val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);1420ath_hal_printf(ah,1421"chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",1422(val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);1423ath_hal_printf(ah,1424"txfifo_valid_0: %1d txfifo_valid_1: %1d\n",1425(val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);1426ath_hal_printf(ah,1427"txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",1428(val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);1429ath_hal_printf(ah, "pcu observe 0x%x \n", OS_REG_READ(ah, AR_OBS_BUS_1));1430ath_hal_printf(ah, "AR_CR 0x%x \n", OS_REG_READ(ah, AR_CR));14311432ar9300_upload_noise_floor(ah, 1, nfarray);1433ath_hal_printf(ah, "2G:\n");1434ath_hal_printf(ah, "Min CCA Out:\n");1435ath_hal_printf(ah, "\t\tChain 0\t\tChain 1\t\tChain 2\n");1436ath_hal_printf(ah, "Control:\t%8d\t%8d\t%8d\n",1437nfarray[0], nfarray[1], nfarray[2]);1438ath_hal_printf(ah, "Extension:\t%8d\t%8d\t%8d\n\n",1439nfarray[3], nfarray[4], nfarray[5]);14401441ar9300_upload_noise_floor(ah, 0, nfarray);1442ath_hal_printf(ah, "5G:\n");1443ath_hal_printf(ah, "Min CCA Out:\n");1444ath_hal_printf(ah, "\t\tChain 0\t\tChain 1\t\tChain 2\n");1445ath_hal_printf(ah, "Control:\t%8d\t%8d\t%8d\n",1446nfarray[0], nfarray[1], nfarray[2]);1447ath_hal_printf(ah, "Extension:\t%8d\t%8d\t%8d\n\n",1448nfarray[3], nfarray[4], nfarray[5]);14491450for (i = 0; i < HAL_NUM_NF_READINGS; i++) {1451ath_hal_printf(ah, "%s Chain %d NF History:\n",1452((i < 3) ? "Control " : "Extension "), i%3);1453for (j = 0, k = h->base.curr_index;1454j < HAL_NF_CAL_HIST_LEN_FULL;1455j++, k++) {1456ath_hal_printf(ah, "Element %d: %d\n",1457j, h->nf_cal_buffer[k % HAL_NF_CAL_HIST_LEN_FULL][i]);1458}1459ath_hal_printf(ah, "Last Programmed NF: %d\n\n", h->base.priv_nf[i]);1460}14611462reg = OS_REG_READ(ah, AR_PHY_FIND_SIG_LOW);1463ath_hal_printf(ah, "FIRStep Low = 0x%x (%d)\n",1464MS(reg, AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW),1465MS(reg, AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW));1466reg = OS_REG_READ(ah, AR_PHY_DESIRED_SZ);1467ath_hal_printf(ah, "Total Desired = 0x%x (%d)\n",1468MS(reg, AR_PHY_DESIRED_SZ_TOT_DES),1469MS(reg, AR_PHY_DESIRED_SZ_TOT_DES));1470ath_hal_printf(ah, "ADC Desired = 0x%x (%d)\n",1471MS(reg, AR_PHY_DESIRED_SZ_ADC),1472MS(reg, AR_PHY_DESIRED_SZ_ADC));1473reg = OS_REG_READ(ah, AR_PHY_FIND_SIG);1474ath_hal_printf(ah, "FIRStep = 0x%x (%d)\n",1475MS(reg, AR_PHY_FIND_SIG_FIRSTEP),1476MS(reg, AR_PHY_FIND_SIG_FIRSTEP));1477reg = OS_REG_READ(ah, AR_PHY_AGC);1478ath_hal_printf(ah, "Coarse High = 0x%x (%d)\n",1479MS(reg, AR_PHY_AGC_COARSE_HIGH),1480MS(reg, AR_PHY_AGC_COARSE_HIGH));1481ath_hal_printf(ah, "Coarse Low = 0x%x (%d)\n",1482MS(reg, AR_PHY_AGC_COARSE_LOW),1483MS(reg, AR_PHY_AGC_COARSE_LOW));1484ath_hal_printf(ah, "Coarse Power Constant = 0x%x (%d)\n",1485MS(reg, AR_PHY_AGC_COARSE_PWR_CONST),1486MS(reg, AR_PHY_AGC_COARSE_PWR_CONST));1487reg = OS_REG_READ(ah, AR_PHY_TIMING5);1488ath_hal_printf(ah, "Enable Cyclic Power Thresh = %d\n",1489MS(reg, AR_PHY_TIMING5_CYCPWR_THR1_ENABLE));1490ath_hal_printf(ah, "Cyclic Power Thresh = 0x%x (%d)\n",1491MS(reg, AR_PHY_TIMING5_CYCPWR_THR1),1492MS(reg, AR_PHY_TIMING5_CYCPWR_THR1));1493ath_hal_printf(ah, "Cyclic Power Thresh 1A= 0x%x (%d)\n",1494MS(reg, AR_PHY_TIMING5_CYCPWR_THR1A),1495MS(reg, AR_PHY_TIMING5_CYCPWR_THR1A));1496reg = OS_REG_READ(ah, AR_PHY_DAG_CTRLCCK);1497ath_hal_printf(ah, "Barker RSSI Thresh Enable = %d\n",1498MS(reg, AR_PHY_DAG_CTRLCCK_EN_RSSI_THR));1499ath_hal_printf(ah, "Barker RSSI Thresh = 0x%x (%d)\n",1500MS(reg, AR_PHY_DAG_CTRLCCK_RSSI_THR),1501MS(reg, AR_PHY_DAG_CTRLCCK_RSSI_THR));150215031504/* Step 1a: Set bit 23 of register 0xa360 to 0 */1505reg = OS_REG_READ(ah, 0xa360);1506reg &= ~0x00800000;1507OS_REG_WRITE(ah, 0xa360, reg);15081509/* Step 2a: Set register 0xa364 to 0x1000 */1510reg = 0x1000;1511OS_REG_WRITE(ah, 0xa364, reg);15121513/* Step 3a: Read bits 17:0 of register 0x9c20 */1514reg = OS_REG_READ(ah, 0x9c20);1515reg &= 0x0003ffff;1516ath_hal_printf(ah,1517"%s: Test Control Status [0x1000] 0x9c20[17:0] = 0x%x\n",1518__func__, reg);15191520/* Step 1b: Set bit 23 of register 0xa360 to 0 */1521reg = OS_REG_READ(ah, 0xa360);1522reg &= ~0x00800000;1523OS_REG_WRITE(ah, 0xa360, reg);15241525/* Step 2b: Set register 0xa364 to 0x1400 */1526reg = 0x1400;1527OS_REG_WRITE(ah, 0xa364, reg);15281529/* Step 3b: Read bits 17:0 of register 0x9c20 */1530reg = OS_REG_READ(ah, 0x9c20);1531reg &= 0x0003ffff;1532ath_hal_printf(ah,1533"%s: Test Control Status [0x1400] 0x9c20[17:0] = 0x%x\n",1534__func__, reg);15351536/* Step 1c: Set bit 23 of register 0xa360 to 0 */1537reg = OS_REG_READ(ah, 0xa360);1538reg &= ~0x00800000;1539OS_REG_WRITE(ah, 0xa360, reg);15401541/* Step 2c: Set register 0xa364 to 0x3C00 */1542reg = 0x3c00;1543OS_REG_WRITE(ah, 0xa364, reg);15441545/* Step 3c: Read bits 17:0 of register 0x9c20 */1546reg = OS_REG_READ(ah, 0x9c20);1547reg &= 0x0003ffff;1548ath_hal_printf(ah,1549"%s: Test Control Status [0x3C00] 0x9c20[17:0] = 0x%x\n",1550__func__, reg);15511552/* Step 1d: Set bit 24 of register 0xa360 to 0 */1553reg = OS_REG_READ(ah, 0xa360);1554reg &= ~0x001040000;1555OS_REG_WRITE(ah, 0xa360, reg);15561557/* Step 2d: Set register 0xa364 to 0x5005D */1558reg = 0x5005D;1559OS_REG_WRITE(ah, 0xa364, reg);15601561/* Step 3d: Read bits 17:0 of register 0xa368 */1562reg = OS_REG_READ(ah, 0xa368);1563reg &= 0x0003ffff;1564ath_hal_printf(ah,1565"%s: Test Control Status [0x5005D] 0xa368[17:0] = 0x%x\n",1566__func__, reg);15671568/* Step 1e: Set bit 24 of register 0xa360 to 0 */1569reg = OS_REG_READ(ah, 0xa360);1570reg &= ~0x001040000;1571OS_REG_WRITE(ah, 0xa360, reg);15721573/* Step 2e: Set register 0xa364 to 0x7005D */1574reg = 0x7005D;1575OS_REG_WRITE(ah, 0xa364, reg);15761577/* Step 3e: Read bits 17:0 of register 0xa368 */1578reg = OS_REG_READ(ah, 0xa368);1579reg &= 0x0003ffff;1580ath_hal_printf(ah,1581"%s: Test Control Status [0x7005D] 0xa368[17:0] = 0x%x\n",1582__func__, reg);15831584/* Step 1f: Set bit 24 of register 0xa360 to 0 */1585reg = OS_REG_READ(ah, 0xa360);1586reg &= ~0x001000000;1587reg |= 0x40000;1588OS_REG_WRITE(ah, 0xa360, reg);15891590/* Step 2f: Set register 0xa364 to 0x3005D */1591reg = 0x3005D;1592OS_REG_WRITE(ah, 0xa364, reg);15931594/* Step 3f: Read bits 17:0 of register 0xa368 */1595reg = OS_REG_READ(ah, 0xa368);1596reg &= 0x0003ffff;1597ath_hal_printf(ah,1598"%s: Test Control Status [0x3005D] 0xa368[17:0] = 0x%x\n",1599__func__, reg);16001601/* Step 1g: Set bit 24 of register 0xa360 to 0 */1602reg = OS_REG_READ(ah, 0xa360);1603reg &= ~0x001000000;1604reg |= 0x40000;1605OS_REG_WRITE(ah, 0xa360, reg);16061607/* Step 2g: Set register 0xa364 to 0x6005D */1608reg = 0x6005D;1609OS_REG_WRITE(ah, 0xa364, reg);16101611/* Step 3g: Read bits 17:0 of register 0xa368 */1612reg = OS_REG_READ(ah, 0xa368);1613reg &= 0x0003ffff;1614ath_hal_printf(ah,1615"%s: Test Control Status [0x6005D] 0xa368[17:0] = 0x%x\n",1616__func__, reg);1617#endif /* AH_DEBUG */1618}16191620/*1621* Return the busy for rx_frame, rx_clear, and tx_frame1622*/1623u_int32_t1624ar9300_get_mib_cycle_counts_pct(struct ath_hal *ah, u_int32_t *rxc_pcnt,1625u_int32_t *rxf_pcnt, u_int32_t *txf_pcnt)1626{1627struct ath_hal_9300 *ahp = AH9300(ah);1628u_int32_t good = 1;16291630u_int32_t rc = OS_REG_READ(ah, AR_RCCNT);1631u_int32_t rf = OS_REG_READ(ah, AR_RFCNT);1632u_int32_t tf = OS_REG_READ(ah, AR_TFCNT);1633u_int32_t cc = OS_REG_READ(ah, AR_CCCNT); /* read cycles last */16341635if (ahp->ah_cycles == 0 || ahp->ah_cycles > cc) {1636/*1637* Cycle counter wrap (or initial call); it's not possible1638* to accurately calculate a value because the registers1639* right shift rather than wrap--so punt and return 0.1640*/1641HALDEBUG(ah, HAL_DEBUG_CHANNEL,1642"%s: cycle counter wrap. ExtBusy = 0\n", __func__);1643good = 0;1644} else {1645u_int32_t cc_d = cc - ahp->ah_cycles;1646u_int32_t rc_d = rc - ahp->ah_rx_clear;1647u_int32_t rf_d = rf - ahp->ah_rx_frame;1648u_int32_t tf_d = tf - ahp->ah_tx_frame;16491650if (cc_d != 0) {1651*rxc_pcnt = rc_d * 100 / cc_d;1652*rxf_pcnt = rf_d * 100 / cc_d;1653*txf_pcnt = tf_d * 100 / cc_d;1654} else {1655good = 0;1656}1657}16581659ahp->ah_cycles = cc;1660ahp->ah_rx_frame = rf;1661ahp->ah_rx_clear = rc;1662ahp->ah_tx_frame = tf;16631664return good;1665}16661667/*1668* Return approximation of extension channel busy over an time interval1669* 0% (clear) -> 100% (busy)1670* -1 for invalid estimate1671*/1672uint32_t1673ar9300_get_11n_ext_busy(struct ath_hal *ah)1674{1675/*1676* Overflow condition to check before multiplying to get %1677* (x * 100 > 0xFFFFFFFF ) => (x > 0x28F5C28)1678*/1679#define OVERFLOW_LIMIT 0x28F5C281680#define ERROR_CODE -116811682struct ath_hal_9300 *ahp = AH9300(ah);1683u_int32_t busy = 0; /* percentage */1684int8_t busyper = 0;1685u_int32_t cycle_count, ctl_busy, ext_busy;16861687/* cycle_count will always be the first to wrap; therefore, read it last1688* This sequence of reads is not atomic, and MIB counter wrap1689* could happen during it ?1690*/1691ctl_busy = OS_REG_READ(ah, AR_RCCNT);1692ext_busy = OS_REG_READ(ah, AR_EXTRCCNT);1693cycle_count = OS_REG_READ(ah, AR_CCCNT);16941695if ((ahp->ah_cycle_count == 0) || (ahp->ah_cycle_count > cycle_count) ||1696(ahp->ah_ctl_busy > ctl_busy) || (ahp->ah_ext_busy > ext_busy))1697{1698/*1699* Cycle counter wrap (or initial call); it's not possible1700* to accurately calculate a value because the registers1701* right shift rather than wrap--so punt and return 0.1702*/1703busyper = ERROR_CODE;1704HALDEBUG(ah, HAL_DEBUG_CHANNEL,1705"%s: cycle counter wrap. ExtBusy = 0\n", __func__);1706} else {1707u_int32_t cycle_delta = cycle_count - ahp->ah_cycle_count;1708u_int32_t ext_busy_delta = ext_busy - ahp->ah_ext_busy;17091710/*1711* Compute extension channel busy percentage1712* Overflow condition: 0xFFFFFFFF < ext_busy_delta * 1001713* Underflow condition/Divide-by-zero: check that cycle_delta >> 7 != 01714* Will never happen, since (ext_busy_delta < cycle_delta) always,1715* and shift necessitated by large ext_busy_delta.1716* Due to timing difference to read the registers and counter overflow,1717* it may still happen that cycle_delta >> 7 = 0.1718*1719*/1720if (cycle_delta) {1721if (ext_busy_delta > OVERFLOW_LIMIT) {1722if (cycle_delta >> 7) {1723busy = ((ext_busy_delta >> 7) * 100) / (cycle_delta >> 7);1724} else {1725busyper = ERROR_CODE;1726}1727} else {1728busy = (ext_busy_delta * 100) / cycle_delta;1729}1730} else {1731busyper = ERROR_CODE;1732}17331734if (busy > 100) {1735busy = 100;1736}1737if ( busyper != ERROR_CODE ) {1738busyper = busy;1739}1740}17411742ahp->ah_cycle_count = cycle_count;1743ahp->ah_ctl_busy = ctl_busy;1744ahp->ah_ext_busy = ext_busy;17451746return busyper;1747#undef OVERFLOW_LIMIT1748#undef ERROR_CODE1749}17501751/* BB Panic Watchdog declarations */1752#define HAL_BB_PANIC_WD_HT20_FACTOR 74 /* 0.74 */1753#define HAL_BB_PANIC_WD_HT40_FACTOR 37 /* 0.37 */17541755void1756ar9300_config_bb_panic_watchdog(struct ath_hal *ah)1757{1758#define HAL_BB_PANIC_IDLE_TIME_OUT 0x0a8c00001759const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan;1760u_int32_t idle_tmo_ms = AH9300(ah)->ah_bb_panic_timeout_ms;1761u_int32_t val, idle_count;17621763if (idle_tmo_ms != 0) {1764/* enable IRQ, disable chip-reset for BB panic */1765val = OS_REG_READ(ah, AR_PHY_PANIC_WD_CTL_2) &1766AR_PHY_BB_PANIC_CNTL2_MASK;1767OS_REG_WRITE(ah, AR_PHY_PANIC_WD_CTL_2,1768(val | AR_PHY_BB_PANIC_IRQ_ENABLE) & ~AR_PHY_BB_PANIC_RST_ENABLE);1769/* bound limit to 10 secs */1770if (idle_tmo_ms > 10000) {1771idle_tmo_ms = 10000;1772}1773if (chan != AH_NULL && IEEE80211_IS_CHAN_HT40(chan)) {1774idle_count = (100 * idle_tmo_ms) / HAL_BB_PANIC_WD_HT40_FACTOR;1775} else {1776idle_count = (100 * idle_tmo_ms) / HAL_BB_PANIC_WD_HT20_FACTOR;1777}1778/*1779* enable panic in non-IDLE mode,1780* disable in IDLE mode,1781* set idle time-out1782*/17831784// EV92527 : Enable IDLE mode panic17851786OS_REG_WRITE(ah, AR_PHY_PANIC_WD_CTL_1,1787AR_PHY_BB_PANIC_NON_IDLE_ENABLE |1788AR_PHY_BB_PANIC_IDLE_ENABLE |1789(AR_PHY_BB_PANIC_IDLE_MASK & HAL_BB_PANIC_IDLE_TIME_OUT) |1790(AR_PHY_BB_PANIC_NON_IDLE_MASK & (idle_count << 2)));1791} else {1792/* disable IRQ, disable chip-reset for BB panic */1793OS_REG_WRITE(ah, AR_PHY_PANIC_WD_CTL_2,1794OS_REG_READ(ah, AR_PHY_PANIC_WD_CTL_2) &1795~(AR_PHY_BB_PANIC_RST_ENABLE | AR_PHY_BB_PANIC_IRQ_ENABLE));1796/* disable panic in non-IDLE mode, disable in IDLE mode */1797OS_REG_WRITE(ah, AR_PHY_PANIC_WD_CTL_1,1798OS_REG_READ(ah, AR_PHY_PANIC_WD_CTL_1) &1799~(AR_PHY_BB_PANIC_NON_IDLE_ENABLE | AR_PHY_BB_PANIC_IDLE_ENABLE));1800}18011802HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: %s BB Panic Watchdog tmo=%ums\n",1803__func__, idle_tmo_ms ? "Enabled" : "Disabled", idle_tmo_ms);1804#undef HAL_BB_PANIC_IDLE_TIME_OUT1805}180618071808void1809ar9300_handle_bb_panic(struct ath_hal *ah)1810{1811u_int32_t status;1812/*1813* we want to avoid printing in ISR context so we save1814* panic watchdog status to be printed later in DPC context1815*/1816AH9300(ah)->ah_bb_panic_last_status = status =1817OS_REG_READ(ah, AR_PHY_PANIC_WD_STATUS);1818/*1819* panic watchdog timer should reset on status read1820* but to make sure we write 0 to the watchdog status bit1821*/1822OS_REG_WRITE(ah, AR_PHY_PANIC_WD_STATUS, status & ~AR_PHY_BB_WD_STATUS_CLR);1823}18241825int1826ar9300_get_bb_panic_info(struct ath_hal *ah, struct hal_bb_panic_info *bb_panic)1827{1828bb_panic->status = AH9300(ah)->ah_bb_panic_last_status;18291830/*1831* For signature 04000539 do not print anything.1832* This is a very common occurence as a compromise between1833* BB Panic and AH_FALSE detects (EV71009). It indicates1834* radar hang, which can be cleared by reprogramming1835* radar related register and does not requre a chip reset1836*/18371838/* Suppress BB Status mesg following signature */1839switch (bb_panic->status) {1840case 0x04000539:1841case 0x04008009:1842case 0x04000b09:1843case 0x1300000a:1844return -1;1845}18461847bb_panic->tsf = ar9300_get_tsf32(ah);1848bb_panic->wd = MS(bb_panic->status, AR_PHY_BB_WD_STATUS);1849bb_panic->det = MS(bb_panic->status, AR_PHY_BB_WD_DET_HANG);1850bb_panic->rdar = MS(bb_panic->status, AR_PHY_BB_WD_RADAR_SM);1851bb_panic->r_odfm = MS(bb_panic->status, AR_PHY_BB_WD_RX_OFDM_SM);1852bb_panic->r_cck = MS(bb_panic->status, AR_PHY_BB_WD_RX_CCK_SM);1853bb_panic->t_odfm = MS(bb_panic->status, AR_PHY_BB_WD_TX_OFDM_SM);1854bb_panic->t_cck = MS(bb_panic->status, AR_PHY_BB_WD_TX_CCK_SM);1855bb_panic->agc = MS(bb_panic->status, AR_PHY_BB_WD_AGC_SM);1856bb_panic->src = MS(bb_panic->status, AR_PHY_BB_WD_SRCH_SM);1857bb_panic->phy_panic_wd_ctl1 = OS_REG_READ(ah, AR_PHY_PANIC_WD_CTL_1);1858bb_panic->phy_panic_wd_ctl2 = OS_REG_READ(ah, AR_PHY_PANIC_WD_CTL_2);1859bb_panic->phy_gen_ctrl = OS_REG_READ(ah, AR_PHY_GEN_CTRL);1860bb_panic->rxc_pcnt = bb_panic->rxf_pcnt = bb_panic->txf_pcnt = 0;1861bb_panic->cycles = ar9300_get_mib_cycle_counts_pct(ah,1862&bb_panic->rxc_pcnt,1863&bb_panic->rxf_pcnt,1864&bb_panic->txf_pcnt);18651866if (ah->ah_config.ath_hal_show_bb_panic) {1867ath_hal_printf(ah, "\n==== BB update: BB status=0x%08x, "1868"tsf=0x%08x ====\n", bb_panic->status, bb_panic->tsf);1869ath_hal_printf(ah, "** BB state: wd=%u det=%u rdar=%u rOFDM=%d "1870"rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",1871bb_panic->wd, bb_panic->det, bb_panic->rdar,1872bb_panic->r_odfm, bb_panic->r_cck, bb_panic->t_odfm,1873bb_panic->t_cck, bb_panic->agc, bb_panic->src);1874ath_hal_printf(ah, "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",1875bb_panic->phy_panic_wd_ctl1, bb_panic->phy_panic_wd_ctl2);1876ath_hal_printf(ah, "** BB mode: BB_gen_controls=0x%08x **\n",1877bb_panic->phy_gen_ctrl);1878if (bb_panic->cycles) {1879ath_hal_printf(ah, "** BB busy times: rx_clear=%d%%, "1880"rx_frame=%d%%, tx_frame=%d%% **\n", bb_panic->rxc_pcnt,1881bb_panic->rxf_pcnt, bb_panic->txf_pcnt);1882}1883ath_hal_printf(ah, "==== BB update: done ====\n\n");1884}18851886return 0; //The returned data will be stored for athstats to retrieve it1887}18881889/* set the reason for HAL reset */1890void1891ar9300_set_hal_reset_reason(struct ath_hal *ah, u_int8_t resetreason)1892{1893AH9300(ah)->ah_reset_reason = resetreason;1894}18951896/*1897* Configure 20/40 operation1898*1899* 20/40 = joint rx clear (control and extension)1900* 20 = rx clear (control)1901*1902* - NOTE: must stop MAC (tx) and requeue 40 MHz packets as 20 MHz1903* when changing from 20/40 => 20 only1904*/1905void1906ar9300_set_11n_mac2040(struct ath_hal *ah, HAL_HT_MACMODE mode)1907{1908u_int32_t macmode;19091910/* Configure MAC for 20/40 operation */1911if (mode == HAL_HT_MACMODE_2040 &&1912!ah->ah_config.ath_hal_cwm_ignore_ext_cca) {1913macmode = AR_2040_JOINED_RX_CLEAR;1914} else {1915macmode = 0;1916}1917OS_REG_WRITE(ah, AR_2040_MODE, macmode);1918}19191920/*1921* Get Rx clear (control/extension channel)1922*1923* Returns active low (busy) for ctrl/ext channel1924* Owl 2.01925*/1926HAL_HT_RXCLEAR1927ar9300_get_11n_rx_clear(struct ath_hal *ah)1928{1929HAL_HT_RXCLEAR rxclear = 0;1930u_int32_t val;19311932val = OS_REG_READ(ah, AR_DIAG_SW);19331934/* control channel */1935if (val & AR_DIAG_RX_CLEAR_CTL_LOW) {1936rxclear |= HAL_RX_CLEAR_CTL_LOW;1937}1938/* extension channel */1939if (val & AR_DIAG_RX_CLEAR_EXT_LOW) {1940rxclear |= HAL_RX_CLEAR_EXT_LOW;1941}1942return rxclear;1943}19441945/*1946* Set Rx clear (control/extension channel)1947*1948* Useful for forcing the channel to appear busy for1949* debugging/diagnostics1950* Owl 2.01951*/1952void1953ar9300_set_11n_rx_clear(struct ath_hal *ah, HAL_HT_RXCLEAR rxclear)1954{1955/* control channel */1956if (rxclear & HAL_RX_CLEAR_CTL_LOW) {1957OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_CLEAR_CTL_LOW);1958} else {1959OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_CLEAR_CTL_LOW);1960}1961/* extension channel */1962if (rxclear & HAL_RX_CLEAR_EXT_LOW) {1963OS_REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_CLEAR_EXT_LOW);1964} else {1965OS_REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_CLEAR_EXT_LOW);1966}1967}196819691970/*1971* HAL support code for force ppm tracking workaround.1972*/19731974u_int32_t1975ar9300_ppm_get_rssi_dump(struct ath_hal *ah)1976{1977u_int32_t retval;1978u_int32_t off1;1979u_int32_t off2;19801981if (OS_REG_READ(ah, AR_PHY_ANALOG_SWAP) & AR_PHY_SWAP_ALT_CHAIN) {1982off1 = 0x2000;1983off2 = 0x1000;1984} else {1985off1 = 0x1000;1986off2 = 0x2000;1987}19881989retval = ((0xff & OS_REG_READ(ah, AR_PHY_CHAN_INFO_GAIN_0 )) << 0) |1990((0xff & OS_REG_READ(ah, AR_PHY_CHAN_INFO_GAIN_0 + off1)) << 8) |1991((0xff & OS_REG_READ(ah, AR_PHY_CHAN_INFO_GAIN_0 + off2)) << 16);19921993return retval;1994}19951996u_int32_t1997ar9300_ppm_force(struct ath_hal *ah)1998{1999u_int32_t data_fine;2000u_int32_t data4;2001//u_int32_t off1;2002//u_int32_t off2;2003HAL_BOOL signed_val = AH_FALSE;20042005// if (OS_REG_READ(ah, AR_PHY_ANALOG_SWAP) & AR_PHY_SWAP_ALT_CHAIN) {2006// off1 = 0x2000;2007// off2 = 0x1000;2008// } else {2009// off1 = 0x1000;2010// off2 = 0x2000;2011// }2012data_fine =2013AR_PHY_CHAN_INFO_GAIN_DIFF_PPM_MASK &2014OS_REG_READ(ah, AR_PHY_CHNINFO_GAINDIFF);20152016/*2017* bit [11-0] is new ppm value. bit 11 is the signed bit.2018* So check value from bit[10:0].2019* Now get the abs val of the ppm value read in bit[0:11].2020* After that do bound check on abs value.2021* if value is off limit, CAP the value and and restore signed bit.2022*/2023if (data_fine & AR_PHY_CHAN_INFO_GAIN_DIFF_PPM_SIGNED_BIT)2024{2025/* get the positive value */2026data_fine = (~data_fine + 1) & AR_PHY_CHAN_INFO_GAIN_DIFF_PPM_MASK;2027signed_val = AH_TRUE;2028}2029if (data_fine > AR_PHY_CHAN_INFO_GAIN_DIFF_UPPER_LIMIT)2030{2031HALDEBUG(ah, HAL_DEBUG_REGIO,2032"%s Correcting ppm out of range %x\n",2033__func__, (data_fine & 0x7ff));2034data_fine = AR_PHY_CHAN_INFO_GAIN_DIFF_UPPER_LIMIT;2035}2036/*2037* Restore signed value if changed above.2038* Use typecast to avoid compilation errors2039*/2040if (signed_val) {2041data_fine = (-(int32_t)data_fine) &2042AR_PHY_CHAN_INFO_GAIN_DIFF_PPM_MASK;2043}20442045/* write value */2046data4 = OS_REG_READ(ah, AR_PHY_TIMING2) &2047~(AR_PHY_TIMING2_USE_FORCE_PPM | AR_PHY_TIMING2_FORCE_PPM_VAL);2048OS_REG_WRITE(ah, AR_PHY_TIMING2,2049data4 | data_fine | AR_PHY_TIMING2_USE_FORCE_PPM);20502051return data_fine;2052}20532054void2055ar9300_ppm_un_force(struct ath_hal *ah)2056{2057u_int32_t data4;20582059data4 = OS_REG_READ(ah, AR_PHY_TIMING2) & ~AR_PHY_TIMING2_USE_FORCE_PPM;2060OS_REG_WRITE(ah, AR_PHY_TIMING2, data4);2061}20622063u_int32_t2064ar9300_ppm_arm_trigger(struct ath_hal *ah)2065{2066u_int32_t val;2067u_int32_t ret;20682069val = OS_REG_READ(ah, AR_PHY_CHAN_INFO_MEMORY);2070ret = OS_REG_READ(ah, AR_TSF_L32);2071OS_REG_WRITE(ah, AR_PHY_CHAN_INFO_MEMORY,2072val | AR_PHY_CHAN_INFO_MEMORY_CAPTURE_MASK);20732074/* return low word of TSF at arm time */2075return ret;2076}20772078int2079ar9300_ppm_get_trigger(struct ath_hal *ah)2080{2081if (OS_REG_READ(ah, AR_PHY_CHAN_INFO_MEMORY) &2082AR_PHY_CHAN_INFO_MEMORY_CAPTURE_MASK)2083{2084/* has not triggered yet, return AH_FALSE */2085return 0;2086}20872088/* else triggered, return AH_TRUE */2089return 1;2090}20912092void2093ar9300_mark_phy_inactive(struct ath_hal *ah)2094{2095OS_REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);2096}20972098/* DEBUG */2099u_int32_t2100ar9300_ppm_get_force_state(struct ath_hal *ah)2101{2102return2103OS_REG_READ(ah, AR_PHY_TIMING2) &2104(AR_PHY_TIMING2_USE_FORCE_PPM | AR_PHY_TIMING2_FORCE_PPM_VAL);2105}21062107/*2108* Return the Cycle counts for rx_frame, rx_clear, and tx_frame2109*/2110HAL_BOOL2111ar9300_get_mib_cycle_counts(struct ath_hal *ah, HAL_SURVEY_SAMPLE *hs)2112{2113/*2114* XXX FreeBSD todo: reimplement this2115*/2116#if 02117p_cnts->tx_frame_count = OS_REG_READ(ah, AR_TFCNT);2118p_cnts->rx_frame_count = OS_REG_READ(ah, AR_RFCNT);2119p_cnts->rx_clear_count = OS_REG_READ(ah, AR_RCCNT);2120p_cnts->cycle_count = OS_REG_READ(ah, AR_CCCNT);2121p_cnts->is_tx_active = (OS_REG_READ(ah, AR_TFCNT) ==2122p_cnts->tx_frame_count) ? AH_FALSE : AH_TRUE;2123p_cnts->is_rx_active = (OS_REG_READ(ah, AR_RFCNT) ==2124p_cnts->rx_frame_count) ? AH_FALSE : AH_TRUE;2125#endif2126return AH_FALSE;2127}21282129void2130ar9300_clear_mib_counters(struct ath_hal *ah)2131{2132u_int32_t reg_val;21332134reg_val = OS_REG_READ(ah, AR_MIBC);2135OS_REG_WRITE(ah, AR_MIBC, reg_val | AR_MIBC_CMC);2136OS_REG_WRITE(ah, AR_MIBC, reg_val & ~AR_MIBC_CMC);2137}213821392140/* Enable or Disable RIFS Rx capability as part of SW WAR for Bug 31602 */2141HAL_BOOL2142ar9300_set_rifs_delay(struct ath_hal *ah, HAL_BOOL enable)2143{2144struct ath_hal_9300 *ahp = AH9300(ah);2145HAL_CHANNEL_INTERNAL *ichan =2146ath_hal_checkchannel(ah, AH_PRIVATE(ah)->ah_curchan);2147HAL_BOOL is_chan_2g = IS_CHAN_2GHZ(ichan);2148u_int32_t tmp = 0;21492150if (enable) {2151if (ahp->ah_rifs_enabled == AH_TRUE) {2152return AH_TRUE;2153}21542155OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, ahp->ah_rifs_reg[0]);2156OS_REG_WRITE(ah, AR_PHY_RIFS_SRCH,2157ahp->ah_rifs_reg[1]);21582159ahp->ah_rifs_enabled = AH_TRUE;2160OS_MEMZERO(ahp->ah_rifs_reg, sizeof(ahp->ah_rifs_reg));2161} else {2162if (ahp->ah_rifs_enabled == AH_TRUE) {2163ahp->ah_rifs_reg[0] = OS_REG_READ(ah,2164AR_PHY_SEARCH_START_DELAY);2165ahp->ah_rifs_reg[1] = OS_REG_READ(ah, AR_PHY_RIFS_SRCH);2166}2167/* Change rifs init delay to 0 */2168OS_REG_WRITE(ah, AR_PHY_RIFS_SRCH,2169(ahp->ah_rifs_reg[1] & ~(AR_PHY_RIFS_INIT_DELAY)));2170tmp = 0xfffff000 & OS_REG_READ(ah, AR_PHY_SEARCH_START_DELAY);2171if (is_chan_2g) {2172if (IEEE80211_IS_CHAN_HT40(AH_PRIVATE(ah)->ah_curchan)) {2173OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, tmp | 500);2174} else { /* Sowl 2G HT-20 default is 0x134 for search start delay */2175OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, tmp | 250);2176}2177} else {2178if (IEEE80211_IS_CHAN_HT40(AH_PRIVATE(ah)->ah_curchan)) {2179OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, tmp | 0x370);2180} else { /* Sowl 5G HT-20 default is 0x1b8 for search start delay */2181OS_REG_WRITE(ah, AR_PHY_SEARCH_START_DELAY, tmp | 0x1b8);2182}2183}21842185ahp->ah_rifs_enabled = AH_FALSE;2186}2187return AH_TRUE;21882189} /* ar9300_set_rifs_delay () */21902191/* Set the current RIFS Rx setting */2192HAL_BOOL2193ar9300_set_11n_rx_rifs(struct ath_hal *ah, HAL_BOOL enable)2194{2195/* Non-Owl 11n chips */2196if ((ath_hal_getcapability(ah, HAL_CAP_RIFS_RX, 0, AH_NULL) == HAL_OK)) {2197if (ar9300_get_capability(ah, HAL_CAP_LDPCWAR, 0, AH_NULL) == HAL_OK) {2198return ar9300_set_rifs_delay(ah, enable);2199}2200return AH_FALSE;2201}22022203return AH_TRUE;2204} /* ar9300_set_11n_rx_rifs () */22052206static hal_mac_hangs_t2207ar9300_compare_dbg_hang(struct ath_hal *ah, mac_dbg_regs_t mac_dbg,2208hal_mac_hang_check_t hang_check, hal_mac_hangs_t hangs, u_int8_t *dcu_chain)2209{2210int i = 0;2211hal_mac_hangs_t found_hangs = 0;22122213if (hangs & dcu_chain_state) {2214for (i = 0; i < 6; i++) {2215if (((mac_dbg.dma_dbg_4 >> (5 * i)) & 0x1f) ==2216hang_check.dcu_chain_state)2217{2218found_hangs |= dcu_chain_state;2219*dcu_chain = i;2220}2221}2222for (i = 0; i < 4; i++) {2223if (((mac_dbg.dma_dbg_5 >> (5 * i)) & 0x1f) ==2224hang_check.dcu_chain_state)2225{2226found_hangs |= dcu_chain_state;2227*dcu_chain = i + 6;2228}2229}2230}22312232if (hangs & dcu_complete_state) {2233if ((mac_dbg.dma_dbg_6 & 0x3) == hang_check.dcu_complete_state) {2234found_hangs |= dcu_complete_state;2235}2236}22372238return found_hangs;22392240} /* end - ar9300_compare_dbg_hang */22412242#define NUM_STATUS_READS 502243HAL_BOOL2244ar9300_detect_mac_hang(struct ath_hal *ah)2245{2246struct ath_hal_9300 *ahp = AH9300(ah);2247mac_dbg_regs_t mac_dbg;2248hal_mac_hang_check_t hang_sig1_val = {0x6, 0x1, 0, 0, 0, 0, 0, 0};2249hal_mac_hangs_t hang_sig1 = (dcu_chain_state | dcu_complete_state);2250int i = 0;2251u_int8_t dcu_chain = 0, current_dcu_chain_state, shift_val;22522253if (!(ahp->ah_hang_wars & HAL_MAC_HANG_WAR)) {2254return AH_FALSE;2255}22562257OS_MEMZERO(&mac_dbg, sizeof(mac_dbg));22582259mac_dbg.dma_dbg_4 = OS_REG_READ(ah, AR_DMADBG_4);2260mac_dbg.dma_dbg_5 = OS_REG_READ(ah, AR_DMADBG_5);2261mac_dbg.dma_dbg_6 = OS_REG_READ(ah, AR_DMADBG_6);22622263HALDEBUG(ah, HAL_DEBUG_DFS, " dma regs: %X %X %X \n",2264mac_dbg.dma_dbg_4, mac_dbg.dma_dbg_5,2265mac_dbg.dma_dbg_6);22662267if (hang_sig1 !=2268ar9300_compare_dbg_hang(ah, mac_dbg,2269hang_sig1_val, hang_sig1, &dcu_chain))2270{2271HALDEBUG(ah, HAL_DEBUG_DFS, " hang sig1 not found \n");2272return AH_FALSE;2273}22742275shift_val = (dcu_chain >= 6) ? (dcu_chain-6) : (dcu_chain);2276shift_val *= 5;22772278for (i = 1; i <= NUM_STATUS_READS; i++) {2279if (dcu_chain < 6) {2280mac_dbg.dma_dbg_4 = OS_REG_READ(ah, AR_DMADBG_4);2281current_dcu_chain_state =2282((mac_dbg.dma_dbg_4 >> shift_val) & 0x1f);2283} else {2284mac_dbg.dma_dbg_5 = OS_REG_READ(ah, AR_DMADBG_5);2285current_dcu_chain_state = ((mac_dbg.dma_dbg_5 >> shift_val) & 0x1f);2286}2287mac_dbg.dma_dbg_6 = OS_REG_READ(ah, AR_DMADBG_6);22882289if (((mac_dbg.dma_dbg_6 & 0x3) != hang_sig1_val.dcu_complete_state)2290|| (current_dcu_chain_state != hang_sig1_val.dcu_chain_state)) {2291return AH_FALSE;2292}2293}2294HALDEBUG(ah, HAL_DEBUG_DFS, "%s sig5count=%d sig6count=%d ", __func__,2295ahp->ah_hang[MAC_HANG_SIG1], ahp->ah_hang[MAC_HANG_SIG2]);2296ahp->ah_hang[MAC_HANG_SIG1]++;2297return AH_TRUE;22982299} /* end - ar9300_detect_mac_hang */23002301/* Determine if the baseband is hung by reading the Observation Bus Register */2302HAL_BOOL2303ar9300_detect_bb_hang(struct ath_hal *ah)2304{2305#define N(a) (sizeof(a) / sizeof(a[0]))2306struct ath_hal_9300 *ahp = AH9300(ah);2307u_int32_t hang_sig = 0;2308int i = 0;2309/* Check the PCU Observation Bus 1 register (0x806c) NUM_STATUS_READS times2310*2311* 4 known BB hang signatures -2312* [1] bits 8,9,11 are 0. State machine state (bits 25-31) is 0x1E2313* [2] bits 8,9 are 1, bit 11 is 0. State machine state (bits 25-31) is 0x522314* [3] bits 8,9 are 1, bit 11 is 0. State machine state (bits 25-31) is 0x182315* [4] bit 10 is 1, bit 11 is 0. WEP state (bits 12-17) is 0x2,2316* Rx State (bits 20-24) is 0x7.2317*/2318hal_hw_hang_check_t hang_list [] =2319{2320/* Offset Reg Value Reg Mask Hang Offset */2321{AR_OBS_BUS_1, 0x1E000000, 0x7E000B00, BB_HANG_SIG1},2322{AR_OBS_BUS_1, 0x52000B00, 0x7E000B00, BB_HANG_SIG2},2323{AR_OBS_BUS_1, 0x18000B00, 0x7E000B00, BB_HANG_SIG3},2324{AR_OBS_BUS_1, 0x00702400, 0x7E7FFFEF, BB_HANG_SIG4}2325};23262327if (!(ahp->ah_hang_wars & (HAL_RIFS_BB_HANG_WAR |2328HAL_DFS_BB_HANG_WAR |2329HAL_RX_STUCK_LOW_BB_HANG_WAR))) {2330return AH_FALSE;2331}23322333hang_sig = OS_REG_READ(ah, AR_OBS_BUS_1);2334for (i = 1; i <= NUM_STATUS_READS; i++) {2335if (hang_sig != OS_REG_READ(ah, AR_OBS_BUS_1)) {2336return AH_FALSE;2337}2338}23392340for (i = 0; i < N(hang_list); i++) {2341if ((hang_sig & hang_list[i].hang_mask) == hang_list[i].hang_val) {2342ahp->ah_hang[hang_list[i].hang_offset]++;2343HALDEBUG(ah, HAL_DEBUG_DFS, "%s sig1count=%d sig2count=%d "2344"sig3count=%d sig4count=%d\n", __func__,2345ahp->ah_hang[BB_HANG_SIG1], ahp->ah_hang[BB_HANG_SIG2],2346ahp->ah_hang[BB_HANG_SIG3], ahp->ah_hang[BB_HANG_SIG4]);2347return AH_TRUE;2348}2349}23502351HALDEBUG(ah, HAL_DEBUG_DFS, "%s Found an unknown BB hang signature! "2352"<0x806c>=0x%x\n", __func__, hang_sig);23532354return AH_FALSE;23552356#undef N2357} /* end - ar9300_detect_bb_hang () */23582359#undef NUM_STATUS_READS23602361HAL_STATUS2362ar9300_select_ant_config(struct ath_hal *ah, u_int32_t cfg)2363{2364struct ath_hal_9300 *ahp = AH9300(ah);2365const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan;2366HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, chan);2367const HAL_CAPABILITIES *p_cap = &AH_PRIVATE(ah)->ah_caps;2368u_int16_t ant_config;2369u_int32_t hal_num_ant_config;23702371hal_num_ant_config = IS_CHAN_2GHZ(ichan) ?2372p_cap->halNumAntCfg2GHz: p_cap->halNumAntCfg5GHz;23732374if (cfg < hal_num_ant_config) {2375if (HAL_OK == ar9300_eeprom_get_ant_cfg(ahp, chan, cfg, &ant_config)) {2376OS_REG_WRITE(ah, AR_PHY_SWITCH_COM, ant_config);2377return HAL_OK;2378}2379}23802381return HAL_EINVAL;2382}23832384/*2385* Functions to get/set DCS mode2386*/2387void2388ar9300_set_dcs_mode(struct ath_hal *ah, u_int32_t mode)2389{2390AH9300(ah)->ah_dcs_enable = mode;2391}23922393u_int32_t2394ar9300_get_dcs_mode(struct ath_hal *ah)2395{2396return AH9300(ah)->ah_dcs_enable;2397}23982399#if ATH_BT_COEX2400void2401ar9300_set_bt_coex_info(struct ath_hal *ah, HAL_BT_COEX_INFO *btinfo)2402{2403struct ath_hal_9300 *ahp = AH9300(ah);24042405ahp->ah_bt_module = btinfo->bt_module;2406ahp->ah_bt_coex_config_type = btinfo->bt_coex_config;2407ahp->ah_bt_active_gpio_select = btinfo->bt_gpio_bt_active;2408ahp->ah_bt_priority_gpio_select = btinfo->bt_gpio_bt_priority;2409ahp->ah_wlan_active_gpio_select = btinfo->bt_gpio_wlan_active;2410ahp->ah_bt_active_polarity = btinfo->bt_active_polarity;2411ahp->ah_bt_coex_single_ant = btinfo->bt_single_ant;2412ahp->ah_bt_wlan_isolation = btinfo->bt_isolation;2413}24142415void2416ar9300_bt_coex_config(struct ath_hal *ah, HAL_BT_COEX_CONFIG *btconf)2417{2418struct ath_hal_9300 *ahp = AH9300(ah);2419HAL_BOOL rx_clear_polarity;24202421/*2422* For Kiwi and Osprey, the polarity of rx_clear is active high.2423* The bt_rxclear_polarity flag from ath_dev needs to be inverted.2424*/2425rx_clear_polarity = !btconf->bt_rxclear_polarity;24262427ahp->ah_bt_coex_mode = (ahp->ah_bt_coex_mode & AR_BT_QCU_THRESH) |2428SM(btconf->bt_time_extend, AR_BT_TIME_EXTEND) |2429SM(btconf->bt_txstate_extend, AR_BT_TXSTATE_EXTEND) |2430SM(btconf->bt_txframe_extend, AR_BT_TX_FRAME_EXTEND) |2431SM(btconf->bt_mode, AR_BT_MODE) |2432SM(btconf->bt_quiet_collision, AR_BT_QUIET) |2433SM(rx_clear_polarity, AR_BT_RX_CLEAR_POLARITY) |2434SM(btconf->bt_priority_time, AR_BT_PRIORITY_TIME) |2435SM(btconf->bt_first_slot_time, AR_BT_FIRST_SLOT_TIME);24362437ahp->ah_bt_coex_mode2 |= SM(btconf->bt_hold_rxclear, AR_BT_HOLD_RX_CLEAR);24382439if (ahp->ah_bt_coex_single_ant == AH_FALSE) {2440/* Enable ACK to go out even though BT has higher priority. */2441ahp->ah_bt_coex_mode2 |= AR_BT_DISABLE_BT_ANT;2442}2443}24442445void2446ar9300_bt_coex_set_qcu_thresh(struct ath_hal *ah, int qnum)2447{2448struct ath_hal_9300 *ahp = AH9300(ah);24492450/* clear the old value, then set the new value */2451ahp->ah_bt_coex_mode &= ~AR_BT_QCU_THRESH;2452ahp->ah_bt_coex_mode |= SM(qnum, AR_BT_QCU_THRESH);2453}24542455void2456ar9300_bt_coex_set_weights(struct ath_hal *ah, u_int32_t stomp_type)2457{2458struct ath_hal_9300 *ahp = AH9300(ah);24592460ahp->ah_bt_coex_bt_weight[0] = AR9300_BT_WGHT;2461ahp->ah_bt_coex_bt_weight[1] = AR9300_BT_WGHT;2462ahp->ah_bt_coex_bt_weight[2] = AR9300_BT_WGHT;2463ahp->ah_bt_coex_bt_weight[3] = AR9300_BT_WGHT;24642465switch (stomp_type) {2466case HAL_BT_COEX_STOMP_ALL:2467ahp->ah_bt_coex_wlan_weight[0] = AR9300_STOMP_ALL_WLAN_WGHT0;2468ahp->ah_bt_coex_wlan_weight[1] = AR9300_STOMP_ALL_WLAN_WGHT1;2469break;2470case HAL_BT_COEX_STOMP_LOW:2471ahp->ah_bt_coex_wlan_weight[0] = AR9300_STOMP_LOW_WLAN_WGHT0;2472ahp->ah_bt_coex_wlan_weight[1] = AR9300_STOMP_LOW_WLAN_WGHT1;2473break;2474case HAL_BT_COEX_STOMP_ALL_FORCE:2475ahp->ah_bt_coex_wlan_weight[0] = AR9300_STOMP_ALL_FORCE_WLAN_WGHT0;2476ahp->ah_bt_coex_wlan_weight[1] = AR9300_STOMP_ALL_FORCE_WLAN_WGHT1;2477break;2478case HAL_BT_COEX_STOMP_LOW_FORCE:2479ahp->ah_bt_coex_wlan_weight[0] = AR9300_STOMP_LOW_FORCE_WLAN_WGHT0;2480ahp->ah_bt_coex_wlan_weight[1] = AR9300_STOMP_LOW_FORCE_WLAN_WGHT1;2481break;2482case HAL_BT_COEX_STOMP_NONE:2483case HAL_BT_COEX_NO_STOMP:2484ahp->ah_bt_coex_wlan_weight[0] = AR9300_STOMP_NONE_WLAN_WGHT0;2485ahp->ah_bt_coex_wlan_weight[1] = AR9300_STOMP_NONE_WLAN_WGHT1;2486break;2487default:2488/* There is a force_weight from registry */2489ahp->ah_bt_coex_wlan_weight[0] = stomp_type;2490ahp->ah_bt_coex_wlan_weight[1] = stomp_type;2491break;2492}2493}24942495void2496ar9300_bt_coex_setup_bmiss_thresh(struct ath_hal *ah, u_int32_t thresh)2497{2498struct ath_hal_9300 *ahp = AH9300(ah);24992500/* clear the old value, then set the new value */2501ahp->ah_bt_coex_mode2 &= ~AR_BT_BCN_MISS_THRESH;2502ahp->ah_bt_coex_mode2 |= SM(thresh, AR_BT_BCN_MISS_THRESH);2503}25042505static void2506ar9300_bt_coex_antenna_diversity(struct ath_hal *ah, u_int32_t value)2507{2508struct ath_hal_9300 *ahp = AH9300(ah);2509#if ATH_ANT_DIV_COMB2510//struct ath_hal_private *ahpriv = AH_PRIVATE(ah);2511const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan;2512#endif25132514HALDEBUG(ah, HAL_DEBUG_BT_COEX, "%s: called, value=%d\n", __func__, value);25152516if (ahp->ah_bt_coex_flag & HAL_BT_COEX_FLAG_ANT_DIV_ALLOW)2517{2518if (ahp->ah_diversity_control == HAL_ANT_VARIABLE)2519{2520/* Config antenna diversity */2521#if ATH_ANT_DIV_COMB2522ar9300_ant_ctrl_set_lna_div_use_bt_ant(ah, value, chan);2523#endif2524}2525}2526}252725282529void2530ar9300_bt_coex_set_parameter(struct ath_hal *ah, u_int32_t type,2531u_int32_t value)2532{2533struct ath_hal_9300 *ahp = AH9300(ah);2534struct ath_hal_private *ahpriv = AH_PRIVATE(ah);25352536switch (type) {2537case HAL_BT_COEX_SET_ACK_PWR:2538if (value) {2539ahp->ah_bt_coex_flag |= HAL_BT_COEX_FLAG_LOW_ACK_PWR;2540} else {2541ahp->ah_bt_coex_flag &= ~HAL_BT_COEX_FLAG_LOW_ACK_PWR;2542}2543ar9300_set_tx_power_limit(ah, ahpriv->ah_powerLimit,2544ahpriv->ah_extraTxPow, 0);2545break;25462547case HAL_BT_COEX_ANTENNA_DIVERSITY:2548if (AR_SREV_POSEIDON(ah) || AR_SREV_APHRODITE(ah)) {2549ahp->ah_bt_coex_flag |= HAL_BT_COEX_FLAG_ANT_DIV_ALLOW;2550if (value) {2551ahp->ah_bt_coex_flag |= HAL_BT_COEX_FLAG_ANT_DIV_ENABLE;2552}2553else {2554ahp->ah_bt_coex_flag &= ~HAL_BT_COEX_FLAG_ANT_DIV_ENABLE;2555}2556ar9300_bt_coex_antenna_diversity(ah, value);2557}2558break;2559case HAL_BT_COEX_LOWER_TX_PWR:2560if (value) {2561ahp->ah_bt_coex_flag |= HAL_BT_COEX_FLAG_LOWER_TX_PWR;2562}2563else {2564ahp->ah_bt_coex_flag &= ~HAL_BT_COEX_FLAG_LOWER_TX_PWR;2565}2566ar9300_set_tx_power_limit(ah, ahpriv->ah_powerLimit,2567ahpriv->ah_extraTxPow, 0);2568break;2569#if ATH_SUPPORT_MCI2570case HAL_BT_COEX_MCI_MAX_TX_PWR:2571if ((ah->ah_config.ath_hal_mci_config &2572ATH_MCI_CONFIG_CONCUR_TX) == ATH_MCI_CONCUR_TX_SHARED_CHN)2573{2574if (value) {2575ahp->ah_bt_coex_flag |= HAL_BT_COEX_FLAG_MCI_MAX_TX_PWR;2576ahp->ah_mci_concur_tx_en = AH_TRUE;2577}2578else {2579ahp->ah_bt_coex_flag &= ~HAL_BT_COEX_FLAG_MCI_MAX_TX_PWR;2580ahp->ah_mci_concur_tx_en = AH_FALSE;2581}2582ar9300_set_tx_power_limit(ah, ahpriv->ah_powerLimit,2583ahpriv->ah_extraTxPow, 0);2584}2585HALDEBUG(ah, HAL_DEBUG_BT_COEX, "(MCI) concur_tx_en = %d\n",2586ahp->ah_mci_concur_tx_en);2587break;2588case HAL_BT_COEX_MCI_FTP_STOMP_RX:2589if (value) {2590ahp->ah_bt_coex_flag |= HAL_BT_COEX_FLAG_MCI_FTP_STOMP_RX;2591}2592else {2593ahp->ah_bt_coex_flag &= ~HAL_BT_COEX_FLAG_MCI_FTP_STOMP_RX;2594}2595break;2596#endif2597default:2598break;2599}2600}26012602void2603ar9300_bt_coex_disable(struct ath_hal *ah)2604{2605struct ath_hal_9300 *ahp = AH9300(ah);26062607/* Always drive rx_clear_external output as 0 */2608ath_hal_gpioCfgOutput(ah, ahp->ah_wlan_active_gpio_select,2609HAL_GPIO_OUTPUT_MUX_AS_OUTPUT);26102611if (ahp->ah_bt_coex_single_ant == AH_TRUE) {2612OS_REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);2613OS_REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);2614}26152616OS_REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE);2617OS_REG_WRITE(ah, AR_BT_COEX_MODE2, 0);2618OS_REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS0, 0);2619OS_REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS1, 0);2620OS_REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS0, 0);2621OS_REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS1, 0);2622OS_REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS2, 0);2623OS_REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS3, 0);26242625ahp->ah_bt_coex_enabled = AH_FALSE;2626}26272628int2629ar9300_bt_coex_enable(struct ath_hal *ah)2630{2631struct ath_hal_9300 *ahp = AH9300(ah);26322633/* Program coex mode and weight registers to actually enable coex */2634OS_REG_WRITE(ah, AR_BT_COEX_MODE, ahp->ah_bt_coex_mode);2635OS_REG_WRITE(ah, AR_BT_COEX_MODE2, ahp->ah_bt_coex_mode2);2636OS_REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS0, ahp->ah_bt_coex_wlan_weight[0]);2637OS_REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS1, ahp->ah_bt_coex_wlan_weight[1]);2638OS_REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS0, ahp->ah_bt_coex_bt_weight[0]);2639OS_REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS1, ahp->ah_bt_coex_bt_weight[1]);2640OS_REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS2, ahp->ah_bt_coex_bt_weight[2]);2641OS_REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS3, ahp->ah_bt_coex_bt_weight[3]);26422643if (ahp->ah_bt_coex_flag & HAL_BT_COEX_FLAG_LOW_ACK_PWR) {2644OS_REG_WRITE(ah, AR_TPC, HAL_BT_COEX_LOW_ACK_POWER);2645} else {2646OS_REG_WRITE(ah, AR_TPC, HAL_BT_COEX_HIGH_ACK_POWER);2647}26482649OS_REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);2650if (ahp->ah_bt_coex_single_ant == AH_TRUE) {2651OS_REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 1);2652} else {2653OS_REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);2654}26552656if (ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_3WIRE) {2657/* For 3-wire, configure the desired GPIO port for rx_clear */2658ath_hal_gpioCfgOutput(ah,2659ahp->ah_wlan_active_gpio_select,2660HAL_GPIO_OUTPUT_MUX_AS_WLAN_ACTIVE);2661}2662else if ((ahp->ah_bt_coex_config_type >= HAL_BT_COEX_CFG_2WIRE_2CH) &&2663(ahp->ah_bt_coex_config_type <= HAL_BT_COEX_CFG_2WIRE_CH0))2664{2665/* For 2-wire, configure the desired GPIO port for TX_FRAME output */2666ath_hal_gpioCfgOutput(ah,2667ahp->ah_wlan_active_gpio_select,2668HAL_GPIO_OUTPUT_MUX_AS_TX_FRAME);2669}26702671/*2672* Enable a weak pull down on BT_ACTIVE.2673* When BT device is disabled, BT_ACTIVE might be floating.2674*/2675OS_REG_RMW(ah, AR_HOSTIF_REG(ah, AR_GPIO_PDPU),2676(AR_GPIO_PULL_DOWN << (ahp->ah_bt_active_gpio_select * 2)),2677(AR_GPIO_PDPU_OPTION << (ahp->ah_bt_active_gpio_select * 2)));26782679ahp->ah_bt_coex_enabled = AH_TRUE;26802681return 0;2682}26832684u_int32_t ar9300_get_bt_active_gpio(struct ath_hal *ah, u_int32_t reg)2685{2686return 0;2687}26882689u_int32_t ar9300_get_wlan_active_gpio(struct ath_hal *ah, u_int32_t reg,u_int32_t bOn)2690{2691return bOn;2692}26932694void2695ar9300_init_bt_coex(struct ath_hal *ah)2696{2697struct ath_hal_9300 *ahp = AH9300(ah);26982699if (ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_3WIRE) {2700OS_REG_SET_BIT(ah, AR_HOSTIF_REG(ah, AR_GPIO_INPUT_EN_VAL),2701(AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB |2702AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB));27032704/*2705* Set input mux for bt_prority_async and2706* bt_active_async to GPIO pins2707*/2708OS_REG_RMW_FIELD(ah,2709AR_HOSTIF_REG(ah, AR_GPIO_INPUT_MUX1),2710AR_GPIO_INPUT_MUX1_BT_ACTIVE,2711ahp->ah_bt_active_gpio_select);2712OS_REG_RMW_FIELD(ah,2713AR_HOSTIF_REG(ah, AR_GPIO_INPUT_MUX1),2714AR_GPIO_INPUT_MUX1_BT_PRIORITY,2715ahp->ah_bt_priority_gpio_select);27162717/* Configure the desired GPIO ports for input */2718ath_hal_gpioCfgInput(ah, ahp->ah_bt_active_gpio_select);2719ath_hal_gpioCfgInput(ah, ahp->ah_bt_priority_gpio_select);27202721if (ahp->ah_bt_coex_enabled) {2722ar9300_bt_coex_enable(ah);2723} else {2724ar9300_bt_coex_disable(ah);2725}2726}2727else if ((ahp->ah_bt_coex_config_type >= HAL_BT_COEX_CFG_2WIRE_2CH) &&2728(ahp->ah_bt_coex_config_type <= HAL_BT_COEX_CFG_2WIRE_CH0))2729{2730/* 2-wire */2731if (ahp->ah_bt_coex_enabled) {2732/* Connect bt_active_async to baseband */2733OS_REG_CLR_BIT(ah,2734AR_HOSTIF_REG(ah, AR_GPIO_INPUT_EN_VAL),2735(AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |2736AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));2737OS_REG_SET_BIT(ah,2738AR_HOSTIF_REG(ah, AR_GPIO_INPUT_EN_VAL),2739AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);27402741/*2742* Set input mux for bt_prority_async and2743* bt_active_async to GPIO pins2744*/2745OS_REG_RMW_FIELD(ah,2746AR_HOSTIF_REG(ah, AR_GPIO_INPUT_MUX1),2747AR_GPIO_INPUT_MUX1_BT_ACTIVE,2748ahp->ah_bt_active_gpio_select);27492750/* Configure the desired GPIO ports for input */2751ath_hal_gpioCfgInput(ah, ahp->ah_bt_active_gpio_select);27522753/* Enable coexistence on initialization */2754ar9300_bt_coex_enable(ah);2755}2756}2757#if ATH_SUPPORT_MCI2758else if (ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_MCI) {2759if (ahp->ah_bt_coex_enabled) {2760ar9300_mci_bt_coex_enable(ah);2761}2762else {2763ar9300_mci_bt_coex_disable(ah);2764}2765}2766#endif /* ATH_SUPPORT_MCI */2767}27682769#endif /* ATH_BT_COEX */27702771HAL_STATUS ar9300_set_proxy_sta(struct ath_hal *ah, HAL_BOOL enable)2772{2773u_int32_t val;2774int wasp_mm_rev;27752776#define AR_SOC_RST_REVISION_ID 0xB80600902777#define REG_READ(_reg) *((volatile u_int32_t *)(_reg))2778wasp_mm_rev = (REG_READ(AR_SOC_RST_REVISION_ID) &2779AR_SREV_REVISION_WASP_MINOR_MINOR_MASK) >>2780AR_SREV_REVISION_WASP_MINOR_MINOR_SHIFT;2781#undef AR_SOC_RST_REVISION_ID2782#undef REG_READ27832784/*2785* Azimuth (ProxySTA) Mode is only supported correctly by2786* Peacock or WASP 1.3.0.1 or later (hopefully) chips.2787*2788* Enable this feature for Scorpion at this time. The silicon2789* still needs to be validated.2790*/2791if (!(AH_PRIVATE((ah))->ah_macVersion == AR_SREV_VERSION_AR9580) &&2792!(AH_PRIVATE((ah))->ah_macVersion == AR_SREV_VERSION_SCORPION) &&2793!((AH_PRIVATE((ah))->ah_macVersion == AR_SREV_VERSION_WASP) &&2794((AH_PRIVATE((ah))->ah_macRev > AR_SREV_REVISION_WASP_13) ||2795(AH_PRIVATE((ah))->ah_macRev == AR_SREV_REVISION_WASP_13 &&2796wasp_mm_rev >= 0 /* 1 */))))2797{2798HALDEBUG(ah, HAL_DEBUG_UNMASKABLE, "%s error: current chip (ver 0x%x, "2799"rev 0x%x, minor minor rev 0x%x) cannot support Azimuth Mode\n",2800__func__, AH_PRIVATE((ah))->ah_macVersion,2801AH_PRIVATE((ah))->ah_macRev, wasp_mm_rev);2802return HAL_ENOTSUPP;2803}28042805OS_REG_WRITE(ah,2806AR_MAC_PCU_LOGIC_ANALYZER, AR_MAC_PCU_LOGIC_ANALYZER_PSTABUG75996);28072808/* turn on mode bit[24] for proxy sta */2809OS_REG_WRITE(ah, AR_PCU_MISC_MODE2,2810OS_REG_READ(ah, AR_PCU_MISC_MODE2) | AR_PCU_MISC_MODE2_PROXY_STA);28112812val = OS_REG_READ(ah, AR_AZIMUTH_MODE);2813if (enable) {2814val |= AR_AZIMUTH_KEY_SEARCH_AD1 |2815AR_AZIMUTH_CTS_MATCH_TX_AD2 |2816AR_AZIMUTH_BA_USES_AD1;2817/* turn off filter pass hold (bit 9) */2818val &= ~AR_AZIMUTH_FILTER_PASS_HOLD;2819} else {2820val &= ~(AR_AZIMUTH_KEY_SEARCH_AD1 |2821AR_AZIMUTH_CTS_MATCH_TX_AD2 |2822AR_AZIMUTH_BA_USES_AD1);2823}2824OS_REG_WRITE(ah, AR_AZIMUTH_MODE, val);28252826/* enable promiscous mode */2827OS_REG_WRITE(ah, AR_RX_FILTER,2828OS_REG_READ(ah, AR_RX_FILTER) | HAL_RX_FILTER_PROM);2829/* enable promiscous in azimuth mode */2830OS_REG_WRITE(ah, AR_PCU_MISC_MODE2, AR_PCU_MISC_MODE2_PROM_VC_MODE);2831OS_REG_WRITE(ah, AR_MAC_PCU_LOGIC_ANALYZER, AR_MAC_PCU_LOGIC_ANALYZER_VC_MODE);28322833/* turn on filter pass hold (bit 9) */2834OS_REG_WRITE(ah, AR_AZIMUTH_MODE,2835OS_REG_READ(ah, AR_AZIMUTH_MODE) | AR_AZIMUTH_FILTER_PASS_HOLD);28362837return HAL_OK;2838}28392840#if 02841void ar9300_mat_enable(struct ath_hal *ah, int enable)2842{2843/*2844* MAT (s/w ProxySTA) implementation requires to turn off interrupt2845* mitigation and turn on key search always for better performance.2846*/2847struct ath_hal_9300 *ahp = AH9300(ah);2848struct ath_hal_private *ap = AH_PRIVATE(ah);28492850ahp->ah_intr_mitigation_rx = !enable;2851if (ahp->ah_intr_mitigation_rx) {2852/*2853* Enable Interrupt Mitigation for Rx.2854* If no build-specific limits for the rx interrupt mitigation2855* timer have been specified, use conservative defaults.2856*/2857#ifndef AH_RIMT_VAL_LAST2858#define AH_RIMT_LAST_MICROSEC 5002859#endif2860#ifndef AH_RIMT_VAL_FIRST2861#define AH_RIMT_FIRST_MICROSEC 20002862#endif2863OS_REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, AH_RIMT_LAST_MICROSEC);2864OS_REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, AH_RIMT_FIRST_MICROSEC);2865} else {2866OS_REG_WRITE(ah, AR_RIMT, 0);2867}28682869ahp->ah_enable_keysearch_always = !!enable;2870ar9300_enable_keysearch_always(ah, ahp->ah_enable_keysearch_always);2871}2872#endif28732874void ar9300_enable_tpc(struct ath_hal *ah)2875{2876u_int32_t val = 0;28772878ah->ah_config.ath_hal_desc_tpc = 1;28792880/* Enable TPC */2881OS_REG_RMW_FIELD(ah, AR_PHY_PWRTX_MAX, AR_PHY_PER_PACKET_POWERTX_MAX, 1);28822883/*2884* Disable per chain power reduction since we are already2885* accounting for this in our calculations2886*/2887val = OS_REG_READ(ah, AR_PHY_POWER_TX_SUB);2888if (AR_SREV_WASP(ah)) {2889OS_REG_WRITE(ah, AR_PHY_POWER_TX_SUB,2890val & AR_PHY_POWER_TX_SUB_2_DISABLE);2891} else {2892OS_REG_WRITE(ah, AR_PHY_POWER_TX_SUB,2893val & AR_PHY_POWER_TX_SUB_3_DISABLE);2894}2895}289628972898/*2899* ar9300_force_tsf_sync2900* This function forces the TSF sync to the given bssid, this is implemented2901* as a temp hack to get the AoW demo, and is primarily used in the WDS client2902* mode of operation, where we sync the TSF to RootAP TSF values2903*/2904void2905ar9300_force_tsf_sync(struct ath_hal *ah, const u_int8_t *bssid,2906u_int16_t assoc_id)2907{2908ar9300_set_operating_mode(ah, HAL_M_STA);2909ar9300_write_associd(ah, bssid, assoc_id);2910}29112912void ar9300_chk_rssi_update_tx_pwr(struct ath_hal *ah, int rssi)2913{2914struct ath_hal_9300 *ahp = AH9300(ah);2915u_int32_t temp_obdb_reg_val = 0, temp_tcp_reg_val;2916u_int32_t temp_powertx_rate9_reg_val;2917int8_t olpc_power_offset = 0;2918int8_t tmp_olpc_val = 0;2919HAL_RSSI_TX_POWER old_greentx_status;2920u_int8_t target_power_val_t[ar9300_rate_size];2921int8_t tmp_rss1_thr1, tmp_rss1_thr2;29222923if ((AH_PRIVATE(ah)->ah_opmode != HAL_M_STA) ||2924!ah->ah_config.ath_hal_sta_update_tx_pwr_enable) {2925return;2926}29272928old_greentx_status = AH9300(ah)->green_tx_status;2929if (ahp->ah_hw_green_tx_enable) {2930tmp_rss1_thr1 = AR9485_HW_GREEN_TX_THRES1_DB;2931tmp_rss1_thr2 = AR9485_HW_GREEN_TX_THRES2_DB;2932} else {2933tmp_rss1_thr1 = WB225_SW_GREEN_TX_THRES1_DB;2934tmp_rss1_thr2 = WB225_SW_GREEN_TX_THRES2_DB;2935}29362937if ((ah->ah_config.ath_hal_sta_update_tx_pwr_enable_S1)2938&& (rssi > tmp_rss1_thr1))2939{2940if (old_greentx_status != HAL_RSSI_TX_POWER_SHORT) {2941AH9300(ah)->green_tx_status = HAL_RSSI_TX_POWER_SHORT;2942}2943} else if (ah->ah_config.ath_hal_sta_update_tx_pwr_enable_S22944&& (rssi > tmp_rss1_thr2))2945{2946if (old_greentx_status != HAL_RSSI_TX_POWER_MIDDLE) {2947AH9300(ah)->green_tx_status = HAL_RSSI_TX_POWER_MIDDLE;2948}2949} else if (ah->ah_config.ath_hal_sta_update_tx_pwr_enable_S3) {2950if (old_greentx_status != HAL_RSSI_TX_POWER_LONG) {2951AH9300(ah)->green_tx_status = HAL_RSSI_TX_POWER_LONG;2952}2953}29542955/* If status is not change, don't do anything */2956if (old_greentx_status == AH9300(ah)->green_tx_status) {2957return;2958}29592960/* for Poseidon which ath_hal_sta_update_tx_pwr_enable is enabled */2961if ((AH9300(ah)->green_tx_status != HAL_RSSI_TX_POWER_NONE)2962&& AR_SREV_POSEIDON(ah))2963{2964if (ahp->ah_hw_green_tx_enable) {2965switch (AH9300(ah)->green_tx_status) {2966case HAL_RSSI_TX_POWER_SHORT:2967/* 1. TxPower Config */2968OS_MEMCPY(target_power_val_t, ar9485_hw_gtx_tp_distance_short,2969sizeof(target_power_val_t));2970/* 1.1 Store OLPC Delta Calibration Offset*/2971olpc_power_offset = 0;2972/* 2. Store OB/DB */2973/* 3. Store TPC settting */2974temp_tcp_reg_val = (SM(14, AR_TPC_ACK) |2975SM(14, AR_TPC_CTS) |2976SM(14, AR_TPC_CHIRP) |2977SM(14, AR_TPC_RPT));2978/* 4. Store BB_powertx_rate9 value */2979temp_powertx_rate9_reg_val =2980AR9485_BBPWRTXRATE9_HW_GREEN_TX_SHORT_VALUE;2981break;2982case HAL_RSSI_TX_POWER_MIDDLE:2983/* 1. TxPower Config */2984OS_MEMCPY(target_power_val_t, ar9485_hw_gtx_tp_distance_middle,2985sizeof(target_power_val_t));2986/* 1.1 Store OLPC Delta Calibration Offset*/2987olpc_power_offset = 0;2988/* 2. Store OB/DB */2989/* 3. Store TPC settting */2990temp_tcp_reg_val = (SM(18, AR_TPC_ACK) |2991SM(18, AR_TPC_CTS) |2992SM(18, AR_TPC_CHIRP) |2993SM(18, AR_TPC_RPT));2994/* 4. Store BB_powertx_rate9 value */2995temp_powertx_rate9_reg_val =2996AR9485_BBPWRTXRATE9_HW_GREEN_TX_MIDDLE_VALUE;2997break;2998case HAL_RSSI_TX_POWER_LONG:2999default:3000/* 1. TxPower Config */3001OS_MEMCPY(target_power_val_t, ahp->ah_default_tx_power,3002sizeof(target_power_val_t));3003/* 1.1 Store OLPC Delta Calibration Offset*/3004olpc_power_offset = 0;3005/* 2. Store OB/DB1/DB2 */3006/* 3. Store TPC settting */3007temp_tcp_reg_val =3008AH9300(ah)->ah_ob_db1[POSEIDON_STORED_REG_TPC];3009/* 4. Store BB_powertx_rate9 value */3010temp_powertx_rate9_reg_val =3011AH9300(ah)->ah_ob_db1[POSEIDON_STORED_REG_BB_PWRTX_RATE9];3012break;3013}3014} else {3015switch (AH9300(ah)->green_tx_status) {3016case HAL_RSSI_TX_POWER_SHORT:3017/* 1. TxPower Config */3018OS_MEMCPY(target_power_val_t, wb225_sw_gtx_tp_distance_short,3019sizeof(target_power_val_t));3020/* 1.1 Store OLPC Delta Calibration Offset*/3021olpc_power_offset =3022wb225_gtx_olpc_cal_offset[WB225_OB_GREEN_TX_SHORT_VALUE] -3023wb225_gtx_olpc_cal_offset[WB225_OB_CALIBRATION_VALUE];3024/* 2. Store OB/DB */3025temp_obdb_reg_val =3026AH9300(ah)->ah_ob_db1[POSEIDON_STORED_REG_OBDB];3027temp_obdb_reg_val &= ~(AR_PHY_65NM_CH0_TXRF2_DB2G |3028AR_PHY_65NM_CH0_TXRF2_OB2G_CCK |3029AR_PHY_65NM_CH0_TXRF2_OB2G_PSK |3030AR_PHY_65NM_CH0_TXRF2_OB2G_QAM);3031temp_obdb_reg_val |= (SM(5, AR_PHY_65NM_CH0_TXRF2_DB2G) |3032SM(WB225_OB_GREEN_TX_SHORT_VALUE,3033AR_PHY_65NM_CH0_TXRF2_OB2G_CCK) |3034SM(WB225_OB_GREEN_TX_SHORT_VALUE,3035AR_PHY_65NM_CH0_TXRF2_OB2G_PSK) |3036SM(WB225_OB_GREEN_TX_SHORT_VALUE,3037AR_PHY_65NM_CH0_TXRF2_OB2G_QAM));3038/* 3. Store TPC settting */3039temp_tcp_reg_val = (SM(6, AR_TPC_ACK) |3040SM(6, AR_TPC_CTS) |3041SM(6, AR_TPC_CHIRP) |3042SM(6, AR_TPC_RPT));3043/* 4. Store BB_powertx_rate9 value */3044temp_powertx_rate9_reg_val =3045WB225_BBPWRTXRATE9_SW_GREEN_TX_SHORT_VALUE;3046break;3047case HAL_RSSI_TX_POWER_MIDDLE:3048/* 1. TxPower Config */3049OS_MEMCPY(target_power_val_t, wb225_sw_gtx_tp_distance_middle,3050sizeof(target_power_val_t));3051/* 1.1 Store OLPC Delta Calibration Offset*/3052olpc_power_offset =3053wb225_gtx_olpc_cal_offset[WB225_OB_GREEN_TX_MIDDLE_VALUE] -3054wb225_gtx_olpc_cal_offset[WB225_OB_CALIBRATION_VALUE];3055/* 2. Store OB/DB */3056temp_obdb_reg_val =3057AH9300(ah)->ah_ob_db1[POSEIDON_STORED_REG_OBDB];3058temp_obdb_reg_val &= ~(AR_PHY_65NM_CH0_TXRF2_DB2G |3059AR_PHY_65NM_CH0_TXRF2_OB2G_CCK |3060AR_PHY_65NM_CH0_TXRF2_OB2G_PSK |3061AR_PHY_65NM_CH0_TXRF2_OB2G_QAM);3062temp_obdb_reg_val |= (SM(5, AR_PHY_65NM_CH0_TXRF2_DB2G) |3063SM(WB225_OB_GREEN_TX_MIDDLE_VALUE,3064AR_PHY_65NM_CH0_TXRF2_OB2G_CCK) |3065SM(WB225_OB_GREEN_TX_MIDDLE_VALUE,3066AR_PHY_65NM_CH0_TXRF2_OB2G_PSK) |3067SM(WB225_OB_GREEN_TX_MIDDLE_VALUE,3068AR_PHY_65NM_CH0_TXRF2_OB2G_QAM));3069/* 3. Store TPC settting */3070temp_tcp_reg_val = (SM(14, AR_TPC_ACK) |3071SM(14, AR_TPC_CTS) |3072SM(14, AR_TPC_CHIRP) |3073SM(14, AR_TPC_RPT));3074/* 4. Store BB_powertx_rate9 value */3075temp_powertx_rate9_reg_val =3076WB225_BBPWRTXRATE9_SW_GREEN_TX_MIDDLE_VALUE;3077break;3078case HAL_RSSI_TX_POWER_LONG:3079default:3080/* 1. TxPower Config */3081OS_MEMCPY(target_power_val_t, ahp->ah_default_tx_power,3082sizeof(target_power_val_t));3083/* 1.1 Store OLPC Delta Calibration Offset*/3084olpc_power_offset =3085wb225_gtx_olpc_cal_offset[WB225_OB_GREEN_TX_LONG_VALUE] -3086wb225_gtx_olpc_cal_offset[WB225_OB_CALIBRATION_VALUE];3087/* 2. Store OB/DB1/DB2 */3088temp_obdb_reg_val =3089AH9300(ah)->ah_ob_db1[POSEIDON_STORED_REG_OBDB];3090/* 3. Store TPC settting */3091temp_tcp_reg_val =3092AH9300(ah)->ah_ob_db1[POSEIDON_STORED_REG_TPC];3093/* 4. Store BB_powertx_rate9 value */3094temp_powertx_rate9_reg_val =3095AH9300(ah)->ah_ob_db1[POSEIDON_STORED_REG_BB_PWRTX_RATE9];3096break;3097}3098}3099/* 1.1 Do OLPC Delta Calibration Offset */3100tmp_olpc_val =3101(int8_t) AH9300(ah)->ah_db2[POSEIDON_STORED_REG_G2_OLPC_OFFSET];3102tmp_olpc_val += olpc_power_offset;3103OS_REG_RMW(ah, AR_PHY_TPC_11_B0,3104(tmp_olpc_val << AR_PHY_TPC_OLPC_GAIN_DELTA_S),3105AR_PHY_TPC_OLPC_GAIN_DELTA);31063107/* 1.2 TxPower Config */3108ar9300_transmit_power_reg_write(ah, target_power_val_t);3109/* 2. Config OB/DB */3110if (!ahp->ah_hw_green_tx_enable) {3111OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TXRF2, temp_obdb_reg_val);3112}3113/* 3. config TPC settting */3114OS_REG_WRITE(ah, AR_TPC, temp_tcp_reg_val);3115/* 4. config BB_powertx_rate9 value */3116OS_REG_WRITE(ah, AR_PHY_BB_POWERTX_RATE9, temp_powertx_rate9_reg_val);3117}3118}31193120#if 03121void3122ar9300_get_vow_stats(3123struct ath_hal *ah, HAL_VOWSTATS* p_stats, u_int8_t vow_reg_flags)3124{3125if (vow_reg_flags & AR_REG_TX_FRM_CNT) {3126p_stats->tx_frame_count = OS_REG_READ(ah, AR_TFCNT);3127}3128if (vow_reg_flags & AR_REG_RX_FRM_CNT) {3129p_stats->rx_frame_count = OS_REG_READ(ah, AR_RFCNT);3130}3131if (vow_reg_flags & AR_REG_RX_CLR_CNT) {3132p_stats->rx_clear_count = OS_REG_READ(ah, AR_RCCNT);3133}3134if (vow_reg_flags & AR_REG_CYCLE_CNT) {3135p_stats->cycle_count = OS_REG_READ(ah, AR_CCCNT);3136}3137if (vow_reg_flags & AR_REG_EXT_CYCLE_CNT) {3138p_stats->ext_cycle_count = OS_REG_READ(ah, AR_EXTRCCNT);3139}3140}3141#endif31423143/*3144* ar9300_is_skip_paprd_by_greentx3145*3146* This function check if we need to skip PAPRD tuning3147* when GreenTx in specific state.3148*/3149HAL_BOOL3150ar9300_is_skip_paprd_by_greentx(struct ath_hal *ah)3151{3152if (AR_SREV_POSEIDON(ah) &&3153ah->ah_config.ath_hal_sta_update_tx_pwr_enable &&3154((AH9300(ah)->green_tx_status == HAL_RSSI_TX_POWER_SHORT) ||3155(AH9300(ah)->green_tx_status == HAL_RSSI_TX_POWER_MIDDLE)))3156{3157return AH_TRUE;3158}3159return AH_FALSE;3160}31613162void3163ar9300_control_signals_for_green_tx_mode(struct ath_hal *ah)3164{3165unsigned int valid_obdb_0_b0 = 0x2d; // 5,5 - dB[0:2],oB[5:3]3166unsigned int valid_obdb_1_b0 = 0x25; // 4,5 - dB[0:2],oB[5:3]3167unsigned int valid_obdb_2_b0 = 0x1d; // 3,5 - dB[0:2],oB[5:3]3168unsigned int valid_obdb_3_b0 = 0x15; // 2,5 - dB[0:2],oB[5:3]3169unsigned int valid_obdb_4_b0 = 0xd; // 1,5 - dB[0:2],oB[5:3]3170struct ath_hal_9300 *ahp = AH9300(ah);31713172if (AR_SREV_POSEIDON(ah) && ahp->ah_hw_green_tx_enable) {3173OS_REG_RMW_FIELD_ALT(ah, AR_PHY_PAPRD_VALID_OBDB_POSEIDON,3174AR_PHY_PAPRD_VALID_OBDB_0, valid_obdb_0_b0);3175OS_REG_RMW_FIELD_ALT(ah, AR_PHY_PAPRD_VALID_OBDB_POSEIDON,3176AR_PHY_PAPRD_VALID_OBDB_1, valid_obdb_1_b0);3177OS_REG_RMW_FIELD_ALT(ah, AR_PHY_PAPRD_VALID_OBDB_POSEIDON,3178AR_PHY_PAPRD_VALID_OBDB_2, valid_obdb_2_b0);3179OS_REG_RMW_FIELD_ALT(ah, AR_PHY_PAPRD_VALID_OBDB_POSEIDON,3180AR_PHY_PAPRD_VALID_OBDB_3, valid_obdb_3_b0);3181OS_REG_RMW_FIELD_ALT(ah, AR_PHY_PAPRD_VALID_OBDB_POSEIDON,3182AR_PHY_PAPRD_VALID_OBDB_4, valid_obdb_4_b0);3183}3184}31853186void ar9300_hwgreentx_set_pal_spare(struct ath_hal *ah, int value)3187{3188struct ath_hal_9300 *ahp = AH9300(ah);31893190if (AR_SREV_POSEIDON(ah) && ahp->ah_hw_green_tx_enable) {3191if ((value == 0) || (value == 1)) {3192OS_REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_TXRF3,3193AR_PHY_65NM_CH0_TXRF3_OLD_PAL_SPARE, value);3194}3195}3196}31973198void ar9300_reset_hw_beacon_proc_crc(struct ath_hal *ah)3199{3200OS_REG_SET_BIT(ah, AR_HWBCNPROC1, AR_HWBCNPROC1_RESET_CRC);3201}32023203int32_t ar9300_get_hw_beacon_rssi(struct ath_hal *ah)3204{3205int32_t val = OS_REG_READ_FIELD(ah, AR_BCN_RSSI_AVE, AR_BCN_RSSI_AVE_VAL);32063207/* RSSI format is 8.4. Ignore lowest four bits */3208val = val >> 4;3209return val;3210}32113212void ar9300_set_hw_beacon_rssi_threshold(struct ath_hal *ah,3213u_int32_t rssi_threshold)3214{3215struct ath_hal_9300 *ahp = AH9300(ah);32163217OS_REG_RMW_FIELD(ah, AR_RSSI_THR, AR_RSSI_THR_VAL, rssi_threshold);32183219/* save value for restoring after chip reset */3220ahp->ah_beacon_rssi_threshold = rssi_threshold;3221}32223223void ar9300_reset_hw_beacon_rssi(struct ath_hal *ah)3224{3225OS_REG_SET_BIT(ah, AR_RSSI_THR, AR_RSSI_BCN_RSSI_RST);3226}32273228void ar9300_set_hw_beacon_proc(struct ath_hal *ah, HAL_BOOL on)3229{3230if (on) {3231OS_REG_SET_BIT(ah, AR_HWBCNPROC1, AR_HWBCNPROC1_CRC_ENABLE |3232AR_HWBCNPROC1_EXCLUDE_TIM_ELM);3233}3234else {3235OS_REG_CLR_BIT(ah, AR_HWBCNPROC1, AR_HWBCNPROC1_CRC_ENABLE |3236AR_HWBCNPROC1_EXCLUDE_TIM_ELM);3237}3238}3239/*3240* Gets the contents of the specified key cache entry.3241*/3242HAL_BOOL3243ar9300_print_keycache(struct ath_hal *ah)3244{32453246const HAL_CAPABILITIES *p_cap = &AH_PRIVATE(ah)->ah_caps;3247u_int32_t key0, key1, key2, key3, key4;3248u_int32_t mac_hi, mac_lo;3249u_int16_t entry = 0;3250u_int32_t valid = 0;3251u_int32_t key_type;32523253ath_hal_printf(ah, "Slot Key\t\t\t Valid Type Mac \n");32543255for (entry = 0 ; entry < p_cap->halKeyCacheSize; entry++) {3256key0 = OS_REG_READ(ah, AR_KEYTABLE_KEY0(entry));3257key1 = OS_REG_READ(ah, AR_KEYTABLE_KEY1(entry));3258key2 = OS_REG_READ(ah, AR_KEYTABLE_KEY2(entry));3259key3 = OS_REG_READ(ah, AR_KEYTABLE_KEY3(entry));3260key4 = OS_REG_READ(ah, AR_KEYTABLE_KEY4(entry));32613262key_type = OS_REG_READ(ah, AR_KEYTABLE_TYPE(entry));32633264mac_lo = OS_REG_READ(ah, AR_KEYTABLE_MAC0(entry));3265mac_hi = OS_REG_READ(ah, AR_KEYTABLE_MAC1(entry));32663267if (mac_hi & AR_KEYTABLE_VALID) {3268valid = 1;3269} else {3270valid = 0;3271}32723273if ((mac_hi != 0) && (mac_lo != 0)) {3274mac_hi &= ~0x8000;3275mac_hi <<= 1;3276mac_hi |= ((mac_lo & (1 << 31) )) >> 31;3277mac_lo <<= 1;3278}32793280ath_hal_printf(ah,3281"%03d "3282"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"3283" %02d %02d "3284"%02x:%02x:%02x:%02x:%02x:%02x \n",3285entry,3286(key0 << 24) >> 24, (key0 << 16) >> 24,3287(key0 << 8) >> 24, key0 >> 24,3288(key1 << 24) >> 24, (key1 << 16) >> 24,3289//(key1 << 8) >> 24, key1 >> 24,3290(key2 << 24) >> 24, (key2 << 16) >> 24,3291(key2 << 8) >> 24, key2 >> 24,3292(key3 << 24) >> 24, (key3 << 16) >> 24,3293//(key3 << 8) >> 24, key3 >> 24,3294(key4 << 24) >> 24, (key4 << 16) >> 24,3295(key4 << 8) >> 24, key4 >> 24,3296valid, key_type,3297(mac_lo << 24) >> 24, (mac_lo << 16) >> 24, (mac_lo << 8) >> 24,3298(mac_lo) >> 24, (mac_hi << 24) >> 24, (mac_hi << 16) >> 24 );3299}33003301return AH_TRUE;3302}33033304/* enable/disable smart antenna mode */3305HAL_BOOL3306ar9300_set_smart_antenna(struct ath_hal *ah, HAL_BOOL enable)3307{3308struct ath_hal_9300 *ahp = AH9300(ah);33093310if (enable) {3311OS_REG_SET_BIT(ah, AR_XRTO, AR_ENABLE_SMARTANTENNA);3312} else {3313OS_REG_CLR_BIT(ah, AR_XRTO, AR_ENABLE_SMARTANTENNA);3314}33153316/* if scropion and smart antenna is enabled, write swcom1 with 0x4403317* and swcom2 with 03318* FIXME Ideally these registers need to be made read from caldata.3319* Until the calibration team gets them, keep them along with board3320* configuration.3321*/3322if (enable && AR_SREV_SCORPION(ah) &&3323(HAL_OK == ar9300_get_capability(ah, HAL_CAP_SMARTANTENNA, 0,0))) {33243325OS_REG_WRITE(ah, AR_PHY_SWITCH_COM, 0x440);3326OS_REG_WRITE(ah, AR_PHY_SWITCH_COM_2, 0);3327}33283329ahp->ah_smartantenna_enable = enable;3330return 1;3331}33323333#ifdef ATH_TX99_DIAG3334#ifndef ATH_SUPPORT_HTC3335void3336ar9300_tx99_channel_pwr_update(struct ath_hal *ah, HAL_CHANNEL *c,3337u_int32_t txpower)3338{3339#define PWR_MAS(_r, _s) (((_r) & 0x3f) << (_s))3340static int16_t p_pwr_array[ar9300_rate_size] = { 0 };3341int32_t i;33423343/* The max power is limited to 63 */3344if (txpower <= AR9300_MAX_RATE_POWER) {3345for (i = 0; i < ar9300_rate_size; i++) {3346p_pwr_array[i] = txpower;3347}3348} else {3349for (i = 0; i < ar9300_rate_size; i++) {3350p_pwr_array[i] = AR9300_MAX_RATE_POWER;3351}3352}33533354OS_REG_WRITE(ah, 0xa458, 0);33553356/* Write the OFDM power per rate set */3357/* 6 (LSB), 9, 12, 18 (MSB) */3358OS_REG_WRITE(ah, 0xa3c0,3359PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_6_24], 24)3360| PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_6_24], 16)3361| PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_6_24], 8)3362| PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_6_24], 0)3363);3364/* 24 (LSB), 36, 48, 54 (MSB) */3365OS_REG_WRITE(ah, 0xa3c4,3366PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_54], 24)3367| PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_48], 16)3368| PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_36], 8)3369| PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_6_24], 0)3370);33713372/* Write the CCK power per rate set */3373/* 1L (LSB), reserved, 2L, 2S (MSB) */3374OS_REG_WRITE(ah, 0xa3c8,3375PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 24)3376| PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 16)3377/* | PWR_MAS(txPowerTimes2, 8) */ /* this is reserved for Osprey */3378| PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 0)3379);3380/* 5.5L (LSB), 5.5S, 11L, 11S (MSB) */3381OS_REG_WRITE(ah, 0xa3cc,3382PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_11S], 24)3383| PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_11L], 16)3384| PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_5S], 8)3385| PWR_MAS(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 0)3386);33873388/* Write the HT20 power per rate set */3389/* 0/8/16 (LSB), 1-3/9-11/17-19, 4, 5 (MSB) */3390OS_REG_WRITE(ah, 0xa3d0,3391PWR_MAS(p_pwr_array[ALL_TARGET_HT20_5], 24)3392| PWR_MAS(p_pwr_array[ALL_TARGET_HT20_4], 16)3393| PWR_MAS(p_pwr_array[ALL_TARGET_HT20_1_3_9_11_17_19], 8)3394| PWR_MAS(p_pwr_array[ALL_TARGET_HT20_0_8_16], 0)3395);33963397/* 6 (LSB), 7, 12, 13 (MSB) */3398OS_REG_WRITE(ah, 0xa3d4,3399PWR_MAS(p_pwr_array[ALL_TARGET_HT20_13], 24)3400| PWR_MAS(p_pwr_array[ALL_TARGET_HT20_12], 16)3401| PWR_MAS(p_pwr_array[ALL_TARGET_HT20_7], 8)3402| PWR_MAS(p_pwr_array[ALL_TARGET_HT20_6], 0)3403);34043405/* 14 (LSB), 15, 20, 21 */3406OS_REG_WRITE(ah, 0xa3e4,3407PWR_MAS(p_pwr_array[ALL_TARGET_HT20_21], 24)3408| PWR_MAS(p_pwr_array[ALL_TARGET_HT20_20], 16)3409| PWR_MAS(p_pwr_array[ALL_TARGET_HT20_15], 8)3410| PWR_MAS(p_pwr_array[ALL_TARGET_HT20_14], 0)3411);34123413/* Mixed HT20 and HT40 rates */3414/* HT20 22 (LSB), HT20 23, HT40 22, HT40 23 (MSB) */3415OS_REG_WRITE(ah, 0xa3e8,3416PWR_MAS(p_pwr_array[ALL_TARGET_HT40_23], 24)3417| PWR_MAS(p_pwr_array[ALL_TARGET_HT40_22], 16)3418| PWR_MAS(p_pwr_array[ALL_TARGET_HT20_23], 8)3419| PWR_MAS(p_pwr_array[ALL_TARGET_HT20_22], 0)3420);34213422/* Write the HT40 power per rate set */3423/* correct PAR difference between HT40 and HT20/LEGACY */3424/* 0/8/16 (LSB), 1-3/9-11/17-19, 4, 5 (MSB) */3425OS_REG_WRITE(ah, 0xa3d8,3426PWR_MAS(p_pwr_array[ALL_TARGET_HT40_5], 24)3427| PWR_MAS(p_pwr_array[ALL_TARGET_HT40_4], 16)3428| PWR_MAS(p_pwr_array[ALL_TARGET_HT40_1_3_9_11_17_19], 8)3429| PWR_MAS(p_pwr_array[ALL_TARGET_HT40_0_8_16], 0)3430);34313432/* 6 (LSB), 7, 12, 13 (MSB) */3433OS_REG_WRITE(ah, 0xa3dc,3434PWR_MAS(p_pwr_array[ALL_TARGET_HT40_13], 24)3435| PWR_MAS(p_pwr_array[ALL_TARGET_HT40_12], 16)3436| PWR_MAS(p_pwr_array[ALL_TARGET_HT40_7], 8)3437| PWR_MAS(p_pwr_array[ALL_TARGET_HT40_6], 0)3438);34393440/* 14 (LSB), 15, 20, 21 */3441OS_REG_WRITE(ah, 0xa3ec,3442PWR_MAS(p_pwr_array[ALL_TARGET_HT40_21], 24)3443| PWR_MAS(p_pwr_array[ALL_TARGET_HT40_20], 16)3444| PWR_MAS(p_pwr_array[ALL_TARGET_HT40_15], 8)3445| PWR_MAS(p_pwr_array[ALL_TARGET_HT40_14], 0)3446);3447#undef PWR_MAS3448}34493450void3451ar9300_tx99_chainmsk_setup(struct ath_hal *ah, int tx_chainmask)3452{3453if (tx_chainmask == 0x5) {3454OS_REG_WRITE(ah, AR_PHY_ANALOG_SWAP,3455OS_REG_READ(ah, AR_PHY_ANALOG_SWAP) | AR_PHY_SWAP_ALT_CHAIN);3456}3457OS_REG_WRITE(ah, AR_PHY_RX_CHAINMASK, tx_chainmask);3458OS_REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, tx_chainmask);34593460OS_REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);3461if (tx_chainmask == 0x5) {3462OS_REG_WRITE(ah, AR_PHY_ANALOG_SWAP,3463OS_REG_READ(ah, AR_PHY_ANALOG_SWAP) | AR_PHY_SWAP_ALT_CHAIN);3464}3465}34663467void3468ar9300_tx99_set_single_carrier(struct ath_hal *ah, int tx_chain_mask,3469int chtype)3470{3471OS_REG_WRITE(ah, 0x98a4, OS_REG_READ(ah, 0x98a4) | (0x7ff << 11) | 0x7ff);3472OS_REG_WRITE(ah, 0xa364, OS_REG_READ(ah, 0xa364) | (1 << 7) | (1 << 1));3473OS_REG_WRITE(ah, 0xa350,3474(OS_REG_READ(ah, 0xa350) | (1 << 31) | (1 << 15)) & ~(1 << 13));34753476/* 11G mode */3477if (!chtype) {3478OS_REG_WRITE(ah, AR_PHY_65NM_CH0_RXTX2,3479OS_REG_READ(ah, AR_PHY_65NM_CH0_RXTX2) | (0x1 << 3) | (0x1 << 2));3480if (AR_SREV_OSPREY(ah) || AR_SREV_WASP(ah)) {3481OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TOP,3482OS_REG_READ(ah, AR_PHY_65NM_CH0_TOP) & ~(0x1 << 4));3483OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TOP2,3484(OS_REG_READ(ah, AR_PHY_65NM_CH0_TOP2)3485| (0x1 << 26) | (0x7 << 24))3486& ~(0x1 << 22));3487} else {3488OS_REG_WRITE(ah, AR_HORNET_CH0_TOP,3489OS_REG_READ(ah, AR_HORNET_CH0_TOP) & ~(0x1 << 4));3490OS_REG_WRITE(ah, AR_HORNET_CH0_TOP2,3491(OS_REG_READ(ah, AR_HORNET_CH0_TOP2)3492| (0x1 << 26) | (0x7 << 24))3493& ~(0x1 << 22));3494}34953496/* chain zero */3497if ((tx_chain_mask & 0x01) == 0x01) {3498OS_REG_WRITE(ah, AR_PHY_65NM_CH0_RXTX1,3499(OS_REG_READ(ah, AR_PHY_65NM_CH0_RXTX1)3500| (0x1 << 31) | (0x5 << 15)3501| (0x3 << 9)) & ~(0x1 << 27)3502& ~(0x1 << 12));3503OS_REG_WRITE(ah, AR_PHY_65NM_CH0_RXTX2,3504(OS_REG_READ(ah, AR_PHY_65NM_CH0_RXTX2)3505| (0x1 << 12) | (0x1 << 10)3506| (0x1 << 9) | (0x1 << 8)3507| (0x1 << 7)) & ~(0x1 << 11));3508OS_REG_WRITE(ah, AR_PHY_65NM_CH0_RXTX3,3509(OS_REG_READ(ah, AR_PHY_65NM_CH0_RXTX3)3510| (0x1 << 29) | (0x1 << 25)3511| (0x1 << 23) | (0x1 << 19)3512| (0x1 << 10) | (0x1 << 9)3513| (0x1 << 8) | (0x1 << 3))3514& ~(0x1 << 28)& ~(0x1 << 24)3515& ~(0x1 << 22)& ~(0x1 << 7));3516OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TXRF1,3517(OS_REG_READ(ah, AR_PHY_65NM_CH0_TXRF1)3518| (0x1 << 23))& ~(0x1 << 21));3519OS_REG_WRITE(ah, AR_PHY_65NM_CH0_BB1,3520OS_REG_READ(ah, AR_PHY_65NM_CH0_BB1)3521| (0x1 << 12) | (0x1 << 10)3522| (0x1 << 9) | (0x1 << 8)3523| (0x1 << 6) | (0x1 << 5)3524| (0x1 << 4) | (0x1 << 3)3525| (0x1 << 2));3526OS_REG_WRITE(ah, AR_PHY_65NM_CH0_BB2,3527OS_REG_READ(ah, AR_PHY_65NM_CH0_BB2) | (0x1 << 31));3528}3529if (AR_SREV_OSPREY(ah) || AR_SREV_WASP(ah)) {3530/* chain one */3531if ((tx_chain_mask & 0x02) == 0x02 ) {3532OS_REG_WRITE(ah, AR_PHY_65NM_CH1_RXTX1,3533(OS_REG_READ(ah, AR_PHY_65NM_CH1_RXTX1)3534| (0x1 << 31) | (0x5 << 15)3535| (0x3 << 9)) & ~(0x1 << 27)3536& ~(0x1 << 12));3537OS_REG_WRITE(ah, AR_PHY_65NM_CH1_RXTX2,3538(OS_REG_READ(ah, AR_PHY_65NM_CH1_RXTX2)3539| (0x1 << 12) | (0x1 << 10)3540| (0x1 << 9) | (0x1 << 8)3541| (0x1 << 7)) & ~(0x1 << 11));3542OS_REG_WRITE(ah, AR_PHY_65NM_CH1_RXTX3,3543(OS_REG_READ(ah, AR_PHY_65NM_CH1_RXTX3)3544| (0x1 << 29) | (0x1 << 25)3545| (0x1 << 23) | (0x1 << 19)3546| (0x1 << 10) | (0x1 << 9)3547| (0x1 << 8) | (0x1 << 3))3548& ~(0x1 << 28)& ~(0x1 << 24)3549& ~(0x1 << 22)& ~(0x1 << 7));3550OS_REG_WRITE(ah, AR_PHY_65NM_CH1_TXRF1,3551(OS_REG_READ(ah, AR_PHY_65NM_CH1_TXRF1)3552| (0x1 << 23))& ~(0x1 << 21));3553OS_REG_WRITE(ah, AR_PHY_65NM_CH1_BB1,3554OS_REG_READ(ah, AR_PHY_65NM_CH1_BB1)3555| (0x1 << 12) | (0x1 << 10)3556| (0x1 << 9) | (0x1 << 8)3557| (0x1 << 6) | (0x1 << 5)3558| (0x1 << 4) | (0x1 << 3)3559| (0x1 << 2));3560OS_REG_WRITE(ah, AR_PHY_65NM_CH1_BB2,3561OS_REG_READ(ah, AR_PHY_65NM_CH1_BB2) | (0x1 << 31));3562}3563}3564if (AR_SREV_OSPREY(ah)) {3565/* chain two */3566if ((tx_chain_mask & 0x04) == 0x04 ) {3567OS_REG_WRITE(ah, AR_PHY_65NM_CH2_RXTX1,3568(OS_REG_READ(ah, AR_PHY_65NM_CH2_RXTX1)3569| (0x1 << 31) | (0x5 << 15)3570| (0x3 << 9)) & ~(0x1 << 27)3571& ~(0x1 << 12));3572OS_REG_WRITE(ah, AR_PHY_65NM_CH2_RXTX2,3573(OS_REG_READ(ah, AR_PHY_65NM_CH2_RXTX2)3574| (0x1 << 12) | (0x1 << 10)3575| (0x1 << 9) | (0x1 << 8)3576| (0x1 << 7)) & ~(0x1 << 11));3577OS_REG_WRITE(ah, AR_PHY_65NM_CH2_RXTX3,3578(OS_REG_READ(ah, AR_PHY_65NM_CH2_RXTX3)3579| (0x1 << 29) | (0x1 << 25)3580| (0x1 << 23) | (0x1 << 19)3581| (0x1 << 10) | (0x1 << 9)3582| (0x1 << 8) | (0x1 << 3))3583& ~(0x1 << 28)& ~(0x1 << 24)3584& ~(0x1 << 22)& ~(0x1 << 7));3585OS_REG_WRITE(ah, AR_PHY_65NM_CH2_TXRF1,3586(OS_REG_READ(ah, AR_PHY_65NM_CH2_TXRF1)3587| (0x1 << 23))& ~(0x1 << 21));3588OS_REG_WRITE(ah, AR_PHY_65NM_CH2_BB1,3589OS_REG_READ(ah, AR_PHY_65NM_CH2_BB1)3590| (0x1 << 12) | (0x1 << 10)3591| (0x1 << 9) | (0x1 << 8)3592| (0x1 << 6) | (0x1 << 5)3593| (0x1 << 4) | (0x1 << 3)3594| (0x1 << 2));3595OS_REG_WRITE(ah, AR_PHY_65NM_CH2_BB2,3596OS_REG_READ(ah, AR_PHY_65NM_CH2_BB2) | (0x1 << 31));3597}3598}35993600OS_REG_WRITE(ah, 0xa28c, 0x11111);3601OS_REG_WRITE(ah, 0xa288, 0x111);3602} else {3603/* chain zero */3604if ((tx_chain_mask & 0x01) == 0x01) {3605OS_REG_WRITE(ah, AR_PHY_65NM_CH0_RXTX1,3606(OS_REG_READ(ah, AR_PHY_65NM_CH0_RXTX1)3607| (0x1 << 31) | (0x1 << 27)3608| (0x3 << 23) | (0x1 << 19)3609| (0x1 << 15) | (0x3 << 9))3610& ~(0x1 << 12));3611OS_REG_WRITE(ah, AR_PHY_65NM_CH0_RXTX2,3612(OS_REG_READ(ah, AR_PHY_65NM_CH0_RXTX2)3613| (0x1 << 12) | (0x1 << 10)3614| (0x1 << 9) | (0x1 << 8)3615| (0x1 << 7) | (0x1 << 3)3616| (0x1 << 2) | (0x1 << 1))3617& ~(0x1 << 11)& ~(0x1 << 0));3618OS_REG_WRITE(ah, AR_PHY_65NM_CH0_RXTX3,3619(OS_REG_READ(ah, AR_PHY_65NM_CH0_RXTX3)3620| (0x1 << 29) | (0x1 << 25)3621| (0x1 << 23) | (0x1 << 19)3622| (0x1 << 10) | (0x1 << 9)3623| (0x1 << 8) | (0x1 << 3))3624& ~(0x1 << 28)& ~(0x1 << 24)3625& ~(0x1 << 22)& ~(0x1 << 7));3626OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TXRF1,3627(OS_REG_READ(ah, AR_PHY_65NM_CH0_TXRF1)3628| (0x1 << 23))& ~(0x1 << 21));3629OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TXRF2,3630OS_REG_READ(ah, AR_PHY_65NM_CH0_TXRF2)3631| (0x3 << 3) | (0x3 << 0));3632OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TXRF3,3633(OS_REG_READ(ah, AR_PHY_65NM_CH0_TXRF3)3634| (0x3 << 29) | (0x3 << 26)3635| (0x2 << 23) | (0x2 << 20)3636| (0x2 << 17))& ~(0x1 << 14));3637OS_REG_WRITE(ah, AR_PHY_65NM_CH0_BB1,3638OS_REG_READ(ah, AR_PHY_65NM_CH0_BB1)3639| (0x1 << 12) | (0x1 << 10)3640| (0x1 << 9) | (0x1 << 8)3641| (0x1 << 6) | (0x1 << 5)3642| (0x1 << 4) | (0x1 << 3)3643| (0x1 << 2));3644OS_REG_WRITE(ah, AR_PHY_65NM_CH0_BB2,3645OS_REG_READ(ah, AR_PHY_65NM_CH0_BB2) | (0x1 << 31));3646if (AR_SREV_OSPREY(ah) || AR_SREV_WASP(ah)) {3647OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TOP,3648OS_REG_READ(ah, AR_PHY_65NM_CH0_TOP) & ~(0x1 << 4));3649OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TOP2,3650OS_REG_READ(ah, AR_PHY_65NM_CH0_TOP2)3651| (0x1 << 26) | (0x7 << 24)3652| (0x3 << 22));3653} else {3654OS_REG_WRITE(ah, AR_HORNET_CH0_TOP,3655OS_REG_READ(ah, AR_HORNET_CH0_TOP) & ~(0x1 << 4));3656OS_REG_WRITE(ah, AR_HORNET_CH0_TOP2,3657OS_REG_READ(ah, AR_HORNET_CH0_TOP2)3658| (0x1 << 26) | (0x7 << 24)3659| (0x3 << 22));3660}36613662if (AR_SREV_OSPREY(ah) || AR_SREV_WASP(ah)) {3663OS_REG_WRITE(ah, AR_PHY_65NM_CH1_RXTX2,3664(OS_REG_READ(ah, AR_PHY_65NM_CH1_RXTX2)3665| (0x1 << 3) | (0x1 << 2)3666| (0x1 << 1)) & ~(0x1 << 0));3667OS_REG_WRITE(ah, AR_PHY_65NM_CH1_RXTX3,3668OS_REG_READ(ah, AR_PHY_65NM_CH1_RXTX3)3669| (0x1 << 19) | (0x1 << 3));3670OS_REG_WRITE(ah, AR_PHY_65NM_CH1_TXRF1,3671OS_REG_READ(ah, AR_PHY_65NM_CH1_TXRF1) | (0x1 << 23));3672}3673if (AR_SREV_OSPREY(ah)) {3674OS_REG_WRITE(ah, AR_PHY_65NM_CH2_RXTX2,3675(OS_REG_READ(ah, AR_PHY_65NM_CH2_RXTX2)3676| (0x1 << 3) | (0x1 << 2)3677| (0x1 << 1)) & ~(0x1 << 0));3678OS_REG_WRITE(ah, AR_PHY_65NM_CH2_RXTX3,3679OS_REG_READ(ah, AR_PHY_65NM_CH2_RXTX3)3680| (0x1 << 19) | (0x1 << 3));3681OS_REG_WRITE(ah, AR_PHY_65NM_CH2_TXRF1,3682OS_REG_READ(ah, AR_PHY_65NM_CH2_TXRF1) | (0x1 << 23));3683}3684}3685if (AR_SREV_OSPREY(ah) || AR_SREV_WASP(ah)) {3686/* chain one */3687if ((tx_chain_mask & 0x02) == 0x02 ) {3688OS_REG_WRITE(ah, AR_PHY_65NM_CH0_RXTX2,3689(OS_REG_READ(ah, AR_PHY_65NM_CH0_RXTX2)3690| (0x1 << 3) | (0x1 << 2)3691| (0x1 << 1)) & ~(0x1 << 0));3692OS_REG_WRITE(ah, AR_PHY_65NM_CH0_RXTX3,3693OS_REG_READ(ah, AR_PHY_65NM_CH0_RXTX3)3694| (0x1 << 19) | (0x1 << 3));3695OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TXRF1,3696OS_REG_READ(ah, AR_PHY_65NM_CH0_TXRF1) | (0x1 << 23));3697if (AR_SREV_OSPREY(ah) || AR_SREV_WASP(ah)) {3698OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TOP,3699OS_REG_READ(ah, AR_PHY_65NM_CH0_TOP) & ~(0x1 << 4));3700OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TOP2,3701OS_REG_READ(ah, AR_PHY_65NM_CH0_TOP2)3702| (0x1 << 26) | (0x7 << 24)3703| (0x3 << 22));3704} else {3705OS_REG_WRITE(ah, AR_HORNET_CH0_TOP,3706OS_REG_READ(ah, AR_HORNET_CH0_TOP) & ~(0x1 << 4));3707OS_REG_WRITE(ah, AR_HORNET_CH0_TOP2,3708OS_REG_READ(ah, AR_HORNET_CH0_TOP2)3709| (0x1 << 26) | (0x7 << 24)3710| (0x3 << 22));3711}37123713OS_REG_WRITE(ah, AR_PHY_65NM_CH1_RXTX1,3714(OS_REG_READ(ah, AR_PHY_65NM_CH1_RXTX1)3715| (0x1 << 31) | (0x1 << 27)3716| (0x3 << 23) | (0x1 << 19)3717| (0x1 << 15) | (0x3 << 9))3718& ~(0x1 << 12));3719OS_REG_WRITE(ah, AR_PHY_65NM_CH1_RXTX2,3720(OS_REG_READ(ah, AR_PHY_65NM_CH1_RXTX2)3721| (0x1 << 12) | (0x1 << 10)3722| (0x1 << 9) | (0x1 << 8)3723| (0x1 << 7) | (0x1 << 3)3724| (0x1 << 2) | (0x1 << 1))3725& ~(0x1 << 11)& ~(0x1 << 0));3726OS_REG_WRITE(ah, AR_PHY_65NM_CH1_RXTX3,3727(OS_REG_READ(ah, AR_PHY_65NM_CH1_RXTX3)3728| (0x1 << 29) | (0x1 << 25)3729| (0x1 << 23) | (0x1 << 19)3730| (0x1 << 10) | (0x1 << 9)3731| (0x1 << 8) | (0x1 << 3))3732& ~(0x1 << 28)& ~(0x1 << 24)3733& ~(0x1 << 22)& ~(0x1 << 7));3734OS_REG_WRITE(ah, AR_PHY_65NM_CH1_TXRF1,3735(OS_REG_READ(ah, AR_PHY_65NM_CH1_TXRF1)3736| (0x1 << 23))& ~(0x1 << 21));3737OS_REG_WRITE(ah, AR_PHY_65NM_CH1_TXRF2,3738OS_REG_READ(ah, AR_PHY_65NM_CH1_TXRF2)3739| (0x3 << 3) | (0x3 << 0));3740OS_REG_WRITE(ah, AR_PHY_65NM_CH1_TXRF3,3741(OS_REG_READ(ah, AR_PHY_65NM_CH1_TXRF3)3742| (0x3 << 29) | (0x3 << 26)3743| (0x2 << 23) | (0x2 << 20)3744| (0x2 << 17))& ~(0x1 << 14));3745OS_REG_WRITE(ah, AR_PHY_65NM_CH1_BB1,3746OS_REG_READ(ah, AR_PHY_65NM_CH1_BB1)3747| (0x1 << 12) | (0x1 << 10)3748| (0x1 << 9) | (0x1 << 8)3749| (0x1 << 6) | (0x1 << 5)3750| (0x1 << 4) | (0x1 << 3)3751| (0x1 << 2));3752OS_REG_WRITE(ah, AR_PHY_65NM_CH1_BB2,3753OS_REG_READ(ah, AR_PHY_65NM_CH1_BB2) | (0x1 << 31));37543755if (AR_SREV_OSPREY(ah)) {3756OS_REG_WRITE(ah, AR_PHY_65NM_CH2_RXTX2,3757(OS_REG_READ(ah, AR_PHY_65NM_CH2_RXTX2)3758| (0x1 << 3) | (0x1 << 2)3759| (0x1 << 1)) & ~(0x1 << 0));3760OS_REG_WRITE(ah, AR_PHY_65NM_CH2_RXTX3,3761OS_REG_READ(ah, AR_PHY_65NM_CH2_RXTX3)3762| (0x1 << 19) | (0x1 << 3));3763OS_REG_WRITE(ah, AR_PHY_65NM_CH2_TXRF1,3764OS_REG_READ(ah, AR_PHY_65NM_CH2_TXRF1) | (0x1 << 23));3765}3766}3767}3768if (AR_SREV_OSPREY(ah)) {3769/* chain two */3770if ((tx_chain_mask & 0x04) == 0x04 ) {3771OS_REG_WRITE(ah, AR_PHY_65NM_CH0_RXTX2,3772(OS_REG_READ(ah, AR_PHY_65NM_CH0_RXTX2)3773| (0x1 << 3) | (0x1 << 2)3774| (0x1 << 1)) & ~(0x1 << 0));3775OS_REG_WRITE(ah, AR_PHY_65NM_CH0_RXTX3,3776OS_REG_READ(ah, AR_PHY_65NM_CH0_RXTX3)3777| (0x1 << 19) | (0x1 << 3));3778OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TXRF1,3779OS_REG_READ(ah, AR_PHY_65NM_CH0_TXRF1) | (0x1 << 23));3780if (AR_SREV_OSPREY(ah) || AR_SREV_WASP(ah)) {3781OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TOP,3782OS_REG_READ(ah, AR_PHY_65NM_CH0_TOP) & ~(0x1 << 4));3783OS_REG_WRITE(ah, AR_PHY_65NM_CH0_TOP2,3784OS_REG_READ(ah, AR_PHY_65NM_CH0_TOP2)3785| (0x1 << 26) | (0x7 << 24)3786| (0x3 << 22));3787} else {3788OS_REG_WRITE(ah, AR_HORNET_CH0_TOP,3789OS_REG_READ(ah, AR_HORNET_CH0_TOP) & ~(0x1 << 4));3790OS_REG_WRITE(ah, AR_HORNET_CH0_TOP2,3791OS_REG_READ(ah, AR_HORNET_CH0_TOP2)3792| (0x1 << 26) | (0x7 << 24)3793| (0x3 << 22));3794}37953796OS_REG_WRITE(ah, AR_PHY_65NM_CH1_RXTX2,3797(OS_REG_READ(ah, AR_PHY_65NM_CH1_RXTX2)3798| (0x1 << 3) | (0x1 << 2)3799| (0x1 << 1)) & ~(0x1 << 0));3800OS_REG_WRITE(ah, AR_PHY_65NM_CH1_RXTX3,3801OS_REG_READ(ah, AR_PHY_65NM_CH1_RXTX3)3802| (0x1 << 19) | (0x1 << 3));3803OS_REG_WRITE(ah, AR_PHY_65NM_CH1_TXRF1,3804OS_REG_READ(ah, AR_PHY_65NM_CH1_TXRF1) | (0x1 << 23));38053806OS_REG_WRITE(ah, AR_PHY_65NM_CH2_RXTX1,3807(OS_REG_READ(ah, AR_PHY_65NM_CH2_RXTX1)3808| (0x1 << 31) | (0x1 << 27)3809| (0x3 << 23) | (0x1 << 19)3810| (0x1 << 15) | (0x3 << 9))3811& ~(0x1 << 12));3812OS_REG_WRITE(ah, AR_PHY_65NM_CH2_RXTX2,3813(OS_REG_READ(ah, AR_PHY_65NM_CH2_RXTX2)3814| (0x1 << 12) | (0x1 << 10)3815| (0x1 << 9) | (0x1 << 8)3816| (0x1 << 7) | (0x1 << 3)3817| (0x1 << 2) | (0x1 << 1))3818& ~(0x1 << 11)& ~(0x1 << 0));3819OS_REG_WRITE(ah, AR_PHY_65NM_CH2_RXTX3,3820(OS_REG_READ(ah, AR_PHY_65NM_CH2_RXTX3)3821| (0x1 << 29) | (0x1 << 25)3822| (0x1 << 23) | (0x1 << 19)3823| (0x1 << 10) | (0x1 << 9)3824| (0x1 << 8) | (0x1 << 3))3825& ~(0x1 << 28)& ~(0x1 << 24)3826& ~(0x1 << 22)& ~(0x1 << 7));3827OS_REG_WRITE(ah, AR_PHY_65NM_CH2_TXRF1,3828(OS_REG_READ(ah, AR_PHY_65NM_CH2_TXRF1)3829| (0x1 << 23))& ~(0x1 << 21));3830OS_REG_WRITE(ah, AR_PHY_65NM_CH2_TXRF2,3831OS_REG_READ(ah, AR_PHY_65NM_CH2_TXRF2)3832| (0x3 << 3) | (0x3 << 0));3833OS_REG_WRITE(ah, AR_PHY_65NM_CH2_TXRF3,3834(OS_REG_READ(ah, AR_PHY_65NM_CH2_TXRF3)3835| (0x3 << 29) | (0x3 << 26)3836| (0x2 << 23) | (0x2 << 20)3837| (0x2 << 17))& ~(0x1 << 14));3838OS_REG_WRITE(ah, AR_PHY_65NM_CH2_BB1,3839OS_REG_READ(ah, AR_PHY_65NM_CH2_BB1)3840| (0x1 << 12) | (0x1 << 10)3841| (0x1 << 9) | (0x1 << 8)3842| (0x1 << 6) | (0x1 << 5)3843| (0x1 << 4) | (0x1 << 3)3844| (0x1 << 2));3845OS_REG_WRITE(ah, AR_PHY_65NM_CH2_BB2,3846OS_REG_READ(ah, AR_PHY_65NM_CH2_BB2) | (0x1 << 31));3847}3848}38493850OS_REG_WRITE(ah, 0xa28c, 0x22222);3851OS_REG_WRITE(ah, 0xa288, 0x222);3852}3853}38543855void3856ar9300_tx99_start(struct ath_hal *ah, u_int8_t *data)3857{3858u_int32_t val;3859u_int32_t qnum = (u_int32_t)data;38603861/* Disable AGC to A2 */3862OS_REG_WRITE(ah, AR_PHY_TEST, (OS_REG_READ(ah, AR_PHY_TEST) | PHY_AGC_CLR));3863OS_REG_WRITE(ah, AR_DIAG_SW, OS_REG_READ(ah, AR_DIAG_SW) &~ AR_DIAG_RX_DIS);38643865OS_REG_WRITE(ah, AR_CR, AR_CR_RXD); /* set receive disable */3866/* set CW_MIN and CW_MAX both to 0, AIFS=2 */3867OS_REG_WRITE(ah, AR_DLCL_IFS(qnum), 0);3868OS_REG_WRITE(ah, AR_D_GBL_IFS_SIFS, 20); /* 50 OK */3869OS_REG_WRITE(ah, AR_D_GBL_IFS_EIFS, 20);3870/* 200 ok for HT20, 400 ok for HT40 */3871OS_REG_WRITE(ah, AR_TIME_OUT, 0x00000400);3872OS_REG_WRITE(ah, AR_DRETRY_LIMIT(qnum), 0xffffffff);38733874/* set QCU modes to early termination */3875val = OS_REG_READ(ah, AR_QMISC(qnum));3876OS_REG_WRITE(ah, AR_QMISC(qnum), val | AR_Q_MISC_DCU_EARLY_TERM_REQ);3877}38783879void3880ar9300_tx99_stop(struct ath_hal *ah)3881{3882/* this should follow the setting of start */3883OS_REG_WRITE(ah, AR_PHY_TEST, OS_REG_READ(ah, AR_PHY_TEST) &~ PHY_AGC_CLR);3884OS_REG_WRITE(ah, AR_DIAG_SW, OS_REG_READ(ah, AR_DIAG_SW) | AR_DIAG_RX_DIS);3885}3886#endif /* ATH_TX99_DIAG */3887#endif /* ATH_SUPPORT_HTC */38883889HAL_BOOL3890ar9300Get3StreamSignature(struct ath_hal *ah)3891{3892return AH_FALSE;3893}38943895HAL_BOOL3896ar9300ForceVCS(struct ath_hal *ah)3897{3898return AH_FALSE;3899}39003901HAL_BOOL3902ar9300SetDfs3StreamFix(struct ath_hal *ah, u_int32_t val)3903{3904return AH_FALSE;3905}39063907static u_int32_t3908ar9300_read_loc_timer(struct ath_hal *ah)3909{39103911return OS_REG_READ(ah, AR_LOC_TIMER_REG);3912}39133914HAL_BOOL3915ar9300_set_ctl_pwr(struct ath_hal *ah, u_int8_t *ctl_array)3916{3917struct ath_hal_9300 *ahp = AH9300(ah);3918ar9300_eeprom_t *p_eep_data = &ahp->ah_eeprom;3919u_int8_t *ctl_index;3920u_int32_t offset = 0;39213922if (!ctl_array)3923return AH_FALSE;39243925/* copy 2G ctl freqbin and power data */3926ctl_index = p_eep_data->ctl_index_2g;3927OS_MEMCPY(ctl_index + OSPREY_NUM_CTLS_2G, ctl_array,3928OSPREY_NUM_CTLS_2G * OSPREY_NUM_BAND_EDGES_2G + /* ctl_freqbin_2G */3929OSPREY_NUM_CTLS_2G * sizeof(OSP_CAL_CTL_DATA_2G)); /* ctl_power_data_2g */3930offset = (OSPREY_NUM_CTLS_2G * OSPREY_NUM_BAND_EDGES_2G) +3931( OSPREY_NUM_CTLS_2G * sizeof(OSP_CAL_CTL_DATA_2G));393239333934/* copy 2G ctl freqbin and power data */3935ctl_index = p_eep_data->ctl_index_5g;3936OS_MEMCPY(ctl_index + OSPREY_NUM_CTLS_5G, ctl_array + offset,3937OSPREY_NUM_CTLS_5G * OSPREY_NUM_BAND_EDGES_5G + /* ctl_freqbin_5G */3938OSPREY_NUM_CTLS_5G * sizeof(OSP_CAL_CTL_DATA_5G)); /* ctl_power_data_5g */39393940return AH_FALSE;3941}39423943void3944ar9300_set_txchainmaskopt(struct ath_hal *ah, u_int8_t mask)3945{3946struct ath_hal_9300 *ahp = AH9300(ah);39473948/* optional txchainmask should be subset of primary txchainmask */3949if ((mask & ahp->ah_tx_chainmask) != mask) {3950ahp->ah_tx_chainmaskopt = 0;3951ath_hal_printf(ah, "Error: ah_tx_chainmask=%d, mask=%d\n", ahp->ah_tx_chainmask, mask);3952return;3953}39543955ahp->ah_tx_chainmaskopt = mask;3956}395739583959