Path: blob/main/sys/dev/ath/ath_hal/ar9002/ar9280_attach.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2008-2009 Sam Leffler, Errno Consulting4* Copyright (c) 2008 Atheros Communications, Inc.5*6* Permission to use, copy, modify, and/or distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*/18#include "opt_ah.h"1920#include "ah.h"21#include "ah_internal.h"22#include "ah_devid.h"2324#include "ah_eeprom_v14.h" /* XXX for tx/rx gain */2526#include "ar9002/ar9280.h"27#include "ar5416/ar5416reg.h"28#include "ar5416/ar5416phy.h"2930#include "ar9002/ar9280v1.ini"31#include "ar9002/ar9280v2.ini"32#include "ar9002/ar9280_olc.h"3334static const HAL_PERCAL_DATA ar9280_iq_cal = { /* single sample */35.calName = "IQ", .calType = IQ_MISMATCH_CAL,36.calNumSamples = MIN_CAL_SAMPLES,37.calCountMax = PER_MAX_LOG_COUNT,38.calCollect = ar5416IQCalCollect,39.calPostProc = ar5416IQCalibration40};41static const HAL_PERCAL_DATA ar9280_adc_gain_cal = { /* single sample */42.calName = "ADC Gain", .calType = ADC_GAIN_CAL,43.calNumSamples = MIN_CAL_SAMPLES,44.calCountMax = PER_MAX_LOG_COUNT,45.calCollect = ar5416AdcGainCalCollect,46.calPostProc = ar5416AdcGainCalibration47};48static const HAL_PERCAL_DATA ar9280_adc_dc_cal = { /* single sample */49.calName = "ADC DC", .calType = ADC_DC_CAL,50.calNumSamples = MIN_CAL_SAMPLES,51.calCountMax = PER_MAX_LOG_COUNT,52.calCollect = ar5416AdcDcCalCollect,53.calPostProc = ar5416AdcDcCalibration54};55static const HAL_PERCAL_DATA ar9280_adc_init_dc_cal = {56.calName = "ADC Init DC", .calType = ADC_DC_INIT_CAL,57.calNumSamples = MIN_CAL_SAMPLES,58.calCountMax = INIT_LOG_COUNT,59.calCollect = ar5416AdcDcCalCollect,60.calPostProc = ar5416AdcDcCalibration61};6263static void ar9280ConfigPCIE(struct ath_hal *ah, HAL_BOOL restore,64HAL_BOOL power_off);65static void ar9280DisablePCIE(struct ath_hal *ah);66static HAL_BOOL ar9280FillCapabilityInfo(struct ath_hal *ah);67static void ar9280WriteIni(struct ath_hal *ah,68const struct ieee80211_channel *chan);6970static void71ar9280AniSetup(struct ath_hal *ah)72{73/*74* These are the parameters from the AR5416 ANI code;75* they likely need quite a bit of adjustment for the76* AR9280.77*/78static const struct ar5212AniParams aniparams = {79.maxNoiseImmunityLevel = 4, /* levels 0..4 */80.totalSizeDesired = { -55, -55, -55, -55, -62 },81.coarseHigh = { -14, -14, -14, -14, -12 },82.coarseLow = { -64, -64, -64, -64, -70 },83.firpwr = { -78, -78, -78, -78, -80 },84.maxSpurImmunityLevel = 7,85.cycPwrThr1 = { 2, 4, 6, 8, 10, 12, 14, 16 },86.maxFirstepLevel = 2, /* levels 0..2 */87.firstep = { 0, 4, 8 },88.ofdmTrigHigh = 500,89.ofdmTrigLow = 200,90.cckTrigHigh = 200,91.cckTrigLow = 100,92.rssiThrHigh = 40,93.rssiThrLow = 7,94.period = 100,95};96/* NB: disable ANI noise immunity for reliable RIFS rx */97AH5416(ah)->ah_ani_function &= ~(1 << HAL_ANI_NOISE_IMMUNITY_LEVEL);9899/* NB: ANI is not enabled yet */100ar5416AniAttach(ah, &aniparams, &aniparams, AH_TRUE);101}102103void104ar9280InitPLL(struct ath_hal *ah, const struct ieee80211_channel *chan)105{106uint32_t pll = SM(0x5, AR_RTC_SOWL_PLL_REFDIV);107108if (AR_SREV_MERLIN_20(ah) &&109chan != AH_NULL && IEEE80211_IS_CHAN_5GHZ(chan)) {110/*111* PLL WAR for Merlin 2.0/2.1112* When doing fast clock, set PLL to 0x142c113* Else, set PLL to 0x2850 to prevent reset-to-reset variation114*/115pll = IS_5GHZ_FAST_CLOCK_EN(ah, chan) ? 0x142c : 0x2850;116if (IEEE80211_IS_CHAN_HALF(chan))117pll |= SM(0x1, AR_RTC_SOWL_PLL_CLKSEL);118else if (IEEE80211_IS_CHAN_QUARTER(chan))119pll |= SM(0x2, AR_RTC_SOWL_PLL_CLKSEL);120} else if (AR_SREV_MERLIN_10_OR_LATER(ah)) {121pll = SM(0x5, AR_RTC_SOWL_PLL_REFDIV);122if (chan != AH_NULL) {123if (IEEE80211_IS_CHAN_HALF(chan))124pll |= SM(0x1, AR_RTC_SOWL_PLL_CLKSEL);125else if (IEEE80211_IS_CHAN_QUARTER(chan))126pll |= SM(0x2, AR_RTC_SOWL_PLL_CLKSEL);127if (IEEE80211_IS_CHAN_5GHZ(chan))128pll |= SM(0x28, AR_RTC_SOWL_PLL_DIV);129else130pll |= SM(0x2c, AR_RTC_SOWL_PLL_DIV);131} else132pll |= SM(0x2c, AR_RTC_SOWL_PLL_DIV);133}134135OS_REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);136OS_DELAY(RTC_PLL_SETTLE_DELAY);137OS_REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_SLEEP_DERIVED_CLK);138}139140/* XXX shouldn't be here! */141#define EEP_MINOR(_ah) \142(AH_PRIVATE(_ah)->ah_eeversion & AR5416_EEP_VER_MINOR_MASK)143144/*145* Attach for an AR9280 part.146*/147static struct ath_hal *148ar9280Attach(uint16_t devid, HAL_SOFTC sc,149HAL_BUS_TAG st, HAL_BUS_HANDLE sh, uint16_t *eepromdata,150HAL_OPS_CONFIG *ah_config,151HAL_STATUS *status)152{153struct ath_hal_9280 *ahp9280;154struct ath_hal_5212 *ahp;155struct ath_hal *ah;156uint32_t val;157HAL_STATUS ecode;158HAL_BOOL rfStatus;159int8_t pwr_table_offset;160uint8_t pwr;161162HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH, "%s: sc %p st %p sh %p\n",163__func__, sc, (void*) st, (void*) sh);164165/* NB: memory is returned zero'd */166ahp9280 = ath_hal_malloc(sizeof (struct ath_hal_9280));167if (ahp9280 == AH_NULL) {168HALDEBUG(AH_NULL, HAL_DEBUG_ANY,169"%s: cannot allocate memory for state block\n", __func__);170*status = HAL_ENOMEM;171return AH_NULL;172}173ahp = AH5212(ahp9280);174ah = &ahp->ah_priv.h;175176ar5416InitState(AH5416(ah), devid, sc, st, sh, status);177178/*179* Use the "local" EEPROM data given to us by the higher layers.180* This is a private copy out of system flash. The Linux ath9k181* commit for the initial AR9130 support mentions MMIO flash182* access is "unreliable." -adrian183*/184if (eepromdata != AH_NULL) {185AH_PRIVATE((ah))->ah_eepromRead = ath_hal_EepromDataRead;186AH_PRIVATE((ah))->ah_eepromWrite = NULL;187ah->ah_eepromdata = eepromdata;188}189190/* XXX override with 9280 specific state */191/* override 5416 methods for our needs */192AH5416(ah)->ah_initPLL = ar9280InitPLL;193194ah->ah_setAntennaSwitch = ar9280SetAntennaSwitch;195ah->ah_configPCIE = ar9280ConfigPCIE;196ah->ah_disablePCIE = ar9280DisablePCIE;197198AH5416(ah)->ah_cal.iqCalData.calData = &ar9280_iq_cal;199AH5416(ah)->ah_cal.adcGainCalData.calData = &ar9280_adc_gain_cal;200AH5416(ah)->ah_cal.adcDcCalData.calData = &ar9280_adc_dc_cal;201AH5416(ah)->ah_cal.adcDcCalInitData.calData = &ar9280_adc_init_dc_cal;202AH5416(ah)->ah_cal.suppCals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;203204AH5416(ah)->ah_spurMitigate = ar9280SpurMitigate;205AH5416(ah)->ah_writeIni = ar9280WriteIni;206AH5416(ah)->ah_olcInit = ar9280olcInit;207AH5416(ah)->ah_olcTempCompensation = ar9280olcTemperatureCompensation;208AH5416(ah)->ah_setPowerCalTable = ar9280SetPowerCalTable;209210AH5416(ah)->ah_rx_chainmask = AR9280_DEFAULT_RXCHAINMASK;211AH5416(ah)->ah_tx_chainmask = AR9280_DEFAULT_TXCHAINMASK;212213if (!ar5416SetResetReg(ah, HAL_RESET_POWER_ON)) {214/* reset chip */215HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't reset chip\n",216__func__);217ecode = HAL_EIO;218goto bad;219}220221if (!ar5416SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) {222HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't wakeup chip\n",223__func__);224ecode = HAL_EIO;225goto bad;226}227/* Read Revisions from Chips before taking out of reset */228val = OS_REG_READ(ah, AR_SREV);229HALDEBUG(ah, HAL_DEBUG_ATTACH,230"%s: ID 0x%x VERSION 0x%x TYPE 0x%x REVISION 0x%x\n",231__func__, MS(val, AR_XSREV_ID), MS(val, AR_XSREV_VERSION),232MS(val, AR_XSREV_TYPE), MS(val, AR_XSREV_REVISION));233/* NB: include chip type to differentiate from pre-Sowl versions */234AH_PRIVATE(ah)->ah_macVersion =235(val & AR_XSREV_VERSION) >> AR_XSREV_TYPE_S;236AH_PRIVATE(ah)->ah_macRev = MS(val, AR_XSREV_REVISION);237AH_PRIVATE(ah)->ah_ispcie = (val & AR_XSREV_TYPE_HOST_MODE) == 0;238239/* setup common ini data; rf backends handle remainder */240if (AR_SREV_MERLIN_20_OR_LATER(ah)) {241HAL_INI_INIT(&ahp->ah_ini_modes, ar9280Modes_v2, 6);242HAL_INI_INIT(&ahp->ah_ini_common, ar9280Common_v2, 2);243HAL_INI_INIT(&AH5416(ah)->ah_ini_pcieserdes,244ar9280PciePhy_clkreq_always_on_L1_v2, 2);245HAL_INI_INIT(&ahp9280->ah_ini_xmodes,246ar9280Modes_fast_clock_v2, 3);247} else {248HAL_INI_INIT(&ahp->ah_ini_modes, ar9280Modes_v1, 6);249HAL_INI_INIT(&ahp->ah_ini_common, ar9280Common_v1, 2);250HAL_INI_INIT(&AH5416(ah)->ah_ini_pcieserdes,251ar9280PciePhy_v1, 2);252}253ar5416AttachPCIE(ah);254255ecode = ath_hal_v14EepromAttach(ah);256if (ecode != HAL_OK)257goto bad;258259if (!ar5416ChipReset(ah, AH_NULL, HAL_RESET_NORMAL)) { /* reset chip */260HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n", __func__);261ecode = HAL_EIO;262goto bad;263}264265AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID);266267if (!ar5212ChipTest(ah)) {268HALDEBUG(ah, HAL_DEBUG_ANY, "%s: hardware self-test failed\n",269__func__);270ecode = HAL_ESELFTEST;271goto bad;272}273274/*275* Set correct Baseband to analog shift276* setting to access analog chips.277*/278OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);279280/* Read Radio Chip Rev Extract */281AH_PRIVATE(ah)->ah_analog5GhzRev = ar5416GetRadioRev(ah);282switch (AH_PRIVATE(ah)->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR) {283case AR_RAD2133_SREV_MAJOR: /* Sowl: 2G/3x3 */284case AR_RAD5133_SREV_MAJOR: /* Sowl: 2+5G/3x3 */285break;286default:287if (AH_PRIVATE(ah)->ah_analog5GhzRev == 0) {288AH_PRIVATE(ah)->ah_analog5GhzRev =289AR_RAD5133_SREV_MAJOR;290break;291}292#ifdef AH_DEBUG293HALDEBUG(ah, HAL_DEBUG_ANY,294"%s: 5G Radio Chip Rev 0x%02X is not supported by "295"this driver\n", __func__,296AH_PRIVATE(ah)->ah_analog5GhzRev);297ecode = HAL_ENOTSUPP;298goto bad;299#endif300}301rfStatus = ar9280RfAttach(ah, &ecode);302if (!rfStatus) {303HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RF setup failed, status %u\n",304__func__, ecode);305goto bad;306}307308/* Enable fixup for AR_AN_TOP2 if necessary */309/*310* The v14 EEPROM layer returns HAL_EIO if PWDCLKIND isn't supported311* by the EEPROM version.312*313* ath9k checks the EEPROM minor version is >= 0x0a here, instead of314* the abstracted EEPROM access layer.315*/316ecode = ath_hal_eepromGet(ah, AR_EEP_PWDCLKIND, &pwr);317if (AR_SREV_MERLIN_20_OR_LATER(ah) && ecode == HAL_OK && pwr == 0) {318printf("[ath] enabling AN_TOP2_FIXUP\n");319AH5416(ah)->ah_need_an_top2_fixup = 1;320}321322/*323* Check whether the power table offset isn't the default.324* This can occur with eeprom minor V21 or greater on Merlin.325*/326(void) ath_hal_eepromGet(ah, AR_EEP_PWR_TABLE_OFFSET, &pwr_table_offset);327if (pwr_table_offset != AR5416_PWR_TABLE_OFFSET_DB)328ath_hal_printf(ah, "[ath]: default pwr offset: %d dBm != EEPROM pwr offset: %d dBm; curves will be adjusted.\n",329AR5416_PWR_TABLE_OFFSET_DB, (int) pwr_table_offset);330331/* XXX check for >= minor ver 17 */332if (AR_SREV_MERLIN_20(ah)) {333/* setup rxgain table */334switch (ath_hal_eepromGet(ah, AR_EEP_RXGAIN_TYPE, AH_NULL)) {335case AR5416_EEP_RXGAIN_13dB_BACKOFF:336HAL_INI_INIT(&ahp9280->ah_ini_rxgain,337ar9280Modes_backoff_13db_rxgain_v2, 6);338break;339case AR5416_EEP_RXGAIN_23dB_BACKOFF:340HAL_INI_INIT(&ahp9280->ah_ini_rxgain,341ar9280Modes_backoff_23db_rxgain_v2, 6);342break;343case AR5416_EEP_RXGAIN_ORIG:344HAL_INI_INIT(&ahp9280->ah_ini_rxgain,345ar9280Modes_original_rxgain_v2, 6);346break;347default:348HALASSERT(AH_FALSE);349goto bad; /* XXX ? try to continue */350}351}352353/* XXX check for >= minor ver 19 */354if (AR_SREV_MERLIN_20(ah)) {355/* setp txgain table */356switch (ath_hal_eepromGet(ah, AR_EEP_TXGAIN_TYPE, AH_NULL)) {357case AR5416_EEP_TXGAIN_HIGH_POWER:358HAL_INI_INIT(&ahp9280->ah_ini_txgain,359ar9280Modes_high_power_tx_gain_v2, 6);360break;361case AR5416_EEP_TXGAIN_ORIG:362HAL_INI_INIT(&ahp9280->ah_ini_txgain,363ar9280Modes_original_tx_gain_v2, 6);364break;365default:366HALASSERT(AH_FALSE);367goto bad; /* XXX ? try to continue */368}369}370371/*372* Got everything we need now to setup the capabilities.373*/374if (!ar9280FillCapabilityInfo(ah)) {375ecode = HAL_EEREAD;376goto bad;377}378379ecode = ath_hal_eepromGet(ah, AR_EEP_MACADDR, ahp->ah_macaddr);380if (ecode != HAL_OK) {381HALDEBUG(ah, HAL_DEBUG_ANY,382"%s: error getting mac address from EEPROM\n", __func__);383goto bad;384}385/* XXX How about the serial number ? */386/* Read Reg Domain */387AH_PRIVATE(ah)->ah_currentRD =388ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, AH_NULL);389AH_PRIVATE(ah)->ah_currentRDext =390ath_hal_eepromGet(ah, AR_EEP_REGDMN_1, AH_NULL);391392/*393* ah_miscMode is populated by ar5416FillCapabilityInfo()394* starting from griffin. Set here to make sure that395* AR_MISC_MODE_MIC_NEW_LOC_ENABLE is set before a GTK is396* placed into hardware.397*/398if (ahp->ah_miscMode != 0)399OS_REG_WRITE(ah, AR_MISC_MODE, OS_REG_READ(ah, AR_MISC_MODE) | ahp->ah_miscMode);400401ar9280AniSetup(ah); /* Anti Noise Immunity */402403/* Setup noise floor min/max/nominal values */404AH5416(ah)->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9280_2GHZ;405AH5416(ah)->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9280_2GHZ;406AH5416(ah)->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9280_2GHZ;407AH5416(ah)->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9280_5GHZ;408AH5416(ah)->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9280_5GHZ;409AH5416(ah)->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9280_5GHZ;410411ar5416InitNfHistBuff(AH5416(ah)->ah_cal.nfCalHist);412413HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: return\n", __func__);414415return ah;416bad:417if (ah != AH_NULL)418ah->ah_detach(ah);419if (status)420*status = ecode;421return AH_NULL;422}423424static void425ar9280ConfigPCIE(struct ath_hal *ah, HAL_BOOL restore, HAL_BOOL power_off)426{427uint32_t val;428429if (AH_PRIVATE(ah)->ah_ispcie && !restore) {430ath_hal_ini_write(ah, &AH5416(ah)->ah_ini_pcieserdes, 1, 0);431OS_DELAY(1000);432}433434/*435* Set PCIe workaround bits436*437* NOTE:438*439* In Merlin and Kite, bit 14 in WA register (disable L1) should only440* be set when device enters D3 and be cleared when device comes back441* to D0.442*/443if (power_off) { /* Power-off */444OS_REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);445446val = OS_REG_READ(ah, AR_WA);447448/*449* Disable bit 6 and 7 before entering D3 to prevent450* system hang.451*/452val &= ~(AR_WA_BIT6 | AR_WA_BIT7);453454/*455* XXX Not sure, is specified in the reference HAL.456*/457val |= AR_WA_BIT22;458459/*460* See above: set AR_WA_D3_L1_DISABLE when entering D3 state.461*462* XXX The reference HAL does it this way - it only sets463* AR_WA_D3_L1_DISABLE if it's set in AR9280_WA_DEFAULT,464* which it (currently) isn't. So the following statement465* is currently a NOP.466*/467if (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE)468val |= AR_WA_D3_L1_DISABLE;469470OS_REG_WRITE(ah, AR_WA, val);471} else { /* Power-on */472val = AR9280_WA_DEFAULT;473474/*475* See note above: make sure L1_DISABLE is not set.476*/477val &= (~AR_WA_D3_L1_DISABLE);478OS_REG_WRITE(ah, AR_WA, val);479480/* set bit 19 to allow forcing of pcie core into L1 state */481OS_REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);482}483}484485static void486ar9280DisablePCIE(struct ath_hal *ah)487{488}489490static void491ar9280WriteIni(struct ath_hal *ah, const struct ieee80211_channel *chan)492{493u_int modesIndex, freqIndex;494int regWrites = 0;495int i;496const HAL_INI_ARRAY *ia;497498/* Setup the indices for the next set of register array writes */499/* XXX Ignore 11n dynamic mode on the AR5416 for the moment */500if (IEEE80211_IS_CHAN_2GHZ(chan)) {501freqIndex = 2;502if (IEEE80211_IS_CHAN_HT40(chan))503modesIndex = 3;504else if (IEEE80211_IS_CHAN_108G(chan))505modesIndex = 5;506else507modesIndex = 4;508} else {509freqIndex = 1;510if (IEEE80211_IS_CHAN_HT40(chan) ||511IEEE80211_IS_CHAN_TURBO(chan))512modesIndex = 2;513else514modesIndex = 1;515}516517/* Set correct Baseband to analog shift setting to access analog chips. */518OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);519OS_REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);520521/*522* This is unwound because at the moment, there's a requirement523* for Merlin (and later, perhaps) to have a specific bit fixed524* in the AR_AN_TOP2 register before writing it.525*/526ia = &AH5212(ah)->ah_ini_modes;527#if 0528regWrites = ath_hal_ini_write(ah, &AH5212(ah)->ah_ini_modes,529modesIndex, regWrites);530#endif531HALASSERT(modesIndex < ia->cols);532for (i = 0; i < ia->rows; i++) {533uint32_t reg = HAL_INI_VAL(ia, i, 0);534uint32_t val = HAL_INI_VAL(ia, i, modesIndex);535536if (reg == AR_AN_TOP2 && AH5416(ah)->ah_need_an_top2_fixup)537val &= ~AR_AN_TOP2_PWDCLKIND;538539OS_REG_WRITE(ah, reg, val);540541/* Analog shift register delay seems needed for Merlin - PR kern/154220 */542if (reg >= 0x7800 && reg < 0x7900)543OS_DELAY(100);544545DMA_YIELD(regWrites);546}547548if (AR_SREV_MERLIN_20_OR_LATER(ah)) {549regWrites = ath_hal_ini_write(ah, &AH9280(ah)->ah_ini_rxgain,550modesIndex, regWrites);551regWrites = ath_hal_ini_write(ah, &AH9280(ah)->ah_ini_txgain,552modesIndex, regWrites);553}554/* XXX Merlin 100us delay for shift registers */555regWrites = ath_hal_ini_write(ah, &AH5212(ah)->ah_ini_common,5561, regWrites);557558if (AR_SREV_MERLIN_20(ah) && IS_5GHZ_FAST_CLOCK_EN(ah, chan)) {559/* 5GHz channels w/ Fast Clock use different modal values */560regWrites = ath_hal_ini_write(ah, &AH9280(ah)->ah_ini_xmodes,561modesIndex, regWrites);562}563}564565#define AR_BASE_FREQ_2GHZ 2300566#define AR_BASE_FREQ_5GHZ 4900567#define AR_SPUR_FEEQ_BOUND_HT40 19568#define AR_SPUR_FEEQ_BOUND_HT20 10569570void571ar9280SpurMitigate(struct ath_hal *ah, const struct ieee80211_channel *chan)572{573static const int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,574AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60 };575static const int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,576AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60 };577static int inc[4] = { 0, 100, 0, 0 };578579int bb_spur = AR_NO_SPUR;580int freq;581int bin, cur_bin;582int bb_spur_off, spur_subchannel_sd;583int spur_freq_sd;584int spur_delta_phase;585int denominator;586int upper, lower, cur_vit_mask;587int tmp, newVal;588int i;589CHAN_CENTERS centers;590591int8_t mask_m[123];592int8_t mask_p[123];593int8_t mask_amt;594int tmp_mask;595int cur_bb_spur;596HAL_BOOL is2GHz = IEEE80211_IS_CHAN_2GHZ(chan);597598OS_MEMZERO(&mask_m, sizeof(int8_t) * 123);599OS_MEMZERO(&mask_p, sizeof(int8_t) * 123);600601ar5416GetChannelCenters(ah, chan, ¢ers);602freq = centers.synth_center;603604/*605* Need to verify range +/- 9.38 for static ht20 and +/- 18.75 for ht40,606* otherwise spur is out-of-band and can be ignored.607*/608for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {609cur_bb_spur = ath_hal_getSpurChan(ah, i, is2GHz);610/* Get actual spur freq in MHz from EEPROM read value */611if (is2GHz) {612cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;613} else {614cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;615}616617if (AR_NO_SPUR == cur_bb_spur)618break;619cur_bb_spur = cur_bb_spur - freq;620621if (IEEE80211_IS_CHAN_HT40(chan)) {622if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&623(cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {624bb_spur = cur_bb_spur;625break;626}627} else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&628(cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {629bb_spur = cur_bb_spur;630break;631}632}633634if (AR_NO_SPUR == bb_spur) {635#if 1636/*637* MRC CCK can interfere with beacon detection and cause deaf/mute.638* Disable MRC CCK for now.639*/640OS_REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK, AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);641#else642/* Enable MRC CCK if no spur is found in this channel. */643OS_REG_SET_BIT(ah, AR_PHY_FORCE_CLKEN_CCK, AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);644#endif645return;646} else {647/*648* For Merlin, spur can break CCK MRC algorithm. Disable CCK MRC if spur649* is found in this channel.650*/651OS_REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK, AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);652}653654bin = bb_spur * 320;655656tmp = OS_REG_READ(ah, AR_PHY_TIMING_CTRL4_CHAIN(0));657658newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |659AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |660AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |661AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);662OS_REG_WRITE(ah, AR_PHY_TIMING_CTRL4_CHAIN(0), newVal);663664newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |665AR_PHY_SPUR_REG_ENABLE_MASK_PPM |666AR_PHY_SPUR_REG_MASK_RATE_SELECT |667AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |668SM(AR5416_SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));669OS_REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);670671/* Pick control or extn channel to cancel the spur */672if (IEEE80211_IS_CHAN_HT40(chan)) {673if (bb_spur < 0) {674spur_subchannel_sd = 1;675bb_spur_off = bb_spur + 10;676} else {677spur_subchannel_sd = 0;678bb_spur_off = bb_spur - 10;679}680} else {681spur_subchannel_sd = 0;682bb_spur_off = bb_spur;683}684685/*686* spur_delta_phase = bb_spur/40 * 2**21 for static ht20,687* /80 for dyn2040.688*/689if (IEEE80211_IS_CHAN_HT40(chan))690spur_delta_phase = ((bb_spur * 262144) / 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;691else692spur_delta_phase = ((bb_spur * 524288) / 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;693694/*695* in 11A mode the denominator of spur_freq_sd should be 40 and696* it should be 44 in 11G697*/698denominator = IEEE80211_IS_CHAN_2GHZ(chan) ? 44 : 40;699spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;700701newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |702SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |703SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));704OS_REG_WRITE(ah, AR_PHY_TIMING11, newVal);705706/* Choose to cancel between control and extension channels */707newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;708OS_REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);709710/*711* ============================================712* Set Pilot and Channel Masks713*714* pilot mask 1 [31:0] = +6..-26, no 0 bin715* pilot mask 2 [19:0] = +26..+7716*717* channel mask 1 [31:0] = +6..-26, no 0 bin718* channel mask 2 [19:0] = +26..+7719*/720cur_bin = -6000;721upper = bin + 100;722lower = bin - 100;723724for (i = 0; i < 4; i++) {725int pilot_mask = 0;726int chan_mask = 0;727int bp = 0;728for (bp = 0; bp < 30; bp++) {729if ((cur_bin > lower) && (cur_bin < upper)) {730pilot_mask = pilot_mask | 0x1 << bp;731chan_mask = chan_mask | 0x1 << bp;732}733cur_bin += 100;734}735cur_bin += inc[i];736OS_REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);737OS_REG_WRITE(ah, chan_mask_reg[i], chan_mask);738}739740/* =================================================741* viterbi mask 1 based on channel magnitude742* four levels 0-3743* - mask (-27 to 27) (reg 64,0x9900 to 67,0x990c)744* [1 2 2 1] for -9.6 or [1 2 1] for +16745* - enable_mask_ppm, all bins move with freq746*747* - mask_select, 8 bits for rates (reg 67,0x990c)748* - mask_rate_cntl, 8 bits for rates (reg 67,0x990c)749* choose which mask to use mask or mask2750*/751752/*753* viterbi mask 2 2nd set for per data rate puncturing754* four levels 0-3755* - mask_select, 8 bits for rates (reg 67)756* - mask (-27 to 27) (reg 98,0x9988 to 101,0x9994)757* [1 2 2 1] for -9.6 or [1 2 1] for +16758*/759cur_vit_mask = 6100;760upper = bin + 120;761lower = bin - 120;762763for (i = 0; i < 123; i++) {764if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {765if ((abs(cur_vit_mask - bin)) < 75) {766mask_amt = 1;767} else {768mask_amt = 0;769}770if (cur_vit_mask < 0) {771mask_m[abs(cur_vit_mask / 100)] = mask_amt;772} else {773mask_p[cur_vit_mask / 100] = mask_amt;774}775}776cur_vit_mask -= 100;777}778779tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)780| (mask_m[48] << 26) | (mask_m[49] << 24)781| (mask_m[50] << 22) | (mask_m[51] << 20)782| (mask_m[52] << 18) | (mask_m[53] << 16)783| (mask_m[54] << 14) | (mask_m[55] << 12)784| (mask_m[56] << 10) | (mask_m[57] << 8)785| (mask_m[58] << 6) | (mask_m[59] << 4)786| (mask_m[60] << 2) | (mask_m[61] << 0);787OS_REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);788OS_REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);789790tmp_mask = (mask_m[31] << 28)791| (mask_m[32] << 26) | (mask_m[33] << 24)792| (mask_m[34] << 22) | (mask_m[35] << 20)793| (mask_m[36] << 18) | (mask_m[37] << 16)794| (mask_m[48] << 14) | (mask_m[39] << 12)795| (mask_m[40] << 10) | (mask_m[41] << 8)796| (mask_m[42] << 6) | (mask_m[43] << 4)797| (mask_m[44] << 2) | (mask_m[45] << 0);798OS_REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);799OS_REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);800801tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)802| (mask_m[18] << 26) | (mask_m[18] << 24)803| (mask_m[20] << 22) | (mask_m[20] << 20)804| (mask_m[22] << 18) | (mask_m[22] << 16)805| (mask_m[24] << 14) | (mask_m[24] << 12)806| (mask_m[25] << 10) | (mask_m[26] << 8)807| (mask_m[27] << 6) | (mask_m[28] << 4)808| (mask_m[29] << 2) | (mask_m[30] << 0);809OS_REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);810OS_REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);811812tmp_mask = (mask_m[ 0] << 30) | (mask_m[ 1] << 28)813| (mask_m[ 2] << 26) | (mask_m[ 3] << 24)814| (mask_m[ 4] << 22) | (mask_m[ 5] << 20)815| (mask_m[ 6] << 18) | (mask_m[ 7] << 16)816| (mask_m[ 8] << 14) | (mask_m[ 9] << 12)817| (mask_m[10] << 10) | (mask_m[11] << 8)818| (mask_m[12] << 6) | (mask_m[13] << 4)819| (mask_m[14] << 2) | (mask_m[15] << 0);820OS_REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);821OS_REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);822823tmp_mask = (mask_p[15] << 28)824| (mask_p[14] << 26) | (mask_p[13] << 24)825| (mask_p[12] << 22) | (mask_p[11] << 20)826| (mask_p[10] << 18) | (mask_p[ 9] << 16)827| (mask_p[ 8] << 14) | (mask_p[ 7] << 12)828| (mask_p[ 6] << 10) | (mask_p[ 5] << 8)829| (mask_p[ 4] << 6) | (mask_p[ 3] << 4)830| (mask_p[ 2] << 2) | (mask_p[ 1] << 0);831OS_REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);832OS_REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);833834tmp_mask = (mask_p[30] << 28)835| (mask_p[29] << 26) | (mask_p[28] << 24)836| (mask_p[27] << 22) | (mask_p[26] << 20)837| (mask_p[25] << 18) | (mask_p[24] << 16)838| (mask_p[23] << 14) | (mask_p[22] << 12)839| (mask_p[21] << 10) | (mask_p[20] << 8)840| (mask_p[19] << 6) | (mask_p[18] << 4)841| (mask_p[17] << 2) | (mask_p[16] << 0);842OS_REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);843OS_REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);844845tmp_mask = (mask_p[45] << 28)846| (mask_p[44] << 26) | (mask_p[43] << 24)847| (mask_p[42] << 22) | (mask_p[41] << 20)848| (mask_p[40] << 18) | (mask_p[39] << 16)849| (mask_p[38] << 14) | (mask_p[37] << 12)850| (mask_p[36] << 10) | (mask_p[35] << 8)851| (mask_p[34] << 6) | (mask_p[33] << 4)852| (mask_p[32] << 2) | (mask_p[31] << 0);853OS_REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);854OS_REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);855856tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)857| (mask_p[59] << 26) | (mask_p[58] << 24)858| (mask_p[57] << 22) | (mask_p[56] << 20)859| (mask_p[55] << 18) | (mask_p[54] << 16)860| (mask_p[53] << 14) | (mask_p[52] << 12)861| (mask_p[51] << 10) | (mask_p[50] << 8)862| (mask_p[49] << 6) | (mask_p[48] << 4)863| (mask_p[47] << 2) | (mask_p[46] << 0);864OS_REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);865OS_REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);866}867868/*869* Fill all software cached or static hardware state information.870* Return failure if capabilities are to come from EEPROM and871* cannot be read.872*/873static HAL_BOOL874ar9280FillCapabilityInfo(struct ath_hal *ah)875{876HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;877878if (!ar5416FillCapabilityInfo(ah))879return AH_FALSE;880pCap->halNumGpioPins = 10;881pCap->halWowSupport = AH_TRUE;882pCap->halWowMatchPatternExact = AH_TRUE;883#if 0884pCap->halWowMatchPatternDword = AH_TRUE;885#endif886pCap->halCSTSupport = AH_TRUE;887pCap->halRifsRxSupport = AH_TRUE;888pCap->halRifsTxSupport = AH_TRUE;889pCap->halRtsAggrLimit = 64*1024; /* 802.11n max */890pCap->halExtChanDfsSupport = AH_TRUE;891pCap->halUseCombinedRadarRssi = AH_TRUE;892#if 0893/* XXX bluetooth */894pCap->halBtCoexSupport = AH_TRUE;895#endif896pCap->halAutoSleepSupport = AH_FALSE; /* XXX? */897pCap->hal4kbSplitTransSupport = AH_FALSE;898/* Disable this so Block-ACK works correctly */899pCap->halHasRxSelfLinkedTail = AH_FALSE;900pCap->halMbssidAggrSupport = AH_TRUE;901pCap->hal4AddrAggrSupport = AH_TRUE;902pCap->halSpectralScanSupport = AH_TRUE;903904if (AR_SREV_MERLIN_20(ah)) {905pCap->halPSPollBroken = AH_FALSE;906/*907* This just enables the support; it doesn't908* state 5ghz fast clock will always be used.909*/910pCap->halSupportsFastClock5GHz = AH_TRUE;911}912pCap->halRxStbcSupport = 1;913pCap->halTxStbcSupport = 1;914pCap->halEnhancedDfsSupport = AH_TRUE;915916return AH_TRUE;917}918919/*920* This has been disabled - having the HAL flip chainmasks on/off921* when attempting to implement 11n disrupts things. For now, just922* leave this flipped off and worry about implementing TX diversity923* for legacy and MCS0-7 when 11n is fully functioning.924*/925HAL_BOOL926ar9280SetAntennaSwitch(struct ath_hal *ah, HAL_ANT_SETTING settings)927{928#define ANTENNA0_CHAINMASK 0x1929#define ANTENNA1_CHAINMASK 0x2930#if 0931struct ath_hal_5416 *ahp = AH5416(ah);932933/* Antenna selection is done by setting the tx/rx chainmasks approp. */934switch (settings) {935case HAL_ANT_FIXED_A:936/* Enable first antenna only */937ahp->ah_tx_chainmask = ANTENNA0_CHAINMASK;938ahp->ah_rx_chainmask = ANTENNA0_CHAINMASK;939break;940case HAL_ANT_FIXED_B:941/* Enable second antenna only, after checking capability */942if (AH_PRIVATE(ah)->ah_caps.halTxChainMask > ANTENNA1_CHAINMASK)943ahp->ah_tx_chainmask = ANTENNA1_CHAINMASK;944ahp->ah_rx_chainmask = ANTENNA1_CHAINMASK;945break;946case HAL_ANT_VARIABLE:947/* Restore original chainmask settings */948/* XXX */949ahp->ah_tx_chainmask = AR9280_DEFAULT_TXCHAINMASK;950ahp->ah_rx_chainmask = AR9280_DEFAULT_RXCHAINMASK;951break;952}953954HALDEBUG(ah, HAL_DEBUG_ANY, "%s: settings=%d, tx/rx chainmask=%d/%d\n",955__func__, settings, ahp->ah_tx_chainmask, ahp->ah_rx_chainmask);956957#endif958return AH_TRUE;959#undef ANTENNA0_CHAINMASK960#undef ANTENNA1_CHAINMASK961}962963static const char*964ar9280Probe(uint16_t vendorid, uint16_t devid)965{966if (vendorid == ATHEROS_VENDOR_ID) {967if (devid == AR9280_DEVID_PCI)968return "Atheros 9220";969if (devid == AR9280_DEVID_PCIE)970return "Atheros 9280";971}972return AH_NULL;973}974AH_CHIP(AR9280, ar9280Probe, ar9280Attach);975976977