Path: blob/main/sys/dev/ath/ath_hal/ar5210/ar5210_attach.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2009 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2004 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 "ar5210/ar5210.h"25#include "ar5210/ar5210reg.h"26#include "ar5210/ar5210phy.h"2728#include "ah_eeprom_v1.h"2930static HAL_BOOL ar5210GetChannelEdges(struct ath_hal *,31uint16_t flags, uint16_t *low, uint16_t *high);32static HAL_BOOL ar5210GetChipPowerLimits(struct ath_hal *ah,33struct ieee80211_channel *chan);3435static void ar5210ConfigPCIE(struct ath_hal *ah, HAL_BOOL restore,36HAL_BOOL power_on);37static void ar5210DisablePCIE(struct ath_hal *ah);3839static const struct ath_hal_private ar5210hal = {{40.ah_magic = AR5210_MAGIC,4142.ah_getRateTable = ar5210GetRateTable,43.ah_detach = ar5210Detach,4445/* Reset Functions */46.ah_reset = ar5210Reset,47.ah_phyDisable = ar5210PhyDisable,48.ah_disable = ar5210Disable,49.ah_configPCIE = ar5210ConfigPCIE,50.ah_disablePCIE = ar5210DisablePCIE,51.ah_setPCUConfig = ar5210SetPCUConfig,52.ah_perCalibration = ar5210PerCalibration,53.ah_perCalibrationN = ar5210PerCalibrationN,54.ah_resetCalValid = ar5210ResetCalValid,55.ah_setTxPowerLimit = ar5210SetTxPowerLimit,56.ah_getChanNoise = ath_hal_getChanNoise,5758/* Transmit functions */59.ah_updateTxTrigLevel = ar5210UpdateTxTrigLevel,60.ah_setupTxQueue = ar5210SetupTxQueue,61.ah_setTxQueueProps = ar5210SetTxQueueProps,62.ah_getTxQueueProps = ar5210GetTxQueueProps,63.ah_releaseTxQueue = ar5210ReleaseTxQueue,64.ah_resetTxQueue = ar5210ResetTxQueue,65.ah_getTxDP = ar5210GetTxDP,66.ah_setTxDP = ar5210SetTxDP,67.ah_numTxPending = ar5210NumTxPending,68.ah_startTxDma = ar5210StartTxDma,69.ah_stopTxDma = ar5210StopTxDma,70.ah_setupTxDesc = ar5210SetupTxDesc,71.ah_setupXTxDesc = ar5210SetupXTxDesc,72.ah_fillTxDesc = ar5210FillTxDesc,73.ah_procTxDesc = ar5210ProcTxDesc,74.ah_getTxIntrQueue = ar5210GetTxIntrQueue,75.ah_reqTxIntrDesc = ar5210IntrReqTxDesc,76.ah_getTxCompletionRates = ar5210GetTxCompletionRates,77.ah_setTxDescLink = ar5210SetTxDescLink,78.ah_getTxDescLink = ar5210GetTxDescLink,79.ah_getTxDescLinkPtr = ar5210GetTxDescLinkPtr,8081/* RX Functions */82.ah_getRxDP = ar5210GetRxDP,83.ah_setRxDP = ar5210SetRxDP,84.ah_enableReceive = ar5210EnableReceive,85.ah_stopDmaReceive = ar5210StopDmaReceive,86.ah_startPcuReceive = ar5210StartPcuReceive,87.ah_stopPcuReceive = ar5210StopPcuReceive,88.ah_setMulticastFilter = ar5210SetMulticastFilter,89.ah_setMulticastFilterIndex = ar5210SetMulticastFilterIndex,90.ah_clrMulticastFilterIndex = ar5210ClrMulticastFilterIndex,91.ah_getRxFilter = ar5210GetRxFilter,92.ah_setRxFilter = ar5210SetRxFilter,93.ah_setupRxDesc = ar5210SetupRxDesc,94.ah_procRxDesc = ar5210ProcRxDesc,95.ah_rxMonitor = ar5210RxMonitor,96.ah_aniPoll = ar5210AniPoll,97.ah_procMibEvent = ar5210MibEvent,9899/* Misc Functions */100.ah_getCapability = ar5210GetCapability,101.ah_setCapability = ar5210SetCapability,102.ah_getDiagState = ar5210GetDiagState,103.ah_getMacAddress = ar5210GetMacAddress,104.ah_setMacAddress = ar5210SetMacAddress,105.ah_getBssIdMask = ar5210GetBssIdMask,106.ah_setBssIdMask = ar5210SetBssIdMask,107.ah_setRegulatoryDomain = ar5210SetRegulatoryDomain,108.ah_setLedState = ar5210SetLedState,109.ah_writeAssocid = ar5210WriteAssocid,110.ah_gpioCfgInput = ar5210GpioCfgInput,111.ah_gpioCfgOutput = ar5210GpioCfgOutput,112.ah_gpioGet = ar5210GpioGet,113.ah_gpioSet = ar5210GpioSet,114.ah_gpioSetIntr = ar5210Gpio0SetIntr,115.ah_getTsf32 = ar5210GetTsf32,116.ah_getTsf64 = ar5210GetTsf64,117.ah_resetTsf = ar5210ResetTsf,118.ah_detectCardPresent = ar5210DetectCardPresent,119.ah_updateMibCounters = ar5210UpdateMibCounters,120.ah_getRfGain = ar5210GetRfgain,121.ah_getDefAntenna = ar5210GetDefAntenna,122.ah_setDefAntenna = ar5210SetDefAntenna,123.ah_getAntennaSwitch = ar5210GetAntennaSwitch,124.ah_setAntennaSwitch = ar5210SetAntennaSwitch,125.ah_setSifsTime = ar5210SetSifsTime,126.ah_getSifsTime = ar5210GetSifsTime,127.ah_setSlotTime = ar5210SetSlotTime,128.ah_getSlotTime = ar5210GetSlotTime,129.ah_setAckTimeout = ar5210SetAckTimeout,130.ah_getAckTimeout = ar5210GetAckTimeout,131.ah_setAckCTSRate = ar5210SetAckCTSRate,132.ah_getAckCTSRate = ar5210GetAckCTSRate,133.ah_setCTSTimeout = ar5210SetCTSTimeout,134.ah_getCTSTimeout = ar5210GetCTSTimeout,135.ah_setDecompMask = ar5210SetDecompMask,136.ah_setCoverageClass = ar5210SetCoverageClass,137.ah_setQuiet = ar5210SetQuiet,138.ah_get11nExtBusy = ar5210Get11nExtBusy,139.ah_getMibCycleCounts = ar5210GetMibCycleCounts,140.ah_setChainMasks = ar5210SetChainMasks,141.ah_enableDfs = ar5210EnableDfs,142.ah_getDfsThresh = ar5210GetDfsThresh,143/* XXX procRadarEvent */144/* XXX isFastClockEnabled */145.ah_getNav = ar5210GetNav,146.ah_setNav = ar5210SetNav,147148/* Key Cache Functions */149.ah_getKeyCacheSize = ar5210GetKeyCacheSize,150.ah_resetKeyCacheEntry = ar5210ResetKeyCacheEntry,151.ah_isKeyCacheEntryValid = ar5210IsKeyCacheEntryValid,152.ah_setKeyCacheEntry = ar5210SetKeyCacheEntry,153.ah_setKeyCacheEntryMac = ar5210SetKeyCacheEntryMac,154155/* Power Management Functions */156.ah_setPowerMode = ar5210SetPowerMode,157.ah_getPowerMode = ar5210GetPowerMode,158159/* Beacon Functions */160.ah_setBeaconTimers = ar5210SetBeaconTimers,161.ah_beaconInit = ar5210BeaconInit,162.ah_setStationBeaconTimers = ar5210SetStaBeaconTimers,163.ah_resetStationBeaconTimers = ar5210ResetStaBeaconTimers,164.ah_getNextTBTT = ar5210GetNextTBTT,165166/* Interrupt Functions */167.ah_isInterruptPending = ar5210IsInterruptPending,168.ah_getPendingInterrupts = ar5210GetPendingInterrupts,169.ah_getInterrupts = ar5210GetInterrupts,170.ah_setInterrupts = ar5210SetInterrupts },171172.ah_getChannelEdges = ar5210GetChannelEdges,173.ah_getWirelessModes = ar5210GetWirelessModes,174.ah_eepromRead = ar5210EepromRead,175#ifdef AH_SUPPORT_WRITE_EEPROM176.ah_eepromWrite = ar5210EepromWrite,177#endif178.ah_getChipPowerLimits = ar5210GetChipPowerLimits,179};180181static HAL_BOOL ar5210FillCapabilityInfo(struct ath_hal *ah);182183/*184* Attach for an AR5210 part.185*/186static struct ath_hal *187ar5210Attach(uint16_t devid, HAL_SOFTC sc, HAL_BUS_TAG st, HAL_BUS_HANDLE sh,188uint16_t *eepromdata, HAL_OPS_CONFIG *ah_config, HAL_STATUS *status)189{190#define N(a) (sizeof(a)/sizeof(a[0]))191struct ath_hal_5210 *ahp;192struct ath_hal *ah;193uint32_t revid, pcicfg;194uint16_t eeval;195HAL_STATUS ecode;196int i;197198HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH,199"%s: devid 0x%x sc %p st %p sh %p\n", __func__, devid,200sc, (void*) st, (void*) sh);201202/* NB: memory is returned zero'd */203ahp = ath_hal_malloc(sizeof (struct ath_hal_5210));204if (ahp == AH_NULL) {205HALDEBUG(AH_NULL, HAL_DEBUG_ANY,206"%s: no memory for state block\n", __func__);207ecode = HAL_ENOMEM;208goto bad;209}210ah = &ahp->ah_priv.h;211/* set initial values */212OS_MEMCPY(&ahp->ah_priv, &ar5210hal, sizeof(struct ath_hal_private));213ah->ah_sc = sc;214ah->ah_st = st;215ah->ah_sh = sh;216217ah->ah_devid = devid; /* NB: for AH_DEBUG_ALQ */218AH_PRIVATE(ah)->ah_devid = devid;219AH_PRIVATE(ah)->ah_subvendorid = 0; /* XXX */220221AH_PRIVATE(ah)->ah_powerLimit = AR5210_MAX_RATE_POWER;222AH_PRIVATE(ah)->ah_tpScale = HAL_TP_SCALE_MAX; /* no scaling */223224ah->ah_powerMode = HAL_PM_UNDEFINED;225ahp->ah_staId1Defaults = 0;226ahp->ah_rssiThr = INIT_RSSI_THR;227ahp->ah_sifstime = (u_int) -1;228ahp->ah_slottime = (u_int) -1;229ahp->ah_acktimeout = (u_int) -1;230ahp->ah_ctstimeout = (u_int) -1;231232if (!ar5210ChipReset(ah, AH_NULL)) { /* reset chip */233HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n",234__func__);235ecode = HAL_EIO;236goto bad;237}238239/* Read Revisions from Chips */240AH_PRIVATE(ah)->ah_macVersion = 1;241AH_PRIVATE(ah)->ah_macRev = OS_REG_READ(ah, AR_SREV) & 0xff;242AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIPID);243AH_PRIVATE(ah)->ah_analog2GhzRev = 0;244245/* Read Radio Chip Rev Extract */246OS_REG_WRITE(ah, (AR_PHY_BASE + (0x34 << 2)), 0x00001c16);247for (i = 0; i < 4; i++)248OS_REG_WRITE(ah, (AR_PHY_BASE + (0x20 << 2)), 0x00010000);249revid = (OS_REG_READ(ah, AR_PHY_BASE + (256 << 2)) >> 28) & 0xf;250251/* Chip labelling is 1 greater than revision register for AR5110 */252AH_PRIVATE(ah)->ah_analog5GhzRev = ath_hal_reverseBits(revid, 4) + 1;253254/*255* Read all the settings from the EEPROM and stash256* ones we'll use later.257*/258pcicfg = OS_REG_READ(ah, AR_PCICFG);259OS_REG_WRITE(ah, AR_PCICFG, pcicfg | AR_PCICFG_EEPROMSEL);260ecode = ath_hal_v1EepromAttach(ah);261if (ecode != HAL_OK) {262goto eebad;263}264ecode = ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, &eeval);265if (ecode != HAL_OK) {266HALDEBUG(ah, HAL_DEBUG_ANY,267"%s: cannot read regulatory domain from EEPROM\n",268__func__);269goto eebad;270}271AH_PRIVATE(ah)->ah_currentRD = eeval;272ecode = ath_hal_eepromGet(ah, AR_EEP_MACADDR, ahp->ah_macaddr);273if (ecode != HAL_OK) {274HALDEBUG(ah, HAL_DEBUG_ANY,275"%s: error getting mac address from EEPROM\n", __func__);276goto eebad;277}278OS_REG_WRITE(ah, AR_PCICFG, pcicfg); /* disable EEPROM access */279280AH_PRIVATE(ah)->ah_getNfAdjust = ar5210GetNfAdjust;281282/*283* Got everything we need now to setup the capabilities.284*/285(void) ar5210FillCapabilityInfo(ah);286287HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: return\n", __func__);288289return ah;290eebad:291OS_REG_WRITE(ah, AR_PCICFG, pcicfg); /* disable EEPROM access */292bad:293if (ahp)294ath_hal_free(ahp);295if (status)296*status = ecode;297return AH_NULL;298#undef N299}300301void302ar5210Detach(struct ath_hal *ah)303{304HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s:\n", __func__);305306HALASSERT(ah != AH_NULL);307HALASSERT(ah->ah_magic == AR5210_MAGIC);308309ath_hal_eepromDetach(ah);310ath_hal_free(ah);311}312313/*314* Store the channel edges for the requested operational mode315*/316static HAL_BOOL317ar5210GetChannelEdges(struct ath_hal *ah,318uint16_t flags, uint16_t *low, uint16_t *high)319{320if (flags & IEEE80211_CHAN_5GHZ) {321*low = 5120;322*high = 5430;323return AH_TRUE;324} else {325return AH_FALSE;326}327}328329static HAL_BOOL330ar5210GetChipPowerLimits(struct ath_hal *ah, struct ieee80211_channel *chan)331{332/* XXX fill in, this is just a placeholder */333HALDEBUG(ah, HAL_DEBUG_ATTACH,334"%s: no min/max power for %u/0x%x\n",335__func__, chan->ic_freq, chan->ic_flags);336chan->ic_maxpower = AR5210_MAX_RATE_POWER;337chan->ic_minpower = 0;338return AH_TRUE;339}340341static void342ar5210ConfigPCIE(struct ath_hal *ah, HAL_BOOL restore, HAL_BOOL power_off)343{344}345346static void347ar5210DisablePCIE(struct ath_hal *ah)348{349}350351/*352* Fill all software cached or static hardware state information.353*/354static HAL_BOOL355ar5210FillCapabilityInfo(struct ath_hal *ah)356{357struct ath_hal_private *ahpriv = AH_PRIVATE(ah);358HAL_CAPABILITIES *pCap = &ahpriv->ah_caps;359360pCap->halWirelessModes |= HAL_MODE_11A;361362pCap->halLow5GhzChan = 5120;363pCap->halHigh5GhzChan = 5430;364365pCap->halSleepAfterBeaconBroken = AH_TRUE;366pCap->halPSPollBroken = AH_FALSE;367pCap->halNumMRRetries = 1; /* No hardware MRR support */368pCap->halNumTxMaps = 1; /* Single TX ptr per descr */369370pCap->halTotalQueues = HAL_NUM_TX_QUEUES;371pCap->halKeyCacheSize = 64;372373/* XXX not needed */374pCap->halChanHalfRate = AH_FALSE;375pCap->halChanQuarterRate = AH_FALSE;376377/*378* RSSI uses the combined field; some 11n NICs may use379* the control chain RSSI.380*/381pCap->halUseCombinedRadarRssi = AH_TRUE;382383if (ath_hal_eepromGetFlag(ah, AR_EEP_RFKILL)) {384/*385* Setup initial rfsilent settings based on the EEPROM386* contents. Pin 0, polarity 0 is fixed; record this387* using the EEPROM format found in later parts.388*/389ahpriv->ah_rfsilent = SM(0, AR_EEPROM_RFSILENT_GPIO_SEL)390| SM(0, AR_EEPROM_RFSILENT_POLARITY);391ahpriv->ah_rfkillEnabled = AH_TRUE;392pCap->halRfSilentSupport = AH_TRUE;393}394395pCap->halTxTstampPrecision = 16;396pCap->halRxTstampPrecision = 15; /* NB: s/w extended from 13 */397pCap->halIntrMask = (HAL_INT_COMMON - HAL_INT_BNR)398| HAL_INT_RX399| HAL_INT_TX400| HAL_INT_FATAL401;402403pCap->hal4kbSplitTransSupport = AH_TRUE;404pCap->halHasRxSelfLinkedTail = AH_TRUE;405406ahpriv->ah_rxornIsFatal = AH_TRUE;407return AH_TRUE;408}409410static const char*411ar5210Probe(uint16_t vendorid, uint16_t devid)412{413if (vendorid == ATHEROS_VENDOR_ID &&414(devid == AR5210_PROD || devid == AR5210_DEFAULT))415return "Atheros 5210";416return AH_NULL;417}418AH_CHIP(AR5210, ar5210Probe, ar5210Attach);419420421