📄 ar5211_attach.c
字号:
/* * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting * Copyright (c) 2002-2005 Atheros Communications, Inc. * All rights reserved. * * $Id: ar5211_attach.c,v 1.1.1.1 2006/09/12 03:45:23 steven Exp $ */#include "opt_ah.h"#ifdef AH_SUPPORT_AR5211#include "ah.h"#include "ah_internal.h"#include "ah_devid.h"#include "ar5211/ar5211.h"#include "ar5211/ar5211reg.h"#include "ar5211/ar5211phy.h"static HAL_BOOL ar5211GetChannelEdges(struct ath_hal *ah, u_int16_t flags, u_int16_t *low, u_int16_t *high);static HAL_BOOL ar5211GetChipPowerLimits(struct ath_hal *ah, HAL_CHANNEL *chans, u_int32_t nchans);static const struct ath_hal_private ar5211hal = {{ .ah_magic = AR5211_MAGIC, .ah_abi = HAL_ABI_VERSION, .ah_countryCode = CTRY_DEFAULT, .ah_getRateTable = ar5211GetRateTable, .ah_detach = ar5211Detach, /* Reset Functions */ .ah_reset = ar5211Reset, .ah_phyDisable = ar5211PhyDisable, .ah_setPCUConfig = ar5211SetPCUConfig, .ah_perCalibration = ar5211PerCalibration, .ah_setTxPowerLimit = ar5211SetTxPowerLimit, /* AR/Radar Functions */ .ah_arEnable = ar5211ArEnable, .ah_arDisable = ar5211ArDisable, .ah_arReset = ar5211ResetAR, .ah_radarHaveEvent = ar5211HaveRadarEvent, .ah_processDfs = ar5211ProcessRadarEvent, .ah_dfsNolCheck = ar5211CheckRadarNol, .ah_radarWait = ar5211RadarWait, /* Xr Functions */ .ah_xrEnable = ar5211XrEnable, .ah_xrDisable = ar5211XrDisable, /* Transmit functions */ .ah_updateTxTrigLevel = ar5211UpdateTxTrigLevel, .ah_setupTxQueue = ar5211SetupTxQueue, .ah_setTxQueueProps = ar5211SetTxQueueProps, .ah_getTxQueueProps = ar5211GetTxQueueProps, .ah_releaseTxQueue = ar5211ReleaseTxQueue, .ah_resetTxQueue = ar5211ResetTxQueue, .ah_getTxDP = ar5211GetTxDP, .ah_setTxDP = ar5211SetTxDP, .ah_numTxPending = ar5211NumTxPending, .ah_startTxDma = ar5211StartTxDma, .ah_stopTxDma = ar5211StopTxDma, .ah_updateCTSForBursting = ar5211UpdateCTSForBursting, .ah_setupTxDesc = ar5211SetupTxDesc, .ah_setupXTxDesc = ar5211SetupXTxDesc, .ah_fillTxDesc = ar5211FillTxDesc, .ah_procTxDesc = ar5211ProcTxDesc, .ah_getTxIntrQueue = ar5211GetTxIntrQueue, .ah_reqTxIntrDesc = ar5211IntrReqTxDesc, /* RX Functions */ .ah_getRxDP = ar5211GetRxDP, .ah_setRxDP = ar5211SetRxDP, .ah_enableReceive = ar5211EnableReceive, .ah_stopDmaReceive = ar5211StopDmaReceive, .ah_startPcuReceive = ar5211StartPcuReceive, .ah_stopPcuReceive = ar5211StopPcuReceive, .ah_setMulticastFilter = ar5211SetMulticastFilter, .ah_setMulticastFilterIndex = ar5211SetMulticastFilterIndex, .ah_clrMulticastFilterIndex = ar5211ClrMulticastFilterIndex, .ah_getRxFilter = ar5211GetRxFilter, .ah_setRxFilter = ar5211SetRxFilter, .ah_setupRxDesc = ar5211SetupRxDesc, .ah_procRxDesc = ar5211ProcRxDesc, .ah_rxMonitor = ar5211AniPoll, .ah_procMibEvent = ar5211MibEvent, /* Misc Functions */ .ah_getCapability = ar5211GetCapability, .ah_setCapability = ar5211SetCapability, .ah_getDiagState = ar5211GetDiagState, .ah_getMacAddress = ar5211GetMacAddress, .ah_setMacAddress = ar5211SetMacAddress, .ah_getBssIdMask = ar5211GetBssIdMask, .ah_setBssIdMask = ar5211SetBssIdMask, .ah_setRegulatoryDomain = ar5211SetRegulatoryDomain, .ah_setLedState = ar5211SetLedState, .ah_writeAssocid = ar5211WriteAssocid, .ah_gpioCfgInput = ar5211GpioCfgInput, .ah_gpioCfgOutput = ar5211GpioCfgOutput, .ah_gpioGet = ar5211GpioGet, .ah_gpioSet = ar5211GpioSet, .ah_gpioSetIntr = ar5211GpioSetIntr, .ah_getTsf32 = ar5211GetTsf32, .ah_getTsf64 = ar5211GetTsf64, .ah_resetTsf = ar5211ResetTsf, .ah_detectCardPresent = ar5211DetectCardPresent, .ah_updateMibCounters = ar5211UpdateMibCounters, .ah_getRfGain = ar5211GetRfgain, .ah_getDefAntenna = ar5211GetDefAntenna, .ah_setDefAntenna = ar5211SetDefAntenna, .ah_setSlotTime = ar5211SetSlotTime, .ah_getSlotTime = ar5211GetSlotTime, .ah_setAckTimeout = ar5211SetAckTimeout, .ah_getAckTimeout = ar5211GetAckTimeout, .ah_setCTSTimeout = ar5211SetCTSTimeout, .ah_getCTSTimeout = ar5211GetCTSTimeout, .ah_setDecompMask = ar5211SetDecompMask, .ah_setCoverageClass = ar5211SetCoverageClass, /* Key Cache Functions */ .ah_getKeyCacheSize = ar5211GetKeyCacheSize, .ah_resetKeyCacheEntry = ar5211ResetKeyCacheEntry, .ah_isKeyCacheEntryValid = ar5211IsKeyCacheEntryValid, .ah_setKeyCacheEntry = ar5211SetKeyCacheEntry, .ah_setKeyCacheEntryMac = ar5211SetKeyCacheEntryMac, /* Power Management Functions */ .ah_setPowerMode = ar5211SetPowerMode, .ah_getPowerMode = ar5211GetPowerMode, /* Beacon Functions */ .ah_beaconInit = ar5211BeaconInit, .ah_setStationBeaconTimers = ar5211SetStaBeaconTimers, .ah_resetStationBeaconTimers = ar5211ResetStaBeaconTimers, .ah_waitForBeaconDone = ar5211WaitForBeaconDone, /* Interrupt Functions */ .ah_isInterruptPending = ar5211IsInterruptPending, .ah_getPendingInterrupts = ar5211GetPendingInterrupts, .ah_getInterrupts = ar5211GetInterrupts, .ah_setInterrupts = ar5211SetInterrupts }, .ah_getChannelEdges = ar5211GetChannelEdges, .ah_getWirelessModes = ar5211GetWirelessModes, .ah_eepromRead = ar5211EepromRead,#ifdef AH_SUPPORT_WRITE_EEPROM .ah_eepromWrite = ar5211EepromWrite,#endif .ah_gpioCfgInput = ar5211GpioCfgInput, .ah_gpioCfgOutput = ar5211GpioCfgOutput, .ah_gpioGet = ar5211GpioGet, .ah_gpioSet = ar5211GpioSet, .ah_gpioSetIntr = ar5211GpioSetIntr, .ah_getChipPowerLimits = ar5211GetChipPowerLimits,};static HAL_BOOL ar5211ChipTest(struct ath_hal *);static HAL_BOOL ar5211FillCapabilityInfo(struct ath_hal *ah);/* * TODO: Need to talk to Praveen about this, these are * not valid 2.4 channels, either we change these * or I need to change the beanie coding to accept these */static const u_int16_t channels2_4[] = { 2412, 2447, 2484 };/* * Return the revsion id for the radio chip. This * fetched via the PHY. */static u_int32_tar5211GetRadioRev(struct ath_hal *ah){ u_int32_t val; int i; OS_REG_WRITE(ah, (AR_PHY_BASE + (0x34 << 2)), 0x00001c16); for (i = 0; i < 8; i++) OS_REG_WRITE(ah, (AR_PHY_BASE + (0x20 << 2)), 0x00010000); val = (OS_REG_READ(ah, AR_PHY_BASE + (256 << 2)) >> 24) & 0xff; val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4); return ath_hal_reverseBits(val, 8);}/* * Attach for an AR5211 part. */struct ath_hal *ar5211Attach(u_int16_t devid, HAL_SOFTC sc, HAL_BUS_TAG st, HAL_BUS_HANDLE sh, HAL_STATUS *status){#define N(a) (sizeof(a)/sizeof(a[0])) struct ath_hal_5211 *ahp; struct ath_hal *ah; u_int i; u_int32_t sum, val; u_int16_t eeval; HAL_STATUS ecode; HALDEBUG(AH_NULL, "%s: sc %p st %u sh %p\n", __func__, sc, st, (void*) sh); /* NB: memory is returned zero'd */ ahp = ath_hal_malloc(sizeof (struct ath_hal_5211)); if (ahp == AH_NULL) { HALDEBUG(AH_NULL, "%s: cannot allocate memory for state " "block\n", __func__); ecode = HAL_ENOMEM; goto bad; } ah = &ahp->ah_priv.h; /* set initial values */ OS_MEMCPY(&ahp->ah_priv, &ar5211hal, sizeof(struct ath_hal_private)); ah->ah_sc = sc; ah->ah_st = st; ah->ah_sh = sh; AH_PRIVATE(ah)->ah_devid = devid; AH_PRIVATE(ah)->ah_subvendorid = 0; /* XXX */ AH_PRIVATE(ah)->ah_powerLimit = MAX_RATE_POWER; AH_PRIVATE(ah)->ah_tpScale = HAL_TP_SCALE_MAX; /* no scaling */ ahp->ah_diversityControl = HAL_ANT_VARIABLE; ahp->ah_atimWindow = 0; ahp->ah_slottime = (u_int) -1; ahp->ah_acktimeout = (u_int) -1; ahp->ah_ctstimeout = (u_int) -1; if (!ar5211ChipReset(ah, AH_FALSE)) { /* reset chip */ HALDEBUG(ah, "%s: chip reset failed\n", __func__); ecode = HAL_EIO; goto bad; } if (AH_PRIVATE(ah)->ah_devid == AR5211_FPGA11B) { /* set it back to OFDM mode to be able to read analog rev id */ OS_REG_WRITE(ah, AR5211_PHY_MODE, AR5211_PHY_MODE_OFDM); OS_REG_WRITE(ah, AR_PHY_PLL_CTL, AR_PHY_PLL_CTL_44); OS_DELAY(1000); } /* Read Revisions from Chips */ val = OS_REG_READ(ah, AR_SREV) & AR_SREV_ID_M; AH_PRIVATE(ah)->ah_macVersion = val >> AR_SREV_ID_S; AH_PRIVATE(ah)->ah_macRev = val & AR_SREV_REVISION_M; if (AH_PRIVATE(ah)->ah_macVersion < AR_SREV_VERSION_MAUI_2 || AH_PRIVATE(ah)->ah_macVersion > AR_SREV_VERSION_OAHU) { HALDEBUG(ah, "%s: Mac Chip Rev 0x%x is not supported by this " "driver\n", __func__, AH_PRIVATE(ah)->ah_macVersion); ecode = HAL_ENOTSUPP; goto bad; } AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID); if (!ar5211ChipTest(ah)) { HALDEBUG(ah, "%s: hardware self-test failed\n", __func__); ecode = HAL_ESELFTEST; goto bad; } /* Set correct Baseband to analog shift setting to access analog chips. */ if (AH_PRIVATE(ah)->ah_macVersion >= AR_SREV_VERSION_OAHU) { OS_REG_WRITE(ah, AR_PHY_BASE, 0x00000007); } else { OS_REG_WRITE(ah, AR_PHY_BASE, 0x00000047); } OS_DELAY(2000); /* Read Radio Chip Rev Extract */ AH_PRIVATE(ah)->ah_analog5GhzRev = ar5211GetRadioRev(ah); if ((AH_PRIVATE(ah)->ah_analog5GhzRev & 0xf0) != RAD5_SREV_MAJOR) { HALDEBUG(ah, "%s: 5G Radio Chip Rev 0x%02X is not supported by "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -