Path: blob/main/sys/dev/ath/ath_hal/ar9002/ar9287_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 */25#include "ah_eeprom_9287.h"2627#include "ar9002/ar9280.h"28#include "ar9002/ar9287.h"29#include "ar5416/ar5416reg.h"30#include "ar5416/ar5416phy.h"3132#include "ar9002/ar9287_cal.h"33#include "ar9002/ar9287_reset.h"34#include "ar9002/ar9287_olc.h"3536#include "ar9002/ar9287.ini"3738static const HAL_PERCAL_DATA ar9287_iq_cal = { /* single sample */39.calName = "IQ", .calType = IQ_MISMATCH_CAL,40.calNumSamples = MIN_CAL_SAMPLES,41.calCountMax = PER_MAX_LOG_COUNT,42.calCollect = ar5416IQCalCollect,43.calPostProc = ar5416IQCalibration44};45static const HAL_PERCAL_DATA ar9287_adc_gain_cal = { /* single sample */46.calName = "ADC Gain", .calType = ADC_GAIN_CAL,47.calNumSamples = MIN_CAL_SAMPLES,48.calCountMax = PER_MIN_LOG_COUNT,49.calCollect = ar5416AdcGainCalCollect,50.calPostProc = ar5416AdcGainCalibration51};52static const HAL_PERCAL_DATA ar9287_adc_dc_cal = { /* single sample */53.calName = "ADC DC", .calType = ADC_DC_CAL,54.calNumSamples = MIN_CAL_SAMPLES,55.calCountMax = PER_MIN_LOG_COUNT,56.calCollect = ar5416AdcDcCalCollect,57.calPostProc = ar5416AdcDcCalibration58};59static const HAL_PERCAL_DATA ar9287_adc_init_dc_cal = {60.calName = "ADC Init DC", .calType = ADC_DC_INIT_CAL,61.calNumSamples = MIN_CAL_SAMPLES,62.calCountMax = INIT_LOG_COUNT,63.calCollect = ar5416AdcDcCalCollect,64.calPostProc = ar5416AdcDcCalibration65};6667static void ar9287ConfigPCIE(struct ath_hal *ah, HAL_BOOL restore,68HAL_BOOL power_off);69static void ar9287DisablePCIE(struct ath_hal *ah);70static HAL_BOOL ar9287FillCapabilityInfo(struct ath_hal *ah);71static void ar9287WriteIni(struct ath_hal *ah,72const struct ieee80211_channel *chan);7374static void75ar9287AniSetup(struct ath_hal *ah)76{77/*78* These are the parameters from the AR5416 ANI code;79* they likely need quite a bit of adjustment for the80* AR9287.81*/82static const struct ar5212AniParams aniparams = {83.maxNoiseImmunityLevel = 4, /* levels 0..4 */84.totalSizeDesired = { -55, -55, -55, -55, -62 },85.coarseHigh = { -14, -14, -14, -14, -12 },86.coarseLow = { -64, -64, -64, -64, -70 },87.firpwr = { -78, -78, -78, -78, -80 },88.maxSpurImmunityLevel = 7,89.cycPwrThr1 = { 2, 4, 6, 8, 10, 12, 14, 16 },90.maxFirstepLevel = 2, /* levels 0..2 */91.firstep = { 0, 4, 8 },92.ofdmTrigHigh = 500,93.ofdmTrigLow = 200,94.cckTrigHigh = 200,95.cckTrigLow = 100,96.rssiThrHigh = 40,97.rssiThrLow = 7,98.period = 100,99};100/* NB: disable ANI noise immunity for reliable RIFS rx */101AH5416(ah)->ah_ani_function &= ~ HAL_ANI_NOISE_IMMUNITY_LEVEL;102103/* NB: ANI is not enabled yet */104ar5416AniAttach(ah, &aniparams, &aniparams, AH_TRUE);105}106107/*108* Attach for an AR9287 part.109*/110static struct ath_hal *111ar9287Attach(uint16_t devid, HAL_SOFTC sc,112HAL_BUS_TAG st, HAL_BUS_HANDLE sh, uint16_t *eepromdata,113HAL_OPS_CONFIG *ah_config,114HAL_STATUS *status)115{116struct ath_hal_9287 *ahp9287;117struct ath_hal_5212 *ahp;118struct ath_hal *ah;119uint32_t val;120HAL_STATUS ecode;121HAL_BOOL rfStatus;122int8_t pwr_table_offset;123124HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH, "%s: sc %p st %p sh %p\n",125__func__, sc, (void*) st, (void*) sh);126127/* NB: memory is returned zero'd */128ahp9287 = ath_hal_malloc(sizeof (struct ath_hal_9287));129if (ahp9287 == AH_NULL) {130HALDEBUG(AH_NULL, HAL_DEBUG_ANY,131"%s: cannot allocate memory for state block\n", __func__);132*status = HAL_ENOMEM;133return AH_NULL;134}135ahp = AH5212(ahp9287);136ah = &ahp->ah_priv.h;137138ar5416InitState(AH5416(ah), devid, sc, st, sh, status);139140if (eepromdata != AH_NULL) {141AH_PRIVATE(ah)->ah_eepromRead = ath_hal_EepromDataRead;142AH_PRIVATE(ah)->ah_eepromWrite = NULL;143ah->ah_eepromdata = eepromdata;144}145146/* XXX override with 9280 specific state */147/* override 5416 methods for our needs */148AH5416(ah)->ah_initPLL = ar9280InitPLL;149150ah->ah_setAntennaSwitch = ar9287SetAntennaSwitch;151ah->ah_configPCIE = ar9287ConfigPCIE;152ah->ah_disablePCIE = ar9287DisablePCIE;153154AH5416(ah)->ah_cal.iqCalData.calData = &ar9287_iq_cal;155AH5416(ah)->ah_cal.adcGainCalData.calData = &ar9287_adc_gain_cal;156AH5416(ah)->ah_cal.adcDcCalData.calData = &ar9287_adc_dc_cal;157AH5416(ah)->ah_cal.adcDcCalInitData.calData = &ar9287_adc_init_dc_cal;158/* Better performance without ADC Gain Calibration */159AH5416(ah)->ah_cal.suppCals = ADC_DC_CAL | IQ_MISMATCH_CAL;160161AH5416(ah)->ah_spurMitigate = ar9280SpurMitigate;162AH5416(ah)->ah_writeIni = ar9287WriteIni;163164ah->ah_setTxPower = ar9287SetTransmitPower;165ah->ah_setBoardValues = ar9287SetBoardValues;166167AH5416(ah)->ah_olcInit = ar9287olcInit;168AH5416(ah)->ah_olcTempCompensation = ar9287olcTemperatureCompensation;169//AH5416(ah)->ah_setPowerCalTable = ar9287SetPowerCalTable;170AH5416(ah)->ah_cal_initcal = ar9287InitCalHardware;171AH5416(ah)->ah_cal_pacal = ar9287PACal;172173/* XXX NF calibration */174/* XXX Ini override? (IFS vars - since the kiwi mac clock is faster?) */175/* XXX what else is kiwi-specific in the radio/calibration pathway? */176177AH5416(ah)->ah_rx_chainmask = AR9287_DEFAULT_RXCHAINMASK;178AH5416(ah)->ah_tx_chainmask = AR9287_DEFAULT_TXCHAINMASK;179180if (!ar5416SetResetReg(ah, HAL_RESET_POWER_ON)) {181/* reset chip */182HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't reset chip\n",183__func__);184ecode = HAL_EIO;185goto bad;186}187188if (!ar5416SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) {189HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't wakeup chip\n",190__func__);191ecode = HAL_EIO;192goto bad;193}194/* Read Revisions from Chips before taking out of reset */195val = OS_REG_READ(ah, AR_SREV);196HALDEBUG(ah, HAL_DEBUG_ATTACH,197"%s: ID 0x%x VERSION 0x%x TYPE 0x%x REVISION 0x%x\n",198__func__, MS(val, AR_XSREV_ID), MS(val, AR_XSREV_VERSION),199MS(val, AR_XSREV_TYPE), MS(val, AR_XSREV_REVISION));200/* NB: include chip type to differentiate from pre-Sowl versions */201AH_PRIVATE(ah)->ah_macVersion =202(val & AR_XSREV_VERSION) >> AR_XSREV_TYPE_S;203AH_PRIVATE(ah)->ah_macRev = MS(val, AR_XSREV_REVISION);204AH_PRIVATE(ah)->ah_ispcie = (val & AR_XSREV_TYPE_HOST_MODE) == 0;205206/* Don't support Kiwi < 1.2; those are pre-release chips */207if (! AR_SREV_KIWI_12_OR_LATER(ah)) {208ath_hal_printf(ah, "[ath]: Kiwi < 1.2 is not supported\n");209ecode = HAL_EIO;210goto bad;211}212213/* setup common ini data; rf backends handle remainder */214HAL_INI_INIT(&ahp->ah_ini_modes, ar9287Modes_9287_1_1, 6);215HAL_INI_INIT(&ahp->ah_ini_common, ar9287Common_9287_1_1, 2);216217/* If pcie_clock_req */218HAL_INI_INIT(&AH5416(ah)->ah_ini_pcieserdes,219ar9287PciePhy_clkreq_always_on_L1_9287_1_1, 2);220221/* XXX WoW ini values */222223/* Else */224#if 0225HAL_INI_INIT(&AH5416(ah)->ah_ini_pcieserdes,226ar9287PciePhy_clkreq_off_L1_9287_1_1, 2);227#endif228229/* Initialise Japan arrays */230HAL_INI_INIT(&ahp9287->ah_ini_cckFirNormal,231ar9287Common_normal_cck_fir_coeff_9287_1_1, 2);232HAL_INI_INIT(&ahp9287->ah_ini_cckFirJapan2484,233ar9287Common_japan_2484_cck_fir_coeff_9287_1_1, 2);234235ar5416AttachPCIE(ah);236237ecode = ath_hal_9287EepromAttach(ah);238if (ecode != HAL_OK)239goto bad;240241if (!ar5416ChipReset(ah, AH_NULL, HAL_RESET_NORMAL)) { /* reset chip */242HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n", __func__);243ecode = HAL_EIO;244goto bad;245}246247AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID);248249if (!ar5212ChipTest(ah)) {250HALDEBUG(ah, HAL_DEBUG_ANY, "%s: hardware self-test failed\n",251__func__);252ecode = HAL_ESELFTEST;253goto bad;254}255256/*257* Set correct Baseband to analog shift258* setting to access analog chips.259*/260OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);261262/* Read Radio Chip Rev Extract */263AH_PRIVATE(ah)->ah_analog5GhzRev = ar5416GetRadioRev(ah);264switch (AH_PRIVATE(ah)->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR) {265case AR_RAD2133_SREV_MAJOR: /* Sowl: 2G/3x3 */266case AR_RAD5133_SREV_MAJOR: /* Sowl: 2+5G/3x3 */267break;268default:269if (AH_PRIVATE(ah)->ah_analog5GhzRev == 0) {270AH_PRIVATE(ah)->ah_analog5GhzRev =271AR_RAD5133_SREV_MAJOR;272break;273}274#ifdef AH_DEBUG275HALDEBUG(ah, HAL_DEBUG_ANY,276"%s: 5G Radio Chip Rev 0x%02X is not supported by "277"this driver\n", __func__,278AH_PRIVATE(ah)->ah_analog5GhzRev);279ecode = HAL_ENOTSUPP;280goto bad;281#endif282}283rfStatus = ar9287RfAttach(ah, &ecode);284if (!rfStatus) {285HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RF setup failed, status %u\n",286__func__, ecode);287goto bad;288}289290/*291* We only implement open-loop TX power control292* for the AR9287 in this codebase.293*/294if (! ath_hal_eepromGetFlag(ah, AR_EEP_OL_PWRCTRL)) {295ath_hal_printf(ah, "[ath] AR9287 w/ closed-loop TX power control"296" isn't supported.\n");297ecode = HAL_ENOTSUPP;298goto bad;299}300301/*302* Check whether the power table offset isn't the default.303* This can occur with eeprom minor V21 or greater on Merlin.304*/305(void) ath_hal_eepromGet(ah, AR_EEP_PWR_TABLE_OFFSET, &pwr_table_offset);306if (pwr_table_offset != AR5416_PWR_TABLE_OFFSET_DB)307ath_hal_printf(ah, "[ath]: default pwr offset: %d dBm != EEPROM pwr offset: %d dBm; curves will be adjusted.\n",308AR5416_PWR_TABLE_OFFSET_DB, (int) pwr_table_offset);309310/* setup rxgain table */311HAL_INI_INIT(&ahp9287->ah_ini_rxgain, ar9287Modes_rx_gain_9287_1_1, 6);312313/* setup txgain table */314HAL_INI_INIT(&ahp9287->ah_ini_txgain, ar9287Modes_tx_gain_9287_1_1, 6);315316/*317* Got everything we need now to setup the capabilities.318*/319if (!ar9287FillCapabilityInfo(ah)) {320ecode = HAL_EEREAD;321goto bad;322}323324ecode = ath_hal_eepromGet(ah, AR_EEP_MACADDR, ahp->ah_macaddr);325if (ecode != HAL_OK) {326HALDEBUG(ah, HAL_DEBUG_ANY,327"%s: error getting mac address from EEPROM\n", __func__);328goto bad;329}330/* XXX How about the serial number ? */331/* Read Reg Domain */332AH_PRIVATE(ah)->ah_currentRD =333ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, AH_NULL);334AH_PRIVATE(ah)->ah_currentRDext = AR9287_RDEXT_DEFAULT;335336/*337* ah_miscMode is populated by ar5416FillCapabilityInfo()338* starting from griffin. Set here to make sure that339* AR_MISC_MODE_MIC_NEW_LOC_ENABLE is set before a GTK is340* placed into hardware.341*/342if (ahp->ah_miscMode != 0)343OS_REG_WRITE(ah, AR_MISC_MODE, OS_REG_READ(ah, AR_MISC_MODE) | ahp->ah_miscMode);344345ar9287AniSetup(ah); /* Anti Noise Immunity */346347/* Setup noise floor min/max/nominal values */348AH5416(ah)->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9287_2GHZ;349AH5416(ah)->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9287_2GHZ;350AH5416(ah)->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9287_2GHZ;351AH5416(ah)->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9287_5GHZ;352AH5416(ah)->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9287_5GHZ;353AH5416(ah)->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9287_5GHZ;354355ar5416InitNfHistBuff(AH5416(ah)->ah_cal.nfCalHist);356357HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: return\n", __func__);358359return ah;360bad:361if (ah != AH_NULL)362ah->ah_detach(ah);363if (status)364*status = ecode;365return AH_NULL;366}367368static void369ar9287ConfigPCIE(struct ath_hal *ah, HAL_BOOL restore, HAL_BOOL power_off)370{371if (AH_PRIVATE(ah)->ah_ispcie && !restore) {372ath_hal_ini_write(ah, &AH5416(ah)->ah_ini_pcieserdes, 1, 0);373OS_DELAY(1000);374OS_REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);375/* Yes, Kiwi uses the Kite PCIe PHY WA */376OS_REG_WRITE(ah, AR_WA, AR9285_WA_DEFAULT);377}378}379380static void381ar9287DisablePCIE(struct ath_hal *ah)382{383/* XXX TODO */384}385386static void387ar9287WriteIni(struct ath_hal *ah, const struct ieee80211_channel *chan)388{389u_int modesIndex, freqIndex;390int regWrites = 0;391392/* Setup the indices for the next set of register array writes */393/* XXX Ignore 11n dynamic mode on the AR5416 for the moment */394if (IEEE80211_IS_CHAN_2GHZ(chan)) {395freqIndex = 2;396if (IEEE80211_IS_CHAN_HT40(chan))397modesIndex = 3;398else if (IEEE80211_IS_CHAN_108G(chan))399modesIndex = 5;400else401modesIndex = 4;402} else {403freqIndex = 1;404if (IEEE80211_IS_CHAN_HT40(chan) ||405IEEE80211_IS_CHAN_TURBO(chan))406modesIndex = 2;407else408modesIndex = 1;409}410411/* Set correct Baseband to analog shift setting to access analog chips. */412OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);413OS_REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);414415regWrites = ath_hal_ini_write(ah, &AH5212(ah)->ah_ini_modes, modesIndex, regWrites);416regWrites = ath_hal_ini_write(ah, &AH9287(ah)->ah_ini_rxgain, modesIndex, regWrites);417regWrites = ath_hal_ini_write(ah, &AH9287(ah)->ah_ini_txgain, modesIndex, regWrites);418regWrites = ath_hal_ini_write(ah, &AH5212(ah)->ah_ini_common, 1, regWrites);419}420421/*422* Fill all software cached or static hardware state information.423* Return failure if capabilities are to come from EEPROM and424* cannot be read.425*/426static HAL_BOOL427ar9287FillCapabilityInfo(struct ath_hal *ah)428{429HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;430431if (!ar5416FillCapabilityInfo(ah))432return AH_FALSE;433pCap->halNumGpioPins = 10;434pCap->halWowSupport = AH_TRUE;435pCap->halWowMatchPatternExact = AH_TRUE;436#if 0437pCap->halWowMatchPatternDword = AH_TRUE;438#endif439440pCap->halCSTSupport = AH_TRUE;441pCap->halRifsRxSupport = AH_TRUE;442pCap->halRifsTxSupport = AH_TRUE;443pCap->halRtsAggrLimit = 64*1024; /* 802.11n max */444pCap->halExtChanDfsSupport = AH_TRUE;445pCap->halUseCombinedRadarRssi = AH_TRUE;446#if 0447/* XXX bluetooth */448pCap->halBtCoexSupport = AH_TRUE;449#endif450pCap->halAutoSleepSupport = AH_FALSE; /* XXX? */451pCap->hal4kbSplitTransSupport = AH_FALSE;452/* Disable this so Block-ACK works correctly */453pCap->halHasRxSelfLinkedTail = AH_FALSE;454pCap->halPSPollBroken = AH_FALSE;455pCap->halSpectralScanSupport = AH_TRUE;456457/* Hardware supports (at least) single-stream STBC TX/RX */458pCap->halRxStbcSupport = 1;459pCap->halTxStbcSupport = 1;460461/* Hardware supports short-GI w/ 20MHz */462pCap->halHTSGI20Support = 1;463464pCap->halEnhancedDfsSupport = AH_TRUE;465466return AH_TRUE;467}468469/*470* This has been disabled - having the HAL flip chainmasks on/off471* when attempting to implement 11n disrupts things. For now, just472* leave this flipped off and worry about implementing TX diversity473* for legacy and MCS0-15 when 11n is fully functioning.474*/475HAL_BOOL476ar9287SetAntennaSwitch(struct ath_hal *ah, HAL_ANT_SETTING settings)477{478return AH_TRUE;479}480481static const char*482ar9287Probe(uint16_t vendorid, uint16_t devid)483{484if (vendorid == ATHEROS_VENDOR_ID) {485if (devid == AR9287_DEVID_PCI)486return "Atheros 9227";487if (devid == AR9287_DEVID_PCIE)488return "Atheros 9287";489}490return AH_NULL;491}492AH_CHIP(AR9287, ar9287Probe, ar9287Attach);493494495